private void processArguments() { Bundle arguments = getArguments(); // Key. mPreferenceKey = arguments.getString(EXTRA_PREFERENCE_KEY); // Enabled. final boolean enabled = arguments.getBoolean(EXTRA_CHECKED); mToggleSwitch.setCheckedInternal(enabled); // Title. PreferenceActivity activity = (PreferenceActivity) getActivity(); if (!activity.onIsMultiPane() || activity.onIsHidingHeaders()) { mOldActivityTitle = getActivity().getTitle(); String title = arguments.getString(EXTRA_TITLE); getActivity().getActionBar().setTitle(title); } // Summary. String summary = arguments.getString(EXTRA_SUMMARY); mSummaryPreference.setSummary(summary); // Settings title and intent. String settingsTitle = arguments.getString(EXTRA_SETTINGS_TITLE); String settingsComponentName = arguments.getString(EXTRA_SETTINGS_COMPONENT_NAME); if (!TextUtils.isEmpty(settingsTitle) && !TextUtils.isEmpty(settingsComponentName)) { Intent settingsIntent = new Intent(Intent.ACTION_MAIN) .setComponent(ComponentName.unflattenFromString(settingsComponentName.toString())); if (!getPackageManager().queryIntentActivities(settingsIntent, 0).isEmpty()) { mSettingsTitle = settingsTitle; mSettingsIntent = settingsIntent; setHasOptionsMenu(true); } } // Enable warning title. mEnableWarningTitle = arguments.getCharSequence(AccessibilitySettings.EXTRA_ENABLE_WARNING_TITLE); // Enable warning message. mEnableWarningMessage = arguments.getCharSequence(AccessibilitySettings.EXTRA_ENABLE_WARNING_MESSAGE); // Disable warning title. mDisableWarningTitle = arguments.getString(AccessibilitySettings.EXTRA_DISABLE_WARNING_TITLE); // Disable warning message. mDisableWarningMessage = arguments.getString(AccessibilitySettings.EXTRA_DISABLE_WARNING_MESSAGE); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mP2pSupported = getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT); mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); mUserManager = (UserManager) getSystemService(Context.USER_SERVICE); mConnectListener = new WifiManager.ActionListener() { @Override public void onSuccess() {} @Override public void onFailure(int reason) { Activity activity = getActivity(); if (activity != null) { Toast.makeText(activity, R.string.wifi_failed_connect_message, Toast.LENGTH_SHORT) .show(); } } }; mSaveListener = new WifiManager.ActionListener() { @Override public void onSuccess() {} @Override public void onFailure(int reason) { Activity activity = getActivity(); if (activity != null) { Toast.makeText(activity, R.string.wifi_failed_save_message, Toast.LENGTH_SHORT) .show(); } } }; mForgetListener = new WifiManager.ActionListener() { @Override public void onSuccess() {} @Override public void onFailure(int reason) { Activity activity = getActivity(); if (activity != null) { Toast.makeText(activity, R.string.wifi_failed_forget_message, Toast.LENGTH_SHORT) .show(); } } }; if (savedInstanceState != null && savedInstanceState.containsKey(SAVE_DIALOG_ACCESS_POINT_STATE)) { mDlgEdit = savedInstanceState.getBoolean(SAVE_DIALOG_EDIT_MODE); 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_BACK | View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT | View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS | View.STATUS_BAR_DISABLE_CLOCK); } // On/off switch is hidden for Setup Wizard if (!mSetupWizardMode) { Switch actionBarSwitch = new Switch(activity); if (activity instanceof PreferenceActivity) { PreferenceActivity preferenceActivity = (PreferenceActivity) activity; if (preferenceActivity.onIsHidingHeaders() || !preferenceActivity.onIsMultiPane()) { final int padding = activity.getResources().getDimensionPixelSize(R.dimen.action_bar_switch_padding); actionBarSwitch.setPaddingRelative(0, 0, padding, 0); activity .getActionBar() .setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM); activity .getActionBar() .setCustomView( actionBarSwitch, new ActionBar.LayoutParams( ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END)); } } mWifiEnabler = new WifiEnabler(activity, actionBarSwitch); } mEmptyView = (TextView) getView().findViewById(android.R.id.empty); getListView().setEmptyView(mEmptyView); if (!mSetupWizardMode) { registerForContextMenu(getListView()); } setHasOptionsMenu(true); }