Refactor WiFi code around XL setup
Major: - move SetupWizard-related codes to WifiSettingsForSetupWizardXL as much as possible - stop using Preference for configurinig wifi network. We use WifiConfigUiForSetupWizardXL instead, which is base on a bare View. Minor: - change button handling code expecting better readability. - hide Detail button. - modify strings a bit. - add logs Bug: 3175016 Change-Id: I5b29917af73aac6a82e13ba846a9d5085f9bd523
This commit is contained in:
@@ -75,7 +75,7 @@
|
||||
<FrameLayout
|
||||
android:id="@+id/wifi_setup"
|
||||
android:layout_width="400dip"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@+id/wifi_setup_status">
|
||||
<fragment
|
||||
@@ -84,6 +84,23 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</FrameLayout>
|
||||
<FrameLayout
|
||||
android:id="@+id/wifi_config_ui"
|
||||
android:layout_width="400dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@+id/wifi_setup_status"
|
||||
android:visibility="gone" />
|
||||
|
||||
<Button android:id="@+id/wifi_setup_detail"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/wifi_config_ui"
|
||||
android:layout_alignLeft="@id/wifi_config_ui"
|
||||
android:textSize="18dip"
|
||||
android:text="@string/wifi_setup_detail"
|
||||
android:gravity="left|center_vertical"
|
||||
android:visibility="gone" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/right_buttons"
|
||||
@@ -97,7 +114,7 @@
|
||||
android:layout_width="260dip"
|
||||
android:layout_height="60dip"
|
||||
android:textSize="24dip"
|
||||
android:text="@string/wifi_forget"
|
||||
android:text="@string/wifi_setup_forget"
|
||||
android:visibility="gone" />
|
||||
|
||||
<Button android:id="@+id/wifi_setup_connect"
|
||||
@@ -105,7 +122,8 @@
|
||||
android:layout_height="60dip"
|
||||
android:layout_marginTop="20dip"
|
||||
android:textSize="24dip"
|
||||
android:text="@string/wifi_connect"
|
||||
android:text="@string/wifi_setup_connect"
|
||||
android:enabled="false"
|
||||
android:visibility="gone" />
|
||||
|
||||
<Button android:id="@+id/wifi_setup_add_network"
|
||||
@@ -131,15 +149,7 @@
|
||||
android:enabled="false" />
|
||||
</LinearLayout>
|
||||
|
||||
<Button android:id="@+id/wifi_setup_detail"
|
||||
android:layout_width="260dip"
|
||||
android:layout_height="60dip"
|
||||
android:layout_above="@+id/wifi_setup_cancel"
|
||||
android:layout_alignLeft="@+id/wifi_setup_cancel"
|
||||
android:textSize="24dip"
|
||||
android:text="@string/wifi_detail"
|
||||
android:visibility="gone" />
|
||||
|
||||
<!-- This misleading name is for keeping consistency between non-XL layouts -->
|
||||
<Button android:id="@+id/wifi_setup_cancel"
|
||||
android:layout_width="260dip"
|
||||
android:layout_height="60dip"
|
||||
@@ -147,6 +157,6 @@
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_toLeftOf="@id/right_buttons"
|
||||
android:textSize="24dip"
|
||||
android:text="@string/wifi_back"
|
||||
android:text="@string/wifi_setup_back"
|
||||
android:visibility="gone" />
|
||||
</RelativeLayout>
|
||||
|
@@ -18,6 +18,28 @@
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<LinearLayout
|
||||
android:id="@+id/wifi_general_info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<TextView android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:ellipsize="marquee"
|
||||
android:fadingEdge="horizontal" />
|
||||
|
||||
<TextView android:id="@+id/summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@android:id/title"
|
||||
android:layout_alignLeft="@android:id/title"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:maxLines="1" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- UI components that should be shown appropriately -->
|
||||
<LinearLayout android:id="@+id/wps_fields"
|
||||
@@ -94,7 +116,7 @@
|
||||
<LinearLayout android:id="@+id/info"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"/> -->
|
||||
android:orientation="vertical"/>
|
||||
|
||||
<LinearLayout android:id="@+id/setup_fields"
|
||||
android:layout_width="fill_parent"
|
@@ -1009,12 +1009,6 @@
|
||||
<string name="wifi_save">Save</string>
|
||||
<!-- Button label to dismiss the dialog -->
|
||||
<string name="wifi_cancel">Cancel</string>
|
||||
<!-- Button label to go back to previous screen. Used in SetupWizard for
|
||||
XLarge screen [CHAR LIMIT=10]-->
|
||||
<string name="wifi_back">Back</string>
|
||||
<!-- Button label to show detailed dialog for WiFi settings.
|
||||
Used in SetupWizard for XLarge screen [CHAR LIMIT=10]-->
|
||||
<string name="wifi_detail">Detail</string>
|
||||
|
||||
<!-- Wi-Fi Advanced Settings --> <skip />
|
||||
<!-- Wi-Fi settings screen, advanced, settings section. This is a header shown above advanced wifi settings. -->
|
||||
@@ -2953,13 +2947,31 @@ found in the list of installed applications.</string>
|
||||
<!-- Button message shown on the button enabling users go the next step.
|
||||
Used in Wifi Setup For Setup Wizard with XL screen. -->
|
||||
<string name="wifi_setup_next">Next</string>
|
||||
<!-- Button label to go back to previous screen. Used in SetupWizard for
|
||||
XLarge screen [CHAR LIMIT=10] -->
|
||||
<string name="wifi_setup_back">Back</string>
|
||||
<!-- Button label to show detailed dialog for a selected WiFi settings.
|
||||
Used in SetupWizard for XLarge screen [CHAR LIMIT=20] -->
|
||||
<string name="wifi_setup_detail">Network details</string>
|
||||
<!-- Button label to connect to a Wi-Fi network.
|
||||
Used in SetupWizard for XLarge screen [CHAR LIMIT=10] -->
|
||||
<string name="wifi_setup_connect">Connect</string>
|
||||
<!-- Button label to delete a Wi-Fi network.
|
||||
Used in SetupWizard for XLarge screen [CHAR LIMIT=10] -->
|
||||
<string name="wifi_setup_forget">Forget</string>
|
||||
<!-- Button label to save a Wi-Fi network configuration.
|
||||
Used in SetupWizard for XLarge screen [CHAR LIMIT=10] -->
|
||||
<string name="wifi_setup_save">Save</string>
|
||||
<!-- Button label to dismiss the dialog.
|
||||
Used in SetupWizard for XLarge screen [CHAR LIMIT=10] -->
|
||||
<string name="wifi_setup_cancel">Cancel</string>
|
||||
|
||||
<!-- The message shown above available networks when the device is scanning
|
||||
available networks [CHAR LIMIT=35] -->
|
||||
<string name="wifi_setup_status_scanning">Scanning networks...</string>
|
||||
<!-- Message shown above available network when there's no connected network.
|
||||
Used in Wifi Setup For Setup Wizard with XL screen. -->
|
||||
<string name="wifi_setup_status_select_network">Touch to select network</string>
|
||||
<string name="wifi_setup_status_select_network">Touch a network to connect to it</string>
|
||||
<!-- Message shown above available networks when a user clicked one of available
|
||||
networks and the UI is showing one possible existing network.
|
||||
Used in Wifi Setup. -->
|
||||
|
@@ -128,8 +128,8 @@ public class WifiConfigController implements TextWatcher,
|
||||
return false;
|
||||
}
|
||||
|
||||
public WifiConfigController(WifiConfigUiBase parent, View view, AccessPoint accessPoint,
|
||||
boolean edit, DialogInterface.OnClickListener listener) {
|
||||
public WifiConfigController(
|
||||
WifiConfigUiBase parent, View view, AccessPoint accessPoint, boolean edit) {
|
||||
mConfigUi = parent;
|
||||
|
||||
mView = view;
|
||||
@@ -141,7 +141,7 @@ public class WifiConfigController implements TextWatcher,
|
||||
final Context context = mConfigUi.getContext();
|
||||
final Resources resources = context.getResources();
|
||||
|
||||
if (mAccessPoint == null) {
|
||||
if (mAccessPoint == null) { // new network
|
||||
mConfigUi.setTitle(R.string.wifi_add_network);
|
||||
mView.findViewById(R.id.type).setVisibility(View.VISIBLE);
|
||||
mSsidView = (TextView) mView.findViewById(R.id.ssid);
|
||||
@@ -626,6 +626,10 @@ public class WifiConfigController implements TextWatcher,
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEdit() {
|
||||
return mEdit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
enableSubmitIfAppropriate();
|
||||
|
@@ -1,167 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.preference.Preference;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
/**
|
||||
* Preference letting users modify a setting for Wifi network. This work as an alternative UI
|
||||
* for {@link WifiDialog} without shouwing popup Dialog.
|
||||
*/
|
||||
public class WifiConfigPreference extends Preference implements WifiConfigUiBase {
|
||||
private static final String TAG = "WifiConfigPreference";
|
||||
|
||||
private WifiSettings mWifiSettings;
|
||||
private View mView;
|
||||
private final DialogInterface.OnClickListener mListener;
|
||||
private WifiConfigController mController;
|
||||
private AccessPoint mAccessPoint;
|
||||
private boolean mEdit;
|
||||
|
||||
// Stores an View id to be focused. Used when view isn't available while setFocus() is called.
|
||||
private int mFocusId = -1;
|
||||
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
public WifiConfigPreference(WifiSettings wifiSettings,
|
||||
DialogInterface.OnClickListener listener,
|
||||
AccessPoint accessPoint, boolean edit) {
|
||||
super(wifiSettings.getActivity());
|
||||
mWifiSettings = wifiSettings;
|
||||
// setLayoutResource(R.layout.wifi_config_preference);
|
||||
setLayoutResource(R.layout.wifi_config_preference2);
|
||||
mListener = listener;
|
||||
mAccessPoint = accessPoint;
|
||||
mEdit = edit;
|
||||
mInflater = (LayoutInflater)
|
||||
wifiSettings.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View onCreateView(ViewGroup parent) {
|
||||
// Called every time the list is created.
|
||||
if (mView == null) {
|
||||
mView = mInflater.inflate(getLayoutResource(), parent, false);
|
||||
mController = new WifiConfigController(this, mView, mAccessPoint, mEdit, mListener);
|
||||
}
|
||||
|
||||
if (mFocusId >= 0) {
|
||||
trySetFocusAndLaunchSoftInput(mFocusId);
|
||||
mFocusId = -1;
|
||||
}
|
||||
|
||||
return mView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WifiConfigController getController() {
|
||||
return mController;
|
||||
}
|
||||
|
||||
public void setFocus(int id) {
|
||||
if (mView != null) {
|
||||
trySetFocusAndLaunchSoftInput(id);
|
||||
mFocusId = -1;
|
||||
} else {
|
||||
mFocusId = id;
|
||||
}
|
||||
}
|
||||
|
||||
private void trySetFocusAndLaunchSoftInput(int id) {
|
||||
final View viewToBeFocused = mView.findViewById(id);
|
||||
if (viewToBeFocused != null && viewToBeFocused.getVisibility() == View.VISIBLE) {
|
||||
viewToBeFocused.requestFocus();
|
||||
// TODO: doesn't work.
|
||||
if (viewToBeFocused instanceof EditText) {
|
||||
Log.d(TAG, "Focused View is EditText. We try showing the software keyboard");
|
||||
// viewToBeFocused.performClick();
|
||||
final InputMethodManager inputMethodManager =
|
||||
(InputMethodManager)
|
||||
getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
inputMethodManager.showSoftInput(viewToBeFocused, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public View findViewById(int id) {
|
||||
return mView.findViewById(id);
|
||||
}
|
||||
|
||||
public AccessPoint getAccessPoint() {
|
||||
return mAccessPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEdit() {
|
||||
return mEdit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LayoutInflater getLayoutInflater() {
|
||||
return mInflater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getSubmitButton() {
|
||||
return (Button)mWifiSettings.getActivity().findViewById(R.id.wifi_setup_connect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getForgetButton() {
|
||||
return (Button)mWifiSettings.getActivity().findViewById(R.id.wifi_setup_forget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getCancelButton() {
|
||||
return (Button)mWifiSettings.getActivity().findViewById(R.id.wifi_setup_cancel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubmitButton(CharSequence text) {
|
||||
final Button button = (Button)
|
||||
mWifiSettings.getActivity().findViewById(R.id.wifi_setup_connect);
|
||||
button.setVisibility(View.VISIBLE);
|
||||
|
||||
// test
|
||||
mWifiSettings.getActivity().findViewById(R.id.wifi_setup_forget).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setForgetButton(CharSequence text) {
|
||||
final Button button = (Button)
|
||||
mWifiSettings.getActivity().findViewById(R.id.wifi_setup_forget);
|
||||
button.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelButton(CharSequence text) {
|
||||
final Button button = (Button)
|
||||
mWifiSettings.getActivity().findViewById(R.id.wifi_setup_cancel);
|
||||
button.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
162
src/com/android/settings/wifi/WifiConfigUiForSetupWizardXL.java
Normal file
162
src/com/android/settings/wifi/WifiConfigUiForSetupWizardXL.java
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
/**
|
||||
* Shows simplified UI for configuring a wifi network. Used only in SetupWizard for XLarge
|
||||
* screen.
|
||||
*/
|
||||
public class WifiConfigUiForSetupWizardXL implements WifiConfigUiBase {
|
||||
private static final String TAG = "WifiConfigPreference";
|
||||
|
||||
private Button mConnectButton;
|
||||
private Button mForgetButton;
|
||||
private Button mCancelButton;
|
||||
|
||||
private final Activity mActivity;
|
||||
private View mView;
|
||||
private WifiConfigController mController;
|
||||
private AccessPoint mAccessPoint;
|
||||
private boolean mEdit;
|
||||
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
/**
|
||||
* @param activity Activity which creates this object.
|
||||
* @param parent Parent ViewGroup (typically some layout) holding a view object created by
|
||||
* this object
|
||||
* @param accessPoint target AccessPoint to be configured.
|
||||
* @param edit
|
||||
*/
|
||||
public WifiConfigUiForSetupWizardXL(
|
||||
Activity activity, ViewGroup parent, AccessPoint accessPoint, boolean edit) {
|
||||
mActivity = activity;
|
||||
mConnectButton = (Button)activity.findViewById(R.id.wifi_setup_connect);
|
||||
mForgetButton = (Button)activity.findViewById(R.id.wifi_setup_forget);
|
||||
mCancelButton = (Button)activity.findViewById(R.id.wifi_setup_cancel);
|
||||
mAccessPoint = accessPoint;
|
||||
mEdit = edit;
|
||||
mInflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
mView = mInflater.inflate(R.layout.wifi_config_ui_for_setup_wizard, parent, false);
|
||||
mController = new WifiConfigController(this, mView, mAccessPoint, edit);
|
||||
trySetFocusAndLaunchSoftInput(R.id.password);
|
||||
}
|
||||
|
||||
private void trySetFocusAndLaunchSoftInput(int id) {
|
||||
final View viewToBeFocused = mView.findViewById(id);
|
||||
if (viewToBeFocused != null && viewToBeFocused.getVisibility() == View.VISIBLE) {
|
||||
viewToBeFocused.requestFocus();
|
||||
// TODO: doesn't work.
|
||||
if (viewToBeFocused instanceof EditText) {
|
||||
Log.d(TAG, "Focused View is EditText. We try showing the software keyboard");
|
||||
// viewToBeFocused.performClick();
|
||||
final InputMethodManager inputMethodManager = (InputMethodManager)
|
||||
mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
inputMethodManager.showSoftInput(viewToBeFocused, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return mView;
|
||||
}
|
||||
|
||||
public AccessPoint getAccessPoint() {
|
||||
return mAccessPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WifiConfigController getController() {
|
||||
return mController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEdit() {
|
||||
return mEdit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LayoutInflater getLayoutInflater() {
|
||||
return mInflater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getSubmitButton() {
|
||||
return mConnectButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getForgetButton() {
|
||||
return mForgetButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getCancelButton() {
|
||||
return mCancelButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubmitButton(CharSequence text) {
|
||||
mConnectButton.setVisibility(View.VISIBLE);
|
||||
mConnectButton.setText(text);
|
||||
|
||||
// test
|
||||
mForgetButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setForgetButton(CharSequence text) {
|
||||
// In XL setup screen, we won't show Forget button for simplifying the UI.
|
||||
// mForgetButton.setVisibility(View.VISIBLE);
|
||||
// mForgetButton.setText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelButton(CharSequence text) {
|
||||
mCancelButton.setVisibility(View.VISIBLE);
|
||||
// We don't want "cancel" label given from caller.
|
||||
// mCancelButton.setText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context getContext() {
|
||||
return mActivity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(int id) {
|
||||
Log.d(TAG, "Ignoring setTitle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(CharSequence title) {
|
||||
Log.d(TAG, "Ignoring setTitle");
|
||||
}
|
||||
}
|
@@ -54,7 +54,7 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase {
|
||||
mView = getLayoutInflater().inflate(R.layout.wifi_dialog, null);
|
||||
setView(mView);
|
||||
setInverseBackgroundForced(true);
|
||||
mController = new WifiConfigController(this, mView, mAccessPoint, mEdit, mListener);
|
||||
mController = new WifiConfigController(this, mView, mAccessPoint, mEdit);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
|
@@ -54,7 +54,6 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -80,21 +79,6 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
private static final int MENU_ID_FORGET = Menu.FIRST + 3;
|
||||
private static final int MENU_ID_MODIFY = Menu.FIRST + 4;
|
||||
|
||||
// Indicates that this fragment is used as a part of Setup Wizard with XL screen settings.
|
||||
// This fragment should show information which has been shown as Dialog in combined UI
|
||||
// inside this fragment.
|
||||
/* package */ static final String IN_XL_SETUP_WIZARD = "in_setup_wizard";
|
||||
|
||||
// this boolean extra specifies whether to disable the Next button when not connected
|
||||
// Note: this is only effective in Setup Wizard with XL screen size.
|
||||
private static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect";
|
||||
|
||||
// In SetupWizard XL, We limit the number of showable access points so that the
|
||||
// ListView won't become larger than the screen.
|
||||
//
|
||||
// This constant doesn't affect other contexts other than SetupWizard XL.
|
||||
private static int MAX_MENU_COUNT_IN_XL = 8;
|
||||
|
||||
private final IntentFilter mFilter;
|
||||
private final BroadcastReceiver mReceiver;
|
||||
private final Scanner mScanner;
|
||||
@@ -113,20 +97,23 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
|
||||
private int mKeyStoreNetworkId = INVALID_NETWORK_ID;
|
||||
|
||||
private WifiDialog mDialog;
|
||||
|
||||
/* Used in Wifi Setup context */
|
||||
|
||||
// this boolean extra specifies whether to disable the Next button when not connected
|
||||
private static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect";
|
||||
|
||||
// Indicates that this fragment is used as a part of Setup Wizard with XL screen settings.
|
||||
// This fragment should show information which has been shown as Dialog in combined UI
|
||||
// inside this fragment.
|
||||
/* package */ static final String IN_XL_SETUP_WIZARD = "in_setup_wizard";
|
||||
|
||||
// should Next button only be enabled when we have a connection?
|
||||
private boolean mEnableNextOnConnection;
|
||||
private boolean mInXlSetupWizard;
|
||||
|
||||
|
||||
// TODO: merge into one
|
||||
private WifiConfigPreference mConfigPreference;
|
||||
private WifiDialog mDialog;
|
||||
|
||||
// Used only in SetupWizard XL, which remembers the network a user selected and
|
||||
// refrain other available networks when trying to connect it.
|
||||
private AccessPoint mConnectingAccessPoint;
|
||||
|
||||
private boolean mRefrainListUpdate;
|
||||
/* End of "used in Wifi Setup context" */
|
||||
|
||||
public WifiSettings() {
|
||||
mFilter = new IntentFilter();
|
||||
@@ -159,11 +146,11 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
final Activity activity = getActivity();
|
||||
final Intent intent = activity.getIntent();
|
||||
|
||||
mInXlSetupWizard = intent.getBooleanExtra(IN_XL_SETUP_WIZARD, false);
|
||||
|
||||
// if we're supposed to enable/disable the Next button based on our current connection
|
||||
// state, start it off in the right state
|
||||
mEnableNextOnConnection = intent.getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false);
|
||||
mInXlSetupWizard = intent.getBooleanExtra(IN_XL_SETUP_WIZARD, false);
|
||||
|
||||
if (mEnableNextOnConnection) {
|
||||
if (mEnableNextOnConnection && hasNextButton()) {
|
||||
@@ -216,33 +203,7 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
mWifiManager.connectNetwork(mKeyStoreNetworkId);
|
||||
}
|
||||
mKeyStoreNetworkId = INVALID_NETWORK_ID;
|
||||
if (mInXlSetupWizard) {
|
||||
// We show "Now scanning"
|
||||
final int wifiState = mWifiManager.getWifiState();
|
||||
switch (wifiState) {
|
||||
case WifiManager.WIFI_STATE_ENABLED: {
|
||||
updateAccessPoints();
|
||||
break;
|
||||
}
|
||||
case WifiManager.WIFI_STATE_DISABLED:
|
||||
case WifiManager.WIFI_STATE_DISABLING:
|
||||
case WifiManager.WIFI_STATE_UNKNOWN: {
|
||||
mWifiManager.setWifiEnabled(true);
|
||||
} // $FALL-THROUGH$
|
||||
default: {
|
||||
mAccessPoints.removeAll();
|
||||
Preference preference = new Preference(getActivity());
|
||||
preference.setLayoutResource(R.layout.preference_widget_shortcut);
|
||||
preference.setSelectable(false);
|
||||
preference.setTitle("Connecting");
|
||||
preference.setSummary("COONNECTING");
|
||||
mAccessPoints.addPreference(preference);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
updateAccessPoints();
|
||||
}
|
||||
updateAccessPoints();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -359,59 +320,18 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a user clicks "Add network" preference or relevant button.
|
||||
* Shows an appropriate Wifi configuration component.
|
||||
* Called when a user clicks "Add network" preference or one of available networks is selected.
|
||||
*/
|
||||
private void showConfigUi(AccessPoint accessPoint, boolean edit) {
|
||||
synchronized (this) {
|
||||
mRefrainListUpdate = false;
|
||||
}
|
||||
mEdit = edit;
|
||||
if (mInXlSetupWizard) {
|
||||
final Activity activity = getActivity();
|
||||
activity.findViewById(R.id.wifi_setup_connect).setVisibility(View.VISIBLE);
|
||||
activity.findViewById(R.id.wifi_setup_cancel).setVisibility(View.VISIBLE);
|
||||
activity.findViewById(R.id.wifi_setup_detail).setVisibility(View.VISIBLE);
|
||||
showConfigPreference(accessPoint, edit);
|
||||
((WifiSettingsForSetupWizardXL)getActivity()).showConfigUi(accessPoint, edit);
|
||||
} else {
|
||||
showDialog(accessPoint, edit);
|
||||
}
|
||||
}
|
||||
|
||||
private void showConfigPreference(AccessPoint accessPoint, boolean edit) {
|
||||
// We don't want to show more than one WifiConfigPreference
|
||||
if (mConfigPreference != null) {
|
||||
mAccessPoints.removePreference(mConfigPreference);
|
||||
}
|
||||
|
||||
mConfigPreference = new WifiConfigPreference(this, this, accessPoint, edit);
|
||||
toggleButtonsVisibility(false);
|
||||
final Activity activity = getActivity();
|
||||
if (activity instanceof WifiSettingsForSetupWizardXL) {
|
||||
((WifiSettingsForSetupWizardXL)activity).onWifiConfigPreferenceAttached(edit);
|
||||
}
|
||||
updateAccessPoints();
|
||||
mScanner.pause();
|
||||
}
|
||||
|
||||
private void toggleButtonsVisibility(boolean firstLayout) {
|
||||
final Activity activity = getActivity();
|
||||
if (firstLayout) {
|
||||
activity.findViewById(R.id.wifi_setup_add_network).setVisibility(View.VISIBLE);
|
||||
activity.findViewById(R.id.wifi_setup_refresh_list).setVisibility(View.VISIBLE);
|
||||
activity.findViewById(R.id.wifi_setup_skip_or_next).setVisibility(View.VISIBLE);
|
||||
activity.findViewById(R.id.wifi_setup_connect).setVisibility(View.GONE);
|
||||
activity.findViewById(R.id.wifi_setup_forget).setVisibility(View.GONE);
|
||||
activity.findViewById(R.id.wifi_setup_cancel).setVisibility(View.GONE);
|
||||
activity.findViewById(R.id.wifi_setup_detail).setVisibility(View.GONE);
|
||||
} else {
|
||||
activity.findViewById(R.id.wifi_setup_add_network).setVisibility(View.GONE);
|
||||
activity.findViewById(R.id.wifi_setup_refresh_list).setVisibility(View.GONE);
|
||||
activity.findViewById(R.id.wifi_setup_skip_or_next).setVisibility(View.GONE);
|
||||
|
||||
// made visible from controller.
|
||||
}
|
||||
}
|
||||
|
||||
private void showDialog(AccessPoint accessPoint, boolean edit) {
|
||||
if (mDialog != null) {
|
||||
mDialog.dismiss();
|
||||
@@ -420,6 +340,11 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
mDialog.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from {@link WifiSettingsForSetupWizardXL} when the object wants to open
|
||||
* {@link WifiDialog} anyway, though usually it prepares its own simplified UI for
|
||||
* configuring a wifi network.
|
||||
*/
|
||||
/* package */ void showDialogForSelectedPreference() {
|
||||
showDialog(mSelectedAccessPoint, mEdit);
|
||||
}
|
||||
@@ -439,41 +364,16 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
* the strength of network and the security for it.
|
||||
*/
|
||||
private void updateAccessPoints() {
|
||||
synchronized (this) {
|
||||
if (mRefrainListUpdate) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mAccessPoints.removeAll();
|
||||
if (mConnectingAccessPoint != null) {
|
||||
mAccessPoints.addPreference(mConnectingAccessPoint);
|
||||
} else if (mConfigPreference != null) {
|
||||
final AccessPoint parent = mConfigPreference.getAccessPoint();
|
||||
if (parent != null) {
|
||||
parent.setSelectable(false);
|
||||
mAccessPoints.addPreference(parent);
|
||||
}
|
||||
mAccessPoints.addPreference(mConfigPreference);
|
||||
} else {
|
||||
// AccessPoints are automatically sorted with TreeSet.
|
||||
final Collection<AccessPoint> accessPoints = constructAccessPoints();
|
||||
|
||||
if (mInXlSetupWizard) {
|
||||
//limit access points on set up wizard
|
||||
int count = MAX_MENU_COUNT_IN_XL;
|
||||
for (AccessPoint accessPoint : accessPoints) {
|
||||
accessPoint.setLayoutResource(R.layout.custom_preference);
|
||||
mAccessPoints.addPreference(accessPoint);
|
||||
count--;
|
||||
if (count <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (AccessPoint accessPoint : accessPoints) {
|
||||
mAccessPoints.addPreference(accessPoint);
|
||||
}
|
||||
// AccessPoints are automatically sorted with TreeSet.
|
||||
final Collection<AccessPoint> accessPoints = constructAccessPoints();
|
||||
if (mInXlSetupWizard) {
|
||||
((WifiSettingsForSetupWizardXL)getActivity()).onAccessPointsUpdated(
|
||||
mAccessPoints, accessPoints);
|
||||
} else {
|
||||
for (AccessPoint accessPoint : accessPoints) {
|
||||
mAccessPoints.addPreference(accessPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -563,13 +463,8 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
final Activity activity = getActivity();
|
||||
if (activity instanceof WifiSettingsForSetupWizardXL) {
|
||||
if (mLastState == DetailedState.FAILED) {
|
||||
// We clean up the status and let users select another network if they want.
|
||||
refreshAccessPoints();
|
||||
}
|
||||
((WifiSettingsForSetupWizardXL)activity).updateConnectionState(mLastState);
|
||||
if (mInXlSetupWizard) {
|
||||
((WifiSettingsForSetupWizardXL)getActivity()).updateConnectionState(mLastState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,9 +481,6 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
private int mRetry = 0;
|
||||
|
||||
void resume() {
|
||||
synchronized (WifiSettings.this) {
|
||||
mRefrainListUpdate = false;
|
||||
}
|
||||
if (!hasMessages(0)) {
|
||||
sendEmptyMessage(0);
|
||||
}
|
||||
@@ -597,9 +489,6 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
void pause() {
|
||||
mRetry = 0;
|
||||
mAccessPoints.setProgress(false);
|
||||
synchronized (WifiSettings.this) {
|
||||
mRefrainListUpdate = true;
|
||||
}
|
||||
removeMessages(0);
|
||||
}
|
||||
|
||||
@@ -619,38 +508,38 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
private void changeNextButtonState(boolean wifiAvailable) {
|
||||
/**
|
||||
* Renames/replaces "Next" button when appropriate. "Next" button usually exists in
|
||||
* Wifi setup screens, not in usual wifi settings screen.
|
||||
*
|
||||
* @param connected true when the device is connected to a wifi network.
|
||||
*/
|
||||
private void changeNextButtonState(boolean connected) {
|
||||
if (mInXlSetupWizard) {
|
||||
final Button button =
|
||||
(Button)getActivity().findViewById(R.id.wifi_setup_skip_or_next);
|
||||
if (wifiAvailable) {
|
||||
button.setText(R.string.wifi_setup_next);
|
||||
} else {
|
||||
button.setText(R.string.wifi_setup_skip);
|
||||
}
|
||||
((WifiSettingsForSetupWizardXL)getActivity()).changeNextButtonState(connected);
|
||||
} else if (mEnableNextOnConnection && hasNextButton()) {
|
||||
// Assumes layout for phones has next button inside it.
|
||||
getNextButton().setEnabled(wifiAvailable);
|
||||
getNextButton().setEnabled(connected);
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick(DialogInterface dialogInterface, int button) {
|
||||
if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) {
|
||||
forget();
|
||||
} else if (button == WifiDialog.BUTTON_SUBMIT) {
|
||||
submit();
|
||||
final Activity activity = getActivity();
|
||||
if (activity instanceof WifiSettingsForSetupWizardXL) {
|
||||
((WifiSettingsForSetupWizardXL)activity).onConnectButtonPressed();
|
||||
if (mInXlSetupWizard) {
|
||||
if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) {
|
||||
((WifiSettingsForSetupWizardXL)getActivity()).onForgetButtonPressed();
|
||||
} else if (button == WifiDialog.BUTTON_SUBMIT) {
|
||||
((WifiSettingsForSetupWizardXL)getActivity()).onConnectButtonPressed();
|
||||
}
|
||||
} else {
|
||||
if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) {
|
||||
forget();
|
||||
} else if (button == WifiDialog.BUTTON_SUBMIT) {
|
||||
submit(mDialog.getController());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* package */ void submit() {
|
||||
final WifiConfigUiBase uiBase = (mDialog != null ? mDialog : mConfigPreference);
|
||||
final WifiConfigController configController = uiBase.getController();
|
||||
|
||||
boolean successful = true;
|
||||
/* package */ void submit(WifiConfigController configController) {
|
||||
switch(configController.chosenNetworkSetupMethod()) {
|
||||
case WifiConfigController.WPS_PBC:
|
||||
mWifiManager.startWpsPbc(mSelectedAccessPoint.bssid);
|
||||
@@ -662,10 +551,10 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
case WifiConfigController.WPS_PIN_FROM_DEVICE:
|
||||
int pin = mWifiManager.startWpsWithPinFromDevice(mSelectedAccessPoint.bssid);
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.wifi_wps_pin_method_configuration)
|
||||
.setMessage(getResources().getString(R.string.wifi_wps_pin_output, pin))
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
.setTitle(R.string.wifi_wps_pin_method_configuration)
|
||||
.setMessage(getResources().getString(R.string.wifi_wps_pin_output, pin))
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
break;
|
||||
case WifiConfigController.MANUAL:
|
||||
final WifiConfiguration config = configController.getConfig();
|
||||
@@ -675,15 +564,13 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
&& !requireKeyStore(mSelectedAccessPoint.getConfig())
|
||||
&& mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
|
||||
mWifiManager.connectNetwork(mSelectedAccessPoint.networkId);
|
||||
} else {
|
||||
successful = false;
|
||||
}
|
||||
} else if (config.networkId != INVALID_NETWORK_ID) {
|
||||
if (mSelectedAccessPoint != null) {
|
||||
mWifiManager.saveNetwork(config);
|
||||
}
|
||||
} else {
|
||||
if (uiBase.isEdit() || requireKeyStore(config)) {
|
||||
if (configController.isEdit() || requireKeyStore(config)) {
|
||||
mWifiManager.saveNetwork(config);
|
||||
} else {
|
||||
mWifiManager.connectNetwork(config);
|
||||
@@ -692,63 +579,42 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
break;
|
||||
}
|
||||
|
||||
if (mInXlSetupWizard && successful && mConfigPreference != null) {
|
||||
// Now connecting to the AccessPoint.
|
||||
mConnectingAccessPoint = mSelectedAccessPoint;
|
||||
mConnectingAccessPoint.setSelectable(false);
|
||||
if (mWifiManager.isWifiEnabled()) {
|
||||
mScanner.resume();
|
||||
}
|
||||
|
||||
detachConfigPreference();
|
||||
updateAccessPoints();
|
||||
}
|
||||
|
||||
/* package */ void forget() {
|
||||
mWifiManager.forgetNetwork(mSelectedAccessPoint.networkId);
|
||||
|
||||
detachConfigPreference();
|
||||
|
||||
changeNextButtonState(false);
|
||||
|
||||
final Activity activity = getActivity();
|
||||
if (activity instanceof WifiSettingsForSetupWizardXL) {
|
||||
((WifiSettingsForSetupWizardXL)activity).onForget();
|
||||
if (mWifiManager.isWifiEnabled()) {
|
||||
mScanner.resume();
|
||||
}
|
||||
updateAccessPoints();
|
||||
|
||||
// We need to rename/replace "Next" button in wifi setup context.
|
||||
changeNextButtonState(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes acccess points and ask Wifi module to scan networks again.
|
||||
*/
|
||||
/* package */ void refreshAccessPoints() {
|
||||
mWifiManager.disconnect();
|
||||
if (mWifiManager.isWifiEnabled()) {
|
||||
mScanner.resume();
|
||||
}
|
||||
|
||||
mConfigPreference = null;
|
||||
mConnectingAccessPoint = null;
|
||||
mAccessPoints.removeAll();
|
||||
|
||||
if (mInXlSetupWizard) {
|
||||
((WifiSettingsForSetupWizardXL)getActivity()).onRefreshAccessPoints();
|
||||
}
|
||||
}
|
||||
|
||||
/* package */ void detachConfigPreference() {
|
||||
if (mConfigPreference != null) {
|
||||
if (mWifiManager.isWifiEnabled()) {
|
||||
mScanner.resume();
|
||||
}
|
||||
mAccessPoints.removePreference(mConfigPreference);
|
||||
mConfigPreference = null;
|
||||
updateAccessPoints();
|
||||
toggleButtonsVisibility(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when "add network" button is pressed.
|
||||
*/
|
||||
/* package */ void onAddNetworkPressed() {
|
||||
// No exact access point is selected.
|
||||
mSelectedAccessPoint = null;
|
||||
showConfigUi(null, true);
|
||||
|
||||
// Set focus to the EditText the user needs to configure.
|
||||
if (mConfigPreference != null) {
|
||||
mConfigPreference.setFocus(R.id.ssid);
|
||||
}
|
||||
}
|
||||
|
||||
/* package */ int getAccessPointsCount() {
|
||||
@@ -759,7 +625,21 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
/* package */ void disableWifi() {
|
||||
mWifiManager.setWifiEnabled(false);
|
||||
/**
|
||||
* Requests wifi module to pause wifi scan. May be ignored when the module is disabled.
|
||||
*/
|
||||
/* package */ void pauseWifiScan() {
|
||||
if (mWifiManager.isWifiEnabled()) {
|
||||
mScanner.pause();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests wifi module to resume wifi scan. May be ignored when the module is disabled.
|
||||
*/
|
||||
/* package */ void resumeWifiScan() {
|
||||
if (mWifiManager.isWifiEnabled()) {
|
||||
mScanner.resume();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,27 +21,36 @@ import com.android.settings.R;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.net.NetworkInfo.DetailedState;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
|
||||
/**
|
||||
* WifiSetings Activity specific for SetupWizard with X-Large screen size.
|
||||
*/
|
||||
public class WifiSettingsForSetupWizardXL extends Activity implements OnClickListener {
|
||||
private static final String TAG = WifiSettingsForSetupWizardXL.class.getSimpleName();
|
||||
private static final String TAG = "SetupWizard";
|
||||
|
||||
// We limit the number of showable access points so that the ListView won't become larger
|
||||
// than the screen.
|
||||
private static int MAX_MENU_COUNT_IN_XL = 8;
|
||||
|
||||
private static final EnumMap<DetailedState, DetailedState> stateMap =
|
||||
new EnumMap<DetailedState, DetailedState>(DetailedState.class);
|
||||
new EnumMap<DetailedState, DetailedState>(DetailedState.class);
|
||||
|
||||
static {
|
||||
stateMap.put(DetailedState.IDLE, DetailedState.DISCONNECTED);
|
||||
@@ -56,11 +65,29 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
||||
stateMap.put(DetailedState.FAILED, DetailedState.FAILED);
|
||||
}
|
||||
|
||||
private WifiManager mWifiManager;
|
||||
|
||||
private TextView mProgressText;
|
||||
private ProgressBar mProgressBar;
|
||||
private WifiSettings mWifiSettings;
|
||||
private TextView mStatusText;
|
||||
|
||||
private Button mAddNetworkButton;
|
||||
private Button mRefreshButton;
|
||||
private Button mSkipOrNextButton;
|
||||
private Button mConnectButton;
|
||||
private Button mForgetButton;
|
||||
private Button mBackButton;
|
||||
|
||||
// Not used now.
|
||||
private Button mDetailButton;
|
||||
|
||||
// true when a user already pressed "Connect" button and waiting for connection.
|
||||
// Also true when the device is already connected to a wifi network on launch.
|
||||
private boolean mAfterTryConnect;
|
||||
|
||||
private WifiConfigUiForSetupWizardXL mWifiConfig;
|
||||
|
||||
private InputMethodManager mInputMethodManager;
|
||||
|
||||
// This count reduces every time when there's a notification about WiFi status change.
|
||||
@@ -82,6 +109,10 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.wifi_settings_for_setup_wizard_xl);
|
||||
|
||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
||||
|
||||
mWifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
|
||||
mWifiSettings =
|
||||
(WifiSettings)getFragmentManager().findFragmentById(R.id.wifi_setup_fragment);
|
||||
mInputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
@@ -100,48 +131,54 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
||||
mProgressBar.setIndeterminate(true);
|
||||
mStatusText.setText(R.string.wifi_setup_status_scanning);
|
||||
|
||||
((Button)findViewById(R.id.wifi_setup_refresh_list)).setOnClickListener(this);
|
||||
((Button)findViewById(R.id.wifi_setup_add_network)).setOnClickListener(this);
|
||||
((Button)findViewById(R.id.wifi_setup_skip_or_next)).setOnClickListener(this);
|
||||
((Button)findViewById(R.id.wifi_setup_connect)).setOnClickListener(this);
|
||||
((Button)findViewById(R.id.wifi_setup_forget)).setOnClickListener(this);
|
||||
((Button)findViewById(R.id.wifi_setup_cancel)).setOnClickListener(this);
|
||||
((Button)findViewById(R.id.wifi_setup_detail)).setOnClickListener(this);
|
||||
mAddNetworkButton = (Button)findViewById(R.id.wifi_setup_add_network);
|
||||
mAddNetworkButton.setOnClickListener(this);
|
||||
mRefreshButton = (Button)findViewById(R.id.wifi_setup_refresh_list);
|
||||
mRefreshButton.setOnClickListener(this);
|
||||
mSkipOrNextButton = (Button)findViewById(R.id.wifi_setup_skip_or_next);
|
||||
mSkipOrNextButton.setOnClickListener(this);
|
||||
mConnectButton = (Button)findViewById(R.id.wifi_setup_connect);
|
||||
mConnectButton.setOnClickListener(this);
|
||||
mForgetButton = (Button)findViewById(R.id.wifi_setup_forget);
|
||||
mForgetButton.setOnClickListener(this);
|
||||
mBackButton = (Button)findViewById(R.id.wifi_setup_cancel);
|
||||
mBackButton.setOnClickListener(this);
|
||||
mDetailButton = (Button)findViewById(R.id.wifi_setup_detail);
|
||||
mDetailButton.setOnClickListener(this);
|
||||
}
|
||||
|
||||
private void restoreFirstButtonVisibilityState() {
|
||||
mAddNetworkButton.setVisibility(View.VISIBLE);
|
||||
mRefreshButton.setVisibility(View.VISIBLE);
|
||||
mSkipOrNextButton.setVisibility(View.VISIBLE);
|
||||
mConnectButton.setVisibility(View.GONE);
|
||||
mForgetButton.setVisibility(View.GONE);
|
||||
mBackButton.setVisibility(View.GONE);
|
||||
mDetailButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final int id = view.getId();
|
||||
switch (id) {
|
||||
case R.id.wifi_setup_refresh_list:
|
||||
mWifiSettings.refreshAccessPoints();
|
||||
break;
|
||||
case R.id.wifi_setup_add_network:
|
||||
mWifiSettings.onAddNetworkPressed();
|
||||
break;
|
||||
case R.id.wifi_setup_skip_or_next:
|
||||
if (view == mAddNetworkButton) {
|
||||
onAddNetworkButtonPressed();
|
||||
} else if (view == mRefreshButton) {
|
||||
refreshAccessPoints(true);
|
||||
} else if (view == mSkipOrNextButton) {
|
||||
if (TextUtils.equals(getString(R.string.wifi_setup_skip), ((Button)view).getText())) {
|
||||
// We don't want to let Wifi enabled when a user press skip without choosing
|
||||
// any access point.
|
||||
mWifiSettings.disableWifi();
|
||||
mWifiManager.setWifiEnabled(false);
|
||||
}
|
||||
setResult(Activity.RESULT_OK);
|
||||
finish();
|
||||
break;
|
||||
case R.id.wifi_setup_connect:
|
||||
mWifiSettings.submit();
|
||||
} else if (view == mConnectButton) {
|
||||
onConnectButtonPressed();
|
||||
break;
|
||||
case R.id.wifi_setup_forget:
|
||||
mWifiSettings.forget();
|
||||
break;
|
||||
case R.id.wifi_setup_cancel:
|
||||
mStatusText.setText(R.string.wifi_setup_status_select_network);
|
||||
mWifiSettings.detachConfigPreference();
|
||||
break;
|
||||
case R.id.wifi_setup_detail:
|
||||
} else if (view == mForgetButton) {
|
||||
onForgetButtonPressed();
|
||||
} else if (view == mBackButton) {
|
||||
onBackButtonPressed();
|
||||
} else if (view == mDetailButton) {
|
||||
mWifiSettings.showDialogForSelectedPreference();
|
||||
break;
|
||||
}
|
||||
hideSoftwareKeyboard();
|
||||
}
|
||||
@@ -157,6 +194,13 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
||||
// Called from WifiSettings
|
||||
/* package */ void updateConnectionState(DetailedState originalState) {
|
||||
final DetailedState state = stateMap.get(originalState);
|
||||
|
||||
if (originalState == DetailedState.FAILED) {
|
||||
// We clean up the current connectivity status and let users select another network
|
||||
// if they want.
|
||||
refreshAccessPoints(true);
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case SCANNING: {
|
||||
// Let users know the device is working correctly though currently there's
|
||||
@@ -165,7 +209,7 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
||||
mProgressBar.setIndeterminate(true);
|
||||
mProgressText.setText(Summary.get(this, DetailedState.SCANNING));
|
||||
} else {
|
||||
// Users already already connected to a network, or see available networks.
|
||||
// Users already connected to a network, or see available networks.
|
||||
mProgressBar.setIndeterminate(false);
|
||||
}
|
||||
break;
|
||||
@@ -180,15 +224,18 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
||||
mProgressBar.setProgress(2);
|
||||
mProgressText.setText(Summary.get(this, state));
|
||||
mStatusText.setText(R.string.wifi_setup_status_proceed_to_next);
|
||||
// We don't want "Add network" button here. User can press it after pressing
|
||||
// "Refresh" button.
|
||||
((Button)findViewById(R.id.wifi_setup_refresh_list)).setEnabled(true);
|
||||
((Button)findViewById(R.id.wifi_setup_skip_or_next)).setEnabled(true);
|
||||
|
||||
mAddNetworkButton.setVisibility(View.GONE);
|
||||
mRefreshButton.setVisibility(View.GONE);
|
||||
mBackButton.setVisibility(View.VISIBLE);
|
||||
mSkipOrNextButton.setVisibility(View.VISIBLE);
|
||||
mSkipOrNextButton.setEnabled(true);
|
||||
|
||||
if (mIgnoringWifiNotificationCount > 0) {
|
||||
// The network is already available before doing anything. We avoid skip this
|
||||
// screen to avoid unnecessary trouble by doing so.
|
||||
mIgnoringWifiNotificationCount = 0;
|
||||
mAfterTryConnect = true;
|
||||
} else {
|
||||
mProgressText.setText(Summary.get(this, state));
|
||||
// setResult(Activity.RESULT_OK);
|
||||
@@ -201,23 +248,42 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
||||
mProgressBar.setProgress(0);
|
||||
mStatusText.setText(R.string.wifi_setup_status_select_network);
|
||||
mProgressText.setText(Summary.get(this, state));
|
||||
enableButtons();
|
||||
|
||||
restoreFirstButtonVisibilityState();
|
||||
mAddNetworkButton.setEnabled(true);
|
||||
mRefreshButton.setEnabled(true);
|
||||
mSkipOrNextButton.setEnabled(true);
|
||||
break;
|
||||
}
|
||||
default: // Not connected.
|
||||
if (mWifiSettings.getAccessPointsCount() == 0 && mIgnoringWifiNotificationCount > 0) {
|
||||
Log.d(TAG, "Currently not connected, but we show \"Scanning\" for a moment");
|
||||
mIgnoringWifiNotificationCount--;
|
||||
mProgressBar.setIndeterminate(true);
|
||||
mProgressText.setText(Summary.get(this, DetailedState.SCANNING));
|
||||
} else if (mShowingConnectingMessageManually && mIgnoringWifiNotificationCount > 0) {
|
||||
Log.i(TAG, "Currently not connected, but we show \"connecting\" for a moment.");
|
||||
mIgnoringWifiNotificationCount--;
|
||||
showConnectingStatus();
|
||||
} else {
|
||||
if (mAfterTryConnect) {
|
||||
// TODO: how to stop connecting the network?
|
||||
Log.i(TAG, String.format(
|
||||
"State %s has been notified after trying to connect a network. ",
|
||||
state.toString()));
|
||||
}
|
||||
|
||||
|
||||
mShowingConnectingMessageManually = false;
|
||||
mProgressBar.setIndeterminate(false);
|
||||
mProgressBar.setProgress(0);
|
||||
|
||||
mStatusText.setText(R.string.wifi_setup_not_connected);
|
||||
mProgressText.setText(getString(R.string.wifi_setup_not_connected));
|
||||
enableButtons();
|
||||
|
||||
mAddNetworkButton.setEnabled(true);
|
||||
mRefreshButton.setEnabled(true);
|
||||
mSkipOrNextButton.setEnabled(true);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -231,40 +297,168 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
||||
mProgressText.setText(Summary.get(this, DetailedState.CONNECTING));
|
||||
}
|
||||
|
||||
private void enableButtons() {
|
||||
((Button)findViewById(R.id.wifi_setup_refresh_list)).setEnabled(true);
|
||||
((Button)findViewById(R.id.wifi_setup_add_network)).setEnabled(true);
|
||||
((Button)findViewById(R.id.wifi_setup_skip_or_next)).setEnabled(true);
|
||||
private void onAddNetworkButtonPressed() {
|
||||
// onConfigUiShown() will be called.
|
||||
mWifiSettings.onAddNetworkPressed();
|
||||
|
||||
// We don't need detail button since all the details are in the main screen.
|
||||
mDetailButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void onWifiConfigPreferenceAttached(boolean isNewNetwork) {
|
||||
/**
|
||||
* Called when the screen enters wifi configuration UI. UI widget for configuring network
|
||||
* (a.k.a. ConfigPreference) should be taken care of by caller side.
|
||||
* This method should handle buttons' visibility/enabled.
|
||||
* @param selectedAccessPoint AccessPoint object being selected. null when a user pressed
|
||||
* "Add network" button, meaning there's no selected access point.
|
||||
*/
|
||||
/* package */ void showConfigUi(AccessPoint selectedAccessPoint, boolean edit) {
|
||||
// We don't want to keep scanning Wi-Fi networks during users' configuring one network.
|
||||
mWifiSettings.pauseWifiScan();
|
||||
|
||||
findViewById(R.id.wifi_setup).setVisibility(View.GONE);
|
||||
final ViewGroup parent = (ViewGroup)findViewById(R.id.wifi_config_ui);
|
||||
parent.setVisibility(View.VISIBLE);
|
||||
parent.removeAllViews();
|
||||
mWifiConfig = new WifiConfigUiForSetupWizardXL(this, parent, selectedAccessPoint, edit);
|
||||
final View view = mWifiConfig.getView();
|
||||
if (selectedAccessPoint != null) {
|
||||
view.findViewById(R.id.wifi_general_info).setVisibility(View.VISIBLE);
|
||||
((TextView)view.findViewById(R.id.title)).setText(selectedAccessPoint.getTitle());
|
||||
((TextView)view.findViewById(R.id.summary)).setText(selectedAccessPoint.getSummary());
|
||||
} else {
|
||||
view.findViewById(R.id.wifi_general_info).setVisibility(View.GONE);
|
||||
}
|
||||
parent.addView(view);
|
||||
|
||||
mStatusText.setText(R.string.wifi_setup_status_edit_network);
|
||||
mAddNetworkButton.setVisibility(View.GONE);
|
||||
mRefreshButton.setVisibility(View.GONE);
|
||||
mSkipOrNextButton.setVisibility(View.GONE);
|
||||
mConnectButton.setVisibility(View.VISIBLE);
|
||||
mConnectButton.setVisibility(View.VISIBLE);
|
||||
mBackButton.setVisibility(View.VISIBLE);
|
||||
// TODO: remove this after UI fix.
|
||||
// mDetailButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void onForget() {
|
||||
// May be called when user press "connect" button in WifiDialog
|
||||
/* package */ void onConnectButtonPressed() {
|
||||
mAfterTryConnect = true;
|
||||
|
||||
mWifiSettings.submit(mWifiConfig.getController());
|
||||
|
||||
// updateConnectionState() isn't called soon after the user's "connect" action,
|
||||
// and the user still sees "not connected" message for a while, which looks strange.
|
||||
// We instead manually show "connecting" message before the system gets actual
|
||||
// "connecting" message from Wi-Fi module.
|
||||
showConnectingStatus();
|
||||
|
||||
// Might be better to delay showing this button.
|
||||
mBackButton.setVisibility(View.VISIBLE);
|
||||
|
||||
findViewById(R.id.wps_fields).setVisibility(View.GONE);
|
||||
findViewById(R.id.security_fields).setVisibility(View.GONE);
|
||||
findViewById(R.id.type).setVisibility(View.GONE);
|
||||
|
||||
mSkipOrNextButton.setVisibility(View.VISIBLE);
|
||||
mSkipOrNextButton.setEnabled(false);
|
||||
mConnectButton.setVisibility(View.GONE);
|
||||
mAddNetworkButton.setVisibility(View.GONE);
|
||||
mRefreshButton.setVisibility(View.GONE);
|
||||
mDetailButton.setVisibility(View.GONE);
|
||||
|
||||
mShowingConnectingMessageManually = true;
|
||||
mIgnoringWifiNotificationCount = 1;
|
||||
}
|
||||
|
||||
// May be called when user press "forget" button in WifiDialog
|
||||
/* package */ void onForgetButtonPressed() {
|
||||
mWifiSettings.forget();
|
||||
|
||||
refreshAccessPoints(false);
|
||||
restoreFirstButtonVisibilityState();
|
||||
mAddNetworkButton.setEnabled(true);
|
||||
mRefreshButton.setEnabled(true);
|
||||
mSkipOrNextButton.setEnabled(true);
|
||||
|
||||
mProgressBar.setIndeterminate(false);
|
||||
mProgressBar.setProgress(0);
|
||||
mProgressText.setText(getString(R.string.wifi_setup_not_connected));
|
||||
}
|
||||
|
||||
public void onRefreshAccessPoints() {
|
||||
private void onBackButtonPressed() {
|
||||
if (mAfterTryConnect) {
|
||||
mAfterTryConnect = false;
|
||||
|
||||
// When a user press "Back" button after pressing "Connect" button, we want to cancel
|
||||
// the "Connect" request and refresh the whole wifi status.
|
||||
restoreFirstButtonVisibilityState();
|
||||
mShowingConnectingMessageManually = false;
|
||||
|
||||
mAddNetworkButton.setEnabled(false);
|
||||
mRefreshButton.setEnabled(false);
|
||||
mSkipOrNextButton.setEnabled(true);
|
||||
|
||||
refreshAccessPoints(true);
|
||||
} else { // During user's Wifi configuration.
|
||||
mWifiSettings.resumeWifiScan();
|
||||
|
||||
mStatusText.setText(R.string.wifi_setup_status_select_network);
|
||||
restoreFirstButtonVisibilityState();
|
||||
|
||||
mAddNetworkButton.setEnabled(true);
|
||||
mRefreshButton.setEnabled(true);
|
||||
mSkipOrNextButton.setEnabled(true);
|
||||
}
|
||||
|
||||
findViewById(R.id.wifi_setup).setVisibility(View.VISIBLE);
|
||||
final ViewGroup parent = (ViewGroup)findViewById(R.id.wifi_config_ui);
|
||||
parent.removeAllViews();
|
||||
parent.setVisibility(View.GONE);
|
||||
mWifiConfig = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param connected true when the device is connected to a specific network.
|
||||
*/
|
||||
/* package */ void changeNextButtonState(boolean connected) {
|
||||
if (connected) {
|
||||
mSkipOrNextButton.setText(R.string.wifi_setup_next);
|
||||
} else {
|
||||
mSkipOrNextButton.setText(R.string.wifi_setup_skip);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the list of AccessPoints are modified and this Activity needs to refresh
|
||||
* the list.
|
||||
*/
|
||||
/* package */ void onAccessPointsUpdated(
|
||||
PreferenceCategory holder, Collection<AccessPoint> accessPoints) {
|
||||
int count = MAX_MENU_COUNT_IN_XL;
|
||||
for (AccessPoint accessPoint : accessPoints) {
|
||||
accessPoint.setLayoutResource(R.layout.custom_preference);
|
||||
holder.addPreference(accessPoint);
|
||||
count--;
|
||||
if (count <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshAccessPoints(boolean disconnectNetwork) {
|
||||
mIgnoringWifiNotificationCount = 5;
|
||||
mProgressBar.setIndeterminate(true);
|
||||
((Button)findViewById(R.id.wifi_setup_add_network)).setEnabled(false);
|
||||
((Button)findViewById(R.id.wifi_setup_refresh_list)).setEnabled(false);
|
||||
mProgressText.setText(Summary.get(this, DetailedState.SCANNING));
|
||||
mStatusText.setText(R.string.wifi_setup_status_scanning);
|
||||
}
|
||||
|
||||
/* package */ void onConnectButtonPressed() {
|
||||
// updateConnectionState() isn't called soon after the user's "connect" action,
|
||||
// and the user still sees "not connected" message for a while, which looks strange.
|
||||
// We instead manually show "connecting" message before the system gets actual
|
||||
// "connecting" message from Wi-Fi module.
|
||||
showConnectingStatus();
|
||||
((Button)findViewById(R.id.wifi_setup_add_network)).setEnabled(false);
|
||||
((Button)findViewById(R.id.wifi_setup_refresh_list)).setEnabled(false);
|
||||
mShowingConnectingMessageManually = true;
|
||||
mIgnoringWifiNotificationCount = 2;
|
||||
if (disconnectNetwork) {
|
||||
mWifiManager.disconnect();
|
||||
}
|
||||
|
||||
mWifiSettings.refreshAccessPoints();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user