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()); } }
private void bindPreference(Preference preference) { preference.setOnPreferenceChangeListener(sBindPreferenceListener); SharedPreferences sprefs = PreferenceManager.getDefaultSharedPreferences(preference.getContext()); if (preference instanceof SeekBarPreferenceDialog) sBindPreferenceListener.onPreferenceChange( preference, sprefs.getInt(preference.getKey(), 100)); else sBindPreferenceListener.onPreferenceChange( preference, sprefs.getString(preference.getKey(), "0")); }
private void startSubSettingsIfNeeded() { if (getArguments() == null) { return; } String componentName = getArguments().getString(EXTRA_PRINT_SERVICE_COMPONENT_NAME); if (componentName != null) { getArguments().remove(EXTRA_PRINT_SERVICE_COMPONENT_NAME); Preference prereference = findPreference(componentName); if (prereference != null) { prereference.performClick(); } } }
public static boolean onDisplayPreferenceDialog( Preference preference, PreferenceFragmentCompat target) { boolean handled = false; if (target.getTargetFragment() instanceof PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) { handled = ((PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) target.getTargetFragment()) .onPreferenceDisplayDialog(target, preference); } if (!handled && target.getActivity() instanceof PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) { handled = ((PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) target.getActivity()) .onPreferenceDisplayDialog(target, preference); } // check if dialog is already showing if (!handled && target.getFragmentManager().findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) { handled = true; } if (!handled && preference instanceof SpectrumPreferenceCompat) { DialogFragment f = SpectrumPreferenceDialogFragmentCompat.newInstance(preference.getKey()); f.setTargetFragment(target, 0); f.show(target.getFragmentManager(), DIALOG_FRAGMENT_TAG); handled = true; } return handled; }
@Override public boolean onPreferenceStartFragment( PreferenceFragmentCompat callingFragment, Preference preference) { try { Fragment fragment = (Fragment) Class.forName(preference.getFragment()).newInstance(); Bundle args = new Bundle(); args.putInt(SettingsFragment.PREFERENCE_RES_ID, getPreferenceResId(preference.getKey())); fragment.setArguments(args); if (isDualPane()) { replaceFragment(R.id.scaffold_content_end_pane, fragment); } else { addFragmentToStack(R.id.scaffold_content, fragment); } return true; } catch (Exception ignored) { return false; } }
@Override protected void onClick() { super.onClick(); NumberPickerDialog dialog = NumberPickerDialog.newInstance(mValue, "Select flash count", new int[] {0, 10}); Activity activity = (Activity) getContext(); activity.getFragmentManager().beginTransaction().add(dialog, "number_picker").commit(); dialog.setListener(listener); }
@Override public void onDisplayPreferenceDialog(Preference preference) { if (preference instanceof TimePreference) { DialogFragment dialogFragment = TimePreferenceFragmentDialog.newInstance(preference.getKey()); dialogFragment.setTargetFragment(this, 0); dialogFragment.show( this.getFragmentManager(), "android.support.v7.preference.PreferenceFragment.DIALOG"); } else { super.onDisplayPreferenceDialog(preference); } }
@Override public void onAttached() { super.onAttached(); Activity activity = (Activity) getContext(); NumberPickerDialog numberPicker = (NumberPickerDialog) activity.getFragmentManager().findFragmentByTag(getFragmentTag()); if (numberPicker != null) { // re-bind listener to fragment numberPicker.setListener(listener); } }
private Preference newAddServicePreferenceOrNull() { final Intent addNewServiceIntent = createAddNewServiceIntentOrNull(); if (addNewServiceIntent == null) { return null; } Preference preference = new Preference(getPrefContext()); preference.setTitle(R.string.print_menu_item_add_service); preference.setIcon(R.drawable.ic_menu_add); preference.setOrder(ORDER_LAST); preference.setIntent(addNewServiceIntent); preference.setPersistent(false); return preference; }
@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; }
@Override public void onBindViewHolder(PreferenceViewHolder view) { super.onBindViewHolder(view); mPreviewView = view.findViewById(R.id.preview_text); setNumberViewValue(mPreviewView, mValue); }
@Override protected void onPrepareForRemoval() { mKeyboardShortcutHandler.unregisterOnSharedPreferenceChangeListener( mPreferencesChangeListener); super.onPrepareForRemoval(); }
@Override public void onAttached() { super.onAttached(); mKeyboardShortcutHandler.registerOnSharedPreferenceChangeListener(mPreferencesChangeListener); }
@Override public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); mView = holder.itemView; setPreviewColor(); }