Search in sources :

Example 96 with SwitchPreference

use of androidx.preference.SwitchPreference in project android_packages_apps_Settings by omnirom.

the class ChannelListPreferenceController method addOrUpdateGroupToggle.

/**
 * Add or find and update the toggle for disabling the entire notification channel group.
 */
private Preference addOrUpdateGroupToggle(@NonNull final PreferenceGroup parent, @NonNull final NotificationChannelGroup group) {
    boolean shouldAdd = false;
    final RestrictedSwitchPreference preference;
    if (parent.getPreferenceCount() > 0 && parent.getPreference(0) instanceof RestrictedSwitchPreference) {
        preference = (RestrictedSwitchPreference) parent.getPreference(0);
    } else {
        shouldAdd = true;
        preference = new RestrictedSwitchPreference(mContext);
    }
    preference.setOrder(-1);
    preference.setTitle(mContext.getString(R.string.notification_switch_label, group.getName()));
    preference.setEnabled(mAdmin == null && isChannelGroupBlockable(group));
    preference.setChecked(!group.isBlocked());
    preference.setOnPreferenceClickListener(preference1 -> {
        final boolean allowGroup = ((SwitchPreference) preference1).isChecked();
        group.setBlocked(!allowGroup);
        mBackend.updateChannelGroup(mAppRow.pkg, mAppRow.uid, group);
        onGroupBlockStateChanged(group);
        return true;
    });
    if (shouldAdd) {
        parent.addPreference(preference);
    }
    return preference;
}
Also used : RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) SwitchPreference(androidx.preference.SwitchPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) PrimarySwitchPreference(com.android.settings.widget.PrimarySwitchPreference)

Example 97 with SwitchPreference

use of androidx.preference.SwitchPreference in project android_packages_apps_Settings by omnirom.

the class AutoSyncDataPreferenceControllerTest method autoSyncData_shouldNotBeSetOnCancel.

@Test
public void autoSyncData_shouldNotBeSetOnCancel() {
    final Context context = RuntimeEnvironment.application;
    final SwitchPreference preference = new SwitchPreference(context);
    preference.setChecked(false);
    mController = new AutoSyncDataPreferenceController(context, mFragment);
    mConfirmSyncFragment.mPreference = preference;
    mConfirmSyncFragment.mEnabling = true;
    mConfirmSyncFragment.onClick(null, DialogInterface.BUTTON_NEGATIVE);
    assertThat(preference.isChecked()).isFalse();
}
Also used : Context(android.content.Context) SwitchPreference(androidx.preference.SwitchPreference) Test(org.junit.Test)

Example 98 with SwitchPreference

use of androidx.preference.SwitchPreference in project android_packages_apps_Settings by omnirom.

the class MmsMessagePreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(ApplicationProvider.getApplicationContext());
    when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
    when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
    when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
    when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);
    mPreference = new SwitchPreference(mContext);
    mController = new MmsMessagePreferenceController(mContext, "mms_message");
    mController.init(SUB_ID);
    mPreference.setKey(mController.getPreferenceKey());
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) Before(org.junit.Before)

Example 99 with SwitchPreference

use of androidx.preference.SwitchPreference in project android_packages_apps_Settings by omnirom.

the class BluetoothDetailsProfilesController method refreshProfilePreference.

/**
 * Refreshes the state for an existing SwitchPreference for a profile.
 */
private void refreshProfilePreference(SwitchPreference profilePref, LocalBluetoothProfile profile) {
    BluetoothDevice device = mCachedDevice.getDevice();
    profilePref.setEnabled(!mCachedDevice.isBusy());
    if (profile instanceof MapProfile) {
        profilePref.setChecked(device.getMessageAccessPermission() == BluetoothDevice.ACCESS_ALLOWED);
    } else if (profile instanceof PbapServerProfile) {
        profilePref.setChecked(device.getPhonebookAccessPermission() == BluetoothDevice.ACCESS_ALLOWED);
    } else if (profile instanceof PanProfile) {
        profilePref.setChecked(profile.getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED);
    } else {
        profilePref.setChecked(profile.isEnabled(device));
    }
    if (profile instanceof A2dpProfile) {
        A2dpProfile a2dp = (A2dpProfile) profile;
        SwitchPreference highQualityPref = (SwitchPreference) mProfilesContainer.findPreference(HIGH_QUALITY_AUDIO_PREF_TAG);
        if (highQualityPref != null) {
            if (a2dp.isEnabled(device) && a2dp.supportsHighQualityAudio(device)) {
                highQualityPref.setVisible(true);
                highQualityPref.setTitle(a2dp.getHighQualityAudioOptionLabel(device));
                highQualityPref.setChecked(a2dp.isHighQualityAudioEnabled(device));
                highQualityPref.setEnabled(!mCachedDevice.isBusy());
            } else {
                highQualityPref.setVisible(false);
            }
        }
    }
}
Also used : MapProfile(com.android.settingslib.bluetooth.MapProfile) PbapServerProfile(com.android.settingslib.bluetooth.PbapServerProfile) A2dpProfile(com.android.settingslib.bluetooth.A2dpProfile) BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) PanProfile(com.android.settingslib.bluetooth.PanProfile) SwitchPreference(androidx.preference.SwitchPreference)

Example 100 with SwitchPreference

use of androidx.preference.SwitchPreference in project android_packages_apps_Settings by omnirom.

the class BluetoothDetailsProfilesController method onPreferenceClick.

/**
 * When the pref for a bluetooth profile is clicked on, we want to toggle the enabled/disabled
 * state for that profile.
 */
@Override
public boolean onPreferenceClick(Preference preference) {
    LocalBluetoothProfile profile = mProfileManager.getProfileByName(preference.getKey());
    if (profile == null) {
        // It might be the PbapServerProfile, which is not stored by name.
        PbapServerProfile psp = mManager.getProfileManager().getPbapProfile();
        if (TextUtils.equals(preference.getKey(), psp.toString())) {
            profile = psp;
        } else {
            return false;
        }
    }
    SwitchPreference profilePref = (SwitchPreference) preference;
    if (profilePref.isChecked()) {
        enableProfile(profile);
    } else {
        disableProfile(profile);
    }
    refreshProfilePreference(profilePref, profile);
    return true;
}
Also used : LocalBluetoothProfile(com.android.settingslib.bluetooth.LocalBluetoothProfile) PbapServerProfile(com.android.settingslib.bluetooth.PbapServerProfile) SwitchPreference(androidx.preference.SwitchPreference)

Aggregations

SwitchPreference (androidx.preference.SwitchPreference)299 Test (org.junit.Test)125 Before (org.junit.Before)68 Intent (android.content.Intent)17 Preference (androidx.preference.Preference)17 ComponentName (android.content.ComponentName)10 A2dpProfile (com.android.settingslib.bluetooth.A2dpProfile)10 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)8 PbapServerProfile (com.android.settingslib.bluetooth.PbapServerProfile)8 ListPreference (androidx.preference.ListPreference)7 PreferenceScreen (androidx.preference.PreferenceScreen)7 RemoteException (android.os.RemoteException)6 PreferenceCategory (androidx.preference.PreferenceCategory)6 HashSet (java.util.HashSet)6 Context (android.content.Context)5 Parcel (android.os.Parcel)5 VisibleForTesting (androidx.annotation.VisibleForTesting)5 BluetoothDevice (android.bluetooth.BluetoothDevice)4 ChangeConfig (android.compat.Compatibility.ChangeConfig)4 ServiceInfo (android.content.pm.ServiceInfo)4