android.view.accessibility.AccessibilityNodeInfo#ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY源码实例Demo

下面列出了android.view.accessibility.AccessibilityNodeInfo#ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: litho   文件: ComponentHost.java
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
  // The view framework requires that a contentDescription be set for the
  // getIterableTextForAccessibility method to work.  If one isn't set, all text granularity
  // actions will be ignored.
  if (action == AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY
      || action == AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY) {
    CharSequence contentDesc = null;
    if (!TextUtils.isEmpty(getContentDescription())) {
      contentDesc = getContentDescription();
    } else if (!getContentDescriptions().isEmpty()) {
      contentDesc = TextUtils.join(", ", getContentDescriptions());
    } else if (!getTextContent().getTextItems().isEmpty()) {
      contentDesc = TextUtils.join(", ", getTextContent().getTextItems());
    }

    if (contentDesc == null) {
      return false;
    }

    mContentDescription = contentDesc;
    super.setContentDescription(mContentDescription);
  }

  return super.performAccessibilityAction(action, arguments);
}
 
@Override
public boolean supportsAccessibilityAction(int action) {
    if (action == AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY ||
            action == AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY ||
            action == AccessibilityNodeInfo.ACTION_NEXT_HTML_ELEMENT ||
            action == AccessibilityNodeInfo.ACTION_PREVIOUS_HTML_ELEMENT ||
            action == AccessibilityNodeInfo.ACTION_CLICK) {
        return true;
    }

    return false;
}
 
@Override
public boolean supportsAccessibilityAction(int action) {
    if (action == AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY ||
            action == AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY ||
            action == AccessibilityNodeInfo.ACTION_NEXT_HTML_ELEMENT ||
            action == AccessibilityNodeInfo.ACTION_PREVIOUS_HTML_ELEMENT ||
            action == AccessibilityNodeInfo.ACTION_CLICK) {
        return true;
    }

    return false;
}
 
源代码4 项目: talkback   文件: SwitchAccessAction.java
@Override
public ActionResult execute(AccessibilityService service) {
  previousSelectionStart = Math.max(0, nodeCompat.getTextSelectionStart());
  previousSelectionEnd = Math.max(0, nodeCompat.getTextSelectionEnd());
  previousTextContent = TextEditingUtils.getNonDefaultTextForNode(nodeCompat);

  switch (getId()) {
    case TextEditingUtils.ACTION_DELETE_TEXT:
      // Delete text with granularity according to args.
      return new ActionResult(TextEditingUtils.deleteTextWithGranularity(nodeCompat, args));
    case AccessibilityNodeInfo.ACTION_SET_SELECTION:
      // Select text with granularity according to args.
      return new ActionResult(TextEditingUtils.selectTextWithGranularity(nodeCompat, args));
    case AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY:
    case AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY:
      if ((args.getInt(ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT)
          == TextEditingUtils.ACTION_GRANULARITY_SENTENCE)) {
        MovementDirection movementDirection =
            (getId() == AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY)
                ? TextEditingUtils.MovementDirection.DIRECTION_NEXT
                : TextEditingUtils.MovementDirection.DIRECTION_PREVIOUS;
        // Sentence granularity doesn't have built-in support, so move cursor by sentence
        // granularity.
        return new ActionResult(
            TextEditingUtils.moveCursorBySentenceGranularity(nodeCompat, movementDirection));
      } else {
        // Perform the original granular movement
        return new ActionResult(
            PerformActionUtils.performAction(nodeCompat, getId(), args, null /* EventId */));
      }
    case TextEditingUtils.ACTION_UNDO:
      // Undo the previous action on this node's timeline.
      return new ActionResult(TextEditingUtils.performUndo(service, nodeCompat));
    case TextEditingUtils.ACTION_REDO:
      // Redo the next action on this node's timeline.
      return new ActionResult(TextEditingUtils.performRedo(service, nodeCompat));
    case AccessibilityNodeInfo.ACTION_SET_TEXT:
      // Set the text and restore the cursor position.
      return new ActionResult(TextEditingUtils.setText(nodeCompat, args));
    case AccessibilityNodeInfo.ACTION_COPY:
    case AccessibilityNodeInfo.ACTION_CUT:
      // For copy and cut actions, select all text as these actions only act on the currently
      // selected text.
      if ((args.getInt(ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT)
              == TextEditingUtils.ACTION_GRANULARITY_ALL)
          && !TextEditingUtils.selectTextWithGranularity(nodeCompat, args)) {
        return new ActionResult(false);
      } else {
        return new ActionResult(
            PerformActionUtils.performAction(nodeCompat, getId(), args, null /* EventId */));
      }
    case AccessibilityNodeInfo.ACTION_CLICK:
      if (nodeCompat.isClickable() && attemptToClickUrl(service)) {
        return new ActionResult(true /* isSuccessful */);
      }
      // Fall-through if there were no clickable urls.
    default:
      // Perform the original user-visible action.
      return new ActionResult(
          PerformActionUtils.performAction(nodeCompat, getId(), args, null /* EventId */));
  }
}