blob: cd9ea88e5b76f2bb3cfd85dc1dc9a782fb126606 [file] [log] [blame]
Amin Shaikh15902ee2017-01-13 11:02:16 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package android.net;
18
19import android.annotation.DrawableRes;
Sundeep Ghuman699deaf2017-02-13 15:32:13 -080020import android.annotation.IntDef;
Amin Shaikh15902ee2017-01-13 11:02:16 -080021import android.annotation.IntRange;
22import android.annotation.NonNull;
23import android.annotation.Nullable;
Amin Shaikh15902ee2017-01-13 11:02:16 -080024import android.content.res.Resources;
25import android.content.res.Resources.Theme;
26import android.graphics.drawable.Drawable;
Amin Shaikh15902ee2017-01-13 11:02:16 -080027import android.net.wifi.WifiManager;
Amin Shaikh15902ee2017-01-13 11:02:16 -080028
Sundeep Ghuman699deaf2017-02-13 15:32:13 -080029import java.lang.annotation.Retention;
30import java.lang.annotation.RetentionPolicy;
31
Amin Shaikh15902ee2017-01-13 11:02:16 -080032/**
33 * Utility methods for working with network badging.
34 *
Joe LaPenna2c60ef02017-05-01 09:46:01 -070035 * @removed
36 *
Amin Shaikh15902ee2017-01-13 11:02:16 -080037 */
Joe LaPenna2c60ef02017-05-01 09:46:01 -070038@Deprecated
Amin Shaikh15902ee2017-01-13 11:02:16 -080039public class NetworkBadging {
Sundeep Ghuman699deaf2017-02-13 15:32:13 -080040
41 @IntDef({BADGING_NONE, BADGING_SD, BADGING_HD, BADGING_4K})
42 @Retention(RetentionPolicy.SOURCE)
43 public @interface Badging {}
44
45 public static final int BADGING_NONE = 0;
46 public static final int BADGING_SD = 10;
47 public static final int BADGING_HD = 20;
48 public static final int BADGING_4K = 30;
49
Amin Shaikh15902ee2017-01-13 11:02:16 -080050 private NetworkBadging() {}
51
52 /**
53 * Returns a Wi-Fi icon for a network with a given signal level and badging value.
54 *
55 * @param signalLevel The level returned by {@link WifiManager#calculateSignalLevel(int, int)}
56 * for a network. Must be between 0 and {@link WifiManager#RSSI_LEVELS}-1.
Stephen Chend831be92017-03-29 15:51:42 -070057 * @param badging {@see NetworkBadging#Badging}, retrieved from
Amin Shaikh15902ee2017-01-13 11:02:16 -080058 * {@link ScoredNetwork#calculateBadge(int)}.
59 * @param theme The theme for the current application, may be null.
60 * @return Drawable for the given icon
61 * @throws IllegalArgumentException if {@code signalLevel} is out of range or {@code badging}
62 * is an invalid value
63 */
64 @NonNull public static Drawable getWifiIcon(
65 @IntRange(from=0, to=4) int signalLevel, @Badging int badging, @Nullable Theme theme) {
Sundeep Ghuman19f64d02017-06-06 13:02:15 -070066 return Resources.getSystem().getDrawable(getWifiSignalResource(signalLevel), theme);
Amin Shaikh15902ee2017-01-13 11:02:16 -080067 }
68
69 /**
70 * Returns the wifi signal resource id for the given signal level.
71 *
72 * <p>This wifi signal resource is a wifi icon to be displayed by itself when there is no badge.
73 *
74 * @param signalLevel The level returned by {@link WifiManager#calculateSignalLevel(int, int)}
75 * for a network. Must be between 0 and {@link WifiManager#RSSI_LEVELS}-1.
76 * @return the @DrawableRes for the icon
77 * @throws IllegalArgumentException for an invalid signal level
78 * @hide
79 */
80 @DrawableRes private static int getWifiSignalResource(int signalLevel) {
81 switch (signalLevel) {
82 case 0:
83 return com.android.internal.R.drawable.ic_wifi_signal_0;
84 case 1:
85 return com.android.internal.R.drawable.ic_wifi_signal_1;
86 case 2:
87 return com.android.internal.R.drawable.ic_wifi_signal_2;
88 case 3:
89 return com.android.internal.R.drawable.ic_wifi_signal_3;
90 case 4:
91 return com.android.internal.R.drawable.ic_wifi_signal_4;
92 default:
93 throw new IllegalArgumentException("Invalid signal level: " + signalLevel);
94 }
95 }
Amin Shaikh15902ee2017-01-13 11:02:16 -080096}