Use "flag" feature of attr.xml to represent keyboard mode

Change-Id: Ibc317ada5167a119477fe8ea2994df6c6462afd0
main
Tadashi G. Takaoka 2010-11-19 14:57:24 -08:00
parent 75fde64890
commit 1d8196cd41
2 changed files with 12 additions and 23 deletions

View File

@ -132,7 +132,15 @@
</declare-styleable> </declare-styleable>
<declare-styleable name="BaseKeyboard_Case"> <declare-styleable name="BaseKeyboard_Case">
<attr name="mode" format="string" /> <!-- This should be matched with KeyboardSwitcher.MODE_* -->
<attr name="mode">
<flag name="text" value="0" />
<flag name="url" value="1" />
<flag name="email" value="2" />
<flag name="im" value="3" />
<flag name="web" value="4" />
<flag name="phone" value="5" />
</attr>
<attr name="settingsKey" format="string" /> <attr name="settingsKey" format="string" />
<attr name="voiceKey" format="string" /> <attr name="voiceKey" format="string" />
</declare-styleable> </declare-styleable>

View File

@ -120,14 +120,6 @@ public class BaseKeyboardParser {
private static final String TAG_CASE = "case"; private static final String TAG_CASE = "case";
private static final String TAG_DEFAULT = "default"; 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 BaseKeyboard mKeyboard;
private final Resources mResources; private final Resources mResources;
@ -411,7 +403,7 @@ public class BaseKeyboardParser {
final BaseKeyboard keyboard = mKeyboard; final BaseKeyboard keyboard = mKeyboard;
final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser), final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.BaseKeyboard_Case); R.styleable.BaseKeyboard_Case);
final String mode = a.getString(R.styleable.BaseKeyboard_Case_mode); final int mode = a.getInt(R.styleable.BaseKeyboard_Case_mode, -1);
final String settingsKey = a.getString(R.styleable.BaseKeyboard_Case_settingsKey); final String settingsKey = a.getString(R.styleable.BaseKeyboard_Case_settingsKey);
final String voiceKey = a.getString(R.styleable.BaseKeyboard_Case_voiceKey); final String voiceKey = a.getString(R.styleable.BaseKeyboard_Case_voiceKey);
a.recycle(); a.recycle();
@ -419,8 +411,7 @@ public class BaseKeyboardParser {
final KeyboardId id = keyboard.mId; final KeyboardId id = keyboard.mId;
if (id == null) if (id == null)
return true; return true;
final boolean modeMatched = (mode == null final boolean modeMatched = (mode == -1 || id.mMode == mode);
|| id.mMode == parseModeString(mode));
final boolean settingsKeyMatched = (settingsKey == null final boolean settingsKeyMatched = (settingsKey == null
|| id.mHasSettingsKey == Boolean.parseBoolean(settingsKey)); || id.mHasSettingsKey == Boolean.parseBoolean(settingsKey));
final boolean voiceKeyMatched = (voiceKey == null final boolean voiceKeyMatched = (voiceKey == null
@ -428,23 +419,13 @@ public class BaseKeyboardParser {
final boolean selected = modeMatched && settingsKeyMatched && voiceKeyMatched; final boolean selected = modeMatched && settingsKeyMatched && voiceKeyMatched;
if (DEBUG_TAG) { if (DEBUG_TAG) {
Log.d(TAG, "parseCaseCondition: " + Boolean.toString(selected).toUpperCase() Log.d(TAG, "parseCaseCondition: " + Boolean.toString(selected).toUpperCase()
+ (mode != null ? " mode=" + mode : "") + (mode != -1 ? " mode=" + mode : "")
+ (settingsKey != null ? " settingsKey="+settingsKey : "") + (settingsKey != null ? " settingsKey="+settingsKey : "")
+ (voiceKey != null ? " voiceKey=" + voiceKey : "")); + (voiceKey != null ? " voiceKey=" + voiceKey : ""));
} }
return selected; 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) private boolean parseDefault(XmlResourceParser parser, Row row, List<Key> keys)
throws XmlPullParserException, IOException { throws XmlPullParserException, IOException {
if (DEBUG_PARSER) debugEnterMethod("parseDefault", keys == null); if (DEBUG_PARSER) debugEnterMethod("parseDefault", keys == null);