Search in sources :

Example 91 with SwitchPreference

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

the class PlatformCompatDashboard method createPreferenceForChange.

/**
 * Create a {@link Preference} for a changeId.
 *
 * <p>The {@link Preference} is a toggle switch that can enable or disable the given change for
 * the currently selected app.</p>
 */
Preference createPreferenceForChange(Context context, CompatibilityChangeInfo change, CompatibilityChangeConfig configMappings) {
    final boolean currentValue = configMappings.isChangeEnabled(change.getId());
    final SwitchPreference item = new SwitchPreference(context);
    final String changeName = change.getName() != null ? change.getName() : "Change_" + change.getId();
    item.setSummary(changeName);
    item.setKey(changeName);
    boolean shouldEnable = true;
    try {
        shouldEnable = getPlatformCompat().getOverrideValidator().getOverrideAllowedState(change.getId(), mSelectedApp).state == ALLOWED;
    } catch (RemoteException e) {
        throw new RuntimeException("Could not check if change can be overridden for app.", e);
    }
    item.setEnabled(shouldEnable);
    item.setChecked(currentValue);
    item.setOnPreferenceChangeListener(new CompatChangePreferenceChangeListener(change.getId()));
    return item;
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) RemoteException(android.os.RemoteException)

Example 92 with SwitchPreference

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

the class WaitForDebuggerPreferenceController method updateState.

private void updateState(Preference preference, String debugApp) {
    final SwitchPreference switchPreference = (SwitchPreference) preference;
    final boolean debuggerEnabled = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.WAIT_FOR_DEBUGGER, SETTING_VALUE_OFF) != SETTING_VALUE_OFF;
    writeDebuggerAppOptions(debugApp, debuggerEnabled, true);
    switchPreference.setChecked(debuggerEnabled);
    switchPreference.setEnabled(!TextUtils.isEmpty(debugApp));
}
Also used : SwitchPreference(androidx.preference.SwitchPreference)

Example 93 with SwitchPreference

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

the class ShowRefreshRatePreferenceController method updateShowRefreshRateSetting.

@VisibleForTesting
void updateShowRefreshRateSetting() {
    // magic communication with surface flinger.
    try {
        if (mSurfaceFlinger != null) {
            final Parcel data = Parcel.obtain();
            final Parcel reply = Parcel.obtain();
            data.writeInterfaceToken(SURFACE_COMPOSER_INTERFACE_KEY);
            data.writeInt(SETTING_VALUE_QUERY);
            mSurfaceFlinger.transact(SURFACE_FLINGER_CODE, data, reply, 0);
            final boolean enabled = reply.readBoolean();
            ((SwitchPreference) mPreference).setChecked(enabled);
            reply.recycle();
            data.recycle();
        }
    } catch (RemoteException ex) {
    // intentional no-op
    }
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) Parcel(android.os.Parcel) RemoteException(android.os.RemoteException) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 94 with SwitchPreference

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

the class ShowRefreshRatePreferenceController method onDeveloperOptionsSwitchDisabled.

@Override
protected void onDeveloperOptionsSwitchDisabled() {
    super.onDeveloperOptionsSwitchDisabled();
    final SwitchPreference preference = (SwitchPreference) mPreference;
    if (preference.isChecked()) {
        // Writing false to the preference when the setting is already off will have a
        // side effect of turning on the preference that we wish to avoid
        writeShowRefreshRateSetting(false);
        preference.setChecked(false);
    }
}
Also used : SwitchPreference(androidx.preference.SwitchPreference)

Example 95 with SwitchPreference

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

the class ShowSurfaceUpdatesPreferenceController method onDeveloperOptionsSwitchDisabled.

@Override
protected void onDeveloperOptionsSwitchDisabled() {
    super.onDeveloperOptionsSwitchDisabled();
    final SwitchPreference preference = (SwitchPreference) mPreference;
    if (preference.isChecked()) {
        // Writing false to the preference when the setting is already off will have a
        // side effect of turning on the preference that we wish to avoid
        writeShowUpdatesSetting(false);
        preference.setChecked(false);
    }
}
Also used : 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