Search in sources :

Example 31 with MagnificationSpec

use of android.view.MagnificationSpec in project android_frameworks_base by DirtyUnicorns.

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 32 with MagnificationSpec

use of android.view.MagnificationSpec in project android_frameworks_base by DirtyUnicorns.

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 33 with MagnificationSpec

use of android.view.MagnificationSpec in project android_frameworks_base by ResurrectionRemix.

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 34 with MagnificationSpec

use of android.view.MagnificationSpec in project android_frameworks_base by ResurrectionRemix.

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 35 with MagnificationSpec

use of android.view.MagnificationSpec in project android_frameworks_base by crdroidandroid.

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)

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