Example usage for android.view.accessibility AccessibilityNodeInfo getBoundsInScreen

List of usage examples for android.view.accessibility AccessibilityNodeInfo getBoundsInScreen

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityNodeInfo getBoundsInScreen.

Prototype

public void getBoundsInScreen(Rect outBounds) 

Source Link

Document

Gets the node bounds in screen coordinates.

Usage

From source file:Main.java

public static Rect getBoundsInScreen(AccessibilityNodeInfo nodeInfo) {
    Rect rect = new Rect();
    nodeInfo.getBoundsInScreen(rect);
    return rect;//w w  w .j  a va2 s  .c om
}

From source file:Main.java

/**
 * Returns the node's bounds clipped to the size of the display
 *
 * @param node/*from w w w.j  a  v  a2  s.  com*/
 * @param width pixel width of the display
 * @param height pixel height of the display
 * @return null if node is null, else a Rect containing visible bounds
 */
public static Rect getVisibleBoundsInScreen(AccessibilityNodeInfo node, int width, int height) {
    if (node == null) {
        return null;
    }
    // targeted node's bounds
    Rect nodeRect = new Rect();
    node.getBoundsInScreen(nodeRect);

    Rect displayRect = new Rect();
    displayRect.top = 0;
    displayRect.left = 0;
    displayRect.right = width;
    displayRect.bottom = height;

    nodeRect.intersect(displayRect);
    return nodeRect;
}

From source file:Main.java

/**
 * Returns the node's bounds clipped to the size of the display
 *
 * @param node//  w  w w . j a v  a  2s.  co  m
 * @param width  pixel width of the display
 * @param height pixel height of the display
 * @return null if node is null, else a Rect containing visible bounds
 */
public static Rect getVisibleBoundsInScreen(AccessibilityNodeInfo node, int width, int height) {
    if (node == null) {
        return null;
    }
    // targeted node's bounds
    Rect nodeRect = new Rect();
    node.getBoundsInScreen(nodeRect);

    Rect displayRect = new Rect();
    displayRect.top = 0;
    displayRect.left = 0;
    displayRect.right = width;
    displayRect.bottom = height;
    boolean intersect = nodeRect.intersect(displayRect);
    return nodeRect;
}

From source file:Main.java

/**
 * Returns the node's bounds clipped to the size of the display
 *
 * @param node//from ww  w .  j  a va2 s  .co  m
 * @param width pixel width of the display
 * @param height pixel height of the display
 * @return null if node is null, else a Rect containing visible bounds
 */
static Rect getVisibleBoundsInScreen(AccessibilityNodeInfo node, int width, int height) {
    if (node == null) {
        return null;
    }
    // targeted node's bounds
    Rect nodeRect = new Rect();
    node.getBoundsInScreen(nodeRect);

    Rect displayRect = new Rect();
    displayRect.top = 0;
    displayRect.left = 0;
    displayRect.right = width;
    displayRect.bottom = height;

    final boolean intersect = nodeRect.intersect(displayRect);
    return nodeRect;
}

From source file:Main.java

/**
 * Returns the node's bounds clipped to the size of the display
 *
 * @param node//  www.ja v a 2s .  co m
 * @param width pixel width of the display
 * @param height pixel height of the display
 * @return null if node is null, else a Rect containing visible bounds
 */
static Rect getVisibleBoundsInScreen(AccessibilityNodeInfo node, int width, int height) {
    if (node == null) {
        return null;
    }
    // targeted node's bounds
    Rect nodeRect = new Rect();
    node.getBoundsInScreen(nodeRect);

    Rect displayRect = new Rect();
    displayRect.top = 0;
    displayRect.left = 0;
    displayRect.right = width;
    displayRect.bottom = height;

    nodeRect.intersect(displayRect);
    return nodeRect;
}

From source file:com.google.android.apps.common.testing.accessibility.framework.ContrastInfoCheck.java

