jenkins-bot has submitted this change and it was merged.
Change subject: Make sure that a new location is "better" than the previous one.
......................................................................
Make sure that a new location is "better" than the previous one.
Change-Id: I64fbd0c41f828cf82de92698be55420c642cbbf9
---
M wikipedia/src/main/java/org/wikipedia/nearby/NearbyActivity.java
1 file changed, 60 insertions(+), 0 deletions(-)
Approvals:
BearND: Looks good to me, approved
jenkins-bot: Verified
diff --git a/wikipedia/src/main/java/org/wikipedia/nearby/NearbyActivity.java
b/wikipedia/src/main/java/org/wikipedia/nearby/NearbyActivity.java
index ef46eea..9e3e007 100644
--- a/wikipedia/src/main/java/org/wikipedia/nearby/NearbyActivity.java
+++ b/wikipedia/src/main/java/org/wikipedia/nearby/NearbyActivity.java
@@ -220,6 +220,9 @@
}
private void makeUseOfNewLocation(Location location) {
+ if (!isBetterLocation(location, lastLocation)) {
+ return;
+ }
nextLocation = location;
if (lastLocation == null || (refreshing && getDistance(lastLocation)
>= MIN_DISTANCE_METERS)) {
@@ -250,6 +253,63 @@
}
}
+ /** Determines whether one Location reading is better than the current
Location fix.
+ * lifted from
http://developer.android.com/guide/topics/location/strategies.html
+ * @param location The new Location that you want to evaluate
+ * @param currentBestLocation The current Location fix, to which you want
to compare the new one
+ */
+ protected boolean isBetterLocation(Location location, Location
currentBestLocation) {
+ if (currentBestLocation == null) {
+ // A new location is always better than no location
+ return true;
+ }
+
+ // Check whether the new location fix is newer or older
+ final int twoMinutes = 1000 * 60 * 2;
+ final int accuracyThreshold = 200;
+ long timeDelta = location.getTime() - currentBestLocation.getTime();
+ boolean isSignificantlyNewer = timeDelta > twoMinutes;
+ boolean isSignificantlyOlder = timeDelta < -twoMinutes;
+ 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;
+ boolean isMoreAccurate = accuracyDelta < 0;
+ boolean isSignificantlyLessAccurate = accuracyDelta >
accuracyThreshold;
+
+ // Check if the old and new location are from the same provider
+ boolean isFromSameProvider = isSameProvider(location.getProvider(),
+
currentBestLocation.getProvider());
+
+ // Determine location quality using a combination of timeliness and
accuracy
+ if (isMoreAccurate) {
+ return true;
+ } else if (isNewer && !isLessAccurate) {
+ return true;
+ } else if (isNewer && !isSignificantlyLessAccurate &&
isFromSameProvider) {
+ return true;
+ }
+ return false;
+ }
+
+ /** Checks whether two providers are the same */
+ private boolean isSameProvider(String provider1, String provider2) {
+ if (provider1 == null) {
+ return provider2 == null;
+ }
+ return provider1.equals(provider2);
+ }
+
private void showNearbyPages(List<NearbyPage> result) {
nearbyList.setEmptyView(nearbyEmptyContainer);
lastLocation = nextLocation;
--
To view, visit https://gerrit.wikimedia.org/r/160509
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I64fbd0c41f828cf82de92698be55420c642cbbf9
Gerrit-PatchSet: 3
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits