Update views for technical debt
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
||||
@@ -17,6 +17,8 @@ import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SimpleAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import massiveattendancescannerapplication.Services.FileReader;
|
||||
import massiveattendancescannerapplication.Services.ServiceHandler;
|
||||
|
||||
public class CourseActivity extends ListActivity {
|
||||
@@ -27,7 +29,7 @@ public class CourseActivity extends ListActivity {
|
||||
JSONObject professor;
|
||||
String JSONString;
|
||||
private static final String COURSE = "courses";
|
||||
private static final String URL = "http://192.168.0.106:3000/professors/56f5fd3a20047f3c15b05f0e";
|
||||
String URL;
|
||||
private static final String TAG_ID = "_id";
|
||||
private static final String TAG_NAME = "name";
|
||||
private static final String TAG_CODE = "code";
|
||||
@@ -38,7 +40,7 @@ public class CourseActivity extends ListActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.course_activity);
|
||||
|
||||
|
||||
URL = FileReader.getUrl(getApplicationContext());
|
||||
courseList = new ArrayList<>();
|
||||
new LoadCourses().execute();
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SimpleAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import massiveattendancescannerapplication.Services.FileReader;
|
||||
import massiveattendancescannerapplication.Services.ServiceHandler;
|
||||
|
||||
public class SectionActivity extends ListActivity {
|
||||
@@ -28,7 +30,7 @@ public class SectionActivity extends ListActivity {
|
||||
String JSONString, course_id, course_name;
|
||||
private static final String COURSE = "courses";
|
||||
private static final String SECTION = "sections";
|
||||
private static final String URL = "http://192.168.0.106:3000/professors/56f5fd3a20047f3c15b05f0e";
|
||||
String URL;
|
||||
private static final String TAG_ID = "_id";
|
||||
private static final String TAG_NAME = "name";
|
||||
private static final String TAG_SEMESTER = "semester";
|
||||
@@ -40,6 +42,7 @@ public class SectionActivity extends ListActivity {
|
||||
setContentView(R.layout.section_activity);
|
||||
|
||||
Intent i = getIntent();
|
||||
URL = FileReader.getUrl(getApplicationContext());
|
||||
course_id = i.getStringExtra("course_id");
|
||||
sectionList = new ArrayList<HashMap<String, String>>();
|
||||
new LoadSections().execute();
|
||||
|
||||
@@ -19,22 +19,18 @@ import java.io.IOException;
|
||||
public class FileReader {
|
||||
|
||||
static String response;
|
||||
private static final String professors = "professors.txt";
|
||||
private static final String courses = "courses.txt";
|
||||
private static final String sections = "sections.txt";
|
||||
private static final String students = "students.txt";
|
||||
private static final String url = "url.txt";
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This function returns the URL direction parsed from the .txt file contained in the phone.
|
||||
* </p>
|
||||
* @param context Application Context.
|
||||
* @param method Method representing POST of GET methods.
|
||||
* @return String containing the URL.
|
||||
*/
|
||||
public static String getUrl(Context context, int method) {
|
||||
public static String getUrl(Context context) {
|
||||
try {
|
||||
return parse(getConfigFile(context,method));
|
||||
return parse(getConfigFile(context));
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
@@ -48,25 +44,18 @@ public class FileReader {
|
||||
* direction for each type.
|
||||
* </p>
|
||||
* @param context Application Context.
|
||||
* @param method Method representing POST of GET methods.
|
||||
* @return BufferedReader containing the information inside the file.
|
||||
*/
|
||||
private static BufferedReader getConfigFile(Context context,int method) {
|
||||
private static BufferedReader getConfigFile(Context context) {
|
||||
if(isExternalStorageReadable()){
|
||||
// Get the directory for the app's private files
|
||||
File file = null;
|
||||
String extr = Environment.getExternalStorageDirectory().toString();
|
||||
File mFolder = new File(extr + "/data");
|
||||
File file;
|
||||
try {
|
||||
if(method == 1) file = new File(context.getExternalFilesDir(null), professors);
|
||||
if(method == 2) file = new File(context.getExternalFilesDir(null), courses);
|
||||
if(method == 3) file = new File(context.getExternalFilesDir(null), sections);
|
||||
if(method == 4) file = new File(context.getExternalFilesDir(null), students);
|
||||
|
||||
if (file!=null) {
|
||||
file = new File(mFolder.getAbsolutePath(), url);
|
||||
java.io.FileReader fr = new java.io.FileReader(file);
|
||||
return new BufferedReader(fr);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
|
||||
@@ -19,12 +19,12 @@ import android.os.Handler;
|
||||
|
||||
public class TransmitterTask extends AsyncTask<JSONObject, Void, Void> {
|
||||
|
||||
private static final String URL = "http://192.168.0.106:3000/professors/56f5fd3a20047f3c15b05f0e";
|
||||
String URL;
|
||||
boolean result;
|
||||
|
||||
final Handler myHandler = new Handler();
|
||||
public TransmitterTask() {
|
||||
|
||||
public TransmitterTask(String URL) {
|
||||
this.URL = URL;
|
||||
}
|
||||
|
||||
protected Void doInBackground(JSONObject... professor) {
|
||||
|
||||
@@ -9,17 +9,24 @@ import java.util.HashMap;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ListActivity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListAdapter;
|
||||
@@ -28,6 +35,7 @@ import android.widget.SimpleAdapter;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import massiveattendancescannerapplication.Services.FileReader;
|
||||
import massiveattendancescannerapplication.Services.ServiceHandler;
|
||||
import massiveattendancescannerapplication.Services.TransmitterTask;
|
||||
|
||||
@@ -42,7 +50,7 @@ public class StudentActivity extends ListActivity {
|
||||
private static final String COURSE = "courses";
|
||||
private static final String SECTION = "sections";
|
||||
private static final String STUDENT = "students";
|
||||
private static final String URL = "http://192.168.0.106:3000/professors/56f5fd3a20047f3c15b05f0e";
|
||||
String URL;
|
||||
private static final String TAG_ID = "_id";
|
||||
private static final String TAG_NO = "id";
|
||||
private static final String TAG_NAME = "name";
|
||||
@@ -58,12 +66,55 @@ public class StudentActivity extends ListActivity {
|
||||
TransmitterTask transmitterTask;
|
||||
ArrayAdapter<String> btArrayAdapter;
|
||||
int assist = 0;
|
||||
boolean flag = false;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.student_activity);
|
||||
|
||||
Intent i = getIntent();
|
||||
URL = FileReader.getUrl(getApplicationContext());
|
||||
ListView lv = getListView();
|
||||
|
||||
lv.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view,
|
||||
int position, long rowId) {
|
||||
AlertDialog.Builder adb = new AlertDialog.Builder(
|
||||
StudentActivity.this);
|
||||
HashMap<String,String> map =(HashMap<String,String>) parent.getItemAtPosition(position);
|
||||
String name = map.get("name");
|
||||
String lastname = map.get("lastname");
|
||||
final int index = Integer.parseInt(map.get("_id"));
|
||||
adb.setTitle("Asistencia Manual");
|
||||
adb.setMessage("¿Desea poner manualmente la asistencia del alumno "+lastname+", "+name+" ?"
|
||||
);
|
||||
adb.setPositiveButton("Si", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
try {
|
||||
JSONObject st = students.getJSONObject(index);
|
||||
JSONArray assistance = st.getJSONArray("assistanceTotal");
|
||||
assist = st.optInt("assistance");
|
||||
st.put("assistance", assist+1);
|
||||
JSONObject dayAssistance = new JSONObject();
|
||||
dayAssistance.put("day", currentDate);
|
||||
dayAssistance.put("assistance", true);
|
||||
assistance.put(dayAssistance);
|
||||
TextView t = (TextView) findViewById(R.id.student_name);
|
||||
t.setTextColor(Color.GREEN);
|
||||
TextView z = (TextView) findViewById(R.id.student_lastname);
|
||||
z.setTextColor(Color.GREEN);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
adb.setNegativeButton("No", null);
|
||||
adb.show();
|
||||
}
|
||||
});
|
||||
|
||||
stateBluetooth = (TextView)findViewById(R.id.bluetoothstate);
|
||||
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
@@ -176,9 +227,24 @@ public class StudentActivity extends ListActivity {
|
||||
StudentActivity.this, studentList,
|
||||
R.layout.list_item_students, new String[]{"section_id", TAG_ID, TAG_NO,
|
||||
TAG_NAME, TAG_LASTNAME}, new int[]{
|
||||
R.id.section_id, R.id.student_id, R.id.student_no, R.id.student_name, R.id.student_lastname});
|
||||
setListAdapter(adapter);
|
||||
R.id.section_id, R.id.student_id, R.id.student_no, R.id.student_name, R.id.student_lastname})
|
||||
/* {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
// Get the Item from ListView
|
||||
View view = super.getView(position, convertView, parent);
|
||||
|
||||
// Initialize a TextView for ListView each Item
|
||||
TextView tv = (TextView) view.findViewById(android.R.id.text1);
|
||||
|
||||
// Set the text color of TextView (ListView Item)
|
||||
tv.setTextColor(Color.RED);
|
||||
|
||||
// Generate ListView Item using TextView
|
||||
return view;
|
||||
}
|
||||
}*/;
|
||||
setListAdapter(adapter);
|
||||
setTitle(section_name);
|
||||
}
|
||||
});
|
||||
@@ -187,19 +253,19 @@ public class StudentActivity extends ListActivity {
|
||||
|
||||
private void CheckBlueToothState(){
|
||||
if (bluetoothAdapter == null){
|
||||
stateBluetooth.setText("Bluetooth NOT supported");
|
||||
stateBluetooth.setText("Bluetooth NO soportado");
|
||||
}else{
|
||||
if (bluetoothAdapter.isEnabled()){
|
||||
if(bluetoothAdapter.isDiscovering()){
|
||||
stateBluetooth.setText("Bluetooth is currently in device discovery process.");
|
||||
stateBluetooth.setText("Bluetooth esta en modo de Descubrimiento.");
|
||||
btnScanDevice.setEnabled(false);
|
||||
|
||||
}else{
|
||||
stateBluetooth.setText("Bluetooth is Enabled.");
|
||||
stateBluetooth.setText("Bluetooth esta Activado.");
|
||||
btnScanDevice.setEnabled(true);
|
||||
}
|
||||
}else{
|
||||
stateBluetooth.setText("Bluetooth is NOT Enabled!");
|
||||
stateBluetooth.setText("Bluetooth NO esta Activado!!");
|
||||
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
|
||||
}
|
||||
@@ -212,6 +278,7 @@ public class StudentActivity extends ListActivity {
|
||||
public void onClick(View arg0) {
|
||||
btArrayAdapter.clear();
|
||||
bluetoothAdapter.startDiscovery();
|
||||
CheckBlueToothState();
|
||||
}};
|
||||
|
||||
private Button.OnClickListener btnEndClassOnClickListener
|
||||
@@ -219,6 +286,7 @@ public class StudentActivity extends ListActivity {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
if (flag) {
|
||||
try {
|
||||
for (int x = 0; x < students.length(); x++) {
|
||||
JSONObject st;
|
||||
@@ -228,30 +296,40 @@ public class StudentActivity extends ListActivity {
|
||||
assistance = st.getJSONArray("assistanceTotal");
|
||||
assert assistance != null;
|
||||
currentDate = SDF.format(new Date());
|
||||
for(int g=0; g<assistance.length(); g++) {
|
||||
for (int g = 0; g < assistance.length(); g++) {
|
||||
JSONObject cons = assistance.getJSONObject(g);
|
||||
String consDay = cons.getString("day");
|
||||
if (consDay.equals(currentDate)){
|
||||
if (consDay.equals(currentDate)) {
|
||||
scanned = true;
|
||||
}
|
||||
}
|
||||
if(!scanned){
|
||||
if (!scanned) {
|
||||
assist = st.optInt("assistance");
|
||||
st.put("assistance", assist+1);
|
||||
st.put("assistance", assist + 1);
|
||||
JSONObject dayAssistance = new JSONObject();
|
||||
dayAssistance.put("day", currentDate);
|
||||
dayAssistance.put("assistance", false);
|
||||
assistance.put(dayAssistance);
|
||||
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
transmitterTask = new TransmitterTask();
|
||||
transmitterTask = new TransmitterTask(URL);
|
||||
transmitterTask.execute(professor);
|
||||
finish();
|
||||
}};
|
||||
} else {
|
||||
AlertDialog.Builder adb = new AlertDialog.Builder(
|
||||
StudentActivity.this);
|
||||
adb.setTitle("Culminación de Escaneo");
|
||||
adb.setMessage("Recuerde que debe escanear al menos una vez a los alumnos");
|
||||
adb.setPositiveButton("OK", null);
|
||||
adb.show();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
@@ -264,6 +342,7 @@ public class StudentActivity extends ListActivity {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
flag = true;
|
||||
if(BluetoothDevice.ACTION_FOUND.equals(action)) {
|
||||
boolean scanned = false;
|
||||
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
@@ -304,6 +383,10 @@ public class StudentActivity extends ListActivity {
|
||||
dayAssistance.put("day", currentDate);
|
||||
dayAssistance.put("assistance", true);
|
||||
assistance.put(dayAssistance);
|
||||
TextView t = (TextView) findViewById(R.id.student_name);
|
||||
t.setTextColor(Color.GREEN);
|
||||
TextView z = (TextView) findViewById(R.id.student_lastname);
|
||||
z.setTextColor(Color.GREEN);
|
||||
}
|
||||
}catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@@ -342,6 +425,10 @@ public class StudentActivity extends ListActivity {
|
||||
dayAssistance.put("day", currentDate);
|
||||
dayAssistance.put("assistance", true);
|
||||
assistance.put(dayAssistance);
|
||||
TextView t = (TextView) findViewById(R.id.student_name);
|
||||
t.setTextColor(Color.GREEN);
|
||||
TextView z = (TextView) findViewById(R.id.student_lastname);
|
||||
z.setTextColor(Color.GREEN);
|
||||
}
|
||||
}catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@@ -350,6 +437,7 @@ public class StudentActivity extends ListActivity {
|
||||
}
|
||||
}
|
||||
btArrayAdapter.add(device.getName() + "\n" + device.getAddress());
|
||||
CheckBlueToothState();
|
||||
btArrayAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,20 @@
|
||||
android:orientation="vertical"
|
||||
android:background="#ffffff">
|
||||
|
||||
<TextView
|
||||
android:text="@string/course_intro"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:id="@+id/textView" />
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:divider="#b5b5b5"
|
||||
android:dividerHeight="1dp"
|
||||
android:background="#f5f5dc"
|
||||
android:cacheColorHint="#00000000"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -5,12 +5,20 @@
|
||||
android:orientation="vertical"
|
||||
android:background="#ffffff">
|
||||
|
||||
<TextView
|
||||
android:text="@string/section_intro"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:id="@+id/textView" />
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:divider="#b5b5b5"
|
||||
android:dividerHeight="1dp"
|
||||
android:background="#f5f5dc"
|
||||
android:cacheColorHint="#00000000"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -5,10 +5,18 @@
|
||||
android:orientation="vertical"
|
||||
android:background="#ffffff">
|
||||
|
||||
<TextView
|
||||
android:text="@string/student_intro"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:id="@+id/textView" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/bluetoothstate"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
/>
|
||||
|
||||
<Button
|
||||
@@ -24,12 +32,6 @@
|
||||
android:text="@string/terminate"
|
||||
/>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/devicesfound"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
/>
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
@@ -39,4 +41,10 @@
|
||||
android:cacheColorHint="#00000000"
|
||||
/>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/devicesfound"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -34,5 +34,8 @@
|
||||
<string name="title_section_activity">Secciones</string>
|
||||
<string name="title_student_activity">Estudiantes</string>
|
||||
<string name="terminate">Culminar Clase</string>
|
||||
<string name="course_intro"> \n Bienvenido \n Lista de Materias Disponibles\n</string>
|
||||
<string name="section_intro"> \n Lista de Secciones Disponibles\n</string>
|
||||
<string name="student_intro"> \n Lista de Estudiantes de la Sección\n Recuerde que debe Escanear los dispositivos al menos una vez. \n</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -4,5 +4,4 @@
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user