Soporte para pictogramas repetidos incluido.

Optimización de VocabularyTalk
parent 636abc32
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
compileSdkVersion 23 compileSdkVersion 21
buildToolsVersion "23.0.1" buildToolsVersion "21.1.2"
defaultConfig { defaultConfig {
applicationId "com.yottacode.pictogrammar" applicationId "com.yottacode.pictogrammar"
minSdkVersion 19 minSdkVersion 19
......
...@@ -124,9 +124,8 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular ...@@ -124,9 +124,8 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
private int find_picto_index(int pic_cat, int pic_id) { private int find_picto_index(int pic_cat, int pic_id) {
LinkedList<Picto> pictos_cat=this.pictos.get(pic_cat); LinkedList<Picto> pictos_cat=this.pictos.get(pic_cat);
int index=-1; int index=-1;
for (int i=0; i<pictos_cat.size() && index==-1; i++) { for (int i=0; i<pictos_cat.size() && index==-1; i++)
if (pictos_cat.get(i).get_id()==pic_id) index=i; if (pictos_cat.get(i).get_id()==pic_id) index=i;
}
return index; return index;
} }
/** /**
...@@ -136,10 +135,12 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular ...@@ -136,10 +135,12 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
public void removePicto(int pic_cat, int pic_id){ public void removePicto(int pic_cat, int pic_id){
LinkedList<Picto> pictos_cat=this.pictos.get(pic_cat); LinkedList<Picto> pictos_cat=this.pictos.get(pic_cat);
int index = find_picto_index(pic_cat, pic_id); int index = find_picto_index(pic_cat, pic_id);
if (index>0) { //puede ocurrir que se intente borrar un pictograma dos veces if (index>=0) { //puede ocurrir que se intente borrar un pictograma dos veces
pictos_cat.remove(); pictos_cat.remove();
PCBcontext.getPcbdb().deletePicto(pic_id); PCBcontext.getPcbdb().deletePicto(pic_id);
} }
else
Log.i(this.getClass().getCanonicalName(),"Trying to delete an unregistered picto:"+pic_id+" cat:"+pic_cat);
} }
/** /**
...@@ -151,11 +152,13 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular ...@@ -151,11 +152,13 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
public void modifyAttsPicto(int pic_cat, int pic_id, JSONObject attrs) { public void modifyAttsPicto(int pic_cat, int pic_id, JSONObject attrs) {
int index=find_picto_index(pic_cat, pic_id); int index=find_picto_index(pic_cat, pic_id);
if (index>0) { //puede ocurrir que se intente modificar un pictograma que fue borrado if (index>=0) { //puede ocurrir que se intente modificar un pictograma que fue borrado
Picto picto = this.pictos.get(pic_cat).get(index); Picto picto = this.pictos.get(pic_cat).get(index);
picto.set_json_attr(attrs); picto.set_json_attr(attrs);
PCBcontext.getPcbdb().modifyPicto(pic_id, attrs.toString()); PCBcontext.getPcbdb().modifyPicto(pic_id, attrs.toString());
} }
else
Log.i(this.getClass().getCanonicalName(),"Trying to modify an unregistered picto:"+pic_id+" cat:"+pic_cat);
} }
/** /**
......
package com.yottacode.pictogram.grammar; import android.util.Log; import com.github.nkzawa.emitter.Emitter; import org.json.JSONException;import org.json.JSONObject; import com.yottacode.pictogram.dao.Picto;import com.yottacode.pictogram.action.Room; /** * Websocket Vocabulary Room based on Room * @author Fernando Martinez Santiago * @version 1.0 */public class VocabularyTalk implements Emitter.Listener { private static final String URL ="vocabulary"; private Room room; private Vocabulary vocabulary; iVocabularyListener listeners[]; public VocabularyTalk(Room room, iVocabularyListener listeners[]) { this.room = room; this.room.listen(URL, this); this.listeners=listeners; } private void emit(iVocabularyListener.action action, int picto_cat, int picto_id, JSONObject args) { for (iVocabularyListener listener: this.listeners) listener.change(action, picto_cat, picto_id, args); } @Override public void call(Object... args) { final String param_action="action"; final String param_attributes="attributes"; final String param_picto="picto"; final String param_picto_cat="id_cat"; final String action_update="update"; final String action_add="add"; final String action_delete="delete"; JSONObject msg = (JSONObject) args[0]; try { Log.d(this.getClass().getName(), "Received something"); String action = msg.getString(param_action).toLowerCase(); Log.d(this.getClass().getName(), "- Action: " + action); JSONObject picto= msg.getJSONObject(param_attributes).getJSONObject(param_picto); Log.d(this.getClass().getName(), "- Picto: " + picto.toString()); JSONObject attrs_picto = picto.getJSONObject(param_attributes); Log.d(this.getClass().getName(), "- Attrs: " + attrs_picto.toString()); // Update a picto // Perfect in categories // In a picto, it refresh the vocabulary and open the main categories if (action.equals(action_update)) { int picto_id = picto.getInt(param_picto); Log.d(this.getClass().getName(), "- Picto ID: " + picto_id); int picto_cat = attrs_picto.optInt(param_picto_cat, Picto.NO_CATEGORY); Log.d(this.getClass().getName(), "- Picto Cat: " + picto_cat); // TODO Here proccess the events recieved via websocket by the dashboard Log.d(this.getClass().getName(), "Received message '" + action + "' for picto " + picto_id + " (cat " + picto_cat + ")"); //Hashtable<iVocabularyListener.arg, Object> atts = new Hashtable<>(1); //atts.put(iVocabularyListener.arg.attributes, attrs_picto); this.emit(iVocabularyListener.action.update, picto_cat, picto_id, attrs_picto); } // Add a picto // The dashboard interts it in hide form and when the user modify the view property // the activity launch an error and go back to the StudentFragment else if (action.equals(action_add)) { int picto_id = picto.getJSONObject("picto").getInt("id"); Log.d(this.getClass().getName(), "- Picto ID: " + picto_id); int picto_cat = attrs_picto.optInt(param_picto_cat, Picto.NO_CATEGORY); Log.d(this.getClass().getName(), "- Picto Cat: " + picto_cat); // TODO Here proccess the events recieved via websocket by the dashboard Log.d(this.getClass().getName(), "Received message '" + action + "' for picto " + picto_id + " (cat " + picto_cat + ")"); final String jexpression="expression"; final String jexpression_text="text"; final String juri="uri"; String text= picto.getJSONObject(jexpression).getString(jexpression_text); String uri=picto.getJSONObject("picto").getString(juri); //Hashtable<iVocabularyListener.arg,Object> atts=new Hashtable<>(3); //atts.put(iVocabularyListener.arg.url,uri); //atts.put(iVocabularyListener.arg.expression,text); //atts.put(iVocabularyListener.arg.attributes, attrs_picto); this.emit(iVocabularyListener.action.add, picto_cat, picto_id, picto); } // Delete a picto // Exit the activity going to StudentFragment else if (action.equals(action_delete)) { int picto_id = picto.getInt(param_picto); Log.d(this.getClass().getName(), "- Picto ID: " + picto_id); int picto_cat = attrs_picto.optInt(param_picto_cat, Picto.NO_CATEGORY); Log.d(this.getClass().getName(), "- Picto Cat: " + picto_cat); // TODO Here proccess the events recieved via websocket by the dashboard Log.d(this.getClass().getName(), "Received message '" + action + "' for picto " + picto_id + " (cat " + picto_cat + ")"); this.emit(iVocabularyListener.action.delete, picto_cat, picto_id, null); } } catch (JSONException e) { Log.e(this.getClass().getCanonicalName(), e.getClass().getCanonicalName() + "--" + e); // System.exit(-1); } } } package com.yottacode.pictogram.grammar; import android.util.Log; import com.github.nkzawa.emitter.Emitter; import org.json.JSONException;import org.json.JSONObject; import com.yottacode.pictogram.dao.Picto;import com.yottacode.pictogram.action.Room; /** * Websocket Vocabulary Room based on Room * @author Fernando Martinez Santiago * @version 1.0 */public class VocabularyTalk implements Emitter.Listener { private static final String URL ="vocabulary"; private Room room; private Vocabulary vocabulary; iVocabularyListener listeners[]; public VocabularyTalk(Room room, iVocabularyListener listeners[]) { this.room = room; this.room.listen(URL, this); this.listeners=listeners; } private void emit(iVocabularyListener.action action, int picto_cat, int picto_id, JSONObject args) { for (iVocabularyListener listener: this.listeners) listener.change(action, picto_cat, picto_id, args); } @Override public void call(Object... args) { final String param_action="action"; final String param_attributes="attributes"; final String param_picto="picto"; final String param_picto_cat="id_cat"; final String action_update="update"; final String action_add="add"; final String action_delete="delete"; JSONObject msg = (JSONObject) args[0]; try { String action = msg.getString(param_action).toLowerCase(); JSONObject picto= msg.getJSONObject(param_attributes).getJSONObject(param_picto); JSONObject attrs_picto = picto.getJSONObject(param_attributes); int picto_id = picto.getInt(param_picto); int picto_cat = attrs_picto.optInt(param_picto_cat, Picto.NO_CATEGORY); Log.d(this.getClass().getName(), "Received message '" + action + "' to picto " + picto_id + " (cat " + picto_cat + ", attrs: "+attrs_picto); this.emit( action.equals(action_update) ? iVocabularyListener.action.update : action.equals(action_add) ? iVocabularyListener.action.add : iVocabularyListener.action.delete , picto_cat, picto_id, attrs_picto); } catch (JSONException e) { Log.e(this.getClass().getCanonicalName(), e.getClass().getCanonicalName() + "--" + e); } }}
\ No newline at end of file \ No newline at end of file
......
...@@ -118,7 +118,7 @@ INSERT INTO `picto_core_cat` (`id`, `id_pic`, `id_cat_pic`, `coord_x`, `coord_y` ...@@ -118,7 +118,7 @@ INSERT INTO `picto_core_cat` (`id`, `id_pic`, `id_cat_pic`, `coord_x`, `coord_y`
(156, 5393, NULL, 4, 0, '#F4FA58'), -- Furniture (156, 5393, NULL, 4, 0, '#F4FA58'), -- Furniture
(157, 11368,NULL, 4, 1, '#F4FA58'), -- Kitchen items (157, 11368,NULL, 4, 1, '#F4FA58'), -- Kitchen items
(159, 2547,NULL, 4, 9, '#2E9AFE'), -- Articles and determinants (159, 2547,NULL, 4, 9, '#2E9AFE'), -- Articles and determinants
(190, 4687,NULL, 4, 7, '#F4FA58'), -- Body parts (190, 4721,NULL, 4, 7, '#F4FA58'), -- Body parts
(191, 50956,NULL, 4, 8, '#F4FA58'), -- Stuff (191, 50956,NULL, 4, 8, '#F4FA58'), -- Stuff
(192, 51336,NULL, 1, 7, '#008000'), -- Animals_and_plants (192, 51336,NULL, 1, 7, '#008000'), -- Animals_and_plants
(25, 676, 376, 2, 2, NULL), -- Desiring.want (25, 676, 376, 2, 2, NULL), -- Desiring.want
...@@ -301,7 +301,9 @@ INSERT INTO `picto_core_cat` (`id`, `id_pic`, `id_cat_pic`, `coord_x`, `coord_y` ...@@ -301,7 +301,9 @@ INSERT INTO `picto_core_cat` (`id`, `id_pic`, `id_cat_pic`, `coord_x`, `coord_y`
(220, 1206,51336, 1, 8, NULL), -- Animals_and_plants.cat (220, 1206,51336, 1, 8, NULL), -- Animals_and_plants.cat
(221, 853,51336, 1, 9, NULL), -- Animals_and_plants.bird (221, 853,51336, 1, 9, NULL), -- Animals_and_plants.bird
(222, 57236,51336, 1, 5, NULL), -- Animals_and_plants.tree (222, 57236,51336, 1, 5, NULL), -- Animals_and_plants.tree
(223, 57384,51336, 1, 6, NULL); -- Animals_and_plants.plant (223, 57384,51336, 1, 6, NULL), -- Animals_and_plants.plant
(224, 50956,50956, 4, 8, '#F4FA58'); -- Stuff.stuff
...@@ -868,9 +870,9 @@ UPDATE picto_exp SET text='encender' WHERE id_pic=325 and lang='es-es'; ...@@ -868,9 +870,9 @@ UPDATE picto_exp SET text='encender' WHERE id_pic=325 and lang='es-es';
UPDATE picto_exp SET text='turn off' WHERE id_pic=328 and lang='en-us'; UPDATE picto_exp SET text='turn off' WHERE id_pic=328 and lang='en-us';
UPDATE picto_exp SET text='turn off' WHERE id_pic=328 and lang='en-gb'; UPDATE picto_exp SET text='turn off' WHERE id_pic=328 and lang='en-gb';
UPDATE picto_exp SET text='apagar' WHERE id_pic=328 and lang='es-es'; UPDATE picto_exp SET text='apagar' WHERE id_pic=328 and lang='es-es';
UPDATE picto_exp SET text='Body' WHERE id_pic=4687 and lang='en-us'; UPDATE picto_exp SET text='Body' WHERE id_pic=4721 and lang='en-us';
UPDATE picto_exp SET text='Body' WHERE id_pic=4687 and lang='en-gb'; UPDATE picto_exp SET text='Body' WHERE id_pic=4721 and lang='en-gb';
UPDATE picto_exp SET text='Cuerpo' WHERE id_pic=4687 and lang='es-es'; UPDATE picto_exp SET text='Cuerpo' WHERE id_pic=4721 and lang='es-es';
UPDATE picto_exp SET text='Stuff' WHERE id_pic=50956 and lang='en-us'; UPDATE picto_exp SET text='Stuff' WHERE id_pic=50956 and lang='en-us';
UPDATE picto_exp SET text='Stuff' WHERE id_pic=50956 and lang='en-gb'; UPDATE picto_exp SET text='Stuff' WHERE id_pic=50956 and lang='en-gb';
UPDATE picto_exp SET text='Cosas' WHERE id_pic=50956 and lang='es-es'; UPDATE picto_exp SET text='Cosas' WHERE id_pic=50956 and lang='es-es';
......
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