2 * Copyright (C) 2016 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
14 package com.android.settings.display;
16 import android.content.Context;
17 import android.hardware.Sensor;
18 import android.hardware.SensorManager;
19 import android.provider.Settings;
20 import android.support.v14.preference.SwitchPreference;
21 import android.support.v7.preference.Preference;
23 import com.android.settings.core.PreferenceController;
25 import static android.provider.Settings.Secure.WAKE_GESTURE_ENABLED;
27 public class LiftToWakePreferenceController extends PreferenceController implements
28 Preference.OnPreferenceChangeListener {
30 private static final String KEY_LIFT_TO_WAKE = "lift_to_wake";
32 public LiftToWakePreferenceController(Context context) {
37 public boolean isAvailable() {
38 SensorManager sensors = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
39 return sensors != null && sensors.getDefaultSensor(Sensor.TYPE_WAKE_GESTURE) != null;
43 public String getPreferenceKey() {
44 return KEY_LIFT_TO_WAKE;
48 public boolean onPreferenceChange(Preference preference, Object newValue) {
49 boolean value = (Boolean) newValue;
50 Settings.Secure.putInt(mContext.getContentResolver(), WAKE_GESTURE_ENABLED, value ? 1 : 0);
55 public void updateState(Preference preference) {
56 int value = Settings.Secure.getInt(mContext.getContentResolver(), WAKE_GESTURE_ENABLED, 0);
57 ((SwitchPreference) preference).setChecked(value != 0);