Search in sources :

Example 1 with OnPreferenceChangeListener

use of androidx.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class MasterSwitchPreferenceTest method clickWidgetView_shouldNotifyPreferenceChanged.

@Test
public void clickWidgetView_shouldNotifyPreferenceChanged() {
    final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext).inflate(R.layout.preference_two_target, null));
    final View widgetView = holder.findViewById(android.R.id.widget_frame);
    final OnPreferenceChangeListener listener = mock(OnPreferenceChangeListener.class);
    preference.setOnPreferenceChangeListener(listener);
    preference.onBindViewHolder(holder);
    preference.setChecked(false);
    widgetView.performClick();
    verify(listener).onPreferenceChange(preference, true);
    preference.setChecked(true);
    widgetView.performClick();
    verify(listener).onPreferenceChange(preference, false);
}
Also used : OnPreferenceChangeListener(androidx.preference.Preference.OnPreferenceChangeListener) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) View(android.view.View) Test(org.junit.Test)

Example 2 with OnPreferenceChangeListener

use of androidx.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class MasterCheckBoxPreferenceTest method clickWidgetView_shouldNotifyPreferenceChanged.

@Test
public void clickWidgetView_shouldNotifyPreferenceChanged() {
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext).inflate(R.layout.preference_two_target, null));
    final View widgetView = holder.findViewById(android.R.id.widget_frame);
    final OnPreferenceChangeListener listener = mock(OnPreferenceChangeListener.class);
    mPreference.setOnPreferenceChangeListener(listener);
    mPreference.onBindViewHolder(holder);
    mPreference.setChecked(false);
    widgetView.performClick();
    verify(listener).onPreferenceChange(mPreference, true);
    mPreference.setChecked(true);
    widgetView.performClick();
    verify(listener).onPreferenceChange(mPreference, false);
}
Also used : OnPreferenceChangeListener(androidx.preference.Preference.OnPreferenceChangeListener) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) View(android.view.View) Test(org.junit.Test)

Example 3 with OnPreferenceChangeListener

use of androidx.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppLaunchSettings method buildStateDropDown.

private void buildStateDropDown() {
    if (mIsBrowser) {
        // Browsers don't show the app-link prefs
        mAppLinkState.setShouldDisableView(true);
        mAppLinkState.setEnabled(false);
        mAppDomainUrls.setShouldDisableView(true);
        mAppDomainUrls.setEnabled(false);
    } else {
        // Designed order of states in the dropdown:
        // 
        // * always
        // * ask
        // * never
        // 
        // Make sure to update linkStateToIndex() if this presentation order is changed.
        mAppLinkState.setEntries(new CharSequence[] { getString(R.string.app_link_open_always), getString(R.string.app_link_open_ask), getString(R.string.app_link_open_never) });
        mAppLinkState.setEntryValues(new CharSequence[] { Integer.toString(INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS), Integer.toString(INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS_ASK), Integer.toString(INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER) });
        mAppLinkState.setEnabled(mHasDomainUrls);
        if (mHasDomainUrls) {
            // Present 'undefined' as 'ask' because the OS treats them identically for
            // purposes of the UI (and does the right thing around pending domain
            // verifications that might arrive after the user chooses 'ask' in this UI).
            final int state = mPm.getIntentVerificationStatusAsUser(mPackageName, UserHandle.myUserId());
            mAppLinkState.setValueIndex(linkStateToIndex(state));
            // Set the callback only after setting the initial selected item
            mAppLinkState.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    return updateAppLinkState(Integer.parseInt((String) newValue));
                }
            });
        }
    }
}
Also used : Preference(androidx.preference.Preference) DropDownPreference(androidx.preference.DropDownPreference) OnPreferenceChangeListener(androidx.preference.Preference.OnPreferenceChangeListener)

Example 4 with OnPreferenceChangeListener

use of androidx.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SettingPref method init.

public Preference init(SettingsPreferenceFragment settings) {
    final Context context = settings.getActivity();
    Preference p = settings.getPreferenceScreen().findPreference(mKey);
    if (p != null && !isApplicable(context)) {
        settings.getPreferenceScreen().removePreference(p);
        p = null;
    }
    if (p instanceof TwoStatePreference) {
        mTwoState = (TwoStatePreference) p;
    } else if (p instanceof DropDownPreference) {
        mDropDown = (DropDownPreference) p;
        CharSequence[] entries = new CharSequence[mValues.length];
        CharSequence[] values = new CharSequence[mValues.length];
        for (int i = 0; i < mValues.length; i++) {
            entries[i] = getCaption(context.getResources(), mValues[i]);
            values[i] = Integer.toString(mValues[i]);
        }
        mDropDown.setEntries(entries);
        mDropDown.setEntryValues(values);
    }
    update(context);
    if (mTwoState != null) {
        p.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                setSetting(context, (Boolean) newValue ? 1 : 0);
                return true;
            }
        });
        return mTwoState;
    }
    if (mDropDown != null) {
        p.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                return setSetting(context, Integer.parseInt((String) newValue));
            }
        });
        return mDropDown;
    }
    return null;
}
Also used : Context(android.content.Context) TwoStatePreference(androidx.preference.TwoStatePreference) TwoStatePreference(androidx.preference.TwoStatePreference) DropDownPreference(androidx.preference.DropDownPreference) Preference(androidx.preference.Preference) OnPreferenceChangeListener(androidx.preference.Preference.OnPreferenceChangeListener) DropDownPreference(androidx.preference.DropDownPreference)

Example 5 with OnPreferenceChangeListener

use of androidx.preference.Preference.OnPreferenceChangeListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ScreenPinningSettings method updateDisplay.

public void updateDisplay() {
    PreferenceScreen root = getPreferenceScreen();
    if (root != null) {
        root.removeAll();
    }
    if (isLockToAppEnabled(getActivity())) {
        addPreferencesFromResource(R.xml.screen_pinning_settings);
        root = getPreferenceScreen();
        mUseScreenLock = (SwitchPreference) root.findPreference(KEY_USE_SCREEN_LOCK);
        mUseScreenLock.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                return setScreenLockUsed((boolean) newValue);
            }
        });
        mUseScreenLock.setChecked(isScreenLockUsed());
        mUseScreenLock.setTitle(getCurrentSecurityTitle());
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) OnPreferenceChangeListener(androidx.preference.Preference.OnPreferenceChangeListener)

Aggregations

OnPreferenceChangeListener (androidx.preference.Preference.OnPreferenceChangeListener)7 Preference (androidx.preference.Preference)5 View (android.view.View)3 DropDownPreference (androidx.preference.DropDownPreference)3 PreferenceViewHolder (androidx.preference.PreferenceViewHolder)3 PreferenceScreen (androidx.preference.PreferenceScreen)2 SwitchPreference (androidx.preference.SwitchPreference)2 Test (org.junit.Test)2 Context (android.content.Context)1 OnClickListener (android.view.View.OnClickListener)1 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ListPreference (androidx.preference.ListPreference)1 PreferenceCategory (androidx.preference.PreferenceCategory)1 TwoStatePreference (androidx.preference.TwoStatePreference)1