Android Preference - top ranked examples from Open Source projects

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

This code example shows how to use the following methods: setOnPreferenceClickListener, setSummary, Preference.setIcon, Preference.setTitle
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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));
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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. 
	 */ 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setEnabled, setChecked
    } 
 
    private void handleNsdStateChanged(int newState) {
        switch (newState) {
            case NsdManager.NSD_STATE_DISABLED:
                mCheckbox.setChecked(false);
                mCheckbox.setEnabled(true);
                break; 
            case NsdManager.NSD_STATE_ENABLED:
                mCheckbox.setChecked(true);
                mCheckbox.setEnabled(true);
                break; 
        } 
    } 
} 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setOnPreferenceClickListener, setSummary, Preference.setIcon, Preference.setTitle
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setSummary, setValue, getKey
            updateEntry(pref);
        } 
    } 
 
    private void updateEntry(ListPreference pref) {
        String value = Settings.System.getString(getContentResolver(), pref.getKey());
        if (value == null) {
            value = "";
        } 
 
        CharSequence entry = findEntryForValue(pref, value);
        if (entry != null) {
            pref.setValue(value);
            pref.setSummary(entry);
            return; 
        } 
    } 
 
    private CharSequence findEntryForValue(ListPreference pref, CharSequence value) {
        CharSequence[] entries = pref.getEntryValues();
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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(), ""));
    } 
 
} 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getContext, setSummary
                // 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)); 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getContext, getKey, setOnPreferenceChangeListener
     * immediately called with the preference's current value upon calling this method. 
     */ 
    public static void setAndCallPreferenceChangeListener(Preference preference,
            Preference.OnPreferenceChangeListener listener) {
        // Set the listener to watch for value changes. 
        preference.setOnPreferenceChangeListener(listener);
 
        // Trigger the listener immediately with the preference's 
        // current value. 
        listener.onPreferenceChange(preference,
                PreferenceManager 
                        .getDefaultSharedPreferences(preference.getContext())
                        .getString(preference.getKey(), ""));
    } 
} 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getKey, setDependency
        } 
 
    } 
 
    private void setHapticButtonDep() { 
        mHapticFeedbackUpPref.setDependency(mHapticFeedbackPref.getKey());
        mHapticFeedbackAllPref.setDependency(mHapticFeedbackUpPref.getKey());
    } 
 
    public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
        if (HAPTIC_FEEDBACK_PREF.equals(key)) {
            Settings.System.putInt(getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED,
                    mHapticFeedbackPref.isChecked() ? 1 : 0);
        } else if (HAPTIC_FEEDBACK_UP_PREF.equals(key)) {
            Settings.System.putInt(getContentResolver(),
                    Settings.System.HAPTIC_FEEDBACK_UP_ENABLED, 
                    mHapticFeedbackUpPref.isChecked() ? 1 : 0);
        } else if (HAPTIC_FEEDBACK_ALL_PREF.equals(key)) {
            Settings.System.putInt(getContentResolver(),
                    Settings.System.HAPTIC_FEEDBACK_ALL_ENABLED, 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android Preference Questions & Answers:

See Code Examples for Android Preference Methods: