diff options
-rw-r--r-- | Android.mk | 6 | ||||
-rw-r--r-- | res/layout/setup_preference.xml | 290 | ||||
-rw-r--r-- | src/com/android/settings/CryptKeeper.java | 117 | ||||
-rw-r--r-- | src/com/android/settings/DevelopmentSettings.java | 6 | ||||
-rw-r--r-- | src/com/android/settings/wifi/WifiPickerActivity.java | 5 | ||||
-rw-r--r-- | src/com/android/settings/wifi/WifiSettingsForSetupWizard.java | 178 | ||||
-rw-r--r-- | src/com/android/settings/wifi/WifiSetupActivity.java | 199 |
7 files changed, 448 insertions, 353 deletions
@@ -10,6 +10,8 @@ LOCAL_SRC_FILES := \ $(call all-java-files-under, src) \ src/com/android/settings/EventLogTags.logtags +LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res + LOCAL_PACKAGE_NAME := Settings LOCAL_CERTIFICATE := platform LOCAL_PRIVILEGED_MODULE := true @@ -18,9 +20,11 @@ LOCAL_PROGUARD_FLAG_FILES := proguard.flags LOCAL_AAPT_FLAGS += -c zz_ZZ +include frameworks/opt/setupwizard/navigationbar/common.mk + include $(BUILD_PACKAGE) -# Use the folloing include to make our test apk. +# Use the following include to make our test apk. ifeq (,$(ONE_SHOT_MAKEFILE)) include $(call all-makefiles-under,$(LOCAL_PATH)) endif diff --git a/res/layout/setup_preference.xml b/res/layout/setup_preference.xml index dc6130d..195214f 100644 --- a/res/layout/setup_preference.xml +++ b/res/layout/setup_preference.xml @@ -16,177 +16,189 @@ ** limitations under the License. */ --> -<view +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - class="com.android.settings.widget.ProportionalOuterFrame" + android:id="@+id/fragment" + android:orientation="vertical" android:layout_height="match_parent" android:layout_width="match_parent"> - - <RelativeLayout - android:id="@+id/title_area" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_alignParentTop="true" - android:gravity="bottom"> - - <LinearLayout - android:id="@+id/title_bar" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:gravity="bottom" - android:orientation="horizontal"> - <TextView - android:id="@+id/title" - android:layout_width="0dip" - android:layout_height="wrap_content" - android:layout_weight="1.0" - style="@style/SetupTitle" - android:text="@string/wifi_setup_wizard_title" - android:gravity="bottom" /> - - <ImageButton - android:id="@+id/more" - android:layout_width="@dimen/setup_button_size" - android:layout_height="@dimen/setup_button_size" - android:layout_marginStart="8dip" - android:layout_marginEnd="8dip" - android:layout_marginBottom="8dip" - android:src="?attr/ic_menu_moreoverflow" - android:background="?android:attr/actionBarItemBackground" - android:contentDescription="@string/wifi_menu_more_options" /> - - </LinearLayout> - - <!-- Divider --> - <View - android:id="@+id/top_divider" - style="@style/TopDivider" - android:layout_below="@id/title_bar" /> - - </RelativeLayout> - - <LinearLayout - xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" + <view + class="com.android.settings.widget.ProportionalOuterFrame" + android:layout_weight="1" android:layout_height="match_parent" - android:layout_below="@id/title_area" - android:background="@android:color/transparent" - android:orientation="vertical" > + android:layout_width="match_parent"> - <TextView - android:id="@+id/wifi_required_info" + <RelativeLayout + android:id="@+id/title_area" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="6dip" - android:textAppearance="?android:attr/textAppearanceMedium" - android:text="@string/wifi_required_info_text" - android:visibility="gone" /> + android:layout_alignParentTop="true" + android:gravity="bottom"> - <ListView - android:id="@android:id/list" - android:layout_width="match_parent" - android:layout_height="0px" - android:layout_weight="1" - android:cacheColorHint="@android:color/transparent" - android:clipToPadding="false" - android:drawSelectorOnTop="false" - android:paddingTop="0dip" - android:scrollbarAlwaysDrawVerticalTrack="true" /> - - <TextView - android:id="@android:id/empty" - android:layout_width="match_parent" - android:layout_height="0px" - android:layout_weight="1" - android:gravity="center" - android:visibility="gone" /> + <LinearLayout + android:id="@+id/title_bar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="bottom" + android:orientation="horizontal"> + <TextView + android:id="@+id/title" + android:layout_width="0dip" + android:layout_height="wrap_content" + android:layout_weight="1.0" + style="@style/SetupTitle" + android:text="@string/wifi_setup_wizard_title" + android:gravity="bottom" /> + + <ImageButton + android:id="@+id/more" + android:layout_width="@dimen/setup_button_size" + android:layout_height="@dimen/setup_button_size" + android:layout_marginStart="8dip" + android:layout_marginEnd="8dip" + android:layout_marginBottom="8dip" + android:src="?attr/ic_menu_moreoverflow" + android:background="?android:attr/actionBarItemBackground" + android:contentDescription="@string/wifi_menu_more_options" /> + + </LinearLayout> + + <!-- Divider --> + <View + android:id="@+id/top_divider" + style="@style/TopDivider" + android:layout_below="@id/title_bar" /> - <ImageView - android:id="@+id/divider" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginTop="@dimen/setup_item_margin" - android:background="@*android:drawable/list_divider_holo_dark" /> + </RelativeLayout> <LinearLayout - android:id="@+id/other_network" + xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/setup_item_margin" - android:background="?android:attr/selectableItemBackground" - android:gravity="center_vertical" - android:minHeight="?android:attr/listPreferredItemHeight" - android:paddingEnd="?android:attr/scrollbarSize" > - - <ImageView - android:id="@+id/add_icon" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="center" - android:src="?attr/ic_menu_add" /> + android:layout_height="match_parent" + android:layout_below="@id/title_area" + android:background="@android:color/transparent" + android:orientation="vertical" > <TextView - android:id="@+id/other" - android:layout_width="wrap_content" + android:id="@+id/wifi_required_info" + android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="6dip" - android:layout_marginStart="15dip" - android:layout_marginEnd="6dip" - android:layout_marginTop="6dip" - android:layout_weight="1" - android:ellipsize="marquee" - android:fadingEdge="horizontal" - android:singleLine="true" android:textAppearance="?android:attr/textAppearanceMedium" - android:text="@string/wifi_other_network" /> + android:text="@string/wifi_required_info_text" + android:visibility="gone" /> - </LinearLayout> + <ListView + android:id="@android:id/list" + android:layout_width="match_parent" + android:layout_height="0px" + android:layout_weight="1" + android:cacheColorHint="@android:color/transparent" + android:clipToPadding="false" + android:drawSelectorOnTop="false" + android:paddingTop="0dip" + android:scrollbarAlwaysDrawVerticalTrack="true" /> - <RelativeLayout - android:id="@+id/button_bar" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_weight="0" - android:visibility="gone" > + <TextView + android:id="@android:id/empty" + android:layout_width="match_parent" + android:layout_height="0px" + android:layout_weight="1" + android:gravity="center" + android:visibility="gone" /> - <Button - android:id="@+id/back_button" - android:layout_width="150dip" + <ImageView + android:id="@+id/divider" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_alignParentStart="true" - android:layout_margin="5dip" - android:text="@string/wifi_setup_back" /> + android:layout_marginTop="@dimen/setup_item_margin" + android:background="@*android:drawable/list_divider_holo_dark" /> - <Button - android:id="@+id/custom_button" - android:layout_width="150dip" + <LinearLayout + android:id="@+id/other_network" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_alignParentEnd="true" - android:layout_margin="5dip" - android:text="@string/wifi_setup_skip" /> + android:layout_marginBottom="@dimen/setup_item_margin" + android:background="?android:attr/selectableItemBackground" + android:gravity="center_vertical" + android:minHeight="?android:attr/listPreferredItemHeight" + android:paddingEnd="?android:attr/scrollbarSize" > + + <ImageView + android:id="@+id/add_icon" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:src="?attr/ic_menu_add" /> - <LinearLayout - android:layout_width="wrap_content" + <TextView + android:id="@+id/other" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="6dip" + android:layout_marginStart="15dip" + android:layout_marginEnd="6dip" + android:layout_marginTop="6dip" + android:layout_weight="1" + android:ellipsize="marquee" + android:fadingEdge="horizontal" + android:singleLine="true" + android:textAppearance="?android:attr/textAppearanceMedium" + android:text="@string/wifi_other_network" /> + + </LinearLayout> + + <RelativeLayout + android:id="@+id/button_bar" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_alignParentEnd="true" - android:orientation="horizontal" > + android:layout_weight="0" + android:visibility="gone" > <Button - android:id="@+id/skip_button" + android:id="@+id/back_button" android:layout_width="150dip" android:layout_height="wrap_content" + android:layout_alignParentStart="true" android:layout_margin="5dip" - android:text="@string/wifi_setup_skip" - android:visibility="gone" /> + android:text="@string/wifi_setup_back" /> <Button - android:id="@+id/next_button" + android:id="@+id/custom_button" android:layout_width="150dip" android:layout_height="wrap_content" + android:layout_alignParentEnd="true" android:layout_margin="5dip" - android:text="@string/wifi_setup_next" - android:visibility="gone" /> - </LinearLayout> - </RelativeLayout> - </LinearLayout> -</view> + android:text="@string/wifi_setup_skip" /> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentEnd="true" + android:orientation="horizontal" > + + <Button + android:id="@+id/skip_button" + android:layout_width="150dip" + android:layout_height="wrap_content" + android:layout_margin="5dip" + android:text="@string/wifi_setup_skip" + android:visibility="gone" /> + + <Button + android:id="@+id/next_button" + android:layout_width="150dip" + android:layout_height="wrap_content" + android:layout_margin="5dip" + android:text="@string/wifi_setup_next" + android:visibility="gone" /> + </LinearLayout> + </RelativeLayout> + </LinearLayout> + </view> + <fragment android:name="com.android.setupwizard.navigationbar.SetupWizardNavBar" + android:id="@+id/navigation_bar" + style="@style/setup_wizard_navbar_style" + android:layout_weight="0" + /> +</LinearLayout> diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java index 4e20823..e9fed4f 100644 --- a/src/com/android/settings/CryptKeeper.java +++ b/src/com/android/settings/CryptKeeper.java @@ -65,6 +65,8 @@ import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternView; import com.android.internal.widget.LockPatternView.Cell; +import static com.android.internal.widget.LockPatternView.DisplayMode; + import java.util.List; /** @@ -122,6 +124,16 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList private int mNotificationCountdown = 0; /** Number of calls to {@link #notifyUser()} before we release the wakelock */ private int mReleaseWakeLockCountdown = 0; + private int mStatusString = R.string.enter_password; + + // how long we wait to clear a wrong pattern + private static final int WRONG_PATTERN_CLEAR_TIMEOUT_MS = 1500; + + private Runnable mClearPatternRunnable = new Runnable() { + public void run() { + mLockPatternView.clearPattern(); + } + }; /** * Used to propagate state through configuration changes (e.g. screen rotation) @@ -175,21 +187,32 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList } else if (failedAttempts == MAX_FAILED_ATTEMPTS) { // Factory reset the device. sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); - } else if ((failedAttempts % COOL_DOWN_ATTEMPTS) == 0) { - if (mLockPatternView != null) { - mLockPatternView.clearPattern(); - } - mCooldown = COOL_DOWN_INTERVAL; - cooldown(); } else { - final TextView status = (TextView) findViewById(R.id.status); - status.setText(R.string.try_again); - // Reenable the password entry - if (mPasswordEntry != null) { - mPasswordEntry.setEnabled(true); - } + // Wrong entry. Handle pattern case. if (mLockPatternView != null) { - mLockPatternView.setEnabled(true); + mLockPatternView.setDisplayMode(DisplayMode.Wrong); + mLockPatternView.removeCallbacks(mClearPatternRunnable); + mLockPatternView.postDelayed(mClearPatternRunnable, WRONG_PATTERN_CLEAR_TIMEOUT_MS); + } + if ((failedAttempts % COOL_DOWN_ATTEMPTS) == 0) { + mCooldown = COOL_DOWN_INTERVAL; + cooldown(); + } else { + final TextView status = (TextView) findViewById(R.id.status); + status.setText(R.string.try_again); + if (mLockPatternView != null) { + mLockPatternView.setDisplayMode(DisplayMode.Wrong); + } + // Reenable the password entry + if (mPasswordEntry != null) { + mPasswordEntry.setEnabled(true); + final InputMethodManager imm = (InputMethodManager) getSystemService( + Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(mPasswordEntry, 0); + } + if (mLockPatternView != null) { + mLockPatternView.setEnabled(true); + } } } } @@ -398,19 +421,28 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList public void onPostExecute(java.lang.Void v) { if(type == StorageManager.CRYPT_TYPE_PIN) { setContentView(R.layout.crypt_keeper_pin_entry); - ((TextView)findViewById(R.id.status)).setText(R.string.enter_pin); + mStatusString = R.string.enter_pin; } else if (type == StorageManager.CRYPT_TYPE_PATTERN) { setContentView(R.layout.crypt_keeper_pattern_entry); setBackFunctionality(false); - ((TextView)findViewById(R.id.status)).setText(R.string.enter_pattern); + mStatusString = R.string.enter_pattern; } else { setContentView(R.layout.crypt_keeper_password_entry); + mStatusString = R.string.enter_password; } + final TextView status = (TextView) findViewById(R.id.status); + status.setText(mStatusString); + + final TextView ownerInfo = (TextView) findViewById(R.id.owner_info); + ownerInfo.setText(owner_info); + ownerInfo.setSelected(true); // Required for marquee'ing to work - final TextView status = (TextView) findViewById(R.id.owner_info); - status.setText(owner_info); - status.setSelected(true); // Required for marquee'ing to work passwordEntryInit(); + + if (mCooldown > 0) { + setBackFunctionality(false); + cooldown(); // in case we are cooling down and coming back from emergency dialler + } } }.execute(); } else if (!mValidationRequested) { @@ -553,13 +585,24 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList // Re-enable the password entry and back presses. if (mPasswordEntry != null) { mPasswordEntry.setEnabled(true); + final InputMethodManager imm = (InputMethodManager) getSystemService( + Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(mPasswordEntry, 0); setBackFunctionality(true); } if (mLockPatternView != null) { mLockPatternView.setEnabled(true); } - status.setText(R.string.enter_password); + status.setText(mStatusString); } else { + // Disable the password entry and back presses. + if (mPasswordEntry != null) { + mPasswordEntry.setEnabled(false); + } + if (mLockPatternView != null) { + mLockPatternView.setEnabled(false); + } + CharSequence template = getText(R.string.crypt_keeper_cooldown); status.setText(TextUtils.expandTemplate(template, Integer.toString(mCooldown))); @@ -583,25 +626,26 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList } protected LockPatternView.OnPatternListener mChooseNewLockPatternListener = - new LockPatternView.OnPatternListener() { + new LockPatternView.OnPatternListener() { - @Override - public void onPatternStart() { - } + @Override + public void onPatternStart() { + mLockPatternView.removeCallbacks(mClearPatternRunnable); + } - @Override - public void onPatternCleared() { - } + @Override + public void onPatternCleared() { + } - @Override - public void onPatternDetected(List<LockPatternView.Cell> pattern) { - mLockPatternView.setEnabled(false); - new DecryptTask().execute(LockPatternUtils.patternToString(pattern)); - } + @Override + public void onPatternDetected(List<LockPatternView.Cell> pattern) { + mLockPatternView.setEnabled(false); + new DecryptTask().execute(LockPatternUtils.patternToString(pattern)); + } - @Override - public void onPatternCellAdded(List<Cell> pattern) { - } + @Override + public void onPatternCellAdded(List<Cell> pattern) { + } }; private void passwordEntryInit() { @@ -655,13 +699,13 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList mWakeLock.acquire(); // Keep awake for 10 minutes - if the user hasn't been alerted by then // best not to just drain their battery - mReleaseWakeLockCountdown = 96; // 96 * 5 + 120 = 600 + mReleaseWakeLockCountdown = 96; // 96 * 5 secs per click + 120 secs before we show this = 600 } } // Asynchronously throw up the IME, since there are issues with requesting it to be shown // immediately. - if (mLockPatternView == null) { + if (mLockPatternView == null && mCooldown <= 0) { mHandler.postDelayed(new Runnable() { @Override public void run() { imm.showSoftInputUnchecked(0, null); @@ -846,6 +890,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList final Intent intent = new Intent(ACTION_EMERGENCY_DIAL); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + setBackFunctionality(true); startActivity(intent); } diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java index 6d9206c..3708999 100644 --- a/src/com/android/settings/DevelopmentSettings.java +++ b/src/com/android/settings/DevelopmentSettings.java @@ -359,8 +359,10 @@ public class DevelopmentSettings extends SettingsPreferenceFragment mWebViewDataReductionProxy = findAndInitCheckboxPref(WEBVIEW_DATA_REDUCTION_PROXY_KEY); String key = Settings.Global.getString(getActivity().getContentResolver(), Settings.Global.WEBVIEW_DATA_REDUCTION_PROXY_KEY); - // Make it not selectable if the key is not available for some reason. - mWebViewDataReductionProxy.setSelectable(key != null && !key.isEmpty()); + // Disable the selection if the key is not available for some reason. + if (key == null || key.isEmpty()) { + disableForUser(mWebViewDataReductionProxy); + } } private ListPreference addListPreference(String prefKey) { diff --git a/src/com/android/settings/wifi/WifiPickerActivity.java b/src/com/android/settings/wifi/WifiPickerActivity.java index 4cb78bd..eec9963 100644 --- a/src/com/android/settings/wifi/WifiPickerActivity.java +++ b/src/com/android/settings/wifi/WifiPickerActivity.java @@ -20,6 +20,7 @@ import com.android.settings.SettingsActivity; import com.android.settings.wifi.p2p.WifiP2pSettings; import android.content.Intent; +import android.preference.PreferenceFragment; import java.lang.Class; @@ -36,13 +37,13 @@ public class WifiPickerActivity extends SettingsActivity implements ButtonBarHan @Override protected boolean isValidFragment(String fragmentName) { - if (getWifiSettingsClass().getName().equals(fragmentName) + if (WifiSettings.class.getName().equals(fragmentName) || WifiP2pSettings.class.getName().equals(fragmentName) || AdvancedWifiSettings.class.getName().equals(fragmentName)) return true; return false; } - /* package */ Class getWifiSettingsClass() { + /* package */ Class<? extends PreferenceFragment> getWifiSettingsClass() { return WifiSettings.class; } }
\ No newline at end of file diff --git a/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java b/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java index 17fca9f..325e1eb 100644 --- a/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java +++ b/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java @@ -17,11 +17,8 @@ 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; @@ -63,25 +60,9 @@ public class WifiSettingsForSetupWizard extends WifiSettings { // 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; @@ -105,7 +86,8 @@ public class WifiSettingsForSetupWizard extends WifiSettings { changeNextButtonState(info.isConnected()); if (mAutoFinishOnConnection && info.isConnected()) { Log.d(TAG, "mReceiver.onReceive context=" + context + " intent=" + intent); - finishOrNext(Activity.RESULT_OK); + WifiSetupActivity activity = (WifiSetupActivity) getActivity(); + activity.finishOrNext(Activity.RESULT_OK); } } }; @@ -150,36 +132,6 @@ public class WifiSettingsForSetupWizard extends WifiSettings { } 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); } @@ -197,30 +149,32 @@ public class WifiSettingsForSetupWizard extends WifiSettings { View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS | View.STATUS_BAR_DISABLE_CLOCK); - final Activity activity = getActivity(); + final WifiSetupActivity activity = (WifiSetupActivity) 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); - /* - * When entering with a savedInstanceState, we may be returning from a later activity in the - * setup flow. It's not clear yet if there are other possible circumstances. It's not - * appropriate to refire our activity results, so we skip that here. - */ - if (mAutoFinishOnConnection && null == savedInstanceState) { + 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()) { - Log.d(TAG, "onActivityCreated Auto-finishing"); - finishOrNext(Activity.RESULT_OK); - return; + /* + * When entering with a savedInstanceState, we may be returning from a later activity in + * the setup flow. It's not clear yet if there are other possible circumstances. It's + * not appropriate to refire our activity results, so we skip that here. + */ + if (savedInstanceState == null) { + final ConnectivityManager connectivity = (ConnectivityManager) + activity.getSystemService(Context.CONNECTIVITY_SERVICE); + if (connectivity != null && + connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) { + Log.d(TAG, "onActivityCreated Auto-finishing"); + activity.finishOrNext(Activity.RESULT_OK); + return; + } } } @@ -242,49 +196,6 @@ public class WifiSettingsForSetupWizard extends WifiSettings { } @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); @@ -297,24 +208,6 @@ public class WifiSettingsForSetupWizard extends WifiSettings { } @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 } @@ -359,39 +252,4 @@ public class WifiSettingsForSetupWizard extends WifiSettings { 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 d4811ed..8e4ff48 100644 --- a/src/com/android/settings/wifi/WifiSetupActivity.java +++ b/src/com/android/settings/wifi/WifiSetupActivity.java @@ -15,37 +15,210 @@ */ package com.android.settings.wifi; +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.res.Resources; +import android.graphics.Color; +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.preference.PreferenceFragment; +import android.util.Log; + import com.android.settings.ButtonBarHandler; +import com.android.settings.R; +import com.android.setupwizard.navigationbar.SetupWizardNavBar; +import com.android.setupwizard.navigationbar.SetupWizardNavBar.NavigationBarListener; -import android.content.res.Resources; +public class WifiSetupActivity extends WifiPickerActivity + implements ButtonBarHandler, NavigationBarListener { + private static final String TAG = "WifiSetupActivity"; -import java.lang.Class; + private static final String EXTRA_ALLOW_SKIP = "allowSkip"; + private static final String EXTRA_USE_IMMERSIVE_MODE = "useImmersiveMode"; + + // this boolean extra shows a custom button that we can control + protected static final String EXTRA_SHOW_CUSTOM_BUTTON = "wifi_show_custom_button"; -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"; private static final String THEME_HOLO = "holo"; private static final String THEME_HOLO_LIGHT = "holo_light"; + private static final String THEME_MATERIAL = "material"; + private static final String THEME_MATERIAL_LIGHT = "material_light"; + + // Activity result when pressing the Skip button + private static final int RESULT_SKIP = Activity.RESULT_FIRST_USER; - // Style resources containing theme settings - private static final String RESOURCE_THEME_DARK = "SetupWizardWifiTheme"; - private static final String RESOURCE_THEME_LIGHT = "SetupWizardWifiTheme.Light"; + // 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; @Override protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { String themeName = getIntent().getStringExtra(EXTRA_THEME); - if (THEME_HOLO_LIGHT.equalsIgnoreCase(themeName)) { - resid = getResources().getIdentifier(RESOURCE_THEME_LIGHT, "style", - getPackageName()); - } else if (THEME_HOLO.equalsIgnoreCase(themeName)) { - resid = getResources().getIdentifier(RESOURCE_THEME_DARK, "style", - getPackageName()); + if (THEME_HOLO_LIGHT.equalsIgnoreCase(themeName) || + THEME_MATERIAL_LIGHT.equalsIgnoreCase(themeName)) { + resid = R.style.SetupWizardWifiTheme_Light; + } else if (THEME_HOLO.equalsIgnoreCase(themeName) || + THEME_MATERIAL.equalsIgnoreCase(themeName)) { + resid = R.style.SetupWizardWifiTheme; } super.onApplyThemeResource(theme, resid, first); } @Override - /* package */ Class getWifiSettingsClass() { + protected boolean isValidFragment(String fragmentName) { + return WifiSettingsForSetupWizard.class.getName().equals(fragmentName); + } + + @Override + /* package */ Class<? extends PreferenceFragment> getWifiSettingsClass() { return WifiSettingsForSetupWizard.class; } + + @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 WifiManager wifiManager = (WifiManager)(getSystemService(Context.WIFI_SERVICE)); + if (wifiManager != null) { + final WifiInfo info = wifiManager.getConnectionInfo(); + if (info != null) { + int netId = info.getNetworkId(); + if (netId != WifiConfiguration.INVALID_NETWORK_ID) { + wifiManager.forget(netId, null); + } + } + } + } + super.onActivityResult(requestCode, resultCode, data); + } + + /** + * Complete this activity and return the results to the caller. If using WizardManager, this + * will invoke the next scripted action; otherwise, we simply finish. + */ + public void finishOrNext(int resultCode) { + Log.d(TAG, "finishOrNext resultCode=" + resultCode + + " isUsingWizardManager=" + isUsingWizardManager()); + if (isUsingWizardManager()) { + sendResultsToSetupWizard(resultCode); + } else { + setResult(resultCode); + finish(); + } + } + + private boolean isUsingWizardManager() { + return 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 = 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); + } + + @Override + public void onNavigationBarCreated(final SetupWizardNavBar bar) { + final boolean useImmersiveMode = + getIntent().getBooleanExtra(EXTRA_USE_IMMERSIVE_MODE, false); + bar.setUseImmersiveMode(useImmersiveMode); + if (useImmersiveMode) { + getWindow().setNavigationBarColor(Color.TRANSPARENT); + getWindow().setStatusBarColor(Color.TRANSPARENT); + } + getIntent().putExtra(EXTRA_SHOW_CUSTOM_BUTTON, false); + bar.getNextButton().setText(R.string.skip_label); + + if (!getIntent().getBooleanExtra(EXTRA_ALLOW_SKIP, true)) { + bar.getNextButton().setEnabled(false); + } + } + + @Override + public void onNavigateBack() { + onBackPressed(); + } + + @Override + public void onNavigateNext() { + boolean isConnected = false; + final ConnectivityManager connectivity = (ConnectivityManager) + getSystemService(Context.CONNECTIVITY_SERVICE); + if (connectivity != null) { + final NetworkInfo info = connectivity.getActiveNetworkInfo(); + isConnected = (info != null) && info.isConnected(); + } + if (isConnected) { + // Warn of possible data charges + WifiSkipDialog.newInstance(R.string.wifi_skipped_message) + .show(getFragmentManager(), "dialog"); + } else { + // Warn of lack of updates + WifiSkipDialog.newInstance(R.string.wifi_and_mobile_skipped_message) + .show(getFragmentManager(), "dialog"); + } + } + + private static class WifiSkipDialog extends DialogFragment { + public static WifiSkipDialog newInstance(int messageRes) { + final Bundle args = new Bundle(); + args.putInt("messageRes", messageRes); + final WifiSkipDialog dialog = new WifiSkipDialog(); + dialog.setArguments(args); + return dialog; + } + + public WifiSkipDialog() { + // no-arg constructor for fragment + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + int messageRes = getArguments().getInt("messageRes"); + return new AlertDialog.Builder(getActivity()) + .setMessage(messageRes) + .setCancelable(false) + .setNegativeButton(R.string.wifi_skip_anyway, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + WifiSetupActivity activity = (WifiSetupActivity) getActivity(); + activity.finishOrNext(RESULT_SKIP); + } + }) + .setPositiveButton(R.string.wifi_dont_skip, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + } + }) + .create(); + } + } } |