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);
}
}
Aggregations