Commit 3a41b3c0 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Optimization

Better internet management
Restart app if not connected at the start
parent fa0b3977
......@@ -164,35 +164,22 @@ public abstract class BaseActivity extends InternetActivity {
}.start();
}
protected void restartApp(Activity activity) {
protected void restartApp(final 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");
Intent mStartActivity = pm.getLaunchIntentForPackage(
getPackageName()
);
mStartActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
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);
System.exit(0);
} catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
}
}
......
......@@ -8,6 +8,7 @@ import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v7.app.AlertDialog;
import android.widget.TextView;
import android.widget.Toast;
/**
......@@ -38,12 +39,12 @@ public abstract class InternetActivity extends NFCActivity {
this.internetAlertDialog
.setTitle(R.string.connection)
.setMessage(R.string.internet_accessibility)
.setCancelable(true)
.setPositiveButton(R.string.pass, null)
.setOnDismissListener(new DialogInterface.OnDismissListener() {
.setCancelable(false)
.setNegativeButton(R.string.pass, new DialogInterface.OnClickListener() {
@Override
public void onDismiss(final DialogInterface dialog) {
public void onClick(DialogInterface dialog, int which) {
internetAlertDialog = null;
if (!checkInternet(context))
enableInternetDialog(context);
}
......
......@@ -2,6 +2,7 @@ package fr.utc.simde.jessy;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
......@@ -132,6 +133,21 @@ public class MainActivity extends BaseActivity {
casConnexionDialog = false;
}
@Override
protected void enableInternetDialog(final Context context) {
Toast.makeText(context, R.string.internet_not_available, Toast.LENGTH_SHORT).show();
dialog.infoDialog(MainActivity.this, getString(R.string.connection), getString(R.string.internet_accessibility), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (!checkInternet(context))
enableInternetDialog(context);
else
restartApp(MainActivity.this);
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (Integer.parseInt(android.os.Build.VERSION.SDK) > 5 && keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
......
......@@ -68,7 +68,7 @@
android:paddingBottom="10dp"
android:gravity="center"
android:textStyle="italic"
android:text="@string/app_not_registred" />
android:text="@string/app_not_connected" />
</LinearLayout>
</RelativeLayout>
......@@ -21,6 +21,7 @@
<string name="quit">Quitter</string>
<string name="app_registred">Appareil enregistré</string>
<string name="app_not_registred">Appareil non enregistré</string>
<string name="app_not_connected">Appareil non connectée</string>
<string name="username_dialog">Connexion par CAS</string>
<string name="badge_dialog">Connexion par badge</string>
<string name="username">Login</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