Integrado el nuevo sistema del PCBContext. Añadido popup de Cargando datos.

parent 60ea3ee3
......@@ -21,7 +21,7 @@ android {
resValue "bool", "force_img_download", "false"
resValue "integer", "netservice_timing", "20"
resValue "integer", "rows", "5"
resValue "integer", "columns", "10"
resValue "integer", "columns", "8"
}
debug {
......@@ -31,7 +31,7 @@ android {
resValue "bool", "force_img_download", "false"
resValue "integer", "netservice_timing", "20"
resValue "integer", "rows", "5"
resValue "integer", "columns", "10"
resValue "integer", "columns", "8"
}
}
productFlavors {
......
......@@ -32,6 +32,11 @@ package com.yottacode.net;
*
* @author dofer
*/
/**
* Modificado por: magc
* LastUpdate: 22 de enero de 2016
*/
public class RestapiWrapper {
String server;
String token;
......@@ -53,6 +58,8 @@ public class RestapiWrapper {
}
public void ask(String operation, Hashtable<String, String> params, String postOrGet, iRestapiListener listener) {
// call preExecute listener to show loading window
listener.preExecute();
// call AsynTask to perform network operation on separate thread
if (this.token != null) {
......
......@@ -12,6 +12,7 @@ import org.json.JSONObject;
* @author dofer
*/
public interface iRestapiListener {
public void preExecute();
public void result(JSONArray result);
public void result(JSONObject result);
public void error(Exception e);
......
......@@ -61,6 +61,11 @@ public class ActionLog implements iRestapiListener {
}
@Override
public void preExecute() {
}
@Override
public void result(JSONArray result) {
}
......
......@@ -134,12 +134,17 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
imageInFile.read(imageData);
Hashtable<String,String> params=new Hashtable<>(3);
params.put("filename", name);
params.put("folder","custompictos");
params.put("id",String.valueOf(PCBcontext.getPcbdb().getCurrentUser().get_id_stu()));
params.put("folder", "custompictos");
params.put("id", String.valueOf(PCBcontext.getPcbdb().getCurrentUser().get_id_stu()));
params.put("file", String.valueOf(imageData));
PCBcontext.getRestapiWrapper().ask("upload", params, "post", new iRestapiListener() {
@Override
public void preExecute() {
}
@Override
public void result(JSONArray result) {
}
......@@ -291,6 +296,11 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
}
@Override
public void preExecute() {
}
@Override
public void result(JSONArray result) {
if (result!=null) {
......
......@@ -58,21 +58,16 @@ import java.util.Locale;
import android.provider.Settings.Secure;
public class PictogramActivity extends Activity implements iVocabularyListener, iImgDownloaderListener, TextToSpeech.OnInitListener {
public class PictogramActivity extends Activity implements iVocabularyListener, TextToSpeech.OnInitListener {
PanelAdapter panelAdapter;
TapeAdapter tapeAdapter;
//PCBDBHelper pcbdb;
//Device device;
//Room room;
Vocabulary vocabulary;
User student;
Context context;
//PCBcontext pcb;
Picto actualCategory;
TextToSpeech tts;
......@@ -98,30 +93,31 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
Log.d(LOG_TAG, "1) Opening PCB");
SSLDummyContext.init(getResources().getBoolean(R.bool.ssl_connect));
PCBcontext.init(this);
Log.d(LOG_TAG, "PCBcontext iniciado");
// Redundante, pero lo hago para forzarlo
/*
student = PCBcontext.getPcbdb().getCurrentUser();
String jsonToken = PCBcontext.getRestapiWrapper().getToken();
Log.d(LOG_TAG, "student name:" + student.get_name_stu());
PCBcontext.set_user(student,jsonToken, this);
*/
// Cargo los datos del alumno y el supervisor seleccionado
//Log.d(LOG_TAG, "student name:" + student.get_name_stu());
// Create user. QUITAR cuando cargue bien el student con find_user
//student = new User(73, "Alumno", "Con Pictogramas", "http://www4.ujaen.es/~dofer/pictures/student/rosa.jpg", "M", "es-es", "");
// QUITAR cuando esté funcionando, porque debe coger de antes estos valores
//PCBcontext.getDevice().setToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkZXNjIjoiTlZpZGlhIFNoaWVsZCIsImlkIjoxNjUsImlkRmlybXdhcmUiOiJBTkRST0lEXzMyIiwiaWF0IjoxNDQyOTAzMzY3fQ.m-jbcEBQceWLZKda6fKMow_dg_fAwK9Nys00QA-gNwY");
//PCBcontext.getDevice().setSerial("serial1");
//PCBcontext.getDevice().setDeviceID("deviceID");
//Log.d(LOG_TAG, "2) OnCreate - Serial:" + pcb.getDevice().getSerial() + " dev. id:" + pcb.getDevice().getDeviceID() + " token:" + pcb.getDevice().getToken());
// Init PCB DB
this.vocabulary=PCBcontext.getVocabulary();
// Open websocket connection
vocabulary.listen(PCBcontext.getRoom(),this);
// Adapter for grid
panelAdapter = new PanelAdapter(new LinkedList<Picto>());
this.vocabulary=PCBcontext.getVocabulary();
if (this.vocabulary != null && this.vocabulary.size() > 0){
Log.d(LOG_TAG, "Vocabulario correcto de tam:" + this.vocabulary.size());
LinkedList<Picto> ll;
if(actualCategory != null) ll = order(vocabulary.next(actualCategory));
else ll = order(vocabulary.startSentence());
panelAdapter.clear();
panelAdapter.addAll(ll);
}
// Open websocket connection
vocabulary.listen(PCBcontext.getRoom(),this);
// Connect the views
final GridView tapeGridView = (GridView) findViewById(R.id.tape_grid_view);
......@@ -144,8 +140,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
if (pictogramSize==0) panelGridView.setNumColumns(10);
else if (pictogramSize==1) panelGridView.setNumColumns(4);
// Adapter for grid
panelAdapter = new PanelAdapter(new LinkedList<Picto>());
panelGridView.setAdapter(panelAdapter);
// Adapter for tape
......@@ -377,7 +371,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
/**
* Load pictos. Asociado a botón provisional para cargar el vocabulario en el adapter
* @param v
* BORRAR. Ya funciona la carga asíncrona del vocabulario
*/
public void load_pictos(View v) {
if(vocabulary != null)
......@@ -397,26 +390,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
}
/**
* Go back. Asociado al botón "volver" carga los pictos anteriores al actual del vocabulario
* @param v
* TODO ¿Quitar? ¿O asociar a otro evento?
*/
public void go_back(View v) {
try {
actualCategory = null;
LinkedList<Picto> ll = order(vocabulary.startSentence());
panelAdapter.clear();
panelAdapter.addAll(ll);
} catch (NullPointerException e){
Log.d(LOG_TAG, "El vocabulario todavía no se ha cargado");
}
}
/**
* Order a linked list of pictos with "blank spaces" between them
* @param list
* @return
......@@ -527,31 +500,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
}
}
// De la interfaz iImgDownloaderListener
@Override
public void loadComplete() {
Log.d(LOG_TAG, "Load images complete");
try {
vocabulary = PCBcontext.getVocabulary();
LinkedList<Picto> ll;
if(actualCategory != null) ll = order(vocabulary.next(actualCategory));
else ll = order(vocabulary.startSentence());
panelAdapter.clear();
panelAdapter.addAll(ll);
}catch(NullPointerException e){
Log.d(LOG_TAG, "El vocabulario todavía no se ha cargado");
}
}
// De la interfaz iImgDownloaderListener
@Override
public void loadImg(Img img) {
Log.d(LOG_TAG, "Load a single image with ID: " + img.get_id());
}
// Disable Back Button --> Kiosk mode
@Override
public void onBackPressed() {
......
......@@ -11,9 +11,11 @@ import java.util.Vector;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -23,6 +25,9 @@ import android.widget.Toast;
import com.yottacode.pictogram.R;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.grammar.Vocabulary;
import com.yottacode.pictogram.net.iImgDownloaderListener;
import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONException;
......@@ -42,7 +47,7 @@ public class StudentFragmentGrid extends Fragment{
Map<String, Bitmap> map_supervisor_pictures = new TreeMap<String, Bitmap>();
Vector<Bitmap> imageStudents = new Vector<Bitmap>();
*/
Boolean modoSupervisor;
//Boolean modoSupervisor;
// NEW
Map<Integer, Vector<Integer>> ids_stu_sup = new TreeMap<Integer, Vector<Integer>>();
......@@ -54,26 +59,19 @@ public class StudentFragmentGrid extends Fragment{
// String constant for logs
private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName()
//A ProgressDialog object
private ProgressDialog progressDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
// Singleton getInstance
//pcb = PCBcontext.getInstance();
/*
Set<String> s_students;
List<String> l_supervisors = new ArrayList<String>();
students_ids = new Vector<Integer>();
supervisor_ids = new Vector<Integer>();
*/
modoSupervisor = false;
try {
// Cargo los datos de los estudiantes
Vector<User> users = PCBcontext.getDevice().getUsers();
if (users!=null){
Log.d(LOG_TAG, "Cargo " + users.size() + " alumnos");
// Recorro el vector para sacar los nombres de estudiantes y las imágenes
for( int i = 0 ; i < users.size() ; i++ ){
int st_id = users.elementAt(i).get_id_stu();
......@@ -91,40 +89,7 @@ public class StudentFragmentGrid extends Fragment{
ids_stu_sup.put(st_id, sups);
}
}
/*
String st_name = users.elementAt(i).get_name_stu();
String st_surname = users.elementAt(i).get_surname_stu();
Bitmap st_picture = users.elementAt(i).get_bitmap_stu(getActivity());
String su_name = users.elementAt(i).get_name_sup();
String su_surname = users.elementAt(i).get_surname_sup();
Bitmap su_picture = users.elementAt(i).get_bitmap_sup(getActivity());
if (!map_students.containsKey(st_name + " " + st_surname)){
// Creo un nuevo supervisor y lo añado
if (su_id!=-1){
l_supervisors = new ArrayList<String>();
l_supervisors.add(su_name + " " + su_surname);
map_supervisor_pictures.put(su_name + " " + su_surname, su_picture);
supervisor_ids.add(su_id);
}
imageStudents.add(st_picture);
map_students.put(st_name + " " + st_surname, l_supervisors);
students_ids.add(st_id);
} else{
// Saco los supervisores, añado uno más y grabo
if (su_id!=-1){
l_supervisors = map_students.get(st_name + " " + st_surname);
l_supervisors.add(su_name + " " + su_surname);
supervisor_ids.add(su_id);
}
map_students.put(st_name + " " + st_surname, l_supervisors);
}
*/
}
// Saco los estudiantes
/*
s_students = map_students.keySet();
students = s_students.toArray(new String[s_students.size()]);
*/
} else{
// TRATO EL ERROR. COMO ?????
}
......@@ -144,11 +109,12 @@ public class StudentFragmentGrid extends Fragment{
try {
List<String> l_students_name = new ArrayList<String>();
Vector<Bitmap> imageStudents = new Vector<Bitmap>();
int id_sup = PCBcontext.getPcbdb().getCurrentUser().get_id_sup();
students_ids = new Vector<Integer>();
for(Map.Entry<Integer,Vector<Integer>> entry : ids_stu_sup.entrySet()) {
Integer id_stu = entry.getKey();
students_ids.add(id_stu);
User currentUser = PCBcontext.getDevice().findUser(id_stu, -1);
User currentUser = PCBcontext.getDevice().findUser(id_stu, id_sup);
String st_name = currentUser.get_name_stu();
Bitmap st_picture = currentUser.get_bitmap_stu(getActivity());
l_students_name.add(st_name);
......@@ -161,30 +127,33 @@ public class StudentFragmentGrid extends Fragment{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
//Log.d("onitemclick", " " + pos + " pulsado");
/*
if (modoSupervisor){
// Llamo al fragment de Supervisores para cargarlos en la misma ventana
Toast.makeText(getActivity().getBaseContext(), "Modo Supervisor activado", Toast.LENGTH_SHORT).show();
PCBcontext.getDevice().setStuId(students_ids.elementAt(pos));
// Llamo al fragment de los supervisores para cargar sus datos
SupervisorFragmentGrid supervisores = (SupervisorFragmentGrid)getFragmentManager().findFragmentById(R.id.supervisores);
// Cojo el nombre y apellidos de ese estudiante
//String name_surname_st = students[pos];
supervisores.change(ids_stu_sup, pos);
} else{
*/
// Entro en pictogram con ese valor de alumno y con supervisor a null
Toast.makeText(getActivity().getBaseContext(), "Modo Supervisor desactivado", Toast.LENGTH_SHORT).show();
PCBcontext.getDevice().setLastStuId(students_ids.elementAt(pos));
PCBcontext.getDevice().setLastSupId(-1);
//Log.d(LOG_TAG, "SET id_alumno:" + students_ids.elementAt(pos) + " /id_supervisor:-1");
Intent pictogramActivity = new Intent(getActivity(), PictogramActivity.class);
startActivity(pictogramActivity);
//}
int id_sup = PCBcontext.getPcbdb().getCurrentUser().get_id_sup();
User student = null;
try {
student = PCBcontext.getDevice().findUser(students_ids.elementAt(pos), id_sup);
} catch (JSONException e) {
e.printStackTrace();
}
String jsonToken = PCBcontext.getRestapiWrapper().getToken();
progressDialog = ProgressDialog.show(getActivity(),"Cargando...",
"Cargando datos del alumno seleccionado, espere por favor...", false, false);
PCBcontext.set_user(student, jsonToken, new iImgDownloaderListener() {
@Override
public void loadComplete() {
//Vocabulary vocabulary = PCBcontext.getVocabulary();
//Log.d(LOG_TAG, "Vocabulario de tam:" + vocabulary.size());
progressDialog.dismiss();
Intent pictogramActivity = new Intent(getActivity(), PictogramActivity.class);
startActivity(pictogramActivity);
}
@Override
public void loadImg(Img image) {
}
});
}
});
} catch (JSONException e) {
......@@ -197,20 +166,4 @@ public class StudentFragmentGrid extends Fragment{
}
return v;
}
/*
public void changeSupervisorMode(boolean value){
modoSupervisor = value;
Toast.makeText(getActivity().getBaseContext(), "Modo Supervisor " + value, Toast.LENGTH_SHORT).show();
SupervisorFragmentGrid supervisores = (SupervisorFragmentGrid)getFragmentManager().findFragmentById(R.id.supervisores);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
if (supervisores.isHidden()) {
ft.show(supervisores);
} else {
ft.hide(supervisores);
}
ft.commit();
}
*/
}
......@@ -51,6 +51,11 @@ public class NetService implements Runnable, iRestapiListener {
}
@Override
public void preExecute() {
}
@Override
public void result(JSONArray result) {
}
......
......@@ -18,7 +18,7 @@
<fragment
android:layout_width="fill_parent"
android:layout_height="300px"
android:layout_height="600px"
class="com.yottacode.pictogram.gui.StudentFragmentGrid"
android:id="@+id/alumnos"
android:layout_below="@+id/logintitle"/>
......
......@@ -15,7 +15,7 @@
<GridView
android:id="@+id/tape_grid_view"
android:layout_width="860dp"
android:layout_width="560dp"
android:layout_height="85dp"
android:gravity="center"
android:numColumns="@integer/columns"
......@@ -44,8 +44,8 @@
android:src="@drawable/ic_action"
android:background="@null"
android:id="@+id/button_delete"
android:layout_below="@+id/button_tts"
android:layout_toRightOf="@+id/tape_grid_view"/>
android:layout_toRightOf="@+id/tape_grid_view"
android:layout_alignParentTop="true"/>
<GridView
android:id="@+id/panel_grid_view"
......
......@@ -37,5 +37,6 @@
<string name="systemMessage">System message</string>
<string name="noInternetConnection">There is no Internet connection. Try again later</string>
<string name="exitingApp">Exiting the app</string>
<string name="serverError">There is a server error. Try again later</string>
</resources>
......@@ -41,6 +41,7 @@
<string name="systemMessage">Mensaje del sistema</string>
<string name="noInternetConnection">No hay conexión a internet. Inténtelo más tarde</string>
<string name="exitingApp">Saliendo de la aplicación</string>
<string name="serverError">Error en el servidor de datos. Inténtelo más tarde</string>
<item type="integer" name="maxInTape">8</item>
......
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