下面列出了android.support.v4.view.accessibility.AccessibilityNodeInfoCompat#ACTION_NEXT_HTML_ELEMENT 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT];
while (true) {
int read = in.read(buffer);
if (read != -1) {
out.write(buffer, 0, read);
} else {
return;
}
}
}
@Nullable
public static String getActions(View view) {
AccessibilityNodeInfoCompat node = createNodeInfoFromView(view);
try {
final StringBuilder actionLabels = new StringBuilder();
final String separator = ", ";
for (AccessibilityActionCompat action : node.getActionList()) {
if (actionLabels.length() > 0) {
actionLabels.append(separator);
}
switch (action.getId()) {
case AccessibilityNodeInfoCompat.ACTION_FOCUS:
actionLabels.append("focus");
break;
case AccessibilityNodeInfoCompat.ACTION_CLEAR_FOCUS:
actionLabels.append("clear-focus");
break;
case AccessibilityNodeInfoCompat.ACTION_SELECT:
actionLabels.append("select");
break;
case AccessibilityNodeInfoCompat.ACTION_CLEAR_SELECTION:
actionLabels.append("clear-selection");
break;
case AccessibilityNodeInfoCompat.ACTION_CLICK:
actionLabels.append("click");
break;
case AccessibilityNodeInfoCompat.ACTION_LONG_CLICK:
actionLabels.append("long-click");
break;
case AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS:
actionLabels.append("accessibility-focus");
break;
case AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
actionLabels.append("clear-accessibility-focus");
break;
case AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY:
actionLabels.append("next-at-movement-granularity");
break;
case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY:
actionLabels.append("previous-at-movement-granularity");
break;
case AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT:
actionLabels.append("next-html-element");
break;
case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_HTML_ELEMENT:
actionLabels.append("previous-html-element");
break;
case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD:
actionLabels.append("scroll-forward");
break;
case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD:
actionLabels.append("scroll-backward");
break;
case AccessibilityNodeInfoCompat.ACTION_CUT:
actionLabels.append("cut");
break;
case AccessibilityNodeInfoCompat.ACTION_COPY:
actionLabels.append("copy");
break;
case AccessibilityNodeInfoCompat.ACTION_PASTE:
actionLabels.append("paste");
break;
case AccessibilityNodeInfoCompat.ACTION_SET_SELECTION:
actionLabels.append("set-selection");
break;
default:
CharSequence label = action.getLabel();
if (label != null) {
actionLabels.append(label);
} else {
actionLabels.append("unknown");
}
break;
}
}
return actionLabels.length() > 0 ? actionLabels.toString() : null;
} finally {
node.recycle();
}
}
/**
* Sends an instruction to ChromeVox to read the specified HTML element in
* the given direction within a node.
* <p>
* WARNING: Calling this method with a source node of
* {@link android.webkit.WebView} has the side effect of closing the IME
* if currently displayed.
*
* @param node The node containing web content with ChromeVox to which the
* message should be sent
* @param direction {@link #DIRECTION_FORWARD} or
* {@link #DIRECTION_BACKWARD}
* @param htmlElement The HTML tag to send
* @return {@code true} if the action was performed, {@code false}
* otherwise.
*/
public static boolean performNavigationToHtmlElementAction(
AccessibilityNodeInfoCompat node, int direction, String htmlElement) {
final int action = (direction == DIRECTION_FORWARD)
? AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT
: AccessibilityNodeInfoCompat.ACTION_PREVIOUS_HTML_ELEMENT;
final Bundle args = new Bundle();
args.putString(
AccessibilityNodeInfoCompat.ACTION_ARGUMENT_HTML_ELEMENT_STRING, htmlElement);
return node.performAction(action, args);
}
/**
* Sends an instruction to ChromeVox to navigate by DOM object in
* the given direction within a node.
*
* @param node The node containing web content with ChromeVox to which the
* message should be sent
* @param direction {@link #DIRECTION_FORWARD} or
* {@link #DIRECTION_BACKWARD}
* @return {@code true} if the action was performed, {@code false}
* otherwise.
*/
public static boolean performNavigationByDOMObject(
AccessibilityNodeInfoCompat node, int direction) {
final int action = (direction == DIRECTION_FORWARD)
? AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT
: AccessibilityNodeInfoCompat.ACTION_PREVIOUS_HTML_ELEMENT;
return node.performAction(action);
}