aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2012-01-24 18:03:50 +0900
committerTadashi G. Takaoka <takaoka@google.com>2012-01-25 13:19:53 +0900
commit117c124c13f0e6af737b1858bd5c4d9e6e7eb353 (patch)
tree6eae8bb1c120650053515a12825c632e1f7cda31 /java/src
parentaf4efd5a3ec32d7f1bf61978286f3a7602ce5609 (diff)
downloadlatinime-117c124c13f0e6af737b1858bd5c4d9e6e7eb353.tar.gz
latinime-117c124c13f0e6af737b1858bd5c4d9e6e7eb353.tar.xz
latinime-117c124c13f0e6af737b1858bd5c4d9e6e7eb353.zip
Add autoGenerateFromAlphabet enum to KeyboardSet.Element.elementKeyboard
This is the first step to support separate Keyboard for elementName. This change is the second attempt of Icef66564. Change-Id: I78ea6cb9ea3d965ff89e0ff5d896a6b11ba5c670
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardId.java52
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSet.java89
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java2
3 files changed, 80 insertions, 63 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
index d95c3b3af..8db8c9460 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
@@ -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 mElementId;
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 elementId, 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.mElementId = elementId;
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.mElementId,
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.mElementId == this.mElementId
&& 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 mElementId < ELEMENT_SYMBOLS;
}
public boolean isSymbolsKeyboard() {
- return mElementState == ELEMENT_SYMBOLS || mElementState == ELEMENT_SYMBOLS_SHIFT;
+ return mElementId == ELEMENT_SYMBOLS || mElementId == ELEMENT_SYMBOLS_SHIFTED;
}
public boolean isPhoneKeyboard() {
- return mElementState == ELEMENT_PHONE || mElementState == ELEMENT_PHONE_SHIFT;
+ return mElementId == ELEMENT_PHONE || mElementId == ELEMENT_PHONE_SHIFTED;
}
public boolean isPhoneShiftKeyboard() {
- return mElementState == ELEMENT_PHONE_SHIFT;
+ return mElementId == 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),
+ elementIdToName(mElementId),
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 elementIdToName(int elementId) {
+ switch (elementId) {
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;
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
index 285252044..c7f964aaa 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
@@ -40,6 +40,7 @@ import java.io.IOException;
import java.lang.ref.SoftReference;
import java.util.HashMap;
import java.util.Locale;
+import java.util.Map;
/**
* This class represents a set of keyboards. Each of them represents a different keyboard
@@ -57,7 +58,18 @@ public class KeyboardSet {
private final Context mContext;
private final Params mParams;
- private static class Params {
+ static class KeyboardElement {
+ final int mElementId;
+ final int mLayoutId;
+ final boolean mAutoGenerate;
+ KeyboardElement(int elementId, int layoutId, boolean autoGenerate) {
+ mElementId = elementId;
+ mLayoutId = layoutId;
+ mAutoGenerate = autoGenerate;
+ }
+ }
+
+ static class Params {
int mMode;
int mInputType;
int mImeOptions;
@@ -69,7 +81,8 @@ public class KeyboardSet {
Locale mLocale;
int mOrientation;
int mWidth;
- final HashMap<Integer, Integer> mElementKeyboards = new HashMap<Integer, Integer>();
+ final Map<Integer, KeyboardElement> mElementKeyboards =
+ new HashMap<Integer, KeyboardElement>();
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();