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