1 /* 2 * Copyright (C) 2016 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_PICK_UP_GESTURE; 20 21 import android.annotation.UserIdInt; 22 import android.content.Context; 23 import android.content.SharedPreferences; 24 import android.hardware.display.AmbientDisplayConfiguration; 25 import android.os.UserHandle; 26 import android.provider.Settings; 27 import android.text.TextUtils; 28 29 public class PickupGesturePreferenceController extends GesturePreferenceController { 30 31 private static final int ON = 1; 32 private static final int OFF = 0; 33 34 private static final String PREF_KEY_VIDEO = "gesture_pick_up_video"; 35 private final String mPickUpPrefKey; 36 37 private final String SECURE_KEY = DOZE_PICK_UP_GESTURE; 38 39 private AmbientDisplayConfiguration mAmbientConfig; 40 @UserIdInt 41 private final int mUserId; 42 PickupGesturePreferenceController(Context context, String key)43 public PickupGesturePreferenceController(Context context, String key) { 44 super(context, key); 45 mUserId = UserHandle.myUserId(); 46 mPickUpPrefKey = key; 47 } 48 setConfig(AmbientDisplayConfiguration config)49 public PickupGesturePreferenceController setConfig(AmbientDisplayConfiguration config) { 50 mAmbientConfig = config; 51 return this; 52 } 53 isSuggestionComplete(Context context, SharedPreferences prefs)54 public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) { 55 AmbientDisplayConfiguration ambientConfig = new AmbientDisplayConfiguration(context); 56 return prefs.getBoolean(PickupGestureSettings.PREF_KEY_SUGGESTION_COMPLETE, false) 57 || !ambientConfig.dozePickupSensorAvailable(); 58 } 59 60 @Override getAvailabilityStatus()61 public int getAvailabilityStatus() { 62 // No hardware support for Pickup Gesture 63 if (!getAmbientConfig().dozePickupSensorAvailable()) { 64 return UNSUPPORTED_ON_DEVICE; 65 } 66 67 return AVAILABLE; 68 } 69 70 @Override isSliceable()71 public boolean isSliceable() { 72 return TextUtils.equals(getPreferenceKey(), "gesture_pick_up"); 73 } 74 75 @Override isPublicSlice()76 public boolean isPublicSlice() { 77 return true; 78 } 79 80 @Override getVideoPrefKey()81 protected String getVideoPrefKey() { 82 return PREF_KEY_VIDEO; 83 } 84 85 @Override isChecked()86 public boolean isChecked() { 87 return getAmbientConfig().pickupGestureEnabled(mUserId); 88 } 89 90 @Override getPreferenceKey()91 public String getPreferenceKey() { 92 return mPickUpPrefKey; 93 } 94 95 @Override setChecked(boolean isChecked)96 public boolean setChecked(boolean isChecked) { 97 return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY, 98 isChecked ? ON : OFF); 99 } 100 getAmbientConfig()101 private AmbientDisplayConfiguration getAmbientConfig() { 102 if (mAmbientConfig == null) { 103 mAmbientConfig = new AmbientDisplayConfiguration(mContext); 104 } 105 106 return mAmbientConfig; 107 } 108 } 109