1341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette/*
2341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * Copyright (C) 2013 The Android Open Source Project
3341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette *
4341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * Licensed under the Apache License, Version 2.0 (the "License");
5341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * you may not use this file except in compliance with the License.
6341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * You may obtain a copy of the License at
7341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette *
8341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette *      http://www.apache.org/licenses/LICENSE-2.0
9341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette *
10341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * Unless required by applicable law or agreed to in writing, software
11341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * distributed under the License is distributed on an "AS IS" BASIS,
12341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * See the License for the specific language governing permissions and
14341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette * limitations under the License.
15341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette */
16341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette
17341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverettepackage com.android.settings.accessibility;
18341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette
19341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viveretteimport android.provider.Settings;
20341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette
219d1bfd1e8de6e46137a9571507c03526880d6a46Chris Wrenimport com.android.internal.logging.MetricsProto.MetricsEvent;
225160536df91bb9daa6cac9a878ce406deda791c6Fabrice Di Meglioimport com.android.settings.widget.ToggleSwitch;
235160536df91bb9daa6cac9a878ce406deda791c6Fabrice Di Meglioimport com.android.settings.widget.ToggleSwitch.OnBeforeCheckedChangeListener;
24341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette
25341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverettepublic class ToggleGlobalGesturePreferenceFragment
26341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette        extends ToggleFeaturePreferenceFragment {
27341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette    @Override
28341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette    protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
29341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette        Settings.Global.putInt(getContentResolver(),
30341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette                Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, enabled ? 1 : 0);
31341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette    }
32341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette
33341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette    @Override
346220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio    protected void onInstallSwitchBarToggleSwitch() {
356220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio        super.onInstallSwitchBarToggleSwitch();
3600b5e6b24741257352da975966ebe6c143b2eff5Fabrice Di Meglio        mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() {
37341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette                @Override
38341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette            public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
39006b2cca1311e61472a8b66fb0c50854fc36d2e7Fabrice Di Meglio                mSwitchBar.setCheckedInternal(checked);
40341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette                getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, checked);
41341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette                onPreferenceToggled(mPreferenceKey, checked);
42341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette                return false;
43341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette            }
44341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette        });
45341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette    }
468a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren
478a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren    @Override
488a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren    protected int getMetricsCategory() {
499d1bfd1e8de6e46137a9571507c03526880d6a46Chris Wren        return MetricsEvent.ACCESSIBILITY_TOGGLE_GLOBAL_GESTURE;
508a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren    }
51341ff66e0374a46f89c51bca2ef55da368b7e40fAlan Viverette}
52