• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.car.settings.home;
18 
19 import android.annotation.DrawableRes;
20 import android.annotation.StringRes;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.net.wifi.WifiManager;
24 
25 import com.android.car.settings.R;
26 import com.android.car.settings.common.IconToggleLineItem;
27 import com.android.car.settings.wifi.CarWifiManager;
28 import com.android.car.settings.wifi.WifiSettingsActivity;
29 
30 
31 /**
32  * Represents the wifi line item on settings home page.
33  */
34 public class WifiLineItem extends IconToggleLineItem {
35     private final Context mContext;
36     private final CarWifiManager mCarWifiManager;
37 
WifiLineItem(Context context, CarWifiManager carWifiManager)38     public WifiLineItem(Context context, CarWifiManager carWifiManager) {
39         super(context.getText(R.string.wifi_settings), context);
40         mContext = context;
41         mCarWifiManager = carWifiManager;
42     }
43 
44     @Override
onToggleClicked(boolean isChecked)45     public void onToggleClicked(boolean isChecked) {
46         mCarWifiManager.setWifiEnabled(isChecked);
47     }
48 
49     @Override
onClicked()50     public void onClicked() {
51         Intent intent = new Intent(mContext, WifiSettingsActivity.class);
52         mContext.startActivity(intent);
53     }
54 
55     @Override
getDesc()56     public CharSequence getDesc() {
57         return mContext.getText(R.string.wifi_settings_summary);
58     }
59 
60     @Override
isChecked()61     public boolean isChecked() {
62         return mCarWifiManager.isWifiEnabled();
63     }
64 
65     @Override
getIcon()66     public @DrawableRes int getIcon() {
67         return getIconRes(mCarWifiManager.getWifiState());
68     }
69 
onWifiStateChanged(int state)70     public void onWifiStateChanged(int state) {
71         if (mIconUpdateListener == null) {
72             return;
73         }
74         mIconUpdateListener.onUpdateIcon(getIconRes(state));
75     }
76 
getIconRes(int state)77     private @DrawableRes int getIconRes(int state) {
78         switch (state) {
79             case WifiManager.WIFI_STATE_ENABLING:
80                 //TODO show gray out?
81             case WifiManager.WIFI_STATE_DISABLED:
82                 return R.drawable.ic_settings_wifi_disabled;
83             default:
84                 return R.drawable.ic_settings_wifi;
85         }
86     }
87 }
88