Add activityRecognitionAPI, InternetAPI, batteryAPI, locationAPI V 0.3
This commit is contained in:
parent
4eabcfca5a
commit
d9d7531ca8
|
|
@ -10,6 +10,13 @@ android {
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
// Enabling multi-dex support.
|
||||||
|
multiDexEnabled true
|
||||||
|
}
|
||||||
|
dexOptions {
|
||||||
|
incremental true
|
||||||
|
javaMaxHeapSize "4g"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import com.pureix.easylocator.controller.service.BatteryAPI;
|
||||||
import com.pureix.easylocator.controller.service.InternetAPI;
|
import com.pureix.easylocator.controller.service.InternetAPI;
|
||||||
import com.pureix.easylocator.controller.service.LocationAPI;
|
import com.pureix.easylocator.controller.service.LocationAPI;
|
||||||
import com.pureix.easylocator.controller.service.SmartLocationAPI;
|
import com.pureix.easylocator.controller.service.SmartLocationAPI;
|
||||||
|
import com.pureix.easylocator.service.batteryService.bean.BatteryInformation;
|
||||||
import com.pureix.easylocator.model.bean.CustomSettingsLocation;
|
import com.pureix.easylocator.model.bean.CustomSettingsLocation;
|
||||||
import com.pureix.easylocator.service.batteryService.listener.BatteryReceiverListener;
|
import com.pureix.easylocator.service.batteryService.listener.BatteryReceiverListener;
|
||||||
import com.pureix.easylocator.service.activityRecognitionService.listener.ActivityRecognitionListener;
|
import com.pureix.easylocator.service.activityRecognitionService.listener.ActivityRecognitionListener;
|
||||||
|
|
@ -24,12 +25,17 @@ import com.pureix.easylocator.service.internetService.listener.ConnectivityRecei
|
||||||
import com.pureix.easylocator.service.locatonService.Listener.LocationReceiverListener;
|
import com.pureix.easylocator.service.locatonService.Listener.LocationReceiverListener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Observable;
|
||||||
|
import java.util.Observer;
|
||||||
|
|
||||||
|
import static com.pureix.easylocator.service.batteryService.broadcastReceiver.BatteryAppSideBroadcast.batteryChangedObservable;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private TextView txt;
|
private TextView txt;
|
||||||
private LocationAPI locationAPI;
|
private LocationAPI locationAPI;
|
||||||
private ActivityRecognitionAPI activityRecognitionAPI;
|
private ActivityRecognitionAPI activityRecognitionAPI;
|
||||||
|
private BatteryAPI batteryAPI;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
@ -39,6 +45,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
txt = (TextView) findViewById(R.id.txt);
|
txt = (TextView) findViewById(R.id.txt);
|
||||||
|
|
||||||
activityRecognitionAPI = new ActivityRecognitionAPI(MainActivity.this);
|
activityRecognitionAPI = new ActivityRecognitionAPI(MainActivity.this);
|
||||||
activityRecognitionAPI.setActivitiesRecognitionListener(new ActivityRecognitionListener()
|
activityRecognitionAPI.setActivitiesRecognitionListener(new ActivityRecognitionListener()
|
||||||
{
|
{
|
||||||
|
|
@ -63,16 +70,18 @@ public class MainActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
BatteryAPI.start(MainActivity.this);
|
batteryAPI = new BatteryAPI(MainActivity.this);
|
||||||
BatteryAPI.batteryListener(new BatteryReceiverListener() {
|
|
||||||
|
batteryAPI.batteryListener(new BatteryReceiverListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onBatteryInformationChanged(int level, int scale, int temperature, int voltage, float batteryPct, int status, boolean isCharging, int chargePlug, boolean usbCharge, boolean acCharge) {
|
public void onBatteryInformationChanged(BatteryInformation batteryInformation) {
|
||||||
txt.append("level is " + level + "/" + scale +
|
txt.append("level is " + batteryInformation.getLevel()
|
||||||
", temp is " + temperature +
|
+ "/" + batteryInformation.getScale() +
|
||||||
", voltage is " + voltage
|
", temp is " + batteryInformation.getTemperature() +
|
||||||
+ " status :" + status +
|
", voltage is " + batteryInformation.getTemperature()
|
||||||
" chargePlug :" + chargePlug +
|
+ " status :" + batteryInformation.getStatus() +
|
||||||
" Battery Pct : " + batteryPct * 100 +"\n\n");
|
" chargePlug :" + batteryInformation.getChargePlug() +
|
||||||
|
" Battery Pct : " + batteryInformation.getBatteryPct() * 100 +"\n\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -101,12 +110,12 @@ public class MainActivity extends AppCompatActivity {
|
||||||
smartLocationAPI.setLocationReceiverListener(new LocationReceiverListener() {
|
smartLocationAPI.setLocationReceiverListener(new LocationReceiverListener() {
|
||||||
@Override
|
@Override
|
||||||
public void getLastKnownLocation(Location location) {
|
public void getLastKnownLocation(Location location) {
|
||||||
|
txt.append("Smart getLastKnownLocation "+location+"\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
|
txt.append("Smart onLocationChanged "+location+"\n\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -150,6 +159,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
activityRecognitionAPI.start();
|
activityRecognitionAPI.start();
|
||||||
locationAPI.start();
|
locationAPI.start();
|
||||||
|
batteryAPI.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -157,6 +167,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
activityRecognitionAPI.pause();
|
activityRecognitionAPI.pause();
|
||||||
locationAPI.pause();
|
locationAPI.pause();
|
||||||
|
batteryAPI.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ buildscript {
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:2.2.3'
|
classpath 'com.android.tools.build:gradle:2.3.2'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,15 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:name=".service.batteryService.broadcastReceiver.BatteryAppSideBroadcast"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".service.batteryService.BatteryService"
|
android:name=".service.batteryService.BatteryService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
|
|
|
||||||
|
|
@ -3,24 +3,44 @@ package com.pureix.easylocator.controller.service;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import com.pureix.easylocator.service.activityRecognitionService.ActivitiesRecognitionService;
|
|
||||||
import com.pureix.easylocator.service.activityRecognitionService.broadcastReceiver.InitializeActivityRecognitionBroadcast;
|
|
||||||
import com.pureix.easylocator.service.batteryService.BatteryService;
|
import com.pureix.easylocator.service.batteryService.BatteryService;
|
||||||
import com.pureix.easylocator.service.batteryService.broadcastReceiver.BatteryStateReceiver;
|
import com.pureix.easylocator.service.batteryService.bean.BatteryInformation;
|
||||||
import com.pureix.easylocator.service.batteryService.broadcastReceiver.InitializeBatteryBroadcast;
|
import com.pureix.easylocator.service.batteryService.broadcastReceiver.InitializeBatteryFromAppBroadcast;
|
||||||
import com.pureix.easylocator.service.batteryService.listener.BatteryReceiverListener;
|
import com.pureix.easylocator.service.batteryService.listener.BatteryReceiverListener;
|
||||||
|
|
||||||
|
import java.util.Observable;
|
||||||
|
import java.util.Observer;
|
||||||
|
|
||||||
|
import static com.pureix.easylocator.service.batteryService.broadcastReceiver.BatteryAppSideBroadcast.batteryChangedObservable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by MelDiSooQi on 2/11/2017.
|
* Created by MelDiSooQi on 2/11/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class BatteryAPI {
|
public class BatteryAPI {
|
||||||
|
|
||||||
private static InitializeBatteryBroadcast broadcast;
|
private static int instanceCounter;
|
||||||
public static BatteryReceiverListener batteryReceiverListener;
|
private Context context;
|
||||||
|
|
||||||
public static void start(Context context)
|
//private InitializeBatteryBroadcast broadcast;
|
||||||
|
private InitializeBatteryFromAppBroadcast broadcast;
|
||||||
|
private static BatteryReceiverListener batteryReceiverListener;
|
||||||
|
|
||||||
|
public BatteryAPI(Context context)
|
||||||
{
|
{
|
||||||
|
this.context = context;
|
||||||
|
instanceCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getInstanceCounter() {
|
||||||
|
return instanceCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start()
|
||||||
|
{
|
||||||
|
broadcast = new InitializeBatteryFromAppBroadcast();
|
||||||
|
broadcast.onResume(context);
|
||||||
|
|
||||||
Intent i = new Intent(context, BatteryService.class);
|
Intent i = new Intent(context, BatteryService.class);
|
||||||
context.stopService(i);
|
context.stopService(i);
|
||||||
context.startService(i);
|
context.startService(i);
|
||||||
|
|
@ -29,13 +49,26 @@ public class BatteryAPI {
|
||||||
// broadcast.onResume(context);
|
// broadcast.onResume(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void pause(Context context)
|
public void pause()
|
||||||
{
|
{
|
||||||
// broadcast.onPause(context);
|
broadcast.onPause(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void batteryListener(BatteryReceiverListener batteryReceiverListener) {
|
public void batteryListener(BatteryReceiverListener batteryReceiverListener) {
|
||||||
BatteryAPI
|
this.batteryReceiverListener = batteryReceiverListener;
|
||||||
.batteryReceiverListener = batteryReceiverListener;
|
createListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createListener() {
|
||||||
|
|
||||||
|
batteryChangedObservable.addObserver(new Observer() {
|
||||||
|
@Override
|
||||||
|
public void update(Observable o, Object batteryInformation) {
|
||||||
|
if(batteryReceiverListener != null) {
|
||||||
|
batteryReceiverListener
|
||||||
|
.onBatteryInformationChanged((BatteryInformation) batteryInformation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,14 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
|
||||||
import com.pureix.easylocator.service.activityRecognitionService.ActivitiesRecognitionService;
|
import com.google.android.gms.location.LocationRequest;
|
||||||
import com.pureix.easylocator.service.activityRecognitionService.broadcastReceiver.InitializeActivityRecognitionBroadcast;
|
import com.google.gson.Gson;
|
||||||
|
import com.pureix.easylocator.model.bean.CustomSettingsLocation;
|
||||||
|
import com.pureix.easylocator.service.locatonService.Constants;
|
||||||
import com.pureix.easylocator.service.locatonService.Listener.LocationReceiverListener;
|
import com.pureix.easylocator.service.locatonService.Listener.LocationReceiverListener;
|
||||||
import com.pureix.easylocator.service.locatonService.LocationService;
|
import com.pureix.easylocator.service.locatonService.LocationService;
|
||||||
|
import com.pureix.easylocator.service.locatonService.LocationServicesConstant;
|
||||||
import com.pureix.easylocator.service.locatonService.broadcastReceiver.InitializeLocationBroadcast;
|
import com.pureix.easylocator.service.locatonService.broadcastReceiver.InitializeLocationBroadcast;
|
||||||
import com.pureix.easylocator.service.locatonService.broadcastReceiver.LocationBroadcast;
|
|
||||||
import com.pureix.easylocator.service.locatonService.permission.LocationPermission;
|
import com.pureix.easylocator.service.locatonService.permission.LocationPermission;
|
||||||
|
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
|
|
@ -32,6 +34,8 @@ public class LocationAPI
|
||||||
private LocationPermission locationPermission;
|
private LocationPermission locationPermission;
|
||||||
private LocationReceiverListener locationReceiverListener;
|
private LocationReceiverListener locationReceiverListener;
|
||||||
|
|
||||||
|
private CustomSettingsLocation customSettingsLocation;
|
||||||
|
|
||||||
public LocationAPI(Context context)
|
public LocationAPI(Context context)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
@ -44,11 +48,30 @@ public class LocationAPI
|
||||||
|
|
||||||
public void start()
|
public void start()
|
||||||
{
|
{
|
||||||
|
startCustomService(createCustomSettingsLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
private CustomSettingsLocation createCustomSettingsLocation() {
|
||||||
|
customSettingsLocation = new CustomSettingsLocation();
|
||||||
|
|
||||||
|
customSettingsLocation.setDetectedActivityType(-1);
|
||||||
|
customSettingsLocation.setDetectedActivityProvider("Normal");
|
||||||
|
|
||||||
|
customSettingsLocation.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
|
||||||
|
customSettingsLocation.setInterval(Constants.UPDATE_INTERVAL);
|
||||||
|
customSettingsLocation.setFastestInterval(Constants.FASTEST_INTERVAL);
|
||||||
|
customSettingsLocation.setSmallestDisplacement(0);
|
||||||
|
|
||||||
|
return customSettingsLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startCustomService(CustomSettingsLocation customSettingsLocation) {
|
||||||
broadcast = new InitializeLocationBroadcast();
|
broadcast = new InitializeLocationBroadcast();
|
||||||
broadcast.onResume(context);
|
broadcast.onResume(context);
|
||||||
|
|
||||||
Intent i = new Intent(context, LocationService.class);
|
Intent i = new Intent(context, LocationService.class);
|
||||||
context.stopService(i);
|
context.stopService(i);
|
||||||
|
i.putExtra(LocationServicesConstant.CUSTOM_SETTINGS_LOCATION, new Gson().toJson(customSettingsLocation));
|
||||||
context.startService(i);
|
context.startService(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import com.google.android.gms.location.DetectedActivity;
|
||||||
import com.google.android.gms.location.LocationRequest;
|
import com.google.android.gms.location.LocationRequest;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.pureix.easylocator.controller.service.ActivityRecognitionAPI;
|
import com.pureix.easylocator.controller.service.ActivityRecognitionAPI;
|
||||||
|
import com.pureix.easylocator.controller.service.LocationAPI;
|
||||||
import com.pureix.easylocator.model.ObservableHandler;
|
import com.pureix.easylocator.model.ObservableHandler;
|
||||||
import com.pureix.easylocator.model.bean.CustomSettingsLocation;
|
import com.pureix.easylocator.model.bean.CustomSettingsLocation;
|
||||||
import com.pureix.easylocator.model.storage.LocalStorage;
|
import com.pureix.easylocator.model.storage.LocalStorage;
|
||||||
|
|
@ -41,6 +42,7 @@ public class SmartLocationBusiness
|
||||||
public static final int LOCATION_PRIORITY_PRIORITY_NO_POWER
|
public static final int LOCATION_PRIORITY_PRIORITY_NO_POWER
|
||||||
= LocationRequest.PRIORITY_NO_POWER;
|
= LocationRequest.PRIORITY_NO_POWER;
|
||||||
private Timer mtimer;
|
private Timer mtimer;
|
||||||
|
private LocationAPI locationAPI;
|
||||||
|
|
||||||
public void start(Context context) {
|
public void start(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
@ -102,7 +104,13 @@ public class SmartLocationBusiness
|
||||||
}
|
}
|
||||||
|
|
||||||
if(DetectedActivity.ON_FOOT == type){
|
if(DetectedActivity.ON_FOOT == type){
|
||||||
|
customSettingsLocation.setDetectedActivityType(type);
|
||||||
|
customSettingsLocation.setDetectedActivityProvider(activityRecognitionAPI.getActivityString(context, detectedActivity.getType()));
|
||||||
|
|
||||||
|
customSettingsLocation.setPriority(LOCATION_PRIORITY_PRIORITY_HIGH_ACCURACY);
|
||||||
|
customSettingsLocation.setInterval(4 * 1000);
|
||||||
|
customSettingsLocation.setFastestInterval(4 * 1000);
|
||||||
|
customSettingsLocation.setSmallestDisplacement(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(DetectedActivity.WALKING == type){
|
if(DetectedActivity.WALKING == type){
|
||||||
|
|
@ -165,7 +173,14 @@ public class SmartLocationBusiness
|
||||||
customSettingsLocation.setSmallestDisplacement(10);
|
customSettingsLocation.setSmallestDisplacement(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveCustomSettingsLocationInLocalStorage(time, customSettingsLocation);
|
reOpenLocationServiceWithNewSettings(customSettingsLocation);
|
||||||
|
//saveCustomSettingsLocationInLocalStorage(time, customSettingsLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reOpenLocationServiceWithNewSettings(CustomSettingsLocation customSettings) {
|
||||||
|
locationAPI = new LocationAPI(context);
|
||||||
|
|
||||||
|
locationAPI.startCustomService(customSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveCustomSettingsLocationInLocalStorage(int time,
|
private void saveCustomSettingsLocationInLocalStorage(int time,
|
||||||
|
|
@ -214,6 +229,7 @@ public class SmartLocationBusiness
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause() {
|
public void pause() {
|
||||||
|
locationAPI.pause();
|
||||||
activityRecognitionAPI.pause();
|
activityRecognitionAPI.pause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import android.content.Intent;
|
||||||
|
|
||||||
import com.google.android.gms.location.DetectedActivity;
|
import com.google.android.gms.location.DetectedActivity;
|
||||||
import com.pureix.easylocator.service.activityRecognitionService.Constants;
|
import com.pureix.easylocator.service.activityRecognitionService.Constants;
|
||||||
import com.pureix.easylocator.service.locatonService.ServicesConstant;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
@ -31,9 +30,9 @@ public class ActivityRecognitionSender
|
||||||
|
|
||||||
// public void sendLocationToApp(String jsonLocation)
|
// public void sendLocationToApp(String jsonLocation)
|
||||||
// {
|
// {
|
||||||
// intent.putExtra(ServicesConstant.SERVICE_ID , ServicesConstant
|
// intent.putExtra(LocationServicesConstant.SERVICE_ID , LocationServicesConstant
|
||||||
// .SERVICE_ID_SEND_JSON_LOCATION);
|
// .SERVICE_ID_SEND_JSON_LOCATION);
|
||||||
// intent.putExtra(ServicesConstant.JSON_LOCATION , jsonLocation);
|
// intent.putExtra(LocationServicesConstant.JSON_LOCATION , jsonLocation);
|
||||||
//
|
//
|
||||||
// context.sendBroadcast(intent);
|
// context.sendBroadcast(intent);
|
||||||
// }
|
// }
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.pureix.easylocator.service.batteryService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by M.Hayle on 6/29/2016.
|
||||||
|
*/
|
||||||
|
public class BatteryServicesConstant
|
||||||
|
{
|
||||||
|
//==========================S Location Service=================================
|
||||||
|
public final static String SERVICE_ID = "SERVICE_ID";
|
||||||
|
public final static int SERVICE_ID_SEND_JSON_BATTERY_INFORMATION = 0;
|
||||||
|
|
||||||
|
//==========================E Location Service=================================
|
||||||
|
|
||||||
|
public final static String JSON_BATTERY_INFORMATION = "BATTERY_INFORMATION";
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,117 @@
|
||||||
|
package com.pureix.easylocator.service.batteryService.bean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by MelDiSooQi on 5/18/2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class BatteryInformation
|
||||||
|
{
|
||||||
|
int level;
|
||||||
|
int scale;
|
||||||
|
int temperature;
|
||||||
|
int voltage;
|
||||||
|
float batteryPct;
|
||||||
|
int status;
|
||||||
|
boolean isCharging;
|
||||||
|
int chargePlug;
|
||||||
|
boolean usbCharge;
|
||||||
|
boolean acCharge;
|
||||||
|
|
||||||
|
public BatteryInformation() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public BatteryInformation(int level, int scale, int temperature, int voltage,
|
||||||
|
float batteryPct, int status, boolean isCharging,
|
||||||
|
int chargePlug, boolean usbCharge, boolean acCharge) {
|
||||||
|
this.level = level;
|
||||||
|
this.scale = scale;
|
||||||
|
this.temperature = temperature;
|
||||||
|
this.voltage = voltage;
|
||||||
|
this.batteryPct = batteryPct;
|
||||||
|
this.status = status;
|
||||||
|
this.isCharging = isCharging;
|
||||||
|
this.chargePlug = chargePlug;
|
||||||
|
this.usbCharge = usbCharge;
|
||||||
|
this.acCharge = acCharge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLevel(int level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getScale() {
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScale(int scale) {
|
||||||
|
this.scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTemperature() {
|
||||||
|
return temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTemperature(int temperature) {
|
||||||
|
this.temperature = temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVoltage() {
|
||||||
|
return voltage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVoltage(int voltage) {
|
||||||
|
this.voltage = voltage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getBatteryPct() {
|
||||||
|
return batteryPct;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBatteryPct(float batteryPct) {
|
||||||
|
this.batteryPct = batteryPct;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCharging() {
|
||||||
|
return isCharging;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCharging(boolean charging) {
|
||||||
|
isCharging = charging;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getChargePlug() {
|
||||||
|
return chargePlug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChargePlug(int chargePlug) {
|
||||||
|
this.chargePlug = chargePlug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUsbCharge() {
|
||||||
|
return usbCharge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsbCharge(boolean usbCharge) {
|
||||||
|
this.usbCharge = usbCharge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAcCharge() {
|
||||||
|
return acCharge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAcCharge(boolean acCharge) {
|
||||||
|
this.acCharge = acCharge;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.pureix.easylocator.service.batteryService.broadcastReceiver;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.pureix.easylocator.model.ObservableHandler;
|
||||||
|
import com.pureix.easylocator.service.batteryService.bean.BatteryInformation;
|
||||||
|
import com.pureix.easylocator.service.batteryService.BatteryServicesConstant;
|
||||||
|
|
||||||
|
public class BatteryAppSideBroadcast extends BroadcastReceiver
|
||||||
|
{
|
||||||
|
public static ObservableHandler batteryChangedObservable = new ObservableHandler();
|
||||||
|
|
||||||
|
boolean isLocationInitialized = false;
|
||||||
|
|
||||||
|
public BatteryAppSideBroadcast() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
Bundle extras = intent.getExtras();
|
||||||
|
|
||||||
|
if(extras.getInt(BatteryServicesConstant.SERVICE_ID) ==
|
||||||
|
BatteryServicesConstant.SERVICE_ID_SEND_JSON_BATTERY_INFORMATION) {
|
||||||
|
|
||||||
|
String jsonBatteryInformation = extras.getString(BatteryServicesConstant.JSON_BATTERY_INFORMATION);
|
||||||
|
|
||||||
|
BatteryInformation batteryInformation = new Gson()
|
||||||
|
.fromJson(jsonBatteryInformation, BatteryInformation.class);
|
||||||
|
|
||||||
|
batteryChangedObservable.setChange(batteryInformation);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.pureix.easylocator.service.batteryService.broadcastReceiver;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import com.pureix.easylocator.service.batteryService.BatteryServicesConstant;
|
||||||
|
import com.pureix.easylocator.service.locatonService.LocationServicesConstant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by MelDiSooQi on 7/16/2016.
|
||||||
|
*/
|
||||||
|
public class BatteryInformationSender
|
||||||
|
{
|
||||||
|
private final Context context;
|
||||||
|
private final Class<?> aClass;
|
||||||
|
private Intent intent;
|
||||||
|
|
||||||
|
public BatteryInformationSender(Context context, Class<?> aClass)
|
||||||
|
{
|
||||||
|
this.context = context;
|
||||||
|
this.aClass = aClass;
|
||||||
|
this.intent = new Intent(context, aClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Intent getIntent() {
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void sendBatteryInformationToApp(String jsonLocation)
|
||||||
|
{
|
||||||
|
intent.putExtra(BatteryServicesConstant.SERVICE_ID , BatteryServicesConstant
|
||||||
|
.SERVICE_ID_SEND_JSON_BATTERY_INFORMATION);
|
||||||
|
intent.putExtra(BatteryServicesConstant.JSON_BATTERY_INFORMATION , jsonLocation);
|
||||||
|
|
||||||
|
context.sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,18 +3,18 @@ package com.pureix.easylocator.service.batteryService.broadcastReceiver;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.pureix.easylocator.service.batteryService.listener.BatteryReceiverListener;
|
import com.google.gson.Gson;
|
||||||
|
import com.pureix.easylocator.service.batteryService.bean.BatteryInformation;
|
||||||
|
|
||||||
import static com.pureix.easylocator.controller.service.BatteryAPI.batteryReceiverListener;
|
|
||||||
|
|
||||||
public class BatteryStateReceiver extends BroadcastReceiver
|
public class BatteryStateReceiver extends BroadcastReceiver
|
||||||
{
|
{
|
||||||
//private static Context context;
|
//private static Context context;
|
||||||
|
|
||||||
|
// public static ObservableHandler batteryChangedObservable = new ObservableHandler();
|
||||||
|
|
||||||
|
|
||||||
private static Boolean batteryReceiverIsRegistered = false;
|
private static Boolean batteryReceiverIsRegistered = false;
|
||||||
|
|
||||||
|
|
@ -47,6 +47,8 @@ public class BatteryStateReceiver extends BroadcastReceiver
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent)
|
public void onReceive(Context context, Intent intent)
|
||||||
{
|
{
|
||||||
|
BatteryInformationSender senderHandler = new BatteryInformationSender(context, BatteryAppSideBroadcast.class);
|
||||||
|
|
||||||
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
|
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
|
||||||
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
|
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
|
||||||
int temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
|
int temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
|
||||||
|
|
@ -67,11 +69,18 @@ public class BatteryStateReceiver extends BroadcastReceiver
|
||||||
|
|
||||||
if(!(level == -1 && scale == -1 && temperature == -1 && voltage == -1
|
if(!(level == -1 && scale == -1 && temperature == -1 && voltage == -1
|
||||||
&& status == -1 && chargePlug == -1)) {
|
&& status == -1 && chargePlug == -1)) {
|
||||||
if(batteryReceiverListener != null) {
|
/*if(batteryReceiverListener != null) {
|
||||||
batteryReceiverListener.onBatteryInformationChanged(level, scale,
|
batteryReceiverListener.onBatteryInformationChanged(level, scale,
|
||||||
temperature, voltage, batteryPct, status, isCharging,
|
temperature, voltage, batteryPct, status, isCharging,
|
||||||
chargePlug, usbCharge, acCharge);
|
chargePlug, usbCharge, acCharge);
|
||||||
}
|
}*/
|
||||||
|
BatteryInformation batteryInformation = new BatteryInformation(level,
|
||||||
|
scale, temperature, voltage, batteryPct, status, isCharging,
|
||||||
|
chargePlug, usbCharge, acCharge);
|
||||||
|
|
||||||
|
sendBatteryInformationToBroadcast(senderHandler, batteryInformation);
|
||||||
|
|
||||||
|
|
||||||
// Toast.makeText(context,
|
// Toast.makeText(context,
|
||||||
// "level is " + level + "/" + scale +
|
// "level is " + level + "/" + scale +
|
||||||
// ", temp is " + temperature +
|
// ", temp is " + temperature +
|
||||||
|
|
@ -82,4 +91,11 @@ public class BatteryStateReceiver extends BroadcastReceiver
|
||||||
// Toast.LENGTH_SHORT).show();
|
// Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendBatteryInformationToBroadcast(BatteryInformationSender senderHandler,
|
||||||
|
BatteryInformation batteryInformation) {
|
||||||
|
senderHandler
|
||||||
|
.sendBatteryInformationToApp(new Gson()
|
||||||
|
.toJson(batteryInformation));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import com.pureix.easylocator.service.activityRecognitionService.broadcastReceiv
|
||||||
|
|
||||||
public class InitializeBatteryBroadcast
|
public class InitializeBatteryBroadcast
|
||||||
{
|
{
|
||||||
private static BatteryStateReceiver broadcastReceiver = null;
|
private static BatteryStateReceiver broadcastReceiver = null;
|
||||||
private static Boolean isRegistered = false;
|
private static Boolean isRegistered = false;
|
||||||
|
|
||||||
public InitializeBatteryBroadcast() {
|
public InitializeBatteryBroadcast() {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.pureix.easylocator.service.batteryService.broadcastReceiver;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.ActivityManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by MelDiSooQi on 1/28/2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class InitializeBatteryFromAppBroadcast
|
||||||
|
{
|
||||||
|
private static BatteryAppSideBroadcast broadcastReceiverFromApp = null;
|
||||||
|
private static Boolean isRegistered = false;
|
||||||
|
|
||||||
|
public InitializeBatteryFromAppBroadcast() {
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initialize()
|
||||||
|
{
|
||||||
|
broadcastReceiverFromApp = new BatteryAppSideBroadcast();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPause(Context context)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (isRegistered) {
|
||||||
|
context.unregisterReceiver(broadcastReceiverFromApp);
|
||||||
|
isRegistered = false;
|
||||||
|
}
|
||||||
|
}catch (Exception e)
|
||||||
|
{}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onResume(Context context)
|
||||||
|
{
|
||||||
|
if (!isRegistered)
|
||||||
|
{
|
||||||
|
IntentFilter filter = new IntentFilter("com.pureix.easylocator.service.batteryService.broadcastReceiver.BatteryAppSideBroadcast");
|
||||||
|
context.registerReceiver(broadcastReceiverFromApp, filter);
|
||||||
|
|
||||||
|
isRegistered = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMyServiceRunning(Activity activity, Class<?> serviceClass)
|
||||||
|
{
|
||||||
|
ActivityManager manager = (ActivityManager) activity
|
||||||
|
.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
for (ActivityManager.RunningServiceInfo service : manager
|
||||||
|
.getRunningServices(Integer.MAX_VALUE)) {
|
||||||
|
if (serviceClass.getName().equals(service.service.getClassName())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,13 +1,17 @@
|
||||||
package com.pureix.easylocator.service.batteryService.listener;
|
package com.pureix.easylocator.service.batteryService.listener;
|
||||||
|
|
||||||
|
import com.pureix.easylocator.service.batteryService.bean.BatteryInformation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by MelDiSooQi on 1/27/2017.
|
* Created by MelDiSooQi on 1/27/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface BatteryReceiverListener
|
public interface BatteryReceiverListener
|
||||||
{
|
{
|
||||||
void onBatteryInformationChanged(int level, int scale, int temperature,
|
/*void onBatteryInformationChanged(int level, int scale, int temperature,
|
||||||
int voltage, float batteryPct, int status,
|
int voltage, float batteryPct, int status,
|
||||||
boolean isCharging, int chargePlug,
|
boolean isCharging, int chargePlug,
|
||||||
boolean usbCharge, boolean acCharge);
|
boolean usbCharge, boolean acCharge);*/
|
||||||
|
|
||||||
|
void onBatteryInformationChanged(BatteryInformation batteryInformation);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import android.os.PowerManager;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.google.android.gms.common.ConnectionResult;
|
import com.google.android.gms.common.ConnectionResult;
|
||||||
import com.google.android.gms.common.GoogleApiAvailability;
|
import com.google.android.gms.common.GoogleApiAvailability;
|
||||||
|
|
@ -25,18 +24,12 @@ import com.google.gson.Gson;
|
||||||
import com.pureix.easylocator.model.bean.CustomSettingsLocation;
|
import com.pureix.easylocator.model.bean.CustomSettingsLocation;
|
||||||
import com.pureix.easylocator.model.storage.LocalStorage;
|
import com.pureix.easylocator.model.storage.LocalStorage;
|
||||||
import com.pureix.easylocator.model.storage.LocalStorageConstant;
|
import com.pureix.easylocator.model.storage.LocalStorageConstant;
|
||||||
import com.pureix.easylocator.service.locatonService.Listener.LocationReceiverListener;
|
|
||||||
import com.pureix.easylocator.service.locatonService.broadcastReceiver.LocationBroadcast;
|
import com.pureix.easylocator.service.locatonService.broadcastReceiver.LocationBroadcast;
|
||||||
import com.pureix.easylocator.service.locatonService.broadcastReceiver.LocationSender;
|
import com.pureix.easylocator.service.locatonService.broadcastReceiver.LocationSender;
|
||||||
|
|
||||||
import java.util.Observable;
|
|
||||||
import java.util.Observer;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
import static com.pureix.easylocator.service.SmartLocationBusiness.smartLocationBusinessObservable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by MelDiSooQi on 1/28/2017.
|
* Created by MelDiSooQi on 1/28/2017.
|
||||||
*/
|
*/
|
||||||
|
|
@ -64,7 +57,9 @@ public class LocationService extends Service implements
|
||||||
private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
|
private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
|
||||||
|
|
||||||
private GoogleApiClient mGoogleApiClient;
|
private GoogleApiClient mGoogleApiClient;
|
||||||
private LocationReceiverListener locationReceiverListener;
|
private CustomSettingsLocation customSettingsLocation;
|
||||||
|
|
||||||
|
//private LocationReceiverListener locationReceiverListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class used for the client Binder. Because we know this service always
|
* Class used for the client Binder. Because we know this service always
|
||||||
|
|
@ -83,11 +78,21 @@ public class LocationService extends Service implements
|
||||||
return mBinder;
|
return mBinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
super.onCreate();
|
||||||
|
Log.e(TAG, "onCreate");
|
||||||
|
context = getApplicationContext();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
super.onStartCommand(intent, flags, startId);
|
super.onStartCommand(intent, flags, startId);
|
||||||
Log.e(TAG, "onStartCommand");
|
Log.e(TAG, "onStartCommand");
|
||||||
|
|
||||||
|
getIntentExtrasData(intent);
|
||||||
|
asOnCreate();
|
||||||
|
|
||||||
PowerManager mgr = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
PowerManager mgr = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -116,26 +121,62 @@ public class LocationService extends Service implements
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void getIntentExtrasData(Intent intent) {
|
||||||
public void onCreate() {
|
if(intent != null) {
|
||||||
super.onCreate();
|
Bundle extras = intent.getExtras();
|
||||||
Log.e(TAG, "onCreate");
|
if (extras != null) {
|
||||||
context = getApplicationContext();
|
String jsonCustomSettingsLocation = extras.getString(LocationServicesConstant.CUSTOM_SETTINGS_LOCATION);
|
||||||
|
|
||||||
senderHandler = new LocationSender(context,
|
customSettingsLocation = new Gson()
|
||||||
LocationBroadcast.class);
|
.fromJson(jsonCustomSettingsLocation, CustomSettingsLocation.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(customSettingsLocation == null)
|
||||||
|
{
|
||||||
|
createCustomSettingsLocation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private CustomSettingsLocation createCustomSettingsLocation() {
|
||||||
|
customSettingsLocation = new CustomSettingsLocation();
|
||||||
|
|
||||||
|
customSettingsLocation.setDetectedActivityType(-1);
|
||||||
|
customSettingsLocation.setDetectedActivityProvider("Normal");
|
||||||
|
|
||||||
|
customSettingsLocation.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
|
||||||
|
customSettingsLocation.setInterval(Constants.UPDATE_INTERVAL);
|
||||||
|
customSettingsLocation.setFastestInterval(Constants.FASTEST_INTERVAL);
|
||||||
|
customSettingsLocation.setSmallestDisplacement(0);
|
||||||
|
|
||||||
|
return customSettingsLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void asOnCreate(){
|
||||||
|
|
||||||
|
senderHandler = new LocationSender(context, LocationBroadcast.class);
|
||||||
|
|
||||||
mInProgress = false;
|
mInProgress = false;
|
||||||
// Create the LocationRequest object
|
// Create the LocationRequest object
|
||||||
mLocationRequest = LocationRequest.create();
|
mLocationRequest = LocationRequest.create();
|
||||||
|
|
||||||
// Use high accuracy
|
// Use high accuracy
|
||||||
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
|
mLocationRequest.setPriority(customSettingsLocation.getPriority());
|
||||||
// Set the update interval to 5 seconds
|
// Set the update interval to 5 seconds
|
||||||
mLocationRequest.setInterval(Constants.UPDATE_INTERVAL);
|
mLocationRequest.setInterval(customSettingsLocation.getInterval());
|
||||||
|
// Set the fastest update interval to 1 second
|
||||||
|
mLocationRequest.setFastestInterval(customSettingsLocation.getFastestInterval());
|
||||||
|
//update the location every some distance
|
||||||
|
mLocationRequest.setSmallestDisplacement(customSettingsLocation.getSmallestDisplacement());
|
||||||
|
|
||||||
|
// Use high accuracy
|
||||||
|
//mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
|
||||||
|
// Set the update interval to 5 seconds
|
||||||
|
//mLocationRequest.setInterval(Constants.UPDATE_INTERVAL);
|
||||||
// mLocationRequest.setInterval(1000);
|
// mLocationRequest.setInterval(1000);
|
||||||
// Set the fastest update interval to 1 second
|
// Set the fastest update interval to 1 second
|
||||||
// mLocationRequest.setFastestInterval(1000);
|
// mLocationRequest.setFastestInterval(1000);
|
||||||
mLocationRequest.setFastestInterval(Constants.FASTEST_INTERVAL);
|
//mLocationRequest.setFastestInterval(Constants.FASTEST_INTERVAL);
|
||||||
//update the location every some distance
|
//update the location every some distance
|
||||||
//mLocationRequest.setSmallestDisplacement(10);
|
//mLocationRequest.setSmallestDisplacement(10);
|
||||||
|
|
||||||
|
|
@ -260,10 +301,10 @@ public class LocationService extends Service implements
|
||||||
try {
|
try {
|
||||||
Location location = getLastLocation();
|
Location location = getLastLocation();
|
||||||
sendLocationToBroadcast(location);
|
sendLocationToBroadcast(location);
|
||||||
if(locationReceiverListener !=null) {
|
/*if(locationReceiverListener !=null) {
|
||||||
locationReceiverListener.getLastKnownLocation(location);
|
locationReceiverListener.getLastKnownLocation(location);
|
||||||
// locationReceiverListener.onLocationChanged(location);
|
// locationReceiverListener.onLocationChanged(location);
|
||||||
}
|
}*/
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
// Request location updates using static settings
|
// Request location updates using static settings
|
||||||
|
|
@ -448,9 +489,9 @@ public class LocationService extends Service implements
|
||||||
}
|
}
|
||||||
|
|
||||||
sendLocationToBroadcast(location);
|
sendLocationToBroadcast(location);
|
||||||
if(locationReceiverListener != null) {
|
// if(locationReceiverListener != null) {
|
||||||
locationReceiverListener.onLocationChanged(location);
|
// locationReceiverListener.onLocationChanged(location);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private CustomSettingsLocation getCustomSettingsLocationInLocalStorage() {
|
private CustomSettingsLocation getCustomSettingsLocationInLocalStorage() {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package com.pureix.easylocator.service.locatonService;
|
||||||
/**
|
/**
|
||||||
* Created by M.Hayle on 6/29/2016.
|
* Created by M.Hayle on 6/29/2016.
|
||||||
*/
|
*/
|
||||||
public class ServicesConstant
|
public class LocationServicesConstant
|
||||||
{
|
{
|
||||||
//==========================S Location Service=================================
|
//==========================S Location Service=================================
|
||||||
public final static String SERVICE_ID = "SERVICE_ID";
|
public final static String SERVICE_ID = "SERVICE_ID";
|
||||||
|
|
@ -23,4 +23,6 @@ public class ServicesConstant
|
||||||
public final static String BEARING = "BEARING";
|
public final static String BEARING = "BEARING";
|
||||||
public final static String SPEED = "SPEED";
|
public final static String SPEED = "SPEED";
|
||||||
//==========================E Location Service=================================
|
//==========================E Location Service=================================
|
||||||
|
|
||||||
|
public final static String CUSTOM_SETTINGS_LOCATION = "CUSTOM_SETTINGS_LOCATION";
|
||||||
}
|
}
|
||||||
|
|
@ -8,8 +8,7 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.pureix.easylocator.model.ObservableHandler;
|
import com.pureix.easylocator.model.ObservableHandler;
|
||||||
import com.pureix.easylocator.service.locatonService.Listener.LocationReceiverListener;
|
import com.pureix.easylocator.service.locatonService.LocationServicesConstant;
|
||||||
import com.pureix.easylocator.service.locatonService.ServicesConstant;
|
|
||||||
import com.pureix.easylocator.service.locatonService.bean.Location;
|
import com.pureix.easylocator.service.locatonService.bean.Location;
|
||||||
|
|
||||||
public class LocationBroadcast extends BroadcastReceiver
|
public class LocationBroadcast extends BroadcastReceiver
|
||||||
|
|
@ -25,19 +24,20 @@ public class LocationBroadcast extends BroadcastReceiver
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Bundle extras = intent.getExtras();
|
Bundle extras = intent.getExtras();
|
||||||
if(extras.getInt(ServicesConstant.SERVICE_ID) == ServicesConstant.SERVICE_ID_SEND_LOCATION)
|
if(extras.getInt(LocationServicesConstant.SERVICE_ID) ==
|
||||||
|
LocationServicesConstant.SERVICE_ID_SEND_LOCATION)
|
||||||
{
|
{
|
||||||
Location location;
|
Location location;
|
||||||
|
|
||||||
int USER_ID = extras.getInt (ServicesConstant.USER_ID);
|
int USER_ID = extras.getInt (LocationServicesConstant.USER_ID);
|
||||||
double latitude = extras.getDouble(ServicesConstant.LATITUDE);
|
double latitude = extras.getDouble(LocationServicesConstant.LATITUDE);
|
||||||
double longitude = extras.getDouble(ServicesConstant.LONGITUDE);
|
double longitude = extras.getDouble(LocationServicesConstant.LONGITUDE);
|
||||||
String locationProvider = extras.getString(ServicesConstant.LOCATION_PROVIDER);
|
String locationProvider = extras.getString(LocationServicesConstant.LOCATION_PROVIDER);
|
||||||
Float accuracy = extras.getFloat(ServicesConstant.ACCURACY);
|
Float accuracy = extras.getFloat(LocationServicesConstant.ACCURACY);
|
||||||
long time = extras.getLong(ServicesConstant.TIME);
|
long time = extras.getLong(LocationServicesConstant.TIME);
|
||||||
double altitude = extras.getDouble(ServicesConstant.ALTITUDE);
|
double altitude = extras.getDouble(LocationServicesConstant.ALTITUDE);
|
||||||
float bearing = extras.getFloat(ServicesConstant.BEARING);
|
float bearing = extras.getFloat(LocationServicesConstant.BEARING);
|
||||||
float speed = extras.getFloat(ServicesConstant.SPEED);
|
float speed = extras.getFloat(LocationServicesConstant.SPEED);
|
||||||
|
|
||||||
|
|
||||||
if(!isLocationInitialized) {
|
if(!isLocationInitialized) {
|
||||||
|
|
@ -58,9 +58,10 @@ public class LocationBroadcast extends BroadcastReceiver
|
||||||
+" USER_ID "+USER_ID;
|
+" USER_ID "+USER_ID;
|
||||||
Toast.makeText(context, "From BroadCast : "+s, Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "From BroadCast : "+s, Toast.LENGTH_SHORT).show();
|
||||||
// LoggerAndToastHandler.PrintToastMsg(s);
|
// LoggerAndToastHandler.PrintToastMsg(s);
|
||||||
}else if(extras.getInt(ServicesConstant.SERVICE_ID) == ServicesConstant.SERVICE_ID_SEND_JSON_LOCATION)
|
}else if(extras.getInt(LocationServicesConstant.SERVICE_ID) ==
|
||||||
|
LocationServicesConstant.SERVICE_ID_SEND_JSON_LOCATION)
|
||||||
{
|
{
|
||||||
String jsonLocation = extras.getString(ServicesConstant.JSON_LOCATION);
|
String jsonLocation = extras.getString(LocationServicesConstant.JSON_LOCATION);
|
||||||
|
|
||||||
android.location.Location location = new Gson()
|
android.location.Location location = new Gson()
|
||||||
.fromJson(jsonLocation, android.location.Location.class);
|
.fromJson(jsonLocation, android.location.Location.class);
|
||||||
|
|
@ -82,7 +83,7 @@ public class LocationBroadcast extends BroadcastReceiver
|
||||||
+" speed "+ kMeter
|
+" speed "+ kMeter
|
||||||
+" accuracy "+location.getAccuracy();
|
+" accuracy "+location.getAccuracy();
|
||||||
|
|
||||||
//Toast.makeText(context, "AFrom BroadCast : "+s, Toast.LENGTH_SHORT).show();
|
// Toast.makeText(context, "AFrom BroadCast : "+s, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package com.pureix.easylocator.service.locatonService.broadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import com.pureix.easylocator.service.locatonService.ServicesConstant;
|
import com.pureix.easylocator.service.locatonService.LocationServicesConstant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by MelDiSooQi on 7/16/2016.
|
* Created by MelDiSooQi on 7/16/2016.
|
||||||
|
|
@ -28,13 +28,13 @@ public class LocationSender
|
||||||
/*
|
/*
|
||||||
public void sendLocationToApp(int userID, double latitude, double longitude, String provider, float accuracy, long time)
|
public void sendLocationToApp(int userID, double latitude, double longitude, String provider, float accuracy, long time)
|
||||||
{
|
{
|
||||||
intent.putExtra(ServicesConstant.SERVICE_ID , ServicesConstant.SERVICE_ID_SEND_LOCATION);
|
intent.putExtra(LocationServicesConstant.SERVICE_ID , LocationServicesConstant.SERVICE_ID_SEND_LOCATION);
|
||||||
intent.putExtra(ServicesConstant.USER_ID , userID);
|
intent.putExtra(LocationServicesConstant.USER_ID , userID);
|
||||||
intent.putExtra(ServicesConstant.LATITUDE , latitude);
|
intent.putExtra(LocationServicesConstant.LATITUDE , latitude);
|
||||||
intent.putExtra(ServicesConstant.LONGITUDE , longitude);
|
intent.putExtra(LocationServicesConstant.LONGITUDE , longitude);
|
||||||
intent.putExtra(ServicesConstant.LOCATION_PROVIDER , provider);
|
intent.putExtra(LocationServicesConstant.LOCATION_PROVIDER , provider);
|
||||||
intent.putExtra(ServicesConstant.ACCURACY , accuracy);
|
intent.putExtra(LocationServicesConstant.ACCURACY , accuracy);
|
||||||
intent.putExtra(ServicesConstant.TIME , time);
|
intent.putExtra(LocationServicesConstant.TIME , time);
|
||||||
|
|
||||||
context.sendBroadcast(intent);
|
context.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
@ -42,56 +42,56 @@ public class LocationSender
|
||||||
|
|
||||||
public void sendLocationToApp(int userID, double latitude, double longitude, String provider, float accuracy, long time, double altitude, float bearing, float speed)
|
public void sendLocationToApp(int userID, double latitude, double longitude, String provider, float accuracy, long time, double altitude, float bearing, float speed)
|
||||||
{
|
{
|
||||||
intent.putExtra(ServicesConstant.SERVICE_ID , ServicesConstant.SERVICE_ID_SEND_LOCATION);
|
intent.putExtra(LocationServicesConstant.SERVICE_ID , LocationServicesConstant.SERVICE_ID_SEND_LOCATION);
|
||||||
intent.putExtra(ServicesConstant.USER_ID , userID);
|
intent.putExtra(LocationServicesConstant.USER_ID , userID);
|
||||||
intent.putExtra(ServicesConstant.LATITUDE , latitude);
|
intent.putExtra(LocationServicesConstant.LATITUDE , latitude);
|
||||||
intent.putExtra(ServicesConstant.LONGITUDE , longitude);
|
intent.putExtra(LocationServicesConstant.LONGITUDE , longitude);
|
||||||
intent.putExtra(ServicesConstant.LOCATION_PROVIDER , provider);
|
intent.putExtra(LocationServicesConstant.LOCATION_PROVIDER , provider);
|
||||||
intent.putExtra(ServicesConstant.ACCURACY , accuracy);
|
intent.putExtra(LocationServicesConstant.ACCURACY , accuracy);
|
||||||
intent.putExtra(ServicesConstant.TIME , time);
|
intent.putExtra(LocationServicesConstant.TIME , time);
|
||||||
intent.putExtra(ServicesConstant.ALTITUDE , altitude);
|
intent.putExtra(LocationServicesConstant.ALTITUDE , altitude);
|
||||||
intent.putExtra(ServicesConstant.BEARING , bearing);
|
intent.putExtra(LocationServicesConstant.BEARING , bearing);
|
||||||
intent.putExtra(ServicesConstant.SPEED , speed);
|
intent.putExtra(LocationServicesConstant.SPEED , speed);
|
||||||
|
|
||||||
context.sendBroadcast(intent);
|
context.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendLocationToApp(String userID, double latitude, double longitude, String provider, float accuracy, long time, double altitude, float bearing, float speed)
|
public void sendLocationToApp(String userID, double latitude, double longitude, String provider, float accuracy, long time, double altitude, float bearing, float speed)
|
||||||
{
|
{
|
||||||
intent.putExtra(ServicesConstant.SERVICE_ID , ServicesConstant.SERVICE_ID_SEND_LOCATION);
|
intent.putExtra(LocationServicesConstant.SERVICE_ID , LocationServicesConstant.SERVICE_ID_SEND_LOCATION);
|
||||||
intent.putExtra(ServicesConstant.USER_ID , userID);
|
intent.putExtra(LocationServicesConstant.USER_ID , userID);
|
||||||
intent.putExtra(ServicesConstant.LATITUDE , latitude);
|
intent.putExtra(LocationServicesConstant.LATITUDE , latitude);
|
||||||
intent.putExtra(ServicesConstant.LONGITUDE , longitude);
|
intent.putExtra(LocationServicesConstant.LONGITUDE , longitude);
|
||||||
intent.putExtra(ServicesConstant.LOCATION_PROVIDER , provider);
|
intent.putExtra(LocationServicesConstant.LOCATION_PROVIDER , provider);
|
||||||
intent.putExtra(ServicesConstant.ACCURACY , accuracy);
|
intent.putExtra(LocationServicesConstant.ACCURACY , accuracy);
|
||||||
intent.putExtra(ServicesConstant.TIME , time);
|
intent.putExtra(LocationServicesConstant.TIME , time);
|
||||||
intent.putExtra(ServicesConstant.ALTITUDE , altitude);
|
intent.putExtra(LocationServicesConstant.ALTITUDE , altitude);
|
||||||
intent.putExtra(ServicesConstant.BEARING , bearing);
|
intent.putExtra(LocationServicesConstant.BEARING , bearing);
|
||||||
intent.putExtra(ServicesConstant.SPEED , speed);
|
intent.putExtra(LocationServicesConstant.SPEED , speed);
|
||||||
|
|
||||||
context.sendBroadcast(intent);
|
context.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendLocationToApp(double latitude, double longitude, String provider, float accuracy, long time, double altitude, float bearing, float speed)
|
public void sendLocationToApp(double latitude, double longitude, String provider, float accuracy, long time, double altitude, float bearing, float speed)
|
||||||
{
|
{
|
||||||
intent.putExtra(ServicesConstant.SERVICE_ID , ServicesConstant.SERVICE_ID_SEND_LOCATION);
|
intent.putExtra(LocationServicesConstant.SERVICE_ID , LocationServicesConstant.SERVICE_ID_SEND_LOCATION);
|
||||||
intent.putExtra(ServicesConstant.LATITUDE , latitude);
|
intent.putExtra(LocationServicesConstant.LATITUDE , latitude);
|
||||||
intent.putExtra(ServicesConstant.LONGITUDE , longitude);
|
intent.putExtra(LocationServicesConstant.LONGITUDE , longitude);
|
||||||
intent.putExtra(ServicesConstant.LOCATION_PROVIDER , provider);
|
intent.putExtra(LocationServicesConstant.LOCATION_PROVIDER , provider);
|
||||||
intent.putExtra(ServicesConstant.ACCURACY , accuracy);
|
intent.putExtra(LocationServicesConstant.ACCURACY , accuracy);
|
||||||
intent.putExtra(ServicesConstant.TIME , time);
|
intent.putExtra(LocationServicesConstant.TIME , time);
|
||||||
intent.putExtra(ServicesConstant.ALTITUDE , altitude);
|
intent.putExtra(LocationServicesConstant.ALTITUDE , altitude);
|
||||||
intent.putExtra(ServicesConstant.BEARING , bearing);
|
intent.putExtra(LocationServicesConstant.BEARING , bearing);
|
||||||
intent.putExtra(ServicesConstant.SPEED , speed);
|
intent.putExtra(LocationServicesConstant.SPEED , speed);
|
||||||
|
|
||||||
context.sendBroadcast(intent);
|
context.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendLocationToApp(String jsonLocation)
|
public void sendLocationToApp(String jsonLocation)
|
||||||
{
|
{
|
||||||
intent.putExtra(ServicesConstant.SERVICE_ID , ServicesConstant
|
intent.putExtra(LocationServicesConstant.SERVICE_ID , LocationServicesConstant
|
||||||
.SERVICE_ID_SEND_JSON_LOCATION);
|
.SERVICE_ID_SEND_JSON_LOCATION);
|
||||||
intent.putExtra(ServicesConstant.JSON_LOCATION , jsonLocation);
|
intent.putExtra(LocationServicesConstant.JSON_LOCATION , jsonLocation);
|
||||||
|
|
||||||
context.sendBroadcast(intent);
|
context.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#Mon Dec 28 10:00:20 PST 2015
|
#Thu May 18 20:32:27 EET 2017
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue