Java Code Examples for androidx.core.view.accessibility.AccessibilityNodeInfoCompat#getWindowId()

The following examples show how to use androidx.core.view.accessibility.AccessibilityNodeInfoCompat#getWindowId() . 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: GlobalVariables.java    From talkback with Apache License 2.0 5 votes vote down vote up
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 2
Source File: AccessibilityFocusActionHistory.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Registers the action information. Called immediately after an accessibility focus action is
 * performed.
 *
 * <p><strong>Note:</strong> Caller is responsible for recycling the {@code node}.
 *
 * @param node Node being accessibility focused.
 * @param extraData Extra information of the action.
 * @param actionTime {@link SystemClock#uptimeMillis()} right before performing focus action.
 * @param currentScreenState Current {@link ScreenState}.
 */
public void onAccessibilityFocusAction(
    AccessibilityNodeInfoCompat node,
    FocusActionInfo extraData,
    long actionTime,
    @Nullable ScreenState currentScreenState) {
  // FocusActionRecord handles making a copy of 'node'. We don't nee to call obtain() here.
  FocusActionRecord record = new FocusActionRecord(node, extraData, actionTime);

  // Add to the record queue.
  focusActionRecordList.offer(record);
  if (focusActionRecordList.size() > MAXIMUM_RECORD_QUEUE_SIZE) {
    // Poll and recycle the eldest order if the queue grows up its maximum size.
    focusActionRecordList.pollFirst().recycle();
  }

  final int windowId = node.getWindowId();
  final CharSequence windowTitle =
      (currentScreenState == null) ? null : currentScreenState.getWindowTitle(windowId);
  // Add to the window record map.
  windowIdTitlePairToFocusActionRecordMap.put(
      Pair.create(windowId, windowTitle), FocusActionRecord.copy(record));

  // Update the last editable node focus action.
  if (node.isEditable() || (Role.getRole(node) == Role.ROLE_EDIT_TEXT)) {
    if (lastEditableFocusActionRecord != null) {
      lastEditableFocusActionRecord.recycle();
    }
    lastEditableFocusActionRecord = FocusActionRecord.copy(record);
  }
}
 
Example 3
Source File: FocusProcessorForScreenStateChange.java    From talkback with Apache License 2.0 5 votes vote down vote up
private boolean hasValidAccessibilityFocusInWindow(AccessibilityWindowInfo window) {
  AccessibilityNodeInfoCompat currentFocus = null;
  try {
    currentFocus =
        accessibilityFocusMonitor.getAccessibilityFocus(/* useInputFocusIfEmpty= */ false);
    return (currentFocus != null)
        && AccessibilityNodeInfoUtils.isVisible(currentFocus)
        && (currentFocus.getWindowId() == window.getId());
  } finally {
    AccessibilityNodeInfoUtils.recycleNodes(currentFocus);
  }
}
 
Example 4
Source File: ActorStateWritable.java    From talkback with Apache License 2.0 5 votes vote down vote up
/** Stores information about completed input-focus action. Caller must recycle node. */
public void setInputFocus(AccessibilityNodeInfoCompat node) {
  long currentTime = SystemClock.uptimeMillis();
  lastWindowId = node.getWindowId();
  lastWindowIdUptimeMs = currentTime;
  if (inputFocusActionRecord != null) {
    AccessibilityNodeInfoUtils.recycleNodes(inputFocusActionRecord.inputFocusedNode);
  }
  inputFocusActionRecord =
      new InputFocusActionRecord(AccessibilityNodeInfoUtils.obtain(node), currentTime);
}