Merge branch 'batteryExclusion' of s416084/find-my-tutor-android into develop

This commit is contained in:
Mieszko Wrzeszczyński 2019-01-12 18:27:16 +00:00 committed by Gogs
commit b528ec68bb
7 changed files with 61 additions and 9 deletions

View File

@ -29,7 +29,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -13,6 +13,7 @@
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-feature android:name="android.hardware.location.gps" />

View File

@ -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

View File

@ -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();
}
}

View File

@ -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();
}
}
}
}

View File

@ -288,6 +288,8 @@
<string name="available_now">Dostępny teraz</string>
<string name="profile_activity_title">Profil użytkownika</string>
<string name="batter_exclusions_title">Uwaga</string>
<string name="batter_exclusions_message">Aby aplikacja była w pełni funkcjonalna, dodaj FMT do wyjątku w oszczędzaniu baterii</string>
<string name="never_logged_in">Nigdy</string>

View File

@ -456,5 +456,7 @@
<string name="user_status_label" translatable="false">Status</string>
<string name="available_now">Available now</string>
<string name="last_sign">Last seen</string>
<string name="batter_exclusions_message">To make app fully functional, add FMT to battery saving exclusions</string>
<string name="batter_exclusions_title">Please note</string>
<string name="never_logged_in">Never</string>
</resources>