List of usage examples for android.view.accessibility AccessibilityNodeInfo isFocused
public boolean isFocused()
From source file:com.googlecode.eyesfree.brailleback.IMENavigationModeTest.java
/** * Tests the behaviour of the "modal editor" mode. *///from w w w . ja va2 s. c om public void testModalEditorMode() { mIMENavMode.onActivate(); verify(mNext).onActivate(); 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_ACCESSIBILITY)).thenReturn(rawNode); when(rawNode.getClassName()).thenReturn(EditText.class.getName()); when(rawNode.isFocused()).thenReturn(true); mIMENavMode.onCreateIME(); mIMENavMode.onBindInput(); mIMENavMode.onStartInput(ei, false /* restarting */); mIMENavMode.onStartInputView(ei, false /* restarting */); verify(mNext, times(1)).onDeactivate(); assertEquals(mBrailleTranslator, mIMENavMode.getBrailleTranslator()); assertEquals(mDisplayManager, 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, never()).onAccessibilityEvent(accessibilityEvent); } finally { accessibilityEvent.recycle(); } AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(); try { mIMENavMode.onInvalidateAccessibilityNode(node); verify(mNext, never()).onInvalidateAccessibilityNode(node); } finally { node.recycle(); } // Move input focus away and back again. when(rawNode.isFocused()).thenReturn(false); accessibilityEvent = AccessibilityEvent.obtain(); accessibilityEvent.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED); try { mIMENavMode.onObserveAccessibilityEvent(accessibilityEvent); verify(mNext, times(2)).onActivate(); when(rawNode.isFocused()).thenReturn(true); mIMENavMode.onObserveAccessibilityEvent(accessibilityEvent); verify(mNext, times(2)).onDeactivate(); } finally { accessibilityEvent.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, never()).onMappedInputEvent(inputEvent, content); verify(mIME).moveCursor(BrailleIME.DIRECTION_FORWARD, AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ACTIVATE_CURRENT, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).sendDefaultAction(); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ROUTE, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).route(0, content); // Finishing and unbinding the input should activate the next nav mode // again. mIMENavMode.onFinishInputView(true); mIMENavMode.onFinishInput(); mIMENavMode.onUnbindInput(); verify(mNext, times(3)).onActivate(); mIMENavMode.onDestroyIME(); // Deactivate, but make sure it didn't happen too early. verify(mNext, times(2)).onDeactivate(); mIMENavMode.onDeactivate(); verify(mNext, times(3)).onDeactivate(); }
From source file:com.googlecode.eyesfree.brailleback.TreeDebugNavigationMode.java
private CharSequence formatNode(AccessibilityNodeInfo node) { StringBuilder sb = new StringBuilder(); sb.append(node.getWindowId());/*from w ww . j av a2s .c om*/ if (node.getClassName() != null) { appendSimpleName(sb, node.getClassName()); } else { sb.append("??"); } if (!node.isVisibleToUser()) { sb.append(":invisible"); } if (node.getText() != null) { sb.append(":"); sb.append(node.getText()); } if (node.getContentDescription() != null) { sb.append(":"); sb.append(node.getContentDescription()); } int actions = node.getActions(); if (actions != 0) { sb.append(":"); if ((actions & AccessibilityNodeInfo.ACTION_FOCUS) != 0) { sb.append("F"); } if ((actions & AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS) != 0) { sb.append("A"); } if ((actions & AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) { sb.append("a"); } if ((actions & AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) != 0) { sb.append("-"); } if ((actions & AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) != 0) { sb.append("+"); } } if (node.isCheckable()) { sb.append(":"); if (node.isChecked()) { sb.append("(X)"); } else { sb.append("( )"); } } if (node.isFocusable()) { sb.append(":focusable"); } if (node.isFocused()) { sb.append(":focused"); } if (node.isSelected()) { sb.append(":selected"); } if (node.isClickable()) { sb.append(":clickable"); } if (node.isLongClickable()) { sb.append(":longClickable"); } if (node.isAccessibilityFocused()) { sb.append(":accessibilityFocused"); } if (!node.isEnabled()) { sb.append(":disabled"); } return sb.toString(); }