@Override public boolean onPreferenceTreeClick(Preference preference) { if (preference.getKey().equals(thumbnailLoadToggleKey)) { final ImageLoader imageLoader = ImageLoader.getInstance(); imageLoader.stop(); imageLoader.clearDiskCache(); imageLoader.clearMemoryCache(); imageLoader.resume(); Toast.makeText(preference.getContext(), R.string.thumbnail_cache_wipe_complete_notice, Toast.LENGTH_SHORT).show(); } return super.onPreferenceTreeClick(preference); }
if (preference.getKey().equals(cacheWipeKey)) { InfoCache.getInstance().clearCache(); Toast.makeText(preference.getContext(), R.string.metadata_cache_wipe_complete_notice, Toast.LENGTH_SHORT).show();
@Override public boolean onLongClick(@NonNull Preference preference, @NonNull View view) { final Toast toast = Toast.makeText(preference.getContext(), "This showcases long click listeners on preferences.", Toast.LENGTH_SHORT); toast.show(); return true; } }
@NonNull public Context getContext() { return getPreference().getContext(); }
public static Boolean getBooleanPreferenceValue(Preference preference) { return android.support.v7.preference.PreferenceManager .getDefaultSharedPreferences(preference.getContext()) .getBoolean(preference.getKey(), true); }
public static String getStringPreferenceValue(Preference preference) { return android.support.v7.preference.PreferenceManager .getDefaultSharedPreferences(preference.getContext()) .getString(preference.getKey(), ""); }
public static Integer getIntegerPreferenceValue(Preference preference) { return android.support.v7.preference.PreferenceManager .getDefaultSharedPreferences(preference.getContext()) .getInt(preference.getKey(), -1); }
private static void bindPreferenceSummaryToValue(Preference preference) { //Don't bind the preference if it doesn't appear in this fragment if(preference != null) { // 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(), "")); } }
static void onCreatePreference(final @NonNull Preference preference, @Nullable final AttributeSet attrs) { final int defStyleAttr = getDefStyleAttr(preference); if (!(preference instanceof CustomIconPreference)) { final PreferenceIconHelper iconHelper = new PreferenceIconHelper(preference); iconHelper.loadFromAttributes(attrs, defStyleAttr, 0); PREFERENCE_ICON_HELPERS.put(preference, iconHelper); } if (preference instanceof DialogPreference && !(preference instanceof CustomDialogIconPreference)) { DialogPreference dialogPreference = (DialogPreference) preference; final DialogPreferenceIconHelper iconHelper = new DialogPreferenceIconHelper(dialogPreference); iconHelper.loadFromAttributes(attrs, defStyleAttr, 0); PREFERENCE_DIALOG_ICON_HELPERS.put(dialogPreference, iconHelper); } if (!(preference instanceof ColorableTextPreference)) { final PreferenceTextHelper textHelper = new PreferenceTextHelper(); textHelper.init(preference.getContext(), attrs, defStyleAttr, 0); PREFERENCE_TEXT_HELPERS.put(preference, textHelper); } }
public static void updatePreferenceSummary(Preference preference) { if (preference.getKey().equals("pref_download_location")) { bindPreferenceSummaryToValueListener.onPreferenceChange(preference, CheckPreferences.getDownloadLocation(preference.getContext())); } else if (preference instanceof SwitchPreference) { bindPreferenceSummaryToValueListener.onPreferenceChange(preference, CheckPreferences.getBooleanPreferenceValue(preference)); } else { bindPreferenceSummaryToValueListener.onPreferenceChange(preference, CheckPreferences.getStringPreferenceValue(preference)); } }
final Context context = preference.getContext(); final Uri selectedUri = Uri.parse(stringValue); final SafeRingtone ringtone = SafeRingtone.obtain(context, selectedUri); Toast.makeText(preference.getContext(), R.string.try_again, Toast.LENGTH_SHORT).show();
if (preference instanceof MultiSelectListPreference) { Set<String> summary = XpSharedPreferences.getStringSet( PreferenceManager.getDefaultSharedPreferences(preference.getContext()), key, new HashSet<String>()); } else { String value = PreferenceManager .getDefaultSharedPreferences(preference.getContext()) .getString(key, ""); sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, value);