diff options
author | Maxime Biais <maxime.biais@gmail.com> | 2014-07-29 20:35:31 +0200 |
---|---|---|
committer | Maxime Biais <maxime.biais@gmail.com> | 2014-07-29 20:35:31 +0200 |
commit | 4e9141a6d5e81d2cd356298bbeba2eb064661090 (patch) | |
tree | c4608520e910192e2e0c7b3a06cb3d3cd1ab3e32 /libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/GeocoderUtils.java | |
parent | d6911576dca7d6eb3b6c98e9ca5ba981644f9066 (diff) | |
download | gradle-perf-android-medium-4e9141a6d5e81d2cd356298bbeba2eb064661090.tar.gz |
remove libs - that comes from a subtree/submodule merge
Diffstat (limited to 'libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/GeocoderUtils.java')
-rw-r--r-- | libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/GeocoderUtils.java | 116 |
1 files changed, 0 insertions, 116 deletions
diff --git a/libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/GeocoderUtils.java b/libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/GeocoderUtils.java deleted file mode 100644 index e861a88b8..000000000 --- a/libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/GeocoderUtils.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.wordpress.android.util; - -import android.content.Context; -import android.location.Address; -import android.location.Geocoder; - -import java.io.IOException; -import java.util.List; -import java.util.Locale; - -public final class GeocoderUtils { - private GeocoderUtils() { - throw new AssertionError(); - } - - public static Geocoder getGeocoder(Context context) { - // first make sure a Geocoder service exists on this device (requires API 9) - if (!Geocoder.isPresent()) { - return null; - } - - Geocoder gcd; - - try { - gcd = new Geocoder(context, Locale.getDefault()); - } catch (NullPointerException cannotIstantiateEx) { - AppLog.e(AppLog.T.UTILS, "Cannot instantiate Geocoder", cannotIstantiateEx); - return null; - } - - return gcd; - } - - public static Address getAddressFromCoords(Context context, double latitude, double longitude) { - Address address = null; - List<Address> addresses = null; - - Geocoder gcd = getGeocoder(context); - - if (gcd == null) { - return null; - } - - try { - addresses = gcd.getFromLocation(latitude, longitude, 1); - } catch (IOException e) { - // may get "Unable to parse response from server" IOException here if Geocoder - // service is hit too frequently - AppLog.e(AppLog.T.UTILS, - "Unable to parse response from server. Is Geocoder service hitting the server too frequently?", - e - ); - } - - // addresses may be null or empty if network isn't connected - if (addresses != null && addresses.size() > 0) { - address = addresses.get(0); - } - - return address; - } - - public static Address getAddressFromLocationName(Context context, String locationName) { - int maxResults = 1; - Address address = null; - List<Address> addresses = null; - - Geocoder gcd = getGeocoder(context); - - if (gcd == null) { - return null; - } - - try { - addresses = gcd.getFromLocationName(locationName, maxResults); - } catch (IOException e) { - AppLog.e(AppLog.T.UTILS, "Failed to get coordinates from location", e); - } - - // addresses may be null or empty if network isn't connected - if (addresses != null && addresses.size() > 0) { - address = addresses.get(0); - } - - return address; - } - - public static String getLocationNameFromAddress(Address address) { - String locality = "", adminArea = "", country = ""; - if (address.getLocality() != null) { - locality = address.getLocality(); - } - - if (address.getAdminArea() != null) { - adminArea = address.getAdminArea(); - } - - if (address.getCountryName() != null) { - country = address.getCountryName(); - } - - return ((locality.equals("")) ? locality : locality + ", ") - + ((adminArea.equals("")) ? adminArea : adminArea + " ") + country; - } - - public static double[] getCoordsFromAddress(Address address) { - double[] coordinates = new double[2]; - - if (address.hasLatitude() && address.hasLongitude()) { - coordinates[0] = address.getLatitude(); - coordinates[1] = address.getLongitude(); - } - - return coordinates; - } -} |