@Override
public List<AccessibilityInfoCheckResult> runCheckOnInfoHierarchy(AccessibilityNodeInfo root, Context context,
        Bundle metadata) {// w  ww. jav a  2  s.  c  o m
    List<AccessibilityInfoCheckResult> results = new ArrayList<AccessibilityInfoCheckResult>();
    Bitmap screenCapture = null;
    if (metadata != null) {
        screenCapture = metadata.getParcelable(AccessibilityCheckMetadata.METADATA_KEY_SCREEN_CAPTURE_BITMAP);
    }

    if (screenCapture == null) {
        results.add(new AccessibilityInfoCheckResult(getClass(), AccessibilityCheckResultType.NOT_RUN,
                "This check did not execute because it was unable to obtain screen capture data.", null));
        return results;
    }

    AccessibilityNodeInfoCompat rootCompat = new AccessibilityNodeInfoCompat(root);
    List<AccessibilityNodeInfoCompat> candidates = AccessibilityNodeInfoUtils.searchAllFromBfs(context,
            rootCompat, FILTER_CONTRAST_EVAL_ELIGIBLE);
    List<AccessibilityNodeInfoCompat> nonCandidates = AccessibilityNodeInfoUtils.searchAllFromBfs(context,
            rootCompat, FILTER_CONTRAST_EVAL_INELIGIBLE);

    // Ineligible nodes all receive NOT_RUN results
    for (AccessibilityNodeInfoCompat nonCandidate : nonCandidates) {
        AccessibilityNodeInfo unwrappedNonCandidate = (AccessibilityNodeInfo) nonCandidate.getInfo();
        results.add(new AccessibilityInfoCheckResult(getClass(), AccessibilityCheckResultType.NOT_RUN,
                "This view's contrast was not evaluated because it contains neither text nor an image.",
                unwrappedNonCandidate));
    }

    Rect screenCaptureBounds = new Rect(0, 0, screenCapture.getWidth() - 1, screenCapture.getHeight() - 1);
    for (AccessibilityNodeInfoCompat candidate : candidates) {
        AccessibilityNodeInfo unwrappedCandidate = (AccessibilityNodeInfo) candidate.getInfo();
        Rect viewBounds = new Rect();
        unwrappedCandidate.getBoundsInScreen(viewBounds);
        if (!screenCaptureBounds.contains(viewBounds)) {
            // If an off-screen view reports itself as visible, we shouldn't evaluate it.
            String message = String.format("View bounds %1$s were not within the screen capture bounds %2$s.",
                    viewBounds, screenCaptureBounds);
            results.add(new AccessibilityInfoCheckResult(getClass(), AccessibilityCheckResultType.NOT_RUN,
                    message, unwrappedCandidate));
            continue;
        }
        ContrastSwatch candidateSwatch = new ContrastSwatch(
                ScreenshotUtils.cropBitmap(screenCapture, viewBounds), viewBounds,
                unwrappedCandidate.getViewIdResourceName());
        double contrastRatio = candidateSwatch.getContrastRatio();
        if (AccessibilityNodeInfoUtils.nodeMatchesAnyClassByType(context, candidate, TextView.class)) {
            if (contrastRatio < ContrastUtils.CONTRAST_RATIO_WCAG_LARGE_TEXT) {
                String message = String.format(
                        "This view's foreground to background contrast ratio " + "(%1$.2f) is not sufficient.",
                        contrastRatio);
                results.add(new AccessibilityInfoCheckResult(getClass(), AccessibilityCheckResultType.ERROR,
                        message, unwrappedCandidate));
            } else if (contrastRatio < ContrastUtils.CONTRAST_RATIO_WCAG_NORMAL_TEXT) {
                String message = String.format(
                        "This view's foreground to background contrast ratio "
                                + "(%1$.2f) may not be sufficient unless it contains large text.",
                        contrastRatio);
                results.add(new AccessibilityInfoCheckResult(getClass(), AccessibilityCheckResultType.WARNING,
                        message, unwrappedCandidate));
            }
        } else if (AccessibilityNodeInfoUtils.nodeMatchesAnyClassByType(context, candidate, ImageView.class)) {
            // Lower confidence in heuristics for ImageViews, so we'll report only warnings and use
            // the more permissive threshold ratio since images are generally large.
            if (contrastRatio < ContrastUtils.CONTRAST_RATIO_WCAG_LARGE_TEXT) {
                String message = String.format("This image's foreground to background contrast ratio "
                        + "(%1$.2f) is not sufficient.  NOTE: This test is experimental and may be less "
                        + "accurate for some images.", contrastRatio);
                results.add(new AccessibilityInfoCheckResult(getClass(), AccessibilityCheckResultType.WARNING,
                        message, unwrappedCandidate));
            }
        }
        candidateSwatch.recycle();
    }

    AccessibilityNodeInfoUtils.recycleNodes(candidates);
    AccessibilityNodeInfoUtils.recycleNodes(nonCandidates);
    return results;
}

