From 7c3ff2d5cbfbfed43445ea4252fde0448a65dfc6 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 4 Jan 2012 22:07:47 +0100 Subject: [PATCH] Fix issue with background service --- .../net/osmand/plus/NavigationService.java | 31 --------------- .../OnNavigationServiceAlarmReceiver.java | 38 +++++++++++++++++++ .../osmand/plus/activities/MapActivity.java | 2 +- 3 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/OnNavigationServiceAlarmReceiver.java diff --git a/OsmAnd/src/net/osmand/plus/NavigationService.java b/OsmAnd/src/net/osmand/plus/NavigationService.java index 6f09f63cf2..c3cfb7ce29 100644 --- a/OsmAnd/src/net/osmand/plus/NavigationService.java +++ b/OsmAnd/src/net/osmand/plus/NavigationService.java @@ -200,8 +200,6 @@ public class NavigationService extends Service implements LocationListener { } - - @Override public void onProviderDisabled(String provider) { Toast.makeText(this, getString(R.string.off_router_service_no_gps_available), Toast.LENGTH_LONG).show(); @@ -220,33 +218,4 @@ public class NavigationService extends Service implements LocationListener { } - 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()); - } - } - - } } diff --git a/OsmAnd/src/net/osmand/plus/OnNavigationServiceAlarmReceiver.java b/OsmAnd/src/net/osmand/plus/OnNavigationServiceAlarmReceiver.java new file mode 100644 index 0000000000..daa9537be6 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/OnNavigationServiceAlarmReceiver.java @@ -0,0 +1,38 @@ +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(), 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()); + } + } + + } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 5ba9d39b9e..036b9cb854 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -693,7 +693,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 = SystemClock.elapsedRealtime(); + long now = System.currentTimeMillis(); // prevent ui hysterisis (check time interval for autozoom) if(Math.abs(mapView.getZoom() - z) > 1 || (lastTimeAutoZooming - now) > 6500){ lastTimeAutoZooming = now;