1 /* 2 * Copyright (C) 2021 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 android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVERLAY; 20 import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY; 21 22 import android.content.Context; 23 import android.provider.Settings; 24 25 import com.android.settings.R; 26 import com.android.settings.core.TogglePreferenceController; 27 28 /** 29 * Configures behaviour of long press home button to invoke assistant app gesture. 30 */ 31 public class ButtonNavigationSettingsAssistController extends TogglePreferenceController { 32 ButtonNavigationSettingsAssistController(Context context, String key)33 public ButtonNavigationSettingsAssistController(Context context, String key) { 34 super(context, key); 35 } 36 37 @Override isChecked()38 public boolean isChecked() { 39 boolean onByDefault = mContext.getResources().getBoolean( 40 com.android.internal.R.bool.config_assistLongPressHomeEnabledDefault); 41 return Settings.Secure.getInt(mContext.getContentResolver(), 42 Settings.Secure.ASSIST_LONG_PRESS_HOME_ENABLED, onByDefault ? 1 : 0) == 1; 43 } 44 45 @Override setChecked(boolean isChecked)46 public boolean setChecked(boolean isChecked) { 47 return Settings.Secure.putInt(mContext.getContentResolver(), 48 Settings.Secure.ASSIST_LONG_PRESS_HOME_ENABLED, isChecked ? 1 : 0); 49 } 50 51 @Override getAvailabilityStatus()52 public int getAvailabilityStatus() { 53 if (SystemNavigationPreferenceController.isOverlayPackageAvailable(mContext, 54 NAV_BAR_MODE_2BUTTON_OVERLAY) 55 || SystemNavigationPreferenceController.isOverlayPackageAvailable(mContext, 56 NAV_BAR_MODE_3BUTTON_OVERLAY)) { 57 return AVAILABLE; 58 } 59 60 return UNSUPPORTED_ON_DEVICE; 61 } 62 63 @Override getSliceHighlightMenuRes()64 public int getSliceHighlightMenuRes() { 65 return R.string.menu_key_system; 66 } 67 } 68