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" applicationId "com.uam.wmi.findmytutor"
minSdkVersion 22 minSdkVersion 22
targetSdkVersion 27 targetSdkVersion 27
versionCode 42 versionCode 43
versionName "1.0.0" versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true

View File

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

View File

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

View File

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