|
@@ -3,6 +3,7 @@ package com.usai.redant.apexdrivers;
|
|
|
import android.app.Application;
|
|
import android.app.Application;
|
|
|
import android.content.ComponentName;
|
|
import android.content.ComponentName;
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
|
import android.content.ServiceConnection;
|
|
import android.content.ServiceConnection;
|
|
|
import android.content.SharedPreferences;
|
|
import android.content.SharedPreferences;
|
|
@@ -13,9 +14,12 @@ import android.graphics.drawable.Drawable;
|
|
|
import android.location.Location;
|
|
import android.location.Location;
|
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
|
import android.os.IBinder;
|
|
import android.os.IBinder;
|
|
|
|
|
+import android.support.v7.app.AlertDialog;
|
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
|
|
|
+import android.widget.Switch;
|
|
|
|
|
|
|
|
|
|
+import com.usai.redant.apexdrivers.network.Network;
|
|
|
import com.usai.redant.apexdrivers.receiver.ApexDriverAlarmReceiver;
|
|
import com.usai.redant.apexdrivers.receiver.ApexDriverAlarmReceiver;
|
|
|
import com.usai.redant.apexdrivers.utils.OperationQueue;
|
|
import com.usai.redant.apexdrivers.utils.OperationQueue;
|
|
|
import com.usai.redant.rautils.receiver.RABroadcast;
|
|
import com.usai.redant.rautils.receiver.RABroadcast;
|
|
@@ -44,7 +48,7 @@ public class ApexDriverApplication extends Application {
|
|
|
public final static int BackgroundReportTypeAlways = 2;
|
|
public final static int BackgroundReportTypeAlways = 2;
|
|
|
public final static int BackgroundReportTypeAllow = 3;
|
|
public final static int BackgroundReportTypeAllow = 3;
|
|
|
|
|
|
|
|
- public int backgroundReportType;
|
|
|
|
|
|
|
+ public int backgroundReportType; // getValueForKeyPath/setValueForKeyPath 变量需公开
|
|
|
|
|
|
|
|
|
|
|
|
|
private ServiceConnection mServiceConnection;
|
|
private ServiceConnection mServiceConnection;
|
|
@@ -64,6 +68,8 @@ public class ApexDriverApplication extends Application {
|
|
|
user = savedUser();
|
|
user = savedUser();
|
|
|
password = savedPassword();
|
|
password = savedPassword();
|
|
|
|
|
|
|
|
|
|
+ loadBackgroundReportType();
|
|
|
|
|
+
|
|
|
Log.d("ApexDriverApplication", "onCreate: u:"+user+" p:"+password);
|
|
Log.d("ApexDriverApplication", "onCreate: u:"+user+" p:"+password);
|
|
|
mServiceConnection = new ServiceConnection() {
|
|
mServiceConnection = new ServiceConnection() {
|
|
|
@Override
|
|
@Override
|
|
@@ -320,4 +326,105 @@ public class ApexDriverApplication extends Application {
|
|
|
public static ApexDriverApplication sharedApplication() {
|
|
public static ApexDriverApplication sharedApplication() {
|
|
|
return mApp;
|
|
return mApp;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public void setBackgroundReportType(int backgroundReportType) {
|
|
|
|
|
+ this.backgroundReportType = backgroundReportType;
|
|
|
|
|
+
|
|
|
|
|
+ SharedPreferences pref = sharedPreferences();
|
|
|
|
|
+ SharedPreferences.Editor editor = pref.edit();
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ editor.putInt("backgroundReportType", backgroundReportType);
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ editor.putInt("backgroundReportType", BackgroundReportTypeNone);
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ editor.commit();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public int getBackgroundReportType() {
|
|
|
|
|
+ return backgroundReportType;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void loadBackgroundReportType() {
|
|
|
|
|
+ SharedPreferences pref = sharedPreferences();
|
|
|
|
|
+ int reportType = pref.getInt("backgroundReportType",BackgroundReportTypeNone);
|
|
|
|
|
+ this.backgroundReportType = reportType;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void reportLocationForOrder(final String location, final String orderId) {
|
|
|
|
|
+
|
|
|
|
|
+ getNetworkQueue().addOperationTask(new OperationQueue.OperationBackgroundCallBack() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Object operationDoInBackground() {
|
|
|
|
|
+
|
|
|
|
|
+ Network.reportLocation(location,orderId);
|
|
|
|
|
+
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ },null,null);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void rejectReportLocation(final String reason, final String orderId) {
|
|
|
|
|
+
|
|
|
|
|
+ getNetworkQueue().addOperationTask(new OperationQueue.OperationBackgroundCallBack() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Object operationDoInBackground() {
|
|
|
|
|
+
|
|
|
|
|
+ Network.rejectReportLocation(reason,orderId);
|
|
|
|
|
+
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ },null,null);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void reportLocationForOrder(final String orderId) {
|
|
|
|
|
+
|
|
|
|
|
+ switch (backgroundReportType) {
|
|
|
|
|
+ case BackgroundReportTypeNone: {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case BackgroundReportTypeReject: {
|
|
|
|
|
+
|
|
|
|
|
+ String reason = "Driver " + user +" rejected to report location";
|
|
|
|
|
+ rejectReportLocation(reason,orderId);
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case BackgroundReportTypeAlways: {
|
|
|
|
|
+
|
|
|
|
|
+ new AlertDialog.Builder(getApplicationContext())
|
|
|
|
|
+ .setTitle("Warning")
|
|
|
|
|
+ .setMessage("Report Location For Order:" + orderId)
|
|
|
|
|
+ .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
+
|
|
|
|
|
+ String location = null;
|
|
|
|
|
+ reportLocationForOrder(location,orderId);
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
+
|
|
|
|
|
+ String reason = "Driver " + user +" cancel to report location";
|
|
|
|
|
+ rejectReportLocation(reason,orderId);
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .show();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case BackgroundReportTypeAllow: {
|
|
|
|
|
+
|
|
|
|
|
+ String location = null;
|
|
|
|
|
+ reportLocationForOrder(location,orderId);
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|