aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java')
-rw-r--r--java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java111
1 files changed, 45 insertions, 66 deletions
diff --git a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java
index bcdcef7dc..08c246f8b 100644
--- a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java
@@ -17,86 +17,65 @@
package com.android.inputmethod.compat;
import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputConnection;
import java.lang.reflect.Field;
public class EditorInfoCompatUtils {
- private static final Field FIELD_IME_FLAG_NAVIGATE_NEXT = CompatUtils.getField(
- EditorInfo.class, "IME_FLAG_NAVIGATE_NEXT");
- private static final Field FIELD_IME_FLAG_NAVIGATE_PREVIOUS = CompatUtils.getField(
- EditorInfo.class, "IME_FLAG_NAVIGATE_PREVIOUS");
- private static final Field FIELD_IME_ACTION_PREVIOUS = CompatUtils.getField(
- EditorInfo.class, "IME_ACTION_PREVIOUS");
- private static final Integer OBJ_IME_FLAG_NAVIGATE_NEXT = (Integer) CompatUtils
- .getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_NEXT);
- private static final Integer OBJ_IME_FLAG_NAVIGATE_PREVIOUS = (Integer) CompatUtils
- .getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_PREVIOUS);
- private static final Integer OBJ_IME_ACTION_PREVIOUS = (Integer) CompatUtils
- .getFieldValue(null, null, FIELD_IME_ACTION_PREVIOUS);
+ // EditorInfo.IME_FLAG_FORCE_ASCII has been introduced since API#16 (JellyBean).
+ private static final Field FIELD_IME_FLAG_FORCE_ASCII = CompatUtils.getField(
+ EditorInfo.class, "IME_FLAG_FORCE_ASCII");
+ private static final Integer OBJ_IME_FLAG_FORCE_ASCII = (Integer) CompatUtils
+ .getFieldValue(null, null, FIELD_IME_FLAG_FORCE_ASCII);
- public static boolean hasFlagNavigateNext(int imeOptions) {
- if (OBJ_IME_FLAG_NAVIGATE_NEXT == null)
- return false;
- return (imeOptions & OBJ_IME_FLAG_NAVIGATE_NEXT) != 0;
+ private EditorInfoCompatUtils() {
+ // This utility class is not publicly instantiable.
}
- public static boolean hasFlagNavigatePrevious(int imeOptions) {
- if (OBJ_IME_FLAG_NAVIGATE_PREVIOUS == null)
+ public static boolean hasFlagForceAscii(int imeOptions) {
+ if (OBJ_IME_FLAG_FORCE_ASCII == null)
return false;
- return (imeOptions & OBJ_IME_FLAG_NAVIGATE_PREVIOUS) != 0;
- }
-
- public static void performEditorActionNext(InputConnection ic) {
- ic.performEditorAction(EditorInfo.IME_ACTION_NEXT);
+ return (imeOptions & OBJ_IME_FLAG_FORCE_ASCII) != 0;
}
- public static void performEditorActionPrevious(InputConnection ic) {
- if (OBJ_IME_ACTION_PREVIOUS == null)
- return;
- ic.performEditorAction(OBJ_IME_ACTION_PREVIOUS);
- }
-
- public static String imeOptionsName(int imeOptions) {
- if (imeOptions == -1)
- return null;
+ public static String imeActionName(int imeOptions) {
final int actionId = imeOptions & EditorInfo.IME_MASK_ACTION;
- final String action;
switch (actionId) {
- case EditorInfo.IME_ACTION_UNSPECIFIED:
- action = "actionUnspecified";
- break;
- case EditorInfo.IME_ACTION_NONE:
- action = "actionNone";
- break;
- case EditorInfo.IME_ACTION_GO:
- action = "actionGo";
- break;
- case EditorInfo.IME_ACTION_SEARCH:
- action = "actionSearch";
- break;
- case EditorInfo.IME_ACTION_SEND:
- action = "actionSend";
- break;
- case EditorInfo.IME_ACTION_NEXT:
- action = "actionNext";
- break;
- case EditorInfo.IME_ACTION_DONE:
- action = "actionDone";
- break;
- default: {
- if (OBJ_IME_ACTION_PREVIOUS != null && actionId == OBJ_IME_ACTION_PREVIOUS) {
- action = "actionPrevious";
- } else {
- action = "actionUnknown(" + actionId + ")";
- }
- break;
- }
+ case EditorInfo.IME_ACTION_UNSPECIFIED:
+ return "actionUnspecified";
+ case EditorInfo.IME_ACTION_NONE:
+ return "actionNone";
+ case EditorInfo.IME_ACTION_GO:
+ return "actionGo";
+ case EditorInfo.IME_ACTION_SEARCH:
+ return "actionSearch";
+ case EditorInfo.IME_ACTION_SEND:
+ return "actionSend";
+ case EditorInfo.IME_ACTION_NEXT:
+ return "actionNext";
+ case EditorInfo.IME_ACTION_DONE:
+ return "actionDone";
+ case EditorInfo.IME_ACTION_PREVIOUS:
+ return "actionPrevious";
+ default:
+ return "actionUnknown(" + actionId + ")";
}
+ }
+
+ public static String imeOptionsName(int imeOptions) {
+ final String action = imeActionName(imeOptions);
+ final StringBuilder flags = new StringBuilder();
if ((imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
- return "flagNoEnterAction|" + action;
- } else {
- return action;
+ flags.append("flagNoEnterAction|");
+ }
+ if ((imeOptions & EditorInfo.IME_FLAG_NAVIGATE_NEXT) != 0) {
+ flags.append("flagNavigateNext|");
+ }
+ if ((imeOptions & EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS) != 0) {
+ flags.append("flagNavigatePrevious|");
+ }
+ if (hasFlagForceAscii(imeOptions)) {
+ flags.append("flagForceAscii|");
}
+ return (action != null) ? flags + action : flags.toString();
}
}