private void updateState() {
    readFontSizePreference(mFontSizePref);
    updateScreenSaverSummary();

    // Update auto brightness if it is available.
    if (mAutoBrightnessPreference != null) {
      int brightnessMode =
          Settings.System.getInt(
              getContentResolver(), SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL);
      mAutoBrightnessPreference.setChecked(brightnessMode != SCREEN_BRIGHTNESS_MODE_MANUAL);
    }

    // Update lift-to-wake if it is available.
    if (mLiftToWakePreference != null) {
      int value = Settings.Secure.getInt(getContentResolver(), WAKE_GESTURE_ENABLED, 0);
      mLiftToWakePreference.setChecked(value != 0);
    }

    // Update proximity wake if it is available.
    if (mProximityWakePreference != null) {
      boolean defaultValue =
          getResources()
              .getBoolean(com.android.internal.R.bool.config_proximityCheckOnWakeEnabledByDefault);
      boolean enabled =
          Settings.System.getInt(
                  getContentResolver(), Settings.System.PROXIMITY_ON_WAKE, defaultValue ? 1 : 0)
              == 1;
      mProximityWakePreference.setChecked(enabled);
    }
  }
Example #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    abdAlatifPref =
        (SwitchPreference) findPreference(getString(R.string.abd_alatif_notificatin_pref_key));
    waliAlahidPref =
        (SwitchPreference) findPreference(getString(R.string.wali_notification_pref_key));
    khadimAlhrmPref =
        (SwitchPreference) findPreference(getString(R.string.khadim_notification_pref_key));
    firstClassPref =
        (SwitchPreference) findPreference(getString(R.string.first_notification_pref_key));

    boolean abdAlatifNotification =
        MyApplication.pref.getBoolean(getString(R.string.abd_alatif_notificatin_pref_key), false);
    boolean waliAlahidNotificatin =
        MyApplication.pref.getBoolean(getString(R.string.wali_notification_pref_key), false);
    boolean khadimAlhrmNotification =
        MyApplication.pref.getBoolean(getString(R.string.khadim_notification_pref_key), false);
    boolean firstClassNotification =
        MyApplication.pref.getBoolean(getString(R.string.first_notification_pref_key), false);

    abdAlatifPref.setChecked(abdAlatifNotification);
    waliAlahidPref.setChecked(waliAlahidNotificatin);
    khadimAlhrmPref.setChecked(khadimAlhrmNotification);
    firstClassPref.setChecked(firstClassNotification);
  }
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.recents_panel_settings);

    PreferenceScreen prefSet = getPreferenceScreen();
    ContentResolver resolver = getActivity().getContentResolver();
    PackageManager pm = getPackageManager();

    mRecentsClearAll = (SwitchPreference) prefSet.findPreference(SHOW_CLEAR_ALL_RECENTS);
    mRecentsClearAll.setChecked(
        Settings.System.getIntForUser(
                resolver, Settings.System.SHOW_CLEAR_ALL_RECENTS, 1, UserHandle.USER_CURRENT)
            == 1);
    mRecentsClearAll.setOnPreferenceChangeListener(this);

    mRecentsClearAllLocation = (ListPreference) prefSet.findPreference(RECENTS_CLEAR_ALL_LOCATION);
    int location =
        Settings.System.getIntForUser(
            resolver, Settings.System.RECENTS_CLEAR_ALL_LOCATION, 3, UserHandle.USER_CURRENT);
    mRecentsClearAllLocation.setValue(String.valueOf(location));
    mRecentsClearAllLocation.setOnPreferenceChangeListener(this);
    updateRecentsLocation(location);

    mOmniSwitch = (Preference) prefSet.findPreference(KEY_OMNISWITCH);
    if (!Helpers.isPackageInstalled(OMNISWITCH_PACKAGE_NAME, pm)) {
      prefSet.removePreference(mOmniSwitch);
    }
  }
  @SmallTest
  @Feature({"Sync"})
  public void testSyncSwitchClearsServerAutofillCreditCards() throws Exception {
    setUpTestAccountAndSignIn();

    setPaymentsIntegrationEnabled(true);

    assertFalse("There should be no server cards", hasServerAutofillCreditCards());
    addServerAutofillCreditCard();
    assertTrue("There should be server cards", hasServerAutofillCreditCards());

    assertTrue(AndroidSyncSettings.isChromeSyncEnabled(mContext));
    SyncCustomizationFragment fragment = startSyncCustomizationFragment();
    assertDefaultSyncOnState(fragment);
    SwitchPreference syncSwitch = getSyncSwitch(fragment);
    assertTrue(syncSwitch.isChecked());
    assertTrue(AndroidSyncSettings.isChromeSyncEnabled(mContext));
    togglePreference(syncSwitch);
    assertFalse(syncSwitch.isChecked());
    assertFalse(AndroidSyncSettings.isChromeSyncEnabled(mContext));

    closeFragment(fragment);

    assertFalse("There should be no server cards remaining", hasServerAutofillCreditCards());
  }
