2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.wifi;
19 import android.content.Intent;
20 import android.content.res.TypedArray;
21 import android.database.DataSetObserver;
22 import android.net.wifi.WifiConfiguration;
23 import android.os.Bundle;
24 import android.view.Gravity;
25 import android.view.LayoutInflater;
26 import android.view.Menu;
27 import android.view.MenuItem;
28 import android.view.View;
29 import android.view.View.OnClickListener;
30 import android.view.ViewGroup;
31 import android.widget.AbsListView.LayoutParams;
32 import android.widget.ListAdapter;
33 import android.widget.ListView;
34 import android.widget.TextView;
36 import com.android.settings.R;
39 * This customized version of WifiSettings is shown to the user only during Setup Wizard. Menu
40 * selections are limited, clicking on an access point will auto-advance to the next screen (once
41 * connected), and, if the user opts to skip ahead without a wifi connection, a warning message
42 * alerts of possible carrier data charges or missing software updates.
44 public class WifiSettingsForSetupWizard extends WifiSettings {
46 private static final String TAG = "WifiSettingsForSetupWizard";
48 // show a text regarding data charges when wifi connection is required during setup wizard
49 protected static final String EXTRA_SHOW_WIFI_REQUIRED_INFO = "wifi_show_wifi_required_info";
51 private View mAddOtherNetworkItem;
52 private ListAdapter mAdapter;
53 private TextView mEmptyFooter;
54 private boolean mListLastEmpty = false;
57 public View onCreateView(final LayoutInflater inflater, ViewGroup container,
58 Bundle savedInstanceState) {
60 final View view = inflater.inflate(R.layout.setup_preference, container, false);
62 final ListView list = (ListView) view.findViewById(android.R.id.list);
63 final View title = view.findViewById(R.id.title);
65 final View header = inflater.inflate(R.layout.setup_wizard_header, list, false);
66 list.addHeaderView(header, null, false);
69 mAddOtherNetworkItem = inflater.inflate(R.layout.setup_wifi_add_network, list, false);
70 list.addFooterView(mAddOtherNetworkItem, null, true);
71 mAddOtherNetworkItem.setOnClickListener(new OnClickListener() {
73 public void onClick(View v) {
74 if (mWifiManager.isWifiEnabled()) {
75 onAddNetworkPressed();
80 final Intent intent = getActivity().getIntent();
81 if (intent.getBooleanExtra(EXTRA_SHOW_WIFI_REQUIRED_INFO, false)) {
82 view.findViewById(R.id.wifi_required_info).setVisibility(View.VISIBLE);
89 public void onActivityCreated(Bundle savedInstanceState) {
90 super.onActivityCreated(savedInstanceState);
92 getView().setSystemUiVisibility(
93 View.STATUS_BAR_DISABLE_HOME |
94 View.STATUS_BAR_DISABLE_RECENT |
95 View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS |
96 View.STATUS_BAR_DISABLE_CLOCK);
98 if (hasNextButton()) {
99 getNextButton().setVisibility(View.GONE);
102 mAdapter = getPreferenceScreen().getRootAdapter();
103 mAdapter.registerDataSetObserver(new DataSetObserver() {
105 public void onChanged() {
113 public void registerForContextMenu(View view) {
114 // Suppressed during setup wizard
118 /* package */ WifiEnabler createWifiEnabler() {
119 // Not shown during setup wizard
124 /* package */ void addOptionsMenuItems(Menu menu) {
125 final boolean wifiIsEnabled = mWifiManager.isWifiEnabled();
126 final TypedArray ta = getActivity().getTheme()
127 .obtainStyledAttributes(new int[] {R.attr.ic_wps});
128 menu.add(Menu.NONE, MENU_ID_WPS_PBC, 0, R.string.wifi_menu_wps_pbc)
129 .setIcon(ta.getDrawable(0))
130 .setEnabled(wifiIsEnabled)
131 .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
132 menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network)
133 .setEnabled(wifiIsEnabled)
134 .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
139 protected void connect(final WifiConfiguration config) {
140 WifiSetupActivity activity = (WifiSetupActivity) getActivity();
141 activity.networkSelected();
142 super.connect(config);
146 protected void connect(final int networkId) {
147 WifiSetupActivity activity = (WifiSetupActivity) getActivity();
148 activity.networkSelected();
149 super.connect(networkId);
153 protected TextView initEmptyView() {
154 mEmptyFooter = new TextView(getActivity());
155 mEmptyFooter.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
156 LayoutParams.MATCH_PARENT));
157 mEmptyFooter.setGravity(Gravity.CENTER);
158 mEmptyFooter.setCompoundDrawablesWithIntrinsicBounds(0,
159 R.drawable.ic_wifi_emptystate, 0,0);
163 protected void updateFooter() {
164 final boolean isEmpty = mAdapter.isEmpty();
165 if (isEmpty != mListLastEmpty) {
166 final ListView list = getListView();
168 list.removeFooterView(mAddOtherNetworkItem);
169 list.addFooterView(mEmptyFooter, null, false);
171 list.removeFooterView(mEmptyFooter);
172 list.addFooterView(mAddOtherNetworkItem, null, true);
174 mListLastEmpty = isEmpty;