use of androidx.preference.TwoStatePreference 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.TwoStatePreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class GesturePreferenceControllerTest method updateState_preferenceSetCheckedWhenSettingIsOn.
@Test
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
// Mock a TwoStatePreference
final TwoStatePreference preference = mock(TwoStatePreference.class);
// Set the setting to be enabled.
mController.mIsPrefEnabled = true;
// Run through updateState
mController.updateState(preference);
// Verify pref is checked (as setting is enabled).
verify(preference).setChecked(true);
}
use of androidx.preference.TwoStatePreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class TimeFormatPreferenceController method updateState.
@Override
public void updateState(Preference preference) {
if (!(preference instanceof TwoStatePreference)) {
return;
}
preference.setEnabled(!AutoTimeFormatPreferenceController.isAutoTimeFormatSelection(mContext));
((TwoStatePreference) preference).setChecked(is24Hour());
final Calendar now = Calendar.getInstance();
mDummyDate.setTimeZone(now.getTimeZone());
// We use December 31st because it's unambiguous when demonstrating the date format.
// We use 13:00 so we can demonstrate the 12/24 hour options.
mDummyDate.set(now.get(Calendar.YEAR), 11, 31, 13, 0, 0);
final Date dummyDate = mDummyDate.getTime();
preference.setSummary(DateFormat.getTimeFormat(mContext).format(dummyDate));
}
use of androidx.preference.TwoStatePreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class VibrateWhenRingPreferenceControllerTest method updateState_settingIsOff_preferenceShouldNotBeChecked.
@Test
public void updateState_settingIsOff_preferenceShouldNotBeChecked() {
final TwoStatePreference preference = mock(TwoStatePreference.class);
Settings.System.putInt(mContext.getContentResolver(), VIBRATE_WHEN_RINGING, 0);
mController.updateState(preference);
assertThat(mController.isChecked()).isFalse();
}
use of androidx.preference.TwoStatePreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class PulseNotificationPreferenceControllerTest method updateState_preferenceSetCheckedWhenSettingIsOn.
@Test
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
final TwoStatePreference preference = mock(TwoStatePreference.class);
final Context context = RuntimeEnvironment.application;
Settings.System.putInt(context.getContentResolver(), NOTIFICATION_LIGHT_PULSE, 1);
mController = new PulseNotificationPreferenceController(context, "testkey");
mController.updateState(preference);
verify(preference).setChecked(true);
}
Aggregations