• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.development;
18 
19 import static android.view.CrossWindowBlurListeners.CROSS_WINDOW_BLUR_SUPPORTED;
20 
21 import android.content.Context;
22 import android.provider.Settings;
23 
24 import androidx.annotation.VisibleForTesting;
25 import androidx.preference.Preference;
26 import androidx.preference.SwitchPreference;
27 
28 import com.android.settings.core.PreferenceControllerMixin;
29 import com.android.settingslib.development.DeveloperOptionsPreferenceController;
30 
31 /**
32  * Controller that toggles window blurs on devices that support it.
33  */
34 public final class EnableBlursPreferenceController extends DeveloperOptionsPreferenceController
35         implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
36 
37     private static final String ENABLE_BLURS_ON_WINDOWS = "enable_blurs_on_windows";
38     private final boolean mBlurSupported;
39 
EnableBlursPreferenceController(Context context)40     public EnableBlursPreferenceController(Context context) {
41         this(context, CROSS_WINDOW_BLUR_SUPPORTED);
42     }
43 
44     @VisibleForTesting
EnableBlursPreferenceController(Context context, boolean blurSupported)45     public EnableBlursPreferenceController(Context context, boolean blurSupported) {
46         super(context);
47         mBlurSupported = blurSupported;
48     }
49 
50     @Override
getPreferenceKey()51     public String getPreferenceKey() {
52         return ENABLE_BLURS_ON_WINDOWS;
53     }
54 
55     @Override
onPreferenceChange(Preference preference, Object newValue)56     public boolean onPreferenceChange(Preference preference, Object newValue) {
57         boolean enabled = (Boolean) newValue;
58         Settings.Global.putInt(mContext.getContentResolver(),
59                 Settings.Global.DISABLE_WINDOW_BLURS, enabled ? 0 : 1);
60         return true;
61     }
62 
63     @Override
isAvailable()64     public boolean isAvailable() {
65         return mBlurSupported;
66     }
67 
68     @Override
updateState(Preference preference)69     public void updateState(Preference preference) {
70         boolean isEnabled = Settings.Global.getInt(mContext.getContentResolver(),
71                     Settings.Global.DISABLE_WINDOW_BLURS, 0) == 0;
72         ((SwitchPreference) mPreference).setChecked(isEnabled);
73     }
74 
75     @Override
onDeveloperOptionsSwitchDisabled()76     protected void onDeveloperOptionsSwitchDisabled() {
77         super.onDeveloperOptionsSwitchDisabled();
78         Settings.Global.putInt(mContext.getContentResolver(),
79                 Settings.Global.DISABLE_WINDOW_BLURS, 0);
80         updateState(null);
81     }
82 }
83