OSDN Git Service

b52aaa7615b3e9ab4b7af286d5890be693728697
[android-x86/packages-apps-Settings.git] / src / com / android / settings / wifi / WifiSettingsForSetupWizard.java
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.content.Intent;
20 import android.content.res.TypedArray;
21 import android.net.wifi.WifiConfiguration;
22 import android.os.Bundle;
23 import android.view.LayoutInflater;
24 import android.view.Menu;
25 import android.view.MenuItem;
26 import android.view.View;
27 import android.view.View.OnClickListener;
28 import android.view.ViewGroup;
29 import android.widget.ImageButton;
30 import android.widget.ListView;
31 import android.widget.PopupMenu;
32 import android.widget.PopupMenu.OnMenuItemClickListener;
33 import android.widget.TextView;
34
35 import com.android.settings.R;
36
37 /**
38  * This customized version of WifiSettings is shown to the user only during Setup Wizard. Menu
39  * selections are limited, clicking on an access point will auto-advance to the next screen (once
40  * connected), and, if the user opts to skip ahead without a wifi connection, a warning message
41  * alerts of possible carrier data charges or missing software updates.
42  */
43 public class WifiSettingsForSetupWizard extends WifiSettings {
44
45     private static final String TAG = "WifiSettingsForSetupWizard";
46
47     // show a text regarding data charges when wifi connection is required during setup wizard
48     protected static final String EXTRA_SHOW_WIFI_REQUIRED_INFO = "wifi_show_wifi_required_info";
49
50     @Override
51     public View onCreateView(final LayoutInflater inflater, ViewGroup container,
52             Bundle savedInstanceState) {
53
54         final View view = inflater.inflate(R.layout.setup_preference, container, false);
55
56         final ListView list = (ListView) view.findViewById(android.R.id.list);
57         final View title = view.findViewById(R.id.title);
58         if (title == null) {
59             final View header = inflater.inflate(R.layout.setup_wizard_header, list, false);
60             list.addHeaderView(header, null, false);
61         }
62
63         final View other = inflater.inflate(R.layout.setup_wifi_add_network, list, false);
64         list.addFooterView(other, null, true);
65         other.setOnClickListener(new OnClickListener() {
66             @Override
67             public void onClick(View v) {
68                 if (mWifiManager.isWifiEnabled()) {
69                     onAddNetworkPressed();
70                 }
71             }
72         });
73
74         final Intent intent = getActivity().getIntent();
75         if (intent.getBooleanExtra(EXTRA_SHOW_WIFI_REQUIRED_INFO, false)) {
76             view.findViewById(R.id.wifi_required_info).setVisibility(View.VISIBLE);
77         }
78
79         return view;
80     }
81
82     @Override
83     public void onActivityCreated(Bundle savedInstanceState) {
84         super.onActivityCreated(savedInstanceState);
85
86         getView().setSystemUiVisibility(
87                 View.STATUS_BAR_DISABLE_HOME |
88                 View.STATUS_BAR_DISABLE_RECENT |
89                 View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS |
90                 View.STATUS_BAR_DISABLE_CLOCK);
91
92         if (hasNextButton()) {
93             getNextButton().setVisibility(View.GONE);
94         }
95     }
96
97     @Override
98     public void registerForContextMenu(View view) {
99         // Suppressed during setup wizard
100     }
101
102     @Override
103     /* package */ WifiEnabler createWifiEnabler() {
104         // Not shown during setup wizard
105         return null;
106     }
107
108     @Override
109     /* package */ void addOptionsMenuItems(Menu menu) {
110         final boolean wifiIsEnabled = mWifiManager.isWifiEnabled();
111         final TypedArray ta = getActivity().getTheme()
112                 .obtainStyledAttributes(new int[] {R.attr.ic_wps});
113         menu.add(Menu.NONE, MENU_ID_WPS_PBC, 0, R.string.wifi_menu_wps_pbc)
114                 .setIcon(ta.getDrawable(0))
115                 .setEnabled(wifiIsEnabled)
116                 .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
117         menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network)
118                 .setEnabled(wifiIsEnabled)
119                 .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
120         ta.recycle();
121     }
122
123     @Override
124     protected void connect(final WifiConfiguration config) {
125         WifiSetupActivity activity = (WifiSetupActivity) getActivity();
126         activity.networkSelected();
127         super.connect(config);
128     }
129
130     @Override
131     protected void connect(final int networkId) {
132         WifiSetupActivity activity = (WifiSetupActivity) getActivity();
133         activity.networkSelected();
134         super.connect(networkId);
135     }
136 }