示例#1
0
 public static void sync(PreferenceManager preferenceManager, String key) {
   Preference pref = preferenceManager.findPreference(key);
   if (pref instanceof ListPreference) {
     ListPreference listPref = (ListPreference) pref;
     pref.setSummary(listPref.getEntry());
   }
 }
  @Override
  public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.settings);

    ListPreference precision = (ListPreference) findPreference(Helper.PRECISION_PREFERENCE);
    time = (EditTextPreference) findPreference(Helper.CUSTOMPRECISIONTIME_PREFERENCE);
    distance = (EditTextPreference) findPreference(Helper.CUSTOMPRECISIONDISTANCE_PREFERENCE);
    streambroadcast_distance =
        (EditTextPreference) findPreference(Helper.BROADCAST_STREAM_DISTANCE_METER);
    streambroadcast_time = (EditTextPreference) findPreference(Helper.BROADCAST_STREAM_TIME);
    custumupload_backlog = (EditTextPreference) findPreference(Helper.CUSTOM_UPLOAD_BACKLOG);
    setEnabledCustomValues(precision.getValue());
    precision.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            setEnabledCustomValues(newValue);
            return true;
          }
        });
    Preference.OnPreferenceChangeListener fiveDigits =
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            String fpExpr = "\\d{1,5}";
            return Pattern.matches(fpExpr, newValue.toString());
          }
        };
    Preference.OnPreferenceChangeListener twentyOneDigits =
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            String fpExpr = "\\d{1,21}";
            return Pattern.matches(fpExpr, newValue.toString());
          }
        };
    Preference.OnPreferenceChangeListener threeDigits =
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            String fpExpr = "\\d{1,3}";
            return Pattern.matches(fpExpr, newValue.toString());
          }
        };

    time.setOnPreferenceChangeListener(fiveDigits);
    distance.setOnPreferenceChangeListener(fiveDigits);
    streambroadcast_distance.setOnPreferenceChangeListener(fiveDigits);
    streambroadcast_time.setOnPreferenceChangeListener(twentyOneDigits);
    custumupload_backlog.setOnPreferenceChangeListener(threeDigits);
  }
示例#3
0
        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
          String stringValue = value.toString();

          if (preference instanceof ListPreference) {
            ListPreference listPreference = (ListPreference) preference;
            int index = listPreference.findIndexOfValue(stringValue);
            preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
          } else if (preference instanceof SeekBarPreferenceDialog) {
            int id = 0;
            if (preference.getKey().equals(Constants.KEY_NAVBAR_ALPHA))
              id = R.string.pref_navbar_opacity;
            else if (preference.getKey().equals(Constants.KEY_NAVBAR_DELAY))
              id = R.string.pref_navbar_delay;
            else if (preference.getKey().equals(Constants.KEY_NAVBAR_DURATION))
              id = R.string.pref_listview_duration_summary;

            if (id != 0) preference.setSummary(getString(id, stringValue));
          } else preference.setSummary(stringValue);

          if (!mIsLoading) XPastaHelpers.sendSettingsChanged(getActivity());

          return true;
        }