From source file:com.android.switchaccess.test.ShadowAccessibilityNodeInfoCompat.java

@Implementation
public void getBoundsInScreen(Rect outBounds) {
    final AccessibilityNodeInfo info = (AccessibilityNodeInfo) mRealObject.getInfo();
    info.getBoundsInScreen(outBounds);
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

private void finishSignIn() {
    AccessibilityNodeInfo mAccessibilityNodeInfo = this.getRootInActiveWindow();
    if (mAccessibilityNodeInfo == null) {
        return;//from   w w  w  .  j  ava  2  s.c  o  m
    }
    AccessibilityNodeInfo mNodeInfos = recurseFindByText("?", mAccessibilityNodeInfo);//??? 
    if (mNodeInfos == null) {
        backHomePager();
        handleHomeInsensitiveCallback(tag_callback_time);
        return;
    }
    AccessibilityNodeInfo mInfo = mNodeInfos;
    Rect mRect = new Rect();
    mInfo.getBoundsInScreen(mRect);

    doShellCmdInputTap(mRect.centerX(), mRect.centerY());//adb? ??root

    backHomePager();
}

From source file:com.google.android.apps.common.testing.accessibility.framework.TouchTargetSizeInfoCheck.java

@Override
public List<AccessibilityInfoCheckResult> runCheckOnInfo(AccessibilityNodeInfo info, Context context,
        Bundle metadata) {//from w ww.j  ava 2 s .com
    ArrayList<AccessibilityInfoCheckResult> results = new ArrayList<AccessibilityInfoCheckResult>();

    // TODO(sjrush): Have all info checks use AccessibilityNodeInfoCompat
    AccessibilityNodeInfoCompat infoCompat = new AccessibilityNodeInfoCompat(info);
    if (!(AccessibilityNodeInfoUtils.isClickable(infoCompat)
            || AccessibilityNodeInfoUtils.isLongClickable(infoCompat))) {
        results.add(new AccessibilityInfoCheckResult(this.getClass(), AccessibilityCheckResultType.NOT_RUN,
                "View is not clickable", info));
        return results;
    }
    if (context == null) {
        results.add(new AccessibilityInfoCheckResult(this.getClass(), AccessibilityCheckResultType.NOT_RUN,
                "This check needs a context", info));
        return results;
    }

    // TODO(sjrush): Find a way to make this check work without a context
    // dp calculation is pixels/density
    float density = context.getResources().getDisplayMetrics().density;
    Rect bounds = new Rect();
    info.getBoundsInScreen(bounds);
    float targetHeight = bounds.height() / density;
    float targetWidth = bounds.width() / density;
    if (targetHeight < TOUCH_TARGET_MIN_HEIGHT || targetWidth < TOUCH_TARGET_MIN_WIDTH) {
        String message = String.format(Locale.US,
                "View is too small of a touch target. Minimum touch target size is %dx%ddp. "
                        + "Actual size is %.1fx%.1fdp (screen density is %.1f).",
                TOUCH_TARGET_MIN_WIDTH, TOUCH_TARGET_MIN_HEIGHT, targetWidth, targetHeight, density);
        results.add(new AccessibilityInfoCheckResult(this.getClass(), AccessibilityCheckResultType.ERROR,
                message, info));
    }
    return results;
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

private void handleIt(AccessibilityNodeInfo info) {

    if (!isCut) {
        isCut = true;//from  w  w  w .ja va2s  .c o  m
        //            Toast.makeText(App.mContext, "??", Toast.LENGTH_SHORT).show();
    }
    Rect mRect = new Rect();
    info.getBoundsInScreen(mRect);
    ShellUtils.CommandResult mCommandResult = doShellCmdInputTap(mRect.centerX(), mRect.centerY());
    if (mCommandResult.result == 0) {
        STATE = STATE_CHECKED_IN;
    }

}