From 783f218706c1c6236746985a32830b9174dfdc1a Mon Sep 17 00:00:00 2001 From: misaochan Date: Fri, 5 Feb 2016 15:50:59 +1300 Subject: [PATCH 1/6] Added CheckBoxPreference in xml --- commons/res/xml/preferences.xml | 5 +++++ .../main/java/fr/free/nrw/commons/upload/GPSExtractor.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/commons/res/xml/preferences.xml b/commons/res/xml/preferences.xml index 802e60b6d..88c2e5b9b 100644 --- a/commons/res/xml/preferences.xml +++ b/commons/res/xml/preferences.xml @@ -7,6 +7,11 @@ android:title="@string/preference_license" android:defaultValue="CC BY-SA" /> + diff --git a/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java b/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java index ba04b2222..91c023f82 100644 --- a/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java +++ b/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java @@ -54,8 +54,8 @@ public class GPSExtractor { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider = locationManager.getBestProvider(criteria, true); + myLocationListener = new MyLocationListener(); - locationManager.requestLocationUpdates(provider, 400, 1, myLocationListener); Location location = locationManager.getLastKnownLocation(provider); From f7c5796d70bfc9fda57fedae19c545056fa48543 Mon Sep 17 00:00:00 2001 From: misaochan Date: Fri, 5 Feb 2016 16:34:00 +1300 Subject: [PATCH 2/6] Minor changes --- commons/res/xml/preferences.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commons/res/xml/preferences.xml b/commons/res/xml/preferences.xml index 88c2e5b9b..23fc30f5d 100644 --- a/commons/res/xml/preferences.xml +++ b/commons/res/xml/preferences.xml @@ -10,7 +10,7 @@ From 5492aa7551f473363720442d77b6376fc91794c4 Mon Sep 17 00:00:00 2001 From: misaochan Date: Fri, 5 Feb 2016 18:00:10 +1300 Subject: [PATCH 3/6] Implement check for gpsPref --- .../fr/free/nrw/commons/upload/GPSExtractor.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java b/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java index 91c023f82..6528cadb7 100644 --- a/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java +++ b/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java @@ -2,18 +2,22 @@ package fr.free.nrw.commons.upload; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.media.ExifInterface; import android.os.Bundle; +import android.preference.PreferenceManager; import android.provider.Settings; import android.util.Log; import android.widget.Toast; import java.io.IOException; +import fr.free.nrw.commons.SettingsActivity; + public class GPSExtractor { @@ -30,6 +34,13 @@ public class GPSExtractor { this.context = context; } + private boolean gpsPreferenceEnabled() { + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); + boolean gpsPref = sharedPref.getBoolean("allowGps", false); + Log.d(TAG, "Gps pref set to: " + gpsPref); + return gpsPref; + } + //Extract GPS coords of image public String getCoords() { @@ -51,6 +62,9 @@ public class GPSExtractor { imageCoordsExists = false; Log.d(TAG, "Picture has no GPS info"); + //Check what user's preference is for automatic location detection + boolean gpsPrefEnabled = gpsPreferenceEnabled(); + LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider = locationManager.getBestProvider(criteria, true); From 11e291cb41fcc228e6014e55daa210533ca26d72 Mon Sep 17 00:00:00 2001 From: misaochan Date: Fri, 5 Feb 2016 18:31:46 +1300 Subject: [PATCH 4/6] If else block for gps prefs --- .../free/nrw/commons/upload/GPSExtractor.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java b/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java index 6528cadb7..16da36b6f 100644 --- a/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java +++ b/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java @@ -65,24 +65,29 @@ public class GPSExtractor { //Check what user's preference is for automatic location detection boolean gpsPrefEnabled = gpsPreferenceEnabled(); - LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); - Criteria criteria = new Criteria(); - String provider = locationManager.getBestProvider(criteria, true); + if (gpsPrefEnabled) { + //If pref enabled, set up LocationListener to get current location + LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); + Criteria criteria = new Criteria(); + String provider = locationManager.getBestProvider(criteria, true); - myLocationListener = new MyLocationListener(); - locationManager.requestLocationUpdates(provider, 400, 1, myLocationListener); - Location location = locationManager.getLastKnownLocation(provider); + myLocationListener = new MyLocationListener(); + locationManager.requestLocationUpdates(provider, 400, 1, myLocationListener); + Location location = locationManager.getLastKnownLocation(provider); - if (location != null) { - myLocationListener.onLocationChanged(location); - } - else { - //calling method is equipped to deal with null return value + if (location != null) { + myLocationListener.onLocationChanged(location); + } else { + //calling method is equipped to deal with null return value + return null; + } + Log.d(TAG, "Current location values: Lat = " + currentLatitude + " Long = " + currentLongitude); + String currentCoords = String.valueOf(currentLatitude) + "|" + String.valueOf(currentLongitude); + return currentCoords; + } else { + //Otherwise treat as if no coords found return null; } - Log.d(TAG, "Current location values: Lat = " + currentLatitude + " Long = " + currentLongitude); - String currentCoords = String.valueOf(currentLatitude) + "|" + String.valueOf(currentLongitude); - return currentCoords; } else { imageCoordsExists = true; From 816acbe04a5efe2f90359804d7841a83630b36ec Mon Sep 17 00:00:00 2001 From: misaochan Date: Fri, 5 Feb 2016 18:33:37 +1300 Subject: [PATCH 5/6] Minor formatting changes --- .../java/fr/free/nrw/commons/upload/GPSExtractor.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java b/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java index 16da36b6f..2dcc076df 100644 --- a/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java +++ b/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java @@ -1,7 +1,6 @@ package fr.free.nrw.commons.upload; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.location.Criteria; import android.location.Location; @@ -10,15 +9,9 @@ import android.location.LocationManager; import android.media.ExifInterface; import android.os.Bundle; import android.preference.PreferenceManager; -import android.provider.Settings; import android.util.Log; -import android.widget.Toast; - import java.io.IOException; -import fr.free.nrw.commons.SettingsActivity; - - public class GPSExtractor { private String filePath; @@ -88,7 +81,6 @@ public class GPSExtractor { //Otherwise treat as if no coords found return null; } - } else { imageCoordsExists = true; Log.d(TAG, "Picture has GPS info"); @@ -105,7 +97,6 @@ public class GPSExtractor { } } - private class MyLocationListener implements LocationListener { @Override From 6e0e58009a835f64c55145a876a1bae0ffe97a98 Mon Sep 17 00:00:00 2001 From: misaochan Date: Fri, 5 Feb 2016 18:34:29 +1300 Subject: [PATCH 6/6] Minor formatting changes 2 --- .../src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java b/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java index 2dcc076df..866ce7f74 100644 --- a/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java +++ b/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java @@ -81,6 +81,7 @@ public class GPSExtractor { //Otherwise treat as if no coords found return null; } + } else { imageCoordsExists = true; Log.d(TAG, "Picture has GPS info");