Search in sources :

Example 6 with TwoStatePreference

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;
}
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 7 with TwoStatePreference

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);
}
Also used : TwoStatePreference(androidx.preference.TwoStatePreference) Test(org.junit.Test)

Example 8 with TwoStatePreference

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));
}
Also used : TwoStatePreference(androidx.preference.TwoStatePreference) Calendar(java.util.Calendar) Date(java.util.Date)

Example 9 with TwoStatePreference

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();
}
Also used : TwoStatePreference(androidx.preference.TwoStatePreference) Test(org.junit.Test)

Example 10 with TwoStatePreference

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);
}
Also used : Context(android.content.Context) TwoStatePreference(androidx.preference.TwoStatePreference) Test(org.junit.Test)

Aggregations

TwoStatePreference (androidx.preference.TwoStatePreference)13 Test (org.junit.Test)8 Context (android.content.Context)7 Preference (androidx.preference.Preference)3 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 DropDownPreference (androidx.preference.DropDownPreference)1 EditTextPreference (androidx.preference.EditTextPreference)1 ListPreference (androidx.preference.ListPreference)1 OnPreferenceChangeListener (androidx.preference.Preference.OnPreferenceChangeListener)1 PreferenceScreen (androidx.preference.PreferenceScreen)1 SwitchPreferenceCompat (androidx.preference.SwitchPreferenceCompat)1 DefaultRingtonePreference (com.android.settings.DefaultRingtonePreference)1 Snackbar (com.google.android.material.snackbar.Snackbar)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1