List of usage examples for android.view.accessibility AccessibilityNodeInfo FOCUS_ACCESSIBILITY
int FOCUS_ACCESSIBILITY
To view the source code for android.view.accessibility AccessibilityNodeInfo FOCUS_ACCESSIBILITY.
Click Source Link
From source file:com.android.utils.FocusFinder.java
public static AccessibilityNodeInfoCompat getFocusedNode(AccessibilityService service, boolean fallbackOnRoot) { AccessibilityNodeInfo root = service.getRootInActiveWindow(); AccessibilityNodeInfo focused = null; try {/*from w w w.j a v a2 s . c o m*/ AccessibilityNodeInfo ret = null; if (root != null) { focused = root.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY); if (focused != null && focused.isVisibleToUser()) { ret = focused; focused = null; } else if (fallbackOnRoot) { ret = root; root = null; } } else { LogUtils.log(service, Log.ERROR, "No current window root"); } if (ret != null) { return new AccessibilityNodeInfoCompat(ret); } } finally { if (root != null) { root.recycle(); } if (focused != null) { focused.recycle(); } } return null; }
From source file:com.android.talkback.contextmenu.ListMenuManager.java
@Override public boolean showMenu(int menuId) { mLastUtterance = mService.getSpeechController().getLastUtterance(); dismissAll();/*from w w w .ja va2 s . c om*/ // Some TalkBack tutorial modules don't allow context menus. if (AccessibilityTutorialActivity.isTutorialActive() && !AccessibilityTutorialActivity.shouldAllowContextMenus()) { return false; } mService.saveFocusedNode(); final ListMenu menu = new ListMenu(mService); menu.setDefaultListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item.hasSubMenu()) { CharSequence[] items = getItemsFromMenu(item.getSubMenu()); ListMenu menu = (ListMenu) item.getSubMenu(); showDialogMenu(menu.getTitle(), items, menu); } else if (item.getItemId() == R.id.spell_last_utterance) { AccessibilityNodeInfo node = mService.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY); if (node != null) { AccessibilityNodeInfoCompat compat = new AccessibilityNodeInfoCompat(node); CharSequence text = NodeSpeechRuleProcessor.getInstance().getDescriptionForNode(compat, null); compat.recycle(); mService.getSpeechController().spellUtterance(text); } } else if (item.getItemId() == R.id.repeat_last_utterance) { mService.getSpeechController().interrupt(); mService.getSpeechController().repeatUtterance(mLastUtterance); } else { mMenuClickProcessor.onMenuItemClicked(item); } return true; } }); ListMenuPreparer menuPreparer = new ListMenuPreparer(mService); menuPreparer.prepareMenu(menu, menuId); showDialogMenu(menu.getTitle(), getItemsFromMenu(menu), menu); return false; }
From source file:com.android.screenspeak.contextmenu.ListMenuManager.java
@Override public boolean showMenu(int menuId) { mLastUtterance = mService.getSpeechController().getLastUtterance(); dismissAll();// ww w . jav a 2 s .co m // Some ScreenSpeak tutorial modules don't allow context menus. if (AccessibilityTutorialActivity.isTutorialActive() && !AccessibilityTutorialActivity.shouldAllowContextMenus()) { return false; } mService.saveFocusedNode(); final ListMenu menu = new ListMenu(mService); menu.setDefaultListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item.hasSubMenu()) { CharSequence[] items = getItemsFromMenu(item.getSubMenu()); ListMenu menu = (ListMenu) item.getSubMenu(); showDialogMenu(menu.getTitle(), items, menu); } else if (item.getItemId() == R.id.spell_last_utterance) { AccessibilityNodeInfo node = mService.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY); if (node != null) { AccessibilityNodeInfoCompat compat = new AccessibilityNodeInfoCompat(node); CharSequence text = NodeSpeechRuleProcessor.getInstance().getDescriptionForNode(compat, null); compat.recycle(); mService.getSpeechController().spellUtterance(text); } } else if (item.getItemId() == R.id.repeat_last_utterance) { mService.getSpeechController().interrupt(); mService.getSpeechController().repeatUtterance(mLastUtterance); } else { mMenuClickProcessor.onMenuItemClicked(item); } return true; } }); ListMenuPreparer menuPreparer = new ListMenuPreparer(mService); menuPreparer.prepareMenu(menu, menuId); showDialogMenu(menu.getTitle(), getItemsFromMenu(menu), menu); return false; }
From source file:com.android.utils.WindowManager.java
/** * @return window that currently accessibilityFocused window. * If there is no accessibility focused window it returns first window that has TYPE_APPLICATION * or null if there is no window with TYPE_APPLICATION type *///w ww .j a va 2s .co m public AccessibilityWindowInfo getCurrentWindow(boolean useInputFocus) { int currentWindowIndex = getFocusedWindowIndex(mWindows, AccessibilityNodeInfo.FOCUS_ACCESSIBILITY); if (currentWindowIndex != WRONG_INDEX) { return mWindows.get(currentWindowIndex); } if (!useInputFocus) { return null; } currentWindowIndex = getFocusedWindowIndex(mWindows, AccessibilityNodeInfo.FOCUS_INPUT); if (currentWindowIndex != WRONG_INDEX) { return mWindows.get(currentWindowIndex); } return null; }
From source file:com.googlecode.eyesfree.brailleback.FocusFinder.java
public static AccessibilityNodeInfoCompat getFocusedNode(AccessibilityService service, boolean fallbackOnRoot) { AccessibilityNodeInfo root = service.getRootInActiveWindow(); AccessibilityNodeInfo focused = null; try {/*from w w w.j a v a 2s . c o m*/ AccessibilityNodeInfo ret = null; if (root != null) { focused = root.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY); if (focused != null && focused.isVisibleToUser()) { ret = focused; focused = null; } else if (fallbackOnRoot) { ret = root; root = null; } } else { LogUtils.log(service, Log.ERROR, "No current window root"); } if (ret != null) { return new AccessibilityNodeInfoCompat(ret); } } finally { if (root != null) { root.recycle(); } if (focused != null) { focused.recycle(); } } return null; }
From source file:com.android.utils.WindowManager.java
private static int getFocusedWindowIndex(List<AccessibilityWindowInfo> windows, int focusType) { if (windows == null) { return WRONG_INDEX; }/*www . j ava 2 s . co m*/ for (int i = 0, size = windows.size(); i < size; i++) { AccessibilityWindowInfo window = windows.get(i); if (window == null) { continue; } if (focusType == AccessibilityNodeInfo.FOCUS_ACCESSIBILITY && window.isAccessibilityFocused()) { return i; } else if (focusType == AccessibilityNodeInfo.FOCUS_INPUT && window.isFocused()) { return i; } } return WRONG_INDEX; }
From source file:com.google.android.marvin.mytalkback.CursorController.java
/** * Clears the current cursor position.// w w w . ja va 2s . c om */ public void clearCursor() { final AccessibilityNodeInfo root = mService.getRootInActiveWindow(); if (root == null) { return; } final AccessibilityNodeInfo focused = root.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY); if (focused == null) { return; } focused.performAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS); }
From source file:com.googlecode.eyesfree.brailleback.IMENavigationModeTest.java
/** * Tests the behaviour of the "text only" mode. * Also used when input is started, but the field is not handled * specially (as with, for example, a focused EditText). *//* w ww . ja v a2s .c om*/ public void testTextOnlyModeInputStarted() { EditorInfo ei = new EditorInfo(); // Mock out the AccessibilityNodeInfo. // The class actually uses the compat variant, but on recent API // releases (including the test environment) they should call through. AccessibilityNodeInfo rawNode = mock(AccessibilityNodeInfo.class); when(mAccessibilityService.getRootInActiveWindow()).thenReturn(rawNode); when(rawNode.findFocus(AccessibilityNodeInfo.FOCUS_INPUT)).thenReturn(rawNode); when(rawNode.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY)).thenReturn(rawNode); when(rawNode.getClassName()).thenReturn("com.example.UnknownWidget"); mIMENavMode.onActivate(); mIMENavMode.onCreateIME(); verify(mNext).onActivate(); mIMENavMode.onBindInput(); mIMENavMode.onStartInput(ei, false /* restarting */); Mockito.reset(mSelfBrailleManager); mIMENavMode.onStartInputView(ei, false /* restarting */); verify(mSelfBrailleManager).setImeOpen(true); assertEquals(mBrailleTranslator, mIMENavMode.getBrailleTranslator()); assertNull(mIMENavMode.getDisplayManager()); assertEquals(mFeedbackManager, mIMENavMode.getFeedbackManager()); AccessibilityEvent accessibilityEvent = AccessibilityEvent.obtain(); try { mIMENavMode.onObserveAccessibilityEvent(accessibilityEvent); verify(mNext).onObserveAccessibilityEvent(accessibilityEvent); } finally { accessibilityEvent.recycle(); } accessibilityEvent = AccessibilityEvent.obtain(); try { mIMENavMode.onAccessibilityEvent(accessibilityEvent); verify(mNext).onAccessibilityEvent(accessibilityEvent); } finally { accessibilityEvent.recycle(); } AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(); try { mIMENavMode.onInvalidateAccessibilityNode(node); verify(mNext).onInvalidateAccessibilityNode(node); } finally { node.recycle(); } DisplayManager.Content content = new DisplayManager.Content(""); mIMENavMode.onPanLeftOverflow(content); verify(mNext).onPanLeftOverflow(content); mIMENavMode.onPanRightOverflow(content); verify(mNext).onPanRightOverflow(content); BrailleInputEvent inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_KEY_ENTER, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).sendAndroidKey(KeyEvent.KEYCODE_ENTER); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_KEY_DEL, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).sendAndroidKey(KeyEvent.KEYCODE_DEL); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_BRAILLE_KEY, 0x1b, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).handleBrailleKey(0x1b); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_NAV_ITEM_NEXT, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext).onMappedInputEvent(inputEvent, content); verify(mIME, never()).moveCursor(anyInt(), anyInt()); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ACTIVATE_CURRENT, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext).onMappedInputEvent(inputEvent, content); verify(mIME, never()).sendDefaultAction(); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ROUTE, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext).onMappedInputEvent(inputEvent, content); verify(mIME, never()).route(anyInt(), any(DisplayManager.Content.class)); verify(mSelfBrailleManager, never()).setImeOpen(false); Mockito.reset(mSelfBrailleManager); mIMENavMode.onFinishInputView(true); mIMENavMode.onFinishInput(); mIMENavMode.onUnbindInput(); mIMENavMode.onDestroyIME(); verify(mSelfBrailleManager, never()).setImeOpen(true); verify(mSelfBrailleManager, atLeastOnce()).setImeOpen(false); // Deactivate, but make sure it didn't happen too early. verify(mNext, never()).onDeactivate(); mIMENavMode.onDeactivate(); verify(mNext).onDeactivate(); }
From source file:com.google.android.marvin.mytalkback.ProcessorFocusAndSingleTap.java
/** * Attempts to place focus on the {@code event}'s source node. *///w ww. j a v a 2s . c o m private boolean setFocusFromViewFocused(AccessibilityEvent event, AccessibilityRecordCompat record) { AccessibilityNodeInfoCompat source = null; AccessibilityNodeInfoCompat existing = null; AccessibilityNodeInfoCompat child = null; try { source = record.getSource(); if (source == null) { return false; } // Under certain conditions, we may need to ignore this event. if (shouldDropFocusEvent(event, source)) { return false; } // Try focusing the source node. if (tryFocusing(source)) { return true; } // If we fail and the source node already contains focus, abort. existing = source.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY); if (existing != null) { return false; } // If we fail to focus a node, perhaps because it is a focusable // but non-speaking container, we should still attempt to place // focus on a speaking child within the container. child = AccessibilityNodeInfoUtils.searchFromBfs(mService, source, AccessibilityNodeInfoUtils.FILTER_SHOULD_FOCUS); if (child == null) { return false; } return tryFocusing(child); } finally { AccessibilityNodeInfoUtils.recycleNodes(source, existing, child); } }
From source file:com.google.android.marvin.mytalkback.ProcessorFocusAndSingleTap.java
/** * Attempts to place focus within a new window. *///from w ww. j a v a 2s.c o m private boolean ensureFocusConsistency(boolean shouldPlaceFocus) { AccessibilityNodeInfoCompat root = null; AccessibilityNodeInfoCompat focused = null; AccessibilityNodeInfoCompat inputFocused = null; AccessibilityNodeInfoCompat firstFocus = null; try { root = AccessibilityServiceCompatUtils.getRootInActiveWindow(mService); if (root == null) { return false; } // First, see if we've already placed accessibility focus. focused = root.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY); if (focused != null) { if (AccessibilityNodeInfoUtils.shouldFocusNode(mService, focused)) { return true; } LogUtils.log(Log.VERBOSE, "Clearing focus from invalid node"); focused.performAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } // If not, should we attempt to place focus? if (!shouldPlaceFocus) { return false; } // Next, see if the system has placed input focus. inputFocused = root.findFocus(AccessibilityNodeInfo.FOCUS_INPUT); if (tryFocusing(inputFocused)) { return true; } // Finally, just try to focus the first focusable item. firstFocus = AccessibilityNodeInfoUtils.searchFromInOrderTraversal(mService, root, AccessibilityNodeInfoUtils.FILTER_SHOULD_FOCUS, NodeFocusFinder.SEARCH_FORWARD); if (tryFocusing(firstFocus)) { return true; } LogUtils.log(Log.ERROR, "Failed to place focus from new window"); return false; } finally { AccessibilityNodeInfoUtils.recycleNodes(root, focused, inputFocused, firstFocus); } }