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 */
16package com.android.settings.display;
17
18import android.content.Context;
19import android.os.UserHandle;
20import android.support.v7.preference.Preference;
21
22import com.android.internal.hardware.AmbientDisplayConfiguration;
23import com.android.settings.R;
24import com.android.settings.core.PreferenceControllerMixin;
25import com.android.settingslib.core.AbstractPreferenceController;
26
27public 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
35    public AmbientDisplayPreferenceController(Context context, AmbientDisplayConfiguration config,
36            String key) {
37        super(context);
38        mConfig = config;
39        mKey = key;
40    }
41
42    @Override
43    public boolean isAvailable() {
44        return mConfig.available();
45    }
46
47    @Override
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
62    public String getPreferenceKey() {
63        return mKey;
64    }
65}
66