mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Added docs for GPSExtractor
This commit is contained in:
parent
a71c324af1
commit
0edbf2f356
2 changed files with 24 additions and 6 deletions
|
|
@ -348,9 +348,9 @@ public class CategorizationFragment extends SherlockFragment{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes asynchronous calls to the Commons MediaWiki API via anonymous subclasses of
|
* Makes asynchronous calls to the Commons MediaWiki API via anonymous subclasses of
|
||||||
* 'MethodAUpdater' and 'PrefixUpdater'. Some of their methods are overridden to implement
|
* 'MethodAUpdater' and 'PrefixUpdater'. Some of their methods are overridden in order to
|
||||||
* more specialized behaviour to aggregate the results. A CountDownLatch is used to ensure that
|
* aggregate the results. A CountDownLatch is used to ensure that MethodA results are shown
|
||||||
* MethodA results are shown above Prefix results.
|
* above Prefix results.
|
||||||
*/
|
*/
|
||||||
private void requestSearchResults() {
|
private void requestSearchResults() {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,11 @@ import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts geolocation to be passed to API for category suggestions. If a picture with geolocation
|
||||||
|
* is uploaded, extract latitude and longitude from EXIF data of image. If a picture without
|
||||||
|
* geolocation is uploaded, retrieve user's location (if enabled in Settings).
|
||||||
|
*/
|
||||||
public class GPSExtractor {
|
public class GPSExtractor {
|
||||||
|
|
||||||
private static final String TAG = GPSExtractor.class.getName();
|
private static final String TAG = GPSExtractor.class.getName();
|
||||||
|
|
@ -31,6 +36,10 @@ public class GPSExtractor {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if user enabled retrieval of their current location in Settings
|
||||||
|
* @return true if enabled, false if disabled
|
||||||
|
*/
|
||||||
private boolean gpsPreferenceEnabled() {
|
private boolean gpsPreferenceEnabled() {
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
boolean gpsPref = sharedPref.getBoolean("allowGps", false);
|
boolean gpsPref = sharedPref.getBoolean("allowGps", false);
|
||||||
|
|
@ -38,6 +47,9 @@ public class GPSExtractor {
|
||||||
return gpsPref;
|
return gpsPref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a LocationManager to listen for current location
|
||||||
|
*/
|
||||||
protected void registerLocationManager() {
|
protected void registerLocationManager() {
|
||||||
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||||
criteria = new Criteria();
|
criteria = new Criteria();
|
||||||
|
|
@ -55,7 +67,10 @@ public class GPSExtractor {
|
||||||
locationManager.removeUpdates(myLocationListener);
|
locationManager.removeUpdates(myLocationListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Extract GPS coords of image
|
/**
|
||||||
|
* Extracts geolocation of image from EXIF data.
|
||||||
|
* @return coordinates of image as string (needs to be passed as a String in API query)
|
||||||
|
*/
|
||||||
public String getCoords() {
|
public String getCoords() {
|
||||||
|
|
||||||
ExifInterface exif;
|
ExifInterface exif;
|
||||||
|
|
@ -136,7 +151,10 @@ public class GPSExtractor {
|
||||||
return decLongitude;
|
return decLongitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Converts format of coords into decimal coords as required by MediaWiki API
|
/**
|
||||||
|
* Converts format of geolocation into decimal coordinates as required by MediaWiki API
|
||||||
|
* @return the coordinates in decimals
|
||||||
|
*/
|
||||||
private String getDecimalCoords(String latitude, String latitude_ref, String longitude, String longitude_ref) {
|
private String getDecimalCoords(String latitude, String latitude_ref, String longitude, String longitude_ref) {
|
||||||
|
|
||||||
if (latitude_ref.equals("N")) {
|
if (latitude_ref.equals("N")) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue