Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 286c5b77 authored by Svetoslav Ganov's avatar Svetoslav Ganov Committed by Android (Google) Code Review
Browse files

Merge "Properly notify magnification listener" into nyc-dev

parents 09282c5d 7d477d48
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -131,11 +131,11 @@ public class MagnificationSpec implements Parcelable {
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("<scale:");
        builder.append(scale);
        builder.append(Float.toString(scale));
        builder.append(",offsetX:");
        builder.append(offsetX);
        builder.append(Float.toString(offsetX));
        builder.append(",offsetY:");
        builder.append(offsetY);
        builder.append(Float.toString(offsetY));
        builder.append(">");
        return builder.toString();
    }
+46 −32
Original line number Diff line number Diff line
@@ -144,12 +144,18 @@ class MagnificationController {
     * @param updateSpec {@code true} to update the scale and center based on
     *                   the region bounds, {@code false} to leave them as-is
     */
    public void setMagnifiedRegion(Region magnified, Region available, boolean updateSpec) {
    private void setMagnifiedRegion(Region magnified, Region available, boolean updateSpec) {
        synchronized (mLock) {
            boolean magnificationChanged = false;
            boolean boundsChanged = false;

            if (!mMagnifiedRegion.equals(magnified)) {
                mMagnifiedRegion.set(magnified);
                mMagnifiedRegion.getBounds(mMagnifiedBounds);
                boundsChanged = true;
            }
            mAvailableRegion.set(available);

            if (updateSpec) {
                final MagnificationSpec sentSpec = mSpecAnimationBridge.mSentMagnificationSpec;
                final float scale = sentSpec.scale;
                final float offsetX = sentSpec.offsetX;
@@ -160,11 +166,13 @@ class MagnificationController {
                        + mMagnifiedBounds.left - offsetX) / scale;
                final float centerY = (mMagnifiedBounds.height() / 2.0f
                        + mMagnifiedBounds.top - offsetY) / scale;
            if (updateSpec) {
                setScaleAndCenter(scale, centerX, centerY, false);
            } else {
                mAms.onMagnificationStateChanged();
                mAms.notifyMagnificationChanged(mMagnifiedRegion, scale, centerX, centerY);
                magnificationChanged = setScaleAndCenterLocked(
                        scale, centerX, centerY, false);
            }

            // If magnification changed we already notified for the change.
            if (boundsChanged && updateSpec && !magnificationChanged) {
                onMagnificationChangedLocked();
            }
        }
    }
@@ -327,20 +335,16 @@ class MagnificationController {
     */
    public boolean reset(boolean animate) {
        synchronized (mLock) {
            return resetLocked(animate);
        }
    }

    private boolean resetLocked(boolean animate) {
            final MagnificationSpec spec = mCurrentMagnificationSpec;
            final boolean changed = !spec.isNop();
            if (changed) {
                spec.clear();
                onMagnificationChangedLocked();
            }

            mSpecAnimationBridge.updateSentSpec(spec, animate);
            return changed;
        }
    }

    /**
     * Scales the magnified region around the specified pivot point,
@@ -416,8 +420,8 @@ class MagnificationController {
        }
    }

    private boolean setScaleAndCenterLocked(
            float scale, float centerX, float centerY, boolean animate) {
    private boolean setScaleAndCenterLocked(float scale, float centerX, float centerY,
            boolean animate) {
        final boolean changed = updateMagnificationSpecLocked(scale, centerX, centerY);
        mSpecAnimationBridge.updateSentSpec(mCurrentMagnificationSpec, animate);
        return changed;
@@ -440,6 +444,12 @@ class MagnificationController {
        }
    }

    private void onMagnificationChangedLocked() {
        mAms.onMagnificationStateChanged();
        mAms.notifyMagnificationChanged(mMagnifiedRegion,
                getScale(), getCenterX(), getCenterY());
    }

    /**
     * Persists the current magnification scale to the current user's settings.
     */
@@ -524,6 +534,10 @@ class MagnificationController {
            changed = true;
        }

        if (changed) {
            onMagnificationChangedLocked();
        }

        return changed;
    }