Update gps location lost message
This commit is contained in:
parent
b7d7d146fb
commit
f2c5979e1e
5 changed files with 66 additions and 49 deletions
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="net.osmand.plus" android:installLocation="auto" android:versionName="0.7.0" android:versionCode="43">
|
||||
package="net.osmand.plus" android:installLocation="auto" android:versionName="0.7.0" android:versionCode="44">
|
||||
<meta-data android:name="com.google.android.backup.api_key"
|
||||
android:value="AEdPqrEAAAAIqF3tNGT66etVBn_vgzpfAY1wmIzKV1Ss6Ku-2A" />
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
||||
|
|
Binary file not shown.
|
@ -21,6 +21,7 @@ import android.os.Binder;
|
|||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.os.PowerManager;
|
||||
import android.os.SystemClock;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
|
@ -33,6 +34,8 @@ public class NavigationService extends Service implements LocationListener {
|
|||
}
|
||||
private final static int NOTIFICATION_SERVICE_ID = 1;
|
||||
public final static String OSMAND_STOP_SERVICE_ACTION = "OSMAND_STOP_SERVICE_ACTION"; //$NON-NLS-1$
|
||||
private static final int LOST_LOCATION_MSG_ID = 10;
|
||||
private static final long LOST_LOCATION_CHECK_DELAY = 20000;
|
||||
|
||||
private NavigationServiceBinder binder = new NavigationServiceBinder();
|
||||
|
||||
|
@ -99,7 +102,7 @@ public class NavigationService extends Service implements LocationListener {
|
|||
if(isContinuous()){
|
||||
// request location updates
|
||||
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||
locationManager.requestLocationUpdates(serviceOffProvider, 1000, 0, NavigationService.this);
|
||||
locationManager.requestLocationUpdates(serviceOffProvider, 0, 0, NavigationService.this);
|
||||
} else {
|
||||
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
||||
pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(this, OnNavigationServiceAlarmReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
@ -171,7 +174,23 @@ public class NavigationService extends Service implements LocationListener {
|
|||
if (lock.isHeld()) {
|
||||
lock.release();
|
||||
}
|
||||
} else {
|
||||
// if continuous notify about lost location
|
||||
if (routingHelper.isFollowingMode() && routingHelper.getLeftDistance() > 0) {
|
||||
Message msg = Message.obtain(handler, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (routingHelper.getLeftDistance() > 0 && !settings.MAP_ACTIVITY_ENABLED.get()) {
|
||||
routingHelper.getVoiceRouter().gpsLocationLost();
|
||||
}
|
||||
}
|
||||
});
|
||||
msg.what = LOST_LOCATION_MSG_ID;
|
||||
handler.removeMessages(LOST_LOCATION_MSG_ID);
|
||||
handler.sendMessageDelayed(msg, LOST_LOCATION_CHECK_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(),
|
||||
location.getSpeed(), location.getAccuracy(), location.getTime(), settings);
|
||||
if(routingHelper.isFollowingMode()){
|
||||
|
@ -200,4 +219,34 @@ public class NavigationService extends Service implements LocationListener {
|
|||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||
}
|
||||
|
||||
|
||||
public static class OnNavigationServiceAlarmReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final WakeLock lock = getLock(context);
|
||||
final NavigationService service = ((OsmandApplication) context.getApplicationContext()).getNavigationService();
|
||||
// do not do nothing
|
||||
if (lock.isHeld() || service == null) {
|
||||
return;
|
||||
}
|
||||
//
|
||||
lock.acquire();
|
||||
// request location updates
|
||||
final LocationManager locationManager = (LocationManager) service.getSystemService(Context.LOCATION_SERVICE);
|
||||
locationManager.requestLocationUpdates(service.getServiceOffProvider(), 0, 0, service);
|
||||
if (service.getServiceOffInterval() > service.getServiceError()) {
|
||||
service.getHandler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// if lock is not anymore held
|
||||
if (lock.isHeld()) {
|
||||
lock.release();
|
||||
locationManager.removeUpdates(service);
|
||||
}
|
||||
}
|
||||
}, service.getServiceError());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
import net.osmand.plus.activities.OsmandApplication;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.location.LocationManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
|
||||
public class OnNavigationServiceAlarmReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final WakeLock lock = NavigationService.getLock(context);
|
||||
final NavigationService service = ((OsmandApplication) context.getApplicationContext()).getNavigationService();
|
||||
// do not do nothing
|
||||
if (lock.isHeld() || service == null) {
|
||||
return;
|
||||
}
|
||||
//
|
||||
lock.acquire();
|
||||
// request location updates
|
||||
final LocationManager locationManager = (LocationManager) service.getSystemService(Context.LOCATION_SERVICE);
|
||||
locationManager.requestLocationUpdates(service.getServiceOffProvider(), 1000, 0, service);
|
||||
if (service.getServiceOffInterval() > service.getServiceError()) {
|
||||
service.getHandler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// if lock is not anymore held
|
||||
if (lock.isHeld()) {
|
||||
lock.release();
|
||||
locationManager.removeUpdates(service);
|
||||
}
|
||||
}
|
||||
}, service.getServiceError());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -47,6 +47,7 @@ import android.hardware.Sensor;
|
|||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.location.GpsStatus;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
|
@ -59,6 +60,7 @@ import android.os.Bundle;
|
|||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.SystemClock;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
|
@ -80,8 +82,8 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
private static final String GPS_STATUS_COMPONENT = "com.eclipsim.gpsstatus2"; //$NON-NLS-1$
|
||||
|
||||
// stupid error but anyway hero 2.1 : always lost gps signal (temporarily unavailable) for timeout = 2000
|
||||
private static final int GPS_TIMEOUT_REQUEST = 1000;
|
||||
private static final int GPS_DIST_REQUEST = 5;
|
||||
private static final int GPS_TIMEOUT_REQUEST = 0;
|
||||
private static final int GPS_DIST_REQUEST = 0;
|
||||
// use only gps (not network) for 12 seconds
|
||||
private static final int USE_ONLY_GPS_INTERVAL = 12000;
|
||||
|
||||
|
@ -672,8 +674,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
@Override
|
||||
public void run() {
|
||||
if (routingHelper.getLeftDistance() > 0 && settings.MAP_ACTIVITY_ENABLED.get()) {
|
||||
// TODO temporary disable
|
||||
// routingHelper.getVoiceRouter().gpsLocationLost();
|
||||
routingHelper.getVoiceRouter().gpsLocationLost();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -689,7 +690,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
if(settings.AUTO_ZOOM_MAP.get() && location.hasSpeed()){
|
||||
int z = defineZoomFromSpeed(location.getSpeed(), mapView.getZoom());
|
||||
if(mapView.getZoom() != z && !mapView.mapIsAnimating()){
|
||||
long now = System.currentTimeMillis();
|
||||
long now = SystemClock.elapsedRealtime();
|
||||
// prevent ui hysterisis (check time interval for autozoom)
|
||||
if(Math.abs(mapView.getZoom() - z) > 1 || (lastTimeAutoZooming - now) > 6500){
|
||||
lastTimeAutoZooming = now;
|
||||
|
@ -801,6 +802,8 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private LocationListener gpsListener = new LocationListener(){
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
|
@ -829,10 +832,13 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||
if (LocationProvider.OUT_OF_SERVICE == status) {
|
||||
// do not use it in routing
|
||||
if (service.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
|
||||
if (LocationProvider.TEMPORARILY_UNAVAILABLE == status) {
|
||||
if(routingHelper.isFollowingMode() && routingHelper.getLeftDistance() > 0){
|
||||
routingHelper.getVoiceRouter().gpsLocationLost();
|
||||
}
|
||||
} else if (LocationProvider.OUT_OF_SERVICE == status) {
|
||||
if(routingHelper.isFollowingMode() && routingHelper.getLeftDistance() > 0){
|
||||
routingHelper.getVoiceRouter().gpsLocationLost();
|
||||
}
|
||||
} else if (LocationProvider.AVAILABLE == status) {
|
||||
// Do not remove right now network listener
|
||||
|
|
Loading…
Reference in a new issue