List of usage examples for android.view.accessibility AccessibilityNodeInfo getText
public CharSequence getText()
From source file:Main.java
public static void dumpNode(AccessibilityNodeInfo node) { Log.d(LOGTAG, String.format("class: %s; text: %s; content-desc: %s", node.getClassName(), node.getText(), node.getContentDescription())); }
From source file:Main.java
public static void findTextAndClick(AccessibilityService accessibilityService, String text) { AccessibilityNodeInfo accessibilityNodeInfo = accessibilityService.getRootInActiveWindow(); if (accessibilityNodeInfo == null) { return;//from w ww . j av a2s . c om } List<AccessibilityNodeInfo> nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByText(text); if (nodeInfoList != null && !nodeInfoList.isEmpty()) { for (AccessibilityNodeInfo nodeInfo : nodeInfoList) { if (nodeInfo != null && (text.equals(nodeInfo.getText()) || text.equals(nodeInfo.getContentDescription()))) { performClick(nodeInfo); break; } } } }
From source file:com.android.switchaccess.test.ShadowAccessibilityNodeInfoCompat.java
@Implementation public String getText() { final AccessibilityNodeInfo info = (AccessibilityNodeInfo) mRealObject.getInfo(); return (String) info.getText(); }
From source file:com.google.android.apps.common.testing.accessibility.framework.ClickableSpanInfoCheck.java
@Override public List<AccessibilityInfoCheckResult> runCheckOnInfo(AccessibilityNodeInfo info, Context context, Bundle metadata) {/*from w w w .ja va2 s .c o m*/ List<AccessibilityInfoCheckResult> results = new ArrayList<AccessibilityInfoCheckResult>(1); AccessibilityNodeInfoCompat compatInfo = new AccessibilityNodeInfoCompat(info); if (AccessibilityNodeInfoUtils.nodeMatchesAnyClassByType(context, compatInfo, TextView.class)) { if (info.getText() instanceof Spanned) { Spanned text = (Spanned) info.getText(); ClickableSpan[] clickableSpans = text.getSpans(0, text.length(), ClickableSpan.class); for (ClickableSpan clickableSpan : clickableSpans) { if (clickableSpan instanceof URLSpan) { String url = ((URLSpan) clickableSpan).getURL(); if (url == null) { results.add(new AccessibilityInfoCheckResult(this.getClass(), AccessibilityCheckResultType.ERROR, "URLSpan has null URL", info)); } else { Uri uri = Uri.parse(url); if (uri.isRelative()) { // Relative URIs cannot be resolved. results.add(new AccessibilityInfoCheckResult(this.getClass(), AccessibilityCheckResultType.ERROR, "URLSpan should not contain relative links", info)); } } } else { // Non-URLSpan ClickableSpan results.add(new AccessibilityInfoCheckResult(this.getClass(), AccessibilityCheckResultType.ERROR, "URLSpan should be used in place of ClickableSpan for improved accessibility", info)); } } } } else { results.add(new AccessibilityInfoCheckResult(this.getClass(), AccessibilityCheckResultType.NOT_RUN, "View must be a TextView", info)); } return results; }
From source file:com.linroid.pushapp.service.ApkAutoInstallService.java
/** * ?//from w ww . ja va 2 s . co m * * @param info * @param text * @param isGlobalAction ? * @return ?? */ private boolean performEventAction(AccessibilityNodeInfo info, String text, boolean isGlobalAction) { if (info == null) { return false; } List<AccessibilityNodeInfo> nodes = info.findAccessibilityNodeInfosByText(text); if (nodes != null && nodes.size() > 0) { for (AccessibilityNodeInfo nodeInfo : nodes) { String nodeText = nodeInfo.getText() == null ? null : nodeInfo.getText().toString(); if (text.equalsIgnoreCase(nodeText)) { if (isGlobalAction) { // performGlobalAction(GLOBAL_ACTION_BACK); } else { performClick(nodeInfo); } return true; } nodeInfo.recycle(); } } return false; }
From source file:com.linroid.pushapp.service.ApkAutoInstallService.java
/** * ?AccessibilityNodeInfo /*from w ww. j ava 2 s. c om*/ * * @param event * @param text * @return */ private AccessibilityNodeInfo getAccessibilityNodeInfoByText(AccessibilityEvent event, String text) { List<AccessibilityNodeInfo> nodes = null; // try-catch? event.getSource NullPointerException try { if (event != null && event.getSource() != null) { nodes = event.getSource().findAccessibilityNodeInfosByText(text); } } catch (Exception e) { } // ?else??? if (nodes == null || nodes.size() == 0) { AccessibilityNodeInfo info = getRootInActiveWindow(); if (info != null) { nodes = info.findAccessibilityNodeInfosByText(text); } } if (nodes != null && nodes.size() > 0) { for (AccessibilityNodeInfo nodeInfo : nodes) { String nodeText = nodeInfo.getText() == null ? BuildConfig.VERSION_NAME : nodeInfo.getText().toString(); //nodeInfo.getClassName().equals(className) && if (nodeText.equalsIgnoreCase(text)) { return nodeInfo; } nodeInfo.recycle(); } } return null; }
From source file:com.googlecode.eyesfree.brailleback.TreeDebugNavigationMode.java
private CharSequence formatNode(AccessibilityNodeInfo node) { StringBuilder sb = new StringBuilder(); sb.append(node.getWindowId());/*from ww w . j av a 2 s . com*/ 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(); }
From source file:com.linroid.pushapp.service.ApkAutoInstallService.java
/** * // w w w.j ava2 s.c om * * @param event */ private void onInstallFail(AccessibilityEvent event) { Timber.e(""); performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK); // sInstallList prepare ??? if (sInstallList != null && sInstallList.size() > 0) { AccessibilityNodeInfo validInfo = getValidAccessibilityNodeInfo(event, sInstallList); if (validInfo != null && processApplicationUninstalled(event) && validInfo.getText() != null) { String label = validInfo.getText().toString(); removePackFromListByAppName(sInstallList, label); for (int i = 0; i < sInstallList.size(); i++) { int key = sInstallList.keyAt(i); Pack pack = sInstallList.get(key); if (pack.getAppName().equals(label)) { addPrepareInstallApplication(pack); sInstallList.remove(key); startActivity(IntentUtil.uninstallApp(pack.getPath())); break; } } validInfo.recycle(); } } }
From source file:com.linroid.pushapp.service.ApkAutoInstallService.java
/** * ??/*from w ww . j a v a 2s . com*/ * * @param event */ private void onApplicationUninstalled(AccessibilityEvent event) { Timber.d("??"); // ??? handler.removeCallbacks(handleUninstallTimeout); AccessibilityNodeInfo validInfo = getValidAccessibilityNodeInfo(event, sUninstallList); String label = null; if (validInfo != null && processApplicationUninstalled(event) && sUninstallList != null && validInfo.getText() != null) { label = validInfo.getText().toString(); removePackFromListByAppName(sUninstallList, label); validInfo.recycle(); } // ???Apk processPrepareInstall(label); }
From source file:com.linroid.pushapp.service.ApkAutoInstallService.java
/** * ?//from w w w . j ava2s. co m * * @param event */ private void onApplicationInstalled(AccessibilityEvent event) { Timber.d("?"); // ?? handler.removeCallbacks(handleInstallTimeout); AccessibilityNodeInfo validInfo = getValidAccessibilityNodeInfo(event, sInstallList); if (validInfo != null) { if (autoOpen.getValue()) { boolean openSuccess = openAfterInstalled(event); Timber.d("?%s", openSuccess); } String label = validInfo.getText().toString(); removePackFromListByAppName(sInstallList, label, true); validInfo.recycle(); } }