Сравнить коммиты
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
1b0559c98a | ||
|
|
2e0e7ea453 | ||
|
|
ac6d677ff4 |
@@ -9,8 +9,8 @@ android {
|
|||||||
buildConfigField "boolean", "HIDDEN_APP", "false"
|
buildConfigField "boolean", "HIDDEN_APP", "false"
|
||||||
minSdkVersion 15
|
minSdkVersion 15
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 51
|
versionCode 52
|
||||||
versionName '5.14'
|
versionName '5.15'
|
||||||
}
|
}
|
||||||
|
|
||||||
lintOptions {
|
lintOptions {
|
||||||
|
|||||||
@@ -20,13 +20,11 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.location.Criteria;
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationListener;
|
import android.location.LocationListener;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Looper;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -72,31 +70,22 @@ public class PositionProvider implements LocationListener {
|
|||||||
public void startUpdates() {
|
public void startUpdates() {
|
||||||
try {
|
try {
|
||||||
locationManager.requestLocationUpdates(
|
locationManager.requestLocationUpdates(
|
||||||
distance > 0 || angle > 0 ? MINIMUM_INTERVAL : interval, 0,
|
getProvider(preferences.getString(MainFragment.KEY_ACCURACY, "medium")),
|
||||||
getCriteria(preferences.getString(MainFragment.KEY_ACCURACY, "medium")),
|
distance > 0 || angle > 0 ? MINIMUM_INTERVAL : interval, 0, this);
|
||||||
this, Looper.myLooper());
|
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
|
Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Criteria getCriteria(String accuracy) {
|
public static String getProvider(String accuracy) {
|
||||||
Criteria criteria = new Criteria();
|
|
||||||
switch (accuracy) {
|
switch (accuracy) {
|
||||||
case "high":
|
case "high":
|
||||||
criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
|
return LocationManager.GPS_PROVIDER;
|
||||||
criteria.setPowerRequirement(Criteria.POWER_HIGH);
|
|
||||||
break;
|
|
||||||
case "low":
|
case "low":
|
||||||
criteria.setHorizontalAccuracy(Criteria.ACCURACY_LOW);
|
return LocationManager.PASSIVE_PROVIDER;
|
||||||
criteria.setPowerRequirement(Criteria.POWER_LOW);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
criteria.setHorizontalAccuracy(Criteria.ACCURACY_MEDIUM);
|
return LocationManager.NETWORK_PROVIDER;
|
||||||
criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return criteria;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -108,15 +108,15 @@ public class ShortcutActivity extends AppCompatActivity {
|
|||||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
|
||||||
Criteria criteria = PositionProvider.getCriteria(
|
String provider = PositionProvider.getProvider(
|
||||||
preferences.getString(MainFragment.KEY_ACCURACY, "medium"));
|
preferences.getString(MainFragment.KEY_ACCURACY, "medium"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, true));
|
Location location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
sendAlarmLocation(location);
|
sendAlarmLocation(location);
|
||||||
} else {
|
} else {
|
||||||
locationManager.requestSingleUpdate(criteria, new LocationListener() {
|
locationManager.requestSingleUpdate(provider, new LocationListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
sendAlarmLocation(location);
|
sendAlarmLocation(location);
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user