Commit ef5d94ba by Jose Antonio

Merge remote-tracking branch 'origin/develop' into develop

parents 17909849 95439012
......@@ -81,6 +81,8 @@ public class PCBDBHelper extends SQLiteOpenHelper {
Log.e(LOG_TAG, e.getMessage() + " BAD FORMED JSON: " + cursor.getString(5));
System.exit(-1);
}
}else{
Log.e(LOG_TAG,"NO HAY USER EN USER DETAIL CON ESE ID: "+sup);
}
cursor.close();
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
......@@ -170,10 +172,6 @@ public class PCBDBHelper extends SQLiteOpenHelper {
e.printStackTrace();
Log.e(LOG_TAG,"Error setting active scene:"+e.getMessage());
}
/*Cursor cursor = getReadableDatabase().rawQuery("SELECT * FROM scene",null);
Log.i(LOG_TAG,"tam scen: "+cursor.getCount());
cursor.close();*/
}
/**
......
......@@ -59,8 +59,6 @@ public class Picto extends Img {
public static String LEGEND = "legend";
public static String URI_SOUND = "uri_sound";
public static String USER_AVATAR = "user_avatar";
//public static String SCENE = "scene";
}
public final static class JSON_ATTTR_LEGEND_VALUES {
......@@ -110,7 +108,6 @@ public class Picto extends Img {
.put(JSON_ATTTRS.STUPICTO_ID,stupicto_id)
.put(JSON_ATTTRS.EXPRESSION,translation)
.put(JSON_ATTTRS.USER_AVATAR,user_avatar)
/*.put(JSON_ATTTRS.SCENE,scene)*/
);
}
public Picto(int id, String url,String translation, String attributes) throws JSONException {
......@@ -350,14 +347,6 @@ public class Picto extends Img {
/**
*
* @return the id of an scene of a picto
*/
/*public int get_id_scene() throws JSONException {
return this.attributes.getInt(JSON_ATTTRS.SCENE);
}
*/
/**
*
* @return the row of the picto
*/
public int get_row() {
......
......@@ -30,7 +30,7 @@ public class User {
public final static class JSON_STUDENT_ATTTRS{
public enum delivery {clean, one, many}
static String CATEGORIES = "categories";
static String ID_ACTIVE_SCENE = "id_active_scene";
static String INPUT_FEEDBACK = "input_feedback";
static String INPUT_SELECTION = "input_selection";
static String PICTOGRAM_SIZE ="size";
......@@ -247,19 +247,20 @@ public class User {
}
/**
*
* @return true if the collection is organized by categories (default: True)
* @return The id of the active scene of this student
*/
public boolean has_categories() {
return this.attributes_stu.optBoolean(JSON_STUDENT_ATTTRS.CATEGORIES, true);
public int get_active_scene() {
try {
return (int) this.attributes_stu.get(JSON_STUDENT_ATTTRS.ID_ACTIVE_SCENE);
} catch (JSONException e) {
e.printStackTrace();
}
return -1;
}
/**
* Change the value wich knows if the user has categories or not
*/
public void set_has_categories(boolean categories){
public void set_active_scene(int id) {
try {
this.attributes_stu.put(JSON_STUDENT_ATTTRS.CATEGORIES, categories);
this.attributes_stu.put(JSON_STUDENT_ATTTRS.ID_ACTIVE_SCENE,id);
} catch (JSONException e) {
e.printStackTrace();
}
......
......@@ -95,7 +95,7 @@ public class Vocabulary implements Iterable<Picto> {
JSONObject attrs_picto = args.getJSONObject("attributes");
attrs_picto.put(Picto.JSON_ATTTRS.STUPICTO_ID,args.getInt("id"));
Picto newPicto=new Picto(picto_id, uri, attrs_picto);
Picto prev_picto=/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().isHas_categories()
Picto prev_picto=/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().has_categories()
? find_picto(newPicto.get_category(), newPicto.get_row(),newPicto.get_column())
: find_picto(newPicto.getFreeRow(),newPicto.getFreeColumn());
......@@ -192,9 +192,9 @@ public class Vocabulary implements Iterable<Picto> {
JSONObject picto, attributes;
JSONObject stupicto = null;
try {
//PCBcontext.getPcbdb().getCurrentUser().set_has_categories(result.getBoolean("categories"));
setHas_categories(result.getBoolean("categories"));
setId_scene(result.getInt("id"));
PCBcontext.getPcbdb().getCurrentUser().set_active_scene(result.getInt("id"));
JSONArray stu_pictos = result.getJSONArray("pictos"); //Obtengo el JSONArray de los pictos
Picto[] pictos = new Picto[stu_pictos.length()];
......@@ -250,7 +250,6 @@ public class Vocabulary implements Iterable<Picto> {
for (Picto updated_picto: updated_collection) {
LinkedList<Picto> pictos_cat;
//Log.i("TAG_PRUEBAS","URL: "+updated_picto.get_url());
Picto picto = new Picto(updated_picto.get_id(),
updated_picto.get_url(),
updated_picto.get_translation(),
......@@ -399,7 +398,7 @@ public class Vocabulary implements Iterable<Picto> {
* @return list of pictos which should be selectable at the beginning of a sentence. Empty categories are removed
*/
public LinkedList<Picto> startSentence(){
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().isHas_categories()) {
if (PCBcontext.getVocabulary().has_categories()) {
return this.pictos.get(new Integer(Picto.NO_CATEGORY));
} else {
LinkedList<Picto> freePictos = new LinkedList<>();
......@@ -438,7 +437,7 @@ public class Vocabulary implements Iterable<Picto> {
public void saveLocalPicto(String url, String exp, int cat, int coord_x, int coord_y, int free_category_coord_x, int free_category_coord_y,String user_avatar, String path_sound,final iLocalPicto listener) {
Picto prev_picto=/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().isHas_categories() ? find_picto(cat, coord_x,coord_y) : find_picto(free_category_coord_x,free_category_coord_y); //¿estamos reemplazanddo un picto que ya existe?
Picto prev_picto=PCBcontext.getVocabulary().has_categories() ? find_picto(cat, coord_x,coord_y) : find_picto(free_category_coord_x,free_category_coord_y); //¿estamos reemplazanddo un picto que ya existe?
if (prev_picto!=null) { //El picto ya existe
removePicto(prev_picto.get_category(),prev_picto.get_id()); //borramos el picto local actual
......@@ -508,7 +507,7 @@ public class Vocabulary implements Iterable<Picto> {
return vocabulary;
}
public boolean isHas_categories() {
public boolean has_categories() {
return has_categories;
}
......
......@@ -150,8 +150,7 @@ public class PictoUploader {
JSONObject json_attrs =new JSONObject().put("status",picto.get_status());
if (picto.get_user_avatar()!=null) json_attrs.put(Picto.JSON_ATTTRS.USER_AVATAR,picto.get_user_avatar());
/*json_attrs.put("scene",picto.get_id_scene());*/
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().isHas_categories())
if (PCBcontext.getVocabulary().has_categories())
json_attrs.put(Picto.JSON_ATTTRS.CATEGORY, picto.get_category())
.put(Picto.JSON_ATTTRS.COLUMN, picto.get_column())
.put(Picto.JSON_ATTTRS.ROW, picto.get_row());
......@@ -159,7 +158,7 @@ public class PictoUploader {
json_attrs.put(Picto.JSON_ATTTRS.CATEGORY, picto.NO_CATEGORY)
.put(Picto.JSON_ATTTRS.FREE_COLUMN, picto.getFreeColumn())
.put(Picto.JSON_ATTTRS.FREE_ROW, picto.getFreeRow());
params.put("json", new JSONObject().put("attributes",json_attrs).put("id_scene",50).toString());
params.put("json", new JSONObject().put("attributes",json_attrs).put("id_scene",PCBcontext.getPcbdb().getActiveSceneForStudent(PCBcontext.getPcbdb().getCurrentUser().get_id_stu())).toString());
} catch (JSONException e) {
e.printStackTrace();
......
......@@ -53,16 +53,17 @@ public class VocabularyTalk implements Emitter.Listener {
JSONObject picto_stupicto = stu_picto.optJSONObject(param_picto);
int picto_id = picto_stupicto.getInt(param_picto_id);
int picto_cat = attrs_stu_picto!=null ? attrs_stu_picto.optInt(param_picto_cat, Picto.NO_CATEGORY) : 0;
PCBcontext.getNetService().nextSynchro(new Date().getTime()+PCBcontext.getNetService().getSynchroTimingLength()*2); //nos saltamos una sincronización para evitar que llegue antes que los websockets
Log.i(LOG_TAG, "Received message '" + action +
"' for picto " + picto_id + " (cat " + picto_cat + ", picto: " + picto_stupicto);
for (iVocabularyListener listener: this.listeners)
listener.change(action.equals(action_update) ? iVocabularyListener.action.update
: action.equals(action_update_category) ? iVocabularyListener.action.update_category
: action.equals(action_add) ? iVocabularyListener.action.add
: iVocabularyListener.action.delete
, picto_cat, picto_id, stu_picto);
if(PCBcontext.getVocabulary().getId_scene() == PCBcontext.getPcbdb().getCurrentUser().get_active_scene()) {
PCBcontext.getNetService().nextSynchro(new Date().getTime() + PCBcontext.getNetService().getSynchroTimingLength() * 2); //nos saltamos una sincronización para evitar que llegue antes que los websockets
Log.i(LOG_TAG, "Received message '" + action +
"' for picto " + picto_id + " (cat " + picto_cat + ", picto: " + picto_stupicto);
for (iVocabularyListener listener : this.listeners)
listener.change(action.equals(action_update) ? iVocabularyListener.action.update
: action.equals(action_update_category) ? iVocabularyListener.action.update_category
: action.equals(action_add) ? iVocabularyListener.action.add
: iVocabularyListener.action.delete
, picto_cat, picto_id, stu_picto);
}
} catch (JSONException e) {
Log.e(LOG_TAG, e.getClass().getCanonicalName() + "--" + e);
}
......
......@@ -77,8 +77,8 @@ public final class PCBcontext {
@Override
public void change(User updatedStudent) {
PCBcontext.getDevice().insertUser(updatedStudent);
if (updatedStudent.is_picto_size_big()!=getPcbdb().getCurrentUser().is_picto_size_big() /*|| updatedStudent.has_categories()!=getPcbdb().getCurrentUser().has_categories()*/
|| PCBcontext.getVocabulary().isHas_categories() != vocabulary.isHas_categories() || PCBcontext.getVocabulary().getId_scene()!= vocabulary.getId_scene())
if (updatedStudent.is_picto_size_big()!=getPcbdb().getCurrentUser().is_picto_size_big() || PCBcontext.getVocabulary().has_categories() != vocabulary.has_categories()
|| PCBcontext.getVocabulary().getId_scene()!= PCBcontext.getPcbdb().getCurrentUser().get_active_scene())
PCBcontext.getNetService().restart_app(false);
else {
PCBcontext.getPcbdb().setCurrentUser(updatedStudent);
......
......@@ -82,7 +82,7 @@ public class PictoMenu {
public void addPicto(int row, int col, int cat, int source) {
//Enviar al PictogramActivity los datos necesarios para crear el picto despues
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().isHas_categories()) {
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().has_categories()) {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.CATEGORY, cat);
activity.getIntent().putExtra(Picto.JSON_ATTTRS.ROW, row);
activity.getIntent().putExtra(Picto.JSON_ATTTRS.COLUMN, col);
......@@ -108,7 +108,7 @@ public class PictoMenu {
intent.putExtra(ID_PICTO_IMAGE,id_picto);
//Enviar al PictogramActivity los datos necesarios para editar el picto despues
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().isHas_categories()) {
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().has_categories()) {
intent.putExtra(Picto.JSON_ATTTRS.CATEGORY, cat);
intent.putExtra(Picto.JSON_ATTTRS.ROW, row);
intent.putExtra(Picto.JSON_ATTTRS.COLUMN, col);
......
......@@ -41,16 +41,13 @@ import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.yottacode.net.RestapiWrapper;
import com.yottacode.pictogram.action.PictosAction;
import com.yottacode.pictogram.action.TalkAction;
import com.yottacode.pictogram.dao.PCBDBHelper;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.grammar.Vocabulary;
import com.yottacode.pictogram.grammar.iLocalPicto;
import com.yottacode.pictogram.net.ImgDownloader;
import com.yottacode.pictogram.net.NetService;
import com.yottacode.pictogram.net.PictoUploader;
import com.yottacode.pictogram.net.websockets.ActionTalk;
import com.yottacode.pictogram.net.websockets.VocabularyTalk;
......@@ -164,11 +161,11 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
this.vocabulary.listen(PCBcontext.getRoom(), this, new ActionTalk.iActionListener() {
@Override
public void action(action action, int picto_cat, int picto_id, JSONObject msg) {
if(msg == null)
Log.i("TAG_PRUEBAS","No viene nada de mensaje");
/* if(msg == null)
Log.i("TAG_PRUEBAS","No viene nada de mensaje");*/
Log.i(this.getClass().getCanonicalName(), action + " from " + picto_cat + "," + picto_id + " catched");
if (action==ActionTalk.iActionListener.action.show) {
Log.i("TAG_PRUEBAS","Llega aqui");
/*Log.i("TAG_PRUEBAS","Llega aqui");
Log.i("TAG_PRUEBAS","show message received:"+msg.toString());
try {
//Log.i("TAG_PRUEBAS","show message received:"+msg.get("expression"));
......@@ -188,7 +185,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
fragmentTransaction.add(R.id.fragment_container, fragment, "ALERTA");
fragmentTransaction.commit();
mainLayout.setEnabled(false); //Desactivar el fondo
mainLayout.setEnabled(false); //Desactivar el fondo*/
}
else if (PCBcontext.getPcbdb().getCurrentUser().is_mirror_on()) {
......@@ -562,7 +559,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
Iterator<Picto> pictos=list.iterator();
while (pictos.hasNext()) {
Picto p= pictos.next();
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().isHas_categories()) {
if (/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/PCBcontext.getVocabulary().has_categories()) {
if (p.get_column() != -1 && p.get_row() != -1
&& p.get_column() < maxRows && p.get_row() < maxColumns) {
mp[p.get_column()][p.get_row()] = p;
......@@ -905,7 +902,7 @@ Log.e(LOG_TAG,"AUDIO:"+(audioFile!=null)+":"+p.get_audioPath());
Picto p = getCurrentPictoGridAdapter().getItem(position);
if (p == null) {
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria
if (getCurrentCategory() != null || /*!PCBcontext.getPcbdb().getCurrentUser().has_categories()*/!PCBcontext.getVocabulary().isHas_categories()) {
if (getCurrentCategory() != null || /*!PCBcontext.getPcbdb().getCurrentUser().has_categories()*/!PCBcontext.getVocabulary().has_categories()) {
int cat = getCurrentCategory() != null ? currentCategory.get_id() : Picto.NO_CATEGORY;
new PictoMenu(PictogramActivity.this).createMenuForNewPicto(position % maxColumns, (int) (position / maxColumns), cat);
} else
......
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