summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/java/android/view/inputmethod/CursorAnchorInfo.java20
-rw-r--r--core/java/android/view/inputmethod/SparseRectFArray.java4
-rw-r--r--core/tests/inputmethodtests/src/android/os/CursorAnchorInfoTest.java52
3 files changed, 71 insertions, 5 deletions
diff --git a/core/java/android/view/inputmethod/CursorAnchorInfo.java b/core/java/android/view/inputmethod/CursorAnchorInfo.java
index d3d5fff..a22931a 100644
--- a/core/java/android/view/inputmethod/CursorAnchorInfo.java
+++ b/core/java/android/view/inputmethod/CursorAnchorInfo.java
@@ -291,15 +291,30 @@ public final class CursorAnchorInfo implements Parcelable {
*/
public Builder setMatrix(final Matrix matrix) {
mMatrix.set(matrix != null ? matrix : Matrix.IDENTITY_MATRIX);
+ mMatrixInitialized = true;
return this;
}
private final Matrix mMatrix = new Matrix(Matrix.IDENTITY_MATRIX);
+ private boolean mMatrixInitialized = false;
/**
- * @return {@link CursorAnchorInfo} using parameters in this
- * {@link Builder}.
+ * @return {@link CursorAnchorInfo} using parameters in this {@link Builder}.
+ * @throws IllegalArgumentException if one or more positional parameters are specified but
+ * the coordinate transformation matrix is not provided via {@link #setMatrix(Matrix)}.
*/
public CursorAnchorInfo build() {
+ if (!mMatrixInitialized) {
+ // Coordinate transformation matrix is mandatory when positional parameters are
+ // specified.
+ if ((mCharacterRectBuilder != null && !mCharacterRectBuilder.isEmpty()) ||
+ !Float.isNaN(mInsertionMarkerHorizontal) ||
+ !Float.isNaN(mInsertionMarkerTop) ||
+ !Float.isNaN(mInsertionMarkerBaseline) ||
+ !Float.isNaN(mInsertionMarkerBottom)) {
+ throw new IllegalArgumentException("Coordinate transformation matrix is " +
+ "required when positional parameters are specified.");
+ }
+ }
return new CursorAnchorInfo(this);
}
@@ -317,6 +332,7 @@ public final class CursorAnchorInfo implements Parcelable {
mInsertionMarkerBaseline = Float.NaN;
mInsertionMarkerBottom = Float.NaN;
mMatrix.set(Matrix.IDENTITY_MATRIX);
+ mMatrixInitialized = false;
if (mCharacterRectBuilder != null) {
mCharacterRectBuilder.reset();
}
diff --git a/core/java/android/view/inputmethod/SparseRectFArray.java b/core/java/android/view/inputmethod/SparseRectFArray.java
index 40cade7..d4ec9d0 100644
--- a/core/java/android/view/inputmethod/SparseRectFArray.java
+++ b/core/java/android/view/inputmethod/SparseRectFArray.java
@@ -196,6 +196,10 @@ public final class SparseRectFArray implements Parcelable {
private float[] mCoordinates = null;
private static int INITIAL_SIZE = 16;
+ public boolean isEmpty() {
+ return mCount <= 0;
+ }
+
/**
* @return {@link SparseRectFArray} using parameters in this {@link SparseRectFArray}.
*/
diff --git a/core/tests/inputmethodtests/src/android/os/CursorAnchorInfoTest.java b/core/tests/inputmethodtests/src/android/os/CursorAnchorInfoTest.java
index 9252270..33192f2 100644
--- a/core/tests/inputmethodtests/src/android/os/CursorAnchorInfoTest.java
+++ b/core/tests/inputmethodtests/src/android/os/CursorAnchorInfoTest.java
@@ -59,9 +59,6 @@ public class CursorAnchorInfoTest extends InstrumentationTestCase {
final float INSERTION_MARKER_TOP = 100.1f;
final float INSERTION_MARKER_BASELINE = 110.4f;
final float INSERTION_MARKER_BOTOM = 111.0f;
- final int CHAR_INDEX = 32;
- final char CHAR_VALUE = 'X';
- final char DEFAULT_CHAR_VALUE = '!';
Matrix TRANSFORM_MATRIX = new Matrix(Matrix.IDENTITY_MATRIX);
TRANSFORM_MATRIX.setScale(10.0f, 20.0f);
@@ -138,6 +135,7 @@ public class CursorAnchorInfoTest extends InstrumentationTestCase {
assertEquals(Float.NaN, uninitializedInfo.getInsertionMarkerTop());
assertEquals(Float.NaN, uninitializedInfo.getInsertionMarkerBaseline());
assertEquals(Float.NaN, uninitializedInfo.getInsertionMarkerBottom());
+ assertEquals(Matrix.IDENTITY_MATRIX, uninitializedInfo.getMatrix());
}
@SmallTest
@@ -169,6 +167,54 @@ public class CursorAnchorInfoTest extends InstrumentationTestCase {
}
@SmallTest
+ public void testMatrixIsRequired() throws Exception {
+ final int SELECTION_START = 30;
+ final int SELECTION_END = 40;
+ final int COMPOSING_TEXT_START = 32;
+ final String COMPOSING_TEXT = "test";
+ final float INSERTION_MARKER_HORIZONTAL = 10.5f;
+ final float INSERTION_MARKER_TOP = 100.1f;
+ final float INSERTION_MARKER_BASELINE = 110.4f;
+ final float INSERTION_MARKER_BOTOM = 111.0f;
+ Matrix TRANSFORM_MATRIX = new Matrix(Matrix.IDENTITY_MATRIX);
+ TRANSFORM_MATRIX.setScale(10.0f, 20.0f);
+
+ final Builder builder = new Builder();
+ // Check twice to make sure if Builder#reset() works as expected.
+ for (int repeatCount = 0; repeatCount < 2; ++repeatCount) {
+ builder.setSelectionRange(SELECTION_START, SELECTION_END)
+ .setComposingText(COMPOSING_TEXT_START, COMPOSING_TEXT);
+ try {
+ // Should succeed as coordinate transformation matrix is not required if no
+ // positional information is specified.
+ new Builder().build();
+ } catch (IllegalArgumentException ex) {
+ assertTrue(false);
+ }
+
+ builder.setInsertionMarkerLocation(INSERTION_MARKER_HORIZONTAL, INSERTION_MARKER_TOP,
+ INSERTION_MARKER_BASELINE, INSERTION_MARKER_BOTOM);
+ try {
+ // Coordinate transformation matrix is required if no positional information is
+ // specified.
+ new Builder().build();
+ } catch (IllegalArgumentException ex) {
+ assertTrue(true);
+ }
+
+ builder.setMatrix(TRANSFORM_MATRIX);
+ try {
+ // Should succeed as coordinate transformation matrix is required.
+ new Builder().build();
+ } catch (IllegalArgumentException ex) {
+ assertTrue(false);
+ }
+
+ builder.reset();
+ }
+ }
+
+ @SmallTest
public void testBuilderAdd() throws Exception {
// A negative index should be rejected.
try {