2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.gestures;
19 import android.content.Context;
20 import android.support.v7.preference.Preference;
21 import android.support.v7.preference.PreferenceScreen;
22 import android.support.v7.preference.TwoStatePreference;
24 import com.android.settings.R;
25 import com.android.settings.core.PreferenceController;
26 import com.android.settings.widget.VideoPreference;
27 import com.android.settingslib.core.lifecycle.Lifecycle;
28 import com.android.settingslib.core.lifecycle.LifecycleObserver;
29 import com.android.settingslib.core.lifecycle.events.OnStart;
30 import com.android.settingslib.core.lifecycle.events.OnStop;
32 public abstract class GesturePreferenceController extends PreferenceController
33 implements Preference.OnPreferenceChangeListener, LifecycleObserver, OnStart, OnStop {
35 private VideoPreference mVideoPreference;
37 public GesturePreferenceController(Context context, Lifecycle lifecycle) {
39 if (lifecycle != null) {
40 lifecycle.addObserver(this);
45 public void displayPreference(PreferenceScreen screen) {
46 super.displayPreference(screen);
48 mVideoPreference = (VideoPreference) screen.findPreference(getVideoPrefKey());
53 public void updateState(Preference preference) {
54 super.updateState(preference);
55 final boolean isEnabled = isSwitchPrefEnabled();
56 if (preference != null) {
57 if (preference instanceof TwoStatePreference) {
58 ((TwoStatePreference) preference).setChecked(isEnabled);
60 preference.setSummary(isEnabled
61 ? R.string.gesture_setting_on
62 : R.string.gesture_setting_off);
64 // Different meanings of "Enabled" for the Preference and Controller.
65 preference.setEnabled(canHandleClicks());
70 public void onStop() {
71 if (mVideoPreference != null) {
72 mVideoPreference.onViewInvisible();
77 public void onStart() {
78 if (mVideoPreference != null) {
79 mVideoPreference.onViewVisible();
83 protected abstract String getVideoPrefKey();
85 protected abstract boolean isSwitchPrefEnabled();
87 protected boolean canHandleClicks() {