Merge "Cleanup EditorInfoCompatUtils"
commit
244c825c4b
|
@ -17,41 +17,14 @@
|
||||||
package com.android.inputmethod.compat;
|
package com.android.inputmethod.compat;
|
||||||
|
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputConnection;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
public class EditorInfoCompatUtils {
|
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_FLAG_FORCE_ASCII = CompatUtils.getField(
|
private static final Field FIELD_IME_FLAG_FORCE_ASCII = CompatUtils.getField(
|
||||||
EditorInfo.class, "IME_FLAG_FORCE_ASCII");
|
EditorInfo.class, "IME_FLAG_FORCE_ASCII");
|
||||||
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_FLAG_FORCE_ASCII = (Integer) CompatUtils
|
private static final Integer OBJ_IME_FLAG_FORCE_ASCII = (Integer) CompatUtils
|
||||||
.getFieldValue(null, null, FIELD_IME_FLAG_FORCE_ASCII);
|
.getFieldValue(null, null, FIELD_IME_FLAG_FORCE_ASCII);
|
||||||
private static final Integer OBJ_IME_ACTION_PREVIOUS = (Integer) CompatUtils
|
|
||||||
.getFieldValue(null, null, FIELD_IME_ACTION_PREVIOUS);
|
|
||||||
|
|
||||||
// EditorInfo.IME_FLAG_NAVIGATE_NEXT has been introduced since API#11 (Honeycomb).
|
|
||||||
public static boolean hasFlagNavigateNext(int imeOptions) {
|
|
||||||
if (OBJ_IME_FLAG_NAVIGATE_NEXT == null)
|
|
||||||
return false;
|
|
||||||
return (imeOptions & OBJ_IME_FLAG_NAVIGATE_NEXT) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS has been introduced since API#11 (Honeycomb).
|
|
||||||
public static boolean hasFlagNavigatePrevious(int imeOptions) {
|
|
||||||
if (OBJ_IME_FLAG_NAVIGATE_PREVIOUS == null)
|
|
||||||
return false;
|
|
||||||
return (imeOptions & OBJ_IME_FLAG_NAVIGATE_PREVIOUS) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// EditorInfo.IME_FLAG_FORCE_ASCII has been introduced since API#16 (JellyBean).
|
// EditorInfo.IME_FLAG_FORCE_ASCII has been introduced since API#16 (JellyBean).
|
||||||
public static boolean hasFlagForceAscii(int imeOptions) {
|
public static boolean hasFlagForceAscii(int imeOptions) {
|
||||||
|
@ -60,13 +33,6 @@ public class EditorInfoCompatUtils {
|
||||||
return (imeOptions & OBJ_IME_FLAG_FORCE_ASCII) != 0;
|
return (imeOptions & OBJ_IME_FLAG_FORCE_ASCII) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditorInfo.IME_ACTION_PREVIOUS has been introduced since API#11 (Honeycomb).
|
|
||||||
public static void performEditorActionPrevious(InputConnection ic) {
|
|
||||||
if (OBJ_IME_ACTION_PREVIOUS == null || ic == null)
|
|
||||||
return;
|
|
||||||
ic.performEditorAction(OBJ_IME_ACTION_PREVIOUS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String imeActionName(int imeOptions) {
|
public static String imeActionName(int imeOptions) {
|
||||||
final int actionId = imeOptions & EditorInfo.IME_MASK_ACTION;
|
final int actionId = imeOptions & EditorInfo.IME_MASK_ACTION;
|
||||||
switch (actionId) {
|
switch (actionId) {
|
||||||
|
@ -84,14 +50,12 @@ public class EditorInfoCompatUtils {
|
||||||
return "actionNext";
|
return "actionNext";
|
||||||
case EditorInfo.IME_ACTION_DONE:
|
case EditorInfo.IME_ACTION_DONE:
|
||||||
return "actionDone";
|
return "actionDone";
|
||||||
default:
|
case EditorInfo.IME_ACTION_PREVIOUS:
|
||||||
if (OBJ_IME_ACTION_PREVIOUS != null && actionId == OBJ_IME_ACTION_PREVIOUS) {
|
|
||||||
return "actionPrevious";
|
return "actionPrevious";
|
||||||
} else {
|
default:
|
||||||
return "actionUnknown(" + actionId + ")";
|
return "actionUnknown(" + actionId + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static String imeOptionsName(int imeOptions) {
|
public static String imeOptionsName(int imeOptions) {
|
||||||
final String action = imeActionName(imeOptions);
|
final String action = imeActionName(imeOptions);
|
||||||
|
@ -99,10 +63,10 @@ public class EditorInfoCompatUtils {
|
||||||
if ((imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
|
if ((imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
|
||||||
flags.append("flagNoEnterAction|");
|
flags.append("flagNoEnterAction|");
|
||||||
}
|
}
|
||||||
if (hasFlagNavigateNext(imeOptions)) {
|
if ((imeOptions & EditorInfo.IME_FLAG_NAVIGATE_NEXT) != 0) {
|
||||||
flags.append("flagNavigateNext|");
|
flags.append("flagNavigateNext|");
|
||||||
}
|
}
|
||||||
if (hasFlagNavigatePrevious(imeOptions)) {
|
if ((imeOptions & EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS) != 0) {
|
||||||
flags.append("flagNavigatePrevious|");
|
flags.append("flagNavigatePrevious|");
|
||||||
}
|
}
|
||||||
if (hasFlagForceAscii(imeOptions)) {
|
if (hasFlagForceAscii(imeOptions)) {
|
||||||
|
|
|
@ -131,11 +131,11 @@ public class KeyboardId {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean navigateNext() {
|
public boolean navigateNext() {
|
||||||
return EditorInfoCompatUtils.hasFlagNavigateNext(mEditorInfo.imeOptions);
|
return (mEditorInfo.imeOptions & EditorInfo.IME_FLAG_NAVIGATE_NEXT) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean navigatePrevious() {
|
public boolean navigatePrevious() {
|
||||||
return EditorInfoCompatUtils.hasFlagNavigatePrevious(mEditorInfo.imeOptions);
|
return (mEditorInfo.imeOptions & EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean passwordInput() {
|
public boolean passwordInput() {
|
||||||
|
|
|
@ -56,7 +56,6 @@ import android.view.inputmethod.InputMethodSubtype;
|
||||||
import com.android.inputmethod.accessibility.AccessibilityUtils;
|
import com.android.inputmethod.accessibility.AccessibilityUtils;
|
||||||
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
|
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
|
||||||
import com.android.inputmethod.compat.CompatUtils;
|
import com.android.inputmethod.compat.CompatUtils;
|
||||||
import com.android.inputmethod.compat.EditorInfoCompatUtils;
|
|
||||||
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
||||||
import com.android.inputmethod.compat.SuggestionSpanUtils;
|
import com.android.inputmethod.compat.SuggestionSpanUtils;
|
||||||
import com.android.inputmethod.keyboard.Keyboard;
|
import com.android.inputmethod.keyboard.Keyboard;
|
||||||
|
@ -1273,7 +1272,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
performeEditorAction(EditorInfo.IME_ACTION_NEXT);
|
performeEditorAction(EditorInfo.IME_ACTION_NEXT);
|
||||||
break;
|
break;
|
||||||
case Keyboard.CODE_ACTION_PREVIOUS:
|
case Keyboard.CODE_ACTION_PREVIOUS:
|
||||||
EditorInfoCompatUtils.performEditorActionPrevious(getCurrentInputConnection());
|
performeEditorAction(EditorInfo.IME_ACTION_PREVIOUS);
|
||||||
break;
|
break;
|
||||||
case Keyboard.CODE_LANGUAGE_SWITCH:
|
case Keyboard.CODE_LANGUAGE_SWITCH:
|
||||||
handleLanguageSwitchKey();
|
handleLanguageSwitchKey();
|
||||||
|
|
Loading…
Reference in New Issue