• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.dream;
18 
19 import android.content.Context;
20 
21 import com.android.internal.annotations.VisibleForTesting;
22 import com.android.settings.R;
23 import com.android.settings.core.TogglePreferenceController;
24 import com.android.settingslib.dream.DreamBackend;
25 
26 /**
27  * Controller for the {@link androidx.preference.SwitchPreference} which controls if dream
28  * overlays should be enabled.
29  */
30 public class DreamHomeControlsPreferenceController extends TogglePreferenceController {
31     private final DreamBackend mBackend;
32 
DreamHomeControlsPreferenceController(Context context, String key)33     public DreamHomeControlsPreferenceController(Context context, String key) {
34         this(context, key, DreamBackend.getInstance(context));
35     }
36 
37     @VisibleForTesting
DreamHomeControlsPreferenceController(Context context, String key, DreamBackend dreamBackend)38     public DreamHomeControlsPreferenceController(Context context, String key,
39             DreamBackend dreamBackend) {
40         super(context, key);
41         mBackend = dreamBackend;
42     }
43 
44     @Override
getAvailabilityStatus()45     public int getAvailabilityStatus() {
46         final boolean supported =
47                 mBackend.getSupportedComplications()
48                         .contains(DreamBackend.COMPLICATION_TYPE_HOME_CONTROLS);
49         return supported ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
50     }
51 
52     @Override
isChecked()53     public boolean isChecked() {
54         return mBackend.getEnabledComplications().contains(
55                 DreamBackend.COMPLICATION_TYPE_HOME_CONTROLS);
56     }
57 
58     @Override
setChecked(boolean isChecked)59     public boolean setChecked(boolean isChecked) {
60         mBackend.setHomeControlsEnabled(isChecked);
61         return true;
62     }
63 
64     @Override
getSliceHighlightMenuRes()65     public int getSliceHighlightMenuRes() {
66         return R.string.menu_key_display;
67     }
68 }
69