AutoclickController.java revision 976724e81bca33dc48347f88633a37a195b9e4ea
1/*
2 * Copyright (C) 2015 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.server.accessibility;
18
19import android.content.Context;
20import android.view.KeyEvent;
21import android.view.MotionEvent;
22import android.view.accessibility.AccessibilityEvent;
23
24/**
25 * Implements "Automatically click on mouse stop" feature.
26 *
27 * If enabled, it will observe motion events from mouse source, and send click event sequence short
28 * while after mouse stops moving. The click will only be performed if mouse movement had been
29 * actually detected.
30 *
31 * Movement detection has tolerance to jitter that may be caused by poor motor control to prevent:
32 * <ul>
33 *   <li>Initiating unwanted clicks with no mouse movement.</li>
34 *   <li>Autoclick never occurring after mouse arriving at target.</li>
35 * </ul>
36 *
37 * Non-mouse motion events, key events (excluding modifiers) and non-movement mouse events cancel
38 * the automatic click.
39 */
40public class AutoclickController implements EventStreamTransformation {
41    private EventStreamTransformation mNext;
42
43    public AutoclickController(Context context) {}
44
45    @Override
46    public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags) {
47        // TODO: Implement this.
48        if (mNext != null) {
49            mNext.onMotionEvent(event, rawEvent, policyFlags);
50        }
51    }
52
53    @Override
54    public void onKeyEvent(KeyEvent event, int policyFlags) {
55        // TODO: Implement this.
56        if (mNext != null) {
57          mNext.onKeyEvent(event, policyFlags);
58        }
59    }
60
61    @Override
62    public void onAccessibilityEvent(AccessibilityEvent event) {
63        if (mNext != null) {
64            mNext.onAccessibilityEvent(event);
65        }
66    }
67
68    @Override
69    public void setNext(EventStreamTransformation next) {
70        mNext = next;
71    }
72
73    @Override
74    public void clearEvents(int inputSource) {
75        if (mNext != null) {
76            mNext.clearEvents(inputSource);
77        }
78    }
79
80    @Override
81    public void onDestroy() {
82    }
83}
84