Browse Source

1.修改Android Apex Drivers后台报告位置设置。

Pen Li 7 years ago
parent
commit
7c693c5d67

+ 108 - 1
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/ApexDriverApplication.java

@@ -3,6 +3,7 @@ package com.usai.redant.apexdrivers;
 import android.app.Application;
 import android.content.ComponentName;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.ServiceConnection;
 import android.content.SharedPreferences;
@@ -13,9 +14,12 @@ import android.graphics.drawable.Drawable;
 import android.location.Location;
 import android.os.Build;
 import android.os.IBinder;
+import android.support.v7.app.AlertDialog;
 import android.text.TextUtils;
 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.utils.OperationQueue;
 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 BackgroundReportTypeAllow = 3;
 
-    public int backgroundReportType;
+    public int backgroundReportType; // getValueForKeyPath/setValueForKeyPath 变量需公开
 
 
     private ServiceConnection mServiceConnection;
@@ -64,6 +68,8 @@ public class ApexDriverApplication extends Application {
             user = savedUser();
             password = savedPassword();
 
+            loadBackgroundReportType();
+
             Log.d("ApexDriverApplication", "onCreate: u:"+user+" p:"+password);
             mServiceConnection = new ServiceConnection() {
                 @Override
@@ -320,4 +326,105 @@ public class ApexDriverApplication extends Application {
     public static ApexDriverApplication sharedApplication() {
         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;
+        }
+    }
 }

+ 105 - 0
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/base/BasicDialog.java

@@ -0,0 +1,105 @@
+package com.usai.redant.apexdrivers.base;
+
+import android.app.Dialog;
+import android.content.Context;
+import android.support.annotation.NonNull;
+import android.view.Gravity;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+
+import com.usai.redant.apexdrivers.R;
+
+
+public class BasicDialog extends Dialog {
+
+    private Context mCtx;
+    private View mRootView;
+    private BasicDialogSetupCallBack mCallBack;
+
+    public final static int BasicDialogContentGravityTop = 0;
+    public final static int BasicDialogContentGravityCenter = 1;
+    public final static int BasicDialogContentGravityBottom = 2;
+
+    public BasicDialog(@NonNull Context context, BasicDialogSetupCallBack callBack) {
+        this(context);
+
+        mCallBack = callBack;
+
+        mCtx = context;
+        init();
+    }
+
+    private BasicDialog(@NonNull Context context) {
+        this(context, R.style.RedAntDialog);
+    }
+
+    private BasicDialog(@NonNull Context context, int themeResId) {
+        super(context, themeResId);
+    }
+
+    private void init() {
+        if (mCallBack != null) {
+            mRootView = mCallBack.createContentView(this);
+            if (mRootView != null) {
+                setContentView(mRootView);
+            }
+        }
+    }
+
+    @Override
+    public void show() {
+
+        if (mRootView == null) {
+            super.show();
+            return;
+        }
+
+        Window dialogWindow = getWindow();
+        if (dialogWindow != null) {
+
+            int gravity = BasicDialogContentGravityCenter;
+            if (mCallBack != null) {
+                gravity = mCallBack.dialogGravity(this);
+            }
+
+            switch (gravity) {
+                case BasicDialogContentGravityTop: {
+                    dialogWindow.setGravity(Gravity.TOP);
+                }
+                break;
+                case BasicDialogContentGravityCenter: {
+                    dialogWindow.setGravity(Gravity.CENTER);
+                }
+                break;
+                case BasicDialogContentGravityBottom: {
+                    dialogWindow.setGravity(Gravity.BOTTOM);
+                }
+                break;
+                default: {
+                    dialogWindow.setGravity(Gravity.CENTER);
+                }
+                break;
+            }
+
+            WindowManager.LayoutParams layoutParams = dialogWindow.getAttributes(); // 获取对话框当前的参数值
+            layoutParams.x = 0; // 新位置X坐标
+            layoutParams.y = 0; // 新位置Y坐标
+            layoutParams.width = (int) mCtx.getResources().getDisplayMetrics().widthPixels; // 宽度
+            mRootView.measure(0, 0);
+            layoutParams.height = mRootView.getMeasuredHeight();
+
+            layoutParams.alpha = 9f; // 透明度
+            dialogWindow.setAttributes(layoutParams);
+        }
+
+        super.show();
+    }
+
+    public interface BasicDialogSetupCallBack {
+
+        View createContentView(final BasicDialog dialog);
+        int dialogGravity(final BasicDialog dialog);
+
+    }
+}

+ 68 - 0
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/login/LoginFragment.java

@@ -5,12 +5,16 @@ package com.usai.redant.apexdrivers.login;
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.os.AsyncTask;
 import android.os.Build;
 import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
 import android.support.v4.app.Fragment;
+import android.support.v7.app.AlertDialog;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.Gravity;
@@ -20,13 +24,16 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputMethodManager;
+import android.widget.Button;
 import android.widget.CheckBox;
 import android.widget.EditText;
+import android.widget.RelativeLayout;
 import android.widget.TextView;
 import android.widget.Toast;
 
 
 import com.usai.redant.apexdrivers.ApexDriverApplication;
+import com.usai.redant.apexdrivers.base.BasicDialog;
 import com.usai.redant.apexdrivers.network.Network;
 import com.usai.redant.apexdrivers.R;
 
@@ -150,6 +157,67 @@ public class LoginFragment extends Fragment/* implements OnClickListener */
 		return view;
 	}
 
