androidx.preference.Preference.OnPreferenceChangeListener Java Examples

The following examples show how to use androidx.preference.Preference.OnPreferenceChangeListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BehaviorPreferenceFragment.java    From AndroidPreferenceActivity with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a listener, which allows to adapt the behavior of the {@link PreferenceActivity} when
 * the value, which determines, whether the action bar's back button should be overwritten, has
 * been changed.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnPreferenceChangeListener}
 */
private OnPreferenceChangeListener createOverrideBackButtonChangeListener() {
    return new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            if (newValue != null) {
                boolean overrideNavigationIcon = (boolean) newValue;
                ((PreferenceActivity) getActivity())
                        .overrideNavigationIcon(overrideNavigationIcon);
            }

            return true;
        }

    };
}
 
Example #2
Source File: BehaviorPreferenceFragment.java    From AndroidPreferenceActivity with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a listener, which allows to adapt the behavior of the {@link PreferenceActivity} when
 * the value, which determines, whether the navigation should be hidden, has been changed.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnPreferenceChangeListener}
 */
private OnPreferenceChangeListener createHideNavigationChangeListener() {
    return new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            if (newValue != null) {
                boolean hideNavigation = (boolean) newValue;
                ((PreferenceActivity) getActivity()).hideNavigation(hideNavigation);
            }

            return true;
        }

    };
}
 
Example #3
Source File: AppearancePreferenceFragment.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a listener, which allows to adapt the app's theme, when the value of the
 * corresponding preference has been changed.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnPreferenceChangeListener}
 */
private OnPreferenceChangeListener createThemeChangeListener() {
    return new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            Intent intent = getActivity().getIntent();
            getActivity().finish();
            startActivity(intent);
            return true;
        }

    };
}
 
Example #4
Source File: AppearancePreferenceFragment.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a listener, which allows to adapt the elevation of the toolbar, when the
 * value of the corresponding preference has been changed.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnPreferenceChangeListener}
 */
private OnPreferenceChangeListener createToolbarElevationChangeListener() {
    return new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            int elevation = Integer.valueOf((String) newValue);
            ((PreferenceActivity) getActivity()).setToolbarElevation(elevation);
            return true;
        }

    };
}
 
Example #5
Source File: AppearancePreferenceFragment.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a listener, which allows to adapt the width of the navigation, when the
 * value of the corresponding preference has been changed.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnPreferenceChangeListener}
 */
private OnPreferenceChangeListener createNavigationWidthChangeListener() {
    return new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            int width = Integer.valueOf((String) newValue);
            ((PreferenceActivity) getActivity())
                    .setNavigationWidth(dpToPixels(getActivity(), width));
            return true;
        }

    };
}
 
Example #6
Source File: AppearancePreferenceFragment.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a listener, which allows to adapt the elevation of the preference screen,
 * when the value of the corresponding preference has been changed.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnPreferenceChangeListener}
 */
private OnPreferenceChangeListener createPreferenceScreenElevationChangeListener() {
    return new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            int elevation = Integer.valueOf((String) newValue);
            ((PreferenceActivity) getActivity()).setCardViewElevation(elevation);
            return true;
        }

    };
}
 
Example #7
Source File: AppearancePreferenceFragment.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a listener, which allows to adapt the elevation of the bread crumbs, when
 * the value of the corresponding preference has been changed.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnPreferenceChangeListener}
 */
private OnPreferenceChangeListener createBreadCrumbElevationChangeListener() {
    return new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            int elevation = Integer.valueOf((String) newValue);
            ((PreferenceActivity) getActivity()).setBreadCrumbElevation(elevation);
            return true;
        }

    };
}
 
Example #8
Source File: AppearancePreferenceFragment.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a listener, which allows to adapt the elevation of a wizard's button bar,
 * when the value of the corresponding preference has been changed.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnPreferenceChangeListener}
 */
private OnPreferenceChangeListener createWizardButtonBarElevationChangeListener() {
    return new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            int elevation = Integer.valueOf((String) newValue);
            ((PreferenceActivity) getActivity()).setButtonBarElevation(elevation);
            return true;
        }

    };
}
 
Example #9
Source File: AppearancePreferenceFragment.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a listener, which allows to adapt the elevation of a preference
 * fragment's button bar, when the value of the corresponding preference has been changed.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnPreferenceChangeListener}
 */
private OnPreferenceChangeListener createPreferenceFragmentButtonBarElevationChangeListener() {
    return new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            int elevation = Integer.valueOf((String) newValue);
            setButtonBarElevation(elevation);
            return true;
        }

    };
}
 
Example #10
Source File: PreferenceFragment.java    From AndroidMaterialDialog with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a listener, which allows to adapt the app's theme, when the value of the
 * corresponding preference has been changed.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnPreferenceChangeListener}
 */
private OnPreferenceChangeListener createThemeChangeListener() {
    return new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            getActivity().recreate();
            return true;
        }

    };
}