Aaron Heuckroth | 2659c0f | 2019-05-02 11:04:42 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 android.content.Context; |
| 20 | import android.provider.Settings; |
| 21 | import android.text.TextUtils; |
| 22 | |
| 23 | import com.android.internal.annotations.VisibleForTesting; |
| 24 | |
| 25 | public class GlobalActionsPanelPreferenceController extends GesturePreferenceController { |
| 26 | private static final String PREF_KEY_VIDEO = "global_actions_panel_video"; |
| 27 | |
Aaron Heuckroth | 2659c0f | 2019-05-02 11:04:42 -0400 | [diff] [blame] | 28 | @VisibleForTesting |
Aran Ink | b8e8154 | 2019-05-07 16:36:56 -0400 | [diff] [blame] | 29 | protected static final String ENABLED_SETTING = Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED; |
Aaron Heuckroth | 2659c0f | 2019-05-02 11:04:42 -0400 | [diff] [blame] | 30 | @VisibleForTesting |
Aran Ink | b8e8154 | 2019-05-07 16:36:56 -0400 | [diff] [blame] | 31 | protected static final String AVAILABLE_SETTING = |
| 32 | Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE; |
Aaron Heuckroth | 2659c0f | 2019-05-02 11:04:42 -0400 | [diff] [blame] | 33 | |
| 34 | @VisibleForTesting |
| 35 | protected static final String TOGGLE_KEY = "gesture_global_actions_panel_switch"; |
| 36 | |
| 37 | public GlobalActionsPanelPreferenceController(Context context, String key) { |
| 38 | super(context, key); |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public int getAvailabilityStatus() { |
| 43 | int enabled = Settings.Secure.getInt(mContext.getContentResolver(), AVAILABLE_SETTING, 0); |
| 44 | return enabled == 1 ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public boolean setChecked(boolean isChecked) { |
| 49 | return Settings.Secure.putInt(mContext.getContentResolver(), ENABLED_SETTING, |
| 50 | isChecked ? 1 : 0); |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | protected String getVideoPrefKey() { |
| 55 | return PREF_KEY_VIDEO; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public boolean isSliceable() { |
| 60 | return TextUtils.equals(getPreferenceKey(), TOGGLE_KEY); |
| 61 | } |
| 62 | |
| 63 | @Override |
Yi-Ling Chuang | 1089f7c | 2019-11-27 17:14:17 +0800 | [diff] [blame] | 64 | public boolean isPublicSlice() { |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | @Override |
Aaron Heuckroth | 2659c0f | 2019-05-02 11:04:42 -0400 | [diff] [blame] | 69 | public boolean isChecked() { |
| 70 | int enabled = Settings.Secure.getInt(mContext.getContentResolver(), ENABLED_SETTING, 0); |
| 71 | return enabled == 1; |
| 72 | } |
| 73 | } |