• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 package com.android.settings.display;
17 
18 import android.content.Context;
19 import android.os.UserHandle;
20 import android.support.v7.preference.Preference;
21 
22 import com.android.internal.hardware.AmbientDisplayConfiguration;
23 import com.android.settings.R;
24 import com.android.settings.core.PreferenceControllerMixin;
25 import com.android.settingslib.core.AbstractPreferenceController;
26 
27 public class AmbientDisplayPreferenceController extends AbstractPreferenceController implements
28         PreferenceControllerMixin {
29 
30     private static final int MY_USER_ID = UserHandle.myUserId();
31 
32     private final AmbientDisplayConfiguration mConfig;
33     private final String mKey;
34 
AmbientDisplayPreferenceController(Context context, AmbientDisplayConfiguration config, String key)35     public AmbientDisplayPreferenceController(Context context, AmbientDisplayConfiguration config,
36             String key) {
37         super(context);
38         mConfig = config;
39         mKey = key;
40     }
41 
42     @Override
isAvailable()43     public boolean isAvailable() {
44         return mConfig.available();
45     }
46 
47     @Override
updateState(Preference preference)48     public void updateState(Preference preference) {
49         super.updateState(preference);
50         if (mConfig.alwaysOnEnabled(MY_USER_ID)) {
51             preference.setSummary(R.string.ambient_display_screen_summary_always_on);
52         } else if (mConfig.pulseOnNotificationEnabled(MY_USER_ID)) {
53             preference.setSummary(R.string.ambient_display_screen_summary_notifications);
54         } else if (mConfig.enabled(MY_USER_ID)) {
55             preference.setSummary(R.string.switch_on_text);
56         } else {
57             preference.setSummary(R.string.switch_off_text);
58         }
59     }
60 
61     @Override
getPreferenceKey()62     public String getPreferenceKey() {
63         return mKey;
64     }
65 }
66