Search in sources :

Example 21 with MagnificationSpec

use of android.view.MagnificationSpec in project platform_frameworks_base by android.

the class MagnificationController method resetLocked.

private boolean resetLocked(boolean animate) {
    if (!mRegistered) {
        return false;
    }
    final MagnificationSpec spec = mCurrentMagnificationSpec;
    final boolean changed = !spec.isNop();
    if (changed) {
        spec.clear();
        onMagnificationChangedLocked();
    }
    mIdOfLastServiceToMagnify = INVALID_ID;
    mSpecAnimationBridge.updateSentSpec(spec, animate);
    return changed;
}
Also used : MagnificationSpec(android.view.MagnificationSpec)

Example 22 with MagnificationSpec

use of android.view.MagnificationSpec in project platform_frameworks_base by android.

the class MagnificationController method updateMagnificationSpecLocked.

/**
     * Updates the current magnification spec.
     *
     * @param scale the magnification scale
     * @param centerX the unscaled, screen-relative X coordinate of the center
     *                of the viewport, or {@link Float#NaN} to leave unchanged
     * @param centerY the unscaled, screen-relative Y coordinate of the center
     *                of the viewport, or {@link Float#NaN} to leave unchanged
     * @return {@code true} if the magnification spec changed or {@code false}
     *         otherwise
     */
private boolean updateMagnificationSpecLocked(float scale, float centerX, float centerY) {
    // Handle defaults.
    if (Float.isNaN(centerX)) {
        centerX = getCenterX();
    }
    if (Float.isNaN(centerY)) {
        centerY = getCenterY();
    }
    if (Float.isNaN(scale)) {
        scale = getScale();
    }
    // Ensure requested center is within the magnification region.
    if (!magnificationRegionContains(centerX, centerY)) {
        return false;
    }
    // Compute changes.
    final MagnificationSpec currSpec = mCurrentMagnificationSpec;
    boolean changed = false;
    final float normScale = MathUtils.constrain(scale, MIN_SCALE, MAX_SCALE);
    if (Float.compare(currSpec.scale, normScale) != 0) {
        currSpec.scale = normScale;
        changed = true;
    }
    final float nonNormOffsetX = mMagnificationBounds.width() / 2.0f + mMagnificationBounds.left - centerX * scale;
    final float offsetX = MathUtils.constrain(nonNormOffsetX, getMinOffsetXLocked(), 0);
    if (Float.compare(currSpec.offsetX, offsetX) != 0) {
        currSpec.offsetX = offsetX;
        changed = true;
    }
    final float nonNormOffsetY = mMagnificationBounds.height() / 2.0f + mMagnificationBounds.top - centerY * scale;
    final float offsetY = MathUtils.constrain(nonNormOffsetY, getMinOffsetYLocked(), 0);
    if (Float.compare(currSpec.offsetY, offsetY) != 0) {
        currSpec.offsetY = offsetY;
        changed = true;
    }
    if (changed) {
        onMagnificationChangedLocked();
    }
    return changed;
}
Also used : MagnificationSpec(android.view.MagnificationSpec)

Example 23 with MagnificationSpec

use of android.view.MagnificationSpec in project platform_frameworks_base by android.

the class MagnificationController method onMagnificationRegionChanged.

/**
     * Update our copy of the current magnification region
     *
     * @param magnified the magnified region
     * @param updateSpec {@code true} to update the scale and center based on
     *                   the region bounds, {@code false} to leave them as-is
     */
private void onMagnificationRegionChanged(Region magnified, boolean updateSpec) {
    synchronized (mLock) {
        if (!mRegistered) {
            // Don't update if we've unregistered
            return;
        }
        boolean magnificationChanged = false;
        boolean boundsChanged = false;
        if (!mMagnificationRegion.equals(magnified)) {
            mMagnificationRegion.set(magnified);
            mMagnificationRegion.getBounds(mMagnificationBounds);
            boundsChanged = true;
        }
        if (updateSpec) {
            final MagnificationSpec sentSpec = mSpecAnimationBridge.mSentMagnificationSpec;
            final float scale = sentSpec.scale;
            final float offsetX = sentSpec.offsetX;
            final float offsetY = sentSpec.offsetY;
            // Compute the new center and update spec as needed.
            final float centerX = (mMagnificationBounds.width() / 2.0f + mMagnificationBounds.left - offsetX) / scale;
            final float centerY = (mMagnificationBounds.height() / 2.0f + mMagnificationBounds.top - offsetY) / scale;
            magnificationChanged = setScaleAndCenterLocked(scale, centerX, centerY, false, INVALID_ID);
        }
        // If magnification changed we already notified for the change.
        if (boundsChanged && updateSpec && !magnificationChanged) {
            onMagnificationChangedLocked();
        }
    }
}
Also used : MagnificationSpec(android.view.MagnificationSpec)

Example 24 with MagnificationSpec

use of android.view.MagnificationSpec in project platform_frameworks_base by android.

the class MagnificationController method setScale.

/**
     * Scales the magnified region around the specified pivot point,
     * optionally animating the transition. If animation is disabled, the
     * transition is immediate.
     *
     * @param scale the target scale, must be >= 1
     * @param pivotX the screen-relative X coordinate around which to scale
     * @param pivotY the screen-relative Y coordinate around which to scale
     * @param animate {@code true} to animate the transition, {@code false}
     *                to transition immediately
     * @param id the ID of the service requesting the change
     * @return {@code true} if the magnification spec changed, {@code false} if
     *         the spec did not change
     */
public boolean setScale(float scale, float pivotX, float pivotY, boolean animate, int id) {
    synchronized (mLock) {
        if (!mRegistered) {
            return false;
        }
        // Constrain scale immediately for use in the pivot calculations.
        scale = MathUtils.constrain(scale, MIN_SCALE, MAX_SCALE);
        final Rect viewport = mTempRect;
        mMagnificationRegion.getBounds(viewport);
        final MagnificationSpec spec = mCurrentMagnificationSpec;
        final float oldScale = spec.scale;
        final float oldCenterX = (viewport.width() / 2.0f - spec.offsetX) / oldScale;
        final float oldCenterY = (viewport.height() / 2.0f - spec.offsetY) / oldScale;
        final float normPivotX = (pivotX - spec.offsetX) / oldScale;
        final float normPivotY = (pivotY - spec.offsetY) / oldScale;
        final float offsetX = (oldCenterX - normPivotX) * (oldScale / scale);
        final float offsetY = (oldCenterY - normPivotY) * (oldScale / scale);
        final float centerX = normPivotX + offsetX;
        final float centerY = normPivotY + offsetY;
        mIdOfLastServiceToMagnify = id;
        return setScaleAndCenterLocked(scale, centerX, centerY, animate, id);
    }
}
Also used : MagnificationSpec(android.view.MagnificationSpec) Rect(android.graphics.Rect)

Example 25 with MagnificationSpec

use of android.view.MagnificationSpec 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

MagnificationSpec (android.view.MagnificationSpec)35 Rect (android.graphics.Rect)12 Point (android.graphics.Point)7 Matrix (android.graphics.Matrix)5 Transformation (android.view.animation.Transformation)5 AccessibilityService (android.accessibilityservice.AccessibilityService)1 Paint (android.graphics.Paint)1 WindowManagerPolicy (android.view.WindowManagerPolicy)1 AccessibilityInteractionClient (android.view.accessibility.AccessibilityInteractionClient)1 AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)1 IStatusBarService (com.android.internal.statusbar.IStatusBarService)1