@Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    String prefName = preference.getKey();
    if (prefName != null && prefName.equals("privacy.masterpassword.enabled")) {
      showDialog(
          (Boolean) newValue ? DIALOG_CREATE_MASTER_PASSWORD : DIALOG_REMOVE_MASTER_PASSWORD);
      return false;
    } else if (prefName != null && prefName.equals("browser.menu.showCharacterEncoding")) {
      setCharEncodingState(((String) newValue).equals("true"));
    }

    setPreference(prefName, newValue);
    if (preference instanceof ListPreference) {
      // We need to find the entry for the new value
      int newIndex = ((ListPreference) preference).findIndexOfValue((String) newValue);
      CharSequence newEntry = ((ListPreference) preference).getEntries()[newIndex];
      ((ListPreference) preference).setSummary(newEntry);
    } else if (preference instanceof LinkPreference) {
      finish();
    } else if (preference instanceof FontSizePreference) {
      final FontSizePreference fontSizePref = (FontSizePreference) preference;
      fontSizePref.setSummary(fontSizePref.getSavedFontSizeName());
    }
    return true;
  }
Ejemplo n.º 2
0
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    String prefName = preference.getKey();
    if (PREFS_MP_ENABLED.equals(prefName)) {
      showDialog(
          (Boolean) newValue ? DIALOG_CREATE_MASTER_PASSWORD : DIALOG_REMOVE_MASTER_PASSWORD);

      // We don't want the "use master password" pref to change until the
      // user has gone through the dialog.
      return false;
    } else if (PREFS_MENU_CHAR_ENCODING.equals(prefName)) {
      setCharEncodingState(((String) newValue).equals("true"));
    } else if (PREFS_ANNOUNCEMENTS_ENABLED.equals(prefName)) {
      // Send a broadcast intent to the product announcements service, either to start or
      // to stop the repeated background checks.
      broadcastAnnouncementsPref(GeckoAppShell.getContext(), ((Boolean) newValue).booleanValue());
    } else if (PREFS_UPDATER_AUTODOWNLOAD.equals(prefName)) {
      org.mozilla.gecko.updater.UpdateServiceHelper.registerForUpdates(
          GeckoAppShell.getContext(), (String) newValue);
    } else if (PREFS_HEALTHREPORT_UPLOAD_ENABLED.equals(prefName)) {
      // The healthreport pref only lives in Android, so we do not persist
      // to Gecko, but we do broadcast intent to the health report
      // background uploader service, which will start or stop the
      // repeated background upload attempts.
      broadcastHealthReportUploadPref(
          GeckoAppShell.getContext(), ((Boolean) newValue).booleanValue());
    } else if (PREFS_GEO_REPORTING.equals(prefName)) {
      // Translate boolean value to int for geo reporting pref.
      newValue = ((Boolean) newValue) ? 1 : 0;
    }

    // Send Gecko-side pref changes to Gecko
    if (!TextUtils.isEmpty(prefName) && !prefName.startsWith(NON_PREF_PREFIX)) {
      PrefsHelper.setPref(prefName, newValue);
    }

    if (preference instanceof ListPreference) {
      // We need to find the entry for the new value
      int newIndex = ((ListPreference) preference).findIndexOfValue((String) newValue);
      CharSequence newEntry = ((ListPreference) preference).getEntries()[newIndex];
      ((ListPreference) preference).setSummary(newEntry);
    } else if (preference instanceof LinkPreference) {
      setResult(RESULT_CODE_EXIT_SETTINGS);
      finish();
    } else if (preference instanceof FontSizePreference) {
      final FontSizePreference fontSizePref = (FontSizePreference) preference;
      fontSizePref.setSummary(fontSizePref.getSavedFontSizeName());
    }

    return true;
  }