blob: 8ba0a0b67ef4c1cb6207d621f2b077c496b72cb8 [file] [log] [blame]
Jeff Brown0029c662011-03-30 02:25:18 -07001/*
2 * Copyright (C) 2011 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 com.android.server.wm.InputFilter;
20
21import android.content.Context;
22import android.util.Slog;
Svetoslav Ganov736c2752011-04-22 18:30:36 -070023import android.view.InputDevice;
Jeff Brown0029c662011-03-30 02:25:18 -070024import android.view.InputEvent;
Jeff Brown0029c662011-03-30 02:25:18 -070025import android.view.MotionEvent;
26import android.view.WindowManagerPolicy;
27
28/**
29 * Input filter for accessibility.
30 *
31 * Currently just a stub but will eventually implement touch exploration, etc.
32 */
33public class AccessibilityInputFilter extends InputFilter {
34 private static final String TAG = "AccessibilityInputFilter";
Svetoslav Ganov736c2752011-04-22 18:30:36 -070035 private static final boolean DEBUG = false;
Jeff Brown0029c662011-03-30 02:25:18 -070036
37 private final Context mContext;
38
Svetoslav Ganov736c2752011-04-22 18:30:36 -070039 /**
40 * This is an interface for explorers that take a {@link MotionEvent}
41 * stream and perform touch exploration of the screen content.
42 */
43 public interface Explorer {
44 /**
45 * Handles a {@link MotionEvent}.
46 *
47 * @param event The event to handle.
48 * @param policyFlags The policy flags associated with the event.
49 */
50 public void onMotionEvent(MotionEvent event, int policyFlags);
51
52 /**
53 * Requests that the explorer clears its internal state.
54 *
55 * @param event The last received event.
56 * @param policyFlags The policy flags associated with the event.
57 */
58 public void clear(MotionEvent event, int policyFlags);
59 }
60
61 private TouchExplorer mTouchExplorer;
62 private int mTouchscreenSourceDeviceId;
63
Jeff Brown0029c662011-03-30 02:25:18 -070064 public AccessibilityInputFilter(Context context) {
65 super(context.getMainLooper());
66 mContext = context;
67 }
68
69 @Override
70 public void onInstalled() {
71 if (DEBUG) {
72 Slog.d(TAG, "Accessibility input filter installed.");
73 }
74 super.onInstalled();
75 }
76
77 @Override
78 public void onUninstalled() {
79 if (DEBUG) {
80 Slog.d(TAG, "Accessibility input filter uninstalled.");
81 }
82 super.onUninstalled();
83 }
84
85 @Override
86 public void onInputEvent(InputEvent event, int policyFlags) {
87 if (DEBUG) {
Svetoslav Ganov736c2752011-04-22 18:30:36 -070088 Slog.d(TAG, "Received event: " + event + ", policyFlags=0x"
89 + Integer.toHexString(policyFlags));
Jeff Brown0029c662011-03-30 02:25:18 -070090 }
Svetoslav Ganov736c2752011-04-22 18:30:36 -070091 if (event.getSource() == InputDevice.SOURCE_TOUCHSCREEN) {
92 MotionEvent motionEvent = (MotionEvent) event;
93 int deviceId = event.getDeviceId();
94 if (mTouchscreenSourceDeviceId != deviceId) {
95 mTouchscreenSourceDeviceId = deviceId;
96 if (mTouchExplorer != null) {
97 mTouchExplorer.clear(motionEvent, policyFlags);
98 } else {
99 mTouchExplorer = new TouchExplorer(this, mContext);
Jeff Brown0029c662011-03-30 02:25:18 -0700100 }
Jeff Brown0029c662011-03-30 02:25:18 -0700101 }
Svetoslav Ganov736c2752011-04-22 18:30:36 -0700102 if ((policyFlags & WindowManagerPolicy.FLAG_PASS_TO_USER) != 0) {
103 mTouchExplorer.onMotionEvent(motionEvent, policyFlags);
104 } else {
105 mTouchExplorer.clear(motionEvent, policyFlags);
106 }
107 } else {
108 super.onInputEvent(event, policyFlags);
Jeff Brown0029c662011-03-30 02:25:18 -0700109 }
Jeff Brown0029c662011-03-30 02:25:18 -0700110 }
111}