am 44e0e4f9: Fix Key.equals(Key)

* commit '44e0e4f99e70b84176ff5c985e456b821a8f0b14':
  Fix Key.equals(Key)
main
Tadashi G. Takaoka 2012-02-02 04:46:06 -08:00 committed by Android Git Automerger
commit 977636cb93
3 changed files with 44 additions and 18 deletions

View File

@ -364,8 +364,8 @@ public class Key {
&& o.mCode == mCode && o.mCode == mCode
&& TextUtils.equals(o.mLabel, mLabel) && TextUtils.equals(o.mLabel, mLabel)
&& TextUtils.equals(o.mHintLabel, mHintLabel) && TextUtils.equals(o.mHintLabel, mHintLabel)
&& o.mIconAttrId != mIconAttrId && o.mIconAttrId == mIconAttrId
&& o.mBackgroundType != mBackgroundType; && o.mBackgroundType == mBackgroundType;
} }
@Override @Override
@ -380,11 +380,20 @@ public class Key {
@Override @Override
public String toString() { public String toString() {
String top = Keyboard.printableCode(mCode); return String.format("%s/%s %d,%d %dx%d %s/%s/%s",
if (Utils.codePointCount(mLabel) != 1) { Keyboard.printableCode(mCode), mLabel, mX, mY, mWidth, mHeight, mHintLabel,
top += "/\"" + mLabel + '"'; KeyboardIconsSet.getIconName(mIconAttrId), backgroundName(mBackgroundType));
}
private static String backgroundName(int backgroundType) {
switch (backgroundType) {
case BACKGROUND_TYPE_NORMAL: return "normal";
case BACKGROUND_TYPE_FUNCTIONAL: return "functional";
case BACKGROUND_TYPE_ACTION: return "action";
case BACKGROUND_TYPE_STICKY_OFF: return "stickyOff";
case BACKGROUND_TYPE_STICKY_ON: return "stickyOn";
default: return null;
} }
return String.format("%s %d,%d", top, mX, mY);
} }
public void markAsLeftEdge(Keyboard.Params params) { public void markAsLeftEdge(Keyboard.Params params) {

View File

@ -57,7 +57,10 @@ public class KeyboardSet {
private final Context mContext; private final Context mContext;
private final Params mParams; private final Params mParams;
private final KeysCache mKeysCache = new KeysCache();
private static final HashMap<KeyboardId, SoftReference<Keyboard>> sKeyboardCache =
new HashMap<KeyboardId, SoftReference<Keyboard>>();
private static final KeysCache sKeysCache = new KeysCache();
public static class KeyboardSetException extends RuntimeException { public static class KeyboardSetException extends RuntimeException {
public final KeyboardId mKeyboardId; public final KeyboardId mKeyboardId;
@ -74,6 +77,10 @@ public class KeyboardSet {
mMap = new HashMap<Key, Key>(); mMap = new HashMap<Key, Key>();
} }
public void clear() {
mMap.clear();
}
public Key get(Key key) { public Key get(Key key) {
final Key existingKey = mMap.get(key); final Key existingKey = mMap.get(key);
if (existingKey != null) { if (existingKey != null) {
@ -103,11 +110,9 @@ public class KeyboardSet {
Params() {} Params() {}
} }
private static final HashMap<KeyboardId, SoftReference<Keyboard>> sKeyboardCache =
new HashMap<KeyboardId, SoftReference<Keyboard>>();
public static void clearKeyboardCache() { public static void clearKeyboardCache() {
sKeyboardCache.clear(); sKeyboardCache.clear();
sKeysCache.clear();
} }
private KeyboardSet(Context context, Params params) { private KeyboardSet(Context context, Params params) {
@ -156,7 +161,7 @@ public class KeyboardSet {
final Keyboard.Builder<Keyboard.Params> builder = final Keyboard.Builder<Keyboard.Params> builder =
new Keyboard.Builder<Keyboard.Params>(context, new Keyboard.Params()); new Keyboard.Builder<Keyboard.Params>(context, new Keyboard.Params());
if (id.isAlphabetKeyboard()) { if (id.isAlphabetKeyboard()) {
builder.setAutoGenerate(mKeysCache); builder.setAutoGenerate(sKeysCache);
} }
builder.load(keyboardXmlId, id); builder.load(keyboardXmlId, id);
builder.setTouchPositionCorrectionEnabled(mParams.mTouchPositionCorrectionEnabled); builder.setTouchPositionCorrectionEnabled(mParams.mTouchPositionCorrectionEnabled);

View File

@ -36,8 +36,9 @@ public class KeyboardIconsSet {
private final Map<Integer, Drawable> mIcons = new HashMap<Integer, Drawable>(); private final Map<Integer, Drawable> mIcons = new HashMap<Integer, Drawable>();
// The key value should be aligned with the enum value of Keyboard.icon*. // The key value should be aligned with the enum value of Keyboard.icon*.
private static final Map<Integer, Integer> ICONS_TO_ATTRS_MAP = new HashMap<Integer, Integer>(); private static final Map<Integer, Integer> ID_TO_ATTR_MAP = new HashMap<Integer, Integer>();
private static final Map<String, Integer> NAME_TO_ATTRS_MAP = new HashMap<String, Integer>(); private static final Map<String, Integer> NAME_TO_ATTR_MAP = new HashMap<String, Integer>();
private static final Map<Integer, String> ATTR_TO_NAME_MAP = new HashMap<Integer, String>();
private static final Collection<Integer> VALID_ATTRS; private static final Collection<Integer> VALID_ATTRS;
static { static {
@ -55,12 +56,13 @@ public class KeyboardIconsSet {
addIconIdMap(11, "shiftKeyShifted", R.styleable.Keyboard_iconShiftKeyShifted); addIconIdMap(11, "shiftKeyShifted", R.styleable.Keyboard_iconShiftKeyShifted);
addIconIdMap(12, "disabledShortcurKey", R.styleable.Keyboard_iconDisabledShortcutKey); addIconIdMap(12, "disabledShortcurKey", R.styleable.Keyboard_iconDisabledShortcutKey);
addIconIdMap(13, "previewTabKey", R.styleable.Keyboard_iconPreviewTabKey); addIconIdMap(13, "previewTabKey", R.styleable.Keyboard_iconPreviewTabKey);
VALID_ATTRS = ICONS_TO_ATTRS_MAP.values(); VALID_ATTRS = ID_TO_ATTR_MAP.values();
} }
private static void addIconIdMap(int iconId, String name, Integer attrId) { private static void addIconIdMap(int iconId, String name, Integer attrId) {
ICONS_TO_ATTRS_MAP.put(iconId, attrId); ID_TO_ATTR_MAP.put(iconId, attrId);
NAME_TO_ATTRS_MAP.put(name, attrId); NAME_TO_ATTR_MAP.put(name, attrId);
ATTR_TO_NAME_MAP.put(attrId, name);
} }
public void loadIcons(final TypedArray keyboardAttrs) { public void loadIcons(final TypedArray keyboardAttrs) {
@ -82,7 +84,7 @@ public class KeyboardIconsSet {
if (iconId == ICON_UNDEFINED) { if (iconId == ICON_UNDEFINED) {
return ATTR_UNDEFINED; return ATTR_UNDEFINED;
} }
final Integer attrId = ICONS_TO_ATTRS_MAP.get(iconId); final Integer attrId = ID_TO_ATTR_MAP.get(iconId);
if (attrId == null) { if (attrId == null) {
throw new IllegalArgumentException("icon id is out of range: " + iconId); throw new IllegalArgumentException("icon id is out of range: " + iconId);
} }
@ -90,13 +92,23 @@ public class KeyboardIconsSet {
} }
public static int getIconAttrId(final String iconName) { public static int getIconAttrId(final String iconName) {
final Integer attrId = NAME_TO_ATTRS_MAP.get(iconName); final Integer attrId = NAME_TO_ATTR_MAP.get(iconName);
if (attrId == null) { if (attrId == null) {
throw new IllegalArgumentException("unknown icon name: " + iconName); throw new IllegalArgumentException("unknown icon name: " + iconName);
} }
return attrId; return attrId;
} }
public static String getIconName(final int attrId) {
if (attrId == ATTR_UNDEFINED) {
return "null";
}
if (ATTR_TO_NAME_MAP.containsKey(attrId)) {
return ATTR_TO_NAME_MAP.get(attrId);
}
return String.format("unknown<0x%08x>", attrId);
}
public Drawable getIconByAttrId(final Integer attrId) { public Drawable getIconByAttrId(final Integer attrId) {
if (attrId == ATTR_UNDEFINED) { if (attrId == ATTR_UNDEFINED) {
return null; return null;