@Override
 public boolean onPreferenceChange(Preference pref, Object newValue) {
   if (KEY_AUTO_SILENCE.equals(pref.getKey())) {
     final ListPreference autoSilencePref = (ListPreference) pref;
     String delay = (String) newValue;
     updateAutoSnoozeSummary(autoSilencePref, delay);
   } else if (KEY_CLOCK_STYLE.equals(pref.getKey())) {
     final ListPreference clockStylePref = (ListPreference) pref;
     final int idx = clockStylePref.findIndexOfValue((String) newValue);
     clockStylePref.setSummary(clockStylePref.getEntries()[idx]);
   } else if (KEY_HOME_TZ.equals(pref.getKey())) {
     final ListPreference homeTimezonePref = (ListPreference) pref;
     final int idx = homeTimezonePref.findIndexOfValue((String) newValue);
     homeTimezonePref.setSummary(homeTimezonePref.getEntries()[idx]);
     notifyHomeTimeZoneChanged();
   } else if (KEY_AUTO_HOME_CLOCK.equals(pref.getKey())) {
     final boolean autoHomeClockEnabled = ((CheckBoxPreference) pref).isChecked();
     final Preference homeTimeZonePref = findPreference(KEY_HOME_TZ);
     homeTimeZonePref.setEnabled(!autoHomeClockEnabled);
     notifyHomeTimeZoneChanged();
   } else if (KEY_VOLUME_BUTTONS.equals(pref.getKey())) {
     final ListPreference volumeButtonsPref = (ListPreference) pref;
     final int index = volumeButtonsPref.findIndexOfValue((String) newValue);
     volumeButtonsPref.setSummary(volumeButtonsPref.getEntries()[index]);
   } else if (KEY_WEEK_START.equals(pref.getKey())) {
     final ListPreference weekStartPref = (ListPreference) findPreference(KEY_WEEK_START);
     final int idx = weekStartPref.findIndexOfValue((String) newValue);
     weekStartPref.setSummary(weekStartPref.getEntries()[idx]);
   }
   // Set result so DeskClock knows to refresh itself
   getActivity().setResult(RESULT_OK);
   return true;
 }
 public boolean onPreferenceChange(Preference preference, Object newValue) {
   if (preference == mNetTrafficState) {
     int intState = Integer.valueOf((String) newValue);
     mNetTrafficVal = setBit(mNetTrafficVal, MASK_UP, getBit(intState, MASK_UP));
     mNetTrafficVal = setBit(mNetTrafficVal, MASK_DOWN, getBit(intState, MASK_DOWN));
     Settings.System.putInt(
         getActivity().getContentResolver(),
         Settings.System.NETWORK_TRAFFIC_STATE,
         mNetTrafficVal);
     int index = mNetTrafficState.findIndexOfValue((String) newValue);
     mNetTrafficState.setSummary(mNetTrafficState.getEntries()[index]);
     updateNetworkTrafficState(index);
     return true;
   } else if (preference == mNetTrafficColor) {
     String hex = ColorPickerPreference.convertToARGB(Integer.valueOf(String.valueOf(newValue)));
     preference.setSummary(hex);
     int intHex = ColorPickerPreference.convertToColorInt(hex);
     Settings.System.putInt(getContentResolver(), Settings.System.NETWORK_TRAFFIC_COLOR, intHex);
     return true;
   } else if (preference == mNetTrafficUnit) {
     mNetTrafficVal = setBit(mNetTrafficVal, MASK_UNIT, ((String) newValue).equals("1"));
     Settings.System.putInt(
         getActivity().getContentResolver(),
         Settings.System.NETWORK_TRAFFIC_STATE,
         mNetTrafficVal);
     int index = mNetTrafficUnit.findIndexOfValue((String) newValue);
     mNetTrafficUnit.setSummary(mNetTrafficUnit.getEntries()[index]);
     return true;
   } else if (preference == mNetTrafficPeriod) {
     int intState = Integer.valueOf((String) newValue);
     mNetTrafficVal = setBit(mNetTrafficVal, MASK_PERIOD, false) + (intState << 16);
     Settings.System.putInt(
         getActivity().getContentResolver(),
         Settings.System.NETWORK_TRAFFIC_STATE,
         mNetTrafficVal);
     int index = mNetTrafficPeriod.findIndexOfValue((String) newValue);
     mNetTrafficPeriod.setSummary(mNetTrafficPeriod.getEntries()[index]);
     return true;
   } else if (preference == mNetTrafficAutohide) {
     boolean value = (Boolean) newValue;
     Settings.System.putInt(
         getActivity().getContentResolver(),
         Settings.System.NETWORK_TRAFFIC_AUTOHIDE,
         value ? 1 : 0);
     return true;
   } else if (preference == mNetTrafficAutohideThreshold) {
     int threshold = (Integer) newValue;
     Settings.System.putInt(
         getActivity().getContentResolver(),
         Settings.System.NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD,
         threshold * 1);
     return true;
   }
   return false;
 }
  /** Loads the default values if we have them if not then blank it all out */
  private void loadDefaultValues() {
    try {
      mNotification.setChecked(pNotify.notify_active);
      mLed.setChecked(pNotify.led_active);
      mRinger.setChecked(pNotify.ringer_active);
      mVibrate.setChecked(pNotify.vibrate_active);
      mRingtone.setRingtone(Uri.parse(pNotify.ringtone));
      mRingVolume.setVolume(pNotify.ringer_vol);

      if (mNotifyIcon.findIndexOfValue(pNotify.notify_icon) > -1)
        mNotifyIcon.setValueIndex(mNotifyIcon.findIndexOfValue(pNotify.notify_icon));

      if (mLedPattern.findIndexOfValue(pNotify.led_pat) > -1)
        mLedPattern.setValueIndex(mLedPattern.findIndexOfValue(pNotify.led_pat));

      if (mLedColor.findIndexOfValue(pNotify.led_color) > -1)
        mLedColor.setValueIndex(mLedColor.findIndexOfValue(pNotify.led_color));

      if (mVibratePattern.findIndexOfValue(pNotify.vibrate_pat) > -1)
        mVibratePattern.setValueIndex(mVibratePattern.findIndexOfValue(pNotify.vibrate_pat));

    } catch (NullPointerException e) {
      if (Log.LOGV) Log.e(TAG + "Null pointer exception " + e.getLocalizedMessage().toString());
    } catch (RuntimeException e) {

    }
  }
        @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 {
            preference.setSummary(stringValue);
          }

          // detect errors
          if (preference.getKey().equals("sos_uri")) {
            try {
              URL url = new URL(value.toString());
              if (!url.getProtocol().equals("http") && !url.getProtocol().equals("https"))
                throw new Exception("SOS URL must be HTTP or HTTPS");
            } catch (Exception e) {
              AlertDialog.Builder dlgAlert = new AlertDialog.Builder(preference.getContext());
              dlgAlert.setMessage("Invalid SOS URL");
              dlgAlert.setTitle(e.getMessage());
              dlgAlert.setPositiveButton("OK", null);
              dlgAlert.setCancelable(true);
              dlgAlert.create().show();
            }
          }

          return true;
        }
        @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 RingtonePreference) {
            if (TextUtils.isEmpty(stringValue)) {
              preference.setSummary(R.string.pref_ringtone_silent);
            } else {
              Ringtone ringtone =
                  RingtoneManager.getRingtone(preference.getContext(), Uri.parse(stringValue));

              if (ringtone == null) {
                preference.setSummary(null);
              } else {
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
              }
            }
          } else {
            preference.setSummary(stringValue);
          }
          return true;
        }
        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
          String stringValue = value.toString();

          if (preference instanceof ListPreference) {
            // For list preferences, look up the correct display value in
            // the preference's 'entries' list.
            ListPreference listPreference = (ListPreference) preference;
            int index = listPreference.findIndexOfValue(stringValue);
            // Set the summary to reflect the new value.
            preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
          } else if (preference instanceof CheckBoxPreference) {
            // Trigger the listener immediately with the preference's
            // current value.
            if (preference.getKey().equals("prefHumidityOnTop")) {
              preference.setSummary(
                  Boolean.valueOf(stringValue)
                      ? R.string.pref_on_top_humidity_summary_yes
                      : R.string.pref_on_top_humidity_summary_no);
            }
          } else if (preference instanceof EditTextPreference) {
          } else {
            // For all other preferences, set the summary to the value's
            // simple string representation.
            preference.setSummary(stringValue);
          }
          return true;
        }
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    String stringValue = newValue.toString();
    String key = preference.getKey();

    if (preference instanceof ListPreference) {
      // For list preferences, look up the correct display value in
      // the preference's 'entries' list (since they have separate labels/values).
      ListPreference listPreference = (ListPreference) preference;
      int prefIndex = listPreference.findIndexOfValue(stringValue);
      if (prefIndex >= 0) {
        preference.setSummary(listPreference.getEntries()[prefIndex]);
      }
    } else if (key.equals(getString(R.string.pref_location_key))) {
      @SunshineSyncAdapter.LocationStatus int status = Utility.getLocationStatus(this);
      switch (status) {
        case SunshineSyncAdapter.LOCATION_STATUS_OK:
          preference.setSummary(stringValue);
          break;
        case SunshineSyncAdapter.LOCATION_STATUS_UNKNOWN:
          preference.setSummary(getString(R.string.pref_location_unknown_description, newValue));
          break;
        case SunshineSyncAdapter.LOCATION_STATUS_INVALID:
          preference.setSummary(getString(R.string.pref_location_error_description, newValue));
          break;
        default:
          preference.setSummary(stringValue);
      }
    } else {
      // For other preferences, set the summary to the value's simple string representation.
      preference.setSummary(stringValue);
    }
    return true;
  }
 /**
  * For each list dialog, we display the value selected in the "summary" text. When a new value is
  * selected from the list dialog, update the summary to the selected entry.
  */
 public boolean onPreferenceChange(Preference preference, Object newValue) {
   ListPreference list = (ListPreference) preference;
   int index = list.findIndexOfValue((String) newValue);
   CharSequence entry = list.getEntries()[index];
   preference.setSummary(entry);
   return true;
 }
