Files
packages_apps_Settings/src/com/android/settings/display/EnableBlursPreferenceController.java
Jyotiraditya 76f9545826 Settings: Move blur toggle to Display options.
Change-Id: I64cadfd69c66a30ada9f5ba5509dd97a85124326
2025-12-10 00:41:27 +09:00

75 lines
2.5 KiB
Java

/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.display;
import static android.view.CrossWindowBlurListeners.CROSS_WINDOW_BLUR_SUPPORTED;
import android.content.Context;
import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.TwoStatePreference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
/**
* Controller that toggles window blurs on devices that support it.
*/
public final class EnableBlursPreferenceController extends AbstractPreferenceController
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
private static final String ENABLE_BLURS_ON_WINDOWS = "enable_blurs_on_windows";
private final boolean mBlurSupported;
public EnableBlursPreferenceController(Context context) {
this(context, CROSS_WINDOW_BLUR_SUPPORTED);
}
@VisibleForTesting
public EnableBlursPreferenceController(Context context, boolean blurSupported) {
super(context);
mBlurSupported = blurSupported;
}
@Override
public String getPreferenceKey() {
return ENABLE_BLURS_ON_WINDOWS;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enabled = (Boolean) newValue;
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DISABLE_WINDOW_BLURS, enabled ? 0 : 1);
return true;
}
@Override
public boolean isAvailable() {
return mBlurSupported;
}
@Override
public void updateState(Preference preference) {
boolean isEnabled = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.DISABLE_WINDOW_BLURS, 0) == 0;
((TwoStatePreference) preference).setChecked(isEnabled);
}
}