Commit ac1690f1 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Merge branch 'release/v0.9.2'

parents ec6e5985 486bb0be
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.utc.simde.jessy"
android:versionCode="25"
android:versionName="0.9.1">
android:versionCode="26"
android:versionName="0.9.2">
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.INTERNET" />
......
......@@ -2,7 +2,9 @@ package fr.utc.simde.jessy;
import android.Manifest;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.DownloadManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
......@@ -16,6 +18,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.util.Log;
......@@ -63,6 +66,9 @@ public abstract class BaseActivity extends InternetActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
this.dialog = new Dialog(this);
}
......@@ -158,6 +164,38 @@ public abstract class BaseActivity extends InternetActivity {
}.start();
}
protected void restartApp(Activity activity) {
try {
PackageManager pm = getPackageManager();
//check if we got the PackageManager
if (pm != null) {
//create the intent with the default start activity for your application
Intent mStartActivity = pm.getLaunchIntentForPackage(
getPackageName()
);
if (mStartActivity != null) {
mStartActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//create a pending intent so the application is restarted after System.exit(0) was called.
// We use an AlarmManager to call this intent in 100ms
int mPendingIntentId = 223344;
PendingIntent mPendingIntent = PendingIntent
.getActivity(activity, mPendingIntentId, mStartActivity,
PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
//kill the application
System.exit(0);
} else {
Log.e(LOG_TAG, "Was not able to restart application, mStartActivity null");
}
} else {
Log.e(LOG_TAG, "Was not able to restart application, PM null");
}
} catch (Exception ex) {
Log.e(LOG_TAG, "Was not able to restart application");
}
}
protected void startMainActivity(final Activity activity) {
disconnect();
......@@ -516,6 +554,7 @@ public abstract class BaseActivity extends InternetActivity {
protected void setNemopayKey(final String key) {
dialog.startLoading(BaseActivity.this, getString(R.string.nemopay_connection), getString(R.string.nemopay_authentification));
new Thread() {
@Override
public void run() {
......@@ -578,7 +617,8 @@ public abstract class BaseActivity extends InternetActivity {
protected void checkUpdate() { checkUpdate(true); }
protected void checkUpdate(final boolean popupIfNot) {
dialog.startLoading(BaseActivity.this, getString(R.string.information_collection), getString(R.string.check_update));
final Dialog updateDialog = new Dialog(BaseActivity.this);
updateDialog.startLoading(BaseActivity.this, getString(R.string.information_collection), getString(R.string.check_update));
new Thread() {
@Override
......@@ -593,7 +633,7 @@ public abstract class BaseActivity extends InternetActivity {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
updateDialog.stopLoading();
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(BaseActivity.this);
alertDialogBuilder
......@@ -602,15 +642,19 @@ public abstract class BaseActivity extends InternetActivity {
.setCancelable(false)
.setPositiveButton(R.string.set_update, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
if (!update(matcher.group(2))) {
dialog.stopLoading();
dialog.errorDialog(BaseActivity.this, getString(R.string.update), getString(R.string.can_not_update));
if (!haveStoragePermission()) {
updateDialog.stopLoading();
updateDialog.errorDialog(BaseActivity.this, getString(R.string.update), getString(R.string.need_storage_permission));
}
else if (!update(matcher.group(2))) {
updateDialog.stopLoading();
updateDialog.errorDialog(BaseActivity.this, getString(R.string.update), getString(R.string.can_not_update));
}
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder);
updateDialog.createDialog(alertDialogBuilder);
}
});
}
......@@ -625,10 +669,10 @@ public abstract class BaseActivity extends InternetActivity {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
updateDialog.stopLoading();
if (popupIfNot)
dialog.errorDialog(BaseActivity.this, getString(R.string.update), e.getMessage() + "\n" + getString(R.string.actual_version) + ": " + BuildConfig.VERSION_NAME);
updateDialog.errorDialog(BaseActivity.this, getString(R.string.update), e.getMessage() + "\n" + getString(R.string.actual_version) + ": " + BuildConfig.VERSION_NAME);
}
});
}
......@@ -641,9 +685,6 @@ public abstract class BaseActivity extends InternetActivity {
final String url = this.gitUrl + getString(R.string.app_name) + " " + version + ".apk";
final Uri uri = Uri.parse("file://" + destination);
if (!haveStoragePermission())
return false;
File file = new File(destination);
if (file.exists())
file.delete();
......@@ -664,7 +705,6 @@ public abstract class BaseActivity extends InternetActivity {
startActivity(install);
unregisterReceiver(this);
finish();
}
};
......
......@@ -473,7 +473,7 @@ public class MainActivity extends BaseActivity {
reloadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startMainActivity(MainActivity.this);
restartApp(MainActivity.this);
}
});
......@@ -481,7 +481,7 @@ public class MainActivity extends BaseActivity {
@Override
public void onClick(View v) {
config.reset();
startMainActivity(MainActivity.this);
restartApp(MainActivity.this);
}
});
......
......@@ -158,6 +158,7 @@
<string name="no_update">Aucune mise à jour disponible</string>
<string name="actual_version">Version actuelle</string>
<string name="available_version">Version disponible</string>
<string name="need_storage_permission">Il est nécessaire d\'autoriser l\'application à sauvegarder du contenu dans votre dossier de téléchargements</string>
<string name="print_mode">Mode d\'affichage</string>
<string name="filters">Filtres d\'affichage</string>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment