|
|
@@ -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() {
|