@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;
  }
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    final FontSizePreference fontSizePref =
        (FontSizePreference) mPreferenceScreen.findPreference(FONT_SIZE_PREF_KEY);
    fontSizePref.onConfigurationChanged(newConfig);
  }
示例#3
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;
  }
  private void refresh(JSONArray jsonPrefs) {
    // enable all preferences once we have them from gecko
    GeckoAppShell.getMainHandler()
        .post(
            new Runnable() {
              public void run() {
                mPreferenceScreen.setEnabled(true);
              }
            });

    try {
      if (mPreferenceScreen == null) return;

      final int length = jsonPrefs.length();
      for (int i = 0; i < length; i++) {
        JSONObject jPref = jsonPrefs.getJSONObject(i);
        final String prefName = jPref.getString("name");
        final String prefType = jPref.getString("type");
        final Preference pref = mPreferenceScreen.findPreference(prefName);

        if (pref instanceof CheckBoxPreference && "bool".equals(prefType)) {
          final boolean value = jPref.getBoolean("value");
          GeckoAppShell.getMainHandler()
              .post(
                  new Runnable() {
                    public void run() {
                      if (((CheckBoxPreference) pref).isChecked() != value)
                        ((CheckBoxPreference) pref).setChecked(value);
                    }
                  });
        } else if (pref instanceof EditTextPreference && "string".equals(prefType)) {
          final String value = jPref.getString("value");
          GeckoAppShell.getMainHandler()
              .post(
                  new Runnable() {
                    public void run() {
                      ((EditTextPreference) pref).setText(value);
                    }
                  });
        } else if (pref instanceof ListPreference && "string".equals(prefType)) {
          final String value = jPref.getString("value");
          GeckoAppShell.getMainHandler()
              .post(
                  new Runnable() {
                    public void run() {
                      ((ListPreference) pref).setValue(value);
                      // Set the summary string to the current entry
                      CharSequence selectedEntry = ((ListPreference) pref).getEntry();
                      ((ListPreference) pref).setSummary(selectedEntry);
                    }
                  });
        } else if (pref instanceof FontSizePreference) {
          final FontSizePreference fontSizePref = (FontSizePreference) pref;
          final String twipValue = jPref.getString("value");
          fontSizePref.setSavedFontSize(twipValue);
          final String fontSizeName = fontSizePref.getSavedFontSizeName();
          GeckoAppShell.getMainHandler()
              .post(
                  new Runnable() {
                    public void run() {
                      fontSizePref.setSummary(fontSizeName); // Ex: "Small".
                    }
                  });
        }
      }
    } catch (JSONException e) {
      Log.e(LOGTAG, "Problem parsing preferences response: ", e);
    }
  }