Exemple #9
0
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (getActivity() == null) {
      // Monkeys cause bad things. This callback may be delayed if for some reason the
      // preference screen was closed really quickly - just bail then.
      return false;
    }

    final String key = preference.getKey();

    if (PreferenceKeys.REMOVAL_ACTION.equals(key)) {
      final String removalAction = newValue.toString();
      mMailPrefs.setRemovalAction(removalAction);
      updateListSwipeTitle(removalAction);
    } else if (AUTO_ADVANCE_WIDGET.equals(key)) {
      final int prefsAutoAdvanceMode =
          AUTO_ADVANCE_VALUES[mAutoAdvance.findIndexOfValue((String) newValue)];
      mMailPrefs.setAutoAdvanceMode(prefsAutoAdvanceMode);
    } else if (!PreferenceKeys.CONVERSATION_LIST_SWIPE.equals(key)
        && !PreferenceKeys.SHOW_SENDER_IMAGES.equals(key)
        && !PreferenceKeys.DEFAULT_REPLY_ALL.equals(key)
        && !PreferenceKeys.CONVERSATION_OVERVIEW_MODE.equals(key)
        && !PreferenceKeys.CONFIRM_DELETE.equals(key)
        && !PreferenceKeys.CONFIRM_ARCHIVE.equals(key)
        && !PreferenceKeys.CONFIRM_SEND.equals(key)) {
      return false;
    }

    return true;
  }
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
          if (preference instanceof ListPreference && newValue instanceof String) {
            final ListPreference listPreference = (ListPreference) preference;
            final int index = listPreference.findIndexOfValue((String) newValue);
            final CharSequence[] entries = listPreference.getEntries();

            if (index >= 0 && index < entries.length) {
              preference.setSummary(entries[index].toString().replaceAll("%", "%%"));
            } else {
              preference.setSummary("");
            }
          }

          final String key = preference.getKey();
          if (getString(R.string.pref_resume_talkback_key).equals(key)) {
            final String oldValue =
                SharedPreferencesUtils.getStringPref(
                    mPrefs,
                    getResources(),
                    R.string.pref_resume_talkback_key,
                    R.string.pref_resume_talkback_default);
            if (!newValue.equals(oldValue)) {
              // Reset the suspend warning dialog when the resume
              // preference changes.
              SharedPreferencesUtils.putBooleanPref(
                  mPrefs, getResources(), R.string.pref_show_suspension_confirmation_dialog, true);
            }
          }

          return true;
        }
  @Override
  public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    // are we starting the preference activity?
    if (!mBindingPreference) {
      if (preference.getKey().equals(getString(R.string.pref_location_key))) {
        FetchWeatherTask weatherTask = new FetchWeatherTask(this);
        String location = value.toString();
        weatherTask.execute(location);
      } else {
        // notify code that weather may be impacted
        getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null);
      }
    }

    if (preference instanceof ListPreference) {
      // For list preferences, look up the correct display value in
      // the preference's 'entries' list (since they have separate labels/values).
      ListPreference listPreference = (ListPreference) preference;
      int prefIndex = listPreference.findIndexOfValue(stringValue);
      if (prefIndex >= 0) {
        preference.setSummary(listPreference.getEntries()[prefIndex]);
      }
    } else {
      // For other preferences, set the summary to the value's simple string representation.
      preference.setSummary(stringValue);
    }
    return true;
  }
        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
          // Do not bind toggles.
          if (preference instanceof CheckBoxPreference
              || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
                  && preference instanceof TwoStatePreference)) {
            return true;
          }

          String stringValue = value.toString();

          if (preference instanceof ListPreference) {
            // For list preferences, look up the correct display value in
            // the preference's 'entries' list.
            ListPreference listPreference = (ListPreference) preference;
            int index = listPreference.findIndexOfValue(stringValue);

            // Set the summary to reflect the new value.
            preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

          } else if (preference instanceof RingtonePreference) {
            // For ringtone preferences, look up the correct display value
            // using RingtoneManager.
            if (TextUtils.isEmpty(stringValue)) {
              // Empty values correspond to 'silent' (no ringtone).
              preference.setSummary(R.string.ringtone_silent);
            } else {
              Ringtone ringtone =
                  RingtoneManager.getRingtone(preference.getContext(), Uri.parse(stringValue));

              if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
              } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
              }
            }

          } else if (preference instanceof EditTextPreference) {
            EditTextPreference textPreference = (EditTextPreference) preference;
            int inputType = textPreference.getEditText().getInputType();
            if (inputType == (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)) {
              preference.setSummary(stringValue.replaceAll(".", "*"));
            } else {
              preference.setSummary(stringValue);
            }
          } else {
            // For all other preferences, set the summary to the value's
            // simple string representation.
            preference.setSummary(stringValue);
          }
          return true;
        }
