am ddf41668: Merge "Support EditorInfo.IME_FLAG_FORCE_ASCII"

* commit 'ddf4166815b9e72fc7fe8091d664f9b12a9cbcad':
  Support EditorInfo.IME_FLAG_FORCE_ASCII
main
Tadashi G. Takaoka 2012-01-16 22:17:46 -08:00 committed by Android Git Automerger
commit 76916e94b5
3 changed files with 30 additions and 5 deletions

View File

@ -26,12 +26,16 @@ public class EditorInfoCompatUtils {
EditorInfo.class, "IME_FLAG_NAVIGATE_NEXT"); EditorInfo.class, "IME_FLAG_NAVIGATE_NEXT");
private static final Field FIELD_IME_FLAG_NAVIGATE_PREVIOUS = CompatUtils.getField( private static final Field FIELD_IME_FLAG_NAVIGATE_PREVIOUS = CompatUtils.getField(
EditorInfo.class, "IME_FLAG_NAVIGATE_PREVIOUS"); EditorInfo.class, "IME_FLAG_NAVIGATE_PREVIOUS");
private static final Field FIELD_IME_FLAG_FORCE_ASCII = CompatUtils.getField(
EditorInfo.class, "IME_FLAG_FORCE_ASCII");
private static final Field FIELD_IME_ACTION_PREVIOUS = CompatUtils.getField( private static final Field FIELD_IME_ACTION_PREVIOUS = CompatUtils.getField(
EditorInfo.class, "IME_ACTION_PREVIOUS"); EditorInfo.class, "IME_ACTION_PREVIOUS");
private static final Integer OBJ_IME_FLAG_NAVIGATE_NEXT = (Integer) CompatUtils private static final Integer OBJ_IME_FLAG_NAVIGATE_NEXT = (Integer) CompatUtils
.getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_NEXT); .getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_NEXT);
private static final Integer OBJ_IME_FLAG_NAVIGATE_PREVIOUS = (Integer) CompatUtils private static final Integer OBJ_IME_FLAG_NAVIGATE_PREVIOUS = (Integer) CompatUtils
.getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_PREVIOUS); .getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_PREVIOUS);
private static final Integer OBJ_IME_FLAG_FORCE_ASCII = (Integer) CompatUtils
.getFieldValue(null, null, FIELD_IME_FLAG_FORCE_ASCII);
private static final Integer OBJ_IME_ACTION_PREVIOUS = (Integer) CompatUtils private static final Integer OBJ_IME_ACTION_PREVIOUS = (Integer) CompatUtils
.getFieldValue(null, null, FIELD_IME_ACTION_PREVIOUS); .getFieldValue(null, null, FIELD_IME_ACTION_PREVIOUS);
@ -47,6 +51,12 @@ public class EditorInfoCompatUtils {
return (imeOptions & OBJ_IME_FLAG_NAVIGATE_PREVIOUS) != 0; return (imeOptions & OBJ_IME_FLAG_NAVIGATE_PREVIOUS) != 0;
} }
public static boolean hasFlagForceAscii(int imeOptions) {
if (OBJ_IME_FLAG_FORCE_ASCII == null)
return false;
return (imeOptions & OBJ_IME_FLAG_FORCE_ASCII) != 0;
}
public static void performEditorActionNext(InputConnection ic) { public static void performEditorActionNext(InputConnection ic) {
ic.performEditorAction(EditorInfo.IME_ACTION_NEXT); ic.performEditorAction(EditorInfo.IME_ACTION_NEXT);
} }
@ -93,10 +103,19 @@ public class EditorInfoCompatUtils {
break; break;
} }
} }
final StringBuilder flags = new StringBuilder();
if ((imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) { if ((imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
return "flagNoEnterAction|" + action; flags.append("flagNoEnterAction|");
} else {
return action;
} }
if (hasFlagNavigateNext(imeOptions)) {
flags.append("flagNavigateNext|");
}
if (hasFlagNavigatePrevious(imeOptions)) {
flags.append("flagNavigatePrevious|");
}
if (hasFlagForceAscii(imeOptions)) {
flags.append("flagForceAscii|");
}
return flags + action;
} }
} }

View File

@ -25,6 +25,7 @@ import android.util.Log;
import android.util.Xml; import android.util.Xml;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.LocaleUtils; import com.android.inputmethod.latin.LocaleUtils;
@ -179,8 +180,9 @@ public class KeyboardSet {
// TODO: Use InputMethodSubtype object as argument. // TODO: Use InputMethodSubtype object as argument.
public Builder setSubtype(Locale inputLocale, boolean asciiCapable, public Builder setSubtype(Locale inputLocale, boolean asciiCapable,
boolean touchPositionCorrectionEnabled) { boolean touchPositionCorrectionEnabled) {
final boolean forceAscii = Utils.inPrivateImeOptions( final boolean forceAscii = EditorInfoCompatUtils.hasFlagForceAscii(mParams.mImeOptions)
mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo); || Utils.inPrivateImeOptions(
mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo);
mParams.mLocale = (forceAscii && !asciiCapable) ? Locale.US : inputLocale; mParams.mLocale = (forceAscii && !asciiCapable) ? Locale.US : inputLocale;
mParams.mTouchPositionCorrectionEnabled = touchPositionCorrectionEnabled; mParams.mTouchPositionCorrectionEnabled = touchPositionCorrectionEnabled;
return this; return this;

View File

@ -104,10 +104,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
*/ */
public static final String IME_OPTION_NO_SETTINGS_KEY = "noSettingsKey"; public static final String IME_OPTION_NO_SETTINGS_KEY = "noSettingsKey";
// TODO: Remove this private option.
/** /**
* The private IME option used to indicate that the given text field needs * The private IME option used to indicate that the given text field needs
* ASCII code points input. * ASCII code points input.
*
* @deprecated Use {@link EditorInfo#IME_FLAG_FORCE_ASCII}.
*/ */
@SuppressWarnings("dep-ann")
public static final String IME_OPTION_FORCE_ASCII = "forceAscii"; public static final String IME_OPTION_FORCE_ASCII = "forceAscii";
/** /**