summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorSundeep Ghuman <sghuman@google.com>2017-02-13 15:32:13 -0800
committerSundeep Ghuman <sghuman@google.com>2017-02-14 14:04:18 -0800
commit699deaf6103d182dbd291ca2b420f30b439753d4 (patch)
tree5cb24622e9500ecc4b40a8b3a12f0f8a268d9399 /core/java/android
parentb3f417ec3a0c549b4c50d4266680e5223bb3b774 (diff)
Move Badging from ScoredNetwork to NetworkingBadging.
This is a non-functional refactor. The old enums will be removed once ag/35323372 is addressed. Bug: 35114358 Test: Ran existing tests (see files touched). Change-Id: I08fd8c7964463b5908ce361e61f8fe811d0ff6f3
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/net/NetworkBadging.java29
-rw-r--r--core/java/android/net/ScoredNetwork.java28
2 files changed, 41 insertions, 16 deletions
diff --git a/core/java/android/net/NetworkBadging.java b/core/java/android/net/NetworkBadging.java
index 5cf2f965ffa6..4409d0a4ce73 100644
--- a/core/java/android/net/NetworkBadging.java
+++ b/core/java/android/net/NetworkBadging.java
@@ -17,6 +17,7 @@
package android.net;
import android.annotation.DrawableRes;
+import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -25,19 +26,29 @@ import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
-import android.net.ScoredNetwork.Badging;
import android.net.wifi.WifiManager;
import android.view.View;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
/**
* Utility methods for working with network badging.
*
- * TODO: move ScoredNetwork.Badging and related constants to this class.
- *
* @hide
*/
@SystemApi
public class NetworkBadging {
+
+ @IntDef({BADGING_NONE, BADGING_SD, BADGING_HD, BADGING_4K})
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface Badging {}
+
+ public static final int BADGING_NONE = 0;
+ public static final int BADGING_SD = 10;
+ public static final int BADGING_HD = 20;
+ public static final int BADGING_4K = 30;
+
private NetworkBadging() {}
/**
@@ -55,7 +66,7 @@ public class NetworkBadging {
@NonNull public static Drawable getWifiIcon(
@IntRange(from=0, to=4) int signalLevel, @Badging int badging, @Nullable Theme theme) {
Resources resources = Resources.getSystem();
- if (badging == ScoredNetwork.BADGING_NONE) {
+ if (badging == BADGING_NONE) {
return resources.getDrawable(getWifiSignalResource(signalLevel), theme);
}
Drawable[] layers = new Drawable[] {
@@ -131,19 +142,19 @@ public class NetworkBadging {
*
* @param badging {@see ScoredNetwork#Badging} from {@link ScoredNetwork#calculateBadge(int)}.
* @return the @DrawableRes for the icon or {@link View#NO_ID} for
- * {@link ScoredNetwork#BADGING_NONE}
+ * {@link NetworkBadging#BADGING_NONE}
* @throws IllegalArgumentException for an invalid badging value.
* @hide
*/
@DrawableRes private static int getWifiBadgeResource(@Badging int badging) {
switch (badging) {
- case ScoredNetwork.BADGING_NONE:
+ case BADGING_NONE:
return View.NO_ID;
- case ScoredNetwork.BADGING_SD:
+ case BADGING_SD:
return com.android.internal.R.drawable.ic_signal_wifi_badged_sd;
- case ScoredNetwork.BADGING_HD:
+ case BADGING_HD:
return com.android.internal.R.drawable.ic_signal_wifi_badged_hd;
- case ScoredNetwork.BADGING_4K:
+ case BADGING_4K:
return com.android.internal.R.drawable.ic_signal_wifi_badged_4k;
default:
throw new IllegalArgumentException("No resource found for badge: " + badging);
diff --git a/core/java/android/net/ScoredNetwork.java b/core/java/android/net/ScoredNetwork.java
index ba0a8b5f082a..a664a8bf1ac1 100644
--- a/core/java/android/net/ScoredNetwork.java
+++ b/core/java/android/net/ScoredNetwork.java
@@ -41,7 +41,7 @@ public class ScoredNetwork implements Parcelable {
* Key used with the {@link #attributes} bundle to define the badging curve.
*
* <p>The badging curve is a {@link RssiCurve} used to map different RSSI values to {@link
- * Badging} enums.
+ * NetworkBadging.Badging} enums.
*/
public static final String ATTRIBUTES_KEY_BADGING_CURVE =
"android.net.attributes.key.BADGING_CURVE";
@@ -70,17 +70,31 @@ public class ScoredNetwork implements Parcelable {
public static final String ATTRIBUTES_KEY_RANKING_SCORE_OFFSET =
"android.net.attributes.key.RANKING_SCORE_OFFSET";
+ /** A {@link NetworkKey} uniquely identifying this network. */
+ public final NetworkKey networkKey;
+
+ // TODO(b/35323372): Delete these once external references are switched.
+ /** @deprecated Use {@link NetworkBadging#Badging} instead. */
+ @Deprecated
@IntDef({BADGING_NONE, BADGING_SD, BADGING_HD, BADGING_4K})
@Retention(RetentionPolicy.SOURCE)
public @interface Badging {}
+ /** @deprecated Use {@link NetworkBadging#BADGING_NONE} instead. */
+ @Deprecated
public static final int BADGING_NONE = 0;
+
+ /** @deprecated Use {@link NetworkBadging#BADGING_SD} instead. */
+ @Deprecated
public static final int BADGING_SD = 10;
+
+ /** @deprecated Use {@link NetworkBadging#BADGING_HD} instead. */
+ @Deprecated
public static final int BADGING_HD = 20;
- public static final int BADGING_4K = 30;
- /** A {@link NetworkKey} uniquely identifying this network. */
- public final NetworkKey networkKey;
+ /** @deprecated Use {@link NetworkBadging#BADGING_4K} instead. */
+ @Deprecated
+ public static final int BADGING_4K = 30;
/**
* The {@link RssiCurve} representing the scores for this network based on the RSSI.
@@ -276,14 +290,14 @@ public class ScoredNetwork implements Parcelable {
}
/**
- * Return the {@link Badging} enum for this network for the given RSSI, derived from the
+ * Return the {@link NetworkBadging.Badging} enum for this network for the given RSSI, derived from the
* badging curve.
*
* <p>If no badging curve is present, {@link #BADGE_NONE} will be returned.
*
* @param rssi The rssi level for which the badge should be calculated
*/
- @Badging
+ @NetworkBadging.Badging
public int calculateBadge(int rssi) {
if (attributes != null && attributes.containsKey(ATTRIBUTES_KEY_BADGING_CURVE)) {
RssiCurve badgingCurve =
@@ -291,7 +305,7 @@ public class ScoredNetwork implements Parcelable {
return badgingCurve.lookupScore(rssi);
}
- return BADGING_NONE;
+ return NetworkBadging.BADGING_NONE;
}
public static final Parcelable.Creator<ScoredNetwork> CREATOR =