Java Code Examples for android.view.accessibility.AccessibilityEvent#TYPE_VIEW_ACCESSIBILITY_FOCUSED
The following examples show how to use
android.view.accessibility.AccessibilityEvent#TYPE_VIEW_ACCESSIBILITY_FOCUSED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomLabelManager.java From brailleback with Apache License 2.0 | 6 votes |
@Override public void onAccessibilityEvent(AccessibilityEvent event) { final Locale currentLocale = Locale.getDefault(); if (!currentLocale.equals(mLastLocale)) { // Refresh cache if device locale has changed since the last event mLastLocale = currentLocale; refreshCacheInternal(null); } switch (event.getEventType()) { case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: prefetchLabelsFromEvent(event); } }
Example 2
Source File: SearchNavigationMode.java From brailleback with Apache License 2.0 | 6 votes |
@Override public boolean onAccessibilityEvent(AccessibilityEvent event) { switch (event.getEventType()) { case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: DisplayManager.Content content = formatEventToBraille(event); if (content != null) { mDisplayManager.setContent(content); } return true; case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: finishSearch(); // Let it fall through so other navigation mode can // receive the window_state_changed event. return false; case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: // This will re-evaluate the search and refocus if necessary. mMatchedNode.reset(AccessibilityNodeInfoUtils.refreshNode( mMatchedNode.get())); evaluateSearch(); return true; } // Don't let fall through. return true; }
Example 3
Source File: DefaultNavigationMode.java From brailleback with Apache License 2.0 | 6 votes |
@Override public boolean onAccessibilityEvent(AccessibilityEvent event) { switch (event.getEventType()) { case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: brailleNodeFromEvent(event); break; case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: brailleFocusedNode(); break; case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: if (!brailleFocusedNode()) { // Since focus is typically not set in a newly opened // window, so braille the window as-if the first focusable // node had focus. We don't update the focus because that // will make other services (e.g. talkback) reflect this // change, which is not desired. brailleFirstFocusableNode(); } break; } return true; }
Example 4
Source File: ProcessorPhoneticLetters.java From talkback with Apache License 2.0 | 6 votes |
private boolean isKeyboardEvent(AccessibilityEvent event) { if (event.getEventType() != AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) { return false; } // For platform since lollipop, check that the current window is an // Input Method. final AccessibilityNodeInfo source = event.getSource(); if (source == null) { return false; } int windowId = source.getWindowId(); source.recycle(); WindowManager manager = new WindowManager(service); return manager.getWindowType(windowId) == AccessibilityWindowInfo.TYPE_INPUT_METHOD; }
Example 5
Source File: ListMenuManager.java From talkback with Apache License 2.0 | 5 votes |
@Override public void onAccessibilityEvent(AccessibilityEvent event, EventId eventId) { if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED && deferredAction != null) { executeDeferredActionByType(DeferredType.ACCESSIBILITY_FOCUS_RECEIVED); } }
Example 6
Source File: DialView.java From android-BasicAccessibility with Apache License 2.0 | 5 votes |
/** * This is where a View should populate outgoing accessibility events with its text content. * While this method is free to modify event attributes other than text content, doing so * should normally be performed in * {@link #onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent)}. * <p/> * <p>Note that the behavior of this method will typically vary, depending on the type of * accessibility event is passed into it. The allowed values also very, and are documented * in {@link android.view.accessibility.AccessibilityEvent}. * <p/> * <p>Typically, this is where you'll describe the state of your custom view. You may also * want to provide custom directions when the user has focused your view. * * @param event The accessibility event which to populate. */ // BEGIN_INCLUDE (on_populate_accessibility_event) @Override @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public void onPopulateAccessibilityEvent(AccessibilityEvent event) { super.onPopulateAccessibilityEvent(event); // Detect what type of accessibility event is being passed in. int eventType = event.getEventType(); // Common case: The user has interacted with our view in some way. State may or may not // have been changed. Read out the current status of the view. // // We also set some other metadata which is not used by TalkBack, but could be used by // other TTS engines. if (eventType == AccessibilityEvent.TYPE_VIEW_SELECTED || eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) { event.getText().add("Mode selected: " + Integer.toString(mActiveSelection + 1) + "."); event.setItemCount(SELECTION_COUNT); event.setCurrentItemIndex(mActiveSelection); } // When a user first focuses on our view, we'll also read out some simple instructions to // make it clear that this is an interactive element. if (eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) { event.getText().add("Tap to change."); } }
Example 7
Source File: AccessibilityTutorialActivity.java From talkback with Apache License 2.0 | 5 votes |
@Override public void onAccessibilityEvent(AccessibilityEvent event, EventId eventId) { if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) { if (runnable != null) { handler.removeCallbacks(runnable); TalkBackService service = TalkBackService.getInstance(); if (service != null) { service.postRemoveEventListener(this); } runnable = null; } } }
Example 8
Source File: GridItemExercise.java From talkback with Apache License 2.0 | 5 votes |
@Override public void sendAccessibilityEvent(View host, int eventType) { super.sendAccessibilityEvent(host, eventType); if (eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) { onAccessibilityFocused(index); } else if (eventType == AccessibilityEvent.TYPE_VIEW_CLICKED) { onAccessibilityClicked(index); } }
Example 9
Source File: FullScreenReadDialog.java From talkback with Apache License 2.0 | 5 votes |
/** * TODO: defers read-from-top by window stable and defers read-from-next by a11y * focus event. */ @Override public void onAccessibilityEvent(AccessibilityEvent event, EventId eventId) { // To make sure the window is ready to restore focused node and start reading. if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) { service.postRemoveEventListener(this); service.getFullScreenReadController().startReadingWithoutDialog(EVENT_ID_UNTRACKED, state); } }
Example 10
Source File: ProcessorPermissionDialogs.java From talkback with Apache License 2.0 | 5 votes |
@Override public void onAccessibilityEvent(AccessibilityEvent event, EventId eventId) { switch (event.getEventType()) { case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: clearNode(); AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event); AccessibilityNodeInfoCompat source = record.getSource(); if (source != null) { if (ALLOW_BUTTON.equals(source.getViewIdResourceName()) && dimScreenController.isDimmingEnabled()) { Rect sourceRect = new Rect(); source.getBoundsInScreen(sourceRect); overlay.show(sourceRect); allowNode = source; } else { source.recycle(); } } break; case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: clearNode(); break; default: // fall out } if (allowNode != null) { overlay.onAccessibilityEvent(event, eventId); } }
Example 11
Source File: ProcessorCursorState.java From talkback with Apache License 2.0 | 5 votes |
@Override public void onAccessibilityEvent(AccessibilityEvent event, EventId eventId) { switch (event.getEventType()) { case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: // Keep track of the accessibility focused EditText. overlay.hide(); saveFocusedNode(AccessibilityEventCompat.asRecord(event)); break; case AccessibilityEvent.TYPE_VIEW_FOCUSED: // On pre Android O devices, double-tap on screen will interpreted as touch down and up // action at the center of the focused node, which might set cursor to the middle of text if // the text is long enough. TalkBack overrides the cursor position to be the end of the // field to avoid the confusion of cursor movement. See for details. if (SHOULD_HANDLE_TOUCH_EVENT) { // Reset the EditText cursor because focusing will snap it to the middle. resetNodeCursor(AccessibilityEventCompat.asRecord(event), eventId); } break; case AccessibilityEvent.TYPE_VIEW_SCROLLED: // Hide the overlay so it doesn't interfere with scrolling. overlay.hide(); break; case AccessibilityEvent.TYPE_TOUCH_INTERACTION_START: if (SHOULD_HANDLE_TOUCH_EVENT) { // Show the overlay if the a11y-focused EditText is editing and we touch the screen. touchStart(event, eventId); } break; case AccessibilityEvent.TYPE_TOUCH_INTERACTION_END: if (SHOULD_HANDLE_TOUCH_EVENT) { // Hide the overlay when we stop touching the screen. touchEnd(event, eventId); } break; default: // fall out } }
Example 12
Source File: AccessibilityEventUtils.java From talkback with Apache License 2.0 | 5 votes |
public static int[] getAllEventTypes() { return new int[] { AccessibilityEvent.TYPE_ANNOUNCEMENT, AccessibilityEvent.TYPE_ASSIST_READING_CONTEXT, AccessibilityEvent.TYPE_GESTURE_DETECTION_END, AccessibilityEvent.TYPE_GESTURE_DETECTION_START, AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED, AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END, AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START, AccessibilityEvent.TYPE_TOUCH_INTERACTION_END, AccessibilityEvent.TYPE_TOUCH_INTERACTION_START, AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED, AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED, AccessibilityEvent.TYPE_VIEW_CLICKED, AccessibilityEvent.TYPE_VIEW_CONTEXT_CLICKED, AccessibilityEvent.TYPE_VIEW_FOCUSED, AccessibilityEvent.TYPE_VIEW_HOVER_ENTER, AccessibilityEvent.TYPE_VIEW_HOVER_EXIT, AccessibilityEvent.TYPE_VIEW_LONG_CLICKED, AccessibilityEvent.TYPE_VIEW_SCROLLED, AccessibilityEvent.TYPE_VIEW_SELECTED, AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED, AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED, AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY, AccessibilityEvent.TYPE_WINDOWS_CHANGED, AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED }; }
Example 13
Source File: GlobalVariables.java From talkback with Apache License 2.0 | 5 votes |
public void updateStateFromEvent(AccessibilityEvent event) { switch (event.getEventType()) { case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: { final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event); final AccessibilityNodeInfoCompat sourceNode = record.getSource(); // Transition the collection state if necessary. mCollectionState.updateCollectionInformation(sourceNode, event); if (sourceNode != null) { final AccessibilityNodeInfoCompat scrollableNode = AccessibilityNodeInfoUtils.getSelfOrMatchingAncestor( sourceNode, AccessibilityNodeInfoUtils.FILTER_SCROLLABLE); mIsLastFocusInScrollableNode = mIsCurrentFocusInScrollableNode; mIsCurrentFocusInScrollableNode = (scrollableNode != null); if (scrollableNode != null) { scrollableNode.recycle(); } TraversalStrategy traversalStrategy = new SimpleTraversalStrategy(); // TODO: TraversalStrategyUtils.isEdgeListItem() doesn't include Role check in // AccessibilityNodeInfoUtils.FILTER_AUTO_SCROLL. Shall we use // TraversalStrategyUtils.isAutoScrollEdgeListItem() instead? mIsFocusEdgeListItem = TraversalStrategyUtils.isEdgeListItem(sourceNode, traversalStrategy); traversalStrategy.recycle(); mLastWindowId = mCurrentWindowId; mCurrentWindowId = sourceNode.getWindowId(); sourceNode.recycle(); } } break; default: // fall out } }
Example 14
Source File: BrailleMenuNavigationMode.java From brailleback with Apache License 2.0 | 5 votes |
@Override public boolean onAccessibilityEvent(AccessibilityEvent event) { switch (event.getEventType()) { case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: closeMenu(); return true; } // Don't let fall through. return true; }
Example 15
Source File: AccessibilityUtils.java From DevUtils with Apache License 2.0 | 4 votes |
/** * 打印 AccessibilityEvent 信息日志 * @param event {@link AccessibilityEvent} * @param tag 日志 TAG */ public static void printAccessibilityEvent(final AccessibilityEvent event, final String tag) { if (event == null || !LogPrintUtils.isPrintLog()) return; StringBuilder builder = new StringBuilder(); builder.append("========================="); builder.append(NEW_LINE_STR); int eventType = event.getEventType(); // 事件类型 builder.append("packageName: " + event.getPackageName() + ""); // 响应事件的应用包名 builder.append(NEW_LINE_STR); builder.append("source: " + event.getSource() + ""); // 事件源信息 builder.append(NEW_LINE_STR); builder.append("source class: " + event.getClassName() + ""); // 事件源的类名, 如 android.widget.TextView builder.append(NEW_LINE_STR); builder.append("event type(int): " + eventType + ""); builder.append(NEW_LINE_STR); switch (eventType) { case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:// 通知栏事件 builder.append("event type: TYPE_NOTIFICATION_STATE_CHANGED"); break; case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: // 窗体状态改变 builder.append("event type: TYPE_WINDOW_STATE_CHANGED"); break; case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: // View 获取到焦点 builder.append("event type: TYPE_VIEW_ACCESSIBILITY_FOCUSED"); break; case AccessibilityEvent.TYPE_GESTURE_DETECTION_START: builder.append("event type: TYPE_VIEW_ACCESSIBILITY_FOCUSED"); break; case AccessibilityEvent.TYPE_GESTURE_DETECTION_END: builder.append("event type: TYPE_GESTURE_DETECTION_END"); break; case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: builder.append("event type: TYPE_WINDOW_CONTENT_CHANGED"); break; case AccessibilityEvent.TYPE_VIEW_CLICKED: builder.append("event type: TYPE_VIEW_CLICKED"); break; case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED: builder.append("event type: TYPE_VIEW_TEXT_CHANGED"); break; case AccessibilityEvent.TYPE_VIEW_SCROLLED: builder.append("event type: TYPE_VIEW_SCROLLED"); break; case AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED: builder.append("event type: TYPE_VIEW_TEXT_SELECTION_CHANGED"); break; } builder.append(NEW_LINE_STR); for (CharSequence txt : event.getText()) { // 输出当前事件包含的文本信息 builder.append("text: " + txt); builder.append(NEW_LINE_STR); } builder.append("========================="); // 打印日志 LogPrintUtils.dTag(tag, builder.toString()); }
Example 16
Source File: AccessibilityEventUtils.java From talkback with Apache License 2.0 | 4 votes |
public static String typeToString(int eventType) { switch (eventType) { case AccessibilityEvent.TYPE_ANNOUNCEMENT: return "TYPE_ANNOUNCEMENT"; case AccessibilityEvent.TYPE_ASSIST_READING_CONTEXT: return "TYPE_ASSIST_READING_CONTEXT"; case AccessibilityEvent.TYPE_GESTURE_DETECTION_END: return "TYPE_GESTURE_DETECTION_END"; case AccessibilityEvent.TYPE_GESTURE_DETECTION_START: return "TYPE_GESTURE_DETECTION_START"; case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED: return "TYPE_NOTIFICATION_STATE_CHANGED"; case AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END: return "TYPE_TOUCH_EXPLORATION_GESTURE_END"; case AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START: return "TYPE_TOUCH_EXPLORATION_GESTURE_START"; case AccessibilityEvent.TYPE_TOUCH_INTERACTION_END: return "TYPE_TOUCH_INTERACTION_END"; case AccessibilityEvent.TYPE_TOUCH_INTERACTION_START: return "TYPE_TOUCH_INTERACTION_START"; case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: return "TYPE_VIEW_ACCESSIBILITY_FOCUSED"; case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: return "TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED"; case AccessibilityEvent.TYPE_VIEW_CLICKED: return "TYPE_VIEW_CLICKED"; case AccessibilityEvent.TYPE_VIEW_CONTEXT_CLICKED: return "TYPE_VIEW_CONTEXT_CLICKED"; case AccessibilityEvent.TYPE_VIEW_FOCUSED: return "TYPE_VIEW_FOCUSED"; case AccessibilityEvent.TYPE_VIEW_HOVER_ENTER: return "TYPE_VIEW_HOVER_ENTER"; case AccessibilityEvent.TYPE_VIEW_HOVER_EXIT: return "TYPE_VIEW_HOVER_EXIT"; case AccessibilityEvent.TYPE_VIEW_LONG_CLICKED: return "TYPE_VIEW_LONG_CLICKED"; case AccessibilityEvent.TYPE_VIEW_SCROLLED: return "TYPE_VIEW_SCROLLED"; case AccessibilityEvent.TYPE_VIEW_SELECTED: return "TYPE_VIEW_SELECTED"; case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED: return "TYPE_VIEW_TEXT_CHANGED"; case AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED: return "TYPE_VIEW_TEXT_SELECTION_CHANGED"; case AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY: return "TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY"; case AccessibilityEvent.TYPE_WINDOWS_CHANGED: return "TYPE_WINDOWS_CHANGED"; case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: return "TYPE_WINDOW_CONTENT_CHANGED"; case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: return "TYPE_WINDOW_STATE_CHANGED"; default: return "(unhandled)"; } }
Example 17
Source File: DirectionNavigationController.java From talkback with Apache License 2.0 | 4 votes |
@Override public int getEventTypes() { return AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED; }
Example 18
Source File: DynamicHeightViewPager.java From px-android with MIT License | 4 votes |
@Override public boolean dispatchPopulateAccessibilityEvent(final AccessibilityEvent event) { isAccessibilityFocused = event.getEventType() == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED; return super.dispatchPopulateAccessibilityEvent(event); }