packagecom.yottacode.pictogram.grammar;importandroid.util.Log;importcom.github.nkzawa.emitter.Emitter;importorg.json.JSONException;importorg.json.JSONObject;importcom.yottacode.pictogram.dao.Picto;importcom.yottacode.pictogram.action.Room;/**
* Websocket Vocabulary Room based on Room
* @author Fernando Martinez Santiago
* @version 1.0
*/publicclassVocabularyTalkimplementsEmitter.Listener{privatestaticfinalStringURL="vocabulary";privateRoomroom;privateVocabularyvocabulary;iVocabularyListenerlisteners[];publicVocabularyTalk(Roomroom,iVocabularyListenerlisteners[]){this.room=room;this.room.listen(URL,this);this.listeners=listeners;}privatevoidemit(iVocabularyListener.actionaction,intpicto_cat,intpicto_id,JSONObjectargs){for(iVocabularyListenerlistener:this.listeners)listener.change(action,picto_cat,picto_id,args);}@Overridepublicvoidcall(Object...args){finalStringparam_action="action";finalStringparam_attributes="attributes";finalStringparam_picto="picto";finalStringparam_picto_cat="id_cat";finalStringaction_update="update";finalStringaction_add="add";finalStringaction_delete="delete";JSONObjectmsg=(JSONObject)args[0];try{Log.d(this.getClass().getName(),"Received something");Stringaction=msg.getString(param_action).toLowerCase();Log.d(this.getClass().getName(),"- Action: "+action);JSONObjectpicto=msg.getJSONObject(param_attributes).getJSONObject(param_picto);Log.d(this.getClass().getName(),"- Picto: "+picto.toString());JSONObjectattrs_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);
}
}
}
packagecom.yottacode.pictogram.grammar;importandroid.util.Log;importcom.github.nkzawa.emitter.Emitter;importorg.json.JSONException;importorg.json.JSONObject;importcom.yottacode.pictogram.dao.Picto;importcom.yottacode.pictogram.action.Room;/**
* Websocket Vocabulary Room based on Room
* @author Fernando Martinez Santiago
* @version 1.0
*/publicclassVocabularyTalkimplementsEmitter.Listener{privatestaticfinalStringURL="vocabulary";privateRoomroom;privateVocabularyvocabulary;iVocabularyListenerlisteners[];publicVocabularyTalk(Roomroom,iVocabularyListenerlisteners[]){this.room=room;this.room.listen(URL,this);this.listeners=listeners;}privatevoidemit(iVocabularyListener.actionaction,intpicto_cat,intpicto_id,JSONObjectargs){for(iVocabularyListenerlistener:this.listeners)listener.change(action,picto_cat,picto_id,args);}@Overridepublicvoidcall(Object...args){finalStringparam_action="action";finalStringparam_attributes="attributes";finalStringparam_picto="picto";finalStringparam_picto_cat="id_cat";finalStringaction_update="update";finalStringaction_add="add";finalStringaction_delete="delete";JSONObjectmsg=(JSONObject)args[0];try{Stringaction=msg.getString(param_action).toLowerCase();JSONObjectpicto=msg.getJSONObject(param_attributes).getJSONObject(param_picto);JSONObjectattrs_picto=picto.getJSONObject(param_attributes);intpicto_id=picto.getInt(param_picto);intpicto_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(JSONExceptione){Log.e(this.getClass().getCanonicalName(),e.getClass().getCanonicalName()+"--"+e);}}}