List of usage examples for android.view.accessibility AccessibilityNodeInfo FOCUS_INPUT
int FOCUS_INPUT
To view the source code for android.view.accessibility AccessibilityNodeInfo FOCUS_INPUT.
Click Source Link
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 *///ww w. j a v a 2 s. c o 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.android.screenspeak.eventprocessor.ProcessorVolumeStream.java
private AccessibilityNodeInfoCompat findInputFocus() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { List<AccessibilityWindowInfo> awis = mService.getWindows(); for (AccessibilityWindowInfo awi : awis) { if (awi.getType() == AccessibilityWindowInfo.TYPE_INPUT_METHOD) continue; AccessibilityNodeInfo info = awi.getRoot(); if (info == null) continue; AccessibilityNodeInfoCompat root = new AccessibilityNodeInfoCompat(awi.getRoot()); AccessibilityNodeInfoCompat focus = root.findFocus(AccessibilityNodeInfo.FOCUS_INPUT); if (focus != null) { if (!root.equals(focus)) root.recycle();/*from w w w .j a v a 2s . c o m*/ return focus; } else { root.recycle(); } } return null; } else { AccessibilityNodeInfo info = mService.getRootInActiveWindow(); if (info == null) return null; AccessibilityNodeInfoCompat root = new AccessibilityNodeInfoCompat(info); AccessibilityNodeInfoCompat focus = root.findFocus(AccessibilityNodeInfoCompat.FOCUS_INPUT); if (focus != null && !focus.equals(root)) root.recycle(); return focus; } }
From source file:com.android.utils.WindowManager.java
private static int getFocusedWindowIndex(List<AccessibilityWindowInfo> windows, int focusType) { if (windows == null) { return WRONG_INDEX; }/*from www . ja v a2 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.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). *//*from w ww . ja va 2 s. 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 within a new window. *//*from w w w . j a va 2 s. c om*/ 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); } }
From source file:com.googlecode.eyesfree.brailleback.IMENavigationModeTest.java
/** * Tests that text and navigation mode is not triggered when the input view * is not shown, even if input is started. This distinction is needed to * handle Chrome correctly.//w w w . jav a 2s .co m */ public void testTextAndNavigationModeRequiresStartInputView() { 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.ExampleWebView"); when(mSelfBrailleManager.hasContentForNode(compatWrapperForNode(rawNode))).thenReturn(true); mIMENavMode.onActivate(); mIMENavMode.onCreateIME(); verify(mNext).onActivate(); mIMENavMode.onBindInput(); mIMENavMode.onStartInput(ei, false /* restarting */); assertEquals(mBrailleTranslator, mIMENavMode.getBrailleTranslator()); assertNull(mIMENavMode.getDisplayManager()); assertEquals(mFeedbackManager, mIMENavMode.getFeedbackManager()); verify(mSelfBrailleManager, atLeastOnce()).setImeOpen(false); 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)); mIMENavMode.onFinishInput(); mIMENavMode.onUnbindInput(); mIMENavMode.onDestroyIME(); verify(mSelfBrailleManager, never()).setImeOpen(true); // Deactivate, but make sure it didn't happen too early. verify(mNext, never()).onDeactivate(); mIMENavMode.onDeactivate(); verify(mNext).onDeactivate(); }
From source file:com.googlecode.eyesfree.brailleback.IMENavigationModeTest.java
/** * Tests the behaviour of the "text and navigation" mode. *//*w w w .j a v a 2 s. c o m*/ public void testTextAndNavigationMode() { 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.ExampleWebView"); when(mSelfBrailleManager.hasContentForNode(compatWrapperForNode(rawNode))).thenReturn(true); mIMENavMode.onActivate(); mIMENavMode.onCreateIME(); verify(mNext).onActivate(); mIMENavMode.onBindInput(); mIMENavMode.onStartInput(ei, false /* restarting */); verify(mSelfBrailleManager, atLeastOnce()).setImeOpen(false); verify(mSelfBrailleManager, never()).setImeOpen(true); mIMENavMode.onStartInputView(ei, false /* restarting */); assertEquals(mBrailleTranslator, mIMENavMode.getBrailleTranslator()); assertNull(mIMENavMode.getDisplayManager()); assertEquals(mFeedbackManager, mIMENavMode.getFeedbackManager()); verify(mSelfBrailleManager, atLeastOnce()).setImeOpen(true); 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_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)); // Nothing above this point should have triggered an action on the // accessibility node. verify(rawNode, never()).performAction(anyInt(), any(Bundle.class)); verifyEventCausesNavigation(BrailleInputEvent.CMD_NAV_ITEM_NEXT, ACTION_NEXT_AT_MOVEMENT_GRANULARITY, MOVEMENT_GRANULARITY_CHARACTER, rawNode, content); verifyEventCausesNavigation(BrailleInputEvent.CMD_NAV_ITEM_PREVIOUS, ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, MOVEMENT_GRANULARITY_CHARACTER, rawNode, content); verifyEventCausesNavigation(BrailleInputEvent.CMD_NAV_LINE_NEXT, ACTION_NEXT_AT_MOVEMENT_GRANULARITY, MOVEMENT_GRANULARITY_LINE, rawNode, content); verifyEventCausesNavigation(BrailleInputEvent.CMD_NAV_LINE_PREVIOUS, ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, MOVEMENT_GRANULARITY_LINE, rawNode, content); Mockito.reset(mSelfBrailleManager); mIMENavMode.onFinishInputView(true); verify(mSelfBrailleManager).setImeOpen(false); mIMENavMode.onFinishInput(); mIMENavMode.onUnbindInput(); mIMENavMode.onDestroyIME(); verify(mSelfBrailleManager, never()).setImeOpen(true); // Deactivate, but make sure it didn't happen too early. verify(mNext, never()).onDeactivate(); mIMENavMode.onDeactivate(); verify(mNext).onDeactivate(); }