Jelajahi Sumber

1.修改Android Apex Drivers位置上传。

Pen Li 7 tahun lalu
induk
melakukan
ad64979e0c

+ 64 - 3
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/ApexDriverApplication.java

@@ -1,8 +1,13 @@
 package com.usai.redant.apexdrivers;
 
 import android.app.Application;
+import android.content.ComponentName;
+import android.content.Context;
 import android.content.Intent;
+import android.content.ServiceConnection;
 import android.content.SharedPreferences;
+import android.location.Location;
+import android.os.IBinder;
 
 import com.usai.redant.rautils.Utils.AESUtil;
 
@@ -15,6 +20,11 @@ public class ApexDriverApplication extends Application {
     public String user;
     public String password;
 
+
+    private ServiceConnection mServiceConnection;
+    private ApexDriversBackgroundService mService;
+    private boolean mRequiredLocation = false;
+
     @Override
     public void onCreate() {
         super.onCreate();
@@ -24,11 +34,62 @@ public class ApexDriverApplication extends Application {
         user = savedUser();
         password = savedPassword();
 
+        mServiceConnection = new ServiceConnection() {
+            @Override
+            public void onServiceConnected(ComponentName name, IBinder service) {
+
+                ApexDriversBackgroundService.MyBinder binder = (ApexDriversBackgroundService.MyBinder)service;
+                mService = (ApexDriversBackgroundService)binder.getService();
+
+            }
+
+            @Override
+            public void onServiceDisconnected(ComponentName name) {
+
+                mService = null;
+            }
+        };
+
+//        Intent serviceintent = new Intent();
+//        serviceintent.setClass(this, ApexDriversBackgroundService.class);
+//        startService(serviceintent);
 
 
-         Intent serviceintent = new Intent();
-         serviceintent.setClass(this, ApexDriversBackgroundService.class);
-         startService(serviceintent);
+        Intent intent = new Intent(getApplicationContext(),ApexDriversBackgroundService.class);
+        bindService(intent,mServiceConnection, Context.BIND_AUTO_CREATE);
+
+    }
+
+
+    @Override
+    public void onTerminate() {
+        super.onTerminate();
+
+        unbindService(mServiceConnection);
+    }
+
+    public void setRequiredLocation(boolean requiredLocation) {
+        mRequiredLocation = requiredLocation;
+
+        if (mService != null) {
+            if (mRequiredLocation) {
+
+                mService.startLocation();
+
+            } else {
+
+                mService.stopLocation();
+
+            }
+        }
+    }
+
+    public boolean getRequiredLocation() {
+        return mRequiredLocation;
+    }
+
+    public Location getCurrentLocation() {
+        return mService.RequestCachedLocation();
     }
 
     public boolean isLogin() {

+ 10 - 0
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/ApexDriversBackgroundService.java

@@ -1,9 +1,11 @@
 package com.usai.redant.apexdrivers;
 
 import android.app.Notification;
+import android.content.Intent;
 import android.location.Location;
 import android.util.Log;
 
+import com.usai.redant.rautils.Receiver.RABroadcast;
 import com.usai.redant.rautils.Service.RAService;
 import com.usai.redant.rautils.Upload.RAUploadManager;
 import com.usai.redant.rautils.Utils.dbgUtil;
@@ -55,6 +57,14 @@ public class ApexDriversBackgroundService extends RAService implements RAService
 
     }
 
+    public void startLocation() {
+        sendBroadcast(new Intent(RABroadcast.ACTION_LOCATION_ENABLE_TRACING));
+    }
+
+    public void stopLocation() {
+        sendBroadcast(new Intent(RABroadcast.ACTION_LOCATION_DISABLE_TRACING));
+    }
+
 
 //    @Override
 //    public IBinder onBind(Intent intent) {

+ 7 - 0
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/Detail/DetailActivity.java

@@ -31,6 +31,7 @@ import android.widget.SimpleAdapter;
 import android.widget.TextView;
 import android.widget.Toast;
 
+import com.usai.redant.apexdrivers.ApexDriverApplication;
 import com.usai.redant.apexdrivers.Detail.Model.DetailActionSelectionModel;
 import com.usai.redant.apexdrivers.Detail.Model.DetailLocationModel;
 import com.usai.redant.apexdrivers.Detail.Model.DetailSubActionModel;
@@ -49,6 +50,7 @@ import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 
 
+import static com.usai.redant.apexdrivers.Detail.Model.DetailSubActionModel.DetailActionSubType.DetailActionSubTypeAccept;
 import static com.usai.redant.apexdrivers.Detail.Model.DetailSubActionModel.DetailActionSubType.DetailActionSubTypeEnum;
 import static com.usai.redant.rautils.Utils.Network.RESULT_TRUE;
 
@@ -332,6 +334,11 @@ public class DetailActivity extends AppCompatActivity implements DetailAdapter.D
             }
             break;
             case DetailSubActionModel.DetailActionType.DetailActionTypeRemote: {
+
+                if (actionModel.actionSubType == DetailActionSubTypeAccept) {
+                    ApexDriverApplication.sharedApplication().setRequiredLocation(true);
+                }
+
                 report(actionModel.url,actionModel.params);
             }
             break;

+ 1 - 0
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/Detail/Model/DetailSubActionModel.java

@@ -18,6 +18,7 @@ public class DetailSubActionModel {
         public static final int DetailActionSubTypeEnum = 0;
         public static final int DetailActionSubTypeAccept = 1;
         public static final int DetailActionSubTypeReject = 2;
+        public static final int DetailActionSubTypeOther = 3;
     }
 
     public int actionType;

+ 8 - 3
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/Home/HomeFragment.java

@@ -28,6 +28,7 @@ import android.widget.RelativeLayout;
 import android.widget.TextView;
 
 
+import com.usai.redant.apexdrivers.ApexDriverApplication;
 import com.usai.redant.apexdrivers.Detail.DetailActivity;
 import com.usai.redant.apexdrivers.R;
 import com.usai.redant.rautils.Utils.Network;
@@ -244,6 +245,9 @@ public class HomeFragment extends Fragment {
                         int restul = json.getInt("result");
                         if (restul == Network.RESULT_TRUE) {
 
+                            boolean requiredLocation = json.optBoolean("requiredLocation");
+                            ApexDriverApplication.sharedApplication().setRequiredLocation(requiredLocation);
+
                             mSelectedModel = null;
                             handleJson(json);
 
@@ -308,12 +312,13 @@ public class HomeFragment extends Fragment {
 
             HomeFragment fragment = mWeakHome.get();
             fragment.dismissProgressDialog();
+            if (fragment.mRefresh.isRefreshing()) {
+                fragment.mRefresh.setRefreshing(false);
+            }
+
             switch (msg.what) {
                 case HomeActionReloadData: {
 
-                    if (fragment.mRefresh.isRefreshing()) {
-                        fragment.mRefresh.setRefreshing(false);
-                    }
                     /**
                      * 手动调用打开/关闭 Group,否则默认关闭
                      * */

+ 13 - 0
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/Network/Network.java

@@ -307,6 +307,19 @@ public class Network extends com.usai.redant.rautils.Utils.Network {
         getJson(URL_LOGOUT,params);
     }
 
+    public static void reportLocation(String location) {
+
+        if (location == null) {
+            return;
+        }
+
+        Bundle params = new Bundle();
+        params.putString("location",location);
+
+        prepareParams(params);
+        getJson(URL_REPORT_LOCATION,params);
+    }
+
     private static JSONObject loadFakeData(Context context, int rawId) {
 
         try

+ 11 - 0
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/Update/UpdateActivity.java

@@ -9,6 +9,7 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.database.Cursor;
+import android.location.Location;
 import android.net.Uri;
 import android.os.Environment;
 import android.os.Handler;
@@ -418,6 +419,13 @@ public class UpdateActivity extends AppCompatActivity implements UpdateAdapter.U
         if (mOrderType2 != null) {
             params.putString("orderType2",mOrderType2);
         }
+        if (ApexDriverApplication.sharedApplication().getRequiredLocation()) {
+            Location location = ApexDriverApplication.sharedApplication().getCurrentLocation();
+            if (location != null) {
+                String locationStr = location.getLatitude() + "," + location.getLongitude();
+                params.putString("location",locationStr);
+            }
+        }
         final ArrayList<UpdatePhotoModel> photoArr = prepareParams(params);
 
         final Bundle finalParams = params;
@@ -435,6 +443,9 @@ public class UpdateActivity extends AppCompatActivity implements UpdateAdapter.U
                             final int result = json.optInt("result",0);
                             if (result == RESULT_TRUE) {
 
+                                boolean requiredLocation = json.optBoolean("requiredLocation");
+                                ApexDriverApplication.sharedApplication().setRequiredLocation(requiredLocation);
+
                                 if (photoArr.size() > 0) {
                                     syncUploadPhotos(photoArr,json);
                                 } else {