bugs #556 and #557 fixed from PCB side

parent 4c4e8f6b
......@@ -41,9 +41,9 @@ public abstract class PictoAction extends Action {
}
@Override
public JSONObject get_json(){
final String param_picto="picto";
final String param_stu_picto="stu_picto";
try {
return super.get_json().put(param_picto, this.get_json_picto());
return super.get_json().put(param_stu_picto, this.get_json_picto());
}catch(JSONException e) {
Log.e(this.getClass().getCanonicalName(),e.getLocalizedMessage());
return null;
......@@ -71,4 +71,4 @@ public abstract class PictoAction extends Action {
.put(param_attrs, attributes);
return subPicto;
}
}
\ No newline at end of file
}
......@@ -244,6 +244,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
values.put("translation",picto.get_translation());
values.put("attributes",picto.get_json_attrs());
db.insert("collection_detail", null, values);
Log.i(this.getClass().getCanonicalName(),"Picto added:"+picto.get_translation());
db.close();
}
......@@ -290,4 +291,4 @@ public class PCBDBHelper extends SQLiteOpenHelper {
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
\ No newline at end of file
}
......@@ -237,12 +237,11 @@ public class UserLogin {
PCBcontext.getDevice().insertUser(student);
progressDialog.dismiss();
activity.startActivity(pictogramActivity);
}
@Override
public void loadImg(Img image) {
}
public void loadImg(Img image) {}
@Override
public void error(Exception e) {
......
......@@ -255,6 +255,10 @@ public class Vocabulary implements Iterable<Picto> {
PCBcontext.getPcbdb().addPicto(pic);
}
public void setImgDownloaderListener(iImgDownloaderListener listener) {
this.imgListener=listener;
}
/**
*
......@@ -374,7 +378,6 @@ public class Vocabulary implements Iterable<Picto> {
}
@Override
public void loadImg(Img image) {
}
@Override
public void error(Exception e) {
......
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; iVocabularyListener listeners[]; public VocabularyTalk(Room room, iVocabularyListener listeners[]) { this.room = room; this.room.listen(URL, this); this.listeners=listeners; } @Override public void call(Object... args) { final String param_action="action"; final String param_attributes="attributes"; final String param_picto="picto"; final String param_stu_picto="stu_picto"; final String param_picto_id="id"; 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.i(this.getClass().getName(), "raw Received message " +msg.toString()); String action = msg.getString(param_action).toLowerCase(); JSONObject stu_picto= msg.getJSONObject(param_attributes).getJSONObject(param_stu_picto); JSONObject attrs_stu_picto = stu_picto.optJSONObject(param_attributes); JSONObject attrs_picto = stu_picto.optJSONObject(param_picto); int picto_id = attrs_picto.getInt(param_picto_id); int picto_cat = attrs_stu_picto!=null ? attrs_stu_picto.optInt(param_picto_cat, Picto.NO_CATEGORY) : 0; Log.i(this.getClass().getName(), "Received message '" + action + "' for picto " + picto_id + " (cat " + picto_cat + ", attrs: " + attrs_picto); for (iVocabularyListener listener: this.listeners) listener.change(action.equals(action_update) ? iVocabularyListener.action.update : action.equals(action_add) ? iVocabularyListener.action.add : iVocabularyListener.action.delete , picto_cat, picto_id, stu_picto); } catch (JSONException e) { Log.e(this.getClass().getCanonicalName(), e.getClass().getCanonicalName() + "--" + e); } }}
\ No newline at end of file
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;
import com.yottacode.pictogram.tools.PCBcontext;
/**
* 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;
iVocabularyListener listeners[];
public VocabularyTalk(Room room, iVocabularyListener listeners[]) {
this.room = room;
this.room.listen(URL, this);
this.listeners=listeners;
}
@Override
public void call(Object... args) {
final String param_action="action";
final String param_attributes="attributes";
final String param_picto="picto";
final String param_stu_picto="stu_picto";
final String param_picto_id="id";
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.i(this.getClass().getName(), "raw Received message " +msg.toString());
String action = msg.getString(param_action).toLowerCase();
JSONObject stu_picto= msg.getJSONObject(param_attributes).getJSONObject(param_stu_picto);
JSONObject attrs_stu_picto = stu_picto.optJSONObject(param_attributes);
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;
Log.i(this.getClass().getName(), "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_add) ? iVocabularyListener.action.add
: iVocabularyListener.action.delete
, picto_cat, picto_id, stu_picto);
} catch (JSONException e) {
Log.e(this.getClass().getCanonicalName(), e.getClass().getCanonicalName() + "--" + e);
}
}
}
......@@ -4,6 +4,7 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.widget.Toast;
import com.google.gson.JsonObject;
import com.koushikdutta.ion.Ion;
......@@ -42,6 +43,7 @@ public class PictoUploader {
private int uploadImg( Img img) throws UnsupportedEncodingException {
int img_id;
Bitmap bmp=null;
Response<JsonObject> response=null;
if (!img.get_filetype().equalsIgnoreCase("png"))
throw new UnsupportedEncodingException("Extension "+img.get_filetype()+" is not supported. Only png files");
Ion ion = Ion.getDefault(PCBcontext.getContext());
......@@ -49,18 +51,13 @@ public class PictoUploader {
try {
bmp=img.get_bitmap(PCBcontext.getContext());
} catch (IOException e) {
Log.e(Img.class.getCanonicalName(), "Error when decoding "+img.file_name());
}
Log.i(this.getClass().getCanonicalName(), "Uploading Picto img " + img.file_name() + " from " + img.get_type() + "- Size:" + bmp.getWidth() + " " + bmp.getHeight());
Log.i(this.getClass().getCanonicalName(), "Uploading Picto img " + img.file_name() + " from " + img.get_type() + "- Size:" + bmp.getWidth() + " " + bmp.getHeight());
File file = img.file(PCBcontext.getContext());
Response<JsonObject> response=null;
try {
response=ion.with(PCBcontext.getContext())
response=ion.with(PCBcontext.getContext())
.load("POST", PCBcontext.getContext().getResources().getString(R.string.server) + "/picto/upload")
.setMultipartParameter("filename", Integer.toString(img.get_id()))
.setMultipartParameter("extension", img.get_filetype())
......@@ -90,7 +87,12 @@ public class PictoUploader {
Log.e(this.getClass().getCanonicalName(), "Image upload error: " + e.getMessage()+
(response == null ? -1 : response.getHeaders().code()));
img_id=-1;
} catch (IOException e) {
Log.e(Img.class.getCanonicalName(), "Error when decoding "+img.file_name());
GUITools.show_alert(PCBcontext.getContext(), R.string.imguserLoadingErrMsg);
img_id=-1;
}
// ion.dump();
return img_id;
}
......
......@@ -23,7 +23,9 @@
<string name="userLoadingTxt">Loading</string>
<string name="userLoadingMsg">Loading students. Please wait.</string>
<string name="imguserLoadingMsg">Loading images students. Please wait.</string>
<string name="noStudentsError">User without any student available</string>
<string name="imguserLoadingErrMsg">Invalid user image.</string>
<string name="noStudentsError">User without any student available</string>
<!-- Alert dialogs -->
<string name="exitPictogram">Exit Pictogram</string>
<string name="enterEscapeCode">Type escape code</string>
......
......@@ -21,7 +21,9 @@
<string name="loginErrorTxt">Login</string>
<string name="loginErrorMsg">El usuario no existe o la contraseña indicada no es correcta. Inténtelo de nuevo.</string>
<string name="imguserLoadingMsg">Cargando imágenes de los alumnos. Por favor espere.</string>
<string name="noStudentsError">El usuario indicado no tiene alumnos asignados. Asigne estudiantes desde el panel de control</string>
<string name="imguserLoadingErrMsg">Imagen con formato no válido.</string>
<string name="noStudentsError">El usuario indicado no tiene alumnos asignados. Asigne estudiantes desde el panel de control</string>
<!-- Alert dialogs -->
<string name="exitPictogram">Salir de Pictogram</string>
......
......@@ -24,7 +24,9 @@
<string name="userLoadingTxt">Cargando</string>
<string name="userLoadingMsg">Cargando alumnos. Por favor espere.</string>
<string name="imguserLoadingMsg">Cargando imágenes de los alumnos. Por favor espere.</string>
<string name="noStudentsError">El usuario indicado no tiene alumnos asignados. Asigne estudiantes desde el panel de control</string>
<string name="imguserLoadingErrMsg">Imagen con formato no válido.</string>
<string name="noStudentsError">El usuario indicado no tiene alumnos asignados. Asigne estudiantes desde el panel de control</string>
<!-- Alert dialogs -->
<string name="exitPictogram">Salir de Pictogram</string>
......
......@@ -7,7 +7,7 @@ android {
defaultConfig {
applicationId "com.yottacode.tablet"
minSdkVersion 21
targetSdkVersion 24
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
......
......@@ -34,8 +34,8 @@ public class MainActivity extends Activity {
}
@Override
protected void onDestroy() {
super.onDestroy();
protected void onStop() {
super.onStop();
PCBcontext.getNetService().closeNotifyStatus();
}
......
......@@ -31,6 +31,7 @@ import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.yottacode.pictogram.net.iImgDownloaderListener;
import com.yottacode.pictogram.tablet.R;
import com.yottacode.pictogram.action.PictosAction;
import com.yottacode.pictogram.action.TalkAction;
......@@ -39,6 +40,7 @@ import com.yottacode.pictogram.grammar.Vocabulary;
import com.yottacode.pictogram.grammar.iLocalPicto;
import com.yottacode.pictogram.grammar.iVocabularyListener;
import com.yottacode.pictogram.net.PictoUploader;
import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONObject;
......@@ -101,6 +103,22 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
this.vocabulary = PCBcontext.getVocabulary();
this.vocabulary.listen(PCBcontext.getRoom(), this);
this.vocabulary.setImgDownloaderListener(new iImgDownloaderListener() {
@Override
public void loadComplete() {
PictogramActivity.this.refresh();
}
@Override
public void loadImg(Img image) {
}
@Override
public void error(Exception err) {
}
});
if (this.vocabulary != null && this.vocabulary.size() > 0) {
Log.d(LOG_TAG, "Vocabulario correcto de tam:" + vocabulary.size());
}
......@@ -345,7 +363,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
*/
@Override
public void change(action action, int picto_cat, int picto_id, JSONObject args) {
Log.d(LOG_TAG, "Vocabulary action listened: " + action);
Log.i(LOG_TAG, "Vocabulary action listened: " + action);
if(args!=null) Log.d(LOG_TAG, "args: " + args.toString());
refresh();
}
......
......@@ -115,9 +115,12 @@ public class StudentFragmentGrid extends Fragment{
PCBcontext.set_user(new_user, intent.getStringExtra("token"), new iImgDownloaderListener() {
@Override
public void loadComplete() {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
Intent pictogramActivity = new Intent(getActivity(), PictogramActivity.class);
startActivity(pictogramActivity);
}
}
@Override
......@@ -183,7 +186,6 @@ public class StudentFragmentGrid extends Fragment{
@Override
public void loadImg(Img image) {
}
public void error(Exception e) {
progressDialog.dismiss();
......
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