• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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.settings.wifi;
18 
19 import android.app.Dialog;
20 import android.net.wifi.WifiConfiguration;
21 import android.os.Bundle;
22 import android.support.v7.preference.PreferenceScreen;
23 import android.text.TextUtils;
24 import android.view.LayoutInflater;
25 import android.view.Menu;
26 import android.view.MenuInflater;
27 import android.view.View;
28 import android.view.View.OnClickListener;
29 import android.view.ViewGroup;
30 import android.widget.LinearLayout;
31 import android.widget.ListView;
32 import android.widget.TextView;
33 
34 import com.android.settings.R;
35 import com.android.settings.SetupWizardUtils;
36 import com.android.setupwizardlib.SetupWizardListLayout;
37 import com.android.setupwizardlib.view.NavigationBar;
38 
39 /**
40  * This customized version of WifiSettings is shown to the user only during Setup Wizard. Menu
41  * is not shown, clicking on an access point will auto-advance to the next screen (once connected),
42  * and, if the user opts to skip ahead without a wifi connection, a warning message alerts of
43  * possible carrier data charges or missing software updates.
44  */
45 public class WifiSettingsForSetupWizard extends WifiSettings {
46 
47     private static final String TAG = "WifiSettingsForSetupWizard";
48 
49     private SetupWizardListLayout mLayout;
50     private View mAddOtherNetworkItem;
51     private TextView mEmptyFooter;
52     private View mMacAddressFooter;
53     private boolean mListLastEmpty = false;
54 
55     @Override
onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)56     public View onCreateView(final LayoutInflater inflater, ViewGroup container,
57             Bundle savedInstanceState) {
58         mLayout = (SetupWizardListLayout)
59                 inflater.inflate(R.layout.setup_wifi_layout, container, false);
60         final ListView list = mLayout.getListView();
61 
62         mAddOtherNetworkItem = inflater.inflate(R.layout.setup_wifi_add_network, list, false);
63         list.addFooterView(mAddOtherNetworkItem, null, true);
64         mAddOtherNetworkItem.setOnClickListener(new OnClickListener() {
65             @Override
66             public void onClick(View v) {
67                 if (mWifiManager.isWifiEnabled()) {
68                     onAddNetworkPressed();
69                 }
70             }
71         });
72 
73         mMacAddressFooter = inflater.inflate(R.layout.setup_wifi_mac_address, list, false);
74         list.addFooterView(mMacAddressFooter, null, false);
75 
76         final NavigationBar navigationBar = mLayout.getNavigationBar();
77         if (navigationBar != null) {
78             WifiSetupActivity activity = (WifiSetupActivity) getActivity();
79             activity.onNavigationBarCreated(navigationBar);
80         }
81 
82         return mLayout;
83     }
84 
85     @Override
onActivityCreated(Bundle savedInstanceState)86     public void onActivityCreated(Bundle savedInstanceState) {
87         super.onActivityCreated(savedInstanceState);
88 
89         if (hasNextButton()) {
90             getNextButton().setVisibility(View.GONE);
91         }
92 
93         updateMacAddress();
94     }
95 
96     @Override
onAccessPointsChanged()97     public void onAccessPointsChanged() {
98         super.onAccessPointsChanged();
99         PreferenceScreen preferenceScreen = getPreferenceScreen();
100         updateFooter(preferenceScreen == null || preferenceScreen.getPreferenceCount() == 0);
101     }
102 
103     @Override
onWifiStateChanged(int state)104     public void onWifiStateChanged(int state) {
105         super.onWifiStateChanged(state);
106         updateMacAddress();
107     }
108 
109     @Override
registerForContextMenu(View view)110     public void registerForContextMenu(View view) {
111         // Suppressed during setup wizard
112     }
113 
114     @Override
createWifiEnabler()115     /* package */ WifiEnabler createWifiEnabler() {
116         // Not shown during setup wizard
117         return null;
118     }
119 
120     @Override
onCreateOptionsMenu(Menu menu, MenuInflater inflater)121     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
122         // Do not show menu during setup wizard
123     }
124 
125     @Override
onCreateDialog(int dialogId)126     public Dialog onCreateDialog(int dialogId) {
127         final Dialog dialog = super.onCreateDialog(dialogId);
128         SetupWizardUtils.applyImmersiveFlags(dialog);
129         return dialog;
130     }
131 
132     @Override
connect(final WifiConfiguration config)133     protected void connect(final WifiConfiguration config) {
134         WifiSetupActivity activity = (WifiSetupActivity) getActivity();
135         activity.networkSelected();
136         super.connect(config);
137     }
138 
139     @Override
connect(final int networkId)140     protected void connect(final int networkId) {
141         WifiSetupActivity activity = (WifiSetupActivity) getActivity();
142         activity.networkSelected();
143         super.connect(networkId);
144     }
145 
146     @Override
initEmptyTextView()147     protected TextView initEmptyTextView() {
148         final LayoutInflater inflater = LayoutInflater.from(getActivity());
149         mEmptyFooter = (TextView) inflater.inflate(R.layout.setup_wifi_empty, getListView(), false);
150         return mEmptyFooter;
151     }
152 
updateFooter(boolean isEmpty)153     protected void updateFooter(boolean isEmpty) {
154         if (isEmpty != mListLastEmpty) {
155             if (isEmpty) {
156                 setFooterView(mEmptyFooter);
157             } else {
158                 LinearLayout layout = new LinearLayout(getContext());
159                 layout.setOrientation(LinearLayout.VERTICAL);
160                 layout.addView(mAddOtherNetworkItem);
161                 layout.addView(mMacAddressFooter);
162                 setFooterView(layout);
163             }
164             mListLastEmpty = isEmpty;
165         }
166     }
167 
168     @Override
setPinnedHeaderView(int layoutResId)169     public View setPinnedHeaderView(int layoutResId) {
170         // Pinned header is not supported in setup wizard
171         return null;
172     }
173 
174     @Override
setPinnedHeaderView(View pinnedHeader)175     public void setPinnedHeaderView(View pinnedHeader) {
176         // Pinned header is not supported in setup wizard
177     }
178 
179     @Override
setProgressBarVisible(boolean visible)180     protected void setProgressBarVisible(boolean visible) {
181         if (mLayout != null) {
182             if (visible) {
183                 mLayout.showProgressBar();
184             } else {
185                 mLayout.hideProgressBar();
186             }
187         }
188     }
189 
updateMacAddress()190     private void updateMacAddress() {
191         if (mMacAddressFooter != null) {
192             String macAddress = null;
193             if (mWifiManager != null) {
194                 android.net.wifi.WifiInfo connectionInfo = mWifiManager.getConnectionInfo();
195                 if (connectionInfo != null) {
196                     macAddress = connectionInfo.getMacAddress();
197                 }
198             }
199             final TextView macAddressTextView =
200                     (TextView) mMacAddressFooter.findViewById(R.id.mac_address);
201             macAddressTextView.setText(!TextUtils.isEmpty(macAddress) ?
202                     macAddress : getString(R.string.status_unavailable));
203         }
204     }
205 }
206