Add device form factor to KeyboardId

This is a groundword for optimizing keyboard parsing.

Bug: 6860259
Change-Id: Ie65aa502b18c920e25cf2998b79120b3cc835952
This commit is contained in:
Tadashi G. Takaoka 2012-07-30 13:35:06 +09:00
parent efd8b838ee
commit 4731b67629
6 changed files with 42 additions and 14 deletions

View file

@ -19,6 +19,8 @@
--> -->
<resources> <resources>
<!-- Device form factor. This value must be aligned with {@link KeyboardId.DEVICE_FORM_FACTOR_TABLET7} -->
<integer name="config_device_form_factor">1</integer>
<bool name="config_enable_show_voice_key_option">false</bool> <bool name="config_enable_show_voice_key_option">false</bool>
<bool name="config_enable_show_popup_on_keypress_option">false</bool> <bool name="config_enable_show_popup_on_keypress_option">false</bool>
<bool name="config_enable_bigram_suggestions_option">false</bool> <bool name="config_enable_bigram_suggestions_option">false</bool>

View file

@ -19,6 +19,8 @@
--> -->
<resources> <resources>
<!-- Device form factor. This value must be aligned with {@link KeyboardId.DEVICE_FORM_FACTOR_TABLET10} -->
<integer name="config_device_form_factor">2</integer>
<bool name="config_enable_show_voice_key_option">false</bool> <bool name="config_enable_show_voice_key_option">false</bool>
<bool name="config_enable_show_popup_on_keypress_option">false</bool> <bool name="config_enable_show_popup_on_keypress_option">false</bool>
<bool name="config_enable_bigram_suggestions_option">false</bool> <bool name="config_enable_bigram_suggestions_option">false</bool>

View file

@ -19,6 +19,8 @@
--> -->
<resources> <resources>
<!-- Device form factor. This value must be aligned with {@link KeyboardId.DEVICE_FORM_FACTOR_PHONE} -->
<integer name="config_device_form_factor">0</integer>
<bool name="config_use_fullscreen_mode">false</bool> <bool name="config_use_fullscreen_mode">false</bool>
<bool name="config_enable_show_voice_key_option">true</bool> <bool name="config_enable_show_voice_key_option">true</bool>
<bool name="config_enable_show_popup_on_keypress_option">true</bool> <bool name="config_enable_show_popup_on_keypress_option">true</bool>

View file

