Android: revisión de la GUI en proceso. Refactorización de Device, PCBDHelper,…

Android: revisión de la GUI en proceso. Refactorización de Device, PCBDHelper, RESTApiWrapper y PCBcontext
parent b7aef735
...@@ -3,7 +3,6 @@ apply plugin: 'com.android.application' ...@@ -3,7 +3,6 @@ apply plugin: 'com.android.application'
android { android {
compileSdkVersion 21 compileSdkVersion 21
buildToolsVersion "21.1.2" buildToolsVersion "21.1.2"
defaultConfig { defaultConfig {
applicationId "com.yottacode.pictogrammar" applicationId "com.yottacode.pictogrammar"
minSdkVersion 19 minSdkVersion 19
...@@ -15,7 +14,7 @@ android { ...@@ -15,7 +14,7 @@ android {
release { release {
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", "server", "https://pre.yottacode.com:1337" resValue "string", "server", "https://pre.yottacode.com:1337"
resValue "string", "db_name", "PCB.db" resValue "string", "db_name", "PCB.db"
resValue "bool", "force_db_create", "false" resValue "bool", "force_db_create", "false"
resValue "bool", "ssl_connect", "false" resValue "bool", "ssl_connect", "false"
...@@ -25,7 +24,7 @@ android { ...@@ -25,7 +24,7 @@ android {
resValue "integer", "columns", "10" resValue "integer", "columns", "10"
} }
debug { debug {
resValue "string", "server", "https://pre.yottacode.com:1337"
resValue "string", "db_name", "PCB.db" resValue "string", "db_name", "PCB.db"
resValue "bool", "force_db_create", "false" resValue "bool", "force_db_create", "false"
resValue "bool", "ssl_connect", "false" resValue "bool", "ssl_connect", "false"
...@@ -35,11 +34,18 @@ android { ...@@ -35,11 +34,18 @@ android {
resValue "integer", "columns", "10" resValue "integer", "columns", "10"
} }
} }
productFlavors {
FernandoFlavor {
resValue "string", "server", "https://127.0.0.1:9944"
}
DefaultFlavor {
resValue "string", "server", "https://pre.yottacode.com:1337"
}
}
} }
dependencies { dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs') compile fileTree(dir: 'libs', include: ['*.jar'])
//compile fileTree(dir: 'E:\\Users\\Fernando\\Google Drive\\experimentos\\Pictogrammar\\android\\app\\libs', include: ['*.jar']) //compile fileTree(dir: 'E:\\Users\\Fernando\\Google Drive\\experimentos\\Pictogrammar\\android\\app\\libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:6.5.87' compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.android.support:appcompat-v7:21.0.3' compile 'com.android.support:appcompat-v7:21.0.3'
......
...@@ -35,7 +35,6 @@ package com.yottacode.net; ...@@ -35,7 +35,6 @@ package com.yottacode.net;
public class RestapiWrapper { public class RestapiWrapper {
String server; String server;
String token; String token;
// String constant for logs // String constant for logs
private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName() private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName()
...@@ -43,6 +42,12 @@ public class RestapiWrapper { ...@@ -43,6 +42,12 @@ public class RestapiWrapper {
this.server=server; this.server=server;
this.token=token; this.token=token;
} }
public void setToken(String token) {
this.token=token;
}
public String getToken() {
return token;
}
public String getServer() { public String getServer() {
return server; return server;
} }
...@@ -50,6 +55,7 @@ public class RestapiWrapper { ...@@ -50,6 +55,7 @@ public class RestapiWrapper {
public void ask(String operation, Hashtable<String, String> params, String postOrGet, iRestapiListener listener) { public void ask(String operation, Hashtable<String, String> params, String postOrGet, iRestapiListener listener) {
// call AsynTask to perform network operation on separate thread // call AsynTask to perform network operation on separate thread
String url = this.server + '/' + operation; String url = this.server + '/' + operation;
Log.d("BORRAR ",url+" T:"+token);
if (token != null) { if (token != null) {
if (params == null) { if (params == null) {
params = new Hashtable<>(1); params = new Hashtable<>(1);
...@@ -91,7 +97,7 @@ public class RestapiWrapper { ...@@ -91,7 +97,7 @@ public class RestapiWrapper {
public static boolean ping(String server, String ping_op, iRestapiListener error_listener) { public static boolean ping(String server, String ping_op, iRestapiListener error_listener) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy); StrictMode.setThreadPolicy(policy);
boolean pingResult = GET(server + "/" + ping_op, null, error_listener)!=null; boolean pingResult = GET(server + "/" + ping_op, null, error_listener)!=null;
return pingResult; return pingResult;
} }
...@@ -140,7 +146,7 @@ public class RestapiWrapper { ...@@ -140,7 +146,7 @@ public class RestapiWrapper {
String value = params.get(param); String value = params.get(param);
sparams += param + '=' + value + '&'; sparams += param + '=' + value + '&';
} }
sparams=sparams.substring(0,sparams.length()-1); if (sparams.length()>0) sparams=sparams.substring(0,sparams.length()-1);
HttpURLConnection urlConnection = null; HttpURLConnection urlConnection = null;
urlConnection = (HttpsURLConnection) url.openConnection(); urlConnection = (HttpsURLConnection) url.openConnection();
......
...@@ -90,7 +90,7 @@ public class Room implements Emitter.Listener { ...@@ -90,7 +90,7 @@ public class Room implements Emitter.Listener {
int id_stu = PCBcontext.getPcbdb().getCurrentUser().get_id_stu(); int id_stu = PCBcontext.getPcbdb().getCurrentUser().get_id_stu();
try { try {
JSONObject msg = new JSONObject().put(param_id_stu, id_stu); JSONObject msg = new JSONObject().put(param_id_stu, id_stu);
this.emit(url, action, msg, PCBcontext.getDevice().getToken()); this.emit(url, action, msg, PCBcontext.getRestapiWrapper().getToken());
}catch (Exception e) { }catch (Exception e) {
Log.e(this.getClass().getCanonicalName(), e.getMessage()); Log.e(this.getClass().getCanonicalName(), e.getMessage());
} }
......
...@@ -152,59 +152,42 @@ public class Device extends SQLiteOpenHelper { ...@@ -152,59 +152,42 @@ public class Device extends SQLiteOpenHelper {
return getParamValue(PARAMS.deviceID); return getParamValue(PARAMS.deviceID);
} }
/**
* Save the token of the device.
*
* @param token of the device.
*/
public void setToken(String token) {
setParam(PARAMS.token, token);
}
/** /**
* Save the id of the student selected * Save the id of the student selected
* @param stu_id of the device. * @param stu_id of the device.
*/ */
public void setStuId(int stu_id) { public void setLastStuId(int stu_id) {
setParam(PARAMS.stu_id, String.valueOf(stu_id)); setParam(PARAMS.stu_id, String.valueOf(stu_id));
} }
/** /**
* Save the id of the supervisor selected * Save the id of the last supervisor
* @param sup_id of the device. * @param sup_id of the device.
* *
*/ */
public void setSupId(int sup_id) { public void setLastSupId(int sup_id) {
setParam(PARAMS.sup_id, String.valueOf(sup_id)); setParam(PARAMS.sup_id, String.valueOf(sup_id));
} }
/**
* Retrieve de token of the device.
* @version 1.0
* @return token of the device or null.
*/
public String getToken() {
return getParamValue(PARAMS.token);
}
/** /**
* Retrieve de user id selected in Login * Retrieve de last logged user
* @author Miguel Ángel * @author Miguel Ángel
* @version 1.0 * @version 1.0
* @return user_id selected or 0. * @return user_id selected or 0.
*/ */
public int getStuId() { public int getLastStuId() {
return Integer.valueOf(getParamValue(PARAMS.stu_id)); return Integer.valueOf(getParamValue(PARAMS.stu_id));
} }
/** /**
* Retrieve de supervisor id selected in Login * Retrieve the last supervisor id selected in Login
* *
* @return sup_id selected or 0. * @return sup_id selected or 0.
*/ */
public int getSupId() { public int getLastSupId() {
return Integer.parseInt(getParamValue(PARAMS.sup_id)); return Integer.parseInt(getParamValue(PARAMS.sup_id));
} }
......
...@@ -81,9 +81,9 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -81,9 +81,9 @@ public class PCBDBHelper extends SQLiteOpenHelper {
* @see PCBDBHelper#getCurrentUser() * @see PCBDBHelper#getCurrentUser()
*/ */
private void setCurrentUser(User user) { private void setCurrentUser(User user) {
PCBcontext.getDevice().setStuId(user.get_id_stu());
PCBcontext.getDevice().setSupId(user.get_id_sup());
this.currentUser = user; this.currentUser = user;
PCBcontext.getDevice().setLastStuId(user.get_id_stu());
PCBcontext.getDevice().setLastSupId(user.get_id_sup());
} }
/** /**
...@@ -91,7 +91,7 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -91,7 +91,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
* @see PCBDBHelper#getCurrentUser() * @see PCBDBHelper#getCurrentUser()
*/ */
public User loadLastUser() { public User loadLastUser() {
String stu=String.valueOf(PCBcontext.getDevice().getStuId()), sup=String.valueOf(PCBcontext.getDevice().getSupId()); String stu=String.valueOf(PCBcontext.getDevice().getLastStuId()), sup=String.valueOf(PCBcontext.getDevice().getLastSupId());
User last_user = null; User last_user = null;
SQLiteDatabase db = this.getReadableDatabase(); SQLiteDatabase db = this.getReadableDatabase();
......
...@@ -42,10 +42,12 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular ...@@ -42,10 +42,12 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
public Vocabulary(iImgDownloaderListener listener) { public Vocabulary(iImgDownloaderListener listener) {
this.pictos = new Hashtable<>(Vocabulary.DEFAULT_VOCABULARY_SIZE); this.pictos = new Hashtable<>(Vocabulary.DEFAULT_VOCABULARY_SIZE);
this.imgListener=listener; this.imgListener=listener;
if (PCBcontext.getNetService().online()) if (PCBcontext.getNetService().online()) {
Log.i(this.getClass().getName(), "downloading vocabulary");
download(); download();
else }else
try { try {
Log.i(this.getClass().getName(), "local vocabulary");
PCBcontext.getPcbdb().getStudentVocabulary(this); PCBcontext.getPcbdb().getStudentVocabulary(this);
listener.loadComplete(); listener.loadComplete();
} catch (JSONException e) { } catch (JSONException e) {
...@@ -256,6 +258,7 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular ...@@ -256,6 +258,7 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
attributes); attributes);
} }
this.synchronizeImgs(pictos); this.synchronizeImgs(pictos);
Log.i(this.getClass().getName(), " Pictos downloaded: " + result.length());
} catch (JSONException e) { } catch (JSONException e) {
Log.e(this.getClass().getName(), " Picto json error from server: " + picto.toString()); Log.e(this.getClass().getName(), " Picto json error from server: " + picto.toString());
this.error(e); this.error(e);
......
...@@ -96,9 +96,10 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener, ...@@ -96,9 +96,10 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener,
//NetService service= PCBcontext.getNetService(); //NetService service= PCBcontext.getNetService();
// Llamo al WS para coger los usuarios y los supervisores de este dispositivo // Llamo al WS para coger los usuarios y los supervisores de este dispositivo
SSLDummyContext.init(getResources().getBoolean(R.bool.ssl_connect)); SSLDummyContext.init(getResources().getBoolean(R.bool.ssl_connect));
PCBcontext.init(this);
// Compruebo si tengo acceso a internet // Compruebo si tengo acceso a internet
//if (!PCBcontext.getRestapiWrapper().ping("/server/ping", this)) { //if (!PCBcontext.getRestapiWrapper().ping("/server/ping", this)) {
if (!RestapiWrapper.ping(getResources().getString(R.string.server),"server/ping",this)) { if (!RestapiWrapper.ping(getResources().getString(R.string.server),"server/ping",this)) {
// No puedo comprobar si el serial es válido. Muestro un alertdialog de error, y cierro la aplicación // No puedo comprobar si el serial es válido. Muestro un alertdialog de error, y cierro la aplicación
AlertDialog alertDialog = new AlertDialog.Builder( AlertDialog alertDialog = new AlertDialog.Builder(
...@@ -119,10 +120,9 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener, ...@@ -119,10 +120,9 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener,
//PCBcontext.getDevice().setToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkZXNjIjoiU00tVDMzMCIsImlkIjoxNzYsImlkRmlybXdhcmUiOiJwcnVlYmFfMTIzNSIsImlhdCI6MTQ0NDM5MDQ5M30.SRJSMWxdenCwecsHIshqh4QEYqFCytI_aHajeVHTT20"); //PCBcontext.getDevice().setToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkZXNjIjoiU00tVDMzMCIsImlkIjoxNzYsImlkRmlybXdhcmUiOiJwcnVlYmFfMTIzNSIsImlhdCI6MTQ0NDM5MDQ5M30.SRJSMWxdenCwecsHIshqh4QEYqFCytI_aHajeVHTT20");
//String deviceID = PCBcontext.getDevice().getDeviceID(); //String deviceID = PCBcontext.getDevice().getDeviceID();
String token = PCBcontext.getDevice().getToken();
RestapiWrapper wrapper = new RestapiWrapper(
getApplicationContext().getResources().getString(R.string.server),token); RestapiWrapper wrapper = PCBcontext.getRestapiWrapper();
//String operation = "/dev/" + deviceID + "/users"; //String operation = "/dev/" + deviceID + "/users";
String operation = ""; // SEGUIR String operation = ""; // SEGUIR
...@@ -253,7 +253,7 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener, ...@@ -253,7 +253,7 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener,
else{ else{
// SEGUIR. Sólo tengo 1 usuario, así que no hace falta que cargue Login // SEGUIR. Sólo tengo 1 usuario, así que no hace falta que cargue Login
PCBcontext.getDevice().setStuId(users.elementAt(0).get_id_stu()); PCBcontext.getDevice().setLastStuId(users.elementAt(0).get_id_stu());
// Si tiene SupID se saca del registro // Si tiene SupID se saca del registro
//PCBcontext.getDevice().setSupId(-1); //PCBcontext.getDevice().setSupId(-1);
......
...@@ -38,9 +38,9 @@ public class MainActivity extends Activity { ...@@ -38,9 +38,9 @@ public class MainActivity extends Activity {
// Singleton getInstance and initialization passing the Context (to create the device) // Singleton getInstance and initialization passing the Context (to create the device)
//PCBcontext pcb = PCBcontext.getInstance(); //PCBcontext pcb = PCBcontext.getInstance();
PCBcontext.init(this); PCBcontext.init(this);
Log.d(LOG_TAG, "PCBcontext iniciado");
// Compruebo si tengo token ya guardado en la bbdd para abrir el intent del registro // Compruebo si tengo token ya guardado en la bbdd para abrir el intent del registro
String token = PCBcontext.getDevice().getToken(); String token = PCBcontext.getRestapiWrapper().getToken();
//if (1==0){ // Fuerzo a que entre en serialActivity //if (1==0){ // Fuerzo a que entre en serialActivity
Intent serialActivity = new Intent(this, SerialActivity.class); Intent serialActivity = new Intent(this, SerialActivity.class);
......
...@@ -99,14 +99,9 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -99,14 +99,9 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
Log.d(LOG_TAG, "1) Opening PCB"); Log.d(LOG_TAG, "1) Opening PCB");
SSLDummyContext.init(getResources().getBoolean(R.bool.ssl_connect)); SSLDummyContext.init(getResources().getBoolean(R.bool.ssl_connect));
try {
// Cargo los datos del alumno y el supervisor seleccionado
int id_alumno = PCBcontext.getDevice().getStuId();
int id_supervisor = PCBcontext.getDevice().getSupId();
Log.d(LOG_TAG, "GET id_alumno:" + id_alumno + " /id_supervisor:" + id_supervisor); // Cargo los datos del alumno y el supervisor seleccionado
student = PCBcontext.getDevice().findUser(id_alumno, id_supervisor);
//Log.d(LOG_TAG, "student name:" + student.get_name_stu()); //Log.d(LOG_TAG, "student name:" + student.get_name_stu());
...@@ -121,15 +116,12 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -121,15 +116,12 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
//Log.d(LOG_TAG, "2) OnCreate - Serial:" + pcb.getDevice().getSerial() + " dev. id:" + pcb.getDevice().getDeviceID() + " token:" + pcb.getDevice().getToken()); //Log.d(LOG_TAG, "2) OnCreate - Serial:" + pcb.getDevice().getSerial() + " dev. id:" + pcb.getDevice().getDeviceID() + " token:" + pcb.getDevice().getToken());
// Init PCB DB // Init PCB DB
PCBcontext.set_user(student,this);
// Open websocket connection // Open websocket connection
PCBcontext.getVocabulary().listen(PCBcontext.getRoom(),this); PCBcontext.getVocabulary().listen(PCBcontext.getRoom(),this);
} catch (JSONException e) {
e.printStackTrace();
Log.e(LOG_TAG,"5) USER JSON ERROR: "+e.getMessage());
}
// Connect the views // Connect the views
final GridView tapeGridView = (GridView) findViewById(R.id.tape_grid_view); final GridView tapeGridView = (GridView) findViewById(R.id.tape_grid_view);
...@@ -218,6 +210,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -218,6 +210,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
actualCategory = p; actualCategory = p;
Toast.makeText(context, "El picto pulsado es una categoría", Toast.LENGTH_SHORT).show(); Toast.makeText(context, "El picto pulsado es una categoría", Toast.LENGTH_SHORT).show();
PCBcontext.getActionLog().log(new PictoAction(PictoAction.SELECT, p));
}else if(tapeAdapter.getCount() < maxInTape){ }else if(tapeAdapter.getCount() < maxInTape){
// If the picto selected is not a category and the tape is not full, it is placed in tape // If the picto selected is not a category and the tape is not full, it is placed in tape
...@@ -234,19 +227,8 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -234,19 +227,8 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
// Call to static log method // Call to static log method
PCBcontext.getActionLog().log(new PictoAction(PictoAction.ADD, p)); PCBcontext.getActionLog().log(new PictoAction(PictoAction.ADD, p));
// Send websocket notification // Send websocket notification
/*
try {
Log.d(LOG_TAG, "Picto: " + p.toString());
//room.talk("/stu/action", "select", p);
room.talk("/stu/action", "add", p);
}catch(JSONException e){
e.printStackTrace();
Log.e(LOG_TAG, "Send action: " + e.getMessage());
}
*/
// when clicking a picto, the activity goes to the main category view // when clicking a picto, the activity goes to the main category view
actualCategory = null; actualCategory = null;
} }
...@@ -313,16 +295,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -313,16 +295,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
// Call to static log method // Call to static log method
PCBcontext.getActionLog().log(new PictosAction(lp)); PCBcontext.getActionLog().log(new PictosAction(lp));
/*
try {
Log.d(LOG_TAG, "Pictos: " + lp.toString());
room.talk("/stu/action", "show", lp);
}catch(JSONException e){
e.printStackTrace();
Log.e(LOG_TAG, "Send action: " + e.getMessage());
}
*/
//send_phrase_action(tapeAdapter.getAll()); //send_phrase_action(tapeAdapter.getAll());
// Uncomment next line for locution when the version of Android be greater than 5.0 // Uncomment next line for locution when the version of Android be greater than 5.0
...@@ -346,19 +318,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -346,19 +318,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
// Call to static log method // Call to static log method
PCBcontext.getActionLog().log(new PictoAction(PictoAction.DELETE, p)); PCBcontext.getActionLog().log(new PictoAction(PictoAction.DELETE, p));
// Send websocket action // Send websocket action
/*
try {
Log.d(LOG_TAG, "Picto: " + p.toString());
room.talk("/stu/action", "delete", p);
}catch(JSONException e){
e.printStackTrace();
Log.e(LOG_TAG, "Send action: " + e.getMessage());
}
*/
//send_del_action(tapeAdapter.getLastItem());
tapeAdapter.deleteLastView(); tapeAdapter.deleteLastView();
tapeAdapter.notifyDataSetChanged(); tapeAdapter.notifyDataSetChanged();
......
...@@ -118,7 +118,8 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo ...@@ -118,7 +118,8 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
//_ANDROIDID = "prueba_1258"; // QUITAR //_ANDROIDID = "prueba_1258"; // QUITAR
SSLDummyContext.init(getResources().getBoolean(R.bool.ssl_connect)); SSLDummyContext.init(getResources().getBoolean(R.bool.ssl_connect));
PCBcontext.init(this);
Log.d(LOG_TAG, "PCBcontext iniciado");
// Compruebo si tengo acceso a internet // Compruebo si tengo acceso a internet
//modificación FERNANDO //modificación FERNANDO
if (!RestapiWrapper.ping(context.getResources().getString(R.string.server),"server/ping",this)) { if (!RestapiWrapper.ping(context.getResources().getString(R.string.server),"server/ping",this)) {
...@@ -156,8 +157,7 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo ...@@ -156,8 +157,7 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
String username = "dofer@ujaen.es"; String username = "dofer@ujaen.es";
String password = "dofer"; String password = "dofer";
RestapiWrapper wrapper = new RestapiWrapper( RestapiWrapper wrapper = PCBcontext.getRestapiWrapper();
getApplicationContext().getResources().getString(R.string.server),null);
//String serial = mSerialView.getText().toString(); //String serial = mSerialView.getText().toString();
//String serial = "0yhHcxMUcm"; // QUITAR //String serial = "0yhHcxMUcm"; // QUITAR
if (username.contains("@")){ if (username.contains("@")){
...@@ -280,7 +280,9 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo ...@@ -280,7 +280,9 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
//Log.d(LOG_TAG, "jsonIdString:" + jsonIdString); //Log.d(LOG_TAG, "jsonIdString:" + jsonIdString);
// Guardo el deviceID, token y serial en la bbdd // Guardo el deviceID, token y serial en la bbdd
//PCBcontext.getDevice().setDeviceID(jsonIdString); //PCBcontext.getDevice().setDeviceID(jsonIdString);
PCBcontext.getDevice().setToken(jsonToken); User student = PCBcontext.getDevice().findUser(st_id, su_id);
PCBcontext.set_user(student, jsonToken, this);
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -294,7 +296,7 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo ...@@ -294,7 +296,7 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
Log.e(this.getClass().getName(), " Server restapi error: " + e.getLocalizedMessage()); Log.e(this.getClass().getName(), " Server restapi error: " + e.getLocalizedMessage());
AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this);
builder.setMessage(getString(R.string.serialRepeated)) builder.setMessage(getString(R.string.serialRepeated)+":"+e.getLocalizedMessage())
.setCancelable(false) .setCancelable(false)
.setPositiveButton("Entendido", new DialogInterface.OnClickListener() { .setPositiveButton("Entendido", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
...@@ -308,8 +310,6 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo ...@@ -308,8 +310,6 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
@Override @Override
public void loadComplete() { public void loadComplete() {
Log.d(LOG_TAG, "Load images complete"); Log.d(LOG_TAG, "Load images complete");
PCBcontext.getDevice().setStuId(st_id);
PCBcontext.getDevice().setSupId(su_id);
Intent pictogramActivity = new Intent(this, PictogramActivity.class); Intent pictogramActivity = new Intent(this, PictogramActivity.class);
startActivity(pictogramActivity); startActivity(pictogramActivity);
......
...@@ -177,8 +177,8 @@ public class StudentFragmentGrid extends Fragment{ ...@@ -177,8 +177,8 @@ public class StudentFragmentGrid extends Fragment{
*/ */
// Entro en pictogram con ese valor de alumno y con supervisor a null // Entro en pictogram con ese valor de alumno y con supervisor a null
Toast.makeText(getActivity().getBaseContext(), "Modo Supervisor desactivado", Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity().getBaseContext(), "Modo Supervisor desactivado", Toast.LENGTH_SHORT).show();
PCBcontext.getDevice().setStuId(students_ids.elementAt(pos)); PCBcontext.getDevice().setLastStuId(students_ids.elementAt(pos));
PCBcontext.getDevice().setSupId(-1); PCBcontext.getDevice().setLastSupId(-1);
//Log.d(LOG_TAG, "SET id_alumno:" + students_ids.elementAt(pos) + " /id_supervisor:-1"); //Log.d(LOG_TAG, "SET id_alumno:" + students_ids.elementAt(pos) + " /id_supervisor:-1");
......
...@@ -67,7 +67,7 @@ public class SupervisorFragment extends ListFragment { ...@@ -67,7 +67,7 @@ public class SupervisorFragment extends ListFragment {
@Override @Override
public void onListItemClick(ListView l, View v, int position, long id) { public void onListItemClick(ListView l, View v, int position, long id) {
// Guardo en device el id del supervisor // Guardo en device el id del supervisor
pcb.getDevice().setSupId(supervisor_ids.elementAt(position)); pcb.getDevice().setLastSupId(supervisor_ids.elementAt(position));
Intent pictogramActivity = new Intent(getActivity(), PictogramActivity.class); Intent pictogramActivity = new Intent(getActivity(), PictogramActivity.class);
startActivity(pictogramActivity); startActivity(pictogramActivity);
......
...@@ -92,7 +92,7 @@ public class SupervisorFragmentGrid extends Fragment { ...@@ -92,7 +92,7 @@ public class SupervisorFragmentGrid extends Fragment {
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) { public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
pcb.getDevice().setSupId(supervisor_ids.elementAt(pos)); pcb.getDevice().setLastSupId(supervisor_ids.elementAt(pos));
Intent pictogramActivity = new Intent(getActivity(), PictogramActivity.class); Intent pictogramActivity = new Intent(getActivity(), PictogramActivity.class);
startActivity(pictogramActivity); startActivity(pictogramActivity);
} }
......
...@@ -35,7 +35,6 @@ public class NetService implements Runnable, iRestapiListener { ...@@ -35,7 +35,6 @@ public class NetService implements Runnable, iRestapiListener {
public NetService(int delay) { public NetService(int delay) {
Log.i(this.getClass().getName(),"Checking Pictogram server access..."); Log.i(this.getClass().getName(),"Checking Pictogram server access...");
//this.online=PCBcontext.getRestapiWrapper().ping_session(ping_session,this);
this.online = RestapiWrapper.ping(PCBcontext.getContext().getResources().getString(R.string.server), ping_session, this); this.online = RestapiWrapper.ping(PCBcontext.getContext().getResources().getString(R.string.server), ping_session, this);
Log.d(this.getClass().getName(),this.online() ? "Pictogram server access ok" : "Pictogram server access failed, Internet connection available?"); Log.d(this.getClass().getName(),this.online() ? "Pictogram server access ok" : "Pictogram server access failed, Internet connection available?");
ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1); ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);
......
...@@ -51,6 +51,7 @@ public final class PCBcontext { ...@@ -51,6 +51,7 @@ public final class PCBcontext {
public static void init(Context c){ public static void init(Context c){
context=c; context=c;
device = new Device(c, null, 1); device = new Device(c, null, 1);
wrapper = new RestapiWrapper(context.getResources().getString(R.string.server),null);
} }
/** /**
...@@ -60,9 +61,8 @@ public final class PCBcontext { ...@@ -60,9 +61,8 @@ public final class PCBcontext {
* @param student * @param student
* @param listener * @param listener
*/ */
public static void set_user(User student, iImgDownloaderListener listener) { public static void set_user(User student, String token, iImgDownloaderListener listener) {
wrapper.setToken(token);
wrapper = new RestapiWrapper(context.getResources().getString(R.string.server), device.getToken());
pcbdb = new PCBDBHelper(null, 1, student); pcbdb = new PCBDBHelper(null, 1, student);
service = new NetService(context.getResources().getInteger(R.integer.netservice_timing)); service = new NetService(context.getResources().getInteger(R.integer.netservice_timing));
vocabulary= new Vocabulary(listener); vocabulary= new Vocabulary(listener);
......
...@@ -27,7 +27,7 @@ public class TTSHelper { ...@@ -27,7 +27,7 @@ public class TTSHelper {
public void createTTS(Context context, String engine) { public void createTTS(Context context, String engine) {
this.destroy(); this.destroy();
this.ttobj = new TextToSpeech( /* this.ttobj = new TextToSpeech(
context, context,
new TextToSpeech.OnInitListener() { new TextToSpeech.OnInitListener() {
@Override @Override
...@@ -36,7 +36,7 @@ public class TTSHelper { ...@@ -36,7 +36,7 @@ public class TTSHelper {
ttobj.setLanguage(Locale.getDefault()); ttobj.setLanguage(Locale.getDefault());
} }
} }
}, engine); }, engine);*/
this.engine_ok=true; this.engine_ok=true;
Log.e(context.getApplicationInfo().processName,"TTS engine "+engine+" loaded"); Log.e(context.getApplicationInfo().processName,"TTS engine "+engine+" loaded");
} }
......
...@@ -46,7 +46,7 @@ public class Translate extends Activity implements iVocabularyListener, iImgDown ...@@ -46,7 +46,7 @@ public class Translate extends Activity implements iVocabularyListener, iImgDown
// String constant for logs // String constant for logs
private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName() private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName()
// String constan for token // String constan for token
private final String TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJvZmZpY2UiOnsiaWQiOjM4NywibmFtZSI6IkNvbXVuaWNhY2nDs24gQXVtZW50YXRpdmEgSkHDqW4gKENBSkEpIiwiYWRkcmVzcyI6IlBhcmFqZSBMYXMgTGFndW5pbGxhcywgRWQgQTMsIHByaW1lcmEgcGxhdGEsIDIzMDcxLiBKYcOpbiIsImVtYWlsIjoiZG9mZXJAdWphZW4uZXMiLCJwaG9uZTEiOiIrMzQgOTUzIDIxIDI4IDg4IiwicGhvbmUyIjpudWxsLCJsYW5nIjoiZXMtZXMiLCJjb3VudHJ5IjoiRVMiLCJhZG1pbiI6NDMsImNvbnRhY3RQZXJzb24iOiJGZXJuYW5kbyBNYXJ0w61uZXogU2FudGlhZ28iLCJtYXhTdHVkZW50cyI6MiwiY3VycmVudFN0dWRlbnRzIjo2fSwiaWQiOjQzLCJuYW1lIjoiRmVybmFuZG8iLCJzdXJuYW1lIjoiTWFydMOtbmV6IiwiZ2VuZGVyIjoiTSIsInBpYyI6Imh0dHA6Ly93d3dkaS51amFlbi5lcy9zaXRlcy9kZWZhdWx0L2ZpbGVzL3lvLmpwZz8xNDQ4MDE5MzU2IiwiYWRkcmVzcyI6bnVsbCwiY291bnRyeSI6bnVsbCwiZW1haWwiOiJkb2ZlckB1amFlbi5lcyIsInBob25lIjoiKzM0OTUzMjEyODg4IiwibGFuZyI6ImVzLWVzIiwiYWN0aXZlIjp0cnVlLCJ0dHNFbmdpbmUiOm51bGwsImlzU3VwQWRtaW4iOnRydWUsImlhdCI6MTQ0OTEyMDA3OCwiZXhwIjoxNDQ5MTI3Mjc4fQ.cx2mKY-cGlug_FoMTW-4eoJHXoGWMep4zF4qKOZjADg"; private final String TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJvZmZpY2UiOnsiaWQiOjM4MywibmFtZSI6IkNvbXVuaWNhY2nDs24gQXVtZW50YXRpdmEgSkHDqW4gKENBSkEpIiwiYWRkcmVzcyI6IlBhcmFqZSBMYXMgTGFndW5pbGxhcywgRWQgQTMsIHByaW1lcmEgcGxhdGEsIDIzMDcxLiBKYcOpbiIsImVtYWlsIjoiZG9mZXJAdWphZW4uZXMiLCJwaG9uZTEiOiIrMzQgOTUzIDIxIDI4IDg4IiwicGhvbmUyIjpudWxsLCJsYW5nIjoiZXMtZXMiLCJjb3VudHJ5IjoiRVMiLCJhZG1pbiI6MjMsImNvbnRhY3RQZXJzb24iOiJGZXJuYW5kbyBNYXJ0w61uZXogU2FudGlhZ28iLCJtYXhTdHVkZW50cyI6MiwiY3VycmVudFN0dWRlbnRzIjowfSwiaWQiOjIzLCJuYW1lIjoiRmVybmFuZG8iLCJzdXJuYW1lIjoiTWFydMOtbmV6IFNhbnRpYWdvIiwiZ2VuZGVyIjoiTSIsInBpYyI6Imh0dHA6Ly93d3dkaS51amFlbi5lcy9zaXRlcy9kZWZhdWx0L2ZpbGVzL3lvLmpwZz8xNDQ4MDE5MzU2IiwiYWRkcmVzcyI6bnVsbCwiY291bnRyeSI6bnVsbCwiZW1haWwiOiJkb2ZlckB1amFlbi5lcyIsInBob25lIjoiKzM0OTUzMjEyODg4IiwibGFuZyI6ImVzLWVzIiwiYWN0aXZlIjp0cnVlLCJ0dHNFbmdpbmUiOm51bGwsImlzU3VwQWRtaW4iOnRydWUsImlhdCI6MTQ1Mjg4NjE1NSwiZXhwIjoxNDUyODkzMzU1fQ.dmxKE4qH1DqBM7BYakgwD0L6y1437_2Ba3T7rHnOIcE";
/** Called when the activity is first created. */ /** Called when the activity is first created. */
@Override @Override
...@@ -76,18 +76,17 @@ public class Translate extends Activity implements iVocabularyListener, iImgDown ...@@ -76,18 +76,17 @@ public class Translate extends Activity implements iVocabularyListener, iImgDown
2, "Antonio", "Roldan", "http://www4.ujaen.es/~dofer/pictures/supervisor/antonio.jpg", "M", "es-es", "")); 2, "Antonio", "Roldan", "http://www4.ujaen.es/~dofer/pictures/supervisor/antonio.jpg", "M", "es-es", ""));
users.add(new User(4, "Rosa", "Mateos", "http://www4.ujaen.es/~dofer/pictures/student/rosa.jpg", "M", "es-es", "", users.add(new User(4, "Rosa", "Mateos", "http://www4.ujaen.es/~dofer/pictures/student/rosa.jpg", "M", "es-es", "",
2, "Antonio", "Roldan", "http://www4.ujaen.es/~dofer/pictures/supervisor/antonio.jpg", "M", "es-es", "")); 2, "Antonio", "Roldan", "http://www4.ujaen.es/~dofer/pictures/supervisor/antonio.jpg", "M", "es-es", ""));
User alumno_picto = new User(56, "Arturito", "Alumno" + User alumno_picto = new User(23, "Arturito", "Alumno" +
" Arturo", "http://www4.ujaen.es/~dofer/pictures/student/rosa.jpg", "M", "es-es", ""); " Arturo", "http://www4.ujaen.es/~dofer/pictures/student/rosa.jpg", "M", "es-es", "");
users.add(alumno_picto); users.add(alumno_picto);
PCBcontext.init(this); PCBcontext.init(this);
PCBcontext.getDevice().setToken(TOKEN);
PCBcontext.getDevice().setSerial("serial1"); PCBcontext.getDevice().setSerial("serial1");
PCBcontext.getDevice().setDeviceID("deviceID"); PCBcontext.getDevice().setDeviceID("deviceID");
PCBcontext.getDevice().deleteDeprecatedImgs(); PCBcontext.getDevice().deleteDeprecatedImgs();
PCBcontext.set_user(alumno_picto, this); PCBcontext.set_user(alumno_picto, TOKEN, this);
Log.i(LOG_TAG, "2) OnCreate - Serial:" + PCBcontext.getDevice().getSerial() + " dev. id:" + Log.i(LOG_TAG, "2) OnCreate - Serial:" + PCBcontext.getDevice().getSerial() + " dev. id:" +
PCBcontext.getDevice().getDeviceID() + " token:" + PCBcontext.getDevice().getToken()); PCBcontext.getDevice().getDeviceID() + " token:" + TOKEN);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment