1 /*
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 
17 package android.net;
18 
19 import android.annotation.DrawableRes;
20 import android.annotation.IntDef;
21 import android.annotation.IntRange;
22 import android.annotation.NonNull;
23 import android.annotation.Nullable;
24 import android.content.res.Resources;
25 import android.content.res.Resources.Theme;
26 import android.graphics.drawable.Drawable;
27 import android.net.wifi.WifiManager;
28 
29 import java.lang.annotation.Retention;
30 import java.lang.annotation.RetentionPolicy;
31 
32 /**
33  * Utility methods for working with network badging.
34  *
35  * @removed
36  *
37  */
38 @Deprecated
39 public class NetworkBadging {
40 
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 
NetworkBadging()50     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.
57      * @param badging  {@see NetworkBadging#Badging}, retrieved from
58      *                 {@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      */
getWifiIcon( @ntRangefrom=0, to=4) int signalLevel, @Badging int badging, @Nullable Theme theme)64     @NonNull public static Drawable getWifiIcon(
65             @IntRange(from=0, to=4) int signalLevel, @Badging int badging, @Nullable Theme theme) {
66         return Resources.getSystem().getDrawable(getWifiSignalResource(signalLevel), theme);
67     }
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      */
getWifiSignalResource(int signalLevel)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     }
96 }
97