Exemple #13
0
 public boolean onPreferenceChange(Preference paramPreference, Object paramObject) {
   ListPreference localListPreference = (ListPreference) paramPreference;
   int i = localListPreference.findIndexOfValue((String) paramObject);
   String str = localListPreference.getEntries()[i].toString();
   Settings localSettings = this.a;
   Object[] arrayOfObject = new Object[1];
   arrayOfObject[0] = str;
   paramPreference.setTitle(localSettings.getString(2131296703, arrayOfObject));
   return true;
 }
  public boolean onPreferenceChange(Preference preference, Object objValue) {
    if (preference == mListLanguage) {
      // set the new language to the array which will be transmitted later
      CellBroadcastSmsConfig.setConfigDataCompleteLanguage(
          mListLanguage.findIndexOfValue((String) objValue) + 1);
    }

    // always let the preference setting proceed.
    return true;
  }
 @Override
 public boolean onPreferenceChange(Preference preference, Object newValue) {
   String key = preference.getKey();
   // Indicate we need to send notifications to UI
   mSettingsChanged = true;
   if (PREFERENCE_KEY_AUTO_ADVANCE.equals(key)) {
     mPreferences.setAutoAdvanceDirection(mAutoAdvance.findIndexOfValue((String) newValue));
     return true;
   } else if (PREFERENCE_KEY_TEXT_ZOOM.equals(key)) {
     mPreferences.setTextZoom(mTextZoom.findIndexOfValue((String) newValue));
     reloadDynamicSummaries();
     return true;
   } else if (MailPrefs.PreferenceKeys.DEFAULT_REPLY_ALL.equals(key)) {
     mMailPrefs.setDefaultReplyAll((Boolean) newValue);
     return true;
   } else if (PREFERENCE_KEY_CONV_LIST_ICON.equals(key)) {
     mMailPrefs.setShowSenderImages((Boolean) newValue);
     return true;
   }
   return false;
 }
  /** Set preference summary. */
  private void setPreferenceSummary(Preference pref, Object value) {
    String stringValue = value.toString();

    if (pref instanceof ListPreference) {
      ListPreference listPreference = (ListPreference) pref;
      int prefIndex = listPreference.findIndexOfValue(stringValue);
      if (prefIndex >= 0) {
        listPreference.setSummary(listPreference.getEntries()[prefIndex]);

        Log.v("Settings", "summary = " + listPreference.getSummary());
      }
    }
  }
        @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 preference.setSummary(stringValue);

          return true;
        }
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (preference.getKey().equals("selectapp")) {
      ListPreference mAppPref = (ListPreference) preference;
      CharSequence[] mEntries = mAppPref.getEntries();
      mAppPref.setTitle(mEntries[mAppPref.findIndexOfValue((String) newValue)]);

      PackageManager pm = getActivity().getPackageManager();

      try {
        mAppPref.setIcon(pm.getApplicationIcon((String) newValue));
      } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    if (preference.getKey().equals("selectadvancedapp")) {
      ListPreference mAdvancedAppPref = (ListPreference) preference;
      CharSequence[] mEntries = mAdvancedAppPref.getEntries();
      mAdvancedAppPref.setTitle(mEntries[mAdvancedAppPref.findIndexOfValue((String) newValue)]);

      PackageManager pm = getActivity().getPackageManager();

      try {
        mAdvancedAppPref.setIcon(pm.getApplicationIcon((String) newValue));
      } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    if (preference.getKey().equals("baud_rate")) {
      ListPreference baudRatePref = (ListPreference) preference;
      CharSequence[] mEntries = baudRatePref.getEntries();
      baudRatePref.setTitle(mEntries[baudRatePref.findIndexOfValue((String) newValue)]);
    }

    return true;
  }
 public boolean onPreferenceChange(Preference preference, Object objValue) {
   if (preference == mVolumeKeyCursorControl) {
     String volumeKeyCursorControl = (String) objValue;
     int val = Integer.parseInt(volumeKeyCursorControl);
     Settings.System.putInt(getContentResolver(), Settings.System.VOLUME_KEY_CURSOR_CONTROL, val);
     int index = mVolumeKeyCursorControl.findIndexOfValue(volumeKeyCursorControl);
     mVolumeKeyCursorControl.setSummary(mVolumeKeyCursorControl.getEntries()[index]);
     return true;
   } else if (preference == mDisableFullscreenKeyboard) {
     Settings.System.putInt(
         getContentResolver(),
         Settings.System.DISABLE_FULLSCREEN_KEYBOARD,
         (Boolean) objValue ? 1 : 0);
     return true;
   } else if (preference == mStatusBarImeSwitcher) {
     Settings.System.putInt(
         getContentResolver(),
         Settings.System.STATUS_BAR_IME_SWITCHER,
         (Boolean) objValue ? 1 : 0);
     return true;
   } else if (preference == mKeyboardRotationToggle) {
     boolean isAutoRotate =
         (Settings.System.getIntForUser(
                 getContentResolver(),
                 Settings.System.ACCELEROMETER_ROTATION,
                 0,
                 UserHandle.USER_CURRENT)
             == 1);
     if (isAutoRotate && (Boolean) objValue) {
       showDialogInner(DLG_KEYBOARD_ROTATION);
     }
     Settings.System.putInt(
         getContentResolver(),
         Settings.System.KEYBOARD_ROTATION_TIMEOUT,
         (Boolean) objValue ? KEYBOARD_ROTATION_TIMEOUT_DEFAULT : 0);
     updateRotationTimeout(KEYBOARD_ROTATION_TIMEOUT_DEFAULT);
     return true;
   } else if (preference == mShowEnterKey) {
     Settings.System.putInt(
         getContentResolver(), Settings.System.FORMAL_TEXT_INPUT, (Boolean) objValue ? 1 : 0);
     return true;
   } else if (preference == mKeyboardRotationTimeout) {
     int timeout = Integer.parseInt((String) objValue);
     Settings.System.putInt(
         getContentResolver(), Settings.System.KEYBOARD_ROTATION_TIMEOUT, timeout);
     updateRotationTimeout(timeout);
     return true;
   }
   return false;
 }
  private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();
    String key = preference.getKey();

    if (preference instanceof ListPreference) {
      ListPreference listPreference = (ListPreference) preference;
      int prefIndex = listPreference.findIndexOfValue(stringValue);
      if (prefIndex >= 0) {
        preference.setSummary(listPreference.getEntries()[prefIndex]);
      }
    } else {
      preference.setSummary(stringValue);
    }
  }
  @Override
  public boolean onPreferenceChange(Preference preference, Object newObj) {
    String objValue = newObj.toString();

    if (preference instanceof ListPreference) {

      ListPreference listPreference = (ListPreference) preference;
      int indexOfPref = listPreference.findIndexOfValue(objValue);
      if (indexOfPref >= 0) {
        preference.setSummary(listPreference.getEntries()[indexOfPref]);
      }
    } else {
      preference.setSummary(objValue);
    }
    return true;
  }
    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
      String stringValue = newValue.toString();

      if (preference instanceof ListPreference) {

        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(stringValue);
        if (prefIndex >= 0) {
          preference.setSummary(listPreference.getEntries()[prefIndex]);
        }
      } else {
        preference.setSummary(stringValue);
      }
      return true;
    }
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
          if (preference instanceof ListPreference) {
            // For list preferences, look up the correct display value in
            // the preference's 'entries' list.
            ListPreference listPreference = (ListPreference) preference;
            String stringValue = newValue.toString();
            int index = listPreference.findIndexOfValue(stringValue);

            // Set the summary to reflect the new value. Escape '%'.
            preference.setSummary(
                index >= 0
                    ? (listPreference.getEntries()[index]).toString().replaceAll("%", "%%")
                    : null);
          }
          return true;
        }
 /** Handles time zone preference changes */
 @Override
 public boolean onPreferenceChange(Preference preference, Object newValue) {
   String tz;
   final Activity activity = getActivity();
   if (preference == mUseHomeTZ) {
     if ((Boolean) newValue) {
       tz = mTimeZoneId;
     } else {
       tz = CalendarCache.TIMEZONE_TYPE_AUTO;
     }
     Utils.setTimeZone(activity, tz);
     return true;
   } else if (preference == mHideDeclined) {
     mHideDeclined.setChecked((Boolean) newValue);
     Intent intent = new Intent(Utils.getWidgetScheduledUpdateAction(activity));
     intent.setDataAndType(CalendarContract.CONTENT_URI, Utils.APPWIDGET_DATA_TYPE);
     activity.sendBroadcast(intent);
     return true;
   } else if (preference == mWeekStart) {
     mWeekStart.setValue((String) newValue);
     mWeekStart.setSummary(mWeekStart.getEntry());
   } else if (preference == mDefaultReminder) {
     mDefaultReminder.setValue((String) newValue);
     mDefaultReminder.setSummary(mDefaultReminder.getEntry());
   } else if (preference == mSnoozeDelay) {
     mSnoozeDelay.setValue((String) newValue);
     mSnoozeDelay.setSummary(mSnoozeDelay.getEntry());
   } else if (preference == mRingtone) {
     if (newValue instanceof String) {
       Utils.setRingTonePreference(activity, (String) newValue);
       String ringtone = getRingtoneTitleFromUri(activity, (String) newValue);
       mRingtone.setSummary(ringtone == null ? "" : ringtone);
     }
     return true;
   } else if (preference == mVibrate) {
     mVibrate.setChecked((Boolean) newValue);
     return true;
   } else if (preference == mDefaultStart) {
     int i = mDefaultStart.findIndexOfValue((String) newValue);
     mDefaultStart.setSummary(mDefaultStart.getEntries()[i]);
     return true;
   } else {
     return true;
   }
   return false;
 }
        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
          String stringValue = value.toString();

          if (preference instanceof ListPreference) {
            // For list preferences, look up the correct display value in
            // the preference's 'entries' list.
            ListPreference listPreference = (ListPreference) preference;
            int index = listPreference.findIndexOfValue(stringValue);

            // Set the summary to reflect the new value.
            preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

            //                preference.setSummary(stringValue);
          }
          return true;
        }
        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
          String stringValue = value.toString();

          if (preference instanceof ListPreference) {
            // For list preferences, look up the correct display value in
            // the preference's 'entries' list.
            ListPreference listPreference = (ListPreference) preference;
            int index = listPreference.findIndexOfValue(stringValue);

            // Set the summary to reflect the new value.
            preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

          } else if (preference instanceof RingtonePreference) {
            // For ringtone preferences, look up the correct display value
            // using RingtoneManager.
            if (TextUtils.isEmpty(stringValue)) {
              // Empty values correspond to 'silent' (no ringtone).
              preference.setSummary(R.string.pref_ringtone_silent);

            } else {
              Ringtone ringtone =
                  RingtoneManager.getRingtone(preference.getContext(), Uri.parse(stringValue));

              if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
              } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
              }
            }

          } else if (preference instanceof EditTextPreference) {
            // For all other preferences, set the summary to the value's
            // simple string representation.

            preference.setSummary(stringValue);
          } else {
            preference.setSummary(stringValue);
          }
          return true;
        }
  @Override
  public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
      // For list preferences, look up the correct display value in
      // the preference's 'entries' list (since they have separate labels/values).
      ListPreference listPreference = (ListPreference) preference;
      int prefIndex = listPreference.findIndexOfValue(stringValue);
      if (prefIndex >= 0) {
        preference.setSummary(listPreference.getEntries()[prefIndex]);
      }
    } else {
      // For other preferences, set the summary to the value's simple string representation.
      preference.setSummary(stringValue);
    }
    return true;
  }
  private void setPreferenceSummary(Preference preference, Object value) {
    String stringValue = value.toString();
    String key = preference.getKey();

    if (preference instanceof ListPreference) {
      // For list preferences, look up the correct display value in
      // the preference's 'entries' list (since they have separate labels/values).
      ListPreference listPreference = (ListPreference) preference;
      int prefIndex = listPreference.findIndexOfValue(stringValue);
      if (prefIndex >= 0) {
        preference.setSummary(listPreference.getEntries()[prefIndex]);
      }
    } else {
      // For other preferences, set the summary to the value's simple string representation.
      preference.setSummary(stringValue);
      Log.i(LOG_TAG, "setPreferenceSummary: " + stringValue);
    }
  }
  @Override
  public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
      // For list preferences, look up the correct display value in
      // the preference's 'entries' list.
      ListPreference listPreference = (ListPreference) preference;
      int index = listPreference.findIndexOfValue(stringValue);
      // Set the summary to reflect the new value.
      preference.setSummary(listPreference.getEntries()[index]);

    } else {
      // For all other preferences, set the summary to the value's
      // simple string representation.
      preference.setSummary(stringValue);
    }
    return true;
  }
 @Override
 public boolean onPreferenceChange(Preference preference, Object value) {
   if (SHOW_INPUT_METHOD_SWITCHER_SETTINGS) {
     if (preference == mShowInputMethodSelectorPref) {
       if (value instanceof String) {
         saveInputMethodSelectorVisibility((String) value);
       }
     }
   }
   if (preference == mVolumeKeyCursorControl) {
     String volumeKeyCursorControl = (String) value;
     int val = Integer.parseInt(volumeKeyCursorControl);
     Settings.System.putInt(
         getActivity().getContentResolver(), Settings.System.VOLUME_KEY_CURSOR_CONTROL, val);
     int index = mVolumeKeyCursorControl.findIndexOfValue(volumeKeyCursorControl);
     mVolumeKeyCursorControl.setSummary(mVolumeKeyCursorControl.getEntries()[index]);
     return true;
   }
   return false;
 }