Loading core/java/android/view/inputmethod/CursorAnchorInfo.java +4 −8 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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(); } Loading @@ -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); } /** Loading core/tests/inputmethodtests/src/android/os/CursorAnchorInfoTest.java +28 −0 Original line number Diff line number Diff line Loading @@ -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. Loading Loading
core/java/android/view/inputmethod/CursorAnchorInfo.java +4 −8 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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(); } Loading @@ -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); } /** Loading
core/tests/inputmethodtests/src/android/os/CursorAnchorInfoTest.java +28 −0 Original line number Diff line number Diff line Loading @@ -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. Loading