1 /*
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 
17 package com.android.settings.gestures;
18 
19 import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE;
20 import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS;
21 
22 import android.content.Context;
23 
24 import com.android.settings.R;
25 import com.android.settings.core.BasePreferenceController;
26 
27 public class PowerMenuPreferenceController extends BasePreferenceController {
28 
PowerMenuPreferenceController(Context context, String key)29     public PowerMenuPreferenceController(Context context, String key) {
30         super(context, key);
31     }
32 
33     @Override
getSummary()34     public CharSequence getSummary() {
35         final int powerButtonValue = PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext);
36         if (powerButtonValue == LONG_PRESS_POWER_ASSISTANT_VALUE) {
37             return mContext.getText(R.string.power_menu_summary_long_press_for_assist_enabled);
38         } else if (powerButtonValue == LONG_PRESS_POWER_GLOBAL_ACTIONS) {
39             return mContext.getText(
40                     R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu);
41         } else {
42             return mContext.getText(
43                     R.string.power_menu_summary_long_press_for_assist_disabled_no_action);
44         }
45     }
46 
47     @Override
getAvailabilityStatus()48     public int getAvailabilityStatus() {
49         return isAssistInvocationAvailable() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
50     }
51 
isAssistInvocationAvailable()52     private boolean isAssistInvocationAvailable() {
53         return mContext.getResources().getBoolean(
54                 com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable);
55     }
56 }
57