• 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 DoubleTapScreenPreferenceController extends GesturePreferenceController {
28 
29     private static final String PREF_KEY_VIDEO = "gesture_double_tap_screen_video";
30     private final String mDoubleTapScreenPrefKey;
31 
32     private final AmbientDisplayConfiguration mAmbientConfig;
33     @UserIdInt
34     private final int mUserId;
35 
DoubleTapScreenPreferenceController(Context context, Lifecycle lifecycle, AmbientDisplayConfiguration config, @UserIdInt int userId, String key)36     public DoubleTapScreenPreferenceController(Context context, Lifecycle lifecycle,
37             AmbientDisplayConfiguration config, @UserIdInt int userId, String key) {
38         super(context, lifecycle);
39         mAmbientConfig = config;
40         mUserId = userId;
41         mDoubleTapScreenPrefKey = key;
42     }
43 
44     @Override
isAvailable()45     public boolean isAvailable() {
46         return mAmbientConfig.pulseOnDoubleTapAvailable();
47     }
48 
49     @Override
getPreferenceKey()50     public String getPreferenceKey() {
51         return mDoubleTapScreenPrefKey;
52     }
53 
54     @Override
onPreferenceChange(Preference preference, Object newValue)55     public boolean onPreferenceChange(Preference preference, Object newValue) {
56         final boolean enabled = (boolean) newValue;
57         Settings.Secure.putInt(mContext.getContentResolver(),
58                 Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, enabled ? 1 : 0);
59         return true;
60     }
61 
62     @Override
getVideoPrefKey()63     protected String getVideoPrefKey() {
64         return PREF_KEY_VIDEO;
65     }
66 
67     @Override
isSwitchPrefEnabled()68     protected boolean isSwitchPrefEnabled() {
69         return mAmbientConfig.pulseOnDoubleTapEnabled(mUserId);
70     }
71 }
72