From fae7a5f0fe25967884290195ea392bd085a21347 Mon Sep 17 00:00:00 2001 From: Domagalski Date: Sat, 12 Jan 2019 14:56:54 +0100 Subject: [PATCH] pop up with battery exc + transaltions --- .idea/misc.xml | 2 +- app/src/main/AndroidManifest.xml | 1 + .../wmi/findmytutor/activity/MapActivity.java | 3 +- .../findmytutor/activity/StartupActivity.java | 15 ++++++- .../uam/wmi/findmytutor/utils/MapUtils.java | 45 ++++++++++++++++--- app/src/main/res/values-pl/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 7 files changed, 61 insertions(+), 9 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index b0c7b20..dc44dda 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -29,7 +29,7 @@ - + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9f3de6a..60022b5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,6 +13,7 @@ + diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java index c30cbe5..b9ab207 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java @@ -8,6 +8,7 @@ import android.content.Context; import android.location.Location; import android.os.Bundle; import android.os.Handler; +import android.os.PowerManager; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.text.TextUtils; @@ -134,7 +135,6 @@ public class MapActivity extends BaseActivity }; - selectLocationButton = findViewById(R.id.select_location_button); removeLocationButton = findViewById(R.id.remove_location_button); mapView = findViewById(R.id.mapView); @@ -145,6 +145,7 @@ public class MapActivity extends BaseActivity handleBackgroundTaskLifeCycle(); manualLocationUtils = new ManualLocationUtils(MapActivity.this); approximatedLocalization = new ApproximatedLocalization(MapUtils.loadJsonFromAsset(getApplicationContext(), "building.geojson")); + MapUtils.BatteryOptimizationsExceptionCheck(this); } @Override diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/StartupActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/StartupActivity.java index 833483f..e988305 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/StartupActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/StartupActivity.java @@ -1,17 +1,27 @@ package com.uam.wmi.findmytutor.activity; import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; +import android.net.Uri; +import android.os.Build; import android.os.Bundle; +import android.os.PowerManager; +import android.provider.Settings; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.FragmentManager; import android.support.v7.app.AppCompatActivity; import android.util.DisplayMetrics; import android.widget.ScrollView; import android.widget.Toast; +import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.utils.LocaleHelper; import com.uam.wmi.findmytutor.utils.PrefUtils; @@ -38,7 +48,6 @@ public class StartupActivity extends AppCompatActivity { } super.onCreate(savedInstanceState); - } @Override @@ -51,4 +60,8 @@ public class StartupActivity extends AppCompatActivity { finish(); } + + } + + diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/MapUtils.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/MapUtils.java index cabb845..200da07 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/utils/MapUtils.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/MapUtils.java @@ -1,8 +1,15 @@ package com.uam.wmi.findmytutor.utils; import android.animation.TypeEvaluator; +import android.app.AlertDialog; import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; import android.location.Location; +import android.net.Uri; +import android.os.Build; +import android.os.PowerManager; +import android.provider.Settings; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; @@ -10,12 +17,14 @@ import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.uam.wmi.findmytutor.R; import java.io.IOException; import java.io.InputStream; -import static com.uam.wmi.findmytutor.utils.Const.outsideLongitudeRange; +import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext; import static com.uam.wmi.findmytutor.utils.Const.outsideLatitudeRange; +import static com.uam.wmi.findmytutor.utils.Const.outsideLongitudeRange; public class MapUtils { @@ -41,8 +50,8 @@ public class MapUtils { // Map Bounds Area public static void setZoom(MapboxMap mapboxMap, Integer zoom) { - makeNewCamera(mapboxMap, 52.466799, 16.927002, zoom, 0, 0, 1000); - mapboxMap.setMinZoomPreference(16); // TODO export to map config + makeNewCamera(mapboxMap, 52.466799, 16.927002, zoom, 0, 0, 1000); + mapboxMap.setMinZoomPreference(16); // TODO export to map config } public static void makeNewCamera(MapboxMap mapboxMap, double lat, double lon, int zoomParam, int bearingParam, int tiltParam, int duration) { @@ -73,11 +82,11 @@ public class MapUtils { } } - public static Boolean checkIfCoordinateIsValid(Location coordinate){ - return outsideLatitudeRange.contains(coordinate.getLatitude()) && outsideLongitudeRange.contains(coordinate.getLongitude()); + public static Boolean checkIfCoordinateIsValid(Location coordinate) { + return outsideLatitudeRange.contains(coordinate.getLatitude()) && outsideLongitudeRange.contains(coordinate.getLongitude()); } - public static Boolean checkIfCoordinateIsValid(Double latitude, Double longitude){ + public static Boolean checkIfCoordinateIsValid(Double latitude, Double longitude) { return Const.buildingLatitudeRange.contains(latitude) && Const.buildingLongitudeRange.contains(longitude); } @@ -97,4 +106,28 @@ public class MapUtils { } } + public static void BatteryOptimizationsExceptionCheck(Context context) { + PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (!pm.isIgnoringBatteryOptimizations(context.getPackageName())) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(R.string.batter_exclusions_title); + builder.setMessage(R.string.batter_exclusions_message) + .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + Intent intent = new Intent(); + intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); + intent.setData(Uri.parse("package:" + getApplicationContext().getPackageName())); + context.startActivity(intent); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // User cancelled the dialog + } + }).show(); + } + } + } + } diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index db0dcb7..d900396 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -288,6 +288,8 @@ Dostępny teraz Profil użytkownika + Uwaga + Aby aplikacja była w pełni funkcjonalna, dodaj FMT do wyjątku w oszczędzaniu baterii diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7fa8adc..f3afc42 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -456,4 +456,6 @@ Status Available now Last seen + To make app fully functional, add FMT to battery saving exclusions + Please note