Search in sources :

Example 1 with TwoStatePreference

use of androidx.preference.TwoStatePreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class GesturePreferenceControllerTest method updateState_preferenceSetUncheckedWhenSettingIsOff.

@Test
public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
    // Mock a TwoStatePreference
    final TwoStatePreference preference = mock(TwoStatePreference.class);
    // Set the setting to be disabled.
    mController.mIsPrefEnabled = false;
    // Run through updateState
    mController.updateState(preference);
    // Verify pref is unchecked (as setting is disabled).
    verify(preference).setChecked(false);
}
Also used : TwoStatePreference(androidx.preference.TwoStatePreference) Test(org.junit.Test)

Example 2 with TwoStatePreference

use of androidx.preference.TwoStatePreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PulseNotificationPreferenceControllerTest method updateState_preferenceSetUncheckedWhenSettingIsOff.

@Test
public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
    final TwoStatePreference preference = mock(TwoStatePreference.class);
    final Context context = RuntimeEnvironment.application;
    Settings.System.putInt(context.getContentResolver(), NOTIFICATION_LIGHT_PULSE, 0);
    mController = new PulseNotificationPreferenceController(context, "testkey");
    mController.updateState(preference);
    verify(preference).setChecked(false);
}
Also used : Context(android.content.Context) TwoStatePreference(androidx.preference.TwoStatePreference) Test(org.junit.Test)

Example 3 with TwoStatePreference

use of androidx.preference.TwoStatePreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class VibrateWhenRingPreferenceControllerTest method updateState_settingIsOn_preferenceShouldBeChecked.

@Test
public void updateState_settingIsOn_preferenceShouldBeChecked() {
    final TwoStatePreference preference = mock(TwoStatePreference.class);
    Settings.System.putInt(mContext.getContentResolver(), VIBRATE_WHEN_RINGING, 1);
    mController.updateState(preference);
    assertThat(mController.isChecked()).isTrue();
}
Also used : TwoStatePreference(androidx.preference.TwoStatePreference) Test(org.junit.Test)

Example 4 with TwoStatePreference

use of androidx.preference.TwoStatePreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AssistFlashScreenPreferenceController method updatePreference.

private void updatePreference() {
    if (mPreference == null || !(mPreference instanceof TwoStatePreference)) {
        return;
    }
    if (isAvailable()) {
        if (mScreen.findPreference(getPreferenceKey()) == null) {
            // add it if it's not on scree
            mScreen.addPreference(mPreference);
        }
    } else {
        mScreen.removePreference(mPreference);
    }
    ComponentName assistant = getCurrentAssist();
    boolean isContextChecked = AssistContextPreferenceController.isChecked(mContext);
    mPreference.setEnabled(isContextChecked && isPreInstalledAssistant(assistant));
    ((TwoStatePreference) mPreference).setChecked(willShowFlash(assistant));
}
Also used : TwoStatePreference(androidx.preference.TwoStatePreference) ComponentName(android.content.ComponentName)

Example 5 with TwoStatePreference

use of androidx.preference.TwoStatePreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WorkSoundPreferenceController method updateWorkPreferences.

private void updateWorkPreferences() {
    if (mWorkPreferenceCategory == null) {
        return;
    }
    final boolean isAvailable = isAvailable();
    mWorkPreferenceCategory.setVisible(isAvailable);
    if (!isAvailable) {
        return;
    }
    if (mWorkUsePersonalSounds == null) {
        mWorkUsePersonalSounds = (TwoStatePreference) mWorkPreferenceCategory.findPreference(KEY_WORK_USE_PERSONAL_SOUNDS);
        mWorkUsePersonalSounds.setOnPreferenceChangeListener((Preference p, Object value) -> {
            if ((boolean) value) {
                UnifyWorkDialogFragment.show(mParent);
                return false;
            } else {
                disableWorkSync();
                return true;
            }
        });
    }
    if (mWorkPhoneRingtonePreference == null) {
        mWorkPhoneRingtonePreference = initWorkPreference(mWorkPreferenceCategory, KEY_WORK_PHONE_RINGTONE);
    }
    if (mWorkNotificationRingtonePreference == null) {
        mWorkNotificationRingtonePreference = initWorkPreference(mWorkPreferenceCategory, KEY_WORK_NOTIFICATION_RINGTONE);
    }
    if (mWorkAlarmRingtonePreference == null) {
        mWorkAlarmRingtonePreference = initWorkPreference(mWorkPreferenceCategory, KEY_WORK_ALARM_RINGTONE);
    }
    if (!mVoiceCapable) {
        mWorkPhoneRingtonePreference.setVisible(false);
        mWorkPhoneRingtonePreference = null;
    }
    final Context managedProfileContext = getManagedProfileContext();
    if (Settings.Secure.getIntForUser(managedProfileContext.getContentResolver(), Settings.Secure.SYNC_PARENT_SOUNDS, 0, mManagedProfileId) == 1) {
        enableWorkSyncSettings();
    } else {
        disableWorkSyncSettings();
    }
}
Also used : Context(android.content.Context) DefaultRingtonePreference(com.android.settings.DefaultRingtonePreference) TwoStatePreference(androidx.preference.TwoStatePreference) Preference(androidx.preference.Preference)

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