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 onPreferenceStartScreen(PreferenceFragmentCompat preferenceFragmentCompat, PreferenceScreen preferenceScreen) { SettingsFragment fragment = new SettingsFragment(); Bundle args = new Bundle(); args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.getKey()); fragment.setArguments(args); FragmentTransaction ft = preferenceFragmentCompat.getFragmentManager().beginTransaction(); ft.add(R.id.fragment_container, fragment, preferenceScreen.getKey()); ft.addToBackStack(preferenceScreen.getTitle().toString()); ft.commit(); toolbar.setTitle(preferenceScreen.getTitle()); return true; }
public static boolean onDisplayPreferenceDialog(PreferenceFragmentCompat preferenceFragment, Preference preference) { if (preference instanceof ClearPatternPreference) { // getChildFragmentManager() will lead to looking for target fragment in the child // fragment manager. FragmentManager fragmentManager = preferenceFragment.getFragmentManager(); if (fragmentManager.findFragmentByTag(DIALOG_FRAGMENT_TAG) == null) { ClearPatternPreferenceDialogFragment dialogFragment = ClearPatternPreferenceDialogFragment.newInstance(preference.getKey()); dialogFragment.setTargetFragment(preferenceFragment, 0); dialogFragment.show(fragmentManager, DIALOG_FRAGMENT_TAG); } return true; } return false; }
@Override public boolean onPreferenceDisplayDialog(PreferenceFragmentCompat caller, Preference pref) { // check if dialog is already showing if (getFragmentManager().findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) { return true; } if (pref instanceof DialogPreference) { String key = pref.getKey(); final DialogFragment f; if (KEY_RELEASE_NOTE.equals(key)) { f = ReleaseNoteDialogFragment.newInstance(key); } else if (KEY_LICENSE.equals(key)) { f = LicenseDialogFragmentProvider.newFragment(getActivity()); } else { return false; } f.setTargetFragment(this, 0); f.show(getFragmentManager(), DIALOG_FRAGMENT_TAG); return true; } return false; }
protected void setSettingFragment(PreferenceFragmentCompat fragment) { // use the class name as the fragment tag. String tag = fragment.getClass().getSimpleName(); FragmentManager manager = getSupportFragmentManager(); FragmentTransaction tx = manager.beginTransaction(); tx.replace(R.id.content, fragment, tag); // Add to backstack only if this is not the first fragment, and the fragment is not already added. List<Fragment> fragments = manager.getFragments(); boolean isFirstFragment = fragments == null || fragments.size() == 0; Fragment existing = manager.findFragmentByTag(tag); boolean isAdded = existing != null; if (!isFirstFragment && !isAdded) { tx.addToBackStack(null); } tx.commit(); }
private void showFragment() { // figure out which fragment to show PreferenceFragmentCompat fragment = null; Intent intent = getIntent(); String fragmentName = intent.getStringExtra(EXTRA_FRAGMENT); if (fragmentName != null && fragmentName.equals(PerDatabaseFragment.class.getSimpleName())) { fragment = new PerDatabaseFragment(); } // default if (fragment == null) { fragment = new SettingsFragment(); } setSettingFragment(fragment); }
@Override public boolean onPreferenceTreeClick(Preference preference) { if (preference instanceof PreferenceScreen) { if (preference.getFragment() != null) { try { Class<?> clazz = getActivity().getClassLoader().loadClass(preference.getFragment()); if (PreferenceFragmentCompat.class.isAssignableFrom(clazz)) { Fragment pf = (Fragment) clazz.getConstructor().newInstance(); getActivity().getSupportFragmentManager() .beginTransaction() .replace(R.id.content_container, pf, SettingsActivity.ARG_SHOW_FRAGMENT) .addToBackStack(pf.getClass().getCanonicalName()) .commit(); return true; } } catch (Exception e) { Analytics.sendException(getActivity(), e, false); } } } return super.onPreferenceTreeClick(preference); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ImplicitCounter.count(this); //Enable the direct access of a specific sub section, e.g.: cards Intent intent = getIntent(); Bundle args = new Bundle(); if (intent != null && intent.getExtras() != null) { args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, intent.getExtras() .getString(Const.PREFERENCE_SCREEN)); } if (savedInstanceState == null) { // Create the fragment only when the activity is created for the first time. ie. not after orientation changes Fragment fragment = getSupportFragmentManager().findFragmentByTag(SettingsFragment.FRAGMENT_TAG); if (fragment == null) { fragment = new SettingsFragment(); } fragment.setArguments(args); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.settings_frame, fragment, SettingsFragment.FRAGMENT_TAG); ft.commit(); } }
@Override protected void onPreferenceScreenChanged(PreferenceFragmentCompat preferenceFragmentCompat, PreferenceScreen preferenceScreen) { super.onPreferenceScreenChanged(preferenceFragmentCompat, preferenceScreen); if (!TextUtils.isEmpty(preferenceScreen.getTitle())) { SettingsActivity a = (SettingsActivity) getActivity(); if (a != null) { a.toolbar.setTitle(preferenceScreen.getTitle()); } } }
@Deprecated @Override public boolean onPreferenceStartScreen(PreferenceFragmentCompat preferenceFragmentCompat, PreferenceScreen preferenceScreen) { _prefScreenBackstack.add(getPreferenceScreen()); preferenceFragmentCompat.setPreferenceScreen(preferenceScreen); updatePreferenceIcons.callback(this); onPreferenceScreenChanged(preferenceFragmentCompat, preferenceScreen); return true; }
@Override public boolean onPreferenceStartScreen( PreferenceFragmentCompat preferenceFragmentCompat, PreferenceScreen preferenceScreen) { if (isMultiPane(this)) { setTitle(preferenceScreen); } onStartSubScreen(preferenceScreen); return true; }
protected void onStartSubScreen(PreferenceScreen preferenceScreen) { Bundle args = new Bundle(); args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.getKey()); args.putString(ConstantsUI.PREF_SCREEN_TITLE, preferenceScreen.getTitle().toString()); replaceSettingsFragment(args); }
public void replaceSettingsFragment(Bundle args) { FragmentManager fm = getSupportFragmentManager(); NGPreferenceSettingsFragment fragment = (NGPreferenceSettingsFragment) fm.findFragmentByTag( getPreferenceSettingsFragmentTag()); if (null != fragment) { removeListener(fragment); } String subScreenKey = null; if (null != args) { subScreenKey = args.getString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT); } String tag = getPreferenceSettingsFragmentTag(); fragment = getNewPreferenceSettingsFragment(subScreenKey); addListener(fragment); if (null != args) { fragment.setArguments(args); } FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.setting_fragment, fragment, tag); if (!isMultiPane(this)) { ft.addToBackStack(tag); } ft.commit(); }
@Override public boolean onPreferenceDisplayDialog(PreferenceFragmentCompat preferenceFragmentCompat, Preference preference) { final String key = preference.getKey(); DialogFragment f; if (preference instanceof ColorPreference) { f = XpColorPreferenceDialogFragment.newInstance(key); } else { return false; } f.setTargetFragment(preferenceFragmentCompat, 0); f.show(this.getSupportFragmentManager(), key); return true; }
public void tintAllPrefIcons(PreferenceFragmentCompat preferenceFragment, @ColorInt int iconColor) { for (String prefKey : preferenceFragment.getPreferenceManager().getSharedPreferences().getAll().keySet()) { Preference pref = preferenceFragment.findPreference(prefKey); if (pref != null) { pref.setIcon(_cu.tintDrawable(pref.getIcon(), iconColor)); } } }
@Override public boolean onPreferenceStartScreen(PreferenceFragmentCompat caller, PreferenceScreen preferenceScreen) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); BarcodeSettingsFragment fragment = BarcodeSettingsFragment.newInstance("Barcode settings"); Bundle args = new Bundle(); args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.getKey()); fragment.setArguments(args); transaction.replace(R.id.settings_fragment, fragment, preferenceScreen.getKey()); transaction.addToBackStack(null); transaction.commit(); return true; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); currentThemeIsDark = App.get().isDarkTheme(); setTheme(currentThemeIsDark ? R.style.PreferenceAppThemeDark : R.style.PreferenceAppThemeLight); setContentView(R.layout.activity_settings); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(true); actionBar.setTitle(R.string.activity_title_settings); } PreferenceFragmentCompat fragment = null; Intent intent = getIntent(); if (intent != null) { String settingsArgument = intent.getStringExtra(ARG_NEW_PREFERENCE_SCREEN); if (settingsArgument != null) { if (settingsArgument.equals(NotificationsSettingsFragment.PREFERENCE_SCREEN_NAME)) { fragment = new NotificationsSettingsFragment(); } } } if (fragment == null) { fragment = new SettingsFragment(); } getSupportFragmentManager().beginTransaction().replace(R.id.fragment_content, fragment).commit(); /*View view = findViewById(R.id.fragment_content); view.setBackgroundColor(Color.TRANSPARENT); view.setBackgroundColor(Color.rgb(4, 26, 55));*/ App.get().addPreferenceChangeObserver(appThemeChangeObserver); }
@Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); ActionBar actionBar=getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeAsUpIndicator(R.drawable.ic_back_white_24dp); if (savedInstanceState == null) { PreferenceFragmentCompat fragment=new SettingsFragment(); if (getIntent()!=null){ String title = getIntent().getStringExtra("title"); if (title != null){ actionBar.setTitle(title); } String key = getIntent().getStringExtra(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT); if (key != null) { Bundle args=new Bundle(); args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, key); fragment.setArguments(args); } } getSupportFragmentManager() .beginTransaction() .add(R.id.activity_settings_container,fragment) .commit(); } }
@Override public boolean onPreferenceStartScreen(PreferenceFragmentCompat caller, PreferenceScreen pref) { startActivity( new Intent(this, SettingsActivity.class) .putExtra("title", pref.getTitle()) .putExtra(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, pref.getKey()) ); return true; }
@Override public boolean onPreferenceDisplayDialog(PreferenceFragmentCompat caller, Preference pref) { DialogPreferenceCompatDialogFragment fragment = new DialogPreferenceCompatDialogFragment(); fragment.setTargetFragment(caller, 0); fragment.show(caller.getFragmentManager(), DIALOG_FRAGMENT_TAG); return true; }
@Override public boolean onPreferenceStartScreen(PreferenceFragmentCompat preferenceFragmentCompat, PreferenceScreen preferenceScreen) { MyPreferenceFragment fragment = new MyPreferenceFragment(); Bundle args = new Bundle(); args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.getKey()); fragment.setArguments(args); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.replace(R.id.fragment, fragment, preferenceScreen.getKey()); ft.addToBackStack(preferenceScreen.getKey()); ft.commitAllowingStateLoss(); return true; }
@Override public boolean onPreferenceStartScreen(PreferenceFragmentCompat preferenceFragmentCompat, PreferenceScreen preferenceScreen) { PrefsFragmentCompat fragment = new PrefsFragmentCompat(); Bundle args = new Bundle(); args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.getKey()); fragment.setArguments(args); getSupportFragmentManager().beginTransaction() .replace(android.R.id.content, fragment, preferenceScreen.getKey()) .addToBackStack(preferenceScreen.getKey()) .commit(); return true; }
public SyncPreferencesViewHolder(PreferenceFragmentCompat view) { syncEnabled = (SwitchPreferenceCompat) view.findPreference(view.getString(R.string.pref_sync_enabled)); providerList = (ListPreference) view.findPreference(view.getString(R.string.pref_sync_provider)); remoteFile = view.findPreference(view.getString(R.string.pref_remote_file)); syncInterval = (ListPreference) view.findPreference(view.getString(R.string.pref_sync_interval)); resetPreferences = view.findPreference(view.getString(R.string.pref_reset_preferences)); download = (PreferenceScreen) view.findPreference(view.getString(R.string.pref_sync_download)); upload = (PreferenceScreen) view.findPreference(view.getString(R.string.pref_sync_upload)); syncOnStart = (SwitchPreferenceCompat) view.findPreference(view.getString(R.string.pref_sync_on_app_start)); }
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if (intent != null && ACTION_PREFS_LEGACY.equals(intent.getAction())) { Fragment fragment = null; try { String clazzname = intent.getDataString(); if (clazzname != null) { Class<?> clazz = getClassLoader().loadClass(clazzname); if (PreferenceFragmentCompat.class.isAssignableFrom(clazz)) { fragment = (Fragment) clazz.getConstructor().newInstance(); } } } catch (Exception e) { e.printStackTrace(); } if (fragment != null) { Fragment oldFragment = getSupportFragmentManager().findFragmentByTag(ARG_SHOW_FRAGMENT); if (oldFragment == null || !fragment.getClass().equals(oldFragment.getClass())) { getSupportFragmentManager() .beginTransaction() .replace(R.id.content_container, fragment, ARG_SHOW_FRAGMENT) .addToBackStack(fragment.getClass().getCanonicalName()) .commit(); } } } }
/** * Displays preference dialogs which aren't supported by default in PreferenceFragmentCompat. * * @return true if we managed a preference which isn't supported by default, false otherwise. */ public static boolean onDisplayPreferenceDialog(PreferenceFragmentCompat preferenceFragmentCompat, Preference preference) { DialogFragment dialogFragment = (DialogFragment) preferenceFragmentCompat.getFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG); if (dialogFragment != null) return false; // Hack to allow a MultiSelectListPreference if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH && preference instanceof MultiSelectListPreference) { dialogFragment = MultiSelectListPreferenceDialogFragmentCompat.newInstance(preference.getKey()); } // Hack to allow a PasswordPreference //else if (preference instanceof PasswordPreference) { // dialogFragment = PasswordPreferenceDialogFragmentCompat.newInstance(preference.getKey()); //} // We've created our own fragment: if (dialogFragment != null) { dialogFragment.setTargetFragment(preferenceFragmentCompat, 0); dialogFragment.show(preferenceFragmentCompat.getFragmentManager(), FRAGMENT_TAG_DIALOG); return true; } return false; }
@Override public boolean onPreferenceStartScreen(PreferenceFragmentCompat pfc, PreferenceScreen screen) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.fragment_container, UTilitiesPreferenceFragment.newInstance("experimental"), UTilitiesPreferenceFragment.class.getSimpleName()); transaction.addToBackStack(null); transaction.commit(); return true; }
public static GenericPreferenceScreen newInstance(@XmlRes int preferenceXml, String root) { Bundle arguments = new Bundle(); arguments.putInt("PreferencesXML", preferenceXml); arguments.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, root); GenericPreferenceScreen genericPreferenceScreen = new GenericPreferenceScreen(); genericPreferenceScreen.setArguments(arguments); return genericPreferenceScreen; }
@Override public boolean onPreferenceStartScreen(PreferenceFragmentCompat preferenceFragmentCompat, PreferenceScreen preferenceScreen) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); SettingsFragment fragment = new SettingsFragment(); Bundle args = new Bundle(); args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.getKey()); fragment.setArguments(args); ft.replace(R.id.settings_frame, fragment, preferenceScreen.getKey()); ft.addToBackStack(preferenceScreen.getKey()); ft.commit(); return true; }
@Override public boolean onPreferenceStartScreen(PreferenceFragmentCompat preferenceFragmentCompat, PreferenceScreen preferenceScreen) { BasePreferenceFragment fragment = new BasePreferenceFragment(); Bundle args = new Bundle(); args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.getKey()); fragment.setArguments(args); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.replace(R.id.content, fragment, preferenceScreen.getKey()); ft.addToBackStack(preferenceScreen.getKey()); ft.commit(); return true; }
protected boolean goBack() { BasePreferenceFragment fragment = (BasePreferenceFragment) getSupportFragmentManager().findFragmentById(R.id.content); if (fragment!=null && fragment.getArguments()!=null) { if (fragment.getArguments().get(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT)!=null) { getSupportFragmentManager().popBackStack(); return true; } } setResult(RESULT_OK); finish(); return true; }
public void tintAllPrefIcons(PreferenceFragmentCompat preferenceFragment, @ColorInt int iconColor) { tintPrefIconsRecursive(getPreferenceScreen(), iconColor); }
@Override public boolean onPreferenceStartScreen(final PreferenceFragmentCompat preferenceFragmentCompat, final PreferenceScreen preferenceScreen) { mReplaceFragmentStrategy.onPreferenceStartScreen(getSupportFragmentManager(), preferenceFragmentCompat, preferenceScreen); return true; }
@Override public PreferenceFragmentCompat onBuildPreferenceFragment(final String rootKey) { return SettingsFragment.newInstance(rootKey); }