Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.accessibility; |
| 18 | |
| 19 | import com.android.server.wm.InputFilter; |
| 20 | |
| 21 | import android.content.Context; |
| 22 | import android.util.Slog; |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 23 | import android.view.InputDevice; |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 24 | import android.view.InputEvent; |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 25 | import android.view.MotionEvent; |
| 26 | import android.view.WindowManagerPolicy; |
| 27 | |
| 28 | /** |
| 29 | * Input filter for accessibility. |
| 30 | * |
| 31 | * Currently just a stub but will eventually implement touch exploration, etc. |
| 32 | */ |
| 33 | public class AccessibilityInputFilter extends InputFilter { |
| 34 | private static final String TAG = "AccessibilityInputFilter"; |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 35 | private static final boolean DEBUG = false; |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 36 | |
| 37 | private final Context mContext; |
| 38 | |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 39 | /** |
| 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 Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 64 | 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 Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 88 | Slog.d(TAG, "Received event: " + event + ", policyFlags=0x" |
| 89 | + Integer.toHexString(policyFlags)); |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 90 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 91 | 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 Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 100 | } |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 101 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 102 | 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 Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 109 | } |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 110 | } |
| 111 | } |