Add autoGenerateFromAlphabet enum to KeyboardSet.Element.elementKeyboard

This is the first step to support separate Keyboard for elementName.

Change-Id: Icef66564b6938910fa06ecab664dce4be84c9505
main
Tadashi G. Takaoka 2012-01-24 18:03:50 +09:00
parent 25971b5a14
commit b5b92f9b78
34 changed files with 143 additions and 134 deletions

View File

@ -346,19 +346,20 @@
<!-- This should be aligned with KeyboardId.ELEMENT_* -->
<attr name="elementName" format="enum">
<enum name="alphabet" value="0" />
<!-- TODO: Implement alphabet variant shift keyboards
<enum name="alphabetManualTemporaryShift" value="1" />
<enum name="alphabetAutomaticTemporaryShift" value="2" />
<enum name="alphabetShiftLock" value="3" />
<enum name="alphabetShiftLockShift" value="4" />
-->
<enum name="alphabetManualShifted" value="1" />
<enum name="alphabetAutomaticShifted" value="2" />
<enum name="alphabetShiftLocked" value="3" />
<enum name="alphabetShiftLockShifted" value="4" />
<enum name="symbols" value="5" />
<enum name="symbolsShift" value="6" />
<enum name="symbolsShifted" value="6" />
<enum name="phone" value="7" />
<enum name="phoneShift" value="8" />
<enum name="phoneShifted" value="8" />
<enum name="number" value="9" />
</attr>
<attr name="elementKeyboard" format="reference" />
<attr name="elementKeyboard" format="reference|enum">
<!-- This should be aligned with KeyboardSet.ELEMENT_KEYBOARD_* -->
<enum name="autoGenerateFromAlphabet" value="1"/>
</attr>
<!-- TODO: Add setShifted and setShiftLocked attribute. -->
</declare-styleable>
</resources>

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -28,13 +28,13 @@
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShift"
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneShift"
latin:elementName="phoneShifted"
latin:elementKeyboard="@xml/kbd_phone_shift" />
<Element
latin:elementName="number"

View File

