aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornchalko <nchalko@google.com>2019-05-30 14:44:51 -0700
committerNick Chalko <nchalko@google.com>2019-05-30 22:15:13 -0700
commitc8d23359e3a41679f8fb8fc6a628eea22d74ab07 (patch)
tree119474e075e59ca1bb521f6f4796150b95dbf6e7
parente90e34dd2fb2e7ec3e7c7c5e0095150f986d3e6e (diff)
downloadTV-c8d23359e3a41679f8fb8fc6a628eea22d74ab07.tar.gz
Move getPostalCode to LocationUtils
PiperOrigin-RevId: 250766274 Change-Id: Ia353e33e7055e77926cb5eec317ca43ad178d1cc
-rw-r--r--common/src/com/android/tv/common/util/LocationUtils.java31
-rw-r--r--common/src/com/android/tv/common/util/PostalCodeUtils.java21
2 files changed, 28 insertions, 24 deletions
diff --git a/common/src/com/android/tv/common/util/LocationUtils.java b/common/src/com/android/tv/common/util/LocationUtils.java
index ee5119eb..60c2a969 100644
--- a/common/src/com/android/tv/common/util/LocationUtils.java
+++ b/common/src/com/android/tv/common/util/LocationUtils.java
@@ -26,13 +26,17 @@ import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
+
import com.android.tv.common.BuildConfig;
+
+
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
@@ -69,15 +73,30 @@ public class LocationUtils {
return null;
}
+ @Nullable
+ static String getCurrentPostalCode(Context context) throws IOException {
+ Address address = getCurrentAddress(context);
+ if (address != null) {
+ Log.i(
+ TAG,
+ "Current country and postal code is "
+ + address.getCountryName()
+ + ", "
+ + address.getPostalCode());
+ return address.getPostalCode();
+ }
+ return null;
+ }
+
/** The listener used when address is updated. */
public interface OnUpdateAddressListener {
/**
* Called when address is updated.
*
- * This listener is removed when this method returns true.
+ * <p>This listener is removed when this method returns true.
*
* @return {@code true} if the job has been finished and the listener needs to be removed;
- * {@code false} otherwise.
+ * {@code false} otherwise.
*/
boolean onUpdateAddress(Address address);
}
@@ -85,8 +104,8 @@ public class LocationUtils {
/**
* Add an {@link OnUpdateAddressListener} instance.
*
- * Note that the listener is removed automatically when
- * {@link OnUpdateAddressListener#onUpdateAddress(Address)} is called and returns {@code true}.
+ * <p>Note that the listener is removed automatically when {@link
+ * OnUpdateAddressListener#onUpdateAddress(Address)} is called and returns {@code true}.
*/
public static void addOnUpdateAddressListener(OnUpdateAddressListener listener) {
sOnUpdateAddressListeners.add(listener);
@@ -95,8 +114,8 @@ public class LocationUtils {
/**
* Remove an {@link OnUpdateAddressListener} instance if it exists.
*
- * Note that the listener will be removed automatically when
- * {@link OnUpdateAddressListener#onUpdateAddress(Address)} is called and returns {@code true}.
+ * <p>Note that the listener will be removed automatically when {@link
+ * OnUpdateAddressListener#onUpdateAddress(Address)} is called and returns {@code true}.
*/
public static void removeOnUpdateAddressListener(OnUpdateAddressListener listener) {
sOnUpdateAddressListeners.remove(listener);
diff --git a/common/src/com/android/tv/common/util/PostalCodeUtils.java b/common/src/com/android/tv/common/util/PostalCodeUtils.java
index c0917af2..6ca3d48c 100644
--- a/common/src/com/android/tv/common/util/PostalCodeUtils.java
+++ b/common/src/com/android/tv/common/util/PostalCodeUtils.java
@@ -17,12 +17,12 @@
package com.android.tv.common.util;
import android.content.Context;
-import android.location.Address;
import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
+
import com.android.tv.common.CommonPreferences;
+
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
@@ -62,7 +62,7 @@ public class PostalCodeUtils {
/** Returns {@code true} if postal code has been changed */
public static boolean updatePostalCode(Context context)
throws IOException, SecurityException, NoPostalCodeException {
- String postalCode = getPostalCode(context);
+ String postalCode = LocationUtils.getCurrentPostalCode(context);
String lastPostalCode = getLastPostalCode(context);
if (TextUtils.isEmpty(postalCode)) {
if (TextUtils.isEmpty(lastPostalCode)) {
@@ -92,21 +92,6 @@ public class PostalCodeUtils {
CommonPreferences.setLastPostalCode(context, postalCode);
}
- @Nullable
- private static String getPostalCode(Context context) throws IOException, SecurityException {
- Address address = LocationUtils.getCurrentAddress(context);
- if (address != null) {
- Log.i(
- TAG,
- "Current country and postal code is "
- + address.getCountryName()
- + ", "
- + address.getPostalCode());
- return address.getPostalCode();
- }
- return null;
- }
-
/** An {@link java.lang.Exception} class to notify no valid postal or zip code is available. */
public static class NoPostalCodeException extends Exception {
public NoPostalCodeException() {}