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.car.developeroptions.gestures; 18 19 import static android.provider.Settings.Secure.DOZE_TAP_SCREEN_GESTURE; 20 21 import android.annotation.UserIdInt; 22 import android.content.Context; 23 import android.hardware.display.AmbientDisplayConfiguration; 24 import android.os.UserHandle; 25 import android.provider.Settings; 26 import android.text.TextUtils; 27 28 public class TapScreenGesturePreferenceController extends GesturePreferenceController { 29 30 private static final String PREF_KEY_VIDEO = "gesture_tap_screen_video"; 31 32 private AmbientDisplayConfiguration mAmbientConfig; 33 @UserIdInt 34 private final int mUserId; 35 TapScreenGesturePreferenceController(Context context, String key)36 public TapScreenGesturePreferenceController(Context context, String key) { 37 super(context, key); 38 mUserId = UserHandle.myUserId(); 39 } 40 setConfig(AmbientDisplayConfiguration config)41 public TapScreenGesturePreferenceController setConfig(AmbientDisplayConfiguration config) { 42 mAmbientConfig = config; 43 return this; 44 } 45 46 @Override getAvailabilityStatus()47 public int getAvailabilityStatus() { 48 // No hardware support for this Gesture 49 if (!getAmbientConfig().tapSensorAvailable()) { 50 return UNSUPPORTED_ON_DEVICE; 51 } 52 53 return AVAILABLE; 54 } 55 56 @Override isSliceable()57 public boolean isSliceable() { 58 return true; 59 } 60 61 @Override getVideoPrefKey()62 protected String getVideoPrefKey() { 63 return PREF_KEY_VIDEO; 64 } 65 66 @Override getSummary()67 public CharSequence getSummary() { 68 return super.getSummary(); 69 } 70 71 @Override isChecked()72 public boolean isChecked() { 73 return getAmbientConfig().tapGestureEnabled(mUserId); 74 } 75 76 @Override setChecked(boolean isChecked)77 public boolean setChecked(boolean isChecked) { 78 return Settings.Secure.putInt(mContext.getContentResolver(), DOZE_TAP_SCREEN_GESTURE, 79 isChecked ? 1 : 0); 80 } 81 getAmbientConfig()82 private AmbientDisplayConfiguration getAmbientConfig() { 83 if (mAmbientConfig == null) { 84 mAmbientConfig = new AmbientDisplayConfiguration(mContext); 85 } 86 return mAmbientConfig; 87 } 88 }