@ -39,16 +39,14 @@ public class KeyboardId {
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_ALPHABET_MANUAL_SHIFTED = 1;
public static final int ELEMENT_ALPHABET_AUTOMATIC_SHIFTED = 2;
public static final int ELEMENT_ALPHABET_SHIFT_LOCKED = 3;
public static final int ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED = 4;
public static final int ELEMENT_SYMBOLS = 5;
public static final int ELEMENT_SYMBOLS_SHIFT = 6;
public static final int ELEMENT_SYMBOLS_SHIFTED = 6;
public static final int ELEMENT_PHONE = 7;
public static final int ELEMENT_PHONE_SHIFT = 8;
public static final int ELEMENT_PHONE_SHIFTED = 8;
public static final int ELEMENT_NUMBER = 9;
private static final int F2KEY_MODE_NONE = 0;
@ -60,7 +58,7 @@ public class KeyboardId {
public final int mOrientation;
public final int mWidth;
public final int mMode;
public final int mElementState;
public final int mElement;
private final int mInputType;
private final int mImeOptions;
private final boolean mSettingsKeyEnabled;
@ -70,14 +68,14 @@ public class KeyboardId {
private final int mHashCode;
public KeyboardId(int elementState, Locale locale, int orientation, int width, int mode,
public KeyboardId(int element, Locale locale, int orientation, int width, int mode,
int inputType, int imeOptions, boolean settingsKeyEnabled, boolean clobberSettingsKey,
boolean shortcutKeyEnabled, boolean hasShortcutKey) {
this.mLocale = locale;
this.mOrientation = orientation;
this.mWidth = width;
this.mMode = mode;
this.mElementState = elementState;
this.mElement = element;
this.mInputType = inputType;
this.mImeOptions = imeOptions;
this.mSettingsKeyEnabled = settingsKeyEnabled;
@ -91,7 +89,7 @@ public class KeyboardId {
private static int hashCode(KeyboardId id) {
return Arrays.hashCode(new Object[] {
id.mOrientation,
id.mElementState,
id.mElement,
id.mMode,
id.mWidth,
id.navigateAction(),
@ -109,7 +107,7 @@ public class KeyboardId {
if (other == this)
return true;
return other.mOrientation == this.mOrientation
&& other.mElementState == this.mElementState
&& other.mElement == this.mElement
&& other.mMode == this.mMode
&& other.mWidth == this.mWidth
&& other.navigateAction() == this.navigateAction()
@ -123,19 +121,19 @@ public class KeyboardId {
}
public boolean isAlphabetKeyboard() {
return mElementState < ELEMENT_SYMBOLS;
return mElement < ELEMENT_SYMBOLS;
}
public boolean isSymbolsKeyboard() {
return mElementState == ELEMENT_SYMBOLS || mElementState == ELEMENT_SYMBOLS_SHIFT;
return mElement == ELEMENT_SYMBOLS || mElement == ELEMENT_SYMBOLS_SHIFTED;
}
public boolean isPhoneKeyboard() {
return mElementState == ELEMENT_PHONE || mElementState == ELEMENT_PHONE_SHIFT;
return mElement == ELEMENT_PHONE || mElement == ELEMENT_PHONE_SHIFTED;
}
public boolean isPhoneShiftKeyboard() {
return mElementState == ELEMENT_PHONE_SHIFT;
return mElement == ELEMENT_PHONE_SHIFTED;
}
public boolean navigateAction() {
@ -190,7 +188,7 @@ public class KeyboardId {
@Override
public String toString() {
return String.format("[%s %s %s%d %s %s %s%s%s%s%s%s%s]",
elementStateToString(mElementState),
elementToString(mElement),
mLocale,
(mOrientation == 1 ? "port" : "land"), mWidth,
modeName(mMode),
@ -213,19 +211,17 @@ public class KeyboardId {
&& TextUtils.equals(a.privateImeOptions, b.privateImeOptions);
}
public static String elementStateToString(int elementState) {
switch (elementState) {
public static String elementToString(int element) {
switch (element) {
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_ALPHABET_MANUAL_SHIFTED: return "alphabetManualShifted";
case ELEMENT_ALPHABET_AUTOMATIC_SHIFTED: return "alphabetAutomaticShifted";
case ELEMENT_ALPHABET_SHIFT_LOCKED: return "alphabetShiftLocked";
case ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED: return "alphabetShiftLockShifted";
case ELEMENT_SYMBOLS: return "symbols";
case ELEMENT_SYMBOLS_SHIFT: return "symbolsShift";
case ELEMENT_SYMBOLS_SHIFTED: return "symbolsShifted";
case ELEMENT_PHONE: return "phone";
case ELEMENT_PHONE_SHIFT: return "phoneShift";
case ELEMENT_PHONE_SHIFTED: return "phoneShifted";
case ELEMENT_NUMBER: return "number";
default: return null;
}

View File

@ -22,6 +22,7 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.util.Log;
import android.util.TypedValue;
import android.util.Xml;
import android.view.inputmethod.EditorInfo;
@ -54,10 +55,12 @@ public class KeyboardSet {
private static final String TAG_KEYBOARD_SET = TAG;
private static final String TAG_ELEMENT = "Element";
private static final int ELEMENT_KEYBOARD_AUTO_GENERATE_FROM_ALPHABET = 1;
private final Context mContext;
private final Params mParams;
private static class Params {
static class Params {
int mMode;
int mInputType;
int mImeOptions;
@ -104,16 +107,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 int element = KeyboardSet.getElement(mParams.mMode, isSymbols, isShift);
// TODO: If xmlId is ELEMENT_KEYBOARD_AUTO_GENERATE_FROM_ALPHABET, auto generate the
// keyboard based on base main alphabet keyboard considering element.
final int xmlId = mParams.mElementKeyboards.get(element);
final KeyboardId id = KeyboardSet.getKeyboardId(element, isSymbols, mParams);
final Keyboard keyboard = getKeyboard(mContext, xmlId, id);
return keyboard;
}
public KeyboardId getMainKeyboardId() {
final int elementState = Builder.getElementState(mParams.mMode, false, false);
return Builder.getKeyboardId(elementState, false, mParams);
final int element = KeyboardSet.getElement(mParams.mMode, false, false);
return KeyboardSet.getKeyboardId(element, false, mParams);
}
private Keyboard getKeyboard(Context context, int xmlId, KeyboardId id) {
@ -147,6 +152,30 @@ public class KeyboardSet {
return keyboard;
}
private static int getElement(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 element, boolean isSymbols, Params params) {
final boolean hasShortcutKey = params.mVoiceKeyEnabled
&& (isSymbols != params.mVoiceKeyOnMain);
return new KeyboardId(element, 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;
@ -218,31 +247,6 @@ public class KeyboardSet {
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);
@ -300,8 +304,14 @@ public class KeyboardSet {
final int elementName = a.getInt(
R.styleable.KeyboardSet_Element_elementName, 0);
final int elementKeyboard = a.getResourceId(
R.styleable.KeyboardSet_Element_elementKeyboard, 0);
final int index = R.styleable.KeyboardSet_Element_elementKeyboard;
final TypedValue v = a.peekValue(index);
final int elementKeyboard;
if (v.type == TypedValue.TYPE_REFERENCE) {
elementKeyboard = a.getResourceId(index, 0);
} else {
elementKeyboard = a.getInt(index, 0);
}
mParams.mElementKeyboards.put(elementName, elementKeyboard);
} finally {
a.recycle();

View File

@ -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();