@ -55,10 +55,15 @@ public class KeyboardId {
public static final int ELEMENT_PHONE_SYMBOLS = 8; public static final int ELEMENT_PHONE_SYMBOLS = 8;
public static final int ELEMENT_NUMBER = 9; public static final int ELEMENT_NUMBER = 9;
public static final int FORM_FACTOR_PHONE = 0;
public static final int FORM_FACTOR_TABLET7 = 1;
public static final int FORM_FACTOR_TABLET10 = 2;
private static final int IME_ACTION_CUSTOM_LABEL = EditorInfo.IME_MASK_ACTION + 1; private static final int IME_ACTION_CUSTOM_LABEL = EditorInfo.IME_MASK_ACTION + 1;
public final InputMethodSubtype mSubtype; public final InputMethodSubtype mSubtype;
public final Locale mLocale; public final Locale mLocale;
public final int mDeviceFormFactor;
public final int mOrientation; public final int mOrientation;
public final int mWidth; public final int mWidth;
public final int mMode; public final int mMode;
@ -72,11 +77,12 @@ public class KeyboardId {
private final int mHashCode; private final int mHashCode;
public KeyboardId(int elementId, InputMethodSubtype subtype, int orientation, int width, public KeyboardId(int elementId, InputMethodSubtype subtype, int deviceFormFactor,
int mode, EditorInfo editorInfo, boolean clobberSettingsKey, boolean shortcutKeyEnabled, int orientation, int width, int mode, EditorInfo editorInfo, boolean clobberSettingsKey,
boolean hasShortcutKey, boolean languageSwitchKeyEnabled) { boolean shortcutKeyEnabled, boolean hasShortcutKey, boolean languageSwitchKeyEnabled) {
mSubtype = subtype; mSubtype = subtype;
mLocale = SubtypeLocale.getSubtypeLocale(subtype); mLocale = SubtypeLocale.getSubtypeLocale(subtype);
mDeviceFormFactor = deviceFormFactor;
mOrientation = orientation; mOrientation = orientation;
mWidth = width; mWidth = width;
mMode = mode; mMode = mode;
@ -94,6 +100,7 @@ public class KeyboardId {
private static int computeHashCode(KeyboardId id) { private static int computeHashCode(KeyboardId id) {
return Arrays.hashCode(new Object[] { return Arrays.hashCode(new Object[] {
id.mDeviceFormFactor,
id.mOrientation, id.mOrientation,
id.mElementId, id.mElementId,
id.mMode, id.mMode,
@ -115,7 +122,8 @@ public class KeyboardId {
private boolean equals(KeyboardId other) { private boolean equals(KeyboardId other) {
if (other == this) if (other == this)
return true; return true;
return other.mOrientation == mOrientation return other.mDeviceFormFactor == mDeviceFormFactor
&& other.mOrientation == mOrientation
&& other.mElementId == mElementId && other.mElementId == mElementId
&& other.mMode == mMode && other.mMode == mMode
&& other.mWidth == mWidth && other.mWidth == mWidth
@ -184,11 +192,11 @@ public class KeyboardId {
@Override @Override
public String toString() { public String toString() {
return String.format("[%s %s:%s %s%d %s %s %s%s%s%s%s%s%s%s]", return String.format("[%s %s:%s %s-%s:%d %s %s %s%s%s%s%s%s%s%s]",
elementIdToName(mElementId), elementIdToName(mElementId),
mLocale, mLocale,
mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET), mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET),
(mOrientation == 1 ? "port" : "land"), mWidth, deviceFormFactor(mDeviceFormFactor), (mOrientation == 1 ? "port" : "land"), mWidth,
modeName(mMode), modeName(mMode),
imeAction(), imeAction(),
(navigateNext() ? "navigateNext" : ""), (navigateNext() ? "navigateNext" : ""),
@ -226,6 +234,15 @@ public class KeyboardId {
} }
} }
public static String deviceFormFactor(int devoceFormFactor) {
switch (devoceFormFactor) {
case FORM_FACTOR_PHONE: return "phone";
case FORM_FACTOR_TABLET7: return "tablet7";
case FORM_FACTOR_TABLET10: return "tablet10";
default: return null;
}
}
public static String modeName(int mode) { public static String modeName(int mode) {
switch (mode) { switch (mode) {
case MODE_TEXT: return "text"; case MODE_TEXT: return "text";

View file

@ -115,6 +115,7 @@ public class KeyboardLayoutSet {
boolean mNoSettingsKey; boolean mNoSettingsKey;
boolean mLanguageSwitchKeyEnabled; boolean mLanguageSwitchKeyEnabled;
InputMethodSubtype mSubtype; InputMethodSubtype mSubtype;
int mDeviceFormFactor;
int mOrientation; int mOrientation;
int mWidth; int mWidth;
// Sparse array of KeyboardLayoutSet element parameters indexed by element's id. // Sparse array of KeyboardLayoutSet element parameters indexed by element's id.
@ -211,9 +212,10 @@ public class KeyboardLayoutSet {
final boolean noLanguage = SubtypeLocale.isNoLanguage(params.mSubtype); final boolean noLanguage = SubtypeLocale.isNoLanguage(params.mSubtype);
final boolean voiceKeyEnabled = params.mVoiceKeyEnabled && !noLanguage; final boolean voiceKeyEnabled = params.mVoiceKeyEnabled && !noLanguage;
final boolean hasShortcutKey = voiceKeyEnabled && (isSymbols != params.mVoiceKeyOnMain); final boolean hasShortcutKey = voiceKeyEnabled && (isSymbols != params.mVoiceKeyOnMain);
return new KeyboardId(keyboardLayoutSetElementId, params.mSubtype, params.mOrientation, return new KeyboardId(keyboardLayoutSetElementId, params.mSubtype, params.mDeviceFormFactor,
params.mWidth, params.mMode, params.mEditorInfo, params.mNoSettingsKey, params.mOrientation, params.mWidth, params.mMode, params.mEditorInfo,
voiceKeyEnabled, hasShortcutKey, params.mLanguageSwitchKeyEnabled); params.mNoSettingsKey, voiceKeyEnabled, hasShortcutKey,
params.mLanguageSwitchKeyEnabled);
} }
public static class Builder { public static class Builder {
@ -239,9 +241,11 @@ public class KeyboardLayoutSet {
mPackageName, NO_SETTINGS_KEY, mEditorInfo); mPackageName, NO_SETTINGS_KEY, mEditorInfo);
} }
public Builder setScreenGeometry(int orientation, int widthPixels) { public Builder setScreenGeometry(int deviceFormFactor, int orientation, int widthPixels) {
mParams.mOrientation = orientation; final Params params = mParams;
mParams.mWidth = widthPixels; params.mDeviceFormFactor = deviceFormFactor;
params.mOrientation = orientation;
params.mWidth = widthPixels;
return this; return this;
} }

View file

@ -137,8 +137,9 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
public void loadKeyboard(EditorInfo editorInfo, SettingsValues settingsValues) { public void loadKeyboard(EditorInfo editorInfo, SettingsValues settingsValues) {
final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder( final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(
mThemeContext, editorInfo); mThemeContext, editorInfo);
builder.setScreenGeometry(mThemeContext.getResources().getConfiguration().orientation, final Resources res = mThemeContext.getResources();
mThemeContext.getResources().getDisplayMetrics().widthPixels); builder.setScreenGeometry(res.getInteger(R.integer.config_device_form_factor),
res.getConfiguration().orientation, res.getDisplayMetrics().widthPixels);
builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype()); builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype());
builder.setOptions( builder.setOptions(
settingsValues.isVoiceKeyEnabled(editorInfo), settingsValues.isVoiceKeyEnabled(editorInfo),