Search in sources :

Example 1 with AccessibilityInteractionClient

use of android.view.accessibility.AccessibilityInteractionClient in project android_frameworks_base by ParanoidAndroid.

the class AccessibilityManagerService method getAccessibilityFocusBoundsInActiveWindow.

/**
     * Gets the bounds of the accessibility focus in the active window.
     *
     * @param outBounds The output to which to write the focus bounds.
     * @return Whether accessibility focus was found and the bounds are populated.
     */
// TODO: (multi-display) Make sure this works for multiple displays. 
boolean getAccessibilityFocusBoundsInActiveWindow(Rect outBounds) {
    // Instead of keeping track of accessibility focus events per
    // window to be able to find the focus in the active window,
    // we take a stateless approach and look it up. This is fine
    // since we do this only when the user clicks/long presses.
    Service service = getQueryBridge();
    final int connectionId = service.mId;
    AccessibilityInteractionClient client = AccessibilityInteractionClient.getInstance();
    client.addConnection(connectionId, service);
    try {
        AccessibilityNodeInfo root = AccessibilityInteractionClient.getInstance().getRootInActiveWindow(connectionId);
        if (root == null) {
            return false;
        }
        AccessibilityNodeInfo focus = root.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY);
        if (focus == null) {
            return false;
        }
        focus.getBoundsInScreen(outBounds);
        MagnificationSpec spec = service.getCompatibleMagnificationSpec(focus.getWindowId());
        if (spec != null && !spec.isNop()) {
            outBounds.offset((int) -spec.offsetX, (int) -spec.offsetY);
            outBounds.scale(1 / spec.scale);
        }
        // Clip to the window rectangle.
        Rect windowBounds = mTempRect;
        getActiveWindowBounds(windowBounds);
        outBounds.intersect(windowBounds);
        // Clip to the screen rectangle.
        mDefaultDisplay.getRealSize(mTempPoint);
        outBounds.intersect(0, 0, mTempPoint.x, mTempPoint.y);
        return true;
    } finally {
        client.removeConnection(connectionId);
    }
}
Also used : MagnificationSpec(android.view.MagnificationSpec) Rect(android.graphics.Rect) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) AccessibilityService(android.accessibilityservice.AccessibilityService) IStatusBarService(com.android.internal.statusbar.IStatusBarService) Point(android.graphics.Point) AccessibilityInteractionClient(android.view.accessibility.AccessibilityInteractionClient)

Aggregations

AccessibilityService (android.accessibilityservice.AccessibilityService)1 Point (android.graphics.Point)1 Rect (android.graphics.Rect)1 MagnificationSpec (android.view.MagnificationSpec)1 AccessibilityInteractionClient (android.view.accessibility.AccessibilityInteractionClient)1 AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)1 IStatusBarService (com.android.internal.statusbar.IStatusBarService)1