[yopme] Don't serialize m_location. We compare them by getElapsedRealtimeNanos().

This commit is contained in:
vng 2013-09-15 12:52:25 +03:00 committed by Alex Zolotarev
parent a3485748da
commit d674b90a2f
4 changed files with 19 additions and 20 deletions

View file

@ -47,14 +47,14 @@ public class LocationRequester implements Handler.Callback
*/
public static boolean isFirstOneBetterLocation(Location firstLoc, Location secondLoc)
{
if (firstLoc == null)
return false;
if (secondLoc == null)
{
// A new location is always better than no location
return true;
}
// Check whether the new location fix is newer or older
final long timeDelta = (firstLoc.getElapsedRealtimeNanos() - secondLoc.getElapsedRealtimeNanos())/1000;
long timeDelta = firstLoc.getElapsedRealtimeNanos() - secondLoc.getElapsedRealtimeNanos();
timeDelta /= 1000;
final boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
final boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
final boolean isNewer = timeDelta > 0;
@ -71,15 +71,14 @@ public class LocationRequester implements Handler.Callback
// Check whether the new location fix is more or less accurate
final int accuracyDelta = (int) (firstLoc.getAccuracy() - secondLoc.getAccuracy());
// Relative diff, not absolute
// Relative difference, not absolute
final boolean almostAsAccurate = Math.abs(accuracyDelta) <= 0.1*secondLoc.getAccuracy();
final boolean isMoreAccurate = accuracyDelta < 0;
final boolean isSignificantlyLessAccurate = accuracyDelta > 200;
// Check if the old and new location are from the same provider
final boolean isFromSameProvider = isSameProvider(firstLoc.getProvider(),
secondLoc.getProvider());
final boolean isFromSameProvider = isSameProvider(firstLoc.getProvider(), secondLoc.getProvider());
// Determine location quality using a combination of timeliness and accuracy
if (isMoreAccurate)
@ -88,6 +87,7 @@ public class LocationRequester implements Handler.Callback
return true;
else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider)
return true;
return false;
}

View file

@ -42,7 +42,6 @@ public class BackscreenActivity extends BSActivity
public final static String EXTRA_ZOOM = AUTHORITY + ".zoom";
public final static String EXTRA_LOCATION = AUTHORITY + ".location";
public enum Mode
{
LOCATION,
@ -52,12 +51,13 @@ public class BackscreenActivity extends BSActivity
private CharSequence mMessage;
private Bitmap mBitmap;
// @Save to state
private MWMPoint mPoint;
private Mode mMode;
/// @name Save to state.
//@{
private MWMPoint mPoint = null;
private Mode mMode = Mode.LOCATION;
private double mZoomLevel = MapDataProvider.ZOOM_DEFAULT;
private Location mLocation;
// @
private Location mLocation = null;
//@}
protected View mView;
protected ImageView mMapView;
@ -111,6 +111,7 @@ public class BackscreenActivity extends BSActivity
protected void onBSPause()
{
super.onBSPause();
mLocationManager.removeUpdates(getLocationPendingIntent(this));
mHandler.removeCallbacks(mInvalidateDrawable);
}
@ -132,9 +133,10 @@ public class BackscreenActivity extends BSActivity
if (savedInstanceState == null)
return;
// Do not save and restore m_location! It's compared by getElapsedRealtimeNanos().
mPoint = (MWMPoint) savedInstanceState.getSerializable(EXTRA_POINT);
mMode = (Mode) savedInstanceState.getSerializable(EXTRA_MODE);
mLocation = (Location) savedInstanceState.getParcelable(EXTRA_LOCATION);
mZoomLevel = savedInstanceState.getDouble(EXTRA_ZOOM);
}
@ -145,7 +147,6 @@ public class BackscreenActivity extends BSActivity
outState.putSerializable(EXTRA_POINT, mPoint);
outState.putSerializable(EXTRA_MODE, mMode);
outState.putParcelable(EXTRA_LOCATION, mLocation);
outState.putDouble(EXTRA_ZOOM, mZoomLevel);
}
@ -187,10 +188,10 @@ public class BackscreenActivity extends BSActivity
mPoint = (MWMPoint) intent.getSerializableExtra(EXTRA_POINT);
mZoomLevel = intent.getDoubleExtra(EXTRA_ZOOM, MapDataProvider.COMFORT_ZOOM);
requestLocationUpdate();
updateData();
invalidate();
requestLocationUpdate();
}
}

View file

@ -10,5 +10,5 @@ public interface MapDataProvider
public final static double COMFORT_ZOOM = 17;
MapData getMyPositionData(double lat, double lon, double zoom);
MapData getPOIData(MWMPoint poi, double zoom, boolean myLocationDetected ,double myLat, double myLon);
MapData getPOIData(MWMPoint poi, double zoom, boolean myLocationDetected, double myLat, double myLon);
}

View file

@ -26,9 +26,7 @@ public class MapRenderer implements MapDataProvider
static public MapRenderer GetRenderer()
{
if (mRenderer == null)
{
mRenderer = new MapRenderer(360, 640);
}
return mRenderer;
}