1/*
2 * Copyright (C) 2013 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
17package com.android.inputmethod.keyboard.internal;
18
19import com.android.inputmethod.accessibility.AccessibilityUtils;
20
21public final class GestureEnabler {
22    /** True if we should handle gesture events. */
23    private boolean mShouldHandleGesture;
24    private boolean mMainDictionaryAvailable;
25    private boolean mGestureHandlingEnabledByInputField;
26    private boolean mGestureHandlingEnabledByUser;
27
28    private void updateGestureHandlingMode() {
29        mShouldHandleGesture = mMainDictionaryAvailable
30                && mGestureHandlingEnabledByInputField
31                && mGestureHandlingEnabledByUser
32                && !AccessibilityUtils.getInstance().isTouchExplorationEnabled();
33    }
34
35    // Note that this method is called from a non-UI thread.
36    public void setMainDictionaryAvailability(final boolean mainDictionaryAvailable) {
37        mMainDictionaryAvailable = mainDictionaryAvailable;
38        updateGestureHandlingMode();
39    }
40
41    public void setGestureHandlingEnabledByUser(final boolean gestureHandlingEnabledByUser) {
42        mGestureHandlingEnabledByUser = gestureHandlingEnabledByUser;
43        updateGestureHandlingMode();
44    }
45
46    public void setPasswordMode(final boolean passwordMode) {
47        mGestureHandlingEnabledByInputField = !passwordMode;
48        updateGestureHandlingMode();
49    }
50
51    public boolean shouldHandleGesture() {
52        return mShouldHandleGesture;
53    }
54}
55