From 581483e4ca8f19a63785af899bdd35491af9aa72 Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Mon, 19 Feb 2018 23:18:57 +0300 Subject: [PATCH] Add new location change states --- .../location/LocationServiceManager.java | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java b/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java index 80c8b970e..9527d7000 100644 --- a/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java +++ b/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java @@ -94,10 +94,10 @@ public class LocationServiceManager implements LocationListener { } } - protected boolean isBetterLocation(Location location, Location currentBestLocation) { + protected LocationChangeType isBetterLocation(Location location, Location currentBestLocation) { if (currentBestLocation == null) { // A new location is always better than no location - return true; + return LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED; } // Check whether the new location fix is newer or older @@ -106,15 +106,6 @@ public class LocationServiceManager implements LocationListener { boolean isSignificantlyOlder = timeDelta < -MIN_LOCATION_UPDATE_REQUEST_TIME_IN_MILLIS; boolean isNewer = timeDelta > 0; - // If it's been more than two minutes since the current location, use the new location - // because the user has likely moved - if (isSignificantlyNewer) { - return true; - // If the new location is more than two minutes older, it must be worse - } else if (isSignificantlyOlder) { - return false; - } - // Check whether the new location fix is more or less accurate int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy()); boolean isLessAccurate = accuracyDelta > 0; @@ -125,25 +116,31 @@ public class LocationServiceManager implements LocationListener { boolean isFromSameProvider = isSameProvider(location.getProvider(), currentBestLocation.getProvider()); - float[] results = new float[5]; - Location.distanceBetween( - currentBestLocation.getLatitude(), - currentBestLocation.getLongitude(), - location.getLatitude(), - location.getLongitude(), - results); + float[] results = new float[5]; + Location.distanceBetween( + currentBestLocation.getLatitude(), + currentBestLocation.getLongitude(), + location.getLatitude(), + location.getLongitude(), + results); - if (isSignificantlyNewer - || isMoreAccurate - || (isNewer && !isLessAccurate) - || (isNewer && !isSignificantlyLessAccurate && isFromSameProvider)) { - Log.d("deneme","distance:"+results[0]); - return true; - // If the new location is more than two minutes older, it must be worse - } else{ - Log.d("deneme","distance:"+results[0]); - return false; - } + // If it's been more than two minutes since the current location, use the new location + // because the user has likely moved + if (isSignificantlyNewer + || isMoreAccurate + || (isNewer && !isLessAccurate) + || (isNewer && !isSignificantlyLessAccurate && isFromSameProvider)) { + Log.d("deneme","distance:"+results[0]); + if (results[0] < 1000) { // Means change is smaller than 1000 meter + return LocationChangeType.LOCATION_SLIGHTLY_CHANGED; + } else { + return LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED; + } + // If the new location is more than two minutes older, it must be worse + } else{ + Log.d("deneme","distance:"+results[0]); + return LocationChangeType.LOCATION_NOT_CHANGED; + } } @@ -206,4 +203,10 @@ public class LocationServiceManager implements LocationListener { public void onProviderDisabled(String provider) { Timber.d("Provider %s disabled", provider); } + + public enum LocationChangeType{ + LOCATION_SIGNIFICANTLY_CHANGED, + LOCATION_SLIGHTLY_CHANGED, + LOCATION_NOT_CHANGED + } }