• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.provider.Settings.Secure.NOTIFICATION_BUBBLES;
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 public class BubbleGlobalPreferenceController extends DeveloperOptionsPreferenceController
32         implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
33 
34     @VisibleForTesting
35     static final int ON = 1;
36     @VisibleForTesting
37     static final int OFF = 0;
38 
BubbleGlobalPreferenceController(Context context)39     public BubbleGlobalPreferenceController(Context context) {
40         super(context);
41     }
42 
43     @Override
getPreferenceKey()44     public String getPreferenceKey() {
45         return NOTIFICATION_BUBBLES;
46     }
47 
48     @Override
onPreferenceChange(Preference preference, Object newValue)49     public boolean onPreferenceChange(Preference preference, Object newValue) {
50         writeSetting((boolean) newValue);
51         return true;
52     }
53 
54     @Override
updateState(Preference preference)55     public void updateState(Preference preference) {
56         ((SwitchPreference) mPreference).setChecked(isEnabled());
57     }
58 
59     @Override
onDeveloperOptionsSwitchDisabled()60     protected void onDeveloperOptionsSwitchDisabled() {
61         super.onDeveloperOptionsSwitchDisabled();
62         writeSetting(false /* isEnabled */);
63         updateState(mPreference);
64     }
65 
isEnabled()66     private boolean isEnabled() {
67         return Settings.Secure.getInt(mContext.getContentResolver(),
68                 NOTIFICATION_BUBBLES, OFF) == ON;
69     }
70 
writeSetting(boolean isEnabled)71     private void writeSetting(boolean isEnabled) {
72         Settings.Secure.putInt(mContext.getContentResolver(),
73                 NOTIFICATION_BUBBLES, isEnabled ? ON : OFF);
74     }
75 }
76