aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/compat
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/compat')
-rw-r--r--java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java79
-rw-r--r--java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java32
2 files changed, 55 insertions, 56 deletions
diff --git a/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java b/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java
index 24eaec85c..5af31795c 100644
--- a/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java
+++ b/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java
@@ -23,39 +23,28 @@ import com.android.inputmethod.annotations.UsedForTesting;
@UsedForTesting
public final class CursorAnchorInfoCompatWrapper {
- public static final int CHARACTER_RECT_TYPE_MASK = 0x0f;
/**
- * Type for {@link #CHARACTER_RECT_TYPE_MASK}: the editor did not specify any type of this
- * character. Editor authors should not use this flag.
+ * The insertion marker or character bounds have at least one visible region.
*/
- public static final int CHARACTER_RECT_TYPE_UNSPECIFIED = 0;
+ public static final int FLAG_HAS_VISIBLE_REGION = 0x01;
/**
- * Type for {@link #CHARACTER_RECT_TYPE_MASK}: the character is entirely visible.
+ * The insertion marker or character bounds have at least one invisible (clipped) region.
*/
- public static final int CHARACTER_RECT_TYPE_FULLY_VISIBLE = 1;
+ public static final int FLAG_HAS_INVISIBLE_REGION = 0x02;
/**
- * Type for {@link #CHARACTER_RECT_TYPE_MASK}: some area of the character is invisible.
+ * The insertion marker or character bounds is placed at right-to-left (RTL) character.
*/
- public static final int CHARACTER_RECT_TYPE_PARTIALLY_VISIBLE = 2;
-
- /**
- * Type for {@link #CHARACTER_RECT_TYPE_MASK}: the character is entirely invisible.
- */
- public static final int CHARACTER_RECT_TYPE_INVISIBLE = 3;
-
- /**
- * Type for {@link #CHARACTER_RECT_TYPE_MASK}: the editor gave up to calculate the rectangle
- * for this character. Input method authors should ignore the returned rectangle.
- */
- public static final int CHARACTER_RECT_TYPE_NOT_FEASIBLE = 4;
+ public static final int FLAG_IS_RTL = 0x04;
// Note that CursorAnchorInfo has been introduced in API level XX (Build.VERSION_CODE.LXX).
private static final CompatUtils.ClassWrapper sCursorAnchorInfoClass;
- private static final CompatUtils.ToObjectMethodWrapper<RectF> sGetCharacterRectMethod;
- private static final CompatUtils.ToIntMethodWrapper sGetCharacterRectFlagsMethod;
+ private static final CompatUtils.ToIntMethodWrapper sGetSelectionStartMethod;
+ private static final CompatUtils.ToIntMethodWrapper sGetSelectionEndMethod;
+ private static final CompatUtils.ToObjectMethodWrapper<RectF> sGetCharacterBoundsMethod;
+ private static final CompatUtils.ToIntMethodWrapper sGetCharacterBoundsFlagsMethod;
private static final CompatUtils.ToObjectMethodWrapper<CharSequence> sGetComposingTextMethod;
private static final CompatUtils.ToIntMethodWrapper sGetComposingTextStartMethod;
private static final CompatUtils.ToFloatMethodWrapper sGetInsertionMarkerBaselineMethod;
@@ -63,20 +52,24 @@ public final class CursorAnchorInfoCompatWrapper {
private static final CompatUtils.ToFloatMethodWrapper sGetInsertionMarkerHorizontalMethod;
private static final CompatUtils.ToFloatMethodWrapper sGetInsertionMarkerTopMethod;
private static final CompatUtils.ToObjectMethodWrapper<Matrix> sGetMatrixMethod;
- private static final CompatUtils.ToBooleanMethodWrapper sIsInsertionMarkerClippedMethod;
+ private static final CompatUtils.ToIntMethodWrapper sGetInsertionMarkerFlagsMethod;
- private static int COMPOSING_TEXT_START_DEFAULT = -1;
+ private static int INVALID_TEXT_INDEX = -1;
static {
sCursorAnchorInfoClass = CompatUtils.getClassWrapper(
"android.view.inputmethod.CursorAnchorInfo");
- sGetCharacterRectMethod = sCursorAnchorInfoClass.getMethod(
- "getCharacterRect", (RectF)null, int.class);
- sGetCharacterRectFlagsMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
- "getCharacterRectFlags", CHARACTER_RECT_TYPE_UNSPECIFIED, int.class);
+ sGetSelectionStartMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
+ "getSelectionStart", INVALID_TEXT_INDEX);
+ sGetSelectionEndMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
+ "getSelectionEnd", INVALID_TEXT_INDEX);
+ sGetCharacterBoundsMethod = sCursorAnchorInfoClass.getMethod(
+ "getCharacterBounds", (RectF)null, int.class);
+ sGetCharacterBoundsFlagsMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
+ "getCharacterBoundsFlags", 0, int.class);
sGetComposingTextMethod = sCursorAnchorInfoClass.getMethod(
"getComposingText", (CharSequence)null);
sGetComposingTextStartMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
- "getComposingTextStart", COMPOSING_TEXT_START_DEFAULT);
+ "getComposingTextStart", INVALID_TEXT_INDEX);
sGetInsertionMarkerBaselineMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
"getInsertionMarkerBaseline", 0.0f);
sGetInsertionMarkerBottomMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
@@ -86,13 +79,13 @@ public final class CursorAnchorInfoCompatWrapper {
sGetInsertionMarkerTopMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
"getInsertionMarkerTop", 0.0f);
sGetMatrixMethod = sCursorAnchorInfoClass.getMethod("getMatrix", (Matrix)null);
- sIsInsertionMarkerClippedMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
- "isInsertionMarkerClipped", false);
+ sGetInsertionMarkerFlagsMethod = sCursorAnchorInfoClass.getPrimitiveMethod(
+ "getInsertionMarkerFlags", 0);
}
@UsedForTesting
- public static boolean isAvailable() {
- return sCursorAnchorInfoClass.exists();
+ public boolean isAvailable() {
+ return sCursorAnchorInfoClass.exists() && mInstance != null;
}
private Object mInstance;
@@ -103,7 +96,7 @@ public final class CursorAnchorInfoCompatWrapper {
@UsedForTesting
public static CursorAnchorInfoCompatWrapper fromObject(final Object instance) {
- if (!isAvailable()) {
+ if (!sCursorAnchorInfoClass.exists()) {
return new CursorAnchorInfoCompatWrapper(null);
}
return new CursorAnchorInfoCompatWrapper(instance);
@@ -118,6 +111,14 @@ public final class CursorAnchorInfoCompatWrapper {
return FakeHolder.sInstance;
}
+ public int getSelectionStart() {
+ return sGetSelectionStartMethod.invoke(mInstance);
+ }
+
+ public int getSelectionEnd() {
+ return sGetSelectionEndMethod.invoke(mInstance);
+ }
+
public CharSequence getComposingText() {
return sGetComposingTextMethod.invoke(mInstance);
}
@@ -130,12 +131,12 @@ public final class CursorAnchorInfoCompatWrapper {
return sGetMatrixMethod.invoke(mInstance);
}
- public RectF getCharacterRect(final int index) {
- return sGetCharacterRectMethod.invoke(mInstance, index);
+ public RectF getCharacterBounds(final int index) {
+ return sGetCharacterBoundsMethod.invoke(mInstance, index);
}
- public int getCharacterRectFlags(final int index) {
- return sGetCharacterRectFlagsMethod.invoke(mInstance, index);
+ public int getCharacterBoundsFlags(final int index) {
+ return sGetCharacterBoundsFlagsMethod.invoke(mInstance, index);
}
public float getInsertionMarkerBaseline() {
@@ -154,7 +155,7 @@ public final class CursorAnchorInfoCompatWrapper {
return sGetInsertionMarkerTopMethod.invoke(mInstance);
}
- public boolean isInsertionMarkerClipped() {
- return sIsInsertionMarkerClippedMethod.invoke(mInstance);
+ public int getInsertionMarkerFlags() {
+ return sGetInsertionMarkerFlagsMethod.invoke(mInstance);
}
}
diff --git a/java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java b/java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java
index 862ec8a58..a5c71b22f 100644
--- a/java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java
@@ -21,30 +21,29 @@ import android.view.inputmethod.InputMethodManager;
public final class InputConnectionCompatUtils {
private static final CompatUtils.ClassWrapper sInputConnectionType;
- private static final CompatUtils.ToBooleanMethodWrapper sRequestUpdateCursorAnchorInfoMethod;
+ private static final CompatUtils.ToBooleanMethodWrapper sRequestCursorUpdatesMethod;
static {
sInputConnectionType = new CompatUtils.ClassWrapper(InputConnection.class);
- sRequestUpdateCursorAnchorInfoMethod = sInputConnectionType.getPrimitiveMethod(
- "requestUpdateCursorAnchorInfo", false, int.class);
+ sRequestCursorUpdatesMethod = sInputConnectionType.getPrimitiveMethod(
+ "requestCursorUpdates", false, int.class);
}
- public static boolean isRequestUpdateCursorAnchorInfoAvailable() {
- return sRequestUpdateCursorAnchorInfoMethod != null;
+ public static boolean isRequestCursorUpdatesAvailable() {
+ return sRequestCursorUpdatesMethod != null;
}
/**
- * Local copies of some constants in CursorAnchorInfoRequest until the SDK becomes publicly
- * available.
+ * Local copies of some constants in InputConnection until the SDK becomes publicly available.
*/
- private static int REQUEST_UPDATE_CURSOR_UPDATE_IMMEDIATE = 1 << 0;
- private static int REQUEST_UPDATE_CURSOR_UPDATE_MONITOR = 1 << 1;
+ private static int CURSOR_UPDATE_IMMEDIATE = 1 << 0;
+ private static int CURSOR_UPDATE_MONITOR = 1 << 1;
- private static boolean requestUpdateCursorAnchorInfoImpl(final InputConnection inputConnection,
+ private static boolean requestCursorUpdatesImpl(final InputConnection inputConnection,
final int cursorUpdateMode) {
- if (!isRequestUpdateCursorAnchorInfoAvailable()) {
+ if (!isRequestCursorUpdatesAvailable()) {
return false;
}
- return sRequestUpdateCursorAnchorInfoMethod.invoke(inputConnection, cursorUpdateMode);
+ return sRequestCursorUpdatesMethod.invoke(inputConnection, cursorUpdateMode);
}
/**
@@ -56,11 +55,10 @@ public final class InputConnectionCompatUtils {
* as soon as possible to notify the current cursor/anchor position to the input method.
* @return {@code false} if the request is not handled. Otherwise returns {@code true}.
*/
- public static boolean requestUpdateCursorAnchorInfo(final InputConnection inputConnection,
+ public static boolean requestCursorUpdates(final InputConnection inputConnection,
final boolean enableMonitor, final boolean requestImmediateCallback) {
- final int cursorUpdateMode = (enableMonitor ? REQUEST_UPDATE_CURSOR_UPDATE_MONITOR : 0)
- | (requestImmediateCallback ? REQUEST_UPDATE_CURSOR_UPDATE_IMMEDIATE : 0);
- return requestUpdateCursorAnchorInfoImpl(inputConnection, cursorUpdateMode);
+ final int cursorUpdateMode = (enableMonitor ? CURSOR_UPDATE_MONITOR : 0)
+ | (requestImmediateCallback ? CURSOR_UPDATE_IMMEDIATE : 0);
+ return requestCursorUpdatesImpl(inputConnection, cursorUpdateMode);
}
-
}