diff options
author | Nick Chalko <nchalko@google.com> | 2017-05-10 19:12:56 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-05-10 19:12:56 +0000 |
commit | 95c15c9733ec09088b49981559f477778204d04a (patch) | |
tree | 14d9836ff9283690321c166560ee3450792236ad /src/com/android/tv/util/LocationUtils.java | |
parent | 62bd372111825762150957fa82a0a95f6acbf9d8 (diff) | |
parent | c11f019e2f3b2e9a4edb0bd2687c149a30c209a0 (diff) | |
download | TV-95c15c9733ec09088b49981559f477778204d04a.tar.gz |
Sync to ub-tv-dev at lost+ hash 550cbec17259717c5453f6be1eb05736ba10ef1d am: 0550a7221b
am: c11f019e2f
Change-Id: I4645f478a402648d74c1d103f87959cd71c57ae5
Diffstat (limited to 'src/com/android/tv/util/LocationUtils.java')
-rw-r--r-- | src/com/android/tv/util/LocationUtils.java | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/com/android/tv/util/LocationUtils.java b/src/com/android/tv/util/LocationUtils.java index 8e3b59e9..2ae6db18 100644 --- a/src/com/android/tv/util/LocationUtils.java +++ b/src/com/android/tv/util/LocationUtils.java @@ -16,7 +16,9 @@ package com.android.tv.util; +import android.Manifest; import android.content.Context; +import android.content.pm.PackageManager; import android.location.Address; import android.location.Geocoder; import android.location.Location; @@ -25,6 +27,7 @@ import android.location.LocationManager; import android.os.Bundle; import android.util.Log; +import com.android.tv.tuner.util.PostalCodeUtils; import java.io.IOException; import java.util.List; @@ -39,6 +42,7 @@ public class LocationUtils { private static Context sApplicationContext; private static Address sAddress; + private static String sCountry; private static IOException sError; /** @@ -59,6 +63,19 @@ public class LocationUtils { return null; } + /** + * Returns the current country. + */ + public static synchronized String getCurrentCountry(Context context) { + if (sCountry != null) { + return sCountry; + } + if (sCountry == null) { + sCountry = context.getResources().getConfiguration().locale.getCountry(); + } + return sCountry; + } + private static void updateAddress(Location location) { if (DEBUG) Log.d(TAG, "Updating address with " + location); if (location == null) { @@ -68,9 +85,14 @@ public class LocationUtils { try { List<Address> addresses = geocoder.getFromLocation( location.getLatitude(), location.getLongitude(), 1); - if (addresses != null) { + if (addresses != null && !addresses.isEmpty()) { sAddress = addresses.get(0); if (DEBUG) Log.d(TAG, "Got " + sAddress); + try { + PostalCodeUtils.updatePostalCode(sApplicationContext); + } catch (Exception e) { + // Do nothing + } } else { if (DEBUG) Log.d(TAG, "No address returned"); } |