AccessibilityEventCompat.java revision b047962755c59a9855328ed273bae33a0663e21a
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 17package android.support.v4.view.accessibility; 18 19import android.os.Build; 20import android.view.accessibility.AccessibilityEvent; 21 22/** 23 * Helper for accessing features in {@link AccessibilityEvent} 24 * introduced after API level 4 in a backwards compatible fashion. 25 */ 26public class AccessibilityEventCompat { 27 28 static interface AccessibilityEventVersionImpl { 29 public int getRecordCount(AccessibilityEvent event); 30 public void appendRecord(AccessibilityEvent event, Object record); 31 public Object getRecord(AccessibilityEvent event, int index); 32 } 33 34 static class AccessibilityEventStubImpl implements AccessibilityEventVersionImpl { 35 36 @Override 37 public void appendRecord(AccessibilityEvent event, Object record) { 38 39 } 40 41 @Override 42 public Object getRecord(AccessibilityEvent event, int index) { 43 return null; 44 } 45 46 @Override 47 public int getRecordCount(AccessibilityEvent event) { 48 return 0; 49 } 50 } 51 52 static class AccessibilityEventIcsImpl extends AccessibilityEventStubImpl { 53 54 @Override 55 public void appendRecord(AccessibilityEvent event, Object record) { 56 AccessibilityEventCompatIcs.appendRecord(event, record); 57 } 58 59 @Override 60 public Object getRecord(AccessibilityEvent event, int index) { 61 return AccessibilityEventCompatIcs.getRecord(event, index); 62 } 63 64 @Override 65 public int getRecordCount(AccessibilityEvent event) { 66 return AccessibilityEventCompatIcs.getRecordCount(event); 67 } 68 } 69 70 private final static AccessibilityEventVersionImpl IMPL; 71 72 static { 73 if (Build.VERSION.SDK_INT >= 14) { // ICS 74 IMPL = new AccessibilityEventIcsImpl(); 75 } else { 76 IMPL = new AccessibilityEventStubImpl(); 77 } 78 } 79 80 /** 81 * Represents the event of a hover enter over a {@link android.view.View}. 82 */ 83 public static final int TYPE_VIEW_HOVER_ENTER = 0x00000080; 84 85 /** 86 * Represents the event of a hover exit over a {@link android.view.View}. 87 */ 88 public static final int TYPE_VIEW_HOVER_EXIT = 0x00000100; 89 90 /** 91 * Represents the event of starting a touch exploration gesture. 92 */ 93 public static final int TYPE_TOUCH_EXPLORATION_GESTURE_START = 0x00000200; 94 95 /** 96 * Represents the event of ending a touch exploration gesture. 97 */ 98 public static final int TYPE_TOUCH_EXPLORATION_GESTURE_END = 0x00000400; 99 100 /** 101 * Represents the event of changing the content of a window. 102 */ 103 public static final int TYPE_WINDOW_CONTENT_CHANGED = 0x00000800; 104 105 /** 106 * Represents the event of scrolling a view. 107 */ 108 public static final int TYPE_VIEW_SCROLLED = 0x00001000; 109 110 /** 111 * Represents the event of changing the selection in an {@link android.widget.EditText}. 112 */ 113 public static final int TYPE_VIEW_TEXT_SELECTION_CHANGED = 0x00002000; 114 115 /** 116 * Represents the event of an application making an announcement. 117 */ 118 public static final int TYPE_ANNOUNCEMENT = 0x00004000; 119 120 /** 121 * Represents the event of gaining accessibility focus. 122 */ 123 public static final int TYPE_VIEW_ACCESSIBILITY_FOCUSED = 0x00008000; 124 125 /** 126 * Represents the event of clearing accessibility focus. 127 */ 128 public static final int TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED = 0x00010000; 129 130 /** 131 * Represents the event of traversing the text of a view at a given movement granularity. 132 */ 133 public static final int TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY = 0x00020000; 134 135 /** 136 * Represents the event of beginning gesture detection. 137 */ 138 public static final int TYPE_GESTURE_DETECTION_START = 0x00040000; 139 140 /** 141 * Represents the event of ending gesture detection. 142 */ 143 public static final int TYPE_GESTURE_DETECTION_END = 0x00080000; 144 145 /** 146 * Represents the event of the user starting to touch the screen. 147 */ 148 public static final int TYPE_TOUCH_INTERACTION_START = 0x00100000; 149 150 /** 151 * Represents the event of the user ending to touch the screen. 152 */ 153 public static final int TYPE_TOUCH_INTERACTION_END = 0x00200000; 154 155 /** 156 * Mask for {@link AccessibilityEvent} all types. 157 * 158 * @see AccessibilityEvent#TYPE_VIEW_CLICKED 159 * @see AccessibilityEvent#TYPE_VIEW_LONG_CLICKED 160 * @see AccessibilityEvent#TYPE_VIEW_SELECTED 161 * @see AccessibilityEvent#TYPE_VIEW_FOCUSED 162 * @see AccessibilityEvent#TYPE_VIEW_TEXT_CHANGED 163 * @see AccessibilityEvent#TYPE_WINDOW_STATE_CHANGED 164 * @see AccessibilityEvent#TYPE_NOTIFICATION_STATE_CHANGED 165 * @see #TYPE_VIEW_HOVER_ENTER 166 * @see #TYPE_VIEW_HOVER_EXIT 167 * @see #TYPE_TOUCH_EXPLORATION_GESTURE_START 168 * @see #TYPE_TOUCH_EXPLORATION_GESTURE_END 169 * @see #TYPE_WINDOW_CONTENT_CHANGED 170 * @see #TYPE_VIEW_SCROLLED 171 * @see #TYPE_VIEW_TEXT_SELECTION_CHANGED 172 * @see #TYPE_ANNOUNCEMENT 173 * @see #TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY 174 * @see #TYPE_GESTURE_DETECTION_START 175 * @see #TYPE_GESTURE_DETECTION_END 176 * @see #TYPE_TOUCH_INTERACTION_START 177 * @see #TYPE_TOUCH_INTERACTION_END 178 */ 179 public static final int TYPES_ALL_MASK = 0xFFFFFFFF; 180 181 /* 182 * Hide constructor from clients. 183 */ 184 private AccessibilityEventCompat() { 185 186 } 187 188 /** 189 * Gets the number of records contained in the event. 190 * 191 * @return The number of records. 192 */ 193 public static int getRecordCount(AccessibilityEvent event) { 194 return IMPL.getRecordCount(event); 195 } 196 197 /** 198 * Appends an {@link android.view.accessibility.AccessibilityRecord} to the end of 199 * event records. 200 * 201 * @param record The record to append. 202 * 203 * @throws IllegalStateException If called from an AccessibilityService. 204 */ 205 public static void appendRecord(AccessibilityEvent event, AccessibilityRecordCompat record) { 206 IMPL.appendRecord(event, record.getImpl()); 207 } 208 209 /** 210 * Gets the record at a given index. 211 * 212 * @param index The index. 213 * @return The record at the specified index. 214 */ 215 public static AccessibilityRecordCompat getRecord(AccessibilityEvent event, int index) { 216 return new AccessibilityRecordCompat(IMPL.getRecord(event, index)); 217 } 218} 219