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
|
<FrameLayout
|
||||||
android:id="@+id/wifi_setup"
|
android:id="@+id/wifi_setup"
|
||||||
android:layout_width="400dip"
|
android:layout_width="400dip"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_below="@+id/wifi_setup_status">
|
android:layout_below="@+id/wifi_setup_status">
|
||||||
<fragment
|
<fragment
|
||||||
@@ -84,6 +84,23 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
</FrameLayout>
|
</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
|
<LinearLayout
|
||||||
android:id="@+id/right_buttons"
|
android:id="@+id/right_buttons"
|
||||||
@@ -97,7 +114,7 @@
|
|||||||
android:layout_width="260dip"
|
android:layout_width="260dip"
|
||||||
android:layout_height="60dip"
|
android:layout_height="60dip"
|
||||||
android:textSize="24dip"
|
android:textSize="24dip"
|
||||||
android:text="@string/wifi_forget"
|
android:text="@string/wifi_setup_forget"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<Button android:id="@+id/wifi_setup_connect"
|
<Button android:id="@+id/wifi_setup_connect"
|
||||||
@@ -105,7 +122,8 @@
|
|||||||
android:layout_height="60dip"
|
android:layout_height="60dip"
|
||||||
android:layout_marginTop="20dip"
|
android:layout_marginTop="20dip"
|
||||||
android:textSize="24dip"
|
android:textSize="24dip"
|
||||||
android:text="@string/wifi_connect"
|
android:text="@string/wifi_setup_connect"
|
||||||
|
android:enabled="false"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<Button android:id="@+id/wifi_setup_add_network"
|
<Button android:id="@+id/wifi_setup_add_network"
|
||||||
@@ -131,15 +149,7 @@
|
|||||||
android:enabled="false" />
|
android:enabled="false" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<Button android:id="@+id/wifi_setup_detail"
|
<!-- This misleading name is for keeping consistency between non-XL layouts -->
|
||||||
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" />
|
|
||||||
|
|
||||||
<Button android:id="@+id/wifi_setup_cancel"
|
<Button android:id="@+id/wifi_setup_cancel"
|
||||||
android:layout_width="260dip"
|
android:layout_width="260dip"
|
||||||
android:layout_height="60dip"
|
android:layout_height="60dip"
|
||||||
@@ -147,6 +157,6 @@
|
|||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_toLeftOf="@id/right_buttons"
|
android:layout_toLeftOf="@id/right_buttons"
|
||||||
android:textSize="24dip"
|
android:textSize="24dip"
|
||||||
android:text="@string/wifi_back"
|
android:text="@string/wifi_setup_back"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
@@ -18,6 +18,28 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="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 -->
|
<!-- UI components that should be shown appropriately -->
|
||||||
<LinearLayout android:id="@+id/wps_fields"
|
<LinearLayout android:id="@+id/wps_fields"
|
||||||
@@ -94,7 +116,7 @@
|
|||||||
<LinearLayout android:id="@+id/info"
|
<LinearLayout android:id="@+id/info"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"/> -->
|
android:orientation="vertical"/>
|
||||||
|
|
||||||
<LinearLayout android:id="@+id/setup_fields"
|
<LinearLayout android:id="@+id/setup_fields"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
@@ -1009,12 +1009,6 @@
|
|||||||
<string name="wifi_save">Save</string>
|
<string name="wifi_save">Save</string>
|
||||||
<!-- Button label to dismiss the dialog -->
|
<!-- Button label to dismiss the dialog -->
|
||||||
<string name="wifi_cancel">Cancel</string>
|
<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 Advanced Settings --> <skip />
|
||||||
<!-- Wi-Fi settings screen, advanced, settings section. This is a header shown above advanced wifi settings. -->
|
<!-- 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.
|
<!-- Button message shown on the button enabling users go the next step.
|
||||||
Used in Wifi Setup For Setup Wizard with XL screen. -->
|
Used in Wifi Setup For Setup Wizard with XL screen. -->
|
||||||
<string name="wifi_setup_next">Next</string>
|
<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
|
<!-- The message shown above available networks when the device is scanning
|
||||||
available networks [CHAR LIMIT=35] -->
|
available networks [CHAR LIMIT=35] -->
|
||||||
<string name="wifi_setup_status_scanning">Scanning networks...</string>
|
<string name="wifi_setup_status_scanning">Scanning networks...</string>
|
||||||
<!-- Message shown above available network when there's no connected network.
|
<!-- Message shown above available network when there's no connected network.
|
||||||
Used in Wifi Setup For Setup Wizard with XL screen. -->
|
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
|
<!-- Message shown above available networks when a user clicked one of available
|
||||||
networks and the UI is showing one possible existing network.
|
networks and the UI is showing one possible existing network.
|
||||||
Used in Wifi Setup. -->
|
Used in Wifi Setup. -->
|
||||||
|
@@ -128,8 +128,8 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WifiConfigController(WifiConfigUiBase parent, View view, AccessPoint accessPoint,
|
public WifiConfigController(
|
||||||
boolean edit, DialogInterface.OnClickListener listener) {
|
WifiConfigUiBase parent, View view, AccessPoint accessPoint, boolean edit) {
|
||||||
mConfigUi = parent;
|
mConfigUi = parent;
|
||||||
|
|
||||||
mView = view;
|
mView = view;
|
||||||
@@ -141,7 +141,7 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
final Context context = mConfigUi.getContext();
|
final Context context = mConfigUi.getContext();
|
||||||
final Resources resources = context.getResources();
|
final Resources resources = context.getResources();
|
||||||
|
|
||||||
if (mAccessPoint == null) {
|
if (mAccessPoint == null) { // new network
|
||||||
mConfigUi.setTitle(R.string.wifi_add_network);
|
mConfigUi.setTitle(R.string.wifi_add_network);
|
||||||
mView.findViewById(R.id.type).setVisibility(View.VISIBLE);
|
mView.findViewById(R.id.type).setVisibility(View.VISIBLE);
|
||||||
mSsidView = (TextView) mView.findViewById(R.id.ssid);
|
mSsidView = (TextView) mView.findViewById(R.id.ssid);
|
||||||
@@ -626,6 +626,10 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEdit() {
|
||||||
|
return mEdit;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
enableSubmitIfAppropriate();
|
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);
|
mView = getLayoutInflater().inflate(R.layout.wifi_dialog, null);
|
||||||
setView(mView);
|
setView(mView);
|
||||||
setInverseBackgroundForced(true);
|
setInverseBackgroundForced(true);
|
||||||
mController = new WifiConfigController(this, mView, mAccessPoint, mEdit, mListener);
|
mController = new WifiConfigController(this, mView, mAccessPoint, mEdit);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,7 +54,6 @@ import android.view.MenuInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.Collection;
|
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_FORGET = Menu.FIRST + 3;
|
||||||
private static final int MENU_ID_MODIFY = Menu.FIRST + 4;
|
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 IntentFilter mFilter;
|
||||||
private final BroadcastReceiver mReceiver;
|
private final BroadcastReceiver mReceiver;
|
||||||
private final Scanner mScanner;
|
private final Scanner mScanner;
|
||||||
@@ -113,20 +97,23 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private int mKeyStoreNetworkId = INVALID_NETWORK_ID;
|
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?
|
// should Next button only be enabled when we have a connection?
|
||||||
private boolean mEnableNextOnConnection;
|
private boolean mEnableNextOnConnection;
|
||||||
private boolean mInXlSetupWizard;
|
private boolean mInXlSetupWizard;
|
||||||
|
|
||||||
|
/* End of "used in Wifi Setup context" */
|
||||||
// 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;
|
|
||||||
|
|
||||||
public WifiSettings() {
|
public WifiSettings() {
|
||||||
mFilter = new IntentFilter();
|
mFilter = new IntentFilter();
|
||||||
@@ -159,11 +146,11 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
final Intent intent = activity.getIntent();
|
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
|
// if we're supposed to enable/disable the Next button based on our current connection
|
||||||
// state, start it off in the right state
|
// state, start it off in the right state
|
||||||
mEnableNextOnConnection = intent.getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false);
|
mEnableNextOnConnection = intent.getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false);
|
||||||
|
mInXlSetupWizard = intent.getBooleanExtra(IN_XL_SETUP_WIZARD, false);
|
||||||
|
|
||||||
if (mEnableNextOnConnection) {
|
if (mEnableNextOnConnection) {
|
||||||
if (mEnableNextOnConnection && hasNextButton()) {
|
if (mEnableNextOnConnection && hasNextButton()) {
|
||||||
@@ -216,33 +203,7 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
mWifiManager.connectNetwork(mKeyStoreNetworkId);
|
mWifiManager.connectNetwork(mKeyStoreNetworkId);
|
||||||
}
|
}
|
||||||
mKeyStoreNetworkId = INVALID_NETWORK_ID;
|
mKeyStoreNetworkId = INVALID_NETWORK_ID;
|
||||||
if (mInXlSetupWizard) {
|
updateAccessPoints();
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
private void showConfigUi(AccessPoint accessPoint, boolean edit) {
|
||||||
synchronized (this) {
|
|
||||||
mRefrainListUpdate = false;
|
|
||||||
}
|
|
||||||
mEdit = edit;
|
mEdit = edit;
|
||||||
if (mInXlSetupWizard) {
|
if (mInXlSetupWizard) {
|
||||||
final Activity activity = getActivity();
|
((WifiSettingsForSetupWizardXL)getActivity()).showConfigUi(accessPoint, edit);
|
||||||
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);
|
|
||||||
} else {
|
} else {
|
||||||
showDialog(accessPoint, edit);
|
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) {
|
private void showDialog(AccessPoint accessPoint, boolean edit) {
|
||||||
if (mDialog != null) {
|
if (mDialog != null) {
|
||||||
mDialog.dismiss();
|
mDialog.dismiss();
|
||||||
@@ -420,6 +340,11 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
mDialog.show();
|
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() {
|
/* package */ void showDialogForSelectedPreference() {
|
||||||
showDialog(mSelectedAccessPoint, mEdit);
|
showDialog(mSelectedAccessPoint, mEdit);
|
||||||
}
|
}
|
||||||
@@ -439,41 +364,16 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
* the strength of network and the security for it.
|
* the strength of network and the security for it.
|
||||||
*/
|
*/
|
||||||
private void updateAccessPoints() {
|
private void updateAccessPoints() {
|
||||||
synchronized (this) {
|
|
||||||
if (mRefrainListUpdate) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mAccessPoints.removeAll();
|
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) {
|
// AccessPoints are automatically sorted with TreeSet.
|
||||||
//limit access points on set up wizard
|
final Collection<AccessPoint> accessPoints = constructAccessPoints();
|
||||||
int count = MAX_MENU_COUNT_IN_XL;
|
if (mInXlSetupWizard) {
|
||||||
for (AccessPoint accessPoint : accessPoints) {
|
((WifiSettingsForSetupWizardXL)getActivity()).onAccessPointsUpdated(
|
||||||
accessPoint.setLayoutResource(R.layout.custom_preference);
|
mAccessPoints, accessPoints);
|
||||||
mAccessPoints.addPreference(accessPoint);
|
} else {
|
||||||
count--;
|
for (AccessPoint accessPoint : accessPoints) {
|
||||||
if (count <= 0) {
|
mAccessPoints.addPreference(accessPoint);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (AccessPoint accessPoint : accessPoints) {
|
|
||||||
mAccessPoints.addPreference(accessPoint);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -563,13 +463,8 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Activity activity = getActivity();
|
if (mInXlSetupWizard) {
|
||||||
if (activity instanceof WifiSettingsForSetupWizardXL) {
|
((WifiSettingsForSetupWizardXL)getActivity()).updateConnectionState(mLastState);
|
||||||
if (mLastState == DetailedState.FAILED) {
|
|
||||||
// We clean up the status and let users select another network if they want.
|
|
||||||
refreshAccessPoints();
|
|
||||||
}
|
|
||||||
((WifiSettingsForSetupWizardXL)activity).updateConnectionState(mLastState);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -586,9 +481,6 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
private int mRetry = 0;
|
private int mRetry = 0;
|
||||||
|
|
||||||
void resume() {
|
void resume() {
|
||||||
synchronized (WifiSettings.this) {
|
|
||||||
mRefrainListUpdate = false;
|
|
||||||
}
|
|
||||||
if (!hasMessages(0)) {
|
if (!hasMessages(0)) {
|
||||||
sendEmptyMessage(0);
|
sendEmptyMessage(0);
|
||||||
}
|
}
|
||||||
@@ -597,9 +489,6 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
void pause() {
|
void pause() {
|
||||||
mRetry = 0;
|
mRetry = 0;
|
||||||
mAccessPoints.setProgress(false);
|
mAccessPoints.setProgress(false);
|
||||||
synchronized (WifiSettings.this) {
|
|
||||||
mRefrainListUpdate = true;
|
|
||||||
}
|
|
||||||
removeMessages(0);
|
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) {
|
if (mInXlSetupWizard) {
|
||||||
final Button button =
|
((WifiSettingsForSetupWizardXL)getActivity()).changeNextButtonState(connected);
|
||||||
(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);
|
|
||||||
}
|
|
||||||
} else if (mEnableNextOnConnection && hasNextButton()) {
|
} else if (mEnableNextOnConnection && hasNextButton()) {
|
||||||
// Assumes layout for phones has next button inside it.
|
getNextButton().setEnabled(connected);
|
||||||
getNextButton().setEnabled(wifiAvailable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(DialogInterface dialogInterface, int button) {
|
public void onClick(DialogInterface dialogInterface, int button) {
|
||||||
if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) {
|
if (mInXlSetupWizard) {
|
||||||
forget();
|
if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) {
|
||||||
} else if (button == WifiDialog.BUTTON_SUBMIT) {
|
((WifiSettingsForSetupWizardXL)getActivity()).onForgetButtonPressed();
|
||||||
submit();
|
} else if (button == WifiDialog.BUTTON_SUBMIT) {
|
||||||
final Activity activity = getActivity();
|
((WifiSettingsForSetupWizardXL)getActivity()).onConnectButtonPressed();
|
||||||
if (activity instanceof WifiSettingsForSetupWizardXL) {
|
}
|
||||||
((WifiSettingsForSetupWizardXL)activity).onConnectButtonPressed();
|
} else {
|
||||||
|
if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) {
|
||||||
|
forget();
|
||||||
|
} else if (button == WifiDialog.BUTTON_SUBMIT) {
|
||||||
|
submit(mDialog.getController());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ void submit() {
|
/* package */ void submit(WifiConfigController configController) {
|
||||||
final WifiConfigUiBase uiBase = (mDialog != null ? mDialog : mConfigPreference);
|
|
||||||
final WifiConfigController configController = uiBase.getController();
|
|
||||||
|
|
||||||
boolean successful = true;
|
|
||||||
switch(configController.chosenNetworkSetupMethod()) {
|
switch(configController.chosenNetworkSetupMethod()) {
|
||||||
case WifiConfigController.WPS_PBC:
|
case WifiConfigController.WPS_PBC:
|
||||||
mWifiManager.startWpsPbc(mSelectedAccessPoint.bssid);
|
mWifiManager.startWpsPbc(mSelectedAccessPoint.bssid);
|
||||||
@@ -662,10 +551,10 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
case WifiConfigController.WPS_PIN_FROM_DEVICE:
|
case WifiConfigController.WPS_PIN_FROM_DEVICE:
|
||||||
int pin = mWifiManager.startWpsWithPinFromDevice(mSelectedAccessPoint.bssid);
|
int pin = mWifiManager.startWpsWithPinFromDevice(mSelectedAccessPoint.bssid);
|
||||||
new AlertDialog.Builder(getActivity())
|
new AlertDialog.Builder(getActivity())
|
||||||
.setTitle(R.string.wifi_wps_pin_method_configuration)
|
.setTitle(R.string.wifi_wps_pin_method_configuration)
|
||||||
.setMessage(getResources().getString(R.string.wifi_wps_pin_output, pin))
|
.setMessage(getResources().getString(R.string.wifi_wps_pin_output, pin))
|
||||||
.setPositiveButton(android.R.string.ok, null)
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
.show();
|
.show();
|
||||||
break;
|
break;
|
||||||
case WifiConfigController.MANUAL:
|
case WifiConfigController.MANUAL:
|
||||||
final WifiConfiguration config = configController.getConfig();
|
final WifiConfiguration config = configController.getConfig();
|
||||||
@@ -675,15 +564,13 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
&& !requireKeyStore(mSelectedAccessPoint.getConfig())
|
&& !requireKeyStore(mSelectedAccessPoint.getConfig())
|
||||||
&& mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
|
&& mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
|
||||||
mWifiManager.connectNetwork(mSelectedAccessPoint.networkId);
|
mWifiManager.connectNetwork(mSelectedAccessPoint.networkId);
|
||||||
} else {
|
|
||||||
successful = false;
|
|
||||||
}
|
}
|
||||||
} else if (config.networkId != INVALID_NETWORK_ID) {
|
} else if (config.networkId != INVALID_NETWORK_ID) {
|
||||||
if (mSelectedAccessPoint != null) {
|
if (mSelectedAccessPoint != null) {
|
||||||
mWifiManager.saveNetwork(config);
|
mWifiManager.saveNetwork(config);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (uiBase.isEdit() || requireKeyStore(config)) {
|
if (configController.isEdit() || requireKeyStore(config)) {
|
||||||
mWifiManager.saveNetwork(config);
|
mWifiManager.saveNetwork(config);
|
||||||
} else {
|
} else {
|
||||||
mWifiManager.connectNetwork(config);
|
mWifiManager.connectNetwork(config);
|
||||||
@@ -692,63 +579,42 @@ public class WifiSettings extends SettingsPreferenceFragment
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mInXlSetupWizard && successful && mConfigPreference != null) {
|
if (mWifiManager.isWifiEnabled()) {
|
||||||
// Now connecting to the AccessPoint.
|
mScanner.resume();
|
||||||
mConnectingAccessPoint = mSelectedAccessPoint;
|
|
||||||
mConnectingAccessPoint.setSelectable(false);
|
|
||||||
}
|
}
|
||||||
|
updateAccessPoints();
|
||||||
detachConfigPreference();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ void forget() {
|
/* package */ void forget() {
|
||||||
mWifiManager.forgetNetwork(mSelectedAccessPoint.networkId);
|
mWifiManager.forgetNetwork(mSelectedAccessPoint.networkId);
|
||||||
|
|
||||||
detachConfigPreference();
|
if (mWifiManager.isWifiEnabled()) {
|
||||||
|
mScanner.resume();
|
||||||
changeNextButtonState(false);
|
|
||||||
|
|
||||||
final Activity activity = getActivity();
|
|
||||||
if (activity instanceof WifiSettingsForSetupWizardXL) {
|
|
||||||
((WifiSettingsForSetupWizardXL)activity).onForget();
|
|
||||||
}
|
}
|
||||||
|
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() {
|
/* package */ void refreshAccessPoints() {
|
||||||
mWifiManager.disconnect();
|
|
||||||
if (mWifiManager.isWifiEnabled()) {
|
if (mWifiManager.isWifiEnabled()) {
|
||||||
mScanner.resume();
|
mScanner.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
mConfigPreference = null;
|
|
||||||
mConnectingAccessPoint = null;
|
|
||||||
mAccessPoints.removeAll();
|
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() {
|
/* package */ void onAddNetworkPressed() {
|
||||||
|
// No exact access point is selected.
|
||||||
mSelectedAccessPoint = null;
|
mSelectedAccessPoint = null;
|
||||||
showConfigUi(null, true);
|
showConfigUi(null, true);
|
||||||
|
|
||||||
// Set focus to the EditText the user needs to configure.
|
|
||||||
if (mConfigPreference != null) {
|
|
||||||
mConfigPreference.setFocus(R.id.ssid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ int getAccessPointsCount() {
|
/* 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.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.NetworkInfo.DetailedState;
|
import android.net.NetworkInfo.DetailedState;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceCategory;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WifiSetings Activity specific for SetupWizard with X-Large screen size.
|
* WifiSetings Activity specific for SetupWizard with X-Large screen size.
|
||||||
*/
|
*/
|
||||||
public class WifiSettingsForSetupWizardXL extends Activity implements OnClickListener {
|
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 =
|
private static final EnumMap<DetailedState, DetailedState> stateMap =
|
||||||
new EnumMap<DetailedState, DetailedState>(DetailedState.class);
|
new EnumMap<DetailedState, DetailedState>(DetailedState.class);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
stateMap.put(DetailedState.IDLE, DetailedState.DISCONNECTED);
|
stateMap.put(DetailedState.IDLE, DetailedState.DISCONNECTED);
|
||||||
@@ -56,11 +65,29 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
|||||||
stateMap.put(DetailedState.FAILED, DetailedState.FAILED);
|
stateMap.put(DetailedState.FAILED, DetailedState.FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private WifiManager mWifiManager;
|
||||||
|
|
||||||
private TextView mProgressText;
|
private TextView mProgressText;
|
||||||
private ProgressBar mProgressBar;
|
private ProgressBar mProgressBar;
|
||||||
private WifiSettings mWifiSettings;
|
private WifiSettings mWifiSettings;
|
||||||
private TextView mStatusText;
|
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;
|
private InputMethodManager mInputMethodManager;
|
||||||
|
|
||||||
// This count reduces every time when there's a notification about WiFi status change.
|
// 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);
|
super.onCreate(savedInstanceState);
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
setContentView(R.layout.wifi_settings_for_setup_wizard_xl);
|
setContentView(R.layout.wifi_settings_for_setup_wizard_xl);
|
||||||
|
|
||||||
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
||||||
|
|
||||||
|
mWifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
|
||||||
mWifiSettings =
|
mWifiSettings =
|
||||||
(WifiSettings)getFragmentManager().findFragmentById(R.id.wifi_setup_fragment);
|
(WifiSettings)getFragmentManager().findFragmentById(R.id.wifi_setup_fragment);
|
||||||
mInputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
mInputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
@@ -100,48 +131,54 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
|||||||
mProgressBar.setIndeterminate(true);
|
mProgressBar.setIndeterminate(true);
|
||||||
mStatusText.setText(R.string.wifi_setup_status_scanning);
|
mStatusText.setText(R.string.wifi_setup_status_scanning);
|
||||||
|
|
||||||
((Button)findViewById(R.id.wifi_setup_refresh_list)).setOnClickListener(this);
|
mAddNetworkButton = (Button)findViewById(R.id.wifi_setup_add_network);
|
||||||
((Button)findViewById(R.id.wifi_setup_add_network)).setOnClickListener(this);
|
mAddNetworkButton.setOnClickListener(this);
|
||||||
((Button)findViewById(R.id.wifi_setup_skip_or_next)).setOnClickListener(this);
|
mRefreshButton = (Button)findViewById(R.id.wifi_setup_refresh_list);
|
||||||
((Button)findViewById(R.id.wifi_setup_connect)).setOnClickListener(this);
|
mRefreshButton.setOnClickListener(this);
|
||||||
((Button)findViewById(R.id.wifi_setup_forget)).setOnClickListener(this);
|
mSkipOrNextButton = (Button)findViewById(R.id.wifi_setup_skip_or_next);
|
||||||
((Button)findViewById(R.id.wifi_setup_cancel)).setOnClickListener(this);
|
mSkipOrNextButton.setOnClickListener(this);
|
||||||
((Button)findViewById(R.id.wifi_setup_detail)).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
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
final int id = view.getId();
|
if (view == mAddNetworkButton) {
|
||||||
switch (id) {
|
onAddNetworkButtonPressed();
|
||||||
case R.id.wifi_setup_refresh_list:
|
} else if (view == mRefreshButton) {
|
||||||
mWifiSettings.refreshAccessPoints();
|
refreshAccessPoints(true);
|
||||||
break;
|
} else if (view == mSkipOrNextButton) {
|
||||||
case R.id.wifi_setup_add_network:
|
|
||||||
mWifiSettings.onAddNetworkPressed();
|
|
||||||
break;
|
|
||||||
case R.id.wifi_setup_skip_or_next:
|
|
||||||
if (TextUtils.equals(getString(R.string.wifi_setup_skip), ((Button)view).getText())) {
|
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
|
// We don't want to let Wifi enabled when a user press skip without choosing
|
||||||
// any access point.
|
// any access point.
|
||||||
mWifiSettings.disableWifi();
|
mWifiManager.setWifiEnabled(false);
|
||||||
}
|
}
|
||||||
setResult(Activity.RESULT_OK);
|
setResult(Activity.RESULT_OK);
|
||||||
finish();
|
finish();
|
||||||
break;
|
} else if (view == mConnectButton) {
|
||||||
case R.id.wifi_setup_connect:
|
|
||||||
mWifiSettings.submit();
|
|
||||||
onConnectButtonPressed();
|
onConnectButtonPressed();
|
||||||
break;
|
} else if (view == mForgetButton) {
|
||||||
case R.id.wifi_setup_forget:
|
onForgetButtonPressed();
|
||||||
mWifiSettings.forget();
|
} else if (view == mBackButton) {
|
||||||
break;
|
onBackButtonPressed();
|
||||||
case R.id.wifi_setup_cancel:
|
} else if (view == mDetailButton) {
|
||||||
mStatusText.setText(R.string.wifi_setup_status_select_network);
|
|
||||||
mWifiSettings.detachConfigPreference();
|
|
||||||
break;
|
|
||||||
case R.id.wifi_setup_detail:
|
|
||||||
mWifiSettings.showDialogForSelectedPreference();
|
mWifiSettings.showDialogForSelectedPreference();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
hideSoftwareKeyboard();
|
hideSoftwareKeyboard();
|
||||||
}
|
}
|
||||||
@@ -157,6 +194,13 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
|||||||
// Called from WifiSettings
|
// Called from WifiSettings
|
||||||
/* package */ void updateConnectionState(DetailedState originalState) {
|
/* package */ void updateConnectionState(DetailedState originalState) {
|
||||||
final DetailedState state = stateMap.get(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) {
|
switch (state) {
|
||||||
case SCANNING: {
|
case SCANNING: {
|
||||||
// Let users know the device is working correctly though currently there's
|
// 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);
|
mProgressBar.setIndeterminate(true);
|
||||||
mProgressText.setText(Summary.get(this, DetailedState.SCANNING));
|
mProgressText.setText(Summary.get(this, DetailedState.SCANNING));
|
||||||
} else {
|
} 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);
|
mProgressBar.setIndeterminate(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -180,15 +224,18 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
|||||||
mProgressBar.setProgress(2);
|
mProgressBar.setProgress(2);
|
||||||
mProgressText.setText(Summary.get(this, state));
|
mProgressText.setText(Summary.get(this, state));
|
||||||
mStatusText.setText(R.string.wifi_setup_status_proceed_to_next);
|
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.
|
mAddNetworkButton.setVisibility(View.GONE);
|
||||||
((Button)findViewById(R.id.wifi_setup_refresh_list)).setEnabled(true);
|
mRefreshButton.setVisibility(View.GONE);
|
||||||
((Button)findViewById(R.id.wifi_setup_skip_or_next)).setEnabled(true);
|
mBackButton.setVisibility(View.VISIBLE);
|
||||||
|
mSkipOrNextButton.setVisibility(View.VISIBLE);
|
||||||
|
mSkipOrNextButton.setEnabled(true);
|
||||||
|
|
||||||
if (mIgnoringWifiNotificationCount > 0) {
|
if (mIgnoringWifiNotificationCount > 0) {
|
||||||
// The network is already available before doing anything. We avoid skip this
|
// The network is already available before doing anything. We avoid skip this
|
||||||
// screen to avoid unnecessary trouble by doing so.
|
// screen to avoid unnecessary trouble by doing so.
|
||||||
mIgnoringWifiNotificationCount = 0;
|
mIgnoringWifiNotificationCount = 0;
|
||||||
|
mAfterTryConnect = true;
|
||||||
} else {
|
} else {
|
||||||
mProgressText.setText(Summary.get(this, state));
|
mProgressText.setText(Summary.get(this, state));
|
||||||
// setResult(Activity.RESULT_OK);
|
// setResult(Activity.RESULT_OK);
|
||||||
@@ -201,23 +248,42 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
|||||||
mProgressBar.setProgress(0);
|
mProgressBar.setProgress(0);
|
||||||
mStatusText.setText(R.string.wifi_setup_status_select_network);
|
mStatusText.setText(R.string.wifi_setup_status_select_network);
|
||||||
mProgressText.setText(Summary.get(this, state));
|
mProgressText.setText(Summary.get(this, state));
|
||||||
enableButtons();
|
|
||||||
|
restoreFirstButtonVisibilityState();
|
||||||
|
mAddNetworkButton.setEnabled(true);
|
||||||
|
mRefreshButton.setEnabled(true);
|
||||||
|
mSkipOrNextButton.setEnabled(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: // Not connected.
|
default: // Not connected.
|
||||||
if (mWifiSettings.getAccessPointsCount() == 0 && mIgnoringWifiNotificationCount > 0) {
|
if (mWifiSettings.getAccessPointsCount() == 0 && mIgnoringWifiNotificationCount > 0) {
|
||||||
|
Log.d(TAG, "Currently not connected, but we show \"Scanning\" for a moment");
|
||||||
mIgnoringWifiNotificationCount--;
|
mIgnoringWifiNotificationCount--;
|
||||||
mProgressBar.setIndeterminate(true);
|
mProgressBar.setIndeterminate(true);
|
||||||
mProgressText.setText(Summary.get(this, DetailedState.SCANNING));
|
mProgressText.setText(Summary.get(this, DetailedState.SCANNING));
|
||||||
} else if (mShowingConnectingMessageManually && mIgnoringWifiNotificationCount > 0) {
|
} else if (mShowingConnectingMessageManually && mIgnoringWifiNotificationCount > 0) {
|
||||||
|
Log.i(TAG, "Currently not connected, but we show \"connecting\" for a moment.");
|
||||||
mIgnoringWifiNotificationCount--;
|
mIgnoringWifiNotificationCount--;
|
||||||
showConnectingStatus();
|
showConnectingStatus();
|
||||||
} else {
|
} 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;
|
mShowingConnectingMessageManually = false;
|
||||||
mProgressBar.setIndeterminate(false);
|
mProgressBar.setIndeterminate(false);
|
||||||
mProgressBar.setProgress(0);
|
mProgressBar.setProgress(0);
|
||||||
|
|
||||||
|
mStatusText.setText(R.string.wifi_setup_not_connected);
|
||||||
mProgressText.setText(getString(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;
|
break;
|
||||||
@@ -231,40 +297,168 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
|||||||
mProgressText.setText(Summary.get(this, DetailedState.CONNECTING));
|
mProgressText.setText(Summary.get(this, DetailedState.CONNECTING));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableButtons() {
|
private void onAddNetworkButtonPressed() {
|
||||||
((Button)findViewById(R.id.wifi_setup_refresh_list)).setEnabled(true);
|
// onConfigUiShown() will be called.
|
||||||
((Button)findViewById(R.id.wifi_setup_add_network)).setEnabled(true);
|
mWifiSettings.onAddNetworkPressed();
|
||||||
((Button)findViewById(R.id.wifi_setup_skip_or_next)).setEnabled(true);
|
|
||||||
|
// 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);
|
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.setIndeterminate(false);
|
||||||
mProgressBar.setProgress(0);
|
mProgressBar.setProgress(0);
|
||||||
mProgressText.setText(getString(R.string.wifi_setup_not_connected));
|
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;
|
mIgnoringWifiNotificationCount = 5;
|
||||||
mProgressBar.setIndeterminate(true);
|
mProgressBar.setIndeterminate(true);
|
||||||
((Button)findViewById(R.id.wifi_setup_add_network)).setEnabled(false);
|
((Button)findViewById(R.id.wifi_setup_add_network)).setEnabled(false);
|
||||||
((Button)findViewById(R.id.wifi_setup_refresh_list)).setEnabled(false);
|
((Button)findViewById(R.id.wifi_setup_refresh_list)).setEnabled(false);
|
||||||
mProgressText.setText(Summary.get(this, DetailedState.SCANNING));
|
mProgressText.setText(Summary.get(this, DetailedState.SCANNING));
|
||||||
mStatusText.setText(R.string.wifi_setup_status_scanning);
|
mStatusText.setText(R.string.wifi_setup_status_scanning);
|
||||||
}
|
|
||||||
|
|
||||||
/* package */ void onConnectButtonPressed() {
|
if (disconnectNetwork) {
|
||||||
// updateConnectionState() isn't called soon after the user's "connect" action,
|
mWifiManager.disconnect();
|
||||||
// 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.
|
mWifiSettings.refreshAccessPoints();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user