Example #5
0
  @Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

    boolean abdAlatifNotification =
        MyApplication.pref.getBoolean(getString(R.string.abd_alatif_notificatin_pref_key), false);
    boolean waliAlahidNotificatin =
        MyApplication.pref.getBoolean(getString(R.string.wali_notification_pref_key), false);
    boolean khadimAlhrmNotification =
        MyApplication.pref.getBoolean(getString(R.string.khadim_notification_pref_key), false);
    boolean firstClassNotification =
        MyApplication.pref.getBoolean(getString(R.string.first_notification_pref_key), false);

    if (key.equalsIgnoreCase(getString(R.string.abd_alatif_notificatin_pref_key))) {
      abdAlatifPref.setChecked(abdAlatifNotification);

    } else if (key.equalsIgnoreCase(getString(R.string.wali_notification_pref_key))) {
      waliAlahidPref.setChecked(waliAlahidNotificatin);

    } else if (key.equalsIgnoreCase(getString(R.string.khadim_notification_pref_key))) {
      khadimAlhrmPref.setChecked(khadimAlhrmNotification);

    } else if (key.equalsIgnoreCase(getString(R.string.first_notification_pref_key))) {
      firstClassPref.setChecked(firstClassNotification);
    }
  }
  protected void resetToDefaults() {
    final Resources res = getResources();
    final boolean batteryLightEnabled = res.getBoolean(R.bool.def_battery_light_enabled);
    final boolean batteryLightPulseEnabled = res.getBoolean(R.bool.def_battery_light_pulse);

    if (mLightEnabledPref != null) mLightEnabledPref.setChecked(batteryLightEnabled);
    if (mPulseEnabledPref != null) mPulseEnabledPref.setChecked(batteryLightPulseEnabled);

    resetColors();
  }
  @Override
  public void onResume() {
    super.onResume();
    getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);

    SwitchPreference switchPreference = (SwitchPreference) findPreference("show_advanced_setting");
    if (switchPreference.isChecked()) {
      addPreferencesFromResource(R.xml.preference_advanced_setting);
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.gesture_anywhere);

    mEnabledPref = (SwitchPreference) findPreference(KEY_ENABLED);
    mEnabledPref.setChecked(
        (Settings.System.getInt(getContentResolver(), Settings.System.GESTURE_ANYWHERE_ENABLED, 0)
            == 1));
    mEnabledPref.setOnPreferenceChangeListener(this);

    mGestureAnywhereFloatingWindow = (SwitchPreference) findPreference(GESTURE_ANYWHERE_FLOATING);
    mGestureAnywhereFloatingWindow.setChecked(
        Settings.System.getInt(getContentResolver(), Settings.System.GESTURE_ANYWHERE_FLOATING, 0)
            == 1);
    mGestureAnywhereFloatingWindow.setOnPreferenceChangeListener(this);

    PreferenceScreen prefSet = getPreferenceScreen();
    mPositionPref = (ListPreference) prefSet.findPreference(KEY_POSITION);
    mPositionPref.setOnPreferenceChangeListener(this);
    int position =
        Settings.System.getInt(
            getContentResolver(), Settings.System.GESTURE_ANYWHERE_POSITION, Gravity.LEFT);
    mPositionPref.setValue(String.valueOf(position));
    updatePositionSummary(position);

    mTriggerWidthPref = (SeekBarPreferenceCham) findPreference(KEY_TRIGGER_WIDTH);
    mTriggerWidthPref.setValue(
        Settings.System.getInt(
            getContentResolver(), Settings.System.GESTURE_ANYWHERE_TRIGGER_WIDTH, 10));
    mTriggerWidthPref.setOnPreferenceChangeListener(this);

    mTriggerTopPref = (SeekBarPreferenceCham) findPreference(KEY_TRIGGER_TOP);
    mTriggerTopPref.setValue(
        Settings.System.getInt(
            getContentResolver(), Settings.System.GESTURE_ANYWHERE_TRIGGER_TOP, 0));
    mTriggerTopPref.setOnPreferenceChangeListener(this);

    mTriggerBottomPref = (SeekBarPreferenceCham) findPreference(KEY_TRIGGER_BOTTOM);
    mTriggerBottomPref.setValue(
        Settings.System.getInt(
            getContentResolver(), Settings.System.GESTURE_ANYWHERE_TRIGGER_HEIGHT, 100));
    mTriggerBottomPref.setOnPreferenceChangeListener(this);

    Preference pref = findPreference(KEY_GESTURES);
    pref.setOnPreferenceClickListener(
        new Preference.OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            startActivity(new Intent(getActivity(), GestureAnywhereBuilderActivity.class));
            return true;
          }
        });
  }
