issues #54, #54 solved

parent 74ae02fe
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;
......@@ -21,11 +29,19 @@ 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;
/**
......@@ -42,10 +58,10 @@ import static android.app.Activity.RESULT_OK;
public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
static final String LOG_TAG=NetService.class.getCanonicalName();
static final String ping_session="server/ping";
private boolean updated;
private final String LOG_TAG=this.getClass().getCanonicalName();
private Vector<iNetServiceStatus> listeners;
private static final long restfullSynchroTimming=PCBcontext.getContext().getResources().getInteger(R.integer.netservice_force_restfull_synchro)*1000;
private long lastRestfullSynchro;
......@@ -166,7 +182,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
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);
Log.e(LOG_TAG, "New version is required! from v" + DeviceHelper.getAppVersion() + " to v" + version+" Activity:"+PCBcontext.getActivityContext().getClass().getCanonicalName());
newVersionAlert(PCBcontext.getActivityContext(), version);
}
} catch (Exception e) {
......@@ -271,12 +287,62 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
device=(iNetServiceDevice)listener;
return device;
}
static void newVersionAlert(Context contex, final float vnew) {
final SpannableString s = new SpannableString(contex.getResources().getString(R.string.server)
+ "/" + contex.getResources().getString(R.string.apk));
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);
final TextView tx1 = new TextView(contex);
tx1.setText("\t"+contex.getResources().getString(R.string.new_version_detail) +
}
};
//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);
......@@ -284,8 +350,8 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
Linkify.addLinks(s, Linkify.WEB_URLS);
AlertDialog.Builder builder = new AlertDialog.Builder(contex);
builder.setTitle(contex.getResources().getString(R.string.app_name)+": "+contex.getResources().getString(R.string.new_version_title)+" v"+vnew)
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() {
......
......@@ -18,8 +18,7 @@ android {
targetSdkVersion 22
versionCode 1
versionName "1.0"
resValue "string","SerialClass","com.yottacode.pictogram.supervisor_tablet.gui.Supervisor_SerialActivity"
resValue "string","apk","pictograms.apk"
resValue "bool","alwaysNotifyVisible","false"
// signingConfig signingConfigs.config
}
productFlavors {
......@@ -30,10 +29,12 @@ android {
DevFlavor {
resValue "string", "server", "https://dev.yottacode.com"
resValue "bool", "ssl_connect", "false"
resValue "string","apk","pictograms_dev.apk"
}
PreFlavor {
resValue "string", "server", "https://pre.yottacode.com"
resValue "bool", "ssl_connect", "true"
resValue "string","apk","pictograms.apk"
}
LocalFlavor {
resValue "string", "server", "http://192.168.1.35:1337"
......
......@@ -40,7 +40,7 @@
android:label="@string/app_name"
android:screenOrientation="landscape" />
<activity
android:name=".gui.Supervisor_SerialActivity"
android:name="com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity"
android:label="@string/title_activity_serial"
android:screenOrientation="landscape" />
<activity
......
package com.yottacode.pictogram.supervisor_tablet.gui;
import android.app.Activity;
import com.yottacode.pictogram.supervisor_tablet.R;
import com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity;
import com.yottacode.tools.GUITools;
/**
* Created by Fernando on 21/11/2016.
*/
public final class Supervisor_SerialActivity extends SerialActivity {
@Override
protected boolean is_legal_user(String user_name, Activity activity) {
boolean legal_user=com.yottacode.pictogram.dao.UserLogin.isSupervisorLoginPattern(user_name);
if (!legal_user)
GUITools.show_alert(activity, R.string.ilegal_user, user_name);
return legal_user;
}
}
......@@ -8,7 +8,7 @@ android {
targetSdkVersion 22
versionCode 1
versionName "1.0"
resValue "string", "SerialClass", "com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity"
resValue "bool","alwaysNotifyVisible","false"
resValue "integer", "rows", "5"
resValue "integer", "columns", "10"
resValue "integer", "rows_big", "4"
......
......@@ -1010,14 +1010,8 @@ protected void showOnlyTape(boolean onlyTape) {
e.printStackTrace();
}
}
Class serialClass;
try {
serialClass = Class.forName(getString(R.string.SerialClass));
} catch (ClassNotFoundException e) {
Log.e(this.getClass().getCanonicalName(), "S:" + getString(R.string.SerialClass));
serialClass = SerialActivity.class;
}
Intent serialActivity = new Intent(getBaseContext(), serialClass);
Intent serialActivity = new Intent(getBaseContext(), com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity.class);
if (lastUserName != null) {
Log.i(this.getClass().getCanonicalName(), "Switch user to " + lastUserName);
serialActivity.putExtra("switch_usr", lastUserName);
......
......@@ -51,14 +51,7 @@ public class LoginActivity extends FragmentActivity {
logoutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Class serialClass;
try {
serialClass=Class.forName(getString(R.string.SerialClass));
} catch (ClassNotFoundException e) {
Log.e(this.getClass().getCanonicalName(),"S:"+getString(R.string.SerialClass));
serialClass=SerialActivity.class;
}
Intent serialActivity = new Intent(getBaseContext(), serialClass);
Intent serialActivity = new Intent(getBaseContext(), com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity.class);
serialActivity.putExtra("resetPrevUser", true);
startActivity(serialActivity);
}
......
......@@ -25,14 +25,8 @@ public class MainActivity extends Activity {
// For deactivating the lock screen (just before setContentView)
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
Class serialClass;
try {
serialClass=Class.forName(getString(R.string.SerialClass));
} catch (ClassNotFoundException e) {
Log.e(this.getClass().getCanonicalName(),"S:"+getString(R.string.SerialClass));
serialClass=SerialActivity.class;
}
Intent serialActivity = new Intent(this, serialClass);
Intent serialActivity = new Intent(this, com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity.class);
serialActivity.putExtra("resetPrevUser", false);
startActivity(serialActivity);
}
......
......@@ -31,14 +31,13 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
public void build() {
this.builder = new NotificationCompat.Builder(PCBcontext.getContext()).setAutoCancel(true).setOngoing(true);
this.builder = new NotificationCompat.Builder(PCBcontext.getContext()).setAutoCancel(true).setOngoing(PCBcontext.getContext().getResources().getBoolean(R.bool.alwaysNotifyVisible));
Intent resultIntent = new Intent(PCBcontext.getContext(), PictogramActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(PCBcontext.getContext());
stackBuilder.addParentStack(PictogramActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent);
Log.e(LOG_TAG,"alwaus visible "+PCBcontext.getContext().getResources().getBoolean(R.bool.alwaysNotifyVisible));
}
public void notifyStatus(boolean updated) {
......@@ -74,14 +73,7 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
Log.i(LOG_TAG,"App restarting");
Context context=activity.getBaseContext();
Class serialClass;
try {
serialClass=Class.forName(context.getString(R.string.SerialClass));
} catch (ClassNotFoundException e) {
Log.e(LOG_TAG,"S:"+PCBcontext.getContext().getString(R.string.SerialClass));
serialClass=SerialActivity.class;
}
Intent serialActivity = new Intent(context, serialClass);
Intent serialActivity = new Intent(context, com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity.class);
serialActivity.putExtra("resetPrevUser", false);
serialActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(serialActivity);
......@@ -94,14 +86,7 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
Context context=PCBcontext.getContext();
Class serialClass;
try {
serialClass=Class.forName(PCBcontext.getContext().getString(R.string.SerialClass));
} catch (ClassNotFoundException e) {
Log.e(LOG_TAG,"S:"+PCBcontext.getContext().getString(R.string.SerialClass));
serialClass=SerialActivity.class;
}
Intent serialActivity = new Intent(context, serialClass);
Intent serialActivity = new Intent(context, com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity.class);
serialActivity.putExtra("resetPrevUser", direct_login);
context.startActivity(serialActivity);
......
......@@ -18,7 +18,7 @@ android {
targetSdkVersion 22
versionCode 1
versionName "1.0"
resValue "string","SerialClass","com.yottacode.pictogram.tabletlibrary.gui.login.SerialActivity"
resValue "bool","alwaysNotifyVisible","true"
resValue "string","apk","pictogram.apk"
// signingConfig signingConfigs.config
}
......@@ -30,10 +30,12 @@ android {
DevFlavor {
resValue "string", "server", "https://dev.yottacode.com"
resValue "bool", "ssl_connect", "false"
resValue "string","apk","pictogram_dev.apk"
}
PreFlavor {
resValue "string", "server", "https://pre.yottacode.com"
resValue "bool", "ssl_connect", "true"
resValue "string","apk","pictogram.apk"
}
LocalFlavor {
resValue "string", "server", "http://192.168.1.35:1337"
......
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