working no duplicate picto and friendly update

parent 46ef4204
Showing with 299 additions and 150 deletions
...@@ -11,15 +11,16 @@ android { ...@@ -11,15 +11,16 @@ android {
versionName "1.0" versionName "1.0"
resValue "string", "db_name", "PCB.db" resValue "string", "db_name", "PCB.db"
resValue "integer", "db_version", "4" resValue "integer", "db_version", "4"
resValue "string", "app_version", "1.0" resValue "string", "app_version", "1.1"
resValue "string", "core_vocabulary", "core_vocabulary" resValue "string", "core_vocabulary", "core_vocabulary"
resValue "string", "apk", "to_be_set_in_subproject" resValue "string", "apk", "to_be_set_in_subproject"
resValue "string", "VersionManagerClass", "to_be_set_in_subproject"
} }
buildTypes { buildTypes {
release { release {
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", "server", "https://pictogram.yottacode.com" resValue "string", "server", "https://api.pictogramweb.com"
resValue "bool", "force_db_create", "false" resValue "bool", "force_db_create", "false"
resValue "bool", "ssl_connect", "true" resValue "bool", "ssl_connect", "true"
resValue "bool", "force_img_download", "false" resValue "bool", "force_img_download", "false"
...@@ -27,7 +28,7 @@ android { ...@@ -27,7 +28,7 @@ android {
resValue "integer", "netservice_force_restfull_synchro", "30" resValue "integer", "netservice_force_restfull_synchro", "30"
} }
debug { debug {
resValue "string", "server", "https://dev.yottacode.com" resValue "string", "server", "https://apidev.pictogramweb.com"
resValue "bool", "force_db_create", "false" resValue "bool", "force_db_create", "false"
resValue "bool", "ssl_connect", "false" resValue "bool", "ssl_connect", "false"
resValue "bool", "force_img_download", "false" resValue "bool", "force_img_download", "false"
......
...@@ -246,6 +246,15 @@ public class Picto extends Img { ...@@ -246,6 +246,15 @@ public class Picto extends Img {
return false; return false;
} }
} }
public void set_visible(boolean visible) {
try {
this.attributes.put(JSON_ATTTRS.STATUS, visible ? JSON_ATTTR_STATUS_VALUES.ENABLED : JSON_ATTTR_STATUS_VALUES.INVISIBLE);
} catch (JSONException e) {
Log.e(LOG_TAG,e.getMessage());
}
}
/** /**
* *
* @return the highlight property of a picto * @return the highlight property of a picto
......
package com.yottacode.pictogram.net; package com.yottacode.pictogram.net;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri; import android.net.Uri;
import android.os.Environment;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent;
import android.widget.TextView;
import com.yottacode.net.RestapiWrapper; import com.yottacode.net.RestapiWrapper;
import com.yottacode.pictogram.R; import com.yottacode.pictogram.R;
...@@ -29,21 +16,11 @@ import org.json.JSONArray; ...@@ -29,21 +16,11 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date; import java.util.Date;
import java.util.Vector; import java.util.Vector;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.net.ssl.HttpsURLConnection;
import static android.app.Activity.RESULT_OK;
/** /**
* Background services to be executed every "delay" seconds. Tasks to be executed: * Background services to be executed every "delay" seconds. Tasks to be executed:
...@@ -164,6 +141,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -164,6 +141,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
/** /**
* ping to the server by using a restapi call. If ok, the call will return the empty set * ping to the server by using a restapi call. If ok, the call will return the empty set
*/ */
Context newVersionContext=null;
@Override @Override
public void run() { public void run() {
try { try {
...@@ -176,14 +154,14 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -176,14 +154,14 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
@Override @Override
public void result(JSONArray result) { public void result(JSONArray result) {
} }
@Override @Override
public void result(JSONObject result) { public void result(JSONObject result) {
try { try {
float version = Float.valueOf(result.getString("version")).floatValue(); final float version = Float.valueOf(result.getString("version")).floatValue();
if (PCBcontext.getActivityContext() != null && version > DeviceHelper.getAppVersion()) {
Log.e(LOG_TAG, "New version is required! from v" + DeviceHelper.getAppVersion() + " to v" + version+" Activity:"+PCBcontext.getActivityContext().getClass().getCanonicalName()); if (PCBcontext.getActivityContext() != null && version > DeviceHelper.getAppVersion() && newVersionContext!=PCBcontext.getActivityContext()) {
newVersionAlert(PCBcontext.getActivityContext(), version); newVersionContext=PCBcontext.getActivityContext(); // prevent from showing several times the alert
newVersionAlert(version,PCBcontext.getActivityContext(), version);
} }
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG, "PING JSON ERROR: " + result + " " + e.getMessage()); Log.e(LOG_TAG, "PING JSON ERROR: " + result + " " + e.getMessage());
...@@ -287,88 +265,18 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -287,88 +265,18 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
device=(iNetServiceDevice)listener; device=(iNetServiceDevice)listener;
return device; return device;
} }
static void newVersionAlert(final Context context, final float vnew) { static void newVersionAlert(final float version, final Context context, final float vnew) {
String apkurl=context.getResources().getString(R.string.server) try {
+ "/" + context.getResources().getString(R.string.apk); iVersionManager versionManager = (iVersionManager)Class.forName(context.getResources().getString(R.string.VersionManagerClass)).newInstance();
apkurl="http://www4.ujaen.es/~dofer/pictogram_dev.apk"; versionManager.newVersionAlert(version,context,vnew);
} catch (InstantiationException e) {
//get destination to update file and set Uri e.printStackTrace();
//TODO: First I wanted to store my update .apk file on internal storage for my app but apparently android does not allow you to open and install } catch (IllegalAccessException e) {
//aplication with existing package from there. So for me, alternative solution is Download directory in external storage. If there is better e.printStackTrace();
//solution, please inform us in comment } catch (ClassNotFoundException e) {
String destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/"; e.printStackTrace();
String fileName = "AppName.apk";
destination += fileName;
final Uri uri = Uri.parse("file://" + destination);
//Delete update file if exists
File file = new File(destination);
if (file.exists())
//file.delete() - test this, I think sometimes it doesnt work
file.delete();
//get url of app on server
String url = apkurl;
//set downloadmanager
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription(context.getString(R.string.new_version_detail));
request.setTitle(context.getString(R.string.app_name));
//set destination
request.setDestinationUri(uri);
// get download service and enqueue file
final DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
final long downloadId = manager.enqueue(request);
//set BroadcastReceiver to install app when .apk is downloaded
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
Intent install = new Intent(Intent.ACTION_VIEW);
install.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
install.setDataAndType(uri,
manager.getMimeTypeForDownloadedFile(downloadId));
context.startActivity(install);
context.unregisterReceiver(this);
}
};
//register receiver for when .apk download is compete
context.registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
if (true) return;
final SpannableString s = new SpannableString(context.getResources().getString(R.string.server)
+ "/" + context.getResources().getString(R.string.apk));
final TextView tx1 = new TextView(context);
tx1.setText("\t"+context.getResources().getString(R.string.new_version_detail) +
"\n\t\t"+ s);
tx1.setTextSize(16);
tx1.setAutoLinkMask(RESULT_OK);
tx1.setMovementMethod(LinkMovementMethod.getInstance());
Linkify.addLinks(s, Linkify.WEB_URLS);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(context.getResources().getString(R.string.app_name)+": "+context.getResources().getString(R.string.new_version_title)+" v"+vnew)
.setCancelable(false)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
DeviceHelper.setAppVersion(vnew);
}
})
.setView(tx1).setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
return false;
} }
}).show();
PCBcontext.setActivityContext(null);
} }
/** /**
* Created by Fernando on 12/08/2016. * Created by Fernando on 12/08/2016.
......
package com.yottacode.pictogram.net;
import android.content.Context;
/**
* Created by Fernando on 10/03/2017.
*/
public interface iVersionManager {
void newVersionAlert(final float version, final Context context, final float vnew);
}
...@@ -22,22 +22,24 @@ import java.util.Set; ...@@ -22,22 +22,24 @@ import java.util.Set;
*/ */
public class TTSHelper { public class TTSHelper {
TextToSpeech ttobj; TextToSpeech ttobj=null;
Voice voice; Voice voice;
boolean voice_ok; boolean voice_ok;
public void createTTS(final Context context, String engine, final Locale locale, final String voice) { public void createTTS(final Context context, String engine, final Locale locale, final String voice) {
this.ttobj = new TextToSpeech(context,new TextToSpeech.OnInitListener() { if (this.ttobj==null) {
this.ttobj = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
public void onInit(int status) { public void onInit(int status) {
Log.e(this.getClass().getCanonicalName(),"TTS engine "+status); Log.e(this.getClass().getCanonicalName(), "TTS engine " + status);
if (status == TextToSpeech.SUCCESS) { if (status == TextToSpeech.SUCCESS) {
ttobj.setLanguage(locale); ttobj.setLanguage(locale);
setVoice(context,voice); setVoice(context, voice);
} }
}}, engine); }
}, engine);
}
} }
public TTSHelper(Context context, String engine, Locale locale,String voice) { public TTSHelper(Context context, String engine, Locale locale,String voice) {
......
...@@ -16,7 +16,7 @@ public class GUITools { ...@@ -16,7 +16,7 @@ public class GUITools {
public void ok(); public void ok();
} }
public static void show_alert(Context context, int resource_msg, String additional_msg, final iOKListener oklistener) { public static AlertDialog show_alert(Context context, int resource_msg, String additional_msg, final iOKListener oklistener) {
AlertDialog.Builder builder = new AlertDialog.Builder(context); AlertDialog.Builder builder = new AlertDialog.Builder(context);
String msg = context.getString(resource_msg); String msg = context.getString(resource_msg);
if (additional_msg != null) msg += ": " + additional_msg; if (additional_msg != null) msg += ": " + additional_msg;
...@@ -29,7 +29,9 @@ public class GUITools { ...@@ -29,7 +29,9 @@ public class GUITools {
} }
}); });
AlertDialog alert = builder.create(); AlertDialog alert = builder.create();
alert.show(); alert.show();
return alert;
} }
public static void show_alert(Context context, int resource_msg) { public static void show_alert(Context context, int resource_msg) {
......
...@@ -65,7 +65,6 @@ ...@@ -65,7 +65,6 @@
<string name="mirror_mode_on">Mirror mode on</string> <string name="mirror_mode_on">Mirror mode on</string>
<string name="new_version_title">New version available</string> <string name="new_version_title">New version available</string>
<string name="new_version_detail">Please, download and install the new version available at</string>
<!--default tts engine and voice--> <!--default tts engine and voice-->
<string name="default_tts_engine">com.google.android.tts</string> <string name="default_tts_engine">com.google.android.tts</string>
......
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
<string name="mirror_mode_on">Modo espejo activado</string> <string name="mirror_mode_on">Modo espejo activado</string>
<string name="new_version_title">Nueva versión disponible</string> <string name="new_version_title">Nueva versión disponible</string>
<string name="new_version_detail">Por favor descargue e instale la nueva versión disponible en</string>
<!--default tts engine and voice--> <!--default tts engine and voice-->
<string name="default_tts_engine">com.google.android.tts</string> <string name="default_tts_engine">com.google.android.tts</string>
<string name="default_tts_voice_male">es-es-x-ana#male_1-local</string> <string name="default_tts_voice_male">es-es-x-ana#male_1-local</string>
......
...@@ -70,7 +70,6 @@ ...@@ -70,7 +70,6 @@
<!--new app version alertbox--> <!--new app version alertbox-->
<string name="new_version_title">Nueva versión disponible</string> <string name="new_version_title">Nueva versión disponible</string>
<string name="new_version_detail">Por favor descargue e instale la nueva versión disponible en</string>
<!--default tts engine and voice--> <!--default tts engine and voice-->
<string name="default_tts_engine">com.google.android.tts</string> <string name="default_tts_engine">com.google.android.tts</string>
......
...@@ -19,6 +19,8 @@ android { ...@@ -19,6 +19,8 @@ android {
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
resValue "bool","alwaysNotifyVisible","false" resValue "bool","alwaysNotifyVisible","false"
resValue "string", "VersionManagerClass", "com.yottacode.pictogram.supervisor_tablet.net.VersionManager"
resValue "string","apk","pictograms.apk"
// signingConfig signingConfigs.config // signingConfig signingConfigs.config
} }
productFlavors { productFlavors {
......
package com.yottacode.pictogram.supervisor_tablet.net;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.view.KeyEvent;
import android.widget.TextView;
import com.yottacode.pictogram.dao.DeviceHelper;
import com.yottacode.pictogram.net.iVersionManager;
import com.yottacode.pictogram.supervisor_tablet.R;
import com.yottacode.pictogram.tools.PCBcontext;
import static android.app.Activity.RESULT_OK;
/**
* Created by Fernando on 10/03/2017.
*/
public class VersionManager implements iVersionManager {
static final String LOG_TAG=VersionManager.class.getCanonicalName();
public void newVersionAlert(final float version, final Context context, final float vnew) {
final SpannableString s = new SpannableString(context.getResources().getString(R.string.server)
+ "/" + context.getResources().getString(com.yottacode.pictogram.R.string.apk));
final TextView tx1 = new TextView(context);
tx1.setText("\t"+context.getResources().getString(R.string.new_version_detail) +
"\n\t\t"+ s);
tx1.setTextSize(16);
tx1.setAutoLinkMask(RESULT_OK);
tx1.setMovementMethod(LinkMovementMethod.getInstance());
Linkify.addLinks(s, Linkify.WEB_URLS);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(context.getResources().getString(R.string.app_name)+": "+context.getResources().getString(R.string.new_version_title)+" v"+vnew)
.setCancelable(false)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
DeviceHelper.setAppVersion(vnew);
}
})
.setView(tx1).setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
return false;
}
}).show();
PCBcontext.setActivityContext(null);
}
}
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="app_name">Pictogram Tablet Supervisor</string> <string name="app_name">Pictogram Tablet Supervisor</string>
<string name="ilegal_user">There is not any supervisor named</string> <string name="new_version_detail">Please, go to Google Play to download the new version </string>
</resources> </resources>
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="app_name">Pictogram Tablet Supervisor</string> <string name="app_name">Pictogram Tablet Supervisor</string>
<string name="ilegal_user"> No existe ningún supervisor </string> <string name="new_version_detail">Por favor, descargue la nueva versión en Google Play </string>
</resources> </resources>
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="app_name">Pictogram Tablet Supervisor</string> <string name="app_name">Pictogram Tablet Supervisor</string>
<string name="ilegal_user">There is not any supervisor named</string> <string name="new_version_detail">Please, go to Google Play to download the new version </string>
</resources> </resources>
...@@ -166,6 +166,7 @@ public class PictoAnimation { ...@@ -166,6 +166,7 @@ public class PictoAnimation {
@Override @Override
public void onAnimationEnd(Animator animation) { public void onAnimationEnd(Animator animation) {
activity.tapeAdapter.deleteItem(position); activity.tapeAdapter.deleteItem(position);
activity.tapeAdapter.notifyDataSetChanged(); activity.tapeAdapter.notifyDataSetChanged();
if (t1.getVisibility()==View.VISIBLE) t1.setAlpha(1); if (t1.getVisibility()==View.VISIBLE) t1.setAlpha(1);
......
...@@ -8,14 +8,17 @@ import com.yottacode.pictogram.dao.Picto; ...@@ -8,14 +8,17 @@ import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Vector;
public class PictoGridAdapter extends ArrayAdapter { public class PictoGridAdapter extends ArrayAdapter {
private LinkedList<Picto> pictoLinkedList; private LinkedList<Picto> pictoLinkedList;
private final String LOG_TAG = this.getClass().getSimpleName(); private final String LOG_TAG = this.getClass().getSimpleName();
private Vector<Picto> pictoLinkedList_inTape;
public PictoGridAdapter(LinkedList<Picto> pictoLinkedList){ public PictoGridAdapter(LinkedList<Picto> pictoLinkedList){
super(PCBcontext.getContext(), PictoItemViewGenerator.LAYOUT, pictoLinkedList); super(PCBcontext.getContext(), PictoItemViewGenerator.LAYOUT, pictoLinkedList);
this.pictoLinkedList = pictoLinkedList; this.pictoLinkedList = pictoLinkedList;
pictoLinkedList_inTape=new Vector<>(5);
} }
@Override @Override
...@@ -33,17 +36,44 @@ public class PictoGridAdapter extends ArrayAdapter { ...@@ -33,17 +36,44 @@ public class PictoGridAdapter extends ArrayAdapter {
return 0; return 0;
} }
public void deleteAll() {
this.pictoLinkedList.clear();
}
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
Picto picto=this.pictoLinkedList.get(position);
if (this.pictoLinkedList_inTape.contains(picto)) picto.set_visible(false);
return PictoItemViewGenerator.getPictoView( return PictoItemViewGenerator.getPictoView(
this.pictoLinkedList.get(position), picto,
convertView, convertView,
parent parent
); );
} }
public void pictoInTape(Picto p) {
p.set_visible(false);
pictoLinkedList_inTape.add(p);
notifyDataSetChanged();
}
public void pictoInGrid(Picto p) {
pictoLinkedList_inTape.get(pictoLinkedList_inTape.indexOf(p)).set_visible(true);
pictoLinkedList_inTape.remove(p);
notifyDataSetChanged();
}
public boolean pictoInThisCategory (Picto picto) {
return pictoLinkedList_inTape.contains(picto);
}
public void allPictosInGrid() {
for (Picto picto: pictoLinkedList_inTape) {
picto.set_visible(true);
}
pictoLinkedList_inTape.clear();
notifyDataSetChanged();
}
} }
...@@ -52,7 +52,6 @@ import com.yottacode.pictogram.net.websockets.ActionTalk; ...@@ -52,7 +52,6 @@ import com.yottacode.pictogram.net.websockets.ActionTalk;
import com.yottacode.pictogram.net.websockets.VocabularyTalk; import com.yottacode.pictogram.net.websockets.VocabularyTalk;
import com.yottacode.pictogram.tabletlibrary.R; import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.cropper.EditPictoActivity; import com.yottacode.pictogram.tabletlibrary.gui.communicator.cropper.EditPictoActivity;
import com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity;
import com.yottacode.pictogram.tabletlibrary.gui.session.SessionActivity; import com.yottacode.pictogram.tabletlibrary.gui.session.SessionActivity;
import com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet; import com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet;
import com.yottacode.pictogram.tools.Img; import com.yottacode.pictogram.tools.Img;
...@@ -234,9 +233,16 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -234,9 +233,16 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (!deleting) { if (!deleting) {
Log.i(PictogramActivity.class.getCanonicalName(), " Deleting item " + position + "-" + id + "(" + PictogramActivity.this.tapeAdapter.getItem(position).get_translation() + ")"); Log.i(PictogramActivity.class.getCanonicalName(), " Deleting item " + position + "-" + id + "(" + PictogramActivity.this.tapeAdapter.getItem(position).get_translation() + ")");
Picto deletedPicto=PictogramActivity.this.tapeAdapter.getItem(position);
if (pictoCategoryGridAdapter.pictoInThisCategory(deletedPicto)) {
pictoCategoryGridAdapter.pictoInGrid(deletedPicto);
}
if (pictoMainGridAdapter.pictoInThisCategory(deletedPicto)) {
pictoMainGridAdapter.pictoInGrid(deletedPicto);
}
new PictoAnimation().animateOnDeleteView(PictogramActivity.this,view, position); new PictoAnimation().animateOnDeleteView(PictogramActivity.this,view, position);
PictogramActivity.this.tapeAdapter.notifyDataSetChanged(); PictogramActivity.this.tapeAdapter.notifyDataSetChanged();
PCBcontext.getActionLog().log(new TalkAction(TalkAction.DELETE, PictogramActivity.this.tapeAdapter.getItem(position))); PCBcontext.getActionLog().log(new TalkAction(TalkAction.DELETE, deletedPicto));
} }
}}); }});
((NetServiceTablet) PCBcontext.getNetService().getNetServiceDevice()).setPictogramActivity(this); ((NetServiceTablet) PCBcontext.getNetService().getNetServiceDevice()).setPictogramActivity(this);
...@@ -252,7 +258,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -252,7 +258,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
} }
PictogramActivity.this.pictoMainGridView.setNumColumns(PictogramActivity.this.maxColumns); PictogramActivity.this.pictoMainGridView.setNumColumns(PictogramActivity.this.maxColumns);
PictogramActivity.this.pictoCategoryGridView.setNumColumns(PictogramActivity.this.maxColumns); PictogramActivity.this.pictoCategoryGridView.setNumColumns(PictogramActivity.this.maxColumns);
setConfig();
this.generateAnimations(); this.generateAnimations();
...@@ -268,6 +274,8 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -268,6 +274,8 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
PCBcontext.setActivityContext(this); PCBcontext.setActivityContext(this);
setConfig();
startTTS();
Toast.makeText(this.getBaseContext(), PCBcontext.getPcbdb().getCurrentUser().get_name_stu()+" "+PCBcontext.getPcbdb().getCurrentUser().get_surname_stu()+ Toast.makeText(this.getBaseContext(), PCBcontext.getPcbdb().getCurrentUser().get_name_stu()+" "+PCBcontext.getPcbdb().getCurrentUser().get_surname_stu()+
(PCBcontext.getPcbdb().getCurrentUser().is_supervisor() (PCBcontext.getPcbdb().getCurrentUser().is_supervisor()
? " ("+ PCBcontext.getPcbdb().getCurrentUser().get_name_sup()+" "+PCBcontext.getPcbdb().getCurrentUser().get_surname_sup()+")" ? " ("+ PCBcontext.getPcbdb().getCurrentUser().get_name_sup()+" "+PCBcontext.getPcbdb().getCurrentUser().get_surname_sup()+")"
...@@ -292,7 +300,6 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -292,7 +300,6 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
} }
public void setConfig() { public void setConfig() {
startTTS();
setFeedback(new View[]{deleteButton, ttsButton, this.showPictoCategoriesViewButton, this.pictoCategoryGridView, this.pictoMainGridView}); setFeedback(new View[]{deleteButton, ttsButton, this.showPictoCategoriesViewButton, this.pictoCategoryGridView, this.pictoMainGridView});
} }
private void setFeedback(View views[]) { private void setFeedback(View views[]) {
...@@ -387,8 +394,16 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -387,8 +394,16 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
} }
@Override @Override
protected void onPause() {
super.onPause();
this.pictoCategoryGridAdapter.allPictosInGrid();
this.pictoMainGridAdapter.allPictosInGrid();
}
@Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
this.pictoCategoryGridAdapter.allPictosInGrid();
this.pictoMainGridAdapter.allPictosInGrid();
Log.i(LOG_TAG, "Closing app"); Log.i(LOG_TAG, "Closing app");
PCBcontext.getNetService().closeNotifyStatus(); PCBcontext.getNetService().closeNotifyStatus();
} }
...@@ -754,6 +769,8 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -754,6 +769,8 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
Picto p = tapeAdapter.getItem(position); Picto p = tapeAdapter.getItem(position);
tapeAdapter.deleteItem(position); tapeAdapter.deleteItem(position);
tapeAdapter.notifyDataSetChanged(); tapeAdapter.notifyDataSetChanged();
getCurrentPictoGridAdapter().pictoInGrid(p);
getCurrentPictoGridAdapter().notifyDataSetChanged();
} }
break; break;
...@@ -795,8 +812,9 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -795,8 +812,9 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
} }
private void addPictoWord(Picto p) { private void addPictoWord(Picto p) {
tapeAdapter.addItem(p);
getCurrentPictoGridAdapter().pictoInTape(p);
currentCategory = null; currentCategory = null;
tapeAdapter.addItem(new Picto(p));
tapeAdapter.notifyDataSetChanged(); tapeAdapter.notifyDataSetChanged();
showPictoMainGridView(); showPictoMainGridView();
PCBcontext.getActionLog().log(new TalkAction(TalkAction.ADD, p)); PCBcontext.getActionLog().log(new TalkAction(TalkAction.ADD, p));
...@@ -902,6 +920,10 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -902,6 +920,10 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
if (PCBcontext.getPcbdb().getCurrentUser().delivery()!= User.JSON_STUDENT_ATTTRS.delivery.clean) { if (PCBcontext.getPcbdb().getCurrentUser().delivery()!= User.JSON_STUDENT_ATTTRS.delivery.clean) {
showOnlyTape(true); showOnlyTape(true);
} }
pictoMainGridAdapter.allPictosInGrid();
pictoMainGridAdapter.notifyDataSetChanged();
pictoCategoryGridAdapter.allPictosInGrid();
pictoCategoryGridAdapter.notifyDataSetChanged();
} }
} }
} }
...@@ -961,8 +983,16 @@ protected void showOnlyTape(boolean onlyTape) { ...@@ -961,8 +983,16 @@ protected void showOnlyTape(boolean onlyTape) {
PCBcontext.getActionLog().log(new TalkAction(TalkAction.DELETE, p)); PCBcontext.getActionLog().log(new TalkAction(TalkAction.DELETE, p));
// Send websocket action // Send websocket action
tapeAdapter.deleteLastView(); Picto last=tapeAdapter.deleteLastView();
tapeAdapter.notifyDataSetChanged(); tapeAdapter.notifyDataSetChanged();
if (pictoMainGridAdapter.pictoInThisCategory(last)) {
pictoMainGridAdapter.pictoInGrid(last);
pictoMainGridAdapter.notifyDataSetChanged();
}
if (pictoCategoryGridAdapter.pictoInThisCategory(last)) {
pictoCategoryGridAdapter.pictoInGrid(last);
pictoCategoryGridAdapter.notifyDataSetChanged();
}
} }
if (!tapeAdapter.hasElements() && tape_delivered) showOnlyTape(false); if (!tapeAdapter.hasElements() && tape_delivered) showOnlyTape(false);
} }
......
...@@ -45,8 +45,9 @@ public class TapeAdapter extends BaseAdapter { ...@@ -45,8 +45,9 @@ public class TapeAdapter extends BaseAdapter {
} }
// AÑADIR ITEM AL ADAPTADOR // AÑADIR ITEM AL ADAPTADOR
public void addItem(Picto p) { public int addItem(Picto p) {
pictoLinkedList.add(p); pictoLinkedList.add(new Picto(p));
return pictoLinkedList.size()-1;
} }
// ELIMINAR ITEM DEL ADAPTADOR // ELIMINAR ITEM DEL ADAPTADOR
...@@ -56,13 +57,15 @@ public class TapeAdapter extends BaseAdapter { ...@@ -56,13 +57,15 @@ public class TapeAdapter extends BaseAdapter {
// ELIMINAR el último ITEM DEL ADAPTADOR // ELIMINAR el último ITEM DEL ADAPTADOR
public void deleteLastView() { public Picto deleteLastView() {
Picto picto=null;
// Controlar excepcion al intentar eliminar el último cuando no hay elementos // Controlar excepcion al intentar eliminar el último cuando no hay elementos
try { try {
pictoLinkedList.removeLast(); picto=pictoLinkedList.removeLast();
} catch (ArrayIndexOutOfBoundsException exception) { } catch (ArrayIndexOutOfBoundsException exception) {
Log.e("Excepción", "ArrayIndexOutOfBounds: " + exception.getMessage()); Log.e("Excepción", "ArrayIndexOutOfBounds: " + exception.getMessage());
} }
return picto;
} }
// ELIMINAR TODOS LOS ITEMS DEL ADAPTADOR // ELIMINAR TODOS LOS ITEMS DEL ADAPTADOR
...@@ -74,7 +77,6 @@ public class TapeAdapter extends BaseAdapter { ...@@ -74,7 +77,6 @@ public class TapeAdapter extends BaseAdapter {
public void clear() { public void clear() {
pictoLinkedList.clear(); pictoLinkedList.clear();
notifyDataSetChanged(); notifyDataSetChanged();
} }
// DEVUELVE TODOS LOS ELEMENTOS // DEVUELVE TODOS LOS ELEMENTOS
public LinkedList<Picto> getAll() { public LinkedList<Picto> getAll() {
......
...@@ -40,7 +40,6 @@ public class LoginActivity extends FragmentActivity { ...@@ -40,7 +40,6 @@ public class LoginActivity extends FragmentActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(com.yottacode.pictogram.tabletlibrary.R.layout.activity_login); setContentView(com.yottacode.pictogram.tabletlibrary.R.layout.activity_login);
......
...@@ -43,8 +43,6 @@ public class SerialActivity extends Activity { ...@@ -43,8 +43,6 @@ public class SerialActivity extends Activity {
LinearLayout stuList; LinearLayout stuList;
LinearLayout supList; LinearLayout supList;
protected boolean is_legal_user(String user_name, Activity activity) {return true;}
/** /**
* Return the default user+pwd when login.The policy is * Return the default user+pwd when login.The policy is
* 1. switch user * 1. switch user
...@@ -155,7 +153,7 @@ public class SerialActivity extends Activity { ...@@ -155,7 +153,7 @@ public class SerialActivity extends Activity {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
String username = mSerialViewMail.getText().toString(); String username = mSerialViewMail.getText().toString();
if (is_legal_user(username,SerialActivity.this)) {
String password = mSerialViewPass.getText().toString(); String password = mSerialViewPass.getText().toString();
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
...@@ -164,7 +162,7 @@ public class SerialActivity extends Activity { ...@@ -164,7 +162,7 @@ public class SerialActivity extends Activity {
editor.commit(); editor.commit();
if (!username.equals("") && !password.equals("")) if (!username.equals("") && !password.equals(""))
new UserLogin().login(username, password, SerialActivity.this, PictogramActivity.class, LoginActivity.class); new UserLogin().login(username, password, SerialActivity.this, PictogramActivity.class, LoginActivity.class);
}
} }
}); });
} }
...@@ -197,5 +195,10 @@ public class SerialActivity extends Activity { ...@@ -197,5 +195,10 @@ public class SerialActivity extends Activity {
} }
} }
@Override
public void onResume() {
super.onResume();
PCBcontext.setActivityContext(this);
}
} }
...@@ -2,7 +2,6 @@ package com.yottacode.pictogram.tabletlibrary.net; ...@@ -2,7 +2,6 @@ package com.yottacode.pictogram.tabletlibrary.net;
import android.app.Activity; import android.app.Activity;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
...@@ -13,7 +12,6 @@ import com.yottacode.pictogram.dao.User; ...@@ -13,7 +12,6 @@ import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.net.NetService; import com.yottacode.pictogram.net.NetService;
import com.yottacode.pictogram.tabletlibrary.R; import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.PictogramActivity; import com.yottacode.pictogram.tabletlibrary.gui.communicator.PictogramActivity;
import com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
/** /**
...@@ -36,8 +34,6 @@ public class NetServiceTablet implements NetService.iNetServiceDevice { ...@@ -36,8 +34,6 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
TaskStackBuilder stackBuilder = TaskStackBuilder.create(PCBcontext.getContext()); TaskStackBuilder stackBuilder = TaskStackBuilder.create(PCBcontext.getContext());
stackBuilder.addParentStack(PictogramActivity.class); stackBuilder.addParentStack(PictogramActivity.class);
stackBuilder.addNextIntent(resultIntent); stackBuilder.addNextIntent(resultIntent);
Log.e(LOG_TAG,"alwaus visible "+PCBcontext.getContext().getResources().getBoolean(R.bool.alwaysNotifyVisible));
} }
public void notifyStatus(boolean updated) { public void notifyStatus(boolean updated) {
......
...@@ -20,6 +20,7 @@ android { ...@@ -20,6 +20,7 @@ android {
versionName "1.0" versionName "1.0"
resValue "bool","alwaysNotifyVisible","true" resValue "bool","alwaysNotifyVisible","true"
resValue "string","apk","pictogram.apk" resValue "string","apk","pictogram.apk"
resValue "string", "VersionManagerClass", "com.yottacode.pictogram.yotta_tablet.net.com.yottacode.pictogram.yotta_tablet.net.VersionManager"
// signingConfig signingConfigs.config // signingConfig signingConfigs.config
} }
productFlavors { productFlavors {
......
package com.yottacode.pictogram.yotta_tablet.kiosk; package com.yottacode.pictogram.yotta_tablet.kiosk;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.NotificationManager;
import android.app.Service; import android.app.Service;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
...@@ -39,6 +40,9 @@ public class KioskService extends Service { ...@@ -39,6 +40,9 @@ public class KioskService extends Service {
public void onDestroy() { public void onDestroy() {
Log.i(TAG, "Stopping service 'KioskService'"); Log.i(TAG, "Stopping service 'KioskService'");
running =false; running =false;
NotificationManager mNotificationManager =
(NotificationManager)this.getBaseContext().getSystemService(this.getBaseContext().NOTIFICATION_SERVICE);
mNotificationManager.cancel(666);
super.onDestroy(); super.onDestroy();
} }
......
package com.yottacode.pictogram.yotta_tablet.net.com.yottacode.pictogram.yotta_tablet.net;
import android.app.DownloadManager;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Environment;
import com.yottacode.pictogram.dao.DeviceHelper;
import com.yottacode.pictogram.net.iVersionManager;
import com.yottacode.pictogram.tools.PCBcontext;
import com.yottacode.pictogram.yotta_tablet.R;
import com.yottacode.tools.GUITools;
import java.io.File;
/**
* Created by Fernando on 10/03/2017.
*/
public class VersionManager implements iVersionManager {
static final String LOG_TAG=VersionManager.class.getCanonicalName();
public void newVersionAlert(final float version, final Context context, final float vnew) {
GUITools.show_alert(
PCBcontext.getActivityContext(), R.string.new_version_title,
PCBcontext.getContext().getResources().getString(R.string.new_version_detail)+" v" + version, new GUITools.iOKListener() {
@Override
public void ok() {
downloadNewVersion(version,PCBcontext.getActivityContext(), version);
}
});
}
private void downloadNewVersion(final float version, final Context context, final float vnew) {
final ProgressDialog progressDialog=ProgressDialog.show(context, context.getString(R.string.userLoadingTxt),context.getString(R.string.new_version_downloading));
progressDialog.show();
String destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/";
String fileName = context.getResources().getString(com.yottacode.pictogram.R.string.apk);
String apkurl=context.getResources().getString(com.yottacode.pictogram.R.string.server)
+ "/" + fileName;
destination += fileName;
final Uri uri = Uri.parse("file://" + destination);
//Delete update file if exists
File file = new File(destination);
if (file.exists())
file.delete();
//set downloadmanager
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(apkurl));
request.setDescription(context.getString(R.string.new_version_detail));
request.setTitle(context.getString(com.yottacode.pictogram.R.string.app_name));
//set destination
request.setDestinationUri(uri);
// get download service and enqueue file
final DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
final long downloadId = manager.enqueue(request);
//register receiver for when .apk download is compete
context.registerReceiver(new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
Intent install = new Intent(Intent.ACTION_VIEW);
install.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
install.setDataAndType(uri,
manager.getMimeTypeForDownloadedFile(downloadId));
context.startActivity(install);
context.unregisterReceiver(this);
DeviceHelper.setAppVersion(version);
}
}
, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
}
...@@ -2,5 +2,8 @@ ...@@ -2,5 +2,8 @@
<resources> <resources>
<string name="app_name">Pictogram Tablet</string> <string name="app_name">Pictogram Tablet</string>
<string name="ilegal_user">There is not any supervisor named</string> <string name="ilegal_user">There is not any supervisor named</string>
<string name="new_version_detail">Pulse OK para proceder con la instalación</string>
<string name="new_version_downloading">Please wait, downloading new version </string>
</resources> </resources>
...@@ -2,5 +2,8 @@ ...@@ -2,5 +2,8 @@
<resources> <resources>
<string name="app_name">Pictogram Tablet</string> <string name="app_name">Pictogram Tablet</string>
<string name="ilegal_user"> No existe ningún supervisor </string> <string name="ilegal_user"> No existe ningún supervisor </string>
<string name="new_version_detail">Pulse OK para proceder con la instalación</string>
<string name="new_version_downloading">Por favor espere, descargando nueva versión </string>
</resources> </resources>
...@@ -2,4 +2,7 @@ ...@@ -2,4 +2,7 @@
<resources> <resources>
<string name="app_name">Pictogram Tablet</string> <string name="app_name">Pictogram Tablet</string>
<string name="ilegal_user">There is not any supervisor named</string> <string name="ilegal_user">There is not any supervisor named</string>
<string name="new_version_detail">Pulse OK para proceder con la instalación</string>
<string name="new_version_downloading">Por favor espere, descargando nueva versión </string>
</resources> </resources>
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