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);
}
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);
}
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));
}
});
}
}
}
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;
}
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());
}
}
Aggregations