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 28 @VisibleForTesting 29 protected static final String ENABLED_SETTING = Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED; 30 @VisibleForTesting 31 protected static final String AVAILABLE_SETTING = 32 Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE; 33 34 @VisibleForTesting 35 protected static final String TOGGLE_KEY = "gesture_global_actions_panel_switch"; 36 GlobalActionsPanelPreferenceController(Context context, String key)37 public GlobalActionsPanelPreferenceController(Context context, String key) { 38 super(context, key); 39 } 40 41 @Override getAvailabilityStatus()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 setChecked(boolean isChecked)48 public boolean setChecked(boolean isChecked) { 49 return Settings.Secure.putInt(mContext.getContentResolver(), ENABLED_SETTING, 50 isChecked ? 1 : 0); 51 } 52 53 @Override getVideoPrefKey()54 protected String getVideoPrefKey() { 55 return PREF_KEY_VIDEO; 56 } 57 58 @Override isSliceable()59 public boolean isSliceable() { 60 return TextUtils.equals(getPreferenceKey(), TOGGLE_KEY); 61 } 62 63 @Override isChecked()64 public boolean isChecked() { 65 int enabled = Settings.Secure.getInt(mContext.getContentResolver(), ENABLED_SETTING, 0); 66 return enabled == 1; 67 } 68 } 69