Beispiel #1
0
 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"));
 }
  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 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);
   }
 }
Beispiel #4
0
        @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 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;
   }
 }