blob: 6ef583b70378490dcd24cde402086ee82cf4cb6b [file] [log] [blame]
Fabian Kozynski83df54b2020-03-24 16:37:57 -04001/*
2 * Copyright (C) 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
17package com.android.settings.gestures;
18
19import android.content.Context;
Fabian Kozynskid0d07dd2020-05-28 13:49:40 -040020import android.content.pm.PackageManager;
Fabian Kozynski83df54b2020-03-24 16:37:57 -040021import android.provider.Settings;
22
23import com.android.settings.R;
24import com.android.settings.core.BasePreferenceController;
25
26public class PowerMenuPreferenceController extends BasePreferenceController {
27
28 private static final String KEY = "gesture_power_menu_summary";
29 private static final String CONTROLS_ENABLED_SETTING = Settings.Secure.CONTROLS_ENABLED;
30 private static final String CARDS_ENABLED_SETTING =
31 Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED;
32 private static final String CARDS_AVAILABLE_SETTING =
33 Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE;
34
35 public PowerMenuPreferenceController(Context context, String key) {
36 super(context, key);
37 }
38
39 @Override
40 public CharSequence getSummary() {
Fabian Kozynskid0d07dd2020-05-28 13:49:40 -040041 boolean controlsVisible = isControlsAvailable()
42 && Settings.Secure.getInt(mContext.getContentResolver(),
43 CONTROLS_ENABLED_SETTING, 1) == 1;
44 boolean cardsVisible = isCardsAvailable()
45 && Settings.Secure.getInt(mContext.getContentResolver(),
46 CARDS_ENABLED_SETTING, 0) == 1;
47 if (controlsVisible && cardsVisible) {
Fabian Kozynski83df54b2020-03-24 16:37:57 -040048 return mContext.getText(R.string.power_menu_cards_passes_device_controls);
Fabian Kozynskid0d07dd2020-05-28 13:49:40 -040049 } else if (controlsVisible) {
Fabian Kozynski83df54b2020-03-24 16:37:57 -040050 return mContext.getText(R.string.power_menu_device_controls);
51 } else if (cardsVisible) {
52 return mContext.getText(R.string.power_menu_cards_passes);
53 } else {
54 return mContext.getText(R.string.power_menu_none);
55 }
56 }
57
58 @Override
59 public int getAvailabilityStatus() {
Fabian Kozynskid0d07dd2020-05-28 13:49:40 -040060 return isCardsAvailable() || isControlsAvailable() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
61 }
62
63 private boolean isControlsAvailable() {
64 return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CONTROLS);
65 }
66
67 private boolean isCardsAvailable() {
68 return Settings.Secure.getInt(mContext.getContentResolver(),
69 CARDS_AVAILABLE_SETTING, 0) == 1;
Fabian Kozynski83df54b2020-03-24 16:37:57 -040070 }
71}