working no duplicate picto and friendly update

parent 46ef4204
Showing with 299 additions and 150 deletions
......@@ -11,15 +11,16 @@ android {
versionName "1.0"
resValue "string", "db_name", "PCB.db"
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", "apk", "to_be_set_in_subproject"
resValue "string", "VersionManagerClass", "to_be_set_in_subproject"
}
buildTypes {
release {
minifyEnabled false
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", "ssl_connect", "true"
resValue "bool", "force_img_download", "false"
......@@ -27,7 +28,7 @@ android {
resValue "integer", "netservice_force_restfull_synchro", "30"
}
debug {
resValue "string", "server", "https://dev.yottacode.com"
resValue "string", "server", "https://apidev.pictogramweb.com"
resValue "bool", "force_db_create", "false"
resValue "bool", "ssl_connect", "false"
resValue "bool", "force_img_download", "false"
......
......@@ -246,6 +246,15 @@ public class Picto extends Img {
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
......
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.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
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.view.KeyEvent;
import android.widget.TextView;
import com.yottacode.net.RestapiWrapper;
import com.yottacode.pictogram.R;
......@@ -29,21 +16,11 @@ import org.json.JSONArray;
import org.json.JSONException;
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.Vector;
import java.util.concurrent.ScheduledThreadPoolExecutor;
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:
......@@ -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
*/
Context newVersionContext=null;
@Override
public void run() {
try {
......@@ -176,14 +154,14 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
@Override
public void result(JSONArray result) {
}
@Override
public void result(JSONObject result) {
try {
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());
newVersionAlert(PCBcontext.getActivityContext(), version);
final float version = Float.valueOf(result.getString("version")).floatValue();
if (PCBcontext.getActivityContext() != null && version > DeviceHelper.getAppVersion() && newVersionContext!=PCBcontext.getActivityContext()) {
newVersionContext=PCBcontext.getActivityContext(); // prevent from showing several times the alert
newVersionAlert(version,PCBcontext.getActivityContext(), version);
}
} catch (Exception e) {
Log.e(LOG_TAG, "PING JSON ERROR: " + result + " " + e.getMessage());
......@@ -287,88 +265,18 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
device=(iNetServiceDevice)listener;
return device;
}
static void newVersionAlert(final Context context, final float vnew) {
String apkurl=context.getResources().getString(R.string.server)
+ "/" + context.getResources().getString(R.string.apk);
apkurl="http://www4.ujaen.es/~dofer/pictogram_dev.apk";
//get destination to update file and set Uri
//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
//aplication with existing package from there. So for me, alternative solution is Download directory in external storage. If there is better
//solution, please inform us in comment
String destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/";
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;
static void newVersionAlert(final float version, final Context context, final float vnew) {
try {
iVersionManager versionManager = (iVersionManager)Class.forName(context.getResources().getString(R.string.VersionManagerClass)).newInstance();
versionManager.newVersionAlert(version,context,vnew);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}).show();
PCBcontext.setActivityContext(null);
}
/**
* 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;
*/
public class TTSHelper {
TextToSpeech ttobj;
TextToSpeech ttobj=null;
Voice voice;
boolean voice_ok;
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) {
Log.e(this.getClass().getCanonicalName(),"TTS engine "+status);
Log.e(this.getClass().getCanonicalName(), "TTS engine " + status);
if (status == TextToSpeech.SUCCESS) {
ttobj.setLanguage(locale);
setVoice(context,voice);
setVoice(context, voice);
}
}}, engine);
}
}, engine);
}
}
public TTSHelper(Context context, String engine, Locale locale,String voice) {
......
......@@ -16,7 +16,7 @@ public class GUITools {
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);
String msg = context.getString(resource_msg);
if (additional_msg != null) msg += ": " + additional_msg;
......@@ -29,7 +29,9 @@ public class GUITools {
}
});
AlertDialog alert = builder.create();
alert.show();
return alert;
}
public static void show_alert(Context context, int resource_msg) {
......
......@@ -65,7 +65,6 @@
<string name="mirror_mode_on">Mirror mode on</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-->
<string name="default_tts_engine">com.google.android.tts</string>
......
......@@ -67,7 +67,7 @@
<string name="mirror_mode_on">Modo espejo activado</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-->
<string name="default_tts_engine">com.google.android.tts</string>
<string name="default_tts_voice_male">es-es-x-ana#male_1-local</string>
......
......@@ -70,7 +70,6 @@
<!--new app version alertbox-->
<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-->
<string name="default_tts_engine">com.google.android.tts</string>
......
......@@ -19,6 +19,8 @@ android {
versionCode 1
versionName "1.0"
resValue "bool","alwaysNotifyVisible","false"
resValue "string", "VersionManagerClass", "com.yottacode.pictogram.supervisor_tablet.net.VersionManager"
resValue "string","apk","pictograms.apk"
// signingConfig signingConfigs.config
}
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"?>
<resources>
<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>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<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>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<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>
......@@ -166,6 +166,7 @@ public class PictoAnimation {
@Override
public void onAnimationEnd(Animator animation) {
activity.tapeAdapter.deleteItem(position);
activity.tapeAdapter.notifyDataSetChanged();
if (t1.getVisibility()==View.VISIBLE) t1.setAlpha(1);
......
......@@ -8,14 +8,17 @@ import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.tools.PCBcontext;
import java.util.LinkedList;
import java.util.Vector;
public class PictoGridAdapter extends ArrayAdapter {
private LinkedList<Picto> pictoLinkedList;
private final String LOG_TAG = this.getClass().getSimpleName();
private Vector<Picto> pictoLinkedList_inTape;
public PictoGridAdapter(LinkedList<Picto> pictoLinkedList){
super(PCBcontext.getContext(), PictoItemViewGenerator.LAYOUT, pictoLinkedList);
this.pictoLinkedList = pictoLinkedList;
pictoLinkedList_inTape=new Vector<>(5);
}
@Override
......@@ -33,17 +36,44 @@ public class PictoGridAdapter extends ArrayAdapter {
return 0;
}
public void deleteAll() {
this.pictoLinkedList.clear();
}
@Override
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(
this.pictoLinkedList.get(position),
picto,
convertView,
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;
import com.yottacode.pictogram.net.websockets.VocabularyTalk;
import com.yottacode.pictogram.tabletlibrary.R;
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.net.NetServiceTablet;
import com.yottacode.pictogram.tools.Img;
......@@ -234,9 +233,16 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (!deleting) {
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);
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);
......@@ -252,7 +258,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
}
PictogramActivity.this.pictoMainGridView.setNumColumns(PictogramActivity.this.maxColumns);
PictogramActivity.this.pictoCategoryGridView.setNumColumns(PictogramActivity.this.maxColumns);
setConfig();
this.generateAnimations();
......@@ -268,6 +274,8 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
protected void onResume() {
super.onResume();
PCBcontext.setActivityContext(this);
setConfig();
startTTS();
Toast.makeText(this.getBaseContext(), PCBcontext.getPcbdb().getCurrentUser().get_name_stu()+" "+PCBcontext.getPcbdb().getCurrentUser().get_surname_stu()+
(PCBcontext.getPcbdb().getCurrentUser().is_supervisor()
? " ("+ PCBcontext.getPcbdb().getCurrentUser().get_name_sup()+" "+PCBcontext.getPcbdb().getCurrentUser().get_surname_sup()+")"
......@@ -292,7 +300,6 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
}
public void setConfig() {
startTTS();
setFeedback(new View[]{deleteButton, ttsButton, this.showPictoCategoriesViewButton, this.pictoCategoryGridView, this.pictoMainGridView});
}
private void setFeedback(View views[]) {
......@@ -387,8 +394,16 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
}
@Override
protected void onPause() {
super.onPause();
this.pictoCategoryGridAdapter.allPictosInGrid();
this.pictoMainGridAdapter.allPictosInGrid();
}
@Override
protected void onStop() {
super.onStop();
this.pictoCategoryGridAdapter.allPictosInGrid();
this.pictoMainGridAdapter.allPictosInGrid();
Log.i(LOG_TAG, "Closing app");
PCBcontext.getNetService().closeNotifyStatus();
}
......@@ -754,6 +769,8 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
Picto p = tapeAdapter.getItem(position);
tapeAdapter.deleteItem(position);
tapeAdapter.notifyDataSetChanged();
getCurrentPictoGridAdapter().pictoInGrid(p);
getCurrentPictoGridAdapter().notifyDataSetChanged();
}
break;
......@@ -795,8 +812,9 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
}
private void addPictoWord(Picto p) {
tapeAdapter.addItem(p);
getCurrentPictoGridAdapter().pictoInTape(p);
currentCategory = null;
tapeAdapter.addItem(new Picto(p));
tapeAdapter.notifyDataSetChanged();
showPictoMainGridView();
PCBcontext.getActionLog().log(new TalkAction(TalkAction.ADD, p));
......@@ -902,6 +920,10 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
if (PCBcontext.getPcbdb().getCurrentUser().delivery()!= User.JSON_STUDENT_ATTTRS.delivery.clean) {
showOnlyTape(true);
}
pictoMainGridAdapter.allPictosInGrid();
pictoMainGridAdapter.notifyDataSetChanged();
pictoCategoryGridAdapter.allPictosInGrid();
pictoCategoryGridAdapter.notifyDataSetChanged();
}
}
}
......@@ -961,8 +983,16 @@ protected void showOnlyTape(boolean onlyTape) {
PCBcontext.getActionLog().log(new TalkAction(TalkAction.DELETE, p));
// Send websocket action
tapeAdapter.deleteLastView();
Picto last=tapeAdapter.deleteLastView();
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);
}
......
......@@ -45,8 +45,9 @@ public class TapeAdapter extends BaseAdapter {
}
// AÑADIR ITEM AL ADAPTADOR
public void addItem(Picto p) {
pictoLinkedList.add(p);
public int addItem(Picto p) {
pictoLinkedList.add(new Picto(p));
return pictoLinkedList.size()-1;
}
// ELIMINAR ITEM DEL ADAPTADOR
......@@ -56,13 +57,15 @@ public class TapeAdapter extends BaseAdapter {
// 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
try {
pictoLinkedList.removeLast();
picto=pictoLinkedList.removeLast();
} catch (ArrayIndexOutOfBoundsException exception) {
Log.e("Excepción", "ArrayIndexOutOfBounds: " + exception.getMessage());
}
return picto;
}
// ELIMINAR TODOS LOS ITEMS DEL ADAPTADOR
......@@ -74,7 +77,6 @@ public class TapeAdapter extends BaseAdapter {
public void clear() {
pictoLinkedList.clear();
notifyDataSetChanged();
}
// DEVUELVE TODOS LOS ELEMENTOS
public LinkedList<Picto> getAll() {
......
......@@ -40,7 +40,6 @@ public class LoginActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(com.yottacode.pictogram.tabletlibrary.R.layout.activity_login);
......
......@@ -43,8 +43,6 @@ public class SerialActivity extends Activity {
LinearLayout stuList;
LinearLayout supList;
protected boolean is_legal_user(String user_name, Activity activity) {return true;}
/**
* Return the default user+pwd when login.The policy is
* 1. switch user
......@@ -155,7 +153,7 @@ public class SerialActivity extends Activity {
@Override
public void onClick(View view) {
String username = mSerialViewMail.getText().toString();
if (is_legal_user(username,SerialActivity.this)) {
String password = mSerialViewPass.getText().toString();
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
......@@ -164,7 +162,7 @@ public class SerialActivity extends Activity {
editor.commit();
if (!username.equals("") && !password.equals(""))
new UserLogin().login(username, password, SerialActivity.this, PictogramActivity.class, LoginActivity.class);
}
}
});
}
......@@ -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;
import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
......@@ -13,7 +12,6 @@ import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.net.NetService;
import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.PictogramActivity;
import com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity;
import com.yottacode.pictogram.tools.PCBcontext;
/**
......@@ -36,8 +34,6 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
TaskStackBuilder stackBuilder = TaskStackBuilder.create(PCBcontext.getContext());
stackBuilder.addParentStack(PictogramActivity.class);
stackBuilder.addNextIntent(resultIntent);
Log.e(LOG_TAG,"alwaus visible "+PCBcontext.getContext().getResources().getBoolean(R.bool.alwaysNotifyVisible));
}
public void notifyStatus(boolean updated) {
......
......@@ -20,6 +20,7 @@ android {
versionName "1.0"
resValue "bool","alwaysNotifyVisible","true"
resValue "string","apk","pictogram.apk"
resValue "string", "VersionManagerClass", "com.yottacode.pictogram.yotta_tablet.net.com.yottacode.pictogram.yotta_tablet.net.VersionManager"
// signingConfig signingConfigs.config
}
productFlavors {
......
package com.yottacode.pictogram.yotta_tablet.kiosk;
import android.app.ActivityManager;
import android.app.NotificationManager;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
......@@ -39,6 +40,9 @@ public class KioskService extends Service {
public void onDestroy() {
Log.i(TAG, "Stopping service 'KioskService'");
running =false;
NotificationManager mNotificationManager =
(NotificationManager)this.getBaseContext().getSystemService(this.getBaseContext().NOTIFICATION_SERVICE);
mNotificationManager.cancel(666);
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 @@
<resources>
<string name="app_name">Pictogram Tablet</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>
......@@ -2,5 +2,8 @@
<resources>
<string name="app_name">Pictogram Tablet</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>
......@@ -2,4 +2,7 @@
<resources>
<string name="app_name">Pictogram Tablet</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>
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