aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/BaseKeyboard.java55
-rw-r--r--java/src/com/android/inputmethod/latin/BaseKeyboardParser.java197
-rw-r--r--java/src/com/android/inputmethod/latin/KeyboardSwitcher.java162
-rw-r--r--java/src/com/android/inputmethod/latin/LatinKeyboard.java11
4 files changed, 248 insertions, 177 deletions
diff --git a/java/src/com/android/inputmethod/latin/BaseKeyboard.java b/java/src/com/android/inputmethod/latin/BaseKeyboard.java
index e5b2756d4..be0a6a28a 100644
--- a/java/src/com/android/inputmethod/latin/BaseKeyboard.java
+++ b/java/src/com/android/inputmethod/latin/BaseKeyboard.java
@@ -16,6 +16,8 @@
package com.android.inputmethod.latin;
+import com.android.inputmethod.latin.KeyboardSwitcher.KeyboardId;
+
import org.xmlpull.v1.XmlPullParserException;
import android.content.Context;
@@ -103,8 +105,7 @@ public class BaseKeyboard {
/** Height of the screen */
private final int mDisplayHeight;
- /** Keyboard mode, or zero, if none. */
- private final int mKeyboardMode;
+ protected final KeyboardId mId;
// Variables for pre-computing nearest keys.
@@ -139,9 +140,6 @@ public class BaseKeyboard {
*/
public int rowEdgeFlags;
- /** The keyboard mode for this row */
- public int mode;
-
private final BaseKeyboard parent;
private Row(BaseKeyboard parent) {
@@ -168,7 +166,6 @@ public class BaseKeyboard {
a = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.BaseKeyboard_Row);
rowEdgeFlags = a.getInt(R.styleable.BaseKeyboard_Row_rowEdgeFlags, 0);
- mode = a.getResourceId(R.styleable.BaseKeyboard_Row_keyboardMode, 0);
}
}
@@ -456,19 +453,32 @@ public class BaseKeyboard {
* @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
*/
public BaseKeyboard(Context context, int xmlLayoutResId) {
- this(context, xmlLayoutResId, 0);
+ this(context, xmlLayoutResId, null);
}
/**
- * Creates a keyboard from the given xml key layout file. Weeds out rows
- * that have a keyboard mode defined but don't match the specified mode.
+ * Creates a keyboard from the given keyboard identifier.
+ * @param context the application or service context
+ * @param id keyboard identifier
+ */
+ public BaseKeyboard(Context context, KeyboardId id) {
+ this(context, id.getXmlId(), id);
+ }
+
+ /**
+ * Creates a keyboard from the given xml key layout file.
* @param context the application or service context
* @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
- * @param modeId keyboard mode identifier
- * @param width sets width of keyboard
- * @param height sets height of keyboard
+ * @param id keyboard identifier
*/
- public BaseKeyboard(Context context, int xmlLayoutResId, int modeId, int width, int height) {
+ private BaseKeyboard(Context context, int xmlLayoutResId, KeyboardId id) {
+ this(context, xmlLayoutResId, id,
+ context.getResources().getDisplayMetrics().widthPixels,
+ context.getResources().getDisplayMetrics().heightPixels);
+ }
+
+ private BaseKeyboard(Context context, int xmlLayoutResId, KeyboardId id, int width,
+ int height) {
Resources res = context.getResources();
GRID_WIDTH = res.getInteger(R.integer.config_keyboard_grid_width);
GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height);
@@ -481,24 +491,11 @@ public class BaseKeyboard {
setKeyWidth(mDisplayWidth / 10);
mDefaultVerticalGap = 0;
mDefaultHeight = mDefaultWidth;
- mKeyboardMode = modeId;
+ mId = id;
loadKeyboard(context, xmlLayoutResId);
}
/**
- * Creates a keyboard from the given xml key layout file. Weeds out rows
- * that have a keyboard mode defined but don't match the specified mode.
- * @param context the application or service context
- * @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
- * @param modeId keyboard mode identifier
- */
- public BaseKeyboard(Context context, int xmlLayoutResId, int modeId) {
- this(context, xmlLayoutResId, modeId,
- context.getResources().getDisplayMetrics().widthPixels,
- context.getResources().getDisplayMetrics().heightPixels);
- }
-
- /**
* <p>Creates a blank keyboard from the given resource file and populates it with the specified
* characters in left-to-right, top-to-bottom fashion, using the specified number of columns.
* </p>
@@ -608,10 +605,6 @@ public class BaseKeyboard {
return mDisplayWidth;
}
- public int getKeyboardMode() {
- return mKeyboardMode;
- }
-
public boolean setShifted(boolean shiftState) {
for (final Key key : mShiftKeys) {
key.on = shiftState;
diff --git a/java/src/com/android/inputmethod/latin/BaseKeyboardParser.java b/java/src/com/android/inputmethod/latin/BaseKeyboardParser.java
index 628e764b5..496f65174 100644
--- a/java/src/com/android/inputmethod/latin/BaseKeyboardParser.java
+++ b/java/src/com/android/inputmethod/latin/BaseKeyboardParser.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
import com.android.inputmethod.latin.BaseKeyboard.Key;
import com.android.inputmethod.latin.BaseKeyboard.Row;
+import com.android.inputmethod.latin.KeyboardSwitcher.KeyboardId;
import org.xmlpull.v1.XmlPullParserException;
@@ -52,7 +53,7 @@ import java.util.List;
* ...
* &gt;/Keyboard&lt;
* </pre>
- * The xml file which is included in other file must have &gt;merge&lt; as root element, such as:
+ * The XML file which is included in other file must have &gt;merge&lt; as root element, such as:
* <pre>
* &gt;!-- xml/other_keys.xml --&lt;
* &gt;merge&lt;
@@ -70,6 +71,38 @@ import java.util.List;
* ...
* &gt;/merge&lt;
* </pre>
+ * You can also use switch-case-default tags to select Rows and Keys.
+ * <pre>
+ * &gt;switch&lt;
+ * &gt;case case_attribute*&lt;
+ * &gt;!-- Any valid tags at switch position --&lt;
+ * &gt;/case&lt;
+ * ...
+ * &gt;default&lt;
+ * &gt;!-- Any valid tags at switch position --&lt;
+ * &gt;/default&lt;
+ * &gt;/switch&lt;
+ * </pre>
+ *
+ * TODO: These are some random ideas to improve this parser.
+ * - can specify keyWidth attribute by multiplication of default keyWidth
+ * for example: keyWidth="200%b" ("b" stands for "base")
+ * - can declare style and specify styles within tags.
+ * for example:
+ * &gt;switch&lt;
+ * &gt;case colorScheme="white"&lt;
+ * &gt;declare-style name="shift-key" parentStyle="modifier-key"&lt;
+ * &gt;item name="keyIcon"&lt;@drawable/sym_keyboard_shift"&gt;/item&lt;
+ * &gt;/declare-style&lt;
+ * &gt;/case&lt;
+ * &gt;case colorScheme="black"&lt;
+ * &gt;declare-style name="shift-key" parentStyle="modifier-key"&lt;
+ * &gt;item name="keyIcon"&lt;@drawable/sym_bkeyboard_shift"&gt;/item&lt;
+ * &gt;/declare-style&lt;
+ * &gt;/case&lt;
+ * &gt;/switch&lt;
+ * ...
+ * &gt;Key include-style="shift-key" ... /&lt;
*/
public class BaseKeyboardParser {
private static final String TAG = "BaseKeyboardParser";
@@ -83,6 +116,17 @@ public class BaseKeyboardParser {
private static final String TAG_SPACER = "Spacer";
private static final String TAG_INCLUDE = "include";
private static final String TAG_MERGE = "merge";
+ private static final String TAG_SWITCH = "switch";
+ private static final String TAG_CASE = "case";
+ private static final String TAG_DEFAULT = "default";
+
+ // String representation of KeyboardSwitcher.MODE_xxx.
+ private static final String MODE_TEXT = "text";
+ private static final String MODE_URL = "url";
+ private static final String MODE_EMAIL = "email";
+ private static final String MODE_IM = "im";
+ private static final String MODE_WEB = "web";
+ private static final String MODE_PHONE = "phone";
private final BaseKeyboard mKeyboard;
private final Resources mResources;
@@ -143,7 +187,7 @@ public class BaseKeyboardParser {
a.recycle();
}
- private void parseKeyboardContent(XmlResourceParser parser, final List<Key> keys)
+ private void parseKeyboardContent(XmlResourceParser parser, List<Key> keys)
throws XmlPullParserException, IOException {
if (DEBUG_PARSER) debugEnterMethod("parseKeyboardContent", keys == null);
int event;
@@ -153,14 +197,13 @@ public class BaseKeyboardParser {
if (DEBUG_TAG) debugStartTag("parseKeyboardContent", tag, keys == null);
if (TAG_ROW.equals(tag)) {
Row row = mKeyboard.createRowFromXml(mResources, parser);
- if (keys != null && maybeStartRow(row)) {
- parseRowContent(parser, row, keys);
- } else {
- // Skip entire <Row></Row>
- parseRowContent(parser, row, null);
- }
+ if (keys != null)
+ startRow(row);
+ parseRowContent(parser, row, keys);
} else if (TAG_INCLUDE.equals(tag)) {
parseIncludeKeyboardContent(parser, keys);
+ } else if (TAG_SWITCH.equals(tag)) {
+ parseSwitchKeyboardContent(parser, keys);
} else {
throw new IllegalStartTag(parser, TAG_ROW);
}
@@ -170,6 +213,8 @@ public class BaseKeyboardParser {
if (TAG_KEYBOARD.equals(tag)) {
endKeyboard(mKeyboard.getVerticalGap());
break;
+ } else if (TAG_CASE.equals(tag) || TAG_DEFAULT.equals(tag)) {
+ break;
} else if (TAG_MERGE.equals(tag)) {
break;
} else {
@@ -194,6 +239,8 @@ public class BaseKeyboardParser {
parseSpacer(parser, keys);
} else if (TAG_INCLUDE.equals(tag)) {
parseIncludeRowContent(parser, row, keys);
+ } else if (TAG_SWITCH.equals(tag)) {
+ parseSwitchRowContent(parser, row, keys);
} else {
throw new IllegalStartTag(parser, TAG_KEY);
}
@@ -204,6 +251,8 @@ public class BaseKeyboardParser {
if (keys != null)
endRow();
break;
+ } else if (TAG_CASE.equals(tag) || TAG_DEFAULT.equals(tag)) {
+ break;
} else if (TAG_MERGE.equals(tag)) {
break;
} else {
@@ -237,7 +286,7 @@ public class BaseKeyboardParser {
} else {
final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.BaseKeyboard);
- int gap = getDimensionOrFraction(a, R.styleable.BaseKeyboard_horizontalGap,
+ final int gap = getDimensionOrFraction(a, R.styleable.BaseKeyboard_horizontalGap,
mKeyboard.getKeyboardWidth(), 0);
a.recycle();
checkEndTag(TAG_SPACER, parser);
@@ -247,17 +296,20 @@ public class BaseKeyboardParser {
private void parseIncludeKeyboardContent(XmlResourceParser parser, List<Key> keys)
throws XmlPullParserException, IOException {
+ if (DEBUG_PARSER) debugEnterMethod("parseIncludeKeyboardContent", keys == null);
parseIncludeInternal(parser, null, keys);
+ if (DEBUG_PARSER) debugLeaveMethod("parseIncludeKeyboardContent", keys == null);
}
private void parseIncludeRowContent(XmlResourceParser parser, Row row, List<Key> keys)
throws XmlPullParserException, IOException {
+ if (DEBUG_PARSER) debugEnterMethod("parseIncludeRowContent", keys == null);
parseIncludeInternal(parser, row, keys);
+ if (DEBUG_PARSER) debugLeaveMethod("parseIncludeRowContent", keys == null);
}
private void parseIncludeInternal(XmlResourceParser parser, Row row, List<Key> keys)
throws XmlPullParserException, IOException {
- if (DEBUG_PARSER) debugEnterMethod("parseInclude", keys == null);
if (keys == null) {
checkEndTag(TAG_INCLUDE, parser);
} else {
@@ -272,7 +324,6 @@ public class BaseKeyboardParser {
throw new ParseException("No keyboardLayout attribute in <include/>", parser);
parseMerge(mResources.getLayout(keyboardLayout), row, keys);
}
- if (DEBUG_PARSER) debugLeaveMethod("parseInclude", keys == null);
}
private void parseMerge(XmlResourceParser parser, Row row, List<Key> keys)
@@ -281,7 +332,7 @@ public class BaseKeyboardParser {
int event;
while ((event = parser.next()) != XmlResourceParser.END_DOCUMENT) {
if (event == XmlResourceParser.START_TAG) {
- String tag = parser.getName();
+ final String tag = parser.getName();
if (DEBUG_TAG) debugStartTag("parseMerge", tag, keys == null);
if (TAG_MERGE.equals(tag)) {
if (row == null) {
@@ -299,6 +350,113 @@ public class BaseKeyboardParser {
if (DEBUG_PARSER) debugLeaveMethod("parseMerge", keys == null);
}
+ private void parseSwitchKeyboardContent(XmlResourceParser parser, List<Key> keys)
+ throws XmlPullParserException, IOException {
+ if (DEBUG_PARSER) debugEnterMethod("parseSwitchKeyboardContent", keys == null);
+ parseSwitchInternal(parser, null, keys);
+ if (DEBUG_PARSER) debugLeaveMethod("parseSwitchKeyboardContent", keys == null);
+ }
+
+ private void parseSwitchRowContent(XmlResourceParser parser, Row row, List<Key> keys)
+ throws XmlPullParserException, IOException {
+ if (DEBUG_PARSER) debugEnterMethod("parseSwitchRowContent", keys == null);
+ parseSwitchInternal(parser, row, keys);
+ if (DEBUG_PARSER) debugLeaveMethod("parseSwitchRowContent", keys == null);
+ }
+
+ private void parseSwitchInternal(XmlResourceParser parser, Row row, List<Key> keys)
+ throws XmlPullParserException, IOException {
+ boolean selected = false;
+ int event;
+ if (DEBUG_TAG) Log.d(TAG, "parseSwitchInternal: id=" + mKeyboard.mId);
+ while ((event = parser.next()) != XmlResourceParser.END_DOCUMENT) {
+ if (event == XmlResourceParser.START_TAG) {
+ final String tag = parser.getName();
+ if (DEBUG_TAG) debugStartTag("parseSwitchInternal", tag, keys == null);
+ if (TAG_CASE.equals(tag)) {
+ selected |= parseCase(parser, row, selected ? null : keys);
+ } else if (TAG_DEFAULT.equals(tag)) {
+ selected |= parseDefault(parser, row, selected ? null : keys);
+ } else {
+ throw new IllegalStartTag(parser, TAG_KEY);
+ }
+ } else if (event == XmlResourceParser.END_TAG) {
+ final String tag = parser.getName();
+ if (DEBUG_TAG) debugEndTag("parseRowContent", tag, keys == null);
+ if (TAG_SWITCH.equals(tag)) {
+ break;
+ } else {
+ throw new IllegalEndTag(parser, TAG_KEY);
+ }
+ }
+ }
+ }
+
+ private boolean parseCase(XmlResourceParser parser, Row row, List<Key> keys)
+ throws XmlPullParserException, IOException {
+ if (DEBUG_PARSER) debugEnterMethod("parseCase", keys == null);
+ final boolean selected = parseCaseCondition(parser);
+ if (row == null) {
+ // Processing Rows.
+ parseKeyboardContent(parser, selected ? keys : null);
+ } else {
+ // Processing Keys.
+ parseRowContent(parser, row, selected ? keys : null);
+ }
+ if (DEBUG_PARSER) debugLeaveMethod("parseCase", keys == null || !selected);
+ return selected;
+ }
+
+ private boolean parseCaseCondition(XmlResourceParser parser) {
+ final BaseKeyboard keyboard = mKeyboard;
+ final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
+ R.styleable.BaseKeyboard_Case);
+ final String mode = a.getString(R.styleable.BaseKeyboard_Case_mode);
+ final String settingsKey = a.getString(R.styleable.BaseKeyboard_Case_settingsKey);
+ final String voiceKey = a.getString(R.styleable.BaseKeyboard_Case_voiceKey);
+ a.recycle();
+
+ final KeyboardId id = keyboard.mId;
+ if (id == null)
+ return true;
+ final boolean modeMatched = (mode == null
+ || id.mMode == parseModeString(mode));
+ final boolean settingsKeyMatched = (settingsKey == null
+ || id.mHasSettingsKey == Boolean.parseBoolean(settingsKey));
+ final boolean voiceKeyMatched = (voiceKey == null
+ || id.mHasVoiceKey == Boolean.parseBoolean(voiceKey));
+ final boolean selected = modeMatched && settingsKeyMatched && voiceKeyMatched;
+ if (DEBUG_TAG) {
+ Log.d(TAG, "parseCaseCondition: " + Boolean.toString(selected).toUpperCase()
+ + (mode != null ? " mode=" + mode : "")
+ + (settingsKey != null ? " settingsKey="+settingsKey : "")
+ + (voiceKey != null ? " voiceKey=" + voiceKey : ""));
+ }
+ return selected;
+ }
+
+ private static int parseModeString(String mode) {
+ if (mode.equals(MODE_TEXT)) return KeyboardSwitcher.MODE_TEXT;
+ if (mode.equals(MODE_URL)) return KeyboardSwitcher.MODE_URL;
+ if (mode.equals(MODE_EMAIL)) return KeyboardSwitcher.MODE_EMAIL;
+ if (mode.equals(MODE_IM)) return KeyboardSwitcher.MODE_IM;
+ if (mode.equals(MODE_WEB)) return KeyboardSwitcher.MODE_WEB;
+ if (mode.equals(MODE_PHONE)) return KeyboardSwitcher.MODE_PHONE;
+ throw new RuntimeException("uknown mode attribute in Keyboard XML: " + mode);
+ }
+
+ private boolean parseDefault(XmlResourceParser parser, Row row, List<Key> keys)
+ throws XmlPullParserException, IOException {
+ if (DEBUG_PARSER) debugEnterMethod("parseDefault", keys == null);
+ if (row == null) {
+ parseKeyboardContent(parser, keys);
+ } else {
+ parseRowContent(parser, row, keys);
+ }
+ if (DEBUG_PARSER) debugLeaveMethod("parseDefault", keys == null);
+ return true;
+ }
+
private static void checkEndTag(String tag, XmlResourceParser parser)
throws XmlPullParserException, IOException {
if (parser.next() == XmlResourceParser.END_TAG && tag.equals(parser.getName()))
@@ -306,18 +464,9 @@ public class BaseKeyboardParser {
throw new NonEmptyTag(tag, parser);
}
- // return true if the row is valid for this keyboard mode
- private boolean maybeStartRow(Row row) {
- if (DEBUG_TAG)
- Log.d(TAG, String.format("startRow: mode=0x%08x keyboardMode=0x%08x",
- row.mode, mKeyboard.getKeyboardMode()));
- if (row.mode == 0 || row.mode == mKeyboard.getKeyboardMode()) {
- mCurrentX = 0;
- mCurrentRow = row;
- return true;
- } else {
- return false;
- }
+ private void startRow(Row row) {
+ mCurrentX = 0;
+ mCurrentRow = row;
}
private void endRow() {
diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
index 05bda6591..7307fcfbb 100644
--- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
@@ -40,76 +40,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
public static final int MODE_WEB = 4;
public static final int MODE_PHONE = 5;
- // Main keyboard layouts without the settings key
- private static final int KEYBOARDMODE_NORMAL = R.id.mode_normal;
- private static final int KEYBOARDMODE_URL = R.id.mode_url;
- private static final int KEYBOARDMODE_EMAIL = R.id.mode_email;
- private static final int KEYBOARDMODE_IM = R.id.mode_im;
- private static final int KEYBOARDMODE_WEB = R.id.mode_webentry;
- private static final int[] QWERTY_MODES = {
- KEYBOARDMODE_NORMAL,
- KEYBOARDMODE_URL,
- KEYBOARDMODE_EMAIL,
- KEYBOARDMODE_IM,
- KEYBOARDMODE_WEB,
- 0 /* for MODE_PHONE */ };
- // Main keyboard layouts with the settings key
- private static final int KEYBOARDMODE_NORMAL_WITH_SETTINGS_KEY =
- R.id.mode_normal_with_settings_key;
- private static final int KEYBOARDMODE_URL_WITH_SETTINGS_KEY =
- R.id.mode_url_with_settings_key;
- private static final int KEYBOARDMODE_EMAIL_WITH_SETTINGS_KEY =
- R.id.mode_email_with_settings_key;
- private static final int KEYBOARDMODE_IM_WITH_SETTINGS_KEY =
- R.id.mode_im_with_settings_key;
- private static final int KEYBOARDMODE_WEB_WITH_SETTINGS_KEY =
- R.id.mode_webentry_with_settings_key;
- private static final int[] QWERTY_WITH_SETTINGS_KEY_MODES = {
- KEYBOARDMODE_NORMAL_WITH_SETTINGS_KEY,
- KEYBOARDMODE_URL_WITH_SETTINGS_KEY,
- KEYBOARDMODE_EMAIL_WITH_SETTINGS_KEY,
- KEYBOARDMODE_IM_WITH_SETTINGS_KEY,
- KEYBOARDMODE_WEB_WITH_SETTINGS_KEY,
- 0 /* for MODE_PHONE */ };
- private static final int[][] QWERTY_KEYBOARD_MODES = {
- QWERTY_MODES, QWERTY_WITH_SETTINGS_KEY_MODES
- };
-
- // Symbols keyboard layouts without the settings key
- private static final int KEYBOARDMODE_SYMBOLS_NORMAL = R.id.mode_symbols_normal;
- private static final int KEYBOARDMODE_SYMBOLS_URL = R.id.mode_symbols_url;
- private static final int KEYBOARDMODE_SYMBOLS_EMAIL = R.id.mode_symbols_email;
- private static final int KEYBOARDMODE_SYMBOLS_IM = R.id.mode_symbols_im;
- private static final int KEYBOARDMODE_SYMBOLS_WEB = R.id.mode_symbols_webentry;
- private static final int[] SYMBOLS_MODES = {
- KEYBOARDMODE_SYMBOLS_NORMAL,
- KEYBOARDMODE_SYMBOLS_URL,
- KEYBOARDMODE_SYMBOLS_EMAIL,
- KEYBOARDMODE_SYMBOLS_IM,
- KEYBOARDMODE_SYMBOLS_WEB,
- 0 /* for MODE_PHONE */ };
- // Symbols keyboard layouts with the settings key
- private static final int KEYBOARDMODE_SYMBOLS_NORMAL_WITH_SETTINGS_KEY =
- R.id.mode_symbols_normal_with_settings_key;
- private static final int KEYBOARDMODE_SYMBOLS_URL_WITH_SETTINGS_KEY =
- R.id.mode_symbols_url_with_settings_key;
- private static final int KEYBOARDMODE_SYMBOLS_EMAIL_WITH_SETTINGS_KEY =
- R.id.mode_symbols_email_with_settings_key;
- private static final int KEYBOARDMODE_SYMBOLS_IM_WITH_SETTINGS_KEY =
- R.id.mode_symbols_im_with_settings_key;
- private static final int KEYBOARDMODE_SYMBOLS_WEB_WITH_SETTINGS_KEY =
- R.id.mode_symbols_webentry_with_settings_key;
- private static final int[] SYMBOLS_WITH_SETTINGS_KEY_MODES = {
- KEYBOARDMODE_SYMBOLS_NORMAL_WITH_SETTINGS_KEY,
- KEYBOARDMODE_SYMBOLS_URL_WITH_SETTINGS_KEY,
- KEYBOARDMODE_SYMBOLS_EMAIL_WITH_SETTINGS_KEY,
- KEYBOARDMODE_SYMBOLS_IM_WITH_SETTINGS_KEY,
- KEYBOARDMODE_SYMBOLS_WEB_WITH_SETTINGS_KEY,
- 0 /* for MODE_PHONE */ };
- private static final int[][] SYMBOLS_KEYBOARD_MODES = {
- SYMBOLS_MODES, SYMBOLS_WITH_SETTINGS_KEY_MODES
- };
-
public static final String DEFAULT_LAYOUT_ID = "4";
public static final String PREF_KEYBOARD_LAYOUT = "pref_keyboard_layout_20100902";
private static final int[] THEMES = new int [] {
@@ -121,14 +51,21 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
private static final int CHAR_THEME_COLOR_BLACK = 1;
// Tables which contains resource ids for each character theme color
- private static final int[] KBD_PHONE = new int[] {R.xml.kbd_phone, R.xml.kbd_phone_black};
+ private static final int[] KBD_PHONE = new int[] {
+ R.xml.kbd_phone, R.xml.kbd_phone_black
+ };
private static final int[] KBD_PHONE_SYMBOLS = new int[] {
- R.xml.kbd_phone_symbols, R.xml.kbd_phone_symbols_black};
+ R.xml.kbd_phone_symbols, R.xml.kbd_phone_symbols_black
+ };
private static final int[] KBD_SYMBOLS = new int[] {
- R.xml.kbd_symbols, R.xml.kbd_symbols_black};
+ R.xml.kbd_symbols, R.xml.kbd_symbols_black
+ };
private static final int[] KBD_SYMBOLS_SHIFT = new int[] {
- R.xml.kbd_symbols_shift, R.xml.kbd_symbols_shift_black};
- private static final int[] KBD_QWERTY = new int[] {R.xml.kbd_qwerty, R.xml.kbd_qwerty_black};
+ R.xml.kbd_symbols_shift, R.xml.kbd_symbols_shift_black
+ };
+ private static final int[] KBD_QWERTY = new int[] {
+ R.xml.kbd_qwerty, R.xml.kbd_qwerty_black
+ };
private static final int SYMBOLS_MODE_STATE_NONE = 0;
private static final int SYMBOLS_MODE_STATE_BEGIN = 1;
@@ -184,9 +121,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
final boolean hasSettingsKey = mHasSettingsKey;
final boolean hasVoiceKey = mVoiceButtonEnabled && !mVoiceButtonOnPrimary;
final int imeOptions = mImeOptions;
- mSymbolsId = new KeyboardId(locale, orientation, SYMBOLS_KEYBOARD_MODES, mode,
+ mSymbolsId = new KeyboardId(locale, orientation, mode,
KBD_SYMBOLS, colorScheme, hasSettingsKey, hasVoiceKey, imeOptions, true);
- mSymbolsShiftedId = new KeyboardId(locale, orientation, SYMBOLS_KEYBOARD_MODES, mode,
+ mSymbolsShiftedId = new KeyboardId(locale, orientation, mode,
KBD_SYMBOLS_SHIFT, colorScheme, hasSettingsKey, hasVoiceKey, imeOptions, true);
}
@@ -194,10 +131,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
* Represents the parameters necessary to construct a new LatinKeyboard,
* which also serve as a unique identifier for each keyboard type.
*/
- private static class KeyboardId {
+ public static class KeyboardId {
public final Locale mLocale;
public final int mOrientation;
- public final int[][] mKeyboardModes;
public final int mMode;
public final int[] mXmlArray;
public final int mColorScheme;
@@ -208,12 +144,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
private final int mHashCode;
- public KeyboardId(Locale locale, int orientation, int[][] keyboardModes, int mode,
+ public KeyboardId(Locale locale, int orientation, int mode,
int[] xmlArray, int colorScheme, boolean hasSettingsKey, boolean hasVoiceKey,
int imeOptions, boolean enableShiftLock) {
this.mLocale = locale;
this.mOrientation = orientation;
- this.mKeyboardModes = keyboardModes;
this.mMode = mode;
this.mXmlArray = xmlArray;
this.mColorScheme = colorScheme;
@@ -225,7 +160,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
this.mHashCode = Arrays.hashCode(new Object[] {
locale,
orientation,
- keyboardModes,
mode,
xmlArray,
colorScheme,
@@ -236,6 +170,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
});
}
+ public int getXmlId() {
+ return mXmlArray[mColorScheme];
+ }
+
+ public boolean isAlphabetMode() {
+ return mXmlArray == KBD_QWERTY;
+ }
+
@Override
public boolean equals(Object other) {
return other instanceof KeyboardId && equals((KeyboardId) other);
@@ -244,7 +186,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
private boolean equals(KeyboardId other) {
return other.mLocale.equals(this.mLocale)
&& other.mOrientation == this.mOrientation
- && other.mKeyboardModes == this.mKeyboardModes
&& other.mMode == this.mMode
&& other.mXmlArray == this.mXmlArray
&& other.mColorScheme == this.mColorScheme
@@ -261,33 +202,26 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
@Override
public String toString() {
- if (DEBUG) {
- return String.format("[%s %s %6s %5s imeOptions=0x%08x xml=0x%08x %s%s%s%s]",
- mLocale,
- (mOrientation == 1 ? "port" : "land"),
- (mKeyboardModes == QWERTY_KEYBOARD_MODES ? "alpha" : "symbol"),
- modeName(mMode),
- mImeOptions,
- mXmlArray[0],
- (mColorScheme == CHAR_THEME_COLOR_WHITE ? "white" : "black"),
- (mHasSettingsKey ? " hasSettingsKey" : ""),
- (mHasVoiceKey ? " hasVoiceKey" : ""),
- (mEnableShiftLock ? " enableShiftLock" : ""));
- } else {
- return super.toString();
- }
+ return String.format("[%s %s %5s imeOptions=0x%08x xml=0x%08x %s%s%s%s]",
+ mLocale,
+ (mOrientation == 1 ? "port" : "land"),
+ modeName(mMode),
+ mImeOptions,
+ mXmlArray[0],
+ (mColorScheme == CHAR_THEME_COLOR_WHITE ? "white" : "black"),
+ (mHasSettingsKey ? " hasSettingsKey" : ""),
+ (mHasVoiceKey ? " hasVoiceKey" : ""),
+ (mEnableShiftLock ? " enableShiftLock" : ""));
}
private static String modeName(int mode) {
- if (DEBUG) {
- switch (mode) {
- case MODE_TEXT: return "text";
- case MODE_URL: return "url";
- case MODE_EMAIL: return "email";
- case MODE_IM: return "im";
- case MODE_WEB: return "web";
- case MODE_PHONE: return "phone";
- }
+ switch (mode) {
+ case MODE_TEXT: return "text";
+ case MODE_URL: return "url";
+ case MODE_EMAIL: return "email";
+ case MODE_IM: return "im";
+ case MODE_WEB: return "web";
+ case MODE_PHONE: return "phone";
}
return null;
}
@@ -304,6 +238,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
loadKeyboardInternal(mode, imeOptions, voiceButtonEnabled, voiceButtonOnPrimary,
false);
} catch (RuntimeException e) {
+ Log.w(TAG, e);
LatinImeLogger.logOnException(mode + "," + imeOptions, e);
}
}
@@ -345,10 +280,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
conf.locale = mLanguageSwitcher.getInputLocale();
res.updateConfiguration(conf, null);
- final int keyboardMode = id.mKeyboardModes[id.mHasSettingsKey ? 1 : 0][id.mMode];
- final int xml = id.mXmlArray[id.mColorScheme];
- keyboard = new LatinKeyboard(mInputMethodService, xml, keyboardMode, id.mColorScheme,
- id.mHasSettingsKey, id.mHasVoiceKey, id.mImeOptions);
+ final int xml = id.getXmlId();
+ keyboard = new LatinKeyboard(mInputMethodService, id);
keyboard.setVoiceMode(
hasVoiceKey(xml == R.xml.kbd_symbols || xml == R.xml.kbd_symbols_black),
mVoiceButtonEnabled);
@@ -383,20 +316,17 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
final int charColorId = getCharColorId();
final int[] xmlArray;
final boolean enableShiftLock;
- final int[][] keyboardModes;
if (isSymbols) {
- keyboardModes = SYMBOLS_KEYBOARD_MODES;
xmlArray = mode == MODE_PHONE ? KBD_PHONE_SYMBOLS : KBD_SYMBOLS;
enableShiftLock = false;
} else { // QWERTY
- keyboardModes = QWERTY_KEYBOARD_MODES;
xmlArray = mode == MODE_PHONE ? KBD_PHONE : KBD_QWERTY;
enableShiftLock = mode == MODE_PHONE ? false : true;
}
final int orientation = mInputMethodService.getResources().getConfiguration().orientation;
final Locale locale = mLanguageSwitcher.getInputLocale();
- return new KeyboardId(locale, orientation, keyboardModes, mode, xmlArray,
+ return new KeyboardId(locale, orientation, mode, xmlArray,
charColorId, mHasSettingsKey, hasVoiceKey, imeOptions, enableShiftLock);
}
@@ -405,7 +335,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
}
public boolean isAlphabetMode() {
- return mCurrentId != null && mCurrentId.mKeyboardModes == QWERTY_KEYBOARD_MODES;
+ return mCurrentId != null && mCurrentId.isAlphabetMode();
}
public void setShifted(boolean shifted) {
diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboard.java b/java/src/com/android/inputmethod/latin/LatinKeyboard.java
index 883069ae6..e1673fb7b 100644
--- a/java/src/com/android/inputmethod/latin/LatinKeyboard.java
+++ b/java/src/com/android/inputmethod/latin/LatinKeyboard.java
@@ -70,7 +70,7 @@ public class LatinKeyboard extends BaseKeyboard {
private LanguageSwitcher mLanguageSwitcher;
private final Resources mRes;
private final Context mContext;
- private int mMode; // TODO: remove this and use the corresponding mode in the parent class
+ private int mMode; // TODO: remove this and use the corresponding mode in the parent class
// Whether this keyboard has voice icon on it
private boolean mHasVoiceButton;
// Whether voice icon is enabled at all
@@ -113,14 +113,12 @@ public class LatinKeyboard extends BaseKeyboard {
private static int sSpacebarVerticalCorrection;
- public LatinKeyboard(Context context, int xmlLayoutResId, int mode, int colorScheme,
- boolean hasSettingsKey, boolean hasVoiceKey, int imeOptions) {
- // TODO: to be used: colorScheme, hasSettingsKey, hasVoiceKey, imeOptions.
- super(context, xmlLayoutResId, mode);
+ public LatinKeyboard(Context context, KeyboardSwitcher.KeyboardId id) {
+ super(context, id);
final Resources res = context.getResources();
mContext = context;
mRes = res;
- mMode = mode;
+ mMode = id.mMode;
mShiftLockIcon = res.getDrawable(R.drawable.sym_keyboard_shift_locked);
mShiftLockPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_shift_locked);
setDefaultBounds(mShiftLockPreviewIcon);
@@ -138,6 +136,7 @@ public class LatinKeyboard extends BaseKeyboard {
setDefaultBounds(m123MicPreviewIcon);
sSpacebarVerticalCorrection = res.getDimensionPixelOffset(
R.dimen.spacebar_vertical_correction);
+ final int xmlLayoutResId = id.getXmlId();
mIsAlphaKeyboard = xmlLayoutResId == R.xml.kbd_qwerty
|| xmlLayoutResId == R.xml.kbd_qwerty_black;
mSpaceKeyIndex = indexOf(LatinIME.KEYCODE_SPACE);