• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.annotation.UserIdInt;
20 import android.content.Context;
21 import android.provider.Settings;
22 import android.support.v7.preference.Preference;
23 
24 import com.android.internal.hardware.AmbientDisplayConfiguration;
25 import com.android.settings.core.lifecycle.Lifecycle;
26 
27 public class PickupGesturePreferenceController extends GesturePreferenceController {
28 
29     private static final String PREF_VIDEO_KEY = "gesture_pick_up_video";
30     private final String mPickUpPrefKey;
31 
32     private final AmbientDisplayConfiguration mAmbientConfig;
33     @UserIdInt
34     private final int mUserId;
35 
PickupGesturePreferenceController(Context context, Lifecycle lifecycle, AmbientDisplayConfiguration config, @UserIdInt int userId, String key)36     public PickupGesturePreferenceController(Context context, Lifecycle lifecycle,
37             AmbientDisplayConfiguration config, @UserIdInt int userId, String key) {
38         super(context, lifecycle);
39         mAmbientConfig = config;
40         mUserId = userId;
41         mPickUpPrefKey = key;
42     }
43 
44     @Override
isAvailable()45     public boolean isAvailable() {
46         return mAmbientConfig.pulseOnPickupAvailable();
47     }
48 
49     @Override
getVideoPrefKey()50     protected String getVideoPrefKey() {
51         return PREF_VIDEO_KEY;
52     }
53 
54     @Override
isSwitchPrefEnabled()55     protected boolean isSwitchPrefEnabled() {
56         return mAmbientConfig.pulseOnPickupEnabled(mUserId);
57     }
58 
59     @Override
getPreferenceKey()60     public String getPreferenceKey() {
61         return mPickUpPrefKey;
62     }
63 
64     @Override
onPreferenceChange(Preference preference, Object newValue)65     public boolean onPreferenceChange(Preference preference, Object newValue) {
66         final boolean enabled = (boolean) newValue;
67         Settings.Secure.putInt(mContext.getContentResolver(),
68                 Settings.Secure.DOZE_PULSE_ON_PICK_UP, enabled ? 1 : 0);
69         return true;
70     }
71 }
72