Pictogram 1.6, Beta 3, issue #423, varios problemas solucionados relativos a:

- grids vacios
- pérdida de conexión justo entre el login de supervisor y la selección de alumnos
- borrado de pictos online/offline
parent dbbe1c3b
......@@ -166,12 +166,9 @@ public class RestapiWrapper {
JSONresponse = new JSONObject("{ "+SERVER_RESULT+": " + response + (responseCode == HttpURLConnection.HTTP_OK
? "}"
: ", "+SERVER_ERROR+": " + responseCode +"}"));
int i=0;
String sresponse=JSONresponse.toString();
do {
Log.i(LOG_TAG, "Server answer("+i+"):" + sresponse.substring(i*1000,((i+1)*1000)>sresponse.length() ? sresponse.length() : (i+1)*1000));
i++;
}while (i*1000<sresponse.length());
Log.i(LOG_TAG, "Server answer:" + JSONresponse.toString());
} catch (JSONException e) {
JSONresponse = null;
Log.e(RestapiWrapper.class.getCanonicalName(),e.getMessage());
......@@ -225,14 +222,15 @@ public class RestapiWrapper {
params.remove("json");
} else
sparams="";
for (String param : params.keySet()) {
String value = params.get(param);
if (param.equals("token"))
urlConnection.setRequestProperty("Authorization", "Bearer " + value);
else {
if (sparams.length() > 0) sparams += '&';
sparams += param + '=' + value;
}
String value = params.get(param);
if (param.equals("token"))
urlConnection.setRequestProperty("Authorization", "Bearer " + value);
else {
if (sparams.length() > 0) sparams += '&';
sparams += param + '=' + value;
}
}
//Send request
......
......@@ -180,6 +180,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
Picto picto = new Picto(cursor.getInt(1), cursor.getString(5),cursor.getInt(4),cursor.getInt(2),cursor.getInt(3),new JSONObject(cursor.getString(7)));
vocabulary.addPicto(picto);
}while (cursor.moveToNext());
cursor.close();
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
......@@ -287,7 +288,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
values.put("translation",picto.get_translation());
values.put("attributes",picto.get_json_attrs());
db.insertWithOnConflict("collection_detail", null, values,SQLiteDatabase.CONFLICT_REPLACE);
Log.i(LOG_TAG,"Picto added:"+picto.get_translation()+" id:"+picto.get_ImgId()+" stupicto_id:"+picto.get_stupicto_id()+" grid:"+picto.get_grid()
Log.i(LOG_TAG,"Picto added/updated:"+picto.get_translation()+" id:"+picto.get_ImgId()+" stupicto_id:"+picto.get_stupicto_id()+" grid:"+picto.get_grid()
+". Attributes:"+picto.get_json_attrs()+". Local:"+picto.local_status()+". Local Updated:"+picto.local_update());
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
}
......
......@@ -307,7 +307,7 @@ public class Picto extends Img {
}
public boolean is_invisible1() {
try {
return this.attributes.getString(JSON_ATTTRS.STATUS).equals(JSON_ATTTR_STATUS_VALUES.INVISIBLE);
return this.attributes.getString(JSON_ATTTRS.STATUS).equals(JSON_ATTTR_STATUS_VALUES.INVISIBLE) || this.attributes.getString(JSON_ATTTRS.STATUS).equals(JSON_ATTTR_STATUS_VALUES.DELETED);
} catch (JSONException e) {
Log.e(LOG_TAG,e.getMessage());
return false;
......@@ -338,7 +338,7 @@ public class Picto extends Img {
}
public void set_visible(boolean visible) {
try {
if (!is_deleted()) try {
this.attributes.put(JSON_ATTTRS.STATUS, visible ? JSON_ATTTR_STATUS_VALUES.ENABLED : JSON_ATTTR_STATUS_VALUES.INVISIBLE);
} catch (JSONException e) {
......@@ -367,7 +367,7 @@ public class Picto extends Img {
? JSON_ATTTR_STATUS_VALUES.ENABLED
: this.attributes.getString(JSON_ATTTRS.STATUS);
} catch (JSONException e) {
return "enabled"; // By default
return JSON_ATTTR_STATUS_VALUES.ENABLED; // By default
}
}
......@@ -492,7 +492,7 @@ public class Picto extends Img {
try {
this.attributes.put(JSON_ATTTRS.STATUS, status);
set_local_status(true);
if (!is_local()) {
if (!is_local() && !is_deleted() && PCBcontext.is_user_online() ) {
new PictoUploader(this).uploadState();
PCBcontext.getActionLog().log(new VocabularyAction(VocabularyAction.ALTERATTRS, this));
}
......@@ -512,7 +512,7 @@ public class Picto extends Img {
}
public boolean is_deleted() {
return this.attributes.optString(JSON_ATTTRS.PCB_STATUS_MODIFICATION,"").equals(JSON_ATTTR_STATUS_VALUES.DELETED);
return this.attributes.optString(JSON_ATTTRS.STATUS,"").equals(JSON_ATTTR_STATUS_VALUES.DELETED);
}
/**
......
......@@ -51,7 +51,6 @@ public class Vocabulary implements Iterable<Picto> {
}else
try {
PCBcontext.getPcbdb().getStudentVocabulary(this);
deleteLocallyDeletedPictos();
if (listener!=null)
listener.loadComplete();
} catch (JSONException e) {
......@@ -59,16 +58,7 @@ public class Vocabulary implements Iterable<Picto> {
listener.error(e);
}
}
private void deleteLocallyDeletedPictos() {
Vector<Picto> pictos_to_be_removed=new Vector<>(3);
for (Picto picto: this)
if (picto.local_status()) {
if (picto.is_deleted())
pictos_to_be_removed.add(picto);
}
for (Picto deleted_picto:pictos_to_be_removed)
this.logicalDeletePicto(deleted_picto.get_grid(),deleted_picto.get_ImgId());
}
public void listen(Room room, VocabularyTalk.iVocabularyListener listener, ActionTalk.iActionListener action_listener) {
VocabularyTalk.iVocabularyListener vocabulary_listeners[] = {new VocabularyTalk.iVocabularyListener() {
@Override
......@@ -163,8 +153,9 @@ public class Vocabulary implements Iterable<Picto> {
private int find_picto_index(int grid_id,int pic_id) {
LinkedList<Picto> pictos_cat = this.pictos.get(grid_id);
int index=-1;
for (int i=0; i<pictos_cat.size() && index==-1; i++)
if (pictos_cat.get(i).get_ImgId()==pic_id) index=i;
if (pictos_cat!=null)
for (int i=0; i<pictos_cat.size() && index==-1; i++)
if (pictos_cat.get(i).get_ImgId()==pic_id) index=i;
return index;
}
......@@ -172,8 +163,9 @@ public class Vocabulary implements Iterable<Picto> {
private Picto find_picto(int id_grid, int row, int column) {
LinkedList<Picto> pictos_cat=this.pictos.get(id_grid);
Picto picto=null;
for (int i=0; i<pictos_cat.size() && picto==null; i++)
if (pictos_cat.get(i).get_column()==column && pictos_cat.get(i).get_row()==row) picto=pictos_cat.get(i);
if (pictos_cat!=null)
for (int i=0; i<pictos_cat.size() && picto==null; i++)
if (pictos_cat.get(i).get_column()==column && pictos_cat.get(i).get_row()==row) picto=pictos_cat.get(i);
return picto;
}
......@@ -187,19 +179,13 @@ public class Vocabulary implements Iterable<Picto> {
public Picto get_picto(int pic_grid,int pic_id) {
Picto picto=null;
LinkedList<Picto> pictos_grid=this.pictos.get(pic_grid);
for (int i=0; i<pictos_grid.size() && picto==null; i++)
if (pictos_grid.get(i).get_ImgId()==pic_id) picto=pictos_grid.get(i);
if (pictos_grid!=null)
for (int i=0; i<pictos_grid.size() && picto==null; i++)
if (pictos_grid.get(i).get_ImgId()==pic_id) picto=pictos_grid.get(i);
return picto;
}
public Picto get_stupicto(int stupicto_id) {
for (Picto picto:this)
if (picto.get_stupicto_id()==stupicto_id)
return picto;
return null;
}
/**
......@@ -207,19 +193,21 @@ public class Vocabulary implements Iterable<Picto> {
* @param pic_id
*/
public void removePicto(int pic_grid,int pic_id){
if (logicalDeletePicto(pic_grid,pic_id))
PCBcontext.getPcbdb().deletePicto(pic_grid,pic_id);
else
Log.i(this.getClass().getCanonicalName(),"Trying to delete an unregistered picto:"+pic_id+" cat:"+pic_grid);
int index = find_picto_index(pic_grid, pic_id);
boolean legal_delete=index>=0;
if (legal_delete) {//puede ocurrir que se intente borrar un pictograma dos veces
pictos.get(new Integer(pic_grid)).remove(index);
PCBcontext.getPcbdb().deletePicto(pic_grid, pic_id);
for (Picto p2:pictos.get(new Integer(pic_grid))) {
Log.e(LOG_TAG,"COJONES VOCABULA_>"+p2.get_translation());
}
}
}
public boolean logicalDeletePicto(int pic_grid, int pic_id){
LinkedList<Picto> pictos_grid=this.pictos.get(pic_grid);
int index = find_picto_index(pic_grid, pic_id);
boolean legal_delete=index>0;
boolean legal_delete=index>=0;
if (legal_delete) { //puede ocurrir que se intente borrar un pictograma dos veces
Picto p = pictos_grid.get(index);
p.alter_status(Picto.JSON_ATTTR_STATUS_VALUES.DELETED);
......
......@@ -6,6 +6,7 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Vector;
/**
* PCB Vocabulary manager
......@@ -18,7 +19,11 @@ public class VocabularyIterator implements Iterator<Picto> {
Integer child_grid;
int location;
VocabularyIterator(Hashtable<Integer,LinkedList<Picto>> pictos) {
this.keys = pictos.keys();
Vector<Integer> vkeys=new Vector(pictos.size());
for (Integer key:pictos.keySet())
if (pictos.get(key).size()>0)
vkeys.add(key);
this.keys=vkeys.elements();
if (pictos.size()>=1) {
this.pictos=pictos;
this.child_grid = this.keys.nextElement();
......@@ -43,9 +48,7 @@ public class VocabularyIterator implements Iterator<Picto> {
if ( this.location==pictos.get(child_grid).size()) {
this.location = 0;
this.child_grid = this.keys.nextElement();
}
picto=pictos.get(child_grid).get(location++);
return picto;
}
......
......@@ -155,14 +155,16 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
public void result(JSONArray result) {
}
@Override
public void result(JSONObject result) {
public void result(final JSONObject result) {
ConnectivityManager cm =
(ConnectivityManager)PCBcontext.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
if (!isConnected)
if (!isConnected) {
setOffline(new NetworkErrorException("No Internet access"));
return;
}
try {
final float version = ((float)(Float.valueOf(result.getString("version")).intValue()*10))/10;
......@@ -176,17 +178,24 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
if (!updated) {
nextRestfullSynchro = new Date().getTime();
updated = true;
String TAG_TOKEN="token";
try {
PCBcontext.getRestapiWrapper().setToken(result.getString(TAG_TOKEN));
Log.e(LOG_TAG,"AAAAAAAAAAAAAAAAAAAAAAAAAAAATOken:"+result.getString(TAG_TOKEN));
} catch (JSONException e) {
Log.e(LOG_TAG,"Error when getting token:"+e.getMessage()+" res:"+result.toString());
}
if (PCBcontext.is_user_logged()) //si el usuario aun no hizo login, en realidad no es necesario hacer nada
// Comprobar si hay usuario offline, para hacer login transparente
if (PCBcontext.is_user_offline()) {
Log.i(LOG_TAG, "PCB online login from offline login");
Log.e(LOG_TAG, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPCB online login from offline login");
login();
} else if (PCBcontext.is_user_online()) {
Log.i(LOG_TAG, "PCB reconnect");
Log.e(LOG_TAG, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPCB reconnect");
PCBcontext.getRoom().connect();
synchronizeStuData();
PCBcontext.getActionLog().batch();
}
} else Log.e(LOG_TAG,"AAAAAAAAAAAAAAAAAAAAAAAAAAAATOkener:"+result.toString());
} else {
//cada restfullSynchroTimming aprox. se fuerza sincronización de vocabulario y configuración de usuario
......
......@@ -28,9 +28,14 @@ import java.util.concurrent.ExecutionException;
* Created by Fernando on 02/03/2016.
*/
public class PictoUploader {
public interface iDeletedOnServer {
void ok(int npictos);
void fail();
}
private static final String LOG_TAG = PictoUploader.class.getName();
Picto picto=null;
private int local_img_id=Picto.STUPICTO_NULL;
private int local_img_id;
private boolean exists_local_img=false;
public PictoUploader(Picto picto) {
this.picto=picto;
......@@ -67,7 +72,8 @@ public class PictoUploader {
int img_id=response.getResult().get("id").getAsInt();
String img_uri=response.getResult().get("uri").getAsString();
img.set_url(img_uri);
local_img_id =img.get_ImgId();
local_img_id=img.get_ImgId();
exists_local_img=true;
img.update_id(img_id);
} else {
Log.i(LOG_TAG, "Uploaded image failed ");
......@@ -337,22 +343,18 @@ public class PictoUploader {
if (picto.local_update())
picto.set_local_update(false);
if (local_img_id!=Picto.STUPICTO_NULL) {
if (exists_local_img) {
picto.set_local_status(false);
Log.i(LOG_TAG, "Deleting local picto " + picto.get_ImgId() + " ");
PCBcontext.getPcbdb().deletePicto(picto.get_grid(), local_img_id);
try {
int stupicto_id = server_response.getInt("id");
picto.set_stupicto_id(stupicto_id);
PCBcontext.getVocabulary().addPicto(picto);
} catch (JSONException e) {
fail(e.getMessage());
Log.e(LOG_TAG, "Error uploading picto when getting json from server:" + e.getMessage() + ":" + server_response.toString());
}
exists_local_img=false;
PCBcontext.getPcbdb().savePicto(this.picto);
PCBcontext.getRoom().emit(new VocabularyAction(VocabularyAction.ADD, this.picto));
}
......@@ -368,7 +370,7 @@ public class PictoUploader {
uploadAttributes();
}
public void deletePicto() {
public void deletePicto(final iDeletedOnServer listener) {
PCBcontext.getRestapiWrapper().ask(
PCBcontext.getPcbdb().getCurrentUser().get_restapi_operation_stu() + "/picto/"+picto.get_stupicto_id(),
......@@ -384,22 +386,18 @@ public class PictoUploader {
@Override
public void result(JSONObject result) {
Log.i(PictoUploader.LOG_TAG, "Delete Picto ok" + PictoUploader.this.picto.get_stupicto_id());
Log.i(PictoUploader.LOG_TAG, "Delete Picto ok: " + PictoUploader.this.picto.get_translation());
PCBcontext.getRoom().emit(new VocabularyAction(VocabularyAction.DELETE, PictoUploader.this.picto));
PCBcontext.getVocabulary().removePicto(picto.get_grid(),picto.get_ImgId());
Toast.makeText(
PCBcontext.getActivityContext(),
(PCBcontext.getActivityContext().getResources().getString(R.string.picto_delete_ok)
+":"+PictoUploader.this.picto.get_translation()), Toast.LENGTH_LONG).show();
if (listener!=null)
listener.ok(1);
}
@Override
public void error(RestapiWrapper.HTTPException e) {
Log.e(LOG_TAG, "Error when deleting picto: " + e.getLocalizedMessage());
Toast.makeText(
PCBcontext.getActivityContext(),
(PCBcontext.getActivityContext().getResources().getString(R.string.picto_delete_fail)
+":"+PictoUploader.this.picto.get_translation()), Toast.LENGTH_LONG).show();
if (listener!=null)
listener.fail();
}
}
);
......
......@@ -2,9 +2,11 @@ package com.yottacode.pictogram.net;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;
import com.yottacode.net.RestapiWrapper;
import com.yottacode.net.TransactionMonitor;
import com.yottacode.pictogram.commonlibrary.R;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.grammar.Vocabulary;
import com.yottacode.pictogram.tools.Img;
......@@ -35,11 +37,30 @@ public class VocabularyDownloader {
this.imgListener=imgListener;
}
public void synchronize() {
synchronize_upload();
pictos.clear();
TransactionMonitor.startTransaction(PCBcontext.getPcbdb());
PCBcontext.getPcbdb().deleteVocabulary(TransactionMonitor.getDBOnTransaction());
synchronize(Picto.ACTIVE_GRID);
synchronize_upload(new PictoUploader.iDeletedOnServer() {
@Override
public void ok(int npictos) {
pictos.clear();
TransactionMonitor.startTransaction(PCBcontext.getPcbdb());
PCBcontext.getPcbdb().deleteVocabulary(TransactionMonitor.getDBOnTransaction());
if (npictos>0)
Toast.makeText(
PCBcontext.getActivityContext(),
PCBcontext.getActivityContext().getResources().getString(R.string.picto_delete_ok)+" "+npictos+ " pictos"
, Toast.LENGTH_LONG).show();
synchronize(Picto.ACTIVE_GRID);
}
@Override
public void fail() {
Log.e(LOG_TAG,"error uploading deleted pictos");
Toast.makeText(
PCBcontext.getActivityContext(),
PCBcontext.getActivityContext().getResources().getString(com.yottacode.pictogram.commonlibrary.R.string.picto_delete_fail)
, Toast.LENGTH_LONG).show();
}
});
}
private void synchronize(final int id_grid) {
......@@ -173,7 +194,7 @@ public class VocabularyDownloader {
* The only issue is: what happens whether the upload fails? --> The image will be lost.
* TODO: keep record of failed uploaded images to re-include as local pictos
*/
private void synchronize_upload() {
private void synchronize_upload(final PictoUploader.iDeletedOnServer deleted_pictos) {
try {
if (this.pictos.isEmpty())
......@@ -183,16 +204,10 @@ public class VocabularyDownloader {
}
Vector<Picto> pictos_to_be_removed=new Vector<>(3);
for (Picto picto: vocabulary) {
if (picto.local_status()) {
if (picto.is_deleted())
pictos_to_be_removed.add(picto);
else {
new PictoUploader(picto).uploadState();
Log.i(this.getClass().getCanonicalName(), "Picto status modified while offline. Picto translation: '" +
picto.get_translation() + "', id:" + picto.get_ImgId() + " Local status?" + picto.local_status());
}
}
if (picto.is_local())
if (picto.is_deleted())
pictos_to_be_removed.add(picto);
else
if (picto.is_local())
try {
Log.i(this.getClass().getCanonicalName(), "Picto added while offline. Picto translation: '" +
......@@ -201,17 +216,43 @@ public class VocabularyDownloader {
} catch (IOException e) {
e.printStackTrace();
Log.e(this.getClass().getName(), " Picto json error from server when uploading: " + picto.toString()+" Message:"+e.getMessage());
}
if (picto.local_update()) {
new PictoUploader(picto).uploadUpdate();
Log.i(this.getClass().getCanonicalName(), "Picto was modified while offline. Picto translation: '" +
picto.get_translation() + "', id:" + picto.get_ImgId() + " Local status?" + picto.local_status());
else {
if (picto.local_status()) {
new PictoUploader(picto).uploadState();
Log.i(this.getClass().getCanonicalName(), "Picto status modified while offline. Picto translation: '" +
picto.get_translation() + "', id:" + picto.get_ImgId() + " Local status?" + picto.local_status());
}
if (picto.local_update()) {
new PictoUploader(picto).uploadUpdate();
Log.i(this.getClass().getCanonicalName(), "Picto was modified while offline. Picto translation: '" +
picto.get_translation() + "', id:" + picto.get_ImgId() + " Local status?" + picto.local_status());
}
}
}
if (pictos_to_be_removed.size()>0) {
final int npictos = pictos_to_be_removed.size();
PictoUploader.iDeletedOnServer listener1 = new PictoUploader.iDeletedOnServer() {
int deleted = 0;
for (Picto deleted_picto:pictos_to_be_removed)
new PictoUploader(deleted_picto).deletePicto();
@Override
public void ok(int n) {
deleted++;
if (deleted == npictos)
deleted_pictos.ok(npictos);
}
@Override
public void fail() {
deleted_pictos.fail();
}
};
for (Picto deleted_picto : pictos_to_be_removed) {
new PictoUploader(deleted_picto).deletePicto(listener1);
}
}
else deleted_pictos.ok(0);
}
......
......@@ -30,7 +30,8 @@ public class PictoGridAdapter extends ArrayAdapter {
@Override
public Picto getItem(int position) {
return this.pictoLinkedList.get(position);
Picto item= this.pictoLinkedList.get(position);
return item!=null && !item.is_deleted() ? item : null;
}
@Override
......
......@@ -126,7 +126,7 @@ public class PictoItemViewGenerator {
pictoImage.setImageBitmap(null);
layoutWrapper.setAlpha(1f);
boolean onVocabularyManager=PCBcontext.getActivityContext().getClass().getSimpleName().equals(VocabularyManager.class.getSimpleName());
boolean onVocabularyManager=PCBcontext.getActivityContext().getClass().getSimpleName().equals(VocabularyManager.class.getSimpleName()) ;
// Picto visibility
if ( onVocabularyManager || (picto != null && !picto.is_invisible())) {
......@@ -138,7 +138,7 @@ public class PictoItemViewGenerator {
if (picto!=null) {
micro_icon.setVisibility(picto.getUriSound() == null || !onVocabularyManager ? View.GONE : View.VISIBLE);
layoutWrapper.setAlpha(!picto.is_invisible() || (onVocabularyManager && !picto.is_invisible1()) ? 1.00f : onVocabularyManager ? 0.25f : 0f);
layoutWrapper.setAlpha(!picto.is_invisible() || (onVocabularyManager && !picto.is_invisible1()) ? 1.00f : onVocabularyManager && !picto.is_deleted() ? 0.25f : 0f);
try {
Bitmap bm = picto.get_bitmap(PCBcontext.getContext());
......
......@@ -4,6 +4,7 @@ import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.net.PictoUploader;
......@@ -235,11 +236,32 @@ public class PictoMenu {
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated()
{
PCBcontext.getVocabulary().logicalDeletePicto(p.get_grid(),p.get_ImgId());
final PictoGridAdapter adapter=activity.getCurrentPictoGridAdapter();
if (PCBcontext.getNetService().online())
new PictoUploader(p).deletePicto(); //delete on server side
activity.getCurrentPictoGridAdapter().notifyDataSetChanged();
activity.refresh();
new PictoUploader(p).deletePicto(new PictoUploader.iDeletedOnServer() {
@Override
public void ok(int npictos) {
Toast.makeText(
activity,
(PCBcontext.getActivityContext().getResources().getString(com.yottacode.pictogram.commonlibrary.R.string.picto_delete_ok)
+":"+p.get_translation()), Toast.LENGTH_LONG).show();
adapter.notifyDataSetChanged();
activity.refresh();
}
@Override
public void fail() {
Toast.makeText(
activity,
(PCBcontext.getActivityContext().getResources().getString(com.yottacode.pictogram.commonlibrary.R.string.picto_delete_fail)
+":"+p.get_translation()), Toast.LENGTH_LONG).show();
}
}); //delete on server side
else {
PCBcontext.getVocabulary().logicalDeletePicto(p.get_grid(), p.get_ImgId());
adapter.notifyDataSetChanged();
activity.refresh();
}
ll.setVisibility(View.GONE);
((RelativeLayout)PieMenu.getParent()).removeView(PieMenu);
......
......@@ -6,15 +6,12 @@ import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
......@@ -98,14 +95,12 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab
int maxColumns, maxRows, maxInTape;
ScheduledThreadPoolExecutor exec_mirror = null;
Picto prev_picto = null;
private boolean feedback_read;
private boolean feedback_highlight;
protected boolean deleting;
;
protected boolean tape_delivered = false;
;
float firstTouchX = -1;
public boolean inserting = false;
@TargetApi(Build.VERSION_CODES.M)
@Override
......@@ -275,59 +270,6 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab
}
private void setFeedback(View views[]) {
boolean vibration = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.VIBRATION);
boolean click = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.BEEP);
this.feedback_read = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.READ);
this.feedback_highlight = PCBcontext.getPcbdb().getCurrentUser().input_feedback_on(User.JSON_STUDENT_INPUT_FEEDBACK.HIGHLIGHT);
Log.i(this.getClass().getCanonicalName(), "Feedback:" + " vibration:" + vibration + " Beep:" + click + " Read:" + feedback_read + " Highlight:" + feedback_highlight);
View.OnTouchListener touchListener;
touchListener =
vibration ? new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
boolean enable_haptic;
enable_haptic = !(v instanceof GridView);
if (!enable_haptic) {
int x = Math.round(event.getX());
int y = Math.round(event.getY());
int position = ((GridView) v).pointToPosition(x, y);
Picto p = position > -1 ? (Picto) ((GridView) v).getItemAtPosition(position) : null;
enable_haptic = (p != null && p.get_ImgId() != 0 && !p.is_invisible() && p.is_enabled());
}
if (enable_haptic)
v.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
return false;
}
}
: click
? new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
: new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
};
for (View view : views)
view.setOnTouchListener(touchListener);
}
@Override
protected void onPause() {
......@@ -426,7 +368,7 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab
this.pictoCategoryGridAdapter.clear();
this.pictoCategoryGridAdapter.addAll(this.sort(this.vocabulary.next(this.currentGrid)));
this.pictoCategoryGridAdapter.notifyDataSetChanged();
Log.e(LOG_TAG,"Grid color:"+PCBcontext.getPcbdb().getGridColor(currentGrid));
this.pictoCategoryGridView.setBackgroundColor(PCBcontext.getPcbdb().getGridColor(currentGrid));
this.pictoMainGridView.setEnabled(false);
......@@ -538,7 +480,7 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab
private class OnPictoClickListener implements AdapterView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (inserting) return;
Picto p = getCurrentPictoGridAdapter().getItem(position);
if (p != null && p.get_ImgId() != 0 ) {
......@@ -602,7 +544,7 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
// Si es supervisor al hacer longClick deshabilito ese pictograma o lo habilito
Picto p = getCurrentPictoGridAdapter().getItem(position);
Log.e(LOG_TAG,"PREV:"+p+(p!=null ? p.get_legend() : "->nulo"));
if (p == null) {
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete
......@@ -665,7 +607,7 @@ public class VocabularyManager extends Activity implements VocabularyTalk.iVocab
}
if (nextActivity != null) {
tape_delivered = false;
finish();
startActivity(nextActivity);
overridePendingTransition(in, out);
......
......@@ -84,6 +84,11 @@ public class StudentFragmentGrid extends Fragment {
private void set_user(int i) {
Boolean offline = getActivity().getIntent().getBooleanExtra("offline", false);
if (offline) {
Log.e(LOG_TAG,"COJONES"+PCBcontext.getNetService().online());
if (PCBcontext.getNetService().online()) {
PCBcontext.getNetService().restart_app(false);
return;
}
User currentUser = null;
try {
currentUser = PCBcontext.getDevice().findUser(idStudents.get(i), getActivity().getIntent().getIntExtra("sup_id", 0));
......
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