diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index 57930c675..57aa5ddf5 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -345,20 +345,19 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
+
+
diff --git a/java/res/xml-ar/keyboard_set.xml b/java/res/xml-ar/keyboard_set.xml
index 68dc34fe3..a8aac169b 100644
--- a/java/res/xml-ar/keyboard_set.xml
+++ b/java/res/xml-ar/keyboard_set.xml
@@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
+
+
+
+
mElementKeyboards = new HashMap();
+ final Map mElementKeyboards =
+ new HashMap();
Params() {}
}
@@ -104,16 +117,18 @@ public class KeyboardSet {
}
private Keyboard getKeyboard(boolean isSymbols, boolean isShift) {
- final int elementState = Builder.getElementState(mParams.mMode, isSymbols, isShift);
- final int xmlId = mParams.mElementKeyboards.get(elementState);
- final KeyboardId id = Builder.getKeyboardId(elementState, isSymbols, mParams);
- final Keyboard keyboard = getKeyboard(mContext, xmlId, id);
+ final int elementId = KeyboardSet.getElementId(mParams.mMode, isSymbols, isShift);
+ final KeyboardElement keyboardElement = mParams.mElementKeyboards.get(elementId);
+ // TODO: If keyboardElement.mAutoGenerate is true, the keyboard will be auto generated
+ // based on keyboardElement.mKayoutId Keyboard XML definition.
+ final KeyboardId id = KeyboardSet.getKeyboardId(elementId, isSymbols, mParams);
+ final Keyboard keyboard = getKeyboard(mContext, keyboardElement.mLayoutId, id);
return keyboard;
}
public KeyboardId getMainKeyboardId() {
- final int elementState = Builder.getElementState(mParams.mMode, false, false);
- return Builder.getKeyboardId(elementState, false, mParams);
+ final int elementId = KeyboardSet.getElementId(mParams.mMode, false, false);
+ return KeyboardSet.getKeyboardId(elementId, false, mParams);
}
private Keyboard getKeyboard(Context context, int xmlId, KeyboardId id) {
@@ -147,6 +162,30 @@ public class KeyboardSet {
return keyboard;
}
+ private static int getElementId(int mode, boolean isSymbols, boolean isShift) {
+ switch (mode) {
+ case KeyboardId.MODE_PHONE:
+ return (isSymbols && isShift)
+ ? KeyboardId.ELEMENT_PHONE_SHIFTED : KeyboardId.ELEMENT_PHONE;
+ case KeyboardId.MODE_NUMBER:
+ return KeyboardId.ELEMENT_NUMBER;
+ default:
+ if (isSymbols) {
+ return isShift
+ ? KeyboardId.ELEMENT_SYMBOLS_SHIFTED : KeyboardId.ELEMENT_SYMBOLS;
+ }
+ return KeyboardId.ELEMENT_ALPHABET;
+ }
+ }
+
+ private static KeyboardId getKeyboardId(int elementId, boolean isSymbols, Params params) {
+ final boolean hasShortcutKey = params.mVoiceKeyEnabled
+ && (isSymbols != params.mVoiceKeyOnMain);
+ return new KeyboardId(elementId, params.mLocale, params.mOrientation, params.mWidth,
+ params.mMode, params.mInputType, params.mImeOptions, params.mSettingsKeyEnabled,
+ params.mNoSettingsKey, params.mVoiceKeyEnabled, hasShortcutKey);
+ }
+
public static class Builder {
private final Context mContext;
private final String mPackageName;
@@ -211,38 +250,15 @@ public class KeyboardSet {
try {
parseKeyboardSet(mResources, R.xml.keyboard_set);
} catch (Exception e) {
- //
+ throw new RuntimeException(e.getMessage() + " in "
+ + mResources.getResourceName(R.xml.keyboard_set)
+ + " of locale " + mParams.mLocale);
} finally {
LocaleUtils.setSystemLocale(mResources, savedLocale);
}
return new KeyboardSet(mContext, mParams);
}
- // TODO: Move this method to KeyboardSet
- static KeyboardId getKeyboardId(int elementState, boolean isSymbols, Params params) {
- final boolean hasShortcutKey = params.mVoiceKeyEnabled
- && (isSymbols != params.mVoiceKeyOnMain);
- return new KeyboardId(elementState, params.mLocale, params.mOrientation, params.mWidth,
- params.mMode, params.mInputType, params.mImeOptions, params.mSettingsKeyEnabled,
- params.mNoSettingsKey, params.mVoiceKeyEnabled, hasShortcutKey);
- }
-
- // TODO: Move this method to KeyboardSet
- static int getElementState(int mode, boolean isSymbols, boolean isShift) {
- switch (mode) {
- case KeyboardId.MODE_PHONE:
- return (isSymbols && isShift)
- ? KeyboardId.ELEMENT_PHONE_SHIFT : KeyboardId.ELEMENT_PHONE;
- case KeyboardId.MODE_NUMBER:
- return KeyboardId.ELEMENT_NUMBER;
- default:
- if (isSymbols) {
- return isShift ? KeyboardId.ELEMENT_SYMBOLS_SHIFT : KeyboardId.ELEMENT_SYMBOLS;
- }
- return KeyboardId.ELEMENT_ALPHABET;
- }
- }
-
private void parseKeyboardSet(Resources res, int resId) throws XmlPullParserException,
IOException {
final XmlResourceParser parser = res.getXml(resId);
@@ -302,7 +318,10 @@ public class KeyboardSet {
R.styleable.KeyboardSet_Element_elementName, 0);
final int elementKeyboard = a.getResourceId(
R.styleable.KeyboardSet_Element_elementKeyboard, 0);
- mParams.mElementKeyboards.put(elementName, elementKeyboard);
+ final boolean elementAutoGenerate = a.getBoolean(
+ R.styleable.KeyboardSet_Element_elementAutoGenerate, false);
+ mParams.mElementKeyboards.put(elementName, new KeyboardElement(
+ elementName, elementKeyboard, elementAutoGenerate));
} finally {
a.recycle();
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
index bc8b7e3f7..38c31adce 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
@@ -43,6 +43,8 @@ public class KeyboardState {
public void setAlphabetManualShiftedKeyboard();
public void setAlphabetAutomaticShiftedKeyboard();
public void setAlphabetShiftLockedKeyboard();
+ // TODO: Add this.
+ //public void setAlphabetShiftLockShiftedKeyboard();
public void setSymbolsKeyboard();
public void setSymbolsShiftedKeyboard();