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

Commit ed1a18f4 authored by Yohei Yukawa's avatar Yohei Yukawa Committed by Android (Google) Code Review
Browse files

Merge "Make a copy of Matrix in CursorAnchorInfoBuilder"

parents fc2cf830 419b1b04
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -290,14 +290,10 @@ public final class CursorAnchorInfo implements Parcelable {
         * is interpreted as an identity matrix.
         */
        public CursorAnchorInfoBuilder setMatrix(final Matrix matrix) {
            if (matrix != null) {
                mMatrix = matrix;
            } else {
                mMatrix = Matrix.IDENTITY_MATRIX;
            }
            mMatrix.set(matrix != null ? matrix : Matrix.IDENTITY_MATRIX);
            return this;
        }
        private Matrix mMatrix = Matrix.IDENTITY_MATRIX;
        private final Matrix mMatrix = new Matrix(Matrix.IDENTITY_MATRIX);

        /**
         * @return {@link CursorAnchorInfo} using parameters in this
@@ -320,7 +316,7 @@ public final class CursorAnchorInfo implements Parcelable {
            mInsertionMarkerTop = Float.NaN;
            mInsertionMarkerBaseline = Float.NaN;
            mInsertionMarkerBottom = Float.NaN;
            mMatrix = Matrix.IDENTITY_MATRIX;
            mMatrix.set(Matrix.IDENTITY_MATRIX);
            if (mCharacterRectBuilder != null) {
                mCharacterRectBuilder.reset();
            }
@@ -338,7 +334,7 @@ public final class CursorAnchorInfo implements Parcelable {
        mInsertionMarkerBottom = builder.mInsertionMarkerBottom;
        mCharacterRects = builder.mCharacterRectBuilder != null ?
                builder.mCharacterRectBuilder.build() : null;
        mMatrix = builder.mMatrix;
        mMatrix = new Matrix(builder.mMatrix);
    }

    /**
+28 −0
Original line number Diff line number Diff line
@@ -139,6 +139,34 @@ public class CursorAnchorInfoTest extends InstrumentationTestCase {
        assertEquals(Float.NaN, uninitializedInfo.getInsertionMarkerBottom());
    }

    @SmallTest
    public void testMatrixIsCopied() throws Exception {
        final Matrix MATRIX1 = new Matrix();
        MATRIX1.setTranslate(10.0f, 20.0f);
        final Matrix MATRIX2 = new Matrix();
        MATRIX2.setTranslate(110.0f, 120.0f);
        final Matrix MATRIX3 = new Matrix();
        MATRIX3.setTranslate(210.0f, 220.0f);
        final Matrix matrix = new Matrix();
        final CursorAnchorInfoBuilder builder = new CursorAnchorInfoBuilder();

        matrix.set(MATRIX1);
        builder.setMatrix(matrix);
        matrix.postRotate(90.0f);

        final CursorAnchorInfo firstInstance = builder.build();
        assertEquals(MATRIX1, firstInstance.getMatrix());
        matrix.set(MATRIX2);
        builder.setMatrix(matrix);
        final CursorAnchorInfo secondInstance = builder.build();
        assertEquals(MATRIX1, firstInstance.getMatrix());
        assertEquals(MATRIX2, secondInstance.getMatrix());

        matrix.set(MATRIX3);
        assertEquals(MATRIX1, firstInstance.getMatrix());
        assertEquals(MATRIX2, secondInstance.getMatrix());
    }

    @SmallTest
    public void testBuilderAdd() throws Exception {
        // A negative index should be rejected.