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;
}
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));
}
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
}
}
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);
}
}
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);
}
}
Aggregations