summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell Brenner <russellbrenner@google.com>2014-06-02 04:33:42 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-06-02 04:33:42 +0000
commit4ad687a0d841dd10470c79007575ee2a9ec2894e (patch)
treec9a09aad0bd7255e168d59a41c50a04d773c56e2
parent09626a8af670d4775c89f28cf5a149fb4668a905 (diff)
parentd3446c5708aff2580d4ddb9f559e72784bfac55e (diff)
downloadpackages_apps_Settings-4ad687a0d841dd10470c79007575ee2a9ec2894e.zip
packages_apps_Settings-4ad687a0d841dd10470c79007575ee2a9ec2894e.tar.gz
packages_apps_Settings-4ad687a0d841dd10470c79007575ee2a9ec2894e.tar.bz2
Merge "Refactor setup wizard-related code"
-rw-r--r--AndroidManifest.xml1
-rw-r--r--res/layout/setup_preference.xml2
-rw-r--r--src/com/android/settings/widget/ProportionalOuterFrame.java63
-rw-r--r--src/com/android/settings/wifi/WifiPickerActivity.java10
-rw-r--r--src/com/android/settings/wifi/WifiSettings.java372
-rw-r--r--src/com/android/settings/wifi/WifiSettingsForSetupWizard.java390
-rw-r--r--src/com/android/settings/wifi/WifiSetupActivity.java7
7 files changed, 516 insertions, 329 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 4388f0b..ee78672 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -169,6 +169,7 @@
</activity>
<activity android:name=".wifi.WifiSetupActivity"
+ android:taskAffinity="com.android.wizard"
android:theme="@style/SetupWizardWifiTheme"
android:label="@string/wifi_setup_wizard_title"
android:icon="@drawable/empty_icon"
diff --git a/res/layout/setup_preference.xml b/res/layout/setup_preference.xml
index d0cbc02..dc6130d 100644
--- a/res/layout/setup_preference.xml
+++ b/res/layout/setup_preference.xml
@@ -18,7 +18,7 @@
-->
<view
xmlns:android="http://schemas.android.com/apk/res/android"
- class="com.android.settings.wifi.WifiSettings$ProportionalOuterFrame"
+ class="com.android.settings.widget.ProportionalOuterFrame"
android:layout_height="match_parent"
android:layout_width="match_parent">
diff --git a/src/com/android/settings/widget/ProportionalOuterFrame.java b/src/com/android/settings/widget/ProportionalOuterFrame.java
new file mode 100644
index 0000000..d23d2c4
--- /dev/null
+++ b/src/com/android/settings/widget/ProportionalOuterFrame.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2011 Google Inc.
+ *
+ * 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.widget;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.RelativeLayout;
+
+import com.android.settings.R;
+
+/**
+ * Used as the outer frame of all setup wizard pages that need to adjust their margins based
+ * on the total size of the available display. (e.g. side margins set to 10% of total width.)
+ */
+public class ProportionalOuterFrame extends RelativeLayout {
+ public ProportionalOuterFrame(Context context) {
+ super(context);
+ }
+
+ public ProportionalOuterFrame(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public ProportionalOuterFrame(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Set our margins and title area height proportionally to the available display size
+ */
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ final int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
+ final int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
+ final Resources res = getContext().getResources();
+ final float titleHeight = res.getFraction(R.dimen.setup_title_height, 1, 1);
+ final float sideMargin = res.getFraction(R.dimen.setup_border_width, 1, 1);
+ final int bottom = res.getDimensionPixelSize(R.dimen.setup_margin_bottom);
+ setPaddingRelative((int) (parentWidth * sideMargin), 0,
+ (int) (parentWidth * sideMargin), bottom);
+ final View title = findViewById(R.id.title_area);
+ if (title != null) {
+ title.setMinimumHeight((int) (parentHeight * titleHeight));
+ }
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ }
+}
diff --git a/src/com/android/settings/wifi/WifiPickerActivity.java b/src/com/android/settings/wifi/WifiPickerActivity.java
index 6dea82e..4cb78bd 100644
--- a/src/com/android/settings/wifi/WifiPickerActivity.java
+++ b/src/com/android/settings/wifi/WifiPickerActivity.java
@@ -21,22 +21,28 @@ import com.android.settings.wifi.p2p.WifiP2pSettings;
import android.content.Intent;
+import java.lang.Class;
+
public class WifiPickerActivity extends SettingsActivity implements ButtonBarHandler {
@Override
public Intent getIntent() {
Intent modIntent = new Intent(super.getIntent());
if (!modIntent.hasExtra(EXTRA_SHOW_FRAGMENT)) {
- modIntent.putExtra(EXTRA_SHOW_FRAGMENT, WifiSettings.class.getName());
+ modIntent.putExtra(EXTRA_SHOW_FRAGMENT, getWifiSettingsClass().getName());
}
return modIntent;
}
@Override
protected boolean isValidFragment(String fragmentName) {
- if (WifiSettings.class.getName().equals(fragmentName)
+ if (getWifiSettingsClass().getName().equals(fragmentName)
|| WifiP2pSettings.class.getName().equals(fragmentName)
|| AdvancedWifiSettings.class.getName().equals(fragmentName)) return true;
return false;
}
+
+ /* package */ Class getWifiSettingsClass() {
+ return WifiSettings.class;
+ }
} \ No newline at end of file
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index a653910..3420f36 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -29,7 +29,6 @@ import com.android.settings.widget.SwitchBar;
import com.android.settings.wifi.p2p.WifiP2pSettings;
import android.app.Activity;
-import android.app.AlertDialog;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -40,7 +39,6 @@ import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.location.LocationManager;
-import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState;
import android.net.wifi.ScanResult;
@@ -54,23 +52,14 @@ import android.os.Handler;
import android.os.Message;
import android.preference.Preference;
import android.preference.PreferenceScreen;
-import android.util.AttributeSet;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
-import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
import android.widget.AdapterView.AdapterContextMenuInfo;
-import android.widget.Button;
-import android.widget.ImageButton;
-import android.widget.PopupMenu;
-import android.widget.PopupMenu.OnMenuItemClickListener;
-import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
@@ -93,10 +82,10 @@ public class WifiSettings extends RestrictedSettingsFragment
implements DialogInterface.OnClickListener, Indexable {
private static final String TAG = "WifiSettings";
- private static final int MENU_ID_WPS_PBC = Menu.FIRST;
+ /* package */ static final int MENU_ID_WPS_PBC = Menu.FIRST;
private static final int MENU_ID_WPS_PIN = Menu.FIRST + 1;
private static final int MENU_ID_P2P = Menu.FIRST + 2;
- private static final int MENU_ID_ADD_NETWORK = Menu.FIRST + 3;
+ /* package */ static final int MENU_ID_ADD_NETWORK = Menu.FIRST + 3;
private static final int MENU_ID_ADVANCED = Menu.FIRST + 4;
private static final int MENU_ID_SCAN = Menu.FIRST + 5;
private static final int MENU_ID_CONNECT = Menu.FIRST + 6;
@@ -105,10 +94,10 @@ public class WifiSettings extends RestrictedSettingsFragment
private static final int MENU_ID_WRITE_NFC = Menu.FIRST + 9;
private static final int WIFI_DIALOG_ID = 1;
- private static final int WPS_PBC_DIALOG_ID = 2;
+ /* package */ static final int WPS_PBC_DIALOG_ID = 2;
private static final int WPS_PIN_DIALOG_ID = 3;
- private static final int WIFI_SKIPPED_DIALOG_ID = 4;
- private static final int WIFI_AND_MOBILE_SKIPPED_DIALOG_ID = 5;
+ /* package */ static final int WIFI_SKIPPED_DIALOG_ID = 4;
+ /* package */ static final int WIFI_AND_MOBILE_SKIPPED_DIALOG_ID = 5;
private static final int WRITE_NFC_DIALOG_ID = 6;
// Combo scans can take 5-6s to complete - set to 10s.
@@ -118,14 +107,11 @@ public class WifiSettings extends RestrictedSettingsFragment
private static final String SAVE_DIALOG_EDIT_MODE = "edit_mode";
private static final String SAVE_DIALOG_ACCESS_POINT_STATE = "wifi_ap_state";
- // Activity result when pressing the Skip button
- private static final int RESULT_SKIP = Activity.RESULT_FIRST_USER;
-
private final IntentFilter mFilter;
private final BroadcastReceiver mReceiver;
private final Scanner mScanner;
- private WifiManager mWifiManager;
+ /* package */ WifiManager mWifiManager;
private WifiManager.ActionListener mConnectListener;
private WifiManager.ActionListener mSaveListener;
private WifiManager.ActionListener mForgetListener;
@@ -145,37 +131,11 @@ public class WifiSettings extends RestrictedSettingsFragment
private TextView mEmptyView;
- /* 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";
-
- // this boolean extra specifies whether to auto finish when connection is established
- private static final String EXTRA_AUTO_FINISH_ON_CONNECT = "wifi_auto_finish_on_connect";
-
- // this boolean extra shows a custom button that we can control
- protected static final String EXTRA_SHOW_CUSTOM_BUTTON = "wifi_show_custom_button";
-
- // show a text regarding data charges when wifi connection is required during setup wizard
- protected static final String EXTRA_SHOW_WIFI_REQUIRED_INFO = "wifi_show_wifi_required_info";
-
- // this boolean extra is set if we are being invoked by the Setup Wizard
- private static final String EXTRA_IS_FIRST_RUN = "firstRun";
-
- // should Next button only be enabled when we have a connection?
- private boolean mEnableNextOnConnection;
-
- // should activity finish once we have a connection?
- private boolean mAutoFinishOnConnection;
-
// Save the dialog details
private boolean mDlgEdit;
private AccessPoint mDlgAccessPoint;
private Bundle mAccessPointSavedState;
- // the action bar uses a different set of controls for Setup Wizard
- private boolean mSetupWizardMode;
-
private SwitchBar mSwitchBar;
/** verbose logging flag. this flag is set thru developer debugging options
@@ -207,93 +167,6 @@ public class WifiSettings extends RestrictedSettingsFragment
}
@Override
- public void onCreate(Bundle icicle) {
- // Set this flag early, as it's needed by getHelpResource(), which is called by super
- mSetupWizardMode = getActivity().getIntent().getBooleanExtra(EXTRA_IS_FIRST_RUN, false);
- super.onCreate(icicle);
- }
-
- @Override
- public View onCreateView(final LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
-
- if (mSetupWizardMode) {
- View view = inflater.inflate(R.layout.setup_preference, container, false);
- View other = view.findViewById(R.id.other_network);
- other.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- if (mWifiManager.isWifiEnabled()) {
- onAddNetworkPressed();
- }
- }
- });
- final ImageButton b = (ImageButton) view.findViewById(R.id.more);
- if (b != null) {
- b.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- if (mWifiManager.isWifiEnabled()) {
- PopupMenu pm = new PopupMenu(inflater.getContext(), b);
- pm.inflate(R.menu.wifi_setup);
- pm.setOnMenuItemClickListener(new OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem item) {
- if (R.id.wifi_wps == item.getItemId()) {
- showDialog(WPS_PBC_DIALOG_ID);
- return true;
- }
- return false;
- }
- });
- pm.show();
- }
- }
- });
- }
-
- Intent intent = getActivity().getIntent();
- if (intent.getBooleanExtra(EXTRA_SHOW_CUSTOM_BUTTON, false)) {
- view.findViewById(R.id.button_bar).setVisibility(View.VISIBLE);
- view.findViewById(R.id.back_button).setVisibility(View.INVISIBLE);
- view.findViewById(R.id.skip_button).setVisibility(View.INVISIBLE);
- view.findViewById(R.id.next_button).setVisibility(View.INVISIBLE);
-
- Button customButton = (Button) view.findViewById(R.id.custom_button);
- customButton.setVisibility(View.VISIBLE);
- customButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- boolean isConnected = false;
- Activity activity = getActivity();
- final ConnectivityManager connectivity = (ConnectivityManager)
- activity.getSystemService(Context.CONNECTIVITY_SERVICE);
- if (connectivity != null) {
- final NetworkInfo info = connectivity.getActiveNetworkInfo();
- isConnected = (info != null) && info.isConnected();
- }
- if (isConnected) {
- // Warn of possible data charges
- showDialog(WIFI_SKIPPED_DIALOG_ID);
- } else {
- // Warn of lack of updates
- showDialog(WIFI_AND_MOBILE_SKIPPED_DIALOG_ID);
- }
- }
- });
- }
-
- if (intent.getBooleanExtra(EXTRA_SHOW_WIFI_REQUIRED_INFO, false)) {
- view.findViewById(R.id.wifi_required_info).setVisibility(View.VISIBLE);
- }
-
- return view;
- } else {
- return super.onCreateView(inflater, container, savedInstanceState);
- }
- }
-
- @Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
@@ -351,60 +224,11 @@ public class WifiSettings extends RestrictedSettingsFragment
mAccessPointSavedState = savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE);
}
- final Activity activity = getActivity();
- final Intent intent = activity.getIntent();
-
- // first if we're supposed to finish once we have a connection
- mAutoFinishOnConnection = intent.getBooleanExtra(EXTRA_AUTO_FINISH_ON_CONNECT, false);
-
- if (mAutoFinishOnConnection) {
- // Hide the next button
- if (hasNextButton()) {
- getNextButton().setVisibility(View.GONE);
- }
-
- final ConnectivityManager connectivity = (ConnectivityManager)
- activity.getSystemService(Context.CONNECTIVITY_SERVICE);
- if (connectivity != null
- && connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) {
- activity.setResult(Activity.RESULT_OK);
- activity.finish();
- return;
- }
- }
-
- // 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);
-
- if (mEnableNextOnConnection) {
- if (hasNextButton()) {
- final ConnectivityManager connectivity = (ConnectivityManager)
- activity.getSystemService(Context.CONNECTIVITY_SERVICE);
- if (connectivity != null) {
- NetworkInfo info = connectivity.getNetworkInfo(
- ConnectivityManager.TYPE_WIFI);
- changeNextButtonState(info.isConnected());
- }
- }
- }
-
addPreferencesFromResource(R.xml.wifi_settings);
- if (mSetupWizardMode) {
- getView().setSystemUiVisibility(
- View.STATUS_BAR_DISABLE_HOME |
- View.STATUS_BAR_DISABLE_RECENT |
- View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS |
- View.STATUS_BAR_DISABLE_CLOCK);
- }
-
mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
getListView().setEmptyView(mEmptyView);
-
- if (!mSetupWizardMode) {
- registerForContextMenu(getListView());
- }
+ registerForContextMenu(getListView());
setHasOptionsMenu(true);
}
@@ -412,13 +236,16 @@ public class WifiSettings extends RestrictedSettingsFragment
public void onStart() {
super.onStart();
- // On/off switch is hidden for Setup Wizard
- if (!mSetupWizardMode) {
- final SettingsActivity activity = (SettingsActivity) getActivity();
+ // On/off switch is hidden for Setup Wizard (returns null)
+ mWifiEnabler = createWifiEnabler();
+ }
- mSwitchBar = activity.getSwitchBar();
- mWifiEnabler = new WifiEnabler(activity, mSwitchBar);
- }
+ /**
+ * @return new WifiEnabler or null (as overridden by WifiSettingsForSetupWizard)
+ */
+ /* package */ WifiEnabler createWifiEnabler() {
+ final SettingsActivity activity = (SettingsActivity) getActivity();
+ return new WifiEnabler(activity, activity.getSwitchBar());
}
@Override
@@ -449,44 +276,41 @@ public class WifiSettings extends RestrictedSettingsFragment
// If the user is not allowed to configure wifi, do not show the menu.
if (isRestrictedAndNotPinProtected()) return;
+ addOptionsMenuItems(menu);
+ super.onCreateOptionsMenu(menu, inflater);
+ }
+
+ /**
+ * @param menu
+ */
+ void addOptionsMenuItems(Menu menu) {
final boolean wifiIsEnabled = mWifiManager.isWifiEnabled();
TypedArray ta = getActivity().getTheme().obtainStyledAttributes(
new int[] {R.attr.ic_menu_add, R.attr.ic_wps});
- if (mSetupWizardMode) {
- menu.add(Menu.NONE, MENU_ID_WPS_PBC, 0, R.string.wifi_menu_wps_pbc)
- .setIcon(ta.getDrawable(1))
- .setEnabled(wifiIsEnabled)
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
- menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network)
- .setEnabled(wifiIsEnabled)
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
- } else {
- menu.add(Menu.NONE, MENU_ID_WPS_PBC, 0, R.string.wifi_menu_wps_pbc)
- .setIcon(ta.getDrawable(1))
- .setEnabled(wifiIsEnabled)
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
- menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network)
- .setIcon(ta.getDrawable(0))
- .setEnabled(wifiIsEnabled)
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
- menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.wifi_menu_scan)
- //.setIcon(R.drawable.ic_menu_scan_network)
+ menu.add(Menu.NONE, MENU_ID_WPS_PBC, 0, R.string.wifi_menu_wps_pbc)
+ .setIcon(ta.getDrawable(1))
+ .setEnabled(wifiIsEnabled)
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+ menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network)
+ .setIcon(ta.getDrawable(0))
+ .setEnabled(wifiIsEnabled)
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+ menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.wifi_menu_scan)
+ //.setIcon(R.drawable.ic_menu_scan_network)
+ .setEnabled(wifiIsEnabled)
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+ menu.add(Menu.NONE, MENU_ID_WPS_PIN, 0, R.string.wifi_menu_wps_pin)
+ .setEnabled(wifiIsEnabled)
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+ if (mP2pSupported) {
+ menu.add(Menu.NONE, MENU_ID_P2P, 0, R.string.wifi_menu_p2p)
.setEnabled(wifiIsEnabled)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
- menu.add(Menu.NONE, MENU_ID_WPS_PIN, 0, R.string.wifi_menu_wps_pin)
- .setEnabled(wifiIsEnabled)
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
- if (mP2pSupported) {
- menu.add(Menu.NONE, MENU_ID_P2P, 0, R.string.wifi_menu_p2p)
- .setEnabled(wifiIsEnabled)
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
- }
- menu.add(Menu.NONE, MENU_ID_ADVANCED, 0, R.string.wifi_menu_advanced)
- //.setIcon(android.R.drawable.ic_menu_manage)
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
}
+ menu.add(Menu.NONE, MENU_ID_ADVANCED, 0, R.string.wifi_menu_advanced)
+ //.setIcon(android.R.drawable.ic_menu_manage)
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
ta.recycle();
- super.onCreateOptionsMenu(menu, inflater);
}
@Override
@@ -667,44 +491,6 @@ public class WifiSettings extends RestrictedSettingsFragment
return new WpsDialog(getActivity(), WpsInfo.PBC);
case WPS_PIN_DIALOG_ID:
return new WpsDialog(getActivity(), WpsInfo.DISPLAY);
- case WIFI_SKIPPED_DIALOG_ID:
- return new AlertDialog.Builder(getActivity())
- .setMessage(R.string.wifi_skipped_message)
- .setCancelable(false)
- .setNegativeButton(R.string.wifi_skip_anyway,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- getActivity().setResult(RESULT_SKIP);
- getActivity().finish();
- }
- })
- .setPositiveButton(R.string.wifi_dont_skip,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- }
- })
- .create();
- case WIFI_AND_MOBILE_SKIPPED_DIALOG_ID:
- return new AlertDialog.Builder(getActivity())
- .setMessage(R.string.wifi_and_mobile_skipped_message)
- .setCancelable(false)
- .setNegativeButton(R.string.wifi_skip_anyway,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- getActivity().setResult(RESULT_SKIP);
- getActivity().finish();
- }
- })
- .setPositiveButton(R.string.wifi_dont_skip,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- }
- })
- .create();
case WRITE_NFC_DIALOG_ID:
if (mSelectedAccessPoint != null) {
mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(
@@ -717,7 +503,7 @@ public class WifiSettings extends RestrictedSettingsFragment
}
/**
- * Shows the latest access points available with supplimental information like
+ * Shows the latest access points available with supplemental information like
* the strength of network and the security for it.
*/
private void updateAccessPoints() {
@@ -882,17 +668,8 @@ public class WifiSettings extends RestrictedSettingsFragment
NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
WifiManager.EXTRA_NETWORK_INFO);
mConnected.set(info.isConnected());
- changeNextButtonState(info.isConnected());
updateAccessPoints();
updateConnectionState(info.getDetailedState());
- if (mAutoFinishOnConnection && info.isConnected()) {
- Activity activity = getActivity();
- if (activity != null) {
- activity.setResult(Activity.RESULT_OK);
- activity.finish();
- }
- return;
- }
} else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) {
updateConnectionState(null);
}
@@ -986,18 +763,6 @@ public class WifiSettings extends RestrictedSettingsFragment
}
}
- /**
- * 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 (mEnableNextOnConnection && hasNextButton()) {
- getNextButton().setEnabled(connected);
- }
- }
-
@Override
public void onClick(DialogInterface dialogInterface, int button) {
if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) {
@@ -1039,7 +804,7 @@ public class WifiSettings extends RestrictedSettingsFragment
/* package */ void forget() {
if (mSelectedAccessPoint.networkId == INVALID_NETWORK_ID) {
- // Should not happen, but a monkey seems to triger it
+ // Should not happen, but a monkey seems to trigger it
Log.e(TAG, "Failed to forget invalid network " + mSelectedAccessPoint.getConfig());
return;
}
@@ -1050,9 +815,6 @@ public class WifiSettings extends RestrictedSettingsFragment
mScanner.resume();
}
updateAccessPoints();
-
- // We need to rename/replace "Next" button in wifi setup context.
- changeNextButtonState(false);
}
/**
@@ -1104,51 +866,9 @@ public class WifiSettings extends RestrictedSettingsFragment
@Override
protected int getHelpResource() {
- if (mSetupWizardMode) {
- return 0;
- }
return R.string.help_url_wifi;
}
- /**
- * Used as the outer frame of all setup wizard pages that need to adjust their margins based
- * on the total size of the available display. (e.g. side margins set to 10% of total width.)
- */
- public static class ProportionalOuterFrame extends RelativeLayout {
- public ProportionalOuterFrame(Context context) {
- super(context);
- }
- public ProportionalOuterFrame(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- public ProportionalOuterFrame(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
-
- /**
- * Set our margins and title area height proportionally to the available display size
- */
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
- int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
- final Resources res = getContext().getResources();
- float titleHeight = res.getFraction(R.dimen.setup_title_height, 1, 1);
- float sideMargin = res.getFraction(R.dimen.setup_border_width, 1, 1);
- int bottom = res.getDimensionPixelSize(R.dimen.setup_margin_bottom);
- setPaddingRelative(
- (int) (parentWidth * sideMargin),
- 0,
- (int) (parentWidth * sideMargin),
- bottom);
- View title = findViewById(R.id.title_area);
- if (title != null) {
- title.setMinimumHeight((int) (parentHeight * titleHeight));
- }
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- }
- }
-
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
diff --git a/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java b/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java
new file mode 100644
index 0000000..25b12b9
--- /dev/null
+++ b/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java
@@ -0,0 +1,390 @@
+/*
+ * Copyright (C) 2014 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 android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.res.TypedArray;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.ImageButton;
+import android.widget.PopupMenu;
+import android.widget.PopupMenu.OnMenuItemClickListener;
+
+import com.android.settings.R;
+
+/**
+ * This customized version of WifiSettings is shown to the user only during Setup Wizard. Menu
+ * selections are limited, clicking on an access point will auto-advance to the next screen (once
+ * connected), and, if the user opts to skip ahead without a wifi connection, a warning message
+ * alerts of possible carrier data charges or missing software updates.
+ */
+public class WifiSettingsForSetupWizard extends WifiSettings {
+
+ private static final String TAG = "WifiSettingsForSetupWizard";
+
+ /* 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";
+
+ // this boolean extra specifies whether to auto finish when connection is established
+ private static final String EXTRA_AUTO_FINISH_ON_CONNECT = "wifi_auto_finish_on_connect";
+
+ // this boolean extra shows a custom button that we can control
+ protected static final String EXTRA_SHOW_CUSTOM_BUTTON = "wifi_show_custom_button";
+
+ // show a text regarding data charges when wifi connection is required during setup wizard
+ protected static final String EXTRA_SHOW_WIFI_REQUIRED_INFO = "wifi_show_wifi_required_info";
+
+ // this boolean extra is set if we are being invoked by the Setup Wizard
+ private static final String EXTRA_IS_FIRST_RUN = "firstRun";
+
+ // Activity result when pressing the Skip button
+ private static final int RESULT_SKIP = Activity.RESULT_FIRST_USER;
+
+ // From WizardManager (must match constants maintained there)
+ private static final String ACTION_NEXT = "com.android.wizard.NEXT";
+ private static final String EXTRA_SCRIPT_URI = "scriptUri";
+ private static final String EXTRA_ACTION_ID = "actionId";
+ private static final String EXTRA_RESULT_CODE = "com.android.setupwizard.ResultCode";
+ private static final int NEXT_REQUEST = 10000;
+
+ // should Next button only be enabled when we have a connection?
+ private boolean mEnableNextOnConnection;
+
+ // should activity finish once we have a connection?
+ private boolean mAutoFinishOnConnection;
+
+ private final IntentFilter mFilter;
+ private final BroadcastReceiver mReceiver;
+
+ public WifiSettingsForSetupWizard() {
+ super();
+
+ mFilter = new IntentFilter();
+ mFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+
+ mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
+ WifiManager.EXTRA_NETWORK_INFO);
+ changeNextButtonState(info.isConnected());
+ if (mAutoFinishOnConnection && info.isConnected()) {
+ finishOrNext(Activity.RESULT_OK);
+ }
+ }
+ };
+ }
+
+ @Override
+ public View onCreateView(final LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ final View view = inflater.inflate(R.layout.setup_preference, container, false);
+ final View other = view.findViewById(R.id.other_network);
+ other.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mWifiManager.isWifiEnabled()) {
+ onAddNetworkPressed();
+ }
+ }
+ });
+ final ImageButton b = (ImageButton) view.findViewById(R.id.more);
+ if (b != null) {
+ b.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mWifiManager.isWifiEnabled()) {
+ PopupMenu pm = new PopupMenu(inflater.getContext(), b);
+ pm.inflate(R.menu.wifi_setup);
+ pm.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+ @Override
+ public boolean onMenuItemClick(MenuItem item) {
+ if (R.id.wifi_wps == item.getItemId()) {
+ showDialog(WPS_PBC_DIALOG_ID);
+ return true;
+ }
+ return false;
+ }
+ });
+ pm.show();
+ }
+ }
+ });
+ }
+
+ final Intent intent = getActivity().getIntent();
+ if (intent.getBooleanExtra(EXTRA_SHOW_CUSTOM_BUTTON, false)) {
+ view.findViewById(R.id.button_bar).setVisibility(View.VISIBLE);
+ view.findViewById(R.id.back_button).setVisibility(View.INVISIBLE);
+ view.findViewById(R.id.skip_button).setVisibility(View.INVISIBLE);
+ view.findViewById(R.id.next_button).setVisibility(View.INVISIBLE);
+
+ Button customButton = (Button) view.findViewById(R.id.custom_button);
+ customButton.setVisibility(View.VISIBLE);
+ customButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ boolean isConnected = false;
+ Activity activity = getActivity();
+ final ConnectivityManager connectivity = (ConnectivityManager)
+ activity.getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (connectivity != null) {
+ final NetworkInfo info = connectivity.getActiveNetworkInfo();
+ isConnected = (info != null) && info.isConnected();
+ }
+ if (isConnected) {
+ // Warn of possible data charges
+ showDialog(WIFI_SKIPPED_DIALOG_ID);
+ } else {
+ // Warn of lack of updates
+ showDialog(WIFI_AND_MOBILE_SKIPPED_DIALOG_ID);
+ }
+ }
+ });
+ }
+
+ if (intent.getBooleanExtra(EXTRA_SHOW_WIFI_REQUIRED_INFO, false)) {
+ view.findViewById(R.id.wifi_required_info).setVisibility(View.VISIBLE);
+ }
+
+ return view;
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ getView().setSystemUiVisibility(
+ View.STATUS_BAR_DISABLE_HOME |
+ View.STATUS_BAR_DISABLE_RECENT |
+ View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS |
+ View.STATUS_BAR_DISABLE_CLOCK);
+
+ final Activity activity = getActivity();
+ final Intent intent = activity.getIntent();
+
+ // first if we're supposed to finish once we have a connection
+ mAutoFinishOnConnection = intent.getBooleanExtra(EXTRA_AUTO_FINISH_ON_CONNECT, false);
+
+ if (mAutoFinishOnConnection) {
+ // Hide the next button
+ if (hasNextButton()) {
+ getNextButton().setVisibility(View.GONE);
+ }
+
+ final ConnectivityManager connectivity = (ConnectivityManager)
+ activity.getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (connectivity != null
+ && connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) {
+ finishOrNext(Activity.RESULT_OK);
+ return;
+ }
+ }
+
+ // 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);
+
+ if (mEnableNextOnConnection) {
+ if (hasNextButton()) {
+ final ConnectivityManager connectivity = (ConnectivityManager)
+ activity.getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (connectivity != null) {
+ NetworkInfo info = connectivity.getNetworkInfo(
+ ConnectivityManager.TYPE_WIFI);
+ changeNextButtonState(info.isConnected());
+ }
+ }
+ }
+ }
+
+ @Override
+ public Dialog onCreateDialog(int dialogId) {
+ switch (dialogId) {
+ case WIFI_SKIPPED_DIALOG_ID:
+ return new AlertDialog.Builder(getActivity())
+ .setMessage(R.string.wifi_skipped_message)
+ .setCancelable(false)
+ .setNegativeButton(R.string.wifi_skip_anyway,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ finishOrNext(RESULT_SKIP);
+ }
+ })
+ .setPositiveButton(R.string.wifi_dont_skip,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ }
+ })
+ .create();
+ case WIFI_AND_MOBILE_SKIPPED_DIALOG_ID:
+ return new AlertDialog.Builder(getActivity())
+ .setMessage(R.string.wifi_and_mobile_skipped_message)
+ .setCancelable(false)
+ .setNegativeButton(R.string.wifi_skip_anyway,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ finishOrNext(RESULT_SKIP);
+ }
+ })
+ .setPositiveButton(R.string.wifi_dont_skip,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ }
+ })
+ .create();
+ }
+ return super.onCreateDialog(dialogId);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ getActivity().registerReceiver(mReceiver, mFilter);
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ getActivity().unregisterReceiver(mReceiver);
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (resultCode == Activity.RESULT_CANCELED) {
+ // Before returning to the settings panel, forget any current access point so it will
+ // not attempt to automatically reconnect and advance
+ // FIXME: when coming back, it would be better to keep the current connection and
+ // override the auto-advance feature
+ final WifiInfo info = mWifiManager.getConnectionInfo();
+ if (null != info) {
+ int netId = info.getNetworkId();
+ if (netId != WifiConfiguration.INVALID_NETWORK_ID) {
+ mWifiManager.forget(netId, null);
+ }
+ }
+ }
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+
+ @Override
+ public void registerForContextMenu(View view) {
+ // Suppressed during setup wizard
+ }
+
+ @Override
+ /* package */ WifiEnabler createWifiEnabler() {
+ // Not shown during setup wizard
+ return null;
+ }
+
+ @Override
+ /* package */ void addOptionsMenuItems(Menu menu) {
+ final boolean wifiIsEnabled = mWifiManager.isWifiEnabled();
+ final TypedArray ta = getActivity().getTheme()
+ .obtainStyledAttributes(new int[] {R.attr.ic_wps});
+ menu.add(Menu.NONE, MENU_ID_WPS_PBC, 0, R.string.wifi_menu_wps_pbc)
+ .setIcon(ta.getDrawable(0))
+ .setEnabled(wifiIsEnabled)
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
+ menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network)
+ .setEnabled(wifiIsEnabled)
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
+ ta.recycle();
+ }
+
+ @Override
+ /* package */ void forget() {
+ super.forget();
+
+ // We need to rename/replace "Next" button in wifi setup context.
+ changeNextButtonState(false);
+ }
+
+ /**
+ * Renames/replaces "Next" button when appropriate. "Next" button usually exists in
+ * Wifi setup screens, not in usual wifi settings screen.
+ *
+ * @param enabled true when the device is connected to a wifi network.
+ */
+ private void changeNextButtonState(boolean enabled) {
+ if (mEnableNextOnConnection && hasNextButton()) {
+ getNextButton().setEnabled(enabled);
+ }
+ }
+
+ /**
+ * Complete this activity and return the results to the caller. If using WizardManager, this
+ * will invoke the next scripted action; otherwise, we simply finish.
+ */
+ private void finishOrNext(int resultCode) {
+ Log.d(TAG, "finishOrNext resultCode=" + resultCode
+ + " isUsingWizardManager=" + isUsingWizardManager());
+ if (isUsingWizardManager()) {
+ sendResultsToSetupWizard(resultCode);
+ } else {
+ Activity activity = getActivity();
+ activity.setResult(resultCode);
+ activity.finish();
+ }
+ }
+
+ private boolean isUsingWizardManager() {
+ return getActivity().getIntent().hasExtra(EXTRA_SCRIPT_URI);
+ }
+
+ /**
+ * Send the results of this activity to WizardManager, which will then send out the next
+ * scripted activity. WizardManager does not actually return an activity result, but if we
+ * invoke WizardManager without requesting a result, the framework will choose not to issue a
+ * call to onActivityResult with RESULT_CANCELED when navigating backward.
+ */
+ private void sendResultsToSetupWizard(int resultCode) {
+ final Intent intent = getActivity().getIntent();
+ final Intent nextIntent = new Intent(ACTION_NEXT);
+ nextIntent.putExtra(EXTRA_SCRIPT_URI, intent.getStringExtra(EXTRA_SCRIPT_URI));
+ nextIntent.putExtra(EXTRA_ACTION_ID, intent.getStringExtra(EXTRA_ACTION_ID));
+ nextIntent.putExtra(EXTRA_RESULT_CODE, resultCode);
+ startActivityForResult(nextIntent, NEXT_REQUEST);
+ }
+}
diff --git a/src/com/android/settings/wifi/WifiSetupActivity.java b/src/com/android/settings/wifi/WifiSetupActivity.java
index 70ee56d..d4811ed 100644
--- a/src/com/android/settings/wifi/WifiSetupActivity.java
+++ b/src/com/android/settings/wifi/WifiSetupActivity.java
@@ -19,6 +19,8 @@ import com.android.settings.ButtonBarHandler;
import android.content.res.Resources;
+import java.lang.Class;
+
public class WifiSetupActivity extends WifiPickerActivity implements ButtonBarHandler {
// Extra containing the resource name of the theme to be used
private static final String EXTRA_THEME = "theme";
@@ -41,4 +43,9 @@ public class WifiSetupActivity extends WifiPickerActivity implements ButtonBarHa
}
super.onApplyThemeResource(theme, resid, first);
}
+
+ @Override
+ /* package */ Class getWifiSettingsClass() {
+ return WifiSettingsForSetupWizard.class;
+ }
}