Update views for technical debt

This commit is contained in:
Reynaldo Reyes
2016-04-28 07:46:52 -04:30
parent 7c08da98e2
commit 3518ab1af7
11 changed files with 179 additions and 71 deletions

View File

@@ -4,7 +4,7 @@
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application <application
android:allowBackup="true" android:allowBackup="true"

View File

@@ -17,6 +17,8 @@ import android.widget.ListAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.SimpleAdapter; import android.widget.SimpleAdapter;
import android.widget.TextView; import android.widget.TextView;
import massiveattendancescannerapplication.Services.FileReader;
import massiveattendancescannerapplication.Services.ServiceHandler; import massiveattendancescannerapplication.Services.ServiceHandler;
public class CourseActivity extends ListActivity { public class CourseActivity extends ListActivity {
@@ -27,7 +29,7 @@ public class CourseActivity extends ListActivity {
JSONObject professor; JSONObject professor;
String JSONString; String JSONString;
private static final String COURSE = "courses"; 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_ID = "_id";
private static final String TAG_NAME = "name"; private static final String TAG_NAME = "name";
private static final String TAG_CODE = "code"; private static final String TAG_CODE = "code";
@@ -38,7 +40,7 @@ public class CourseActivity extends ListActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.course_activity); setContentView(R.layout.course_activity);
URL = FileReader.getUrl(getApplicationContext());
courseList = new ArrayList<>(); courseList = new ArrayList<>();
new LoadCourses().execute(); new LoadCourses().execute();

View File

@@ -17,6 +17,8 @@ import android.widget.ListAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.SimpleAdapter; import android.widget.SimpleAdapter;
import android.widget.TextView; import android.widget.TextView;
import massiveattendancescannerapplication.Services.FileReader;
import massiveattendancescannerapplication.Services.ServiceHandler; import massiveattendancescannerapplication.Services.ServiceHandler;
public class SectionActivity extends ListActivity { public class SectionActivity extends ListActivity {
@@ -28,7 +30,7 @@ public class SectionActivity extends ListActivity {
String JSONString, course_id, course_name; String JSONString, course_id, course_name;
private static final String COURSE = "courses"; private static final String COURSE = "courses";
private static final String SECTION = "sections"; 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_ID = "_id";
private static final String TAG_NAME = "name"; private static final String TAG_NAME = "name";
private static final String TAG_SEMESTER = "semester"; private static final String TAG_SEMESTER = "semester";
@@ -40,6 +42,7 @@ public class SectionActivity extends ListActivity {
setContentView(R.layout.section_activity); setContentView(R.layout.section_activity);
Intent i = getIntent(); Intent i = getIntent();
URL = FileReader.getUrl(getApplicationContext());
course_id = i.getStringExtra("course_id"); course_id = i.getStringExtra("course_id");
sectionList = new ArrayList<HashMap<String, String>>(); sectionList = new ArrayList<HashMap<String, String>>();
new LoadSections().execute(); new LoadSections().execute();

View File

@@ -19,22 +19,18 @@ import java.io.IOException;
public class FileReader { public class FileReader {
static String response; static String response;
private static final String professors = "professors.txt"; private static final String url = "url.txt";
private static final String courses = "courses.txt";
private static final String sections = "sections.txt";
private static final String students = "students.txt";
/** /**
* <p> * <p>
* This function returns the URL direction parsed from the .txt file contained in the phone. * This function returns the URL direction parsed from the .txt file contained in the phone.
* </p> * </p>
* @param context Application Context. * @param context Application Context.
* @param method Method representing POST of GET methods.
* @return String containing the URL. * @return String containing the URL.
*/ */
public static String getUrl(Context context, int method) { public static String getUrl(Context context) {
try { try {
return parse(getConfigFile(context,method)); return parse(getConfigFile(context));
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@@ -48,25 +44,18 @@ public class FileReader {
* direction for each type. * direction for each type.
* </p> * </p>
* @param context Application Context. * @param context Application Context.
* @param method Method representing POST of GET methods.
* @return BufferedReader containing the information inside the file. * @return BufferedReader containing the information inside the file.
*/ */
private static BufferedReader getConfigFile(Context context,int method) { private static BufferedReader getConfigFile(Context context) {
if(isExternalStorageReadable()){ if(isExternalStorageReadable()){
// Get the directory for the app's private files // 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 { try {
if(method == 1) file = new File(context.getExternalFilesDir(null), professors); file = new File(mFolder.getAbsolutePath(), url);
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) {
java.io.FileReader fr = new java.io.FileReader(file); java.io.FileReader fr = new java.io.FileReader(file);
return new BufferedReader(fr); return new BufferedReader(fr);
}else{
return null;
}
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block

View File

@@ -19,12 +19,12 @@ import android.os.Handler;
public class TransmitterTask extends AsyncTask<JSONObject, Void, Void> { 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; boolean result;
final Handler myHandler = new Handler(); final Handler myHandler = new Handler();
public TransmitterTask() { public TransmitterTask(String URL) {
this.URL = URL;
} }
protected Void doInBackground(JSONObject... professor) { protected Void doInBackground(JSONObject... professor) {

View File

@@ -9,17 +9,24 @@ import java.util.HashMap;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import android.app.AlertDialog;
import android.app.ListActivity; import android.app.ListActivity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.database.Cursor;
import android.graphics.Color;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.ListAdapter; import android.widget.ListAdapter;
@@ -28,6 +35,7 @@ import android.widget.SimpleAdapter;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import massiveattendancescannerapplication.Services.FileReader;
import massiveattendancescannerapplication.Services.ServiceHandler; import massiveattendancescannerapplication.Services.ServiceHandler;
import massiveattendancescannerapplication.Services.TransmitterTask; import massiveattendancescannerapplication.Services.TransmitterTask;
@@ -42,7 +50,7 @@ public class StudentActivity extends ListActivity {
private static final String COURSE = "courses"; private static final String COURSE = "courses";
private static final String SECTION = "sections"; private static final String SECTION = "sections";
private static final String STUDENT = "students"; 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_ID = "_id";
private static final String TAG_NO = "id"; private static final String TAG_NO = "id";
private static final String TAG_NAME = "name"; private static final String TAG_NAME = "name";
@@ -58,12 +66,55 @@ public class StudentActivity extends ListActivity {
TransmitterTask transmitterTask; TransmitterTask transmitterTask;
ArrayAdapter<String> btArrayAdapter; ArrayAdapter<String> btArrayAdapter;
int assist = 0; int assist = 0;
boolean flag = false;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.student_activity); setContentView(R.layout.student_activity);
Intent i = getIntent(); 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); stateBluetooth = (TextView)findViewById(R.id.bluetoothstate);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
@@ -176,9 +227,24 @@ public class StudentActivity extends ListActivity {
StudentActivity.this, studentList, StudentActivity.this, studentList,
R.layout.list_item_students, new String[]{"section_id", TAG_ID, TAG_NO, R.layout.list_item_students, new String[]{"section_id", TAG_ID, TAG_NO,
TAG_NAME, TAG_LASTNAME}, new int[]{ 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}); R.id.section_id, R.id.student_id, R.id.student_no, R.id.student_name, R.id.student_lastname})
setListAdapter(adapter); /* {
@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); setTitle(section_name);
} }
}); });
@@ -187,19 +253,19 @@ public class StudentActivity extends ListActivity {
private void CheckBlueToothState(){ private void CheckBlueToothState(){
if (bluetoothAdapter == null){ if (bluetoothAdapter == null){
stateBluetooth.setText("Bluetooth NOT supported"); stateBluetooth.setText("Bluetooth NO soportado");
}else{ }else{
if (bluetoothAdapter.isEnabled()){ if (bluetoothAdapter.isEnabled()){
if(bluetoothAdapter.isDiscovering()){ if(bluetoothAdapter.isDiscovering()){
stateBluetooth.setText("Bluetooth is currently in device discovery process."); stateBluetooth.setText("Bluetooth esta en modo de Descubrimiento.");
btnScanDevice.setEnabled(false); btnScanDevice.setEnabled(false);
}else{ }else{
stateBluetooth.setText("Bluetooth is Enabled."); stateBluetooth.setText("Bluetooth esta Activado.");
btnScanDevice.setEnabled(true); btnScanDevice.setEnabled(true);
} }
}else{ }else{
stateBluetooth.setText("Bluetooth is NOT Enabled!"); stateBluetooth.setText("Bluetooth NO esta Activado!!");
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
} }
@@ -212,6 +278,7 @@ public class StudentActivity extends ListActivity {
public void onClick(View arg0) { public void onClick(View arg0) {
btArrayAdapter.clear(); btArrayAdapter.clear();
bluetoothAdapter.startDiscovery(); bluetoothAdapter.startDiscovery();
CheckBlueToothState();
}}; }};
private Button.OnClickListener btnEndClassOnClickListener private Button.OnClickListener btnEndClassOnClickListener
@@ -219,6 +286,7 @@ public class StudentActivity extends ListActivity {
@Override @Override
public void onClick(View arg0) { public void onClick(View arg0) {
if (flag) {
try { try {
for (int x = 0; x < students.length(); x++) { for (int x = 0; x < students.length(); x++) {
JSONObject st; JSONObject st;
@@ -242,16 +310,26 @@ public class StudentActivity extends ListActivity {
dayAssistance.put("day", currentDate); dayAssistance.put("day", currentDate);
dayAssistance.put("assistance", false); dayAssistance.put("assistance", false);
assistance.put(dayAssistance); assistance.put(dayAssistance);
} }
} }
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
transmitterTask = new TransmitterTask(); transmitterTask = new TransmitterTask(URL);
transmitterTask.execute(professor); transmitterTask.execute(professor);
finish(); 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 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@@ -264,6 +342,7 @@ public class StudentActivity extends ListActivity {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String action = intent.getAction(); String action = intent.getAction();
flag = true;
if(BluetoothDevice.ACTION_FOUND.equals(action)) { if(BluetoothDevice.ACTION_FOUND.equals(action)) {
boolean scanned = false; boolean scanned = false;
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
@@ -304,6 +383,10 @@ public class StudentActivity extends ListActivity {
dayAssistance.put("day", currentDate); dayAssistance.put("day", currentDate);
dayAssistance.put("assistance", true); dayAssistance.put("assistance", true);
assistance.put(dayAssistance); 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) { }catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
@@ -342,6 +425,10 @@ public class StudentActivity extends ListActivity {
dayAssistance.put("day", currentDate); dayAssistance.put("day", currentDate);
dayAssistance.put("assistance", true); dayAssistance.put("assistance", true);
assistance.put(dayAssistance); 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) { }catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
@@ -350,6 +437,7 @@ public class StudentActivity extends ListActivity {
} }
} }
btArrayAdapter.add(device.getName() + "\n" + device.getAddress()); btArrayAdapter.add(device.getName() + "\n" + device.getAddress());
CheckBlueToothState();
btArrayAdapter.notifyDataSetChanged(); btArrayAdapter.notifyDataSetChanged();
} }
} }

View File

@@ -5,12 +5,20 @@
android:orientation="vertical" android:orientation="vertical"
android:background="#ffffff"> 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 <ListView
android:id="@android:id/list" android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:divider="#b5b5b5" android:divider="#b5b5b5"
android:dividerHeight="1dp" android:dividerHeight="1dp"
android:background="#f5f5dc"
android:cacheColorHint="#00000000"/> android:cacheColorHint="#00000000"/>
</LinearLayout> </LinearLayout>

View File

@@ -5,12 +5,20 @@
android:orientation="vertical" android:orientation="vertical"
android:background="#ffffff"> 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 <ListView
android:id="@android:id/list" android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:divider="#b5b5b5" android:divider="#b5b5b5"
android:dividerHeight="1dp" android:dividerHeight="1dp"
android:background="#f5f5dc"
android:cacheColorHint="#00000000"/> android:cacheColorHint="#00000000"/>
</LinearLayout> </LinearLayout>

View File

@@ -5,10 +5,18 @@
android:orientation="vertical" android:orientation="vertical"
android:background="#ffffff"> 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 <TextView
android:id="@+id/bluetoothstate" android:id="@+id/bluetoothstate"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center"
/> />
<Button <Button
@@ -24,12 +32,6 @@
android:text="@string/terminate" android:text="@string/terminate"
/> />
<ListView
android:id="@+id/devicesfound"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<ListView <ListView
android:id="@android:id/list" android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_width="fill_parent"
@@ -39,4 +41,10 @@
android:cacheColorHint="#00000000" android:cacheColorHint="#00000000"
/> />
<ListView
android:id="@+id/devicesfound"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout> </LinearLayout>

View File

@@ -34,5 +34,8 @@
<string name="title_section_activity">Secciones</string> <string name="title_section_activity">Secciones</string>
<string name="title_student_activity">Estudiantes</string> <string name="title_student_activity">Estudiantes</string>
<string name="terminate">Culminar Clase</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> </resources>

View File

@@ -4,5 +4,4 @@
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
</style> </style>
</resources> </resources>