Preference setOnPreferenceChangeListener - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Preference setOnPreferenceChangeListener method.

This code example shows how to use the following methods:setOnPreferenceChangeListener, setChecked
  public void onResume() { 
    super.onResume(); 
 
    CheckBoxPreference pref=(CheckBoxPreference)findPreference(KEY_ENABLED);
     
    pref.setChecked(mgr.isAdminActive(cn));
    pref.setOnPreferenceChangeListener(this);
  } 
 
  @Override 
  public boolean onPreferenceChange(Preference pref, Object newValue) {
    if (KEY_ENABLED.equals(pref.getKey())) {
      boolean value=((Boolean)newValue).booleanValue();
 
      if (value) {
        Intent intent=
            new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, cn);
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                        getString(R.string.device_admin_explanation));
6
CodeRank
This code example shows how to use the following methods:setOnPreferenceChangeListener
        mCheckbox.setOnPreferenceChangeListener(this);
    } 
 
    public void pause() { 
        mContext.unregisterReceiver(mReceiver);
        mCheckbox.setOnPreferenceChangeListener(null);
    } 
 
    public boolean onPreferenceChange(Preference preference, Object value) {
 
        final boolean desiredState = (Boolean) value;
        mCheckbox.setEnabled(false);
        mNsdManager.setEnabled(desiredState);
        return false; 
    } 
 
    private void handleNsdStateChanged(int newState) {
        switch (newState) {
            case NsdManager.NSD_STATE_DISABLED:
                mCheckbox.setChecked(false);
7
CodeRank
This code example shows how to use the following methods:getKey, setOnPreferenceChangeListener
     * immediately updated upon calling this method. The exact display format is 
     * dependent on the type of preference. 
     */ 
    public static void bindPreferenceSummaryToValue(SharedPreferences prefs, Preference preference) {
        // Set the listener to watch for value changes. 
        preference.setOnPreferenceChangeListener(sSetSummaryListener);
 
        // Trigger the listener immediately with the preference's current value. 
        sSetSummaryListener
                .onPreferenceChange(preference, prefs.getString(preference.getKey(), ""));
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:setDefaultValue, setKey, setOnPreferenceChangeListener, setSummary, setTitle
This code example shows how to use the following methods:getEntry, setSummary, setOnPreferenceChangeListener
This code example shows how to use the following methods:getContext, getKey, setOnPreferenceChangeListener
	 * @see #sBindPreferenceSummaryToValueListener 
	 */ 
	private static void bindPreferenceSummaryToValue(Preference preference) {
		// Set the listener to watch for value changes. 
		preference
				.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
 
		// Trigger the listener immediately with the preference's 
		// current value. 
		sBindPreferenceSummaryToValueListener.onPreferenceChange(
				preference,
				PreferenceManager.getDefaultSharedPreferences(
						preference.getContext()).getString(preference.getKey(),
						"")); 
	} 
 
	/** 
	 * This fragment shows general preferences only. It is used when the 
	 * activity is showing a two-pane settings UI. 
	 */ 
7
CodeRank
This code example shows how to use the following methods:setOnPreferenceChangeListener
        mParent = mFragment.getPreferenceScreen();
        mVoiceCategory = (PreferenceCategory) mParent.findPreference(KEY_VOICE_CATEGORY);
        mRecognizerPref = (ListPreference) mVoiceCategory.findPreference(KEY_RECOGNIZER);
        mRecognizerSettingsPref = mVoiceCategory.findPreference(KEY_RECOGNIZER_SETTINGS);
        mTtsSettingsPref = mVoiceCategory.findPreference(KEY_TTS_SETTINGS);
        mRecognizerPref.setOnPreferenceChangeListener(this);
        mSettingsPref = (PreferenceScreen)
                mVoiceCategory.findPreference(KEY_RECOGNIZER_SETTINGS);
 
        mAvailableRecognizersMap = new HashMap<String, ResolveInfo>();
 
        populateOrRemovePreferences(); 
    } 
 
    private void populateOrRemovePreferences() { 
        boolean hasRecognizerPrefs = populateOrRemoveRecognizerPrefs();
        boolean hasTtsPrefs = populateOrRemoveTtsPrefs();
        if (!hasRecognizerPrefs && !hasTtsPrefs) {
            // There were no TTS settings and no recognizer settings, 
            // so it should be safe to hide the preference category 
6
CodeRank
This code example shows how to use the following methods:setEnabled, setOnPreferenceChangeListener, isChecked
6
CodeRank
This code example shows how to use the following methods:setValueIndex, setOnPreferenceChangeListener
        mAutoAdvance = (ListPreference) findPreference(PREFERENCE_KEY_AUTO_ADVANCE);
        mAutoAdvance.setValueIndex(mPreferences.getAutoAdvanceDirection());
        mAutoAdvance.setOnPreferenceChangeListener(this);
 
        mTextZoom = (ListPreference) findPreference(PREFERENCE_KEY_TEXT_ZOOM);
        mTextZoom.setValueIndex(mPreferences.getTextZoom());
        mTextZoom.setOnPreferenceChangeListener(this);
 
        reloadDynamicSummaries(); 
    } 
 
    /** 
     * Reload any preference summaries that are updated dynamically 
     */ 
    private void reloadDynamicSummaries() { 
        int textZoomIndex = mPreferences.getTextZoom();
        // Update summary - but only load the array once 
        if (mSizeSummaries == null) {
            mSizeSummaries = getActivity().getResources()
                    .getTextArray(R.array.general_preference_text_zoom_summary_array);
7
CodeRank
This code example shows how to use the following methods:getEntry, setSummary, setOnPreferenceChangeListener

Related Preference setOnPreferenceChangeListener Questions & Answers:

setOnPreferenceChangeListener Method Overview
Sets the callback to be invoked when this Preference is changed by the user (but before the internal state has been updated).
See Code Examples for other Android Preference Methods: