diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index 15e006593..94f7ab78b 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -164,8 +164,6 @@
-
-
@@ -328,4 +326,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-ar/keyboard_set.xml b/java/res/xml-ar/keyboard_set.xml
new file mode 100644
index 000000000..68dc34fe3
--- /dev/null
+++ b/java/res/xml-ar/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-de-rZZ/kbd_qwerty.xml b/java/res/xml-cs/keyboard_set.xml
similarity index 52%
rename from java/res/xml-de-rZZ/kbd_qwerty.xml
rename to java/res/xml-cs/keyboard_set.xml
index d5fd8ef7a..94076d3e0 100644
--- a/java/res/xml-de-rZZ/kbd_qwerty.xml
+++ b/java/res/xml-cs/keyboard_set.xml
@@ -18,10 +18,25 @@
*/
-->
-
-
-
+ latin:keyboardLocale="cs">
+
+
+
+
+
+
+
diff --git a/java/res/xml-da/kbd_qwerty.xml b/java/res/xml-da/kbd_qwerty.xml
deleted file mode 100644
index 37a50fdfd..000000000
--- a/java/res/xml-da/kbd_qwerty.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
diff --git a/java/res/xml-da/keyboard_set.xml b/java/res/xml-da/keyboard_set.xml
new file mode 100644
index 000000000..84d126dc2
--- /dev/null
+++ b/java/res/xml-da/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-de-rZZ/keyboard_set.xml b/java/res/xml-de-rZZ/keyboard_set.xml
new file mode 100644
index 000000000..230972998
--- /dev/null
+++ b/java/res/xml-de-rZZ/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-de/kbd_qwerty.xml b/java/res/xml-de/kbd_qwerty.xml
deleted file mode 100644
index 89e10b26d..000000000
--- a/java/res/xml-de/kbd_qwerty.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
diff --git a/java/res/xml-de/keyboard_set.xml b/java/res/xml-de/keyboard_set.xml
new file mode 100644
index 000000000..c17883620
--- /dev/null
+++ b/java/res/xml-de/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-es/keyboard_set.xml b/java/res/xml-es/keyboard_set.xml
new file mode 100644
index 000000000..77f378637
--- /dev/null
+++ b/java/res/xml-es/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-fi/keyboard_set.xml b/java/res/xml-fi/keyboard_set.xml
new file mode 100644
index 000000000..0c3a96d36
--- /dev/null
+++ b/java/res/xml-fi/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-fr-rCA/kbd_qwerty.xml b/java/res/xml-fr-rCA/kbd_qwerty.xml
deleted file mode 100644
index 7bdfbadf1..000000000
--- a/java/res/xml-fr-rCA/kbd_qwerty.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
diff --git a/java/res/xml-fr-rCA/keyboard_set.xml b/java/res/xml-fr-rCA/keyboard_set.xml
new file mode 100644
index 000000000..b3bb4cc12
--- /dev/null
+++ b/java/res/xml-fr-rCA/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-fr-rCH/kbd_qwerty.xml b/java/res/xml-fr-rCH/kbd_qwerty.xml
deleted file mode 100644
index 41b701d83..000000000
--- a/java/res/xml-fr-rCH/kbd_qwerty.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
diff --git a/java/res/xml-fr-rCH/keyboard_set.xml b/java/res/xml-fr-rCH/keyboard_set.xml
new file mode 100644
index 000000000..d6dcf7541
--- /dev/null
+++ b/java/res/xml-fr-rCH/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-fr/keyboard_set.xml b/java/res/xml-fr/keyboard_set.xml
new file mode 100644
index 000000000..b94a3f252
--- /dev/null
+++ b/java/res/xml-fr/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-hr/kbd_qwerty.xml b/java/res/xml-hr/kbd_qwerty.xml
deleted file mode 100644
index ca92e86a7..000000000
--- a/java/res/xml-hr/kbd_qwerty.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
diff --git a/java/res/xml-hr/keyboard_set.xml b/java/res/xml-hr/keyboard_set.xml
new file mode 100644
index 000000000..1d8582c0a
--- /dev/null
+++ b/java/res/xml-hr/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-hu/kbd_qwerty.xml b/java/res/xml-hu/kbd_qwerty.xml
deleted file mode 100644
index 3195d5b1f..000000000
--- a/java/res/xml-hu/kbd_qwerty.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
diff --git a/java/res/xml-hu/keyboard_set.xml b/java/res/xml-hu/keyboard_set.xml
new file mode 100644
index 000000000..077111923
--- /dev/null
+++ b/java/res/xml-hu/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-iw/keyboard_set.xml b/java/res/xml-iw/keyboard_set.xml
new file mode 100644
index 000000000..ce25aae72
--- /dev/null
+++ b/java/res/xml-iw/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-nb/kbd_qwerty.xml b/java/res/xml-nb/kbd_qwerty.xml
deleted file mode 100644
index 1f4e86e89..000000000
--- a/java/res/xml-nb/kbd_qwerty.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
diff --git a/java/res/xml-nb/keyboard_set.xml b/java/res/xml-nb/keyboard_set.xml
new file mode 100644
index 000000000..eacda8f87
--- /dev/null
+++ b/java/res/xml-nb/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-pl/keyboard_set.xml b/java/res/xml-pl/keyboard_set.xml
new file mode 100644
index 000000000..89bd72f1a
--- /dev/null
+++ b/java/res/xml-pl/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-pt/kbd_qwerty.xml b/java/res/xml-pt/kbd_qwerty.xml
deleted file mode 100644
index f5dcbc61b..000000000
--- a/java/res/xml-pt/kbd_qwerty.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
diff --git a/java/res/xml-pt/keyboard_set.xml b/java/res/xml-pt/keyboard_set.xml
new file mode 100644
index 000000000..de31e0be5
--- /dev/null
+++ b/java/res/xml-pt/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-ru/kbd_qwerty.xml b/java/res/xml-ru/kbd_qwerty.xml
deleted file mode 100644
index aee1b1bfc..000000000
--- a/java/res/xml-ru/kbd_qwerty.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
diff --git a/java/res/xml-ru/keyboard_set.xml b/java/res/xml-ru/keyboard_set.xml
new file mode 100644
index 000000000..eabee5dc3
--- /dev/null
+++ b/java/res/xml-ru/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-sr/keyboard_set.xml b/java/res/xml-sr/keyboard_set.xml
new file mode 100644
index 000000000..e72a0f23f
--- /dev/null
+++ b/java/res/xml-sr/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-sv/kbd_qwerty.xml b/java/res/xml-sv/kbd_qwerty.xml
deleted file mode 100644
index e29d9abce..000000000
--- a/java/res/xml-sv/kbd_qwerty.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
diff --git a/java/res/xml-sv/keyboard_set.xml b/java/res/xml-sv/keyboard_set.xml
new file mode 100644
index 000000000..df06aef68
--- /dev/null
+++ b/java/res/xml-sv/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-tr/kbd_qwerty.xml b/java/res/xml-tr/kbd_qwerty.xml
deleted file mode 100644
index d2c38f60a..000000000
--- a/java/res/xml-tr/kbd_qwerty.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
diff --git a/java/res/xml-tr/keyboard_set.xml b/java/res/xml-tr/keyboard_set.xml
new file mode 100644
index 000000000..854ab8566
--- /dev/null
+++ b/java/res/xml-tr/keyboard_set.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/res/xml-ar/kbd_qwerty.xml b/java/res/xml/kbd_arabic.xml
similarity index 96%
rename from java/res/xml-ar/kbd_qwerty.xml
rename to java/res/xml/kbd_arabic.xml
index b26a938cc..91b22810b 100644
--- a/java/res/xml-ar/kbd_qwerty.xml
+++ b/java/res/xml/kbd_arabic.xml
@@ -20,7 +20,6 @@
diff --git a/java/res/xml-iw/kbd_qwerty.xml b/java/res/xml/kbd_hebrew.xml
similarity index 91%
rename from java/res/xml-iw/kbd_qwerty.xml
rename to java/res/xml/kbd_hebrew.xml
index 54cd4b5e9..f25aaddfa 100644
--- a/java/res/xml-iw/kbd_qwerty.xml
+++ b/java/res/xml/kbd_hebrew.xml
@@ -2,7 +2,7 @@
+
+
+
+
+
+
+
+
+
diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java
index dbe7aec6a..e75e14861 100644
--- a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java
+++ b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java
@@ -17,7 +17,7 @@
package com.android.inputmethod.deprecated.languageswitcher;
import com.android.inputmethod.compat.SharedPreferencesCompat;
-import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
+import com.android.inputmethod.keyboard.KeyboardSet;
import com.android.inputmethod.latin.DictionaryFactory;
import com.android.inputmethod.latin.LocaleUtils;
import com.android.inputmethod.latin.R;
@@ -162,8 +162,8 @@ public class InputLanguageSelection extends PreferenceActivity {
try {
final String localeStr = locale.toString();
- final String[] layoutCountryCodes = KeyboardBuilder.parseKeyboardLocale(
- this, R.xml.kbd_qwerty).split(",", -1);
+ final String[] layoutCountryCodes = KeyboardSet.parseKeyboardLocale(
+ getResources(), R.xml.keyboard_set).split(",", -1);
if (!TextUtils.isEmpty(localeStr) && layoutCountryCodes.length > 0) {
for (String s : layoutCountryCodes) {
if (s.equals(localeStr)) {
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
index ecc821a4b..44c0c9337 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
@@ -21,11 +21,11 @@ import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.compat.InputTypeCompatUtils;
-import com.android.inputmethod.latin.R;
import java.util.Arrays;
import java.util.Locale;
+// TODO: Move to com.android.inputmethod.keyboard.internal package.
/**
* Represents the parameters necessary to construct a new LatinKeyboard,
* which also serve as a unique identifier for each keyboard type.
@@ -38,6 +38,20 @@ public class KeyboardId {
public static final int MODE_PHONE = 4;
public static final int MODE_NUMBER = 5;
+ public static final int ELEMENT_ALPHABET = 0;
+ /* TODO: Implement alphabet variant shift keyboard.
+ public static final int ELEMENT_ALPHABET_MANUAL_TEMPORARY_SHIFT = 1;
+ public static final int ELEMENT_ALPHABET_AUTOMATIC_TEMPORARY_SHIFT = 2;
+ public static final int ELEMENT_ALPHABET_SHIFT_LOCK = 3;
+ public static final int ELEMENT_ALPHABET_SHIFT_LOCK_SHIFT = 4;
+ */
+ public static final int ELEMENT_SYMBOLS = 5;
+ public static final int ELEMENT_SYMBOLS_SHIFT = 6;
+ public static final int ELEMENT_PHONE = 7;
+ public static final int ELEMENT_PHONE_SHIFT = 8;
+ public static final int ELEMENT_NUMBER = 9;
+
+ // TODO: These constants could be private.
public static final int F2KEY_MODE_NONE = 0;
public static final int F2KEY_MODE_SETTINGS = 1;
public static final int F2KEY_MODE_SHORTCUT_IME = 2;
@@ -47,7 +61,9 @@ public class KeyboardId {
public final int mOrientation;
public final int mWidth;
public final int mMode;
- public final int mXmlId;
+ // TODO: Remove this field.
+ private final int mXmlId;
+ public final int mElementState;
public final boolean mNavigateAction;
public final boolean mPasswordInput;
// TODO: Clean up these booleans and modes.
@@ -58,16 +74,18 @@ public class KeyboardId {
public final boolean mHasShortcutKey;
public final int mImeAction;
- public final String mXmlName;
- public final EditorInfo mEditorInfo;
+ // TODO: Remove this field.
+ private final EditorInfo mEditorInfo;
private final int mHashCode;
- public KeyboardId(String xmlName, int xmlId, Locale locale, int orientation, int width,
+ // TODO: The hasSettings, f2KeyMode, and clobberSettingsKey arguments could be reduced.
+ public KeyboardId(int xmlId, int elementState, Locale locale, int orientation, int width,
int mode, EditorInfo editorInfo, boolean hasSettingsKey, int f2KeyMode,
boolean clobberSettingsKey, boolean shortcutKeyEnabled, boolean hasShortcutKey) {
final int inputType = (editorInfo != null) ? editorInfo.inputType : 0;
final int imeOptions = (editorInfo != null) ? editorInfo.imeOptions : 0;
+ this.mElementState = elementState;
this.mLocale = locale;
this.mOrientation = orientation;
this.mWidth = width;
@@ -89,7 +107,6 @@ public class KeyboardId {
this.mImeAction = imeOptions & (
EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION);
- this.mXmlName = xmlName;
this.mEditorInfo = editorInfo;
this.mHashCode = Arrays.hashCode(new Object[] {
@@ -98,6 +115,7 @@ public class KeyboardId {
width,
mode,
xmlId,
+ elementState,
mNavigateAction,
mPasswordInput,
hasSettingsKey,
@@ -109,29 +127,31 @@ public class KeyboardId {
});
}
- public KeyboardId cloneWithNewXml(String xmlName, int xmlId) {
- return new KeyboardId(xmlName, xmlId, mLocale, mOrientation, mWidth, mMode, mEditorInfo,
- false, F2KEY_MODE_NONE, false, false, false);
+ public KeyboardId cloneWithNewXml(int xmlId) {
+ return new KeyboardId(xmlId, mElementState, mLocale,
+ mOrientation, mWidth, mMode, mEditorInfo, false, F2KEY_MODE_NONE, false, false,
+ false);
}
+ // Remove this method.
public int getXmlId() {
return mXmlId;
}
public boolean isAlphabetKeyboard() {
- return mXmlId == R.xml.kbd_qwerty;
+ return mElementState < ELEMENT_SYMBOLS;
}
public boolean isSymbolsKeyboard() {
- return mXmlId == R.xml.kbd_symbols || mXmlId == R.xml.kbd_symbols_shift;
+ return mElementState == ELEMENT_SYMBOLS || mElementState == ELEMENT_SYMBOLS_SHIFT;
}
public boolean isPhoneKeyboard() {
- return mMode == MODE_PHONE;
+ return mElementState == ELEMENT_PHONE || mElementState == ELEMENT_PHONE_SHIFT;
}
public boolean isPhoneShiftKeyboard() {
- return mXmlId == R.xml.kbd_phone_shift;
+ return mElementState == ELEMENT_PHONE_SHIFT;
}
@Override
@@ -145,6 +165,7 @@ public class KeyboardId {
&& other.mWidth == this.mWidth
&& other.mMode == this.mMode
&& other.mXmlId == this.mXmlId
+ && other.mElementState == this.mElementState
&& other.mNavigateAction == this.mNavigateAction
&& other.mPasswordInput == this.mPasswordInput
&& other.mHasSettingsKey == this.mHasSettingsKey
@@ -162,8 +183,8 @@ public class KeyboardId {
@Override
public String toString() {
- return String.format("[%s.xml %s %s%d %s %s %s%s%s%s%s%s%s]",
- mXmlName,
+ return String.format("[%s %s %s%d %s %s %s%s%s%s%s%s%s]",
+ elementStateToString(mElementState),
mLocale,
(mOrientation == 1 ? "port" : "land"), mWidth,
modeName(mMode),
@@ -186,6 +207,24 @@ public class KeyboardId {
&& TextUtils.equals(a.privateImeOptions, b.privateImeOptions);
}
+ public static String elementStateToString(int elementState) {
+ switch (elementState) {
+ case ELEMENT_ALPHABET: return "alphabet";
+ /* TODO: Implement alphabet variant shift keyboard.
+ case ELEMENT_ALPHABET_MANUAL_TEMPORARY_SHIFT: return "alphabetManualTemporaryShift";
+ case ELEMENT_ALPHABET_AUTOMATIC_TEMPORARY_SHIFT: return "alphabetAutomaticTemporaryShift";
+ case ELEMENT_ALPHABET_SHIFT_LOCK: return "alphabetShiftLock";
+ case ELEMENT_ALPHABET_SHIFT_LOCK_SHIFT: return "alphabetShiftLockShift";
+ */
+ case ELEMENT_SYMBOLS: return "symbols";
+ case ELEMENT_SYMBOLS_SHIFT: return "symbolsShift";
+ case ELEMENT_PHONE: return "phone";
+ case ELEMENT_PHONE_SHIFT: return "phoneShift";
+ case ELEMENT_NUMBER: return "number";
+ default: return null;
+ }
+ }
+
public static String modeName(int mode) {
switch (mode) {
case MODE_TEXT: return "text";
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
index a803188da..0697c187e 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
@@ -19,15 +19,28 @@ package com.android.inputmethod.keyboard;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.content.res.XmlResourceParser;
import android.util.DisplayMetrics;
+import android.util.Xml;
import android.view.inputmethod.EditorInfo;
+import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
+import com.android.inputmethod.keyboard.internal.KeyboardBuilder.IllegalEndTag;
+import com.android.inputmethod.keyboard.internal.KeyboardBuilder.IllegalStartTag;
+import com.android.inputmethod.keyboard.internal.KeyboardBuilder.ParseException;
import com.android.inputmethod.latin.LatinIME;
+import com.android.inputmethod.latin.LocaleUtils;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SettingsValues;
import com.android.inputmethod.latin.SubtypeSwitcher;
import com.android.inputmethod.latin.Utils;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.IOException;
+import java.util.HashMap;
import java.util.Locale;
/**
@@ -37,6 +50,9 @@ import java.util.Locale;
* A {@link KeyboardSet} needs to be created for each {@link android.view.inputmethod.EditorInfo}.
*/
public class KeyboardSet {
+ private static final String TAG_KEYBOARD_SET = "KeyboardSet";
+ private static final String TAG_ELEMENT = "Element";
+
// TODO: Make these KeyboardId private.
public final KeyboardId mAlphabetId;
public final KeyboardId mSymbolsId;
@@ -52,6 +68,9 @@ public class KeyboardSet {
private final Resources mResources;
private final EditorInfo mEditorInfo;
+ private final HashMap mElementKeyboards =
+ new HashMap();
+
private final int mMode;
private final boolean mVoiceKeyEnabled;
private final boolean mNoSettingsKey;
@@ -91,31 +110,42 @@ public class KeyboardSet {
}
public KeyboardSet build() {
+ final Locale savedLocale = LocaleUtils.setSystemLocale(mResources, mLocale);
+ try {
+ parseKeyboardSet(mResources, R.xml.keyboard_set);
+ } catch (Exception e) {
+ //
+ } finally {
+ LocaleUtils.setSystemLocale(mResources, savedLocale);
+ }
return new KeyboardSet(this);
}
KeyboardId getKeyboardId(boolean isSymbols, boolean isShift) {
- final int xmlId = getXmlId(mMode, isSymbols, isShift);
- final boolean hasShortCutKey = mVoiceKeyEnabled && (isSymbols != mVoiceKeyOnMain);
- return new KeyboardId(mResources.getResourceEntryName(xmlId), xmlId, mLocale,
- mConf.orientation, mMetrics.widthPixels, mMode, mEditorInfo, mHasSettingsKey,
- mF2KeyMode, mNoSettingsKey, mVoiceKeyEnabled, hasShortCutKey);
+ final int elementState = getElementState(mMode, isSymbols, isShift);
+ final int xmlId = mElementKeyboards.get(elementState);
+ final boolean hasShortcutKey = mVoiceKeyEnabled && (isSymbols != mVoiceKeyOnMain);
+ return new KeyboardId(xmlId, elementState, mLocale, mConf.orientation,
+ mMetrics.widthPixels, mMode, mEditorInfo, mHasSettingsKey, mF2KeyMode,
+ mNoSettingsKey, mVoiceKeyEnabled, hasShortcutKey);
}
- private static int getXmlId(int mode, boolean isSymbols, boolean isShift) {
+ private static int getElementState(int mode, boolean isSymbols, boolean isShift) {
switch (mode) {
case KeyboardId.MODE_PHONE:
- return (isSymbols && isShift) ? R.xml.kbd_phone_shift : R.xml.kbd_phone;
+ return (isSymbols && isShift)
+ ? KeyboardId.ELEMENT_PHONE_SHIFT : KeyboardId.ELEMENT_PHONE;
case KeyboardId.MODE_NUMBER:
- return R.xml.kbd_number;
+ return KeyboardId.ELEMENT_NUMBER;
default:
if (isSymbols) {
- return isShift ? R.xml.kbd_symbols_shift : R.xml.kbd_symbols;
+ return isShift ? KeyboardId.ELEMENT_SYMBOLS_SHIFT : KeyboardId.ELEMENT_SYMBOLS;
}
- return R.xml.kbd_qwerty;
+ return KeyboardId.ELEMENT_ALPHABET;
}
}
+ // TODO: Move to KeyboardId.
private static int getF2KeyMode(boolean settingsKeyEnabled, boolean noSettingsKey) {
if (noSettingsKey) {
// Never shows the Settings key
@@ -130,5 +160,95 @@ public class KeyboardSet {
return KeyboardId.F2KEY_MODE_SHORTCUT_IME_OR_SETTINGS;
}
}
+
+ private void parseKeyboardSet(Resources res, int resId) throws XmlPullParserException,
+ IOException {
+ final XmlResourceParser parser = res.getXml(resId);
+ try {
+ int event;
+ while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) {
+ if (event == XmlPullParser.START_TAG) {
+ final String tag = parser.getName();
+ if (TAG_KEYBOARD_SET.equals(tag)) {
+ parseKeyboardSetContent(parser);
+ } else {
+ throw new IllegalStartTag(parser, TAG_KEYBOARD_SET);
+ }
+ }
+ }
+ } finally {
+ parser.close();
+ }
+ }
+
+ private void parseKeyboardSetContent(XmlPullParser parser) throws XmlPullParserException,
+ IOException {
+ int event;
+ while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) {
+ if (event == XmlPullParser.START_TAG) {
+ final String tag = parser.getName();
+ if (TAG_ELEMENT.equals(tag)) {
+ parseKeyboardSetElement(parser);
+ } else {
+ throw new IllegalStartTag(parser, TAG_KEYBOARD_SET);
+ }
+ } else if (event == XmlPullParser.END_TAG) {
+ final String tag = parser.getName();
+ if (TAG_KEYBOARD_SET.equals(tag)) {
+ break;
+ } else {
+ throw new IllegalEndTag(parser, TAG_KEYBOARD_SET);
+ }
+ }
+ }
+ }
+
+ private void parseKeyboardSetElement(XmlPullParser parser) throws XmlPullParserException,
+ IOException {
+ final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
+ R.styleable.KeyboardSet_Element);
+ try {
+ if (!a.hasValue(R.styleable.KeyboardSet_Element_elementName)) {
+ throw new ParseException(
+ "No elementName attribute in <" + TAG_ELEMENT + "/>", parser);
+ }
+ if (!a.hasValue(R.styleable.KeyboardSet_Element_elementKeyboard)) {
+ throw new ParseException(
+ "No elementKeyboard attribute in <" + TAG_ELEMENT + "/>", parser);
+ }
+ KeyboardBuilder.checkEndTag(TAG_ELEMENT, parser);
+
+ final int elementName = a.getInt(
+ R.styleable.KeyboardSet_Element_elementName, 0);
+ final int elementKeyboard = a.getResourceId(
+ R.styleable.KeyboardSet_Element_elementKeyboard, 0);
+ mElementKeyboards.put(elementName, elementKeyboard);
+ } finally {
+ a.recycle();
+ }
+ }
+ }
+
+ public static String parseKeyboardLocale(Resources res, int resId)
+ throws XmlPullParserException, IOException {
+ final XmlPullParser parser = res.getXml(resId);
+ if (parser == null) return "";
+ int event;
+ while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) {
+ if (event == XmlPullParser.START_TAG) {
+ final String tag = parser.getName();
+ if (TAG_KEYBOARD_SET.equals(tag)) {
+ final TypedArray keyboardSetAttr = res.obtainAttributes(
+ Xml.asAttributeSet(parser), R.styleable.KeyboardSet);
+ final String locale = keyboardSetAttr.getString(
+ R.styleable.KeyboardSet_keyboardLocale);
+ keyboardSetAttr.recycle();
+ return locale;
+ } else {
+ throw new IllegalStartTag(parser, TAG_KEYBOARD_SET);
+ }
+ }
+ }
+ return "";
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
index ac9290bfd..e0f21a247 100644
--- a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
@@ -207,7 +207,7 @@ public class MiniKeyboard extends Keyboard {
public Builder(KeyboardView view, int xmlId, Key parentKey, Keyboard parentKeyboard) {
super(view.getContext(), new MiniKeyboardParams());
- load(parentKeyboard.mId.cloneWithNewXml(mResources.getResourceEntryName(xmlId), xmlId));
+ load(parentKeyboard.mId.cloneWithNewXml(xmlId));
// TODO: Mini keyboard's vertical gap is currently calculated heuristically.
// Should revise the algorithm.
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index de64639b0..d9d9c2f83 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -292,7 +292,7 @@ public class KeyboardBuilder {
return new Keyboard(mParams);
}
- private void parseKeyboard(XmlResourceParser parser)
+ private void parseKeyboard(XmlPullParser parser)
throws XmlPullParserException, IOException {
if (DEBUG) Log.d(TAG, String.format("<%s> %s", TAG_KEYBOARD, mParams.mId));
int event;
@@ -311,30 +311,6 @@ public class KeyboardBuilder {
}
}
- public static String parseKeyboardLocale(
- Context context, int resId) throws XmlPullParserException, IOException {
- final Resources res = context.getResources();
- final XmlPullParser parser = res.getXml(resId);
- if (parser == null) return "";
- int event;
- while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) {
- if (event == XmlPullParser.START_TAG) {
- final String tag = parser.getName();
- if (TAG_KEYBOARD.equals(tag)) {
- final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
- R.styleable.Keyboard);
- final String locale = keyboardAttr.getString(
- R.styleable.Keyboard_keyboardLocale);
- keyboardAttr.recycle();
- return locale;
- } else {
- throw new IllegalStartTag(parser, TAG_KEYBOARD);
- }
- }
- }
- return "";
- }
-
private void parseKeyboardAttributes(XmlPullParser parser) {
final int displayWidth = mDisplayMetrics.widthPixels;
final TypedArray keyboardAttr = mContext.obtainStyledAttributes(
@@ -757,7 +733,7 @@ public class KeyboardBuilder {
}
}
- private static void checkEndTag(String tag, XmlPullParser parser)
+ public static void checkEndTag(String tag, XmlPullParser parser)
throws XmlPullParserException, IOException {
if (parser.next() == XmlPullParser.END_TAG && tag.equals(parser.getName()))
return;
@@ -856,14 +832,14 @@ public class KeyboardBuilder {
}
@SuppressWarnings("serial")
- private static class IllegalStartTag extends ParseException {
+ public static class IllegalStartTag extends ParseException {
public IllegalStartTag(XmlPullParser parser, String parent) {
super("Illegal start tag " + parser.getName() + " in " + parent, parser);
}
}
@SuppressWarnings("serial")
- private static class IllegalEndTag extends ParseException {
+ public static class IllegalEndTag extends ParseException {
public IllegalEndTag(XmlPullParser parser, String parent) {
super("Illegal end tag " + parser.getName() + " in " + parent, parser);
}
diff --git a/java/src/com/android/inputmethod/latin/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/MoreSuggestions.java
index 9a59ef2e0..86072b64b 100644
--- a/java/src/com/android/inputmethod/latin/MoreSuggestions.java
+++ b/java/src/com/android/inputmethod/latin/MoreSuggestions.java
@@ -178,7 +178,7 @@ public class MoreSuggestions extends Keyboard {
int minWidth, int maxRow) {
final Keyboard keyboard = KeyboardSwitcher.getInstance().getLatinKeyboard();
final int xmlId = R.xml.kbd_suggestions_pane_template;
- load(keyboard.mId.cloneWithNewXml(mResources.getResourceEntryName(xmlId), xmlId));
+ load(keyboard.mId.cloneWithNewXml(xmlId));
mParams.mVerticalGap = mParams.mTopPadding = keyboard.mVerticalGap / 2;
final int count = mParams.layout(suggestions, fromPos, maxWidth, minWidth, maxRow,
diff --git a/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java b/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java
index 058a3e7c0..7029dde6b 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java
@@ -50,10 +50,9 @@ public class SuggestTestsBase extends AndroidTestCase {
+ "orientation=" + orientation);
return null;
}
- return new KeyboardId(locale.toString() + " keyboard",
- com.android.inputmethod.latin.R.xml.kbd_qwerty, locale, orientation, width,
- KeyboardId.MODE_TEXT, new EditorInfo(), false, KeyboardId.F2KEY_MODE_NONE,
- false, false, false);
+ return new KeyboardId(com.android.inputmethod.latin.R.xml.kbd_qwerty,
+ KeyboardId.ELEMENT_ALPHABET, locale, orientation, width, KeyboardId.MODE_TEXT,
+ new EditorInfo(), false, KeyboardId.F2KEY_MODE_NONE, false, false, false);
}
protected InputStream openTestRawResource(int resIdInTest) {