|
|
@@ -58,6 +58,7 @@ public class ApexDriverApplication extends Application {
|
|
|
private String firstName;
|
|
|
|
|
|
private volatile long notificationID;
|
|
|
+ private boolean authExpired = false;
|
|
|
|
|
|
public boolean isbackground=true;
|
|
|
|
|
|
@@ -119,6 +120,10 @@ public class ApexDriverApplication extends Application {
|
|
|
bintent.setClass(ApexDriverApplication.this, ApexDriverAlarmReceiver.class);
|
|
|
// bintent.putExtra("msg", msg.toString());
|
|
|
sendBroadcast(bintent);
|
|
|
+
|
|
|
+ if (authExpired) {
|
|
|
+ showAuthoExpiredAlert(activity);
|
|
|
+ }
|
|
|
}
|
|
|
// isbackground = false;
|
|
|
}
|
|
|
@@ -519,6 +524,7 @@ public class ApexDriverApplication extends Application {
|
|
|
editor.commit();
|
|
|
}
|
|
|
|
|
|
+ authExpired = false;
|
|
|
setShouldAutoLogin(false);
|
|
|
}
|
|
|
|
|
|
@@ -674,6 +680,68 @@ public class ApexDriverApplication extends Application {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 自动登出提示的情况
|
|
|
+ * 1. 当前在前台,存在Activity
|
|
|
+ * 1.1 如果Activity是MainActivity,直接登出
|
|
|
+ * 1.2 如果Activity不是MainActivity,返回到MainActivity,并且在MainActivity.OnResume时登出
|
|
|
+ *
|
|
|
+ * 2. 当前在后台,没有Activity,则在LifeCycleCallback的回掉中,OnResume通过Activity提示登出
|
|
|
+ * 2.1 如果Activity是MainActivity,直接登出
|
|
|
+ * 2.2 如果Activity不是MainActivity,返回到MainActivity,并且在MainActivity.OnResume时登出
|
|
|
+ *
|
|
|
+ * */
|
|
|
+ public void authorizationExpired() {
|
|
|
+ new Handler(Looper.getMainLooper()).post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ authExpired = true;
|
|
|
+ if (mCurActivity != null && !isbackground) {
|
|
|
+ showAuthoExpiredAlert(mCurActivity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showAuthoExpiredAlert(final Activity activity) {
|
|
|
+ if (activity != null && authExpired) {
|
|
|
+
|
|
|
+ new AlertDialog.Builder(activity)
|
|
|
+ .setTitle(getString(R.string.warning))
|
|
|
+ .setTitle(getString(R.string.auth_expired_msg))
|
|
|
+ .setPositiveButton(getString(R.string.btn_ok), new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ autoLogout(activity);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .setCancelable(false)
|
|
|
+ .show();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void autoLogout(Activity activity) {
|
|
|
+ if (activity != null) {
|
|
|
+
|
|
|
+ if (activity instanceof MainActivity) {
|
|
|
+ ((MainActivity) activity).logout();
|
|
|
+ } else {
|
|
|
+
|
|
|
+ // 在MainActivity.onResume自动登出
|
|
|
+ Intent intent = new Intent(activity, getMainActivityClass());
|
|
|
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
+ activity.startActivity(intent);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isAuthExpired() {
|
|
|
+ return authExpired;
|
|
|
+ }
|
|
|
+
|
|
|
public void receiveNotificationOnMainThread(final JSONObject notification) {
|
|
|
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
|
|
@Override
|
|
|
@@ -764,6 +832,10 @@ public class ApexDriverApplication extends Application {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public Class getMainActivityClass() {
|
|
|
+ return MainActivity.class;
|
|
|
+ }
|
|
|
+
|
|
|
public void popLocalNotification(JSONObject notification) {
|
|
|
|
|
|
if (notification == null) {
|
|
|
@@ -794,7 +866,7 @@ public class ApexDriverApplication extends Application {
|
|
|
//
|
|
|
// Intent intent = DetailActivity.build(getApplicationContext(),orderID,orderType,orderType2,statusNo);
|
|
|
// intent.putExtra("goHome",true);
|
|
|
- Intent intent = new Intent(getApplicationContext(),MainActivity.class);
|
|
|
+ Intent intent = new Intent(getApplicationContext(), getMainActivityClass());
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); // getIntent可能是null
|
|
|
intent.putExtra("aps",aps.toString()); // 程序在后台的情况下,点击通知将程序唤醒到前台时,并不能取得extra
|
|
|
|