Example #9
0
  @Override
  public void onResume() {
    super.onResume();

    abdAlatifPref.setOnPreferenceChangeListener(this);
    waliAlahidPref.setOnPreferenceChangeListener(this);
    khadimAlhrmPref.setOnPreferenceChangeListener(this);
    firstClassPref.setOnPreferenceChangeListener(this);

    MyApplication.pref.registerOnSharedPreferenceChangeListener(this);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.global_actions);

    final PreferenceScreen prefScreen = getPreferenceScreen();
    final ContentResolver contentResolver = getContext().getContentResolver();

    final String[] defaultActions =
        getContext()
            .getResources()
            .getStringArray(com.android.internal.R.array.config_globalActionsList);
    final List<String> defaultActionsList = Arrays.asList(defaultActions);

    final String[] allActions =
        getContext()
            .getResources()
            .getStringArray(com.android.internal.R.array.values_globalActionsList);

    final String enabledActions =
        Settings.System.getString(contentResolver, Settings.System.GLOBAL_ACTIONS_LIST);

    List<String> enabledActionsList = null;
    if (enabledActions != null) {
      enabledActionsList = Arrays.asList(enabledActions.split(","));
    }

    mGlobalActionsMap = new LinkedHashMap<String, Boolean>();
    for (String actionKey : allActions) {
      if (enabledActionsList != null) {
        mGlobalActionsMap.put(actionKey, enabledActionsList.contains(actionKey));
      } else {
        mGlobalActionsMap.put(actionKey, defaultActionsList.contains(actionKey));
      }
    }
    final UserManager um = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
    boolean multiUser = um.isUserSwitcherEnabled();
    Preference userPref = null;
    int count = prefScreen.getPreferenceCount();
    for (int i = 0; i < count; i++) {
      Preference p = prefScreen.getPreference(i);
      if (p instanceof SwitchPreference) {
        SwitchPreference action = (SwitchPreference) p;
        String key = action.getKey();
        if (key.equals("users") && !multiUser) {
          userPref = action;
        }
        action.setChecked(mGlobalActionsMap.get(key));
      }
    }
    if (userPref != null) {
      prefScreen.removePreference(userPref);
    }
  }
  @Override
  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    if (preference == mTapToWake) {
      return mHardware.set(FEATURE_TAP_TO_WAKE, mTapToWake.isChecked());
    } else if (preference == mWakeWhenPluggedOrUnplugged) {
      Settings.Global.putInt(
          getContentResolver(),
          Settings.Global.WAKE_WHEN_PLUGGED_OR_UNPLUGGED,
          mWakeWhenPluggedOrUnplugged.isChecked() ? 1 : 0);
      return true;
    }

    return super.onPreferenceTreeClick(preferenceScreen, preference);
  }
 private void updateNetworkTrafficState(int mIndex) {
   if (mIndex <= 0) {
     mNetTrafficUnit.setEnabled(false);
     mNetTrafficColor.setEnabled(false);
     mNetTrafficPeriod.setEnabled(false);
     mNetTrafficAutohide.setEnabled(false);
     mNetTrafficAutohideThreshold.setEnabled(false);
   } else {
     mNetTrafficUnit.setEnabled(true);
     mNetTrafficColor.setEnabled(true);
     mNetTrafficPeriod.setEnabled(true);
     mNetTrafficAutohide.setEnabled(true);
     mNetTrafficAutohideThreshold.setEnabled(true);
   }
 }
 private void assertDefaultSyncOffState(SyncCustomizationFragment fragment) {
   assertFalse("The sync switch should be off.", getSyncSwitch(fragment).isChecked());
   assertTrue("The sync switch should be enabled.", getSyncSwitch(fragment).isEnabled());
   SwitchPreference syncEverything = getSyncEverything(fragment);
   assertTrue("The sync everything switch should be on.", syncEverything.isChecked());
   assertFalse("The sync everything switch should be disabled.", syncEverything.isEnabled());
   for (CheckBoxPreference dataType : getDataTypes(fragment).values()) {
     String key = dataType.getKey();
     assertTrue("Data type " + key + " should be checked.", dataType.isChecked());
     assertFalse("Data type " + key + " should be disabled.", dataType.isEnabled());
   }
   assertFalse("The encryption button should be disabled.", getEncryption(fragment).isEnabled());
   assertTrue(
       "The manage sync data button should be always enabled.",
       getManageData(fragment).isEnabled());
 }
  @SmallTest
  @Feature({"Sync"})
  public void testSyncSwitch() throws Exception {
    setUpTestAccountAndSignIn();
    SyncTestUtil.waitForSyncActive();
    SyncCustomizationFragment fragment = startSyncCustomizationFragment();
    final SwitchPreference syncSwitch = getSyncSwitch(fragment);

    assertTrue(syncSwitch.isChecked());
    assertTrue(AndroidSyncSettings.isChromeSyncEnabled(mContext));
    togglePreference(syncSwitch);
    assertFalse(syncSwitch.isChecked());
    assertFalse(AndroidSyncSettings.isChromeSyncEnabled(mContext));
    togglePreference(syncSwitch);
    assertTrue(syncSwitch.isChecked());
    assertTrue(AndroidSyncSettings.isChromeSyncEnabled(mContext));
  }
 private void updateReminderPreferences(SwitchPreference preference) {
   Log.d(TAG, "updateReminderPreferences() called");
   if (preference.isChecked()) {
     TimePickerFragment dialog = new TimePickerFragment();
     dialog.setPreference(preference);
     dialog.show(getFragmentManager(), "TimePickerFragment");
   }
 }
 private void handleTogglePowerButtonEndsCallPreferenceClick() {
   Settings.Secure.putInt(
       getContentResolver(),
       Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
       (mTogglePowerButtonEndsCallPreference.isChecked()
           ? Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP
           : Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_SCREEN_OFF));
 }
 private void handleToggleLargeTextPreferenceClick() {
   try {
     mCurConfig.fontScale = mToggleLargeTextPreference.isChecked() ? LARGE_FONT_SCALE : 1;
     ActivityManagerNative.getDefault().updatePersistentConfiguration(mCurConfig);
   } catch (RemoteException re) {
     /* ignore */
   }
 }
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (requestCode == REQUEST_CODE_EXIT_ECM) {
     Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
     // Set Airplane mode based on the return value and checkbox state
     mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes, mAirplaneModePreference.isChecked());
   }
   super.onActivityResult(requestCode, resultCode, data);
 }
  @Override
  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    if (preference instanceof SwitchPreference) {
      SwitchPreference action = (SwitchPreference) preference;
      mGlobalActionsMap.put(action.getKey(), action.isChecked());

      List<String> enabledActionsList = new ArrayList<String>();
      for (String actionKey : mGlobalActionsMap.keySet()) {
        Boolean checked = mGlobalActionsMap.get(actionKey);
        if (checked) {
          enabledActionsList.add(actionKey);
        }
      }
      setList(enabledActionsList);
      return true;
    }
    return super.onPreferenceTreeClick(preferenceScreen, preference);
  }
  @Override
  protected void onBindView(View view) {
    super.onBindView(view);

    TextView title = (TextView) view.findViewById(android.R.id.title);
    if (title != null) {
      title.setSingleLine(false);
      title.setMaxLines(3);
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setDisplayShowTitleEnabled(true);

    // Add 'general' preferences, defined in the XML file
    addPreferencesFromResource(R.xml.pref_general);

    SwitchPreference switchPreference;
    PreferenceManager preferenceManager = getPreferenceManager();
    switchPreference = (SwitchPreference) preferenceManager.findPreference(KEY_SWITCH_PREFERENCE);
    if (preferenceManager.getSharedPreferences().getBoolean(KEY_SWITCH_PREFERENCE, true)) {
      switchPreference.setChecked(true);
    } else {
      switchPreference.setChecked(false);
    }
  }
  @Override
  public void onResume() {
    super.onResume();
    updateDisplayRotationPreferenceDescription();

    if (mTapToWake != null) {
      mTapToWake.setChecked(mHardware.get(FEATURE_TAP_TO_WAKE));
    }

    RotationPolicy.registerRotationPolicyListener(getActivity(), mRotationPolicyListener);

    final ContentResolver resolver = getContentResolver();

    boolean dozeEnabled =
        Settings.Secure.getInt(getContentResolver(), Settings.Secure.DOZE_ENABLED, 1) != 0;
    if (mDozeFragement != null) {
      mDozeFragement.setSummary(
          dozeEnabled ? R.string.summary_doze_enabled : R.string.summary_doze_disabled);
    }

    // Display rotation observer
    resolver.registerContentObserver(
        Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION),
        true,
        mAccelerometerRotationObserver);

    // Default value for wake-on-plug behavior from config.xml
    boolean wakeUpWhenPluggedOrUnpluggedConfig =
        getResources().getBoolean(com.android.internal.R.bool.config_unplugTurnsOnScreen);

    mWakeWhenPluggedOrUnplugged.setChecked(
        Settings.Global.getInt(
                getContentResolver(),
                Settings.Global.WAKE_WHEN_PLUGGED_OR_UNPLUGGED,
                (wakeUpWhenPluggedOrUnpluggedConfig ? 1 : 0))
            == 1);

    updateState();
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.identicons_prefs);

    mEnabledPref = (SwitchPreference) findPreference(KEY_ENABLED);
    mEnabledPref.setChecked(
        (Settings.System.getInt(getContentResolver(), Settings.System.IDENTICONS_ENABLED, 0) == 1));
    mEnabledPref.setOnPreferenceChangeListener(this);

    PreferenceScreen prefSet = getPreferenceScreen();
    mStylePref = (ImageListPreference) prefSet.findPreference(KEY_STYLE);
    mStylePref.setOnPreferenceChangeListener(this);
    int style = Settings.System.getInt(getContentResolver(), Settings.System.IDENTICONS_STYLE, 0);
    mStylePref.setValue(String.valueOf(style));
    updateStyleSummary(style);

    Preference startServicePref = findPreference(KEY_CREATE);
    startServicePref.setOnPreferenceClickListener(
        new Preference.OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            getActivity().startService(new Intent(getActivity(), IdenticonCreationService.class));
            return true;
          }
        });

    startServicePref = findPreference(KEY_REMOVE);
    startServicePref.setOnPreferenceClickListener(
        new Preference.OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            getActivity().startService(new Intent(getActivity(), IdenticonRemovalService.class));
            return true;
          }
        });
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.navbar_fragment_prefs);

    resolver = getActivity().getContentResolver();
    final PreferenceScreen prefScreen = getPreferenceScreen();

    final PreferenceCategory navbarCategory =
        (PreferenceCategory) prefScreen.findPreference(CATEGORY_NAVBAR);

    mNavBar = prefScreen.findPreference(NAVIGATION_BAR);
    mNavDimen = prefScreen.findPreference(NAVIGATION_BAR_DIMEN);

    // kill-app long press back
    mKillAppLongPressBack = (SwitchPreference) findPreference(KILL_APP_LONGPRESS_BACK);
    mKillAppLongPressBack.setOnPreferenceChangeListener(this);
    int killAppLongPressBack = Settings.Secure.getInt(resolver, KILL_APP_LONGPRESS_BACK, 0);
    mKillAppLongPressBack.setChecked(killAppLongPressBack != 0);

    // Enable or disable NavbarImeSwitcher based on boolean: config_show_cmIMESwitcher
    // boolean showCmImeSwitcher =
    // getResources().getBoolean(com.android.internal.R.bool.config_show_cmIMESwitcher);
    boolean showCmImeSwitcher = true;
    if (!showCmImeSwitcher) {
      Preference pref = findPreference(STATUS_BAR_IME_SWITCHER);
      if (pref != null) {
        navbarCategory.removePreference(pref);
      }
    }

    // remove if tablet
    if ((getActivity().getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK)
        >= Configuration.SCREENLAYOUT_SIZE_LARGE) {
      navbarCategory.removePreference(findPreference(KEY_NAVIGATION_BAR_LEFT));
    }
  }
  private PreferenceScreen createPreferenceHierarchy() {
    PreferenceScreen root = getPreferenceScreen();
    if (root != null) {
      root.removeAll();
    }
    addPreferencesFromResource(R.xml.location_settings);
    root = getPreferenceScreen();

    mLocationAccess = (SwitchPreference) root.findPreference(KEY_LOCATION_TOGGLE);
    mNetwork = (CheckBoxPreference) root.findPreference(KEY_LOCATION_NETWORK);
    mGps = (CheckBoxPreference) root.findPreference(KEY_LOCATION_GPS);
    mAssistedGps = (CheckBoxPreference) root.findPreference(KEY_ASSISTED_GPS);
    mGpsDownloadDataWifiOnly =
        (CheckBoxPreference) root.findPreference(KEY_GPS_DOWNLOAD_DATA_WIFI_ONLY);

    // Only enable these controls if this user is allowed to change location
    // sharing settings.
    final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
    boolean isToggleAllowed = !um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION);
    if (mLocationAccess != null) mLocationAccess.setEnabled(isToggleAllowed);
    if (mNetwork != null) mNetwork.setEnabled(isToggleAllowed);
    if (mGps != null) mGps.setEnabled(isToggleAllowed);
    if (mAssistedGps != null) mAssistedGps.setEnabled(isToggleAllowed);
    if (mGpsDownloadDataWifiOnly != null) mGpsDownloadDataWifiOnly.setEnabled(isToggleAllowed);

    if (!LongTermOrbits.isSupported()) {
      root.removePreference(mGpsDownloadDataWifiOnly);
      mGpsDownloadDataWifiOnly = null;
    } else {
      if (saveDownloadDataWifiOnlyPref(getActivity())) {
        root.removePreference(mGpsDownloadDataWifiOnly);
        mGpsDownloadDataWifiOnly = null;
      }
    }

    mLocationAccess.setOnPreferenceChangeListener(this);
    return root;
  }
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      addPreferencesFromResource(R.xml.launcher_preferences);

      SwitchPreference pref =
          (SwitchPreference) findPreference(Utilities.ALLOW_ROTATION_PREFERENCE_KEY);
      pref.setPersistent(false);

      Bundle extras = new Bundle();
      extras.putBoolean(LauncherSettings.Settings.EXTRA_DEFAULT_VALUE, false);
      Bundle value =
          getActivity()
              .getContentResolver()
              .call(
                  LauncherSettings.Settings.CONTENT_URI,
                  LauncherSettings.Settings.METHOD_GET_BOOLEAN,
                  Utilities.ALLOW_ROTATION_PREFERENCE_KEY,
                  extras);
      pref.setChecked(value.getBoolean(LauncherSettings.Settings.EXTRA_VALUE));

      pref.setOnPreferenceChangeListener(this);
    }
    @Override
    public boolean onPreferenceChange(Preference preference, Object value) {

      if (preference.getKey().equals("lock_pattern_on")) {
        SwitchPreference service = (SwitchPreference) preference;
        service.setChecked((Boolean) value);

        // 由未开启状态转为开启状态
        if ((Boolean) value) {
          // 默认没有创建成功,手势密码不存在
          PreferenceManager.getDefaultSharedPreferences(this.getActivity().getApplicationContext())
              .edit()
              .putBoolean("lock_pattern_on", false)
              .commit();

          this.getFragmentManager()
              .beginTransaction()
              .replace(R.id.settings_container, new CreatePasswordFragment())
              .commit();

        } else {
          // 默认没有取消成功,手势密码依旧存在
          PreferenceManager.getDefaultSharedPreferences(this.getActivity().getApplicationContext())
              .edit()
              .putBoolean("lock_pattern_on", true)
              .commit();

          // 取消手势密码,要先验证
          LockPatternActivity.IntentBuilder.newPatternComparator(
                  getActivity().getApplicationContext())
              .startForResult(this, REQ_ENTER_PATTERN);
        }
      }

      return true;
    }
  @SmallTest
  @Feature({"Sync"})
  public void testPaymentsIntegrationEnabledBySyncEverything() throws Exception {
    setUpTestAccountAndSignIn();
    setPaymentsIntegrationEnabled(false);
    disableDataType(ModelType.AUTOFILL);

    // Get the UI elements.
    SyncCustomizationFragment fragment = startSyncCustomizationFragment();
    SwitchPreference syncEverything = getSyncEverything(fragment);
    CheckBoxPreference syncAutofill =
        (CheckBoxPreference)
            fragment.findPreference(SyncCustomizationFragment.PREFERENCE_SYNC_AUTOFILL);
    CheckBoxPreference paymentsIntegration =
        (CheckBoxPreference)
            fragment.findPreference(SyncCustomizationFragment.PREFERENCE_PAYMENTS_INTEGRATION);

    // All three are unchecked and payments is disabled.
    assertFalse(syncEverything.isChecked());
    assertFalse(syncAutofill.isChecked());
    assertTrue(syncAutofill.isEnabled());
    assertFalse(paymentsIntegration.isChecked());
    assertFalse(paymentsIntegration.isEnabled());

    // All three are checked after toggling sync everything.
    togglePreference(syncEverything);
    assertTrue(syncEverything.isChecked());
    assertTrue(syncAutofill.isChecked());
    assertFalse(syncAutofill.isEnabled());
    assertTrue(paymentsIntegration.isChecked());
    assertFalse(paymentsIntegration.isEnabled());

    // Closing the fragment enabled payments integration.
    closeFragment(fragment);
    assertPaymentsIntegrationEnabled(true);
  }
  @Override
  public void onStart() {
    super.onStart();

    Preference togglePref =
        mAppSettingsFragment.findPreference(
            getString(org.wordpress.passcodelock.R.string.pref_key_passcode_toggle));
    Preference changePref =
        mAppSettingsFragment.findPreference(
            getString(org.wordpress.passcodelock.R.string.pref_key_change_passcode));

    if (togglePref != null && changePref != null) {
      mPasscodePreferenceFragment.setPreferences(togglePref, changePref);
      ((SwitchPreference) togglePref)
          .setChecked(AppLockManager.getInstance().getAppLock().isPasswordLocked());
    }
  }
  private void updateModeSummary() {
    int mode =
        Settings.System.getIntForUser(
            getContentResolver(),
            Settings.System.DISPLAY_TEMPERATURE_MODE,
            MODE_OFF,
            UserHandle.USER_CURRENT);

    int index = ArrayUtils.indexOf(mModeValues, String.valueOf(mode));
    mLiveDisplay.setSummary(mModeSummaries[index]);

    if (mDisplayTemperature != null) {
      mDisplayTemperature.setEnabled(mode != MODE_OFF);
    }
    if (mOutdoorMode != null) {
      mOutdoorMode.setEnabled(mode != MODE_OFF);
    }
  }