Add battery saver

This commit is contained in:
Mieszko Wrzeszczyński 2019-01-07 09:46:14 +01:00
parent aaca6c008e
commit d0b714731b
4 changed files with 8 additions and 4 deletions

View File

@ -10,7 +10,7 @@ android {
applicationId "com.uam.wmi.findmytutor"
minSdkVersion 22
targetSdkVersion 27
versionCode 42
versionCode 43
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true

View File

@ -199,6 +199,8 @@ public abstract class BaseActivity
}
public void stopBackgroundLocalizationTask() {
PrefUtils.storeEnableSharingLocalization(getApplicationContext(), false);
Intent stopIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
stopIntent.putExtra("request_stop", true);
@ -208,6 +210,7 @@ public abstract class BaseActivity
public void startBackgroundLocalizationTask() {
checkPermissions();
PrefUtils.storeEnableSharingLocalization(getApplicationContext(), true);
Intent startIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
startIntent.putExtra("notify_interval", onlineBackgroundLocationInterval);

View File

@ -207,7 +207,8 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
/** Sharing level list **/
locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
((MapActivity) getActivity()).stopBackgroundLocalizationTask();
((MapActivity) getActivity()).startBackgroundLocalizationTask();
PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) newValue)));
if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) {

View File

@ -168,7 +168,7 @@ public class BackgroundLocalizationService extends Service {
if (saveMode != 0) {
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
} else {
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
mLocationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);
}
mLocationRequest.setFastestInterval(notify_interval);
@ -293,7 +293,7 @@ public class BackgroundLocalizationService extends Service {
latitude = location.getLatitude();
longitude = location.getLongitude();
altitude = location.getAltitude();
Log.e(TAG,"TASK" + latitude + " " + longitude);
approximatedLocalization = new ApproximatedLocalization(MapUtils.loadJsonFromAsset(getApplicationContext(), "building.geojson"));
approximatedBuildingPart = approximatedLocalization.getNameOfBuildingPart(Point.fromLngLat(longitude, latitude));
}