Rescaling of pictos from PCB implemented

User/Pwd DAO managament implemented (issue #350)
parent 373cb7c1
...@@ -31,7 +31,7 @@ android { ...@@ -31,7 +31,7 @@ android {
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"
......
...@@ -203,15 +203,69 @@ public class Device extends SQLiteOpenHelper { ...@@ -203,15 +203,69 @@ public class Device extends SQLiteOpenHelper {
Cursor cursor = db.query("users_detail", null, null, null, null, null, null, null); Cursor cursor = db.query("users_detail", null, null, null, null, null, null, null);
while (cursor.moveToNext() && user == null) while (cursor.moveToNext() && user == null)
if (cursor.getInt(0) == id_stu && cursor.getInt(7) == id_sup) if (cursor.getInt(0) == id_stu && cursor.getInt(9) == id_sup)
user = new User(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getString(6), user = new User(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getString(6), cursor.getString(7), cursor.getString(8),
cursor.getInt(7), cursor.getString(8), cursor.getString(9), cursor.getString(10), cursor.getString(11), cursor.getString(12), cursor.getString(13)); cursor.getInt(9), cursor.getString(10), cursor.getString(11), cursor.getString(12), cursor.getString(13), cursor.getString(14), cursor.getString(15), cursor.getString(16), cursor.getString(17));
cursor.close(); cursor.close();
db.close(); db.close();
return user; return user;
} }
private Vector<User> recoverStudents(Integer id_sup) throws JSONException{
SQLiteDatabase db = this.getReadableDatabase();
Vector<User> users = new Vector<>();
Cursor cursor = db.query("users_detail", null, null, null, null, null, null, null);
while (cursor.moveToNext())
if (cursor.getInt(9) == id_sup)
users.add(new User(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getString(6), cursor.getString(7), cursor.getString(8),
cursor.getInt(9), cursor.getString(10), cursor.getString(11), cursor.getString(12), cursor.getString(13), cursor.getString(14), cursor.getString(15), cursor.getString(16), cursor.getString(17)));
cursor.close();
db.close();
return users;
}
/**
* @param auser
* @param apwd
* @return the information of an specific user, if they are available in the local DB
*/
public Vector<User> findUser(String auser, String apwd) throws JSONException, LoginException {
SQLiteDatabase db = this.getReadableDatabase();
boolean user_found=false;
Vector<User> users=null;
Cursor cursor = db.query("supervisor", null, null, null, null, null, null, null);
while (cursor.moveToNext() && users == null && !user_found) {
user_found = cursor.getString(10).equalsIgnoreCase(auser);
if (user_found)
if (cursor.getString(2).equals(apwd)) {
users = recoverStudents(cursor.getInt(0));
if (users.size() == 0)
throw new LoginException("Supervisor hasn't got students", false, true, true);
}
else throw new LoginException("Supervisor password incorrect", false, true,false);
}
cursor.close();
if (!user_found) {
cursor = db.query("student", null, null, null, null, null, null, null);
while (cursor.moveToNext() && users == null && !user_found) {
user_found = cursor.getString(1).equalsIgnoreCase(auser);
if (user_found)
if (cursor.getString(2).equals(apwd)) {
users = new Vector<>(1);
users.add(new User(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getString(6), cursor.getString(7), cursor.getString(8),
User.NO_SUPERVISOR, "", "", "", "", "", "", "", ""));
}
else throw new LoginException("Student password incorrect", true, false,false);
}
cursor.close();
}
if (!user_found) throw new LoginException("User not found", false, false,false);
db.close();
return users;
}
/** /**
* @return a Vector<User> with the whole user who has been registered. * @return a Vector<User> with the whole user who has been registered.
...@@ -225,8 +279,8 @@ public class Device extends SQLiteOpenHelper { ...@@ -225,8 +279,8 @@ public class Device extends SQLiteOpenHelper {
Cursor cursor = db.query("users_detail", null, null, null, null, null, null, null); Cursor cursor = db.query("users_detail", null, null, null, null, null, null, null);
Vector<User> users = new Vector<User>(cursor.getCount()); Vector<User> users = new Vector<User>(cursor.getCount());
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
user = new User(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getString(6), user = new User(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getString(6), cursor.getString(7), cursor.getString(8),
cursor.getInt(7), cursor.getString(8), cursor.getString(9), cursor.getString(10), cursor.getString(11), cursor.getString(12), cursor.getString(13)); cursor.getInt(9), cursor.getString(10), cursor.getString(11), cursor.getString(12), cursor.getString(13), cursor.getString(14), cursor.getString(15), cursor.getString(16), cursor.getString(17));
users.add(user); users.add(user);
} }
...@@ -238,6 +292,8 @@ public class Device extends SQLiteOpenHelper { ...@@ -238,6 +292,8 @@ public class Device extends SQLiteOpenHelper {
private void updateUser(User user, SQLiteDatabase db) { private void updateUser(User user, SQLiteDatabase db) {
db.execSQL("UPDATE users_detail SET " + db.execSQL("UPDATE users_detail SET " +
"nickname_stu='" + user.get_nickname_stu() + "', " +
"pwd_stu='" + user.get_pwd_stu() + "', " +
"name_stu='" + user.get_name_stu() + "', " + "name_stu='" + user.get_name_stu() + "', " +
"surname_stu='" + user.get_surname_stu() + "', " + "surname_stu='" + user.get_surname_stu() + "', " +
"url_img_stu='" + user.get_url_img_stu() + "', " + "url_img_stu='" + user.get_url_img_stu() + "', " +
...@@ -245,6 +301,8 @@ public class Device extends SQLiteOpenHelper { ...@@ -245,6 +301,8 @@ public class Device extends SQLiteOpenHelper {
"lang_stu='" + user.get_lang_stu() + "', " + "lang_stu='" + user.get_lang_stu() + "', " +
"attributes_stu='" + user.get_json_attrs() + "', " + "attributes_stu='" + user.get_json_attrs() + "', " +
"name_sup='" + user.get_name_sup() + "', " + "name_sup='" + user.get_name_sup() + "', " +
"nickname_sup='" + user.get_email_sup() + "', " +
"pwd_sup='" + user.get_pwd_sup() + "', " +
"surname_sup='" + user.get_surname_sup() + "', " + "surname_sup='" + user.get_surname_sup() + "', " +
"url_img_sup='" + user.get_url_img_sup() + "', " + "url_img_sup='" + user.get_url_img_sup() + "', " +
"gender_sup='" + user.get_gender_sup() + "', " + "gender_sup='" + user.get_gender_sup() + "', " +
...@@ -256,6 +314,8 @@ public class Device extends SQLiteOpenHelper { ...@@ -256,6 +314,8 @@ public class Device extends SQLiteOpenHelper {
private void insertUser(User user, SQLiteDatabase db) { private void insertUser(User user, SQLiteDatabase db) {
db.execSQL("INSERT INTO users_detail values (" + db.execSQL("INSERT INTO users_detail values (" +
user.get_id_stu() + ", " + user.get_id_stu() + ", " +
"'" + user.get_nickname_stu() + "', " +
"'" + user.get_pwd_stu() + "', " +
"'" + user.get_name_stu() + "', " + "'" + user.get_name_stu() + "', " +
"'" + user.get_surname_stu() + "', " + "'" + user.get_surname_stu() + "', " +
"'" + user.get_url_img_stu() + "', " + "'" + user.get_url_img_stu() + "', " +
...@@ -263,6 +323,8 @@ public class Device extends SQLiteOpenHelper { ...@@ -263,6 +323,8 @@ public class Device extends SQLiteOpenHelper {
"'" + user.get_lang_stu() + "', " + "'" + user.get_lang_stu() + "', " +
"'" + user.get_json_attrs() + "', " + "'" + user.get_json_attrs() + "', " +
"'" + user.get_id_sup() + "', " + "'" + user.get_id_sup() + "', " +
"'" + user.get_email_sup() + "', " +
"'" + user.get_pwd_sup() + "', " +
"'" + user.get_name_sup() + "', " + "'" + user.get_name_sup() + "', " +
"'" + user.get_surname_sup() + "', " + "'" + user.get_surname_sup() + "', " +
"'" + user.get_url_img_sup() + "'," + "'" + user.get_url_img_sup() + "'," +
......
package com.yottacode.pictogram.dao;
/**
* Created by Fernando on 15/03/2016.
*/
public class LoginException extends Exception{
boolean student;
boolean supervisor;
boolean no_students;
public LoginException(String msg, boolean student, boolean supervisor, boolean no_students) {
super(msg);
this.student=student;
this.supervisor=supervisor;
this.no_students=no_students;
}
public boolean knonwn_student() {return student;}
public boolean known_supervisor() {return supervisor;}
public boolean no_students() {return no_students;}
}
...@@ -102,8 +102,8 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -102,8 +102,8 @@ public class PCBDBHelper extends SQLiteOpenHelper {
if (cursor.getCount() > 0) { if (cursor.getCount() > 0) {
cursor.moveToFirst(); cursor.moveToFirst();
try { try {
last_user = new User(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getString(6), last_user = new User(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getString(6), cursor.getString(7), cursor.getString(8),
cursor.getInt(7), cursor.getString(8), cursor.getString(9), cursor.getString(10), cursor.getString(11), cursor.getString(12), cursor.getString(13)); cursor.getInt(9), cursor.getString(10), cursor.getString(11), cursor.getString(12), cursor.getString(13), cursor.getString(14), cursor.getString(15), cursor.getString(16), cursor.getString(17));
} catch (JSONException e) { } catch (JSONException e) {
Log.e(this.getClass().getName(), e.getMessage() + " BAD FORMED JSON: " + cursor.getString(5)); Log.e(this.getClass().getName(), e.getMessage() + " BAD FORMED JSON: " + cursor.getString(5));
System.exit(-1); System.exit(-1);
...@@ -257,7 +257,7 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -257,7 +257,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
new String[]{ Integer.toString(this.currentUser.get_id_stu()), new String[]{ Integer.toString(this.currentUser.get_id_stu()),
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.
......
package com.yottacode.pictogram.dao;
/**
* Created by Fernando on 15/03/2016.
*/
public class Supervisor {
}
...@@ -15,12 +15,12 @@ import com.yottacode.pictogram.grammar.Vocabulary; ...@@ -15,12 +15,12 @@ import com.yottacode.pictogram.grammar.Vocabulary;
* A user of the PCB. A user can be an Student or a Supervisor using a student configuration * A user of the PCB. A user can be an Student or a Supervisor using a student configuration
* * * *
* @author Fernando Martinez Santiago * @author Fernando Martinez Santiago
* @version 1.0 * @version 1.1
*/ */
public class User { public class User {
private static final int NO_SUPERVISOR = -1; public static final int NO_SUPERVISOR = -1;
public boolean has_supervisor() { public boolean has_supervisor() {
return this.get_id_sup()!=User.NO_SUPERVISOR; return this.get_id_sup()!=User.NO_SUPERVISOR;
} }
...@@ -34,18 +34,20 @@ public class User { ...@@ -34,18 +34,20 @@ public class User {
static String TTS_VOICE = "tts voice"; static String TTS_VOICE = "tts voice";
} }
private Img img_stu; private Img img_stu;
private String name_stu, surname_stu, gender_stu, lang_stu; private String nickname_stu, pwd_stu, name_stu, surname_stu, gender_stu, lang_stu;
private JSONObject attributes_stu; private JSONObject attributes_stu;
private Img img_sup; private Img img_sup;
private String name_sup, surname_sup, gender_sup, lang_sup, tts_engine_sup; private String email_sup, pwd_sup, name_sup, surname_sup, gender_sup, lang_sup, tts_engine_sup;
public User(int id_stu, String name_stu, String surname_stu, String url_img_stu, String gender_stu, String lang_stu, String attributes_stu) throws JSONException { public User(int id_stu, String nickname_stu, String pwd_stu, String name_stu, String surname_stu, String url_img_stu, String gender_stu, String lang_stu, String attributes_stu) throws JSONException {
this(id_stu, name_stu, surname_stu, url_img_stu, gender_stu, lang_stu, attributes_stu,User.NO_SUPERVISOR,"","","","M","es-es",null); this(id_stu, nickname_stu, pwd_stu, name_stu, surname_stu, url_img_stu, gender_stu, lang_stu, attributes_stu,User.NO_SUPERVISOR,"","","","","","M","es-es",null);
} }
public User(int id_stu, String name_stu, String surname_stu, String url_img_stu, String gender_stu, String lang_stu, String attributes_stu, public User(int id_stu, String nickname_stu, String pwd_stu, String name_stu, String surname_stu, String url_img_stu, String gender_stu, String lang_stu, String attributes_stu,
int id_sup,String name_sup, String surname_sup, String url_img_sup, String gender_sup, String lang_sup, String tts_engine_sup) throws JSONException { int id_sup, String email_sup, String pwd_sup, String name_sup, String surname_sup, String url_img_sup, String gender_sup, String lang_sup, String tts_engine_sup) throws JSONException {
this.img_stu=new Img(id_stu,url_img_stu,Img.STUDENT); this.img_stu=new Img(id_stu,url_img_stu,Img.STUDENT);
this.nickname_stu=nickname_stu;
this.pwd_stu=pwd_stu;
this.name_stu=name_stu; this.name_stu=name_stu;
this.surname_stu=surname_stu; this.surname_stu=surname_stu;
this.gender_stu=gender_stu; this.gender_stu=gender_stu;
...@@ -53,6 +55,8 @@ public class User { ...@@ -53,6 +55,8 @@ public class User {
this.attributes_stu= attributes_stu!=null && attributes_stu.trim().length()>0 ? new JSONObject(attributes_stu) : new JSONObject(); this.attributes_stu= attributes_stu!=null && attributes_stu.trim().length()>0 ? new JSONObject(attributes_stu) : new JSONObject();
this.img_sup=new Img(id_sup,url_img_sup,Img.SUPERVISOR); this.img_sup=new Img(id_sup,url_img_sup,Img.SUPERVISOR);
this.email_sup=email_sup;
this.pwd_sup=pwd_sup;
this.name_sup=name_sup; this.name_sup=name_sup;
this.surname_sup=surname_sup; this.surname_sup=surname_sup;
this.gender_sup=gender_sup; this.gender_sup=gender_sup;
...@@ -70,6 +74,19 @@ public class User { ...@@ -70,6 +74,19 @@ public class User {
public int get_id_stu() {return this.img_stu.get_id();} public int get_id_stu() {return this.img_stu.get_id();}
/** /**
*
* @return nickname (username) of the student
*/
public String get_nickname_stu() {return this.nickname_stu;}
/**
*
* @return pwd of the student
*/
public String get_pwd_stu() {return this.pwd_stu;}
/**
* @ return the RESTAPI operator for the current student * @ return the RESTAPI operator for the current student
*/ */
public String get_restapi_operation_stu() { public String get_restapi_operation_stu() {
...@@ -131,6 +148,18 @@ public class User { ...@@ -131,6 +148,18 @@ public class User {
/** /**
* *
* @return nickname (username) of the student
*/
public String get_email_sup() {return this.email_sup;}
/**
*
* @return pwd of the student
*/
public String get_pwd_sup() {return this.pwd_sup;}
/**
*
* @return name of the supervisor * @return name of the supervisor
*/ */
public String get_name_sup() {return this.name_sup;} public String get_name_sup() {return this.name_sup;}
......
...@@ -261,7 +261,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -261,7 +261,7 @@ public class Vocabulary implements Iterable<Picto> {
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(index);
PCBcontext.getPcbdb().deletePicto(pic_id); PCBcontext.getPcbdb().deletePicto(pic_id);
} }
else else
...@@ -332,7 +332,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -332,7 +332,7 @@ public class Vocabulary implements Iterable<Picto> {
/* /*
* It saves locally a new picto obtained from the PCB * It saves locally a new picto obtained from the PCB
*/ */
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, final iLocalPicto listener) {
int id= PCBcontext.getDevice().getNextLocalPictoID(); int id= PCBcontext.getDevice().getNextLocalPictoID();
final Picto picto[]=new Picto[1]; final Picto picto[]=new Picto[1];
try { try {
...@@ -340,19 +340,13 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -340,19 +340,13 @@ public class Vocabulary implements Iterable<Picto> {
addPicto(picto[0], ImgDownloader.tsource.local, new iImgDownloaderListener() { addPicto(picto[0], ImgDownloader.tsource.local, new iImgDownloaderListener() {
@Override @Override
public void loadComplete() { public void loadComplete() {
try { listener.saved(picto[0]);
new PictoUploader(picto[0]).upload(); //id<0 iif it is a local id
} catch (IOException e) {
e.printStackTrace();
}
} }
@Override @Override
public void loadImg(Img image) { public void loadImg(Img image) {
} }
}); });
} catch (Exception e) { } catch (Exception e) {
picto[0]=null; picto[0]=null;
e.printStackTrace(); e.printStackTrace();
......
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 { Log.i(this.getClass().getName(), "raw Received message " +msg.toString()); 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.getJSONObject(param_picto).getInt(param_picto_id); int picto_cat = attrs_picto.optInt(param_picto_cat, Picto.NO_CATEGORY); 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, 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 { Log.i(this.getClass().getName(), "raw Received message " +msg.toString()); String action = msg.getString(param_action).toLowerCase(); JSONObject picto= msg.getJSONObject(param_attributes).getJSONObject(param_picto); JSONObject attrs_picto = picto.optJSONObject(param_attributes); int picto_id = picto.getJSONObject(param_picto).getInt(param_picto_id); int picto_cat = attrs_picto!=null ? attrs_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, 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
......
package com.yottacode.pictogram.grammar;
import com.yottacode.pictogram.dao.Picto;
/**
* Created by Fernando on 14/03/2016.
*/
public interface iLocalPicto {
public void saved(Picto localPicto);
}
...@@ -199,8 +199,8 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{ ...@@ -199,8 +199,8 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{
int st_id_int = st_id.intValue(); int st_id_int = st_id.intValue();
int st_supervision_int = st_supervision.intValue(); int st_supervision_int = st_supervision.intValue();
if (st_supervision_int==2){ if (st_supervision_int==2){
student = new User(st_id_int, st_name, st_surname, st_pic, st_gender, st_lang, st_attributes, student = new User(st_id_int,"nickname_stu","pwd_stu", st_name, st_surname, st_pic, st_gender, st_lang, st_attributes,
sup_id, "", "", "", "M", "es-es", ""); sup_id, "nickname_sup","pwd_sup","", "", "", "M", "es-es", "");
users.add(student); users.add(student);
} }
} }
...@@ -213,8 +213,8 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{ ...@@ -213,8 +213,8 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{
PCBcontext.set_user(student, token, null); // no hay que hacer nada cuando termine PCBcontext.set_user(student, token, null); // no hay que hacer nada cuando termine
} else{ } else{
student = new User(-1, "", "", "", "M", "es-es", "", student = new User(-1, "nickname_stu","pwd_stu","", "", "", "M", "es-es", "",
sup_id, "", "", "", "M", "es-es", ""); sup_id, "nickname_stu","pwd_stu","", "", "", "M", "es-es", "");
PCBcontext.set_user(student, token, new iImgDownloaderListener() { PCBcontext.set_user(student, token, new iImgDownloaderListener() {
@Override @Override
public void loadComplete() { public void loadComplete() {
......
...@@ -43,10 +43,15 @@ import com.yottacode.pictogram.action.VocabularyAction; ...@@ -43,10 +43,15 @@ import com.yottacode.pictogram.action.VocabularyAction;
import com.yottacode.pictogram.dao.Picto; import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.dao.User; import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.grammar.Vocabulary; import com.yottacode.pictogram.grammar.Vocabulary;
import com.yottacode.pictogram.grammar.iLocalPicto;
import com.yottacode.pictogram.grammar.iVocabularyListener; import com.yottacode.pictogram.grammar.iVocabularyListener;
import com.yottacode.pictogram.net.PictoUploader;
import com.yottacode.pictogram.net.iImgDownloaderListener;
import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -542,12 +547,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -542,12 +547,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
return ll; return ll;
} }
// De la interfaz iVocabularyListener public void refresh() {
@Override
public void change(action action, int picto_cat, int picto_id, JSONObject args) {
Log.d(LOG_TAG, "Vocabulary action listened: " + action);
if(args!=null) Log.d(LOG_TAG, "args: " + args.toString());
// Background task that updates the ui into the main thread. // Background task that updates the ui into the main thread.
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
...@@ -567,6 +567,13 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -567,6 +567,13 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
} }
}); });
} }
// De la interfaz iVocabularyListener
@Override
public void change(action action, int picto_cat, int picto_id, JSONObject args) {
Log.d(LOG_TAG, "Vocabulary action listened: " + action);
if(args!=null) Log.d(LOG_TAG, "args: " + args.toString());
refresh();
}
// Disable Back Button --> Kiosk mode // Disable Back Button --> Kiosk mode
@Override @Override
...@@ -850,26 +857,35 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -850,26 +857,35 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
// Set up the input // Set up the input
final EditText input = new EditText(this); final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_TEXT ); input.setInputType(InputType.TYPE_CLASS_TEXT);
builder.setView(input); builder.setView(input);
// Set up the buttons // Set up the buttons
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
int cat=PictogramActivity.this.currentCategory != null ? PictogramActivity.this.currentCategory.get_id() : Picto.NO_CATEGORY; int cat = PictogramActivity.this.currentCategory != null ? PictogramActivity.this.currentCategory.get_id() : Picto.NO_CATEGORY;
Picto localPicto=PCBcontext.getVocabulary().saveLocalPicto( PCBcontext.getVocabulary().saveLocalPicto(
selectedImagePath, selectedImagePath,
input.getText().toString(), input.getText().toString(),
cat, cat,
row, row,
col); col, new iLocalPicto() {
@Override
change(action.add, cat, localPicto.get_id(),null); //gui must be refresh public void saved(Picto localPicto) {
PictogramActivity.this.refresh();
try {
new PictoUploader(localPicto).upload();
} catch (IOException e) {
Log.e(Vocabulary.class.getCanonicalName(), e.getMessage());
}
}
});
} }
}); });
builder.show(); builder.show();
} }
/** /**
* Función para la selección de una foto del carrete * Función para la selección de una foto del carrete
......
...@@ -297,8 +297,8 @@ public class SerialActivity extends Activity implements iRestapiListener { ...@@ -297,8 +297,8 @@ public class SerialActivity extends Activity implements iRestapiListener {
//if (users.contains(user)) users.remove(user); //if (users.contains(user)) users.remove(user);
User student = new User(st_id_int, st_name, st_surname, st_pic, st_gender, st_lang, st_attributes, User student = new User(st_id_int, "nickname_stu","pwd_stu", st_name, st_surname, st_pic, st_gender, st_lang, st_attributes,
-1, "", "", "", "M", "es-es", ""); -1, "nickname_stu","pwd_stu", "", "", "", "M", "es-es", "");
users.add(student); users.add(student);
Log.d(LOG_TAG, "jsonToken válido:" + jsonToken); Log.d(LOG_TAG, "jsonToken válido:" + jsonToken);
......
...@@ -114,7 +114,6 @@ public class ImgDownloader extends AsyncTask<Vector<Img>, Void, Img> { ...@@ -114,7 +114,6 @@ public class ImgDownloader extends AsyncTask<Vector<Img>, Void, Img> {
@Override @Override
protected void onPostExecute(Img img) { protected void onPostExecute(Img img) {
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);
......
...@@ -157,7 +157,7 @@ public class PictoUploader { ...@@ -157,7 +157,7 @@ public class PictoUploader {
* i) to upload the image, * i) to upload the image,
* ii) to upload the attributes * ii) to upload the attributes
* iii) to upload the expression * 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 old_picto=this.picto.get_id();
...@@ -166,7 +166,7 @@ public class PictoUploader { ...@@ -166,7 +166,7 @@ public class PictoUploader {
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,11 +4,8 @@ package com.yottacode.pictogram.tools; ...@@ -4,11 +4,8 @@ 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;
...@@ -16,8 +13,9 @@ import java.io.FileNotFoundException; ...@@ -16,8 +13,9 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Enumeration;
import com.yottacode.tools.FileTools;
import com.yottacode.tools.ImgTools;
/** /**
* Img * Img
...@@ -131,7 +129,7 @@ public class Img { ...@@ -131,7 +129,7 @@ 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, new Rect(0,0,78,66),null); this.bitmap = new ImgTools(BitmapFactory.decodeStream(is)).resize(78,66);
}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());
} }
......
...@@ -56,6 +56,7 @@ public final class PCBcontext { ...@@ -56,6 +56,7 @@ public final class PCBcontext {
device = new Device(c, null, 1); device = new Device(c, null, 1);
wrapper = new RestapiWrapper(context.getResources().getString(R.string.server), null); wrapper = new RestapiWrapper(context.getResources().getString(R.string.server), null);
service = new NetService(context.getResources().getInteger(R.integer.netservice_timing)); service = new NetService(context.getResources().getInteger(R.integer.netservice_timing));
device.deleteDeprecatedImgs();
Log.i(PCBcontext.class.getCanonicalName(), "PCB context started. It's required to be invoked set_user method"); Log.i(PCBcontext.class.getCanonicalName(), "PCB context started. It's required to be invoked set_user method");
} }
else Log.e(PCBcontext.class.getClass().getCanonicalName(), "Init method was previously invoked! Please, revise your code"); else Log.e(PCBcontext.class.getClass().getCanonicalName(), "Init method was previously invoked! Please, revise your code");
......
package com.yottacode.tools;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import java.util.BitSet;
/**
* Created by Fernando on 15/03/2016.
*/
public class ImgTools {
Bitmap bitmap;
public ImgTools(Bitmap bitmap ) { this.bitmap=bitmap;}
public Bitmap resize(int w, int h) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int newWidth = w;
int newHeight = h;
// calculamos el escalado de la imagen destino
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// para poder manipular la imagen
// debemos crear una matriz
Matrix matrix = new Matrix();
// resize the Bitmap
matrix.postScale(scaleWidth, scaleHeight);
// volvemos a crear la imagen con los nuevos valores
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
width, height, matrix, true);
// si queremos poder mostrar nuestra imagen tenemos que crear un
// objeto drawable y así asignarlo a un botón, imageview...
return resizedBitmap;
}
}
...@@ -19,6 +19,8 @@ translation VARCHAR(60) NOT NULL ...@@ -19,6 +19,8 @@ translation VARCHAR(60) NOT NULL
CREATE TABLE student ( CREATE TABLE student (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
nickname TEXT(40) NOT NULL,
pwd TEXT(40) NOT NULL,
name TEXT(40) NOT NULL, name TEXT(40) NOT NULL,
surname TEXT(60) NOT NULL, surname TEXT(60) NOT NULL,
url_img VARCHAR(250) NOT NULL, url_img VARCHAR(250) NOT NULL,
...@@ -30,6 +32,8 @@ attributes TEXT(1024) NULL ...@@ -30,6 +32,8 @@ attributes TEXT(1024) NULL
CREATE TABLE supervisor ( CREATE TABLE supervisor (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
email TEXT(140) NOT NULL,
pwd TEXT(40) NOT NULL,
name TEXT(40) NOT NULL, name TEXT(40) NOT NULL,
surname TEXT(60) NOT NULL, surname TEXT(60) NOT NULL,
url_img VARCHAR(250) NOT NULL, url_img VARCHAR(250) NOT NULL,
...@@ -39,7 +43,7 @@ tts_engine TEXT(100) NULL ...@@ -39,7 +43,7 @@ tts_engine TEXT(100) NULL
) )
;-- ;--
insert into supervisor values(-1,"","","","M","es-es",NULL) insert into supervisor values(-1,"","","","","","M","es-es",NULL)
;-- ;--
CREATE TABLE users ( CREATE TABLE users (
...@@ -76,8 +80,8 @@ type TEXT(5) NOT NULL CHECK (type in ('stu','sup','pic')) ...@@ -76,8 +80,8 @@ type TEXT(5) NOT NULL CHECK (type in ('stu','sup','pic'))
;-- ;--
CREATE VIEW users_detail AS CREATE VIEW users_detail AS
SELECT id_stu, a.name name_stu, a.surname surname_stu, a.url_img url_img_stu, a.gender gender_stu, a.lang lang_stu, a.attributes attributes_stu, SELECT id_stu, a.nickname nickname_stu, a.pwd pwd_stu, a.name name_stu, a.surname surname_stu, a.url_img url_img_stu, a.gender gender_stu, a.lang lang_stu, a.attributes attributes_stu,
id_sup, b.name name_sup, b.surname surname_sup, b.url_img url_img_sup, b.gender gender_sup, b.lang lang_sup, b.tts_engine tts_engine_sup id_sup, b.email email_sup, b.pwd pwd_sup, b.name name_sup, b.surname surname_sup, b.url_img url_img_sup, b.gender gender_sup, b.lang lang_sup, b.tts_engine tts_engine_sup
FROM student a, supervisor b, users FROM student a, supervisor b, users
WHERE a.id=users.id_stu AND b.id=users.id_sup WHERE a.id=users.id_stu AND b.id=users.id_sup
;-- ;--
...@@ -174,8 +178,8 @@ CREATE TRIGGER trg_insert_users_detail ...@@ -174,8 +178,8 @@ CREATE TRIGGER trg_insert_users_detail
INSTEAD OF INSERT ON users_detail INSTEAD OF INSERT ON users_detail
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
INSERT OR REPLACE INTO student VALUES (NEW.id_stu, NEW.name_stu, NEW.surname_stu, NEW.url_img_stu, NEW.gender_stu, NEW.lang_stu, NEW.attributes_stu); INSERT OR REPLACE INTO student VALUES (NEW.id_stu, NEW.nickname_stu, NEW.pwd_stu, NEW.name_stu, NEW.surname_stu, NEW.url_img_stu, NEW.gender_stu, NEW.lang_stu, NEW.attributes_stu);
INSERT OR REPLACE INTO supervisor VALUES (NEW.id_sup, NEW.name_sup, NEW.surname_sup, NEW.url_img_sup, NEW.gender_sup, NEW.lang_sup, NEW.tts_engine_sup); INSERT OR REPLACE INTO supervisor VALUES (NEW.id_sup, NEW.email_sup, NEW.pwd_sup, NEW.name_sup, NEW.surname_sup, NEW.url_img_sup, NEW.gender_sup, NEW.lang_sup, NEW.tts_engine_sup);
INSERT INTO users VALUES (NEW.id_stu,NEW.id_sup); INSERT INTO users VALUES (NEW.id_stu,NEW.id_sup);
END END
;-- ;--
...@@ -184,8 +188,8 @@ CREATE TRIGGER trg_update_users_detail ...@@ -184,8 +188,8 @@ CREATE TRIGGER trg_update_users_detail
INSTEAD OF UPDATE ON users_detail INSTEAD OF UPDATE ON users_detail
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
UPDATE student SET name=NEW.name_stu, surname=NEW.surname_stu, url_img=NEW.url_img_stu, gender=NEW.gender_stu, lang=NEW.lang_stu, attributes=NEW.attributes_stu WHERE id=NEW.id_stu; UPDATE student SET nickname=NEW.nickname_stu, pwd=NEW.pwd_stu,name=NEW.name_stu, surname=NEW.surname_stu, url_img=NEW.url_img_stu, gender=NEW.gender_stu, lang=NEW.lang_stu, attributes=NEW.attributes_stu WHERE id=NEW.id_stu;
UPDATE supervisor SET name=NEW.name_sup, surname=NEW.surname_sup, url_img=NEW.url_img_sup, gender=NEW.gender_sup, lang=NEW.lang_sup, tts_engine=NEW.tts_engine_sup WHERE id=NEW.id_sup; UPDATE supervisor SET email=NEW.email_sup, pwd=NEW.pwd_sup, name=NEW.name_sup, surname=NEW.surname_sup, url_img=NEW.url_img_sup, gender=NEW.gender_sup, lang=NEW.lang_sup, tts_engine=NEW.tts_engine_sup WHERE id=NEW.id_sup;
END END
;-- ;--
......
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