+	@Override
+	public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+		super.onViewCreated(view, savedInstanceState);
+
+		if (ApexDriverApplication.sharedApplication().getBackgroundReportType() == ApexDriverApplication.BackgroundReportTypeNone) {
+
+			new BasicDialog(getContext(), new BasicDialog.BasicDialogSetupCallBack() {
+				@Override
+				public View createContentView(final BasicDialog dialog) {
+
+					View rootView = LayoutInflater.from(getContext()).inflate(R.layout.report_background_location_dialog,null);
+
+					Button rejectBtn, askBtn, allowBtn;
+
+					rejectBtn = rootView.findViewById(R.id.report_reject_btn);
+					rejectBtn.setOnClickListener(new View.OnClickListener() {
+						@Override
+						public void onClick(View v) {
+
+							ApexDriverApplication.sharedApplication().setBackgroundReportType(ApexDriverApplication.BackgroundReportTypeReject);
+							dialog.dismiss();
+						}
+					});
+
+					askBtn = rootView.findViewById(R.id.report_always_ask_btn);
+					askBtn.setOnClickListener(new View.OnClickListener() {
+						@Override
+						public void onClick(View v) {
+
+							ApexDriverApplication.sharedApplication().setBackgroundReportType(ApexDriverApplication.BackgroundReportTypeAlways);
+							dialog.dismiss();
+						}
+					});
+
+
+					allowBtn = rootView.findViewById(R.id.report_allow_btn);
+					allowBtn.setOnClickListener(new View.OnClickListener() {
+						@Override
+						public void onClick(View v) {
+
+							ApexDriverApplication.sharedApplication().setBackgroundReportType(ApexDriverApplication.BackgroundReportTypeAllow);
+							dialog.dismiss();
+						}
+					});
+
+					return rootView;
+				}
+
+				@Override
+				public int dialogGravity(final BasicDialog dialog) {
+					return BasicDialog.BasicDialogContentGravityCenter;
+				}
+			}).show();
+
+		}
+	}
+
+	@Override
+	public void onCreate(@Nullable Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+	}
 
 	public void attemptLogin() {
 

+ 25 - 4
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/network/Network.java

@@ -245,14 +245,35 @@ public class Network extends com.usai.redant.rautils.utils.Network {
         getJson(URL_LOGOUT,params);
     }
 
-    public static void reportLocation(String location) {
+    public static void reportLocation(String location, String orderId) {
 
-        if (location == null) {
-            return;
+        Bundle params = new Bundle();
+        if (location != null) {
+            params.putString("location",location);
+        }
+
+        if (orderId != null) {
+            params.putString("orderID",orderId);
         }
 
+        params.putInt("userOption",0);
+
+        prepareParams(params);
+        getJson(URL_REPORT_LOCATION,params);
+    }
+
+    public static void rejectReportLocation(String reason, String orderId) {
+
         Bundle params = new Bundle();
-        params.putString("location",location);
+        if (reason != null) {
+            params.putString("reason",reason);
+        }
+
+        if (orderId != null) {
+            params.putString("orderID",orderId);
+        }
+
+        params.putInt("userOption",1);
 
         prepareParams(params);
         getJson(URL_REPORT_LOCATION,params);

+ 1 - 1
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/setting/changepassword/ChangePasswordDialog.java

@@ -35,7 +35,7 @@ public class ChangePasswordDialog extends Dialog {
     private Button cancelBtn,changeBtn;
 
     public ChangePasswordDialog(@NonNull Context context) {
-        this(context,R.style.changePasswordDialog);
+        this(context,R.style.RedAntDialog);
     }
 
     public ChangePasswordDialog(@NonNull Context context, int themeResId) {

+ 7 - 0
ApexDrivers/app/src/main/res/drawable/basic_dialog_bg.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <corners android:radius="5dp"></corners>
+    <solid android:color="#ffffff"/>
+
+</shape>

+ 24 - 0
ApexDrivers/app/src/main/res/drawable/btn_clickable_bg.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item android:state_pressed="true">
+
+        <shape>
+
+            <solid android:color="#aaaaaa"></solid>
+
+        </shape>
+
+    </item>
+
+    <item android:state_pressed="false">
+
+        <shape>
+
+            <solid android:color="#00000000"></solid>
+
+        </shape>
+
+    </item>
+
+</selector>

+ 96 - 0
ApexDrivers/app/src/main/res/layout/report_background_location_dialog.xml

@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+    >
+
+    <RelativeLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:background="@drawable/basic_dialog_bg"
+        android:layout_margin="20dp"
+        >
+
+        <TextView
+            android:id="@+id/report_title_tv"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_margin="5dp"
+            android:textSize="17sp"
+            android:textStyle="bold"
+            android:textAlignment="center"
+            android:textColor="#000000"
+            android:text="Warning"
+            />
+        <TextView
+            android:id="@+id/report_msg_tv"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/report_title_tv"
+            android:layout_marginLeft="5dp"
+            android:layout_marginRight="5dp"
+            android:layout_marginBottom="5dp"
+            android:singleLine="false"
+            android:textSize="15sp"
+            android:textAlignment="center"
+            android:textColor="#000000"
+            android:text="Apex &amp; Drivers need background send location"
+            />
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/report_msg_tv"
+            android:layout_marginBottom="5dp"
+            android:orientation="vertical"
+            >
+
+            <Button
+                android:id="@+id/report_reject_btn"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="5dp"
+                android:layout_marginRight="5dp"
+                android:layout_marginBottom="1dp"
+                android:text="Reject"
+                android:textSize="17sp"
+                android:textAllCaps="false"
+                android:textColor="#2476FF"
+                android:background="@drawable/btn_clickable_bg"
+                />
+
+            <Button
+                android:id="@+id/report_always_ask_btn"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="5dp"
+                android:layout_marginRight="5dp"
+                android:layout_marginBottom="1dp"
+                android:text="Always ask"
+                android:textSize="17sp"
+                android:textAllCaps="false"
+                android:textColor="#2476FF"
+                android:background="@drawable/btn_clickable_bg"
+                />
+
+            <Button
+                android:id="@+id/report_allow_btn"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="5dp"
+                android:layout_marginRight="5dp"
+                android:layout_marginBottom="1dp"
+                android:text="Allow"
+                android:textSize="17sp"
+                android:textAllCaps="false"
+                android:textColor="#2476FF"
+                android:background="@drawable/btn_clickable_bg"
+                />
+
+        </LinearLayout>
+
+
+    </RelativeLayout>
+
+
+</RelativeLayout>

+ 1 - 2
ApexDrivers/app/src/main/res/values/styles.xml

@@ -109,7 +109,7 @@
 
     <!--Dialog 样式-->
 
-    <style name="changePasswordDialog" parent="@android:style/Theme.Dialog">
+    <style name="RedAntDialog" parent="@android:style/Theme.Dialog">
 
         <!-- 背景透明 -->
         <item name="android:windowBackground">@android:color/transparent</item>
@@ -129,7 +129,6 @@
     </style>
 
 
-
     <!-- Dialog进出动画 -->
     <style name="DialogAnimation" parent="@android:style/Animation.Dialog">
         <item name="android:windowEnterAnimation">@anim/dialog_in</item>