1 /*
2  * Copyright (C) 2020 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 com.android.tv.settings.widget;
18 
19 import android.content.Context;
20 import android.graphics.drawable.Drawable;
21 import android.widget.ImageView;
22 
23 import androidx.preference.PreferenceViewHolder;
24 
25 import com.android.settingslib.wifi.AccessPoint;
26 import com.android.tv.settings.R;
27 import com.android.tv.settings.overlay.FlavorUtils;
28 
29 /**
30  * Preference for overriding wifi icons
31  */
32 public class TvAccessPointPreference extends AccessPointPreference {
33 
34     private AccessPoint mAccessPoint;
35 
TvAccessPointPreference(AccessPoint accessPoint, Context context, AccessPointPreference.UserBadgeCache cache, boolean forSavedNetworks)36     public TvAccessPointPreference(AccessPoint accessPoint, Context context,
37             AccessPointPreference.UserBadgeCache cache, boolean forSavedNetworks) {
38         super(accessPoint, context, cache, forSavedNetworks);
39         mAccessPoint = accessPoint;
40     }
41 
42     @Override
updateIcon(int level, Context context)43     protected void updateIcon(int level, Context context) {
44         if (FlavorUtils.isTwoPanel(getContext())) {
45             switch (level) {
46                 case 4:
47                     setIcon(R.drawable.ic_wifi_signal_4_white);
48                     return;
49                 case 3:
50                     setIcon(R.drawable.ic_wifi_signal_3_white);
51                     return;
52                 case 2:
53                     setIcon(R.drawable.ic_wifi_signal_2_white);
54                     return;
55                 case 1:
56                     setIcon(R.drawable.ic_wifi_signal_1_white);
57                     return;
58                 case 0:
59                     // fall through
60                 default:
61                     setIcon(R.drawable.ic_wifi_signal_0_white);
62                     return;
63             }
64         } else {
65             super.updateIcon(level, context);
66         }
67     }
68 
69     @Override
onBindViewHolder(final PreferenceViewHolder view)70     public void onBindViewHolder(final PreferenceViewHolder view) {
71         super.onBindViewHolder(view);
72         if (FlavorUtils.isTwoPanel(getContext())) {
73             ImageView frictionImageView = (ImageView) view.findViewById(R.id.friction_icon);
74             if (frictionImageView == null || mAccessPoint == null) {
75                 return;
76             }
77             // Update the lock icon when WiFi network is secured
78             if ((mAccessPoint.getSecurity() != AccessPoint.SECURITY_NONE)
79                     && (mAccessPoint.getSecurity() != AccessPoint.SECURITY_OWE)) {
80                 Drawable drawable = getContext()
81                         .getDrawable(R.drawable.ic_wifi_signal_lock_outline);
82                 frictionImageView.setImageDrawable(drawable);
83             }
84         }
85     }
86 }
87