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.content.Intent; 22 import android.content.SharedPreferences; 23 import android.provider.Settings; 24 import android.support.v7.preference.Preference; 25 26 import com.android.internal.hardware.AmbientDisplayConfiguration; 27 import com.android.settings.R; 28 import com.android.settings.search.DatabaseIndexingUtils; 29 import com.android.settings.search.InlineSwitchPayload; 30 import com.android.settings.search.ResultPayload; 31 import com.android.settingslib.core.lifecycle.Lifecycle; 32 33 import static android.provider.Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP; 34 35 public class DoubleTapScreenPreferenceController extends GesturePreferenceController { 36 37 private final int ON = 1; 38 private final int OFF = 0; 39 40 private static final String PREF_KEY_VIDEO = "gesture_double_tap_screen_video"; 41 private final String mDoubleTapScreenPrefKey; 42 43 private final String SECURE_KEY = DOZE_PULSE_ON_DOUBLE_TAP; 44 45 private final AmbientDisplayConfiguration mAmbientConfig; 46 @UserIdInt 47 private final int mUserId; 48 49 public DoubleTapScreenPreferenceController(Context context, Lifecycle lifecycle, 50 AmbientDisplayConfiguration config, @UserIdInt int userId, String key) { 51 super(context, lifecycle); 52 mAmbientConfig = config; 53 mUserId = userId; 54 mDoubleTapScreenPrefKey = key; 55 } 56 57 public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) { 58 AmbientDisplayConfiguration ambientConfig = new AmbientDisplayConfiguration(context); 59 return !ambientConfig.pulseOnDoubleTapAvailable() 60 || prefs.getBoolean(DoubleTapScreenSettings.PREF_KEY_SUGGESTION_COMPLETE, false); 61 } 62 63 @Override 64 public boolean isAvailable() { 65 return mAmbientConfig.pulseOnDoubleTapAvailable(); 66 } 67 68 @Override 69 public String getPreferenceKey() { 70 return mDoubleTapScreenPrefKey; 71 } 72 73 @Override 74 public boolean onPreferenceChange(Preference preference, Object newValue) { 75 final boolean enabled = (boolean) newValue; 76 Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY, enabled ? ON : OFF); 77 return true; 78 } 79 80 @Override 81 protected String getVideoPrefKey() { 82 return PREF_KEY_VIDEO; 83 } 84 85 @Override 86 protected boolean isSwitchPrefEnabled() { 87 return mAmbientConfig.pulseOnDoubleTapEnabled(mUserId); 88 } 89 90 @Override 91 public ResultPayload getResultPayload() { 92 final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext, 93 DoubleTapScreenSettings.class.getName(), mDoubleTapScreenPrefKey, 94 mContext.getString(R.string.display_settings)); 95 96 return new InlineSwitchPayload(SECURE_KEY, ResultPayload.SettingsSource.SECURE, 97 ON /* onValue */, intent, isAvailable(), ON /* defaultValue */); 98 } 99 }