Working on GUI for uploading pictos from PCB

parent fbf06221
...@@ -26,17 +26,17 @@ android { ...@@ -26,17 +26,17 @@ android {
resValue "bool", "force_img_download", "false" resValue "bool", "force_img_download", "false"
resValue "integer", "netservice_timing", "20" resValue "integer", "netservice_timing", "20"
resValue "integer", "rows", "5" resValue "integer", "rows", "5"
resValue "integer", "columns", "8" resValue "integer", "columns", "10"
} }
debug { debug {
resValue "string", "db_name", "PCB.db" resValue "string", "db_name", "PCB.db"
resValue "bool", "force_db_create", "false" resValue "bool", "force_db_create", "true"
resValue "bool", "ssl_connect", "false" resValue "bool", "ssl_connect", "false"
resValue "bool", "force_img_download", "false" resValue "bool", "force_img_download", "false"
resValue "integer", "netservice_timing", "20" resValue "integer", "netservice_timing", "20"
resValue "integer", "rows", "5" resValue "integer", "rows", "5"
resValue "integer", "columns", "8" resValue "integer", "columns", "10"
} }
} }
productFlavors { productFlavors {
......
...@@ -83,7 +83,7 @@ public class Translate extends Activity implements iVocabularyListener, iImgDown ...@@ -83,7 +83,7 @@ public class Translate extends Activity implements iVocabularyListener, iImgDown
PCBcontext.init(this); PCBcontext.init(this);
PCBcontext.getDevice().setSerial("serial1"); PCBcontext.getDevice().setSerial("serial1");
PCBcontext.getDevice().setDeviceID("deviceID"); PCBcontext.getDevice().setDeviceID("deviceID");
PCBcontext.getDevice().deleteDeprecatedImgs();
PCBcontext.set_user(alumno_picto, TOKEN, this); PCBcontext.set_user(alumno_picto, TOKEN, this);
Log.i(LOG_TAG, "2) OnCreate - Serial:" + PCBcontext.getDevice().getSerial() + " dev. id:" + Log.i(LOG_TAG, "2) OnCreate - Serial:" + PCBcontext.getDevice().getSerial() + " dev. id:" +
PCBcontext.getDevice().getDeviceID() + " token:" + TOKEN); PCBcontext.getDevice().getDeviceID() + " token:" + TOKEN);
......
...@@ -17,6 +17,13 @@ ...@@ -17,6 +17,13 @@
<android:uses-permission android:name="android.permission.READ_PHONE_STATE" /> <android:uses-permission android:name="android.permission.READ_PHONE_STATE" />
<android:uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <android:uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<android:uses-permission android:name="android.permission.READ_CALL_LOG" />
<application <application
android:name=".kiosk.AppContext" android:name=".kiosk.AppContext"
android:allowBackup="true" android:allowBackup="true"
...@@ -36,24 +43,22 @@ ...@@ -36,24 +43,22 @@
<activity <activity
android:name=".gui.MainActivity" android:name=".gui.MainActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="landscape"> android:screenOrientation="landscape" />
</activity>
<activity <activity
android:name=".gui.SerialActivity" android:name=".gui.SerialActivity"
android:label="@string/title_activity_serial" android:label="@string/title_activity_serial"
android:screenOrientation="landscape"> android:screenOrientation="landscape" />
</activity>
<activity <activity
android:name=".gui.LoginActivity" android:name=".gui.LoginActivity"
android:exported="true" android:exported="true"
android:label="@string/title_activity_login_activity_fragments" android:label="@string/title_activity_login_activity_fragments"
android:screenOrientation="landscape"/> android:screenOrientation="landscape" />
<activity <activity
android:name=".gui.PictogramActivity" android:name=".gui.PictogramActivity"
android:exported="true" android:exported="true"
android:label="@string/app_name" android:label="@string/app_name"
android:launchMode="singleTop" android:launchMode="singleTop"
android:screenOrientation="landscape"/> android:screenOrientation="landscape" />
<!-- Intent Filter to run the app when the boot is completed --> <!-- Intent Filter to run the app when the boot is completed -->
<receiver android:name=".kiosk.BootReceiver"> <receiver android:name=".kiosk.BootReceiver">
<intent-filter> <intent-filter>
...@@ -66,7 +71,16 @@ ...@@ -66,7 +71,16 @@
android:exported="false" /> android:exported="false" />
<service <service
android:name=".net.NetService" android:name=".net.NetService"
android:exported="false"/> android:exported="false" />
<activity
android:name=".ImgLabelActivity"
android:label="@string/title_activity_img_label"
android:parentActivityName=".gui.PictogramActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.yottacode.pictogram.gui.PictogramActivity" />
</activity>
</application> </application>
</manifest> </manifest>
...@@ -317,13 +317,17 @@ public class Device extends SQLiteOpenHelper { ...@@ -317,13 +317,17 @@ public class Device extends SQLiteOpenHelper {
/** /**
* delete the list of images (students, supervisors, pictograms) which are no longer used * delete the list of images (students, supervisors, pictograms) which are no longer used
*/ */
public void deleteDeprecatedImgs() throws IOException { public void deleteDeprecatedImgs() {
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.query("deprecated_images", null, null, null, null, null, null); Cursor cursor = db.query("deprecated_images", null, null, null, null, null, null);
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
String type = cursor.getString(1); String type = cursor.getString(1);
String folder = type.equals("stu") ? Img.STUDENT : type.equals("sup") ? Img.SUPERVISOR : Img.VOCABULARY; String folder = type.equals("stu") ? Img.STUDENT : type.equals("sup") ? Img.SUPERVISOR : Img.VOCABULARY;
(new Img(cursor.getInt(0), null, folder)).delete_bitmap(this.context); try {
(new Img(cursor.getInt(0), null, folder)).delete_bitmap(this.context);
} catch (IOException e) {
e.printStackTrace();
}
Log.i(this.getClass().getCanonicalName(), "Image file " + cursor.getString(1) + "." + cursor.getInt(0) + " deleted"); Log.i(this.getClass().getCanonicalName(), "Image file " + cursor.getString(1) + "." + cursor.getInt(0) + " deleted");
} }
cursor.close(); cursor.close();
......
...@@ -203,11 +203,15 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -203,11 +203,15 @@ public class PCBDBHelper extends SQLiteOpenHelper {
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
int id_stu = this.getCurrentUser().get_id_stu(); int id_stu = this.getCurrentUser().get_id_stu();
int seconds1 = Calendar.getInstance().get(Calendar.SECOND); int seconds1 = Calendar.getInstance().get(Calendar.SECOND);
db.delete("collection", "id_stu=?", new String[] {String.valueOf(id_stu)});
db.delete("collection", "id_stu=" + id_stu, null);
int newsize=0;
ContentValues values=new ContentValues(5); ContentValues values=new ContentValues(5);
values.put("id_stu", id_stu); values.put("id_stu", id_stu);
for (Picto picto : vocabulary) { for (Picto picto : vocabulary) {
values.put("id_picto", picto.get_id()); newsize++;
values.put("id_picto", picto.get_id());
values.put("url", picto.get_url()); values.put("url", picto.get_url());
values.put("translation",picto.get_translation()); values.put("translation",picto.get_translation());
values.put("attributes",picto.get_json_attrs()); values.put("attributes",picto.get_json_attrs());
...@@ -215,7 +219,8 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -215,7 +219,8 @@ public class PCBDBHelper extends SQLiteOpenHelper {
} }
int seconds2 = Calendar.getInstance().get(Calendar.SECOND); int seconds2 = Calendar.getInstance().get(Calendar.SECOND);
Log.i(this.getClass().getName(), " Local student vocabulary updated, id:" + id_stu + ", cats: "+vocabulary.size() +" time:"+(seconds2-seconds1)); Log.i(this.getClass().getName(), " Local student vocabulary updated, id:" + id_stu + ", cats: " + vocabulary.size() + " time:" + (seconds2 - seconds1) + " secs. Size: " + newsize + " read only?" + db.isReadOnly());
db.close(); db.close();
} }
...@@ -248,11 +253,11 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -248,11 +253,11 @@ public class PCBDBHelper extends SQLiteOpenHelper {
int id_stu = this.getCurrentUser().get_id_stu(); int id_stu = this.getCurrentUser().get_id_stu();
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
db.delete("collection","id_stu=? AND id_sup=? AND id_picto=?", db.delete("collection","id_stu=? AND id_picto=?",
new String[]{ Integer.toString(this.currentUser.get_id_stu()), new String[]{ Integer.toString(this.currentUser.get_id_stu()),
Integer.toString(this.currentUser.get_id_sup()),
Integer.toString(picto_id)}); Integer.toString(picto_id)});
db.close(); db.close();
PCBcontext.getDevice().deleteDeprecatedImgs();
} }
/** /**
* Update a picto of the current collection's student. * Update a picto of the current collection's student.
......
...@@ -23,14 +23,14 @@ public class Picto extends Img { ...@@ -23,14 +23,14 @@ public class Picto extends Img {
private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName() private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName()
public final static class JSON_ATTTRS { public final static class JSON_ATTTRS {
static String CATEGORY = "id_cat"; public static String CATEGORY = "id_cat";
static String ROW = "coord_x"; public static String COLUMN = "coord_x";
static String COLUMN = "coord_y"; public static String ROW = "coord_y";
static String MAGNIFY = "magnify"; public static String MAGNIFY = "magnify";
static String HIGHLIGHT = "highlight"; public static String HIGHLIGHT = "highlight";
static String STATUS = "status"; public static String STATUS = "status";
static String COLOR = "color"; public static String COLOR = "color";
static String PCB_STATUS_MODIFICATION="pcb_status_modification"; public static String PCB_STATUS_MODIFICATION="pcb_status_modification";
} }
public final static class JSON_ATTTR_STATUS_VALUES { public final static class JSON_ATTTR_STATUS_VALUES {
...@@ -46,7 +46,7 @@ public class Picto extends Img { ...@@ -46,7 +46,7 @@ public class Picto extends Img {
private JSONObject attributes; private JSONObject attributes;
private String translation; private String translation;
public Picto(int id, String url, String translation, int cat, int column, int row) throws JSONException { public Picto(int id, String url, String translation, int cat, int row, int column) throws JSONException {
this(id, url, translation, new JSONObject() this(id, url, translation, new JSONObject()
.put(JSON_ATTTRS.CATEGORY,cat) .put(JSON_ATTTRS.CATEGORY,cat)
.put(JSON_ATTTRS.COLUMN,column) .put(JSON_ATTTRS.COLUMN,column)
......
...@@ -47,11 +47,9 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -47,11 +47,9 @@ public class Vocabulary implements Iterable<Picto> {
this.pictos = new Hashtable<>(Vocabulary.DEFAULT_VOCABULARY_SIZE); this.pictos = new Hashtable<>(Vocabulary.DEFAULT_VOCABULARY_SIZE);
this.imgListener=listener; this.imgListener=listener;
if (PCBcontext.getNetService().online()) { if (PCBcontext.getNetService().online()) {
Log.i(this.getClass().getName(), "FERNANDO Downloading vocabulary");
synchronize(); synchronize();
}else }else
try { try {
Log.i(this.getClass().getName(), "FERNANDO Local vocabulary");
PCBcontext.getPcbdb().getStudentVocabulary(this); PCBcontext.getPcbdb().getStudentVocabulary(this);
listener.loadComplete(); listener.loadComplete();
} catch (JSONException e) { } catch (JSONException e) {
...@@ -121,6 +119,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -121,6 +119,7 @@ public class Vocabulary implements Iterable<Picto> {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
Log.e(this.getClass().getName(), " Picto json error from server: " + picto.toString()); Log.e(this.getClass().getName(), " Picto json error from server: " + picto.toString());
} }
} }
} }
...@@ -217,17 +216,17 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -217,17 +216,17 @@ public class Vocabulary implements Iterable<Picto> {
Log.d(this.getClass().getName(), "Vocabulary size: " + updated_collection.length); Log.d(this.getClass().getName(), "Vocabulary size: " + updated_collection.length);
ImgDownloader downloader = new ImgDownloader(PCBcontext.getContext(), imgListener,ImgDownloader.tsource.remote); ImgDownloader downloader = new ImgDownloader(PCBcontext.getContext(), imgListener,ImgDownloader.tsource.remote);
downloader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, imgs); downloader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, imgs);
PCBcontext.getPcbdb().setStudentVocabulary(this); }
}
public int size() { return this.pictos.size();} public int size() { return this.pictos.size();}
/** /**
* It includes/updates a new picto to the user collection: download the image from remote or local storage, add the picto to the current vocabulary and update the database * It includes/updates a new picto to the user collection: download the image from remote or local storage, add the picto to the current vocabulary and update the database
* @param pic * @param pic
*/ */
public void addPicto(Picto pic, ImgDownloader.tsource source){ public void addPicto(Picto pic, ImgDownloader.tsource source){
addPicto(pic, source, this.imgListener);
}
public void addPicto(Picto pic, ImgDownloader.tsource source, iImgDownloaderListener imgListener){
Vector<Img> imgs=new Vector<Img>(1); Vector<Img> imgs=new Vector<Img>(1);
imgs.add(new Img(pic.get_id(), pic.get_url(), Img.VOCABULARY)); imgs.add(new Img(pic.get_id(), pic.get_url(), Img.VOCABULARY));
...@@ -312,14 +311,6 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -312,14 +311,6 @@ public class Vocabulary implements Iterable<Picto> {
*/ */
public LinkedList<Picto> startSentence(){ public LinkedList<Picto> startSentence(){
return this.pictos.get(new Integer(Picto.NO_CATEGORY)); return this.pictos.get(new Integer(Picto.NO_CATEGORY));
/*Iterator<Picto> pictos=this.pictos.get(new Integer(Picto.NO_CATEGORY)).iterator();
LinkedList<Picto> filteredPictos=new LinkedList<Picto>();
while (pictos.hasNext()) {
Picto picto = pictos.next();
if (!picto.is_category() || isVisibleCategory(picto.get_id()))
filteredPictos.add(picto);
}
return filteredPictos;*/
} }
/** /**
...@@ -343,19 +334,32 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -343,19 +334,32 @@ public class Vocabulary implements Iterable<Picto> {
*/ */
public Picto saveLocalPicto(String url, String exp, int cat, int coord_x, int coord_y) { public Picto saveLocalPicto(String url, String exp, int cat, int coord_x, int coord_y) {
int id= PCBcontext.getDevice().getNextLocalPictoID(); int id= PCBcontext.getDevice().getNextLocalPictoID();
Picto picto; final Picto picto[]=new Picto[1];
try { try {
picto = new Picto(id, url, exp, cat, coord_x, coord_y); picto[0] = new Picto(id, url, exp, cat, coord_x, coord_y);
addPicto(picto[0], ImgDownloader.tsource.local, new iImgDownloaderListener() {
@Override
public void loadComplete() {
try {
new PictoUploader(picto[0]).upload(); //id<0 iif it is a local id
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void loadImg(Img image) {
}
});
addPicto(picto, ImgDownloader.tsource.local);
new PictoUploader(picto).upload(); //id<0 iif it is a local id
} catch (Exception e) { } catch (Exception e) {
picto=null; picto[0]=null;
e.printStackTrace(); e.printStackTrace();
Log.e(Vocabulary.class.getCanonicalName(), e.getMessage()); Log.e(Vocabulary.class.getCanonicalName(), e.getMessage());
} }
PCBcontext.getActionLog().log(new VocabularyAction(VocabularyAction.ADD, picto)); PCBcontext.getActionLog().log(new VocabularyAction(VocabularyAction.ADD, picto[0]));
return picto; return picto[0];
} }
/** /**
......
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_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 + "' 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, attrs_picto); } catch (JSONException e) { Log.e(this.getClass().getCanonicalName(), e.getClass().getCanonicalName() + "--" + 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_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 { 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_id); int picto_cat = attrs_picto.optInt(param_picto_cat, Picto.NO_CATEGORY); Log.d(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, 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
......
...@@ -16,6 +16,5 @@ import java.util.LinkedList; ...@@ -16,6 +16,5 @@ import java.util.LinkedList;
*/ */
public interface iVocabularyListener { public interface iVocabularyListener {
public enum action {delete,add,update} public enum action {delete,add,update}
public enum arg {attributes, expression, url}
public void change(iVocabularyListener.action action, int picto_cat, int picto_id, JSONObject args); public void change(iVocabularyListener.action action, int picto_cat, int picto_id, JSONObject args);
} }
...@@ -261,7 +261,6 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{ ...@@ -261,7 +261,6 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{
} }
}); });
PCBcontext.getDevice().deleteDeprecatedImgs();
// Si sólo hay 1 estudiante paso a Pictogram // Si sólo hay 1 estudiante paso a Pictogram
if (users.size() == 1){ if (users.size() == 1){
//close the progress dialog //close the progress dialog
...@@ -289,8 +288,6 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{ ...@@ -289,8 +288,6 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} }
} }
......
...@@ -331,7 +331,6 @@ public class SerialActivity extends Activity implements iRestapiListener { ...@@ -331,7 +331,6 @@ public class SerialActivity extends Activity implements iRestapiListener {
setContentView(R.layout.activity_serial); setContentView(R.layout.activity_serial);
} }
}); });
PCBcontext.getDevice().deleteDeprecatedImgs();
} else{ } else{
// Es un Supervisor // Es un Supervisor
...@@ -372,8 +371,6 @@ public class SerialActivity extends Activity implements iRestapiListener { ...@@ -372,8 +371,6 @@ public class SerialActivity extends Activity implements iRestapiListener {
} catch (JSONException e) { } catch (JSONException e) {
//Log.d(LOG_TAG, "ERROR 2"); //Log.d(LOG_TAG, "ERROR 2");
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} }
} }
......
...@@ -8,6 +8,7 @@ import android.util.Log; ...@@ -8,6 +8,7 @@ import android.util.Log;
import com.yottacode.pictogram.R; import com.yottacode.pictogram.R;
import com.yottacode.pictogram.tools.Img; import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -68,7 +69,7 @@ public class ImgDownloader extends AsyncTask<Vector<Img>, Void, Img> { ...@@ -68,7 +69,7 @@ public class ImgDownloader extends AsyncTask<Vector<Img>, Void, Img> {
if (!img.exists_bitmap(this.context) || this.force_download) try { if (!img.exists_bitmap(this.context) || this.force_download) try {
this.activityManager.getMemoryInfo(mi); this.activityManager.getMemoryInfo(mi);
Log.i(this.getClass().getCanonicalName(), img.get_url() + " to be downloaded"); Log.i(this.getClass().getCanonicalName(), "Picto Img "+img.get_url() + " to be downloaded");
if (this.source==source.remote) { if (this.source==source.remote) {
String surl = context.getResources().getString(R.string.server) + "/" + img.get_url(); String surl = context.getResources().getString(R.string.server) + "/" + img.get_url();
URL url = new URL(surl); URL url = new URL(surl);
...@@ -113,8 +114,8 @@ public class ImgDownloader extends AsyncTask<Vector<Img>, Void, Img> { ...@@ -113,8 +114,8 @@ public class ImgDownloader extends AsyncTask<Vector<Img>, Void, Img> {
@Override @Override
protected void onPostExecute(Img img) { protected void onPostExecute(Img img) {
Log.d(this.getClass().getCanonicalName(), "Inside OnPostExecute()"+new SimpleDateFormat("HH:mm:ss")); PCBcontext.getDevice().deleteDeprecatedImgs();
if (imgListener!=null) if (imgListener!=null)
if(img == null) imgListener.loadComplete(); if(img == null) imgListener.loadComplete();
else imgListener.loadImg(img); else imgListener.loadImg(img);
} }
......
...@@ -37,7 +37,11 @@ public class PictoUploader { ...@@ -37,7 +37,11 @@ public class PictoUploader {
throw new UnsupportedEncodingException("Extension "+img.get_filetype()+" is not supported. Only png files"); throw new UnsupportedEncodingException("Extension "+img.get_filetype()+" is not supported. Only png files");
Ion ion = Ion.getDefault(PCBcontext.getContext()); Ion ion = Ion.getDefault(PCBcontext.getContext());
Log.i(this.getClass().getCanonicalName(), "Uploading " + img.file_name() + " from " + img.get_type()); try {
Log.i(this.getClass().getCanonicalName(), "Uploading Picto img" + img.file_name() + " from " + img.get_type() + "size:" + img.get_bitmap(PCBcontext.getContext()).getWidth() + " " + img.get_bitmap(PCBcontext.getContext()).getHeight());
} catch (IOException e) {
Log.i(this.getClass().getCanonicalName(), "Uploading Picto img" + img.file_name() + " from " + img.get_type());
}
File file = img.file(PCBcontext.getContext()); File file = img.file(PCBcontext.getContext());
Response<JsonObject> response=null; Response<JsonObject> response=null;
...@@ -149,15 +153,20 @@ public class PictoUploader { ...@@ -149,15 +153,20 @@ public class PictoUploader {
} }
/** /**
*Try to Upload local picto. It requires: i) to upload the image, ii) to upload the attributes and iii) to upload the expression *Try to Upload local picto. It requires:
**/ * i) to upload the image,
* ii) to upload the attributes
* iii) to upload the expression
* iv) delete the old local picto since it will be recovered from the server
**/
public void upload() throws IOException { public void upload() throws IOException {
int old_picto=this.picto.get_id();
int img_id = uploadImg(this.picto); int img_id = uploadImg(this.picto);
if (img_id > 0) { if (img_id > 0) {
uploadAttributes(img_id); uploadAttributes(img_id);
uploadTranslation(img_id); uploadTranslation(img_id);
PCBcontext.getRoom().emit(new VocabularyAction(VocabularyAction.ADD, PictoUploader.this.picto)); PCBcontext.getRoom().emit(new VocabularyAction(VocabularyAction.ADD, PictoUploader.this.picto));
PCBcontext.getPcbdb().deletePicto(old_picto);
} }
} }
......
...@@ -4,8 +4,11 @@ package com.yottacode.pictogram.tools; ...@@ -4,8 +4,11 @@ package com.yottacode.pictogram.tools;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.util.Log; import android.util.Log;
import com.yottacode.tools.FileTools;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -15,6 +18,7 @@ import java.io.IOException; ...@@ -15,6 +18,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Enumeration; import java.util.Enumeration;
/** /**
* Img * Img
* @author Fernando * @author Fernando
...@@ -26,11 +30,17 @@ public class Img { ...@@ -26,11 +30,17 @@ public class Img {
static public String SUPERVISOR="supervisor"; static public String SUPERVISOR="supervisor";
public static final void mkDirs(Context context) { public static final void mkDirs(Context context) {
new File(path(context, Img.VOCABULARY) ).mkdirs() ; File file;
new File(path(context, Img.STUDENT) ).mkdirs() ; file = new File(path(context, Img.VOCABULARY));
new File(path(context, Img.SUPERVISOR) ).mkdirs() ; FileTools.deleteDirectory(file);
file.mkdirs();
file = new File(path(context, Img.STUDENT));
FileTools.deleteDirectory(file);
file.mkdirs();
file = new File(path(context, Img.SUPERVISOR));
FileTools.deleteDirectory(file);
file.mkdirs();
} }
protected int id; protected int id;
protected String url; protected String url;
String type; String type;
...@@ -121,12 +131,13 @@ public class Img { ...@@ -121,12 +131,13 @@ public class Img {
File file = file(context); File file = file(context);
FileOutputStream os = new FileOutputStream(file); FileOutputStream os = new FileOutputStream(file);
try { try {
this.bitmap = BitmapFactory.decodeStream(is); this.bitmap = BitmapFactory.decodeStream(is, new Rect(0,0,78,66),null);
}catch(java.lang.OutOfMemoryError err) { }catch(java.lang.OutOfMemoryError err) {
Log.e(Img.class.getCanonicalName(), "Out of memory when decoding "+this.get_url()); Log.e(Img.class.getCanonicalName(), "Out of memory when decoding "+this.get_url());
} }
ByteArrayOutputStream outstream = new ByteArrayOutputStream(); ByteArrayOutputStream outstream = new ByteArrayOutputStream();
this.bitmap.setHasAlpha(true); this.bitmap.setHasAlpha(true);
Log.i(this.getClass().getCanonicalName(), "Img Uploading Picto img" + file_name() + " from " + get_type() + "size:" + get_bitmap(PCBcontext.getContext()).getWidth() + " " + get_bitmap(PCBcontext.getContext()).getHeight());
this.bitmap.compress(Bitmap.CompressFormat.PNG, 100, outstream); this.bitmap.compress(Bitmap.CompressFormat.PNG, 100, outstream);
byte[] byteArray = outstream.toByteArray(); byte[] byteArray = outstream.toByteArray();
os.write(byteArray); os.write(byteArray);
......
package com.yottacode.tools;
import java.io.File;
/**
* Created by Fernando on 14/03/2016.
*/
public class FileTools {
public static boolean deleteDirectory(File path) {
if( path.exists() ) {
File[] files = path.listFiles();
if (files == null) {
return true;
}
for(int i=0; i<files.length; i++) {
if(files[i].isDirectory()) {
deleteDirectory(files[i]);
}
else {
files[i].delete();
}
}
}
return( path.delete() );
}
}
...@@ -47,4 +47,9 @@ ...@@ -47,4 +47,9 @@
<string name="naturalgrammar">SUpO_EN</string> <string name="naturalgrammar">SUpO_EN</string>
<string name="pictogrammar">SUpO_PICTOEN</string> <string name="pictogrammar">SUpO_PICTOEN</string>
<string name="nogrammar">Warning: unknown language</string> <string name="nogrammar">Warning: unknown language</string>
<!--Upload local img -->
<string name="enterImgLabel">Enter img label</string>
<string name="notNewCats">Including new categories is not allowed</string>
</resources> </resources>
...@@ -52,4 +52,8 @@ ...@@ -52,4 +52,8 @@
<item type="integer" name="maxInTape">8</item> <item type="integer" name="maxInTape">8</item>
<!--Upload local img -->
<string name="enterImgLabel">Introduzca etiqueta de la imagen</string>
<string name="notNewCats">No puede añadir nuevas categorias</string>
</resources> </resources>
...@@ -48,5 +48,23 @@ ...@@ -48,5 +48,23 @@
<string name="grammar">SUpO_EN</string> <string name="grammar">SUpO_EN</string>
<string name="nogrammar">Warning: unknown language</string> <string name="nogrammar">Warning: unknown language</string>
<item type="integer" name="maxInTape">8</item> <!--Upload local img -->
<string name="enterImgLabel">Introduzca etiqueta de la imagen</string>
<string name="notNewCats">No puede añadir nuevas categorias</string>
<item name="maxInTape" type="integer">8</item>
<string name="title_activity_img_label">img_label</string>
<!-- Strings related to login -->
<string name="prompt_email">Email</string>
<string name="prompt_password">Password (optional)</string>
<string name="action_sign_in">Sign in or register</string>
<string name="action_sign_in_short">Sign in</string>
<string name="error_invalid_email">This email address is invalid</string>
<string name="error_invalid_password">This password is too short</string>
<string name="error_incorrect_password">This password is incorrect</string>
<string name="error_field_required">This field is required</string>
<string name="permission_rationale">"Contacts permissions are needed for providing email
completions."
</string>
</resources> </resources>
\ No newline at end of file
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