From 3518ab1af7ae5e08f28fab2de16373a7d2ebbf99 Mon Sep 17 00:00:00 2001 From: Reynaldo Reyes Date: Thu, 28 Apr 2016 07:46:52 -0430 Subject: [PATCH] Update views for technical debt --- app/src/main/AndroidManifest.xml | 2 +- .../CourseActivity.java | 6 +- .../SectionActivity.java | 5 +- .../Services/FileReader.java | 31 ++-- .../Services/TransmitterTask.java | 6 +- .../StudentActivity.java | 160 ++++++++++++++---- app/src/main/res/layout/course_activity.xml | 8 + app/src/main/res/layout/section_activity.xml | 8 + app/src/main/res/layout/student_activity.xml | 20 ++- app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/styles.xml | 1 - 11 files changed, 179 insertions(+), 71 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7d844b2..e4cacd5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,7 +4,7 @@ - + (); new LoadCourses().execute(); diff --git a/app/src/main/java/massiveattendancescannerapplication/SectionActivity.java b/app/src/main/java/massiveattendancescannerapplication/SectionActivity.java index e51864f..ee45a4e 100644 --- a/app/src/main/java/massiveattendancescannerapplication/SectionActivity.java +++ b/app/src/main/java/massiveattendancescannerapplication/SectionActivity.java @@ -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>(); new LoadSections().execute(); diff --git a/app/src/main/java/massiveattendancescannerapplication/Services/FileReader.java b/app/src/main/java/massiveattendancescannerapplication/Services/FileReader.java index 2a032f3..a7a440c 100644 --- a/app/src/main/java/massiveattendancescannerapplication/Services/FileReader.java +++ b/app/src/main/java/massiveattendancescannerapplication/Services/FileReader.java @@ -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"; /** *

* This function returns the URL direction parsed from the .txt file contained in the phone. *

* @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. *

* @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) { - java.io.FileReader fr = new java.io.FileReader(file); - return new BufferedReader(fr); - }else{ - return null; - } + file = new File(mFolder.getAbsolutePath(), url); + java.io.FileReader fr = new java.io.FileReader(file); + return new BufferedReader(fr); } catch (FileNotFoundException e) { // TODO Auto-generated catch block diff --git a/app/src/main/java/massiveattendancescannerapplication/Services/TransmitterTask.java b/app/src/main/java/massiveattendancescannerapplication/Services/TransmitterTask.java index 09cd35d..fc9518a 100644 --- a/app/src/main/java/massiveattendancescannerapplication/Services/TransmitterTask.java +++ b/app/src/main/java/massiveattendancescannerapplication/Services/TransmitterTask.java @@ -19,12 +19,12 @@ import android.os.Handler; public class TransmitterTask extends AsyncTask { - 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) { diff --git a/app/src/main/java/massiveattendancescannerapplication/StudentActivity.java b/app/src/main/java/massiveattendancescannerapplication/StudentActivity.java index eaa6346..f85a28d 100644 --- a/app/src/main/java/massiveattendancescannerapplication/StudentActivity.java +++ b/app/src/main/java/massiveattendancescannerapplication/StudentActivity.java @@ -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 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 map =(HashMap) 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,39 +286,50 @@ public class StudentActivity extends ListActivity { @Override public void onClick(View arg0) { - try { - for (int x = 0; x < students.length(); x++) { - JSONObject st; - boolean scanned = false; - st = students.getJSONObject(x); - JSONArray assistance; - assistance = st.getJSONArray("assistanceTotal"); - assert assistance != null; - currentDate = SDF.format(new Date()); - for(int g=0; g + + \ No newline at end of file diff --git a/app/src/main/res/layout/section_activity.xml b/app/src/main/res/layout/section_activity.xml index e8aeb97..cd9a82b 100644 --- a/app/src/main/res/layout/section_activity.xml +++ b/app/src/main/res/layout/section_activity.xml @@ -5,12 +5,20 @@ android:orientation="vertical" android:background="#ffffff"> + + \ No newline at end of file diff --git a/app/src/main/res/layout/student_activity.xml b/app/src/main/res/layout/student_activity.xml index a9e646c..5cea3f0 100644 --- a/app/src/main/res/layout/student_activity.xml +++ b/app/src/main/res/layout/student_activity.xml @@ -5,10 +5,18 @@ android:orientation="vertical" android:background="#ffffff"> + +