Create M.A.S.A. Mobile version 1.0
This commit is contained in:
@@ -64,13 +64,11 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/.git" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
||||
|
@@ -23,12 +23,16 @@ public class CourseActivity extends ListActivity {
|
||||
|
||||
private ProgressDialog pDialog;
|
||||
ArrayList<HashMap<String, String>> courseList;
|
||||
JSONArray course = null;
|
||||
private static final String URL = "http://192.168.0.101:3000/courses";
|
||||
JSONArray courses;
|
||||
JSONObject professor;
|
||||
String JSONString;
|
||||
private static final String COURSE = "courses";
|
||||
private static final String URL = "http://192.168.0.106:3000/professors/56f5fd3a20047f3c15b05f0e";
|
||||
private static final String TAG_ID = "_id";
|
||||
private static final String TAG_NAME = "name";
|
||||
private static final String TAG_CODE = "code";
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -66,7 +70,6 @@ public class CourseActivity extends ListActivity {
|
||||
protected String doInBackground(String... args) {
|
||||
|
||||
ServiceHandler sh = new ServiceHandler();
|
||||
String JSONString = null;
|
||||
try {
|
||||
JSONString = sh.getServiceCall(URL);
|
||||
} catch (IOException e) {
|
||||
@@ -74,20 +77,20 @@ public class CourseActivity extends ListActivity {
|
||||
}
|
||||
|
||||
try {
|
||||
course = new JSONArray(JSONString);
|
||||
|
||||
for (int i = 0; i < course.length(); i++) {
|
||||
JSONObject c = course.getJSONObject(i);
|
||||
String id = c.getString(TAG_ID);
|
||||
String name = c.getString(TAG_NAME);
|
||||
String code = c.getString(TAG_CODE);
|
||||
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put(TAG_ID, id);
|
||||
map.put(TAG_NAME, name);
|
||||
map.put(TAG_CODE, code);
|
||||
|
||||
courseList.add(map);
|
||||
professor = new JSONObject(JSONString);
|
||||
if (professor.has(COURSE)) {
|
||||
courses = professor.getJSONArray(COURSE);
|
||||
for (int i = 0; i < courses.length(); i++) {
|
||||
JSONObject c = courses.getJSONObject(i);
|
||||
String id = c.getString(TAG_ID);
|
||||
String name = c.getString(TAG_NAME);
|
||||
String code = c.getString(TAG_CODE);
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put(TAG_ID, id);
|
||||
map.put(TAG_NAME, name);
|
||||
map.put(TAG_CODE, code);
|
||||
courseList.add(map);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
@@ -6,13 +6,9 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.content.Intent;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
|
||||
|
||||
public class MainActivity extends ActionBarActivity {
|
||||
|
||||
public static final int REQUEST_ENABLE_BT = 1;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -38,23 +34,8 @@ public class MainActivity extends ActionBarActivity {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
//Called when the user clicks on Scan
|
||||
public void scanPhones (View view) {
|
||||
|
||||
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (mBluetoothAdapter == null) {
|
||||
// Device does not support Bluetooth
|
||||
}
|
||||
|
||||
if (!mBluetoothAdapter.isEnabled()) {
|
||||
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
|
||||
}
|
||||
Intent intent = new Intent(this, ScanActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
//Called when the user clicks on Listar Materias
|
||||
public void adminScreen (View view) {
|
||||
public void courseScreen (View view) {
|
||||
Intent intent = new Intent(this, CourseActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
@@ -23,8 +23,12 @@ public class SectionActivity extends ListActivity {
|
||||
|
||||
private ProgressDialog pDialog;
|
||||
ArrayList<HashMap<String, String>> sectionList;
|
||||
String course_id, course_name;
|
||||
private static final String URL = "http://192.168.0.101:3000/sections";
|
||||
JSONArray courses,sections;
|
||||
JSONObject professor;
|
||||
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";
|
||||
private static final String TAG_ID = "_id";
|
||||
private static final String TAG_NAME = "name";
|
||||
private static final String TAG_SEMESTER = "semester";
|
||||
@@ -72,7 +76,6 @@ public class SectionActivity extends ListActivity {
|
||||
|
||||
protected String doInBackground(String... args) {
|
||||
ServiceHandler sh = new ServiceHandler();
|
||||
String JSONString = null;
|
||||
try {
|
||||
JSONString = sh.getServiceCall(URL);
|
||||
} catch (IOException e) {
|
||||
@@ -80,29 +83,40 @@ public class SectionActivity extends ListActivity {
|
||||
}
|
||||
|
||||
try {
|
||||
JSONArray sections = new JSONArray(JSONString);
|
||||
for (int i = 0; i < sections.length(); i++) {
|
||||
JSONObject c = sections.getJSONObject(i);
|
||||
professor = new JSONObject(JSONString);
|
||||
if (professor.has(COURSE)) {
|
||||
courses = professor.getJSONArray(COURSE);
|
||||
for (int i = 0; i < courses.length(); i++) {
|
||||
JSONObject c = courses.getJSONObject(i);
|
||||
String course = c.getString(TAG_ID);
|
||||
assert course != null;
|
||||
if (course.equals(course_id)){
|
||||
if (c.has(SECTION)){
|
||||
sections = c.getJSONArray(SECTION);
|
||||
for (int j = 0; j < sections.length(); j++) {
|
||||
JSONObject s = sections.getJSONObject(j);
|
||||
|
||||
String section_id = c.getString(TAG_ID);
|
||||
String section_no = String.valueOf(i + 1);
|
||||
String name = c.getString(TAG_NAME);
|
||||
String semester = c.getString(TAG_SEMESTER);
|
||||
String section_id = s.getString(TAG_ID);
|
||||
String section_no = String.valueOf(j + 1);
|
||||
String name = s.getString(TAG_NAME);
|
||||
String semester = s.getString(TAG_SEMESTER);
|
||||
|
||||
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("course_id", course_id);
|
||||
map.put(TAG_ID, section_id);
|
||||
map.put("section_no", section_no + ".");
|
||||
map.put(TAG_NAME, name);
|
||||
map.put(TAG_SEMESTER, semester);
|
||||
|
||||
sectionList.add(map);
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("course_id", course_id);
|
||||
map.put(TAG_ID, section_id);
|
||||
map.put("section_no", section_no + ".");
|
||||
map.put(TAG_NAME, name);
|
||||
map.put(TAG_SEMESTER, semester);
|
||||
sectionList.add(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -110,7 +124,6 @@ public class SectionActivity extends ListActivity {
|
||||
pDialog.dismiss();
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
|
||||
ListAdapter adapter = new SimpleAdapter(
|
||||
SectionActivity.this, sectionList,
|
||||
R.layout.list_item_sections, new String[] { "course_id", TAG_ID, "track_no",
|
||||
|
@@ -5,9 +5,10 @@ import android.util.Log;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@@ -70,31 +71,25 @@ public class ServiceHandler {
|
||||
* @author Reynaldo
|
||||
*/
|
||||
|
||||
public boolean postServiceCall(String url, JSONArray jsonArray) throws IOException {
|
||||
public boolean postServiceCall(String url, JSONObject jsonobject) throws IOException {
|
||||
int inputStream;
|
||||
response="";
|
||||
try {
|
||||
HttpClient httpclient = new DefaultHttpClient();
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
|
||||
String json = jsonArray.toString();
|
||||
StringEntity se = new StringEntity(json);
|
||||
httpPost.setEntity(se);
|
||||
httpPost.setHeader("Accept", "application/json");
|
||||
httpPost.setHeader("Content-type", "application/json");
|
||||
HttpResponse httpResponse = httpclient.execute(httpPost);
|
||||
inputStream = httpResponse.getStatusLine().getStatusCode();
|
||||
if (inputStream == 200){
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
HttpClient httpclient = new DefaultHttpClient();
|
||||
HttpPut httpPut = new HttpPut(url);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.d("InputStream", e.getLocalizedMessage());
|
||||
String json = jsonobject.toString();
|
||||
StringEntity se = new StringEntity(json);
|
||||
httpPut.setEntity(se);
|
||||
httpPut.setHeader("Accept", "application/json");
|
||||
httpPut.setHeader("Content-type", "application/json");
|
||||
HttpResponse httpResponse = httpclient.execute(httpPut);
|
||||
inputStream = httpResponse.getStatusLine().getStatusCode();
|
||||
if (inputStream == 200){
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String convertInputStreamToString(InputStream inputStream) throws IOException{
|
||||
|
@@ -0,0 +1,45 @@
|
||||
package massiveattendancescannerapplication.Services;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This is an AsyncTask that handles the construction of the Answer object and the AnswerArray
|
||||
* which is the JSON object containing a JSON array of JSON objects. After the final JSON object
|
||||
* is created this function invokes the POST method to send the information o the corresponding
|
||||
* service.
|
||||
* </p>
|
||||
*
|
||||
* @author Reynaldo
|
||||
*/
|
||||
|
||||
public class TransmitterTask extends AsyncTask<JSONObject, Void, Void> {
|
||||
|
||||
private static final String URL = "http://192.168.0.106:3000/professors/56f5fd3a20047f3c15b05f0e";
|
||||
boolean result;
|
||||
|
||||
final Handler myHandler = new Handler();
|
||||
public TransmitterTask() {
|
||||
|
||||
}
|
||||
|
||||
protected Void doInBackground(JSONObject... professor) {
|
||||
|
||||
while (true){
|
||||
ServiceHandler pt = new ServiceHandler();
|
||||
try{
|
||||
result = pt.postServiceCall(URL,professor[0]);
|
||||
if(result){
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -1,45 +1,100 @@
|
||||
package massiveattendancescannerapplication;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
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.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SimpleAdapter;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import massiveattendancescannerapplication.Services.ServiceHandler;
|
||||
import massiveattendancescannerapplication.Services.TransmitterTask;
|
||||
|
||||
|
||||
public class StudentActivity extends ListActivity {
|
||||
|
||||
private ProgressDialog pDialog;
|
||||
ArrayList<HashMap<String, String>> studentList;
|
||||
private static final String URL = "http://192.168.0.101:3000/sections";
|
||||
JSONArray courses,sections,students;
|
||||
JSONObject professor;
|
||||
String course_id, section_name, section_id, currentDate;
|
||||
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";
|
||||
private static final String TAG_ID = "_id";
|
||||
private static final String TAG_NO = "id";
|
||||
private static final String TAG_NAME = "name";
|
||||
private static final String TAG_LASTNAME = "lastname";
|
||||
private static final String TAG_STUDENTS = "students";
|
||||
JSONArray students = null;
|
||||
String section_id = null;
|
||||
String section_name = null;
|
||||
private static final String BT_ADDRESS = "btaddress";
|
||||
private static final int REQUEST_ENABLE_BT = 1;
|
||||
SimpleDateFormat SDF = new SimpleDateFormat("dd/MM/yyyy");
|
||||
TextView stateBluetooth;
|
||||
BluetoothAdapter bluetoothAdapter;
|
||||
ListView listDevicesFound;
|
||||
Button btnScanDevice,btnEndClass;
|
||||
TransmitterTask transmitterTask;
|
||||
ArrayAdapter<String> btArrayAdapter;
|
||||
int assist = 0;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.student_activity);
|
||||
Intent i = getIntent();
|
||||
|
||||
stateBluetooth = (TextView)findViewById(R.id.bluetoothstate);
|
||||
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
|
||||
listDevicesFound = (ListView)findViewById(R.id.devicesfound);
|
||||
btArrayAdapter = new ArrayAdapter<>(StudentActivity.this,
|
||||
android.R.layout.simple_list_item_1);
|
||||
listDevicesFound.setAdapter(btArrayAdapter);
|
||||
|
||||
btnScanDevice = (Button)findViewById(R.id.scandevice);
|
||||
btnScanDevice.setOnClickListener(btnScanDeviceOnClickListener);
|
||||
|
||||
btnEndClass = (Button)findViewById(R.id.terminate);
|
||||
btnEndClass.setOnClickListener(btnEndClassOnClickListener);
|
||||
|
||||
CheckBlueToothState();
|
||||
|
||||
registerReceiver(ActionFoundReceiver,
|
||||
new IntentFilter(BluetoothDevice.ACTION_FOUND));
|
||||
|
||||
course_id = i.getStringExtra("course_id");
|
||||
section_id = i.getStringExtra("section_id");
|
||||
studentList = new ArrayList<>();
|
||||
new LoadStudents().execute();
|
||||
ListView lv = getListView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
unregisterReceiver(ActionFoundReceiver);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
class LoadStudents extends AsyncTask<String, String, String> {
|
||||
@@ -67,49 +122,61 @@ public class StudentActivity extends ListActivity {
|
||||
}
|
||||
|
||||
try {
|
||||
JSONArray sections = new JSONArray(JSONString);
|
||||
|
||||
for (int i = 0; i < sections.length(); i++) {
|
||||
JSONObject c = sections.getJSONObject(i);
|
||||
String section = c.getString(TAG_ID);
|
||||
assert section != null;
|
||||
if (section.equals(section_id)){
|
||||
section_name = c.getString(TAG_NAME);
|
||||
students = c.getJSONArray(TAG_STUDENTS);
|
||||
for (int x = 0; x < students.length(); x++) {
|
||||
JSONObject s = students.getJSONObject(x);
|
||||
String student_id = String.valueOf(x + 1);
|
||||
String student_no = s.getString(TAG_NO);
|
||||
String name = s.getString(TAG_NAME);
|
||||
String lastname = s.getString(TAG_LASTNAME);
|
||||
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("student_id", student_id);
|
||||
map.put(TAG_ID, student_id);
|
||||
map.put("student_no", student_no);
|
||||
map.put(TAG_NAME, name);
|
||||
map.put(TAG_LASTNAME, lastname);
|
||||
|
||||
studentList.add(map);
|
||||
professor = new JSONObject(JSONString);
|
||||
if (professor.has(COURSE)) {
|
||||
courses = professor.getJSONArray(COURSE);
|
||||
for (int i = 0; i < courses.length(); i++) {
|
||||
JSONObject c = courses.getJSONObject(i);
|
||||
String course = c.getString(TAG_ID);
|
||||
assert course != null;
|
||||
if (course.equals(course_id)){
|
||||
if (c.has(SECTION)) {
|
||||
sections = c.getJSONArray(SECTION);
|
||||
for (int j = 0; j < sections.length(); j++) {
|
||||
JSONObject s = sections.getJSONObject(j);
|
||||
String section = s.getString(TAG_ID);
|
||||
assert section != null;
|
||||
if (section.equals(section_id)) {
|
||||
if(s.has(STUDENT)) {
|
||||
section_name = s.getString(TAG_NAME);
|
||||
students = s.getJSONArray(TAG_STUDENTS);
|
||||
for (int x = 0; x < students.length(); x++) {
|
||||
JSONObject st = students.getJSONObject(x);
|
||||
String student_id = String.valueOf(x + 1);
|
||||
String student_no = st.getString(TAG_NO);
|
||||
String name = st.getString(TAG_NAME);
|
||||
String lastname = st.getString(TAG_LASTNAME);
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("student_id", student_id);
|
||||
map.put(TAG_ID, student_id);
|
||||
map.put("student_no", student_no);
|
||||
map.put(TAG_NAME, name);
|
||||
map.put(TAG_LASTNAME, lastname);
|
||||
studentList.add(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void onPostExecute(String file_url) {
|
||||
|
||||
pDialog.dismiss();
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
ListAdapter adapter = new SimpleAdapter(
|
||||
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 });
|
||||
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);
|
||||
|
||||
setTitle(section_name);
|
||||
@@ -117,4 +184,174 @@ public class StudentActivity extends ListActivity {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckBlueToothState(){
|
||||
if (bluetoothAdapter == null){
|
||||
stateBluetooth.setText("Bluetooth NOT supported");
|
||||
}else{
|
||||
if (bluetoothAdapter.isEnabled()){
|
||||
if(bluetoothAdapter.isDiscovering()){
|
||||
stateBluetooth.setText("Bluetooth is currently in device discovery process.");
|
||||
btnScanDevice.setEnabled(false);
|
||||
|
||||
}else{
|
||||
stateBluetooth.setText("Bluetooth is Enabled.");
|
||||
btnScanDevice.setEnabled(true);
|
||||
}
|
||||
}else{
|
||||
stateBluetooth.setText("Bluetooth is NOT Enabled!");
|
||||
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Button.OnClickListener btnScanDeviceOnClickListener
|
||||
= new Button.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
btArrayAdapter.clear();
|
||||
bluetoothAdapter.startDiscovery();
|
||||
}};
|
||||
|
||||
private Button.OnClickListener btnEndClassOnClickListener
|
||||
= new Button.OnClickListener(){
|
||||
|
||||
@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<assistance.length(); g++) {
|
||||
JSONObject cons = assistance.getJSONObject(g);
|
||||
String consDay = cons.getString("day");
|
||||
if (consDay.equals(currentDate)){
|
||||
scanned = true;
|
||||
}
|
||||
}
|
||||
if(!scanned){
|
||||
assist = st.optInt("assistance");
|
||||
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.execute(professor);
|
||||
finish();
|
||||
}};
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if(requestCode == REQUEST_ENABLE_BT){
|
||||
CheckBlueToothState();
|
||||
}
|
||||
}
|
||||
|
||||
private final BroadcastReceiver ActionFoundReceiver = new BroadcastReceiver(){
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if(BluetoothDevice.ACTION_FOUND.equals(action)) {
|
||||
boolean scanned = false;
|
||||
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
String device_name = device.getName();
|
||||
String device_address = device.getAddress();
|
||||
for (int x = 0; x < students.length(); x++) {
|
||||
JSONObject st = null;
|
||||
try {
|
||||
st = students.getJSONObject(x);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String student_bt = null;
|
||||
try {
|
||||
assert st != null;
|
||||
student_bt = st.getString(BT_ADDRESS);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(student_bt != null) {
|
||||
if (student_bt.equals(device_address)) {
|
||||
Toast.makeText(getApplicationContext(), "FOUND DEVICE!", Toast.LENGTH_SHORT).show();
|
||||
try {
|
||||
JSONArray assistance;
|
||||
assistance = st.getJSONArray("assistanceTotal");
|
||||
currentDate = SDF.format(new Date());
|
||||
for(int g=0; g<assistance.length(); g++) {
|
||||
JSONObject cons = assistance.getJSONObject(g);
|
||||
String consDay = cons.getString("day");
|
||||
if (consDay.equals(currentDate)){
|
||||
scanned = true;
|
||||
}
|
||||
}
|
||||
if(!scanned){
|
||||
assist = st.optInt("assistance");
|
||||
st.put("assistance", assist+1);
|
||||
JSONObject dayAssistance = new JSONObject();
|
||||
dayAssistance.put("day", currentDate);
|
||||
dayAssistance.put("assistance", true);
|
||||
assistance.put(dayAssistance);
|
||||
}
|
||||
}catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}else {
|
||||
String student_no = null;
|
||||
try {
|
||||
student_no = st.getString(TAG_NO);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
assert student_no != null;
|
||||
if (device_name.equals(student_no)) {
|
||||
Toast.makeText(getApplicationContext(), "FOUND ID!", Toast.LENGTH_SHORT).show();
|
||||
try {
|
||||
st.put("btaddress",device_address);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
JSONArray assistance;
|
||||
assistance = st.getJSONArray("assistanceTotal");
|
||||
currentDate = SDF.format(new Date());
|
||||
for(int g=0; g<assistance.length(); g++) {
|
||||
JSONObject cons = assistance.getJSONObject(g);
|
||||
String consDay = cons.getString("day");
|
||||
if (consDay.equals(currentDate)){
|
||||
scanned = true;
|
||||
}
|
||||
}
|
||||
if(!scanned){
|
||||
assist = st.optInt("assistance");
|
||||
st.put("assistance", assist+1);
|
||||
JSONObject dayAssistance = new JSONObject();
|
||||
dayAssistance.put("day", currentDate);
|
||||
dayAssistance.put("assistance", true);
|
||||
assistance.put(dayAssistance);
|
||||
}
|
||||
}catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
btArrayAdapter.add(device.getName() + "\n" + device.getAddress());
|
||||
btArrayAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@
|
||||
android:text="@string/button_show_classes"
|
||||
android:id="@+id/button"
|
||||
android:layout_marginTop="50dp"
|
||||
android:onClick="adminScreen"
|
||||
android:onClick="courseScreen"
|
||||
android:layout_below="@+id/textView"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
|
@@ -16,9 +16,16 @@
|
||||
android:text="@string/scanning"
|
||||
android:enabled="false"
|
||||
/>
|
||||
<Button
|
||||
android:id="@+id/terminate"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/terminate"
|
||||
android:enabled="false"
|
||||
/>
|
||||
<ListView
|
||||
android:id="@+id/devicesfound"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
@@ -2,21 +2,21 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<!-- Album id / Hidden by default -->
|
||||
<!-- Section DB ID/ Hidden by default -->
|
||||
<TextView
|
||||
android:id="@+id/section_id"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone" />
|
||||
|
||||
<!-- Song id / Hidden by default -->
|
||||
<!-- Student DB ID/ Hidden by default -->
|
||||
<TextView
|
||||
android:id="@+id/student_id"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone" />
|
||||
|
||||
<!-- Track serial no -->
|
||||
<!-- Student ID number -->
|
||||
<TextView
|
||||
android:id="@+id/student_no"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -28,7 +28,7 @@
|
||||
android:textSize="16dip"
|
||||
android:layout_alignParentLeft="true"/>
|
||||
|
||||
<!-- Song Name -->
|
||||
<!-- Student Last Name -->
|
||||
<TextView
|
||||
android:id="@+id/student_lastname"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -36,11 +36,11 @@
|
||||
android:paddingBottom="15dip"
|
||||
android:paddingLeft="5dip"
|
||||
android:paddingTop="15dip"
|
||||
android:textColor="#000000"
|
||||
android:textColor="#ff0000"
|
||||
android:textSize="16dip"
|
||||
android:layout_toRightOf="@+id/student_no"/>
|
||||
|
||||
<!-- Song duration -->
|
||||
<!-- Student First Name -->
|
||||
<TextView
|
||||
android:id="@+id/student_name"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -48,7 +48,7 @@
|
||||
android:paddingBottom="15dip"
|
||||
android:paddingLeft="5dip"
|
||||
android:paddingTop="15dip"
|
||||
android:textColor="#000000"
|
||||
android:textColor="#ffff0000"
|
||||
android:textSize="16dip"
|
||||
android:layout_toRightOf="@+id/student_lastname"/>
|
||||
|
||||
|
@@ -5,12 +5,38 @@
|
||||
android:orientation="vertical"
|
||||
android:background="#ffffff">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/bluetoothstate"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/scandevice"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/scanning"
|
||||
/>
|
||||
<Button
|
||||
android:id="@+id/terminate"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
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"
|
||||
android:layout_height="wrap_content"
|
||||
android:divider="#b5b5b5"
|
||||
android:dividerHeight="1dp"
|
||||
android:cacheColorHint="#00000000"/>
|
||||
android:cacheColorHint="#00000000"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
@@ -6,7 +6,7 @@
|
||||
<string name="button_scan">Escanear</string>
|
||||
<string name="button_show_classes">Listar Materias</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="title_activity_scan">Escaneando...</string>
|
||||
<string name="title_activity_scan">Escaneando…</string>
|
||||
<string name="button_show_class">Mostrar Clases</string>
|
||||
<string name="button_add_class">Añadir Clases</string>
|
||||
<string name="button_rm_class">Eliminar Clases</string>
|
||||
@@ -33,5 +33,6 @@
|
||||
<string name="title_course_activity">Materias</string>
|
||||
<string name="title_section_activity">Secciones</string>
|
||||
<string name="title_student_activity">Estudiantes</string>
|
||||
<string name="terminate">Culminar Clase</string>
|
||||
|
||||
</resources>
|
||||
|
Reference in New Issue
Block a user