From c4f71668d7b8203dc66f0f04c089a363189eb4ce Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 20 Dec 2010 20:30:26 +0900 Subject: [PATCH] Remove multi-tap feature Change-Id: Ife44b3f9d420d77d2cfb51044a8356f02ed63e8b --- java/proguard.flags | 1 + java/res/values/attrs.xml | 4 +- java/res/values/config.xml | 1 - java/res/xml-xlarge/kbd_key_styles.xml | 32 ++-- java/res/xml-xlarge/kbd_numkey_styles.xml | 56 +++---- java/res/xml-xlarge/kbd_phone.xml | 12 +- java/res/xml-xlarge/kbd_phone_symbols.xml | 18 +- java/res/xml/kbd_key_styles.xml | 56 +++---- java/res/xml/kbd_number.xml | 4 +- java/res/xml/kbd_numkey_styles.xml | 56 +++---- java/res/xml/kbd_phone_symbols.xml | 6 +- java/res/xml/kbd_qwerty_black_symbol.xml | 8 +- .../com/android/inputmethod/keyboard/Key.java | 22 ++- .../inputmethod/keyboard/KeyStyles.java | 54 +----- .../inputmethod/keyboard/Keyboard.java | 3 + .../inputmethod/keyboard/KeyboardParser.java | 8 +- .../inputmethod/keyboard/KeyboardView.java | 4 +- .../inputmethod/keyboard/LatinKeyboard.java | 14 +- .../keyboard/LatinKeyboardView.java | 2 +- .../keyboard/MiniKeyboardKeyDetector.java | 2 +- .../inputmethod/keyboard/PointerTracker.java | 97 ++--------- .../keyboard/PopupCharactersParser.java | 13 +- .../keyboard/ProximityKeyDetector.java | 15 +- .../inputmethod/latin/TextEntryState.java | 4 +- .../inputmethod/keyboard/KeyStylesTests.java | 30 ---- .../keyboard/PopupCharactersParserTests.java | 158 +++++++++--------- 26 files changed, 267 insertions(+), 413 deletions(-) diff --git a/java/proguard.flags b/java/proguard.flags index 202307592..9096855e8 100644 --- a/java/proguard.flags +++ b/java/proguard.flags @@ -12,4 +12,5 @@ void setDatabaseMax(int); void setDatabaseDelete(int); void waitUntilUpdateDBDone(); + void waitForDictionaryLoading(); } diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 549c2ae81..9759e0eb6 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -94,8 +94,8 @@ - - + + diff --git a/java/res/values/config.xml b/java/res/values/config.xml index 4187c31fb..122530480 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -41,7 +41,6 @@ 16 400 1200 - 800 small 9 diff --git a/java/res/xml-xlarge/kbd_key_styles.xml b/java/res/xml-xlarge/kbd_key_styles.xml index 6c1df0b9e..eb3758024 100644 --- a/java/res/xml-xlarge/kbd_key_styles.xml +++ b/java/res/xml-xlarge/kbd_key_styles.xml @@ -31,7 +31,7 @@ latin:isModifier="true" /> @@ -81,7 +81,7 @@ latin:styleName="functionalKeyStyle" /> @@ -127,25 +127,25 @@ @@ -89,60 +89,60 @@ > diff --git a/java/res/xml-xlarge/kbd_phone.xml b/java/res/xml-xlarge/kbd_phone.xml index 66f602068..45c298362 100644 --- a/java/res/xml-xlarge/kbd_phone.xml +++ b/java/res/xml-xlarge/kbd_phone.xml @@ -44,11 +44,11 @@ @@ -108,7 +108,7 @@ latin:styleName="functionalKeyStyle" /> @@ -139,32 +139,32 @@ @@ -186,7 +186,7 @@ > @@ -195,7 +195,7 @@ > @@ -204,7 +204,7 @@ > @@ -213,7 +213,7 @@ > @@ -226,7 +226,7 @@ > @@ -236,7 +236,7 @@ > @@ -250,7 +250,7 @@ > @@ -260,7 +260,7 @@ > @@ -270,12 +270,12 @@ diff --git a/java/res/xml/kbd_number.xml b/java/res/xml/kbd_number.xml index f4a5def95..f4fe8401a 100644 --- a/java/res/xml/kbd_number.xml +++ b/java/res/xml/kbd_number.xml @@ -37,7 +37,7 @@ > @@ -46,7 +46,7 @@ > diff --git a/java/res/xml/kbd_numkey_styles.xml b/java/res/xml/kbd_numkey_styles.xml index 006476db2..2f9ae325a 100644 --- a/java/res/xml/kbd_numkey_styles.xml +++ b/java/res/xml/kbd_numkey_styles.xml @@ -27,60 +27,60 @@ > @@ -89,60 +89,60 @@ > diff --git a/java/res/xml/kbd_phone_symbols.xml b/java/res/xml/kbd_phone_symbols.xml index 1997a75fc..67cd330e7 100644 --- a/java/res/xml/kbd_phone_symbols.xml +++ b/java/res/xml/kbd_phone_symbols.xml @@ -56,7 +56,7 @@ @@ -72,7 +72,7 @@ latin:keyEdgeFlags="left" /> @@ -85,7 +85,7 @@ latin:rowEdgeFlags="bottom" > 0) { - count++; - while ((lastIndex = value.indexOf(",", lastIndex + 1)) > 0) { - count++; - } - } - int[] values = new int[count]; - count = 0; - StringTokenizer st = new StringTokenizer(value, ","); - while (st.hasMoreTokens()) { - values[count++] = Integer.parseInt(st.nextToken()); - } - return values; - } } private static class DeclaredKeyStyle extends EmptyKeyStyle { private final HashMap mAttributes = new HashMap(); - @Override - public int[] getIntArray(TypedArray a, int index) { - return a.hasValue(index) - ? super.getIntArray(a, index) : (int[])mAttributes.get(index); - } - @Override public CharSequence[] getTextArray(TypedArray a, int index) { return a.hasValue(index) @@ -221,7 +175,7 @@ public class KeyStyles { private void parseKeyStyleAttributes(TypedArray keyAttr) { // TODO: Currently not all Key attributes can be declared as style. - readIntArray(keyAttr, R.styleable.Keyboard_Key_codes); + readInt(keyAttr, R.styleable.Keyboard_Key_code); readText(keyAttr, R.styleable.Keyboard_Key_keyLabel); readFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelOption); readTextArray(keyAttr, R.styleable.Keyboard_Key_popupCharacters); @@ -262,12 +216,6 @@ public class KeyStyles { mAttributes.put(index, a.getBoolean(index, false)); } - private void readIntArray(TypedArray a, int index) { - final int[] value = parseIntArray(a, index); - if (value != null) - mAttributes.put(index, value); - } - private void readTextArray(TypedArray a, int index) { final CharSequence[] value = parseTextArray(a, index); if (value != null) diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index a20c86142..ae1d302db 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -65,12 +65,15 @@ public class Keyboard { public static final int CODE_PERIOD = '.'; /** Special keys code. These should be aligned with values/keycodes.xml */ + public static final int CODE_DUMMY = 0; public static final int CODE_SHIFT = -1; public static final int CODE_SWITCH_ALPHA_SYMBOL = -2; public static final int CODE_CANCEL = -3; public static final int CODE_DONE = -4; public static final int CODE_DELETE = -5; public static final int CODE_ALT = -6; + // Code value representing the code is not specified. + public static final int CODE_UNSPECIFIED = -99; public static final int CODE_SETTINGS = -100; public static final int CODE_SETTINGS_LONGPRESS = -101; // TODO: remove this once LatinIME stops referring to this. diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java index ed59b8be5..c41d57075 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java @@ -279,14 +279,14 @@ public class KeyboardParser { checkEndTag(TAG_KEY, parser); } else { Key key = new Key(mResources, row, mCurrentX, mCurrentY, parser, mKeyStyles); - if (DEBUG) Log.d(TAG, String.format("<%s keyLabel=%s codes=%s popupCharacters=%s />", - TAG_KEY, key.mLabel, Arrays.toString(key.mCodes), + if (DEBUG) Log.d(TAG, String.format("<%s keyLabel=%s code=%d popupCharacters=%s />", + TAG_KEY, key.mLabel, key.mCode, Arrays.toString(key.mPopupCharacters))); checkEndTag(TAG_KEY, parser); keys.add(key); - if (key.mCodes[0] == Keyboard.CODE_SHIFT) + if (key.mCode == Keyboard.CODE_SHIFT) mKeyboard.getShiftKeys().add(key); - if (key.mCodes[0] == Keyboard.CODE_SPACE) + if (key.mCode == Keyboard.CODE_SPACE) mKeyboard.setSpaceKey(key); endKey(key); } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 7f573b24c..7c6e4dc4e 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -834,7 +834,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { // For characters, use large font. For labels like "Done", use small font. final int labelSize; final Typeface labelStyle; - if (label.length() > 1 && key.mCodes.length < 2) { + if (label.length() > 1) { labelSize = mLabelTextSize; if ((key.mLabelOption & KEY_LABEL_OPTION_FONT_NORMAL) != 0) { labelStyle = Typeface.DEFAULT; @@ -943,7 +943,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { // TODO Should take care of temporaryShiftLabel here. mPreviewText.setCompoundDrawables(null, null, null, null); mPreviewText.setText(adjustCase(tracker.getPreviewText(key))); - if (key.mLabel.length() > 1 && key.mCodes.length < 2) { + if (key.mLabel.length() > 1) { mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mKeyLetterSize); mPreviewText.setTypeface(Typeface.DEFAULT_BOLD); } else { diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index b9041e36b..7b079e38e 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -294,7 +294,7 @@ public class LatinKeyboard extends Keyboard { public boolean isInside(Key key, int pointX, int pointY) { int x = pointX; int y = pointY; - final int code = key.mCodes[0]; + final int code = key.mCode; if (code == CODE_SHIFT || code == CODE_DELETE) { y -= key.mHeight / 10; if (code == CODE_SHIFT) x += key.mWidth / 6; @@ -348,11 +348,11 @@ public class LatinKeyboard extends Keyboard { mPrefLetterY = y; for (int i = 0; i < nearby.length; i++) { Key k = nearbyKeys.get(nearby[i]); - if (k != key && inPrefList(k.mCodes[0], pref)) { + if (k != key && inPrefList(k.mCode, pref)) { final int dist = distanceFrom(k, x, y); if (dist < (int) (k.mWidth * OVERLAP_PERCENTAGE_LOW_PROB) && - (pref[k.mCodes[0]] > pref[mPrefLetter] * 3)) { - mPrefLetter = k.mCodes[0]; + (pref[k.mCode] > pref[mPrefLetter] * 3)) { + mPrefLetter = k.mCode; mPrefDistance = dist; if (DEBUG_PREFERRED_LETTER) { Log.d(TAG, "CORRECTED ALTHOUGH PREFERRED !!!!!!"); @@ -376,11 +376,11 @@ public class LatinKeyboard extends Keyboard { for (int i = 0; i < nearby.length; i++) { Key k = nearbyKeys.get(nearby[i]); - if (inPrefList(k.mCodes[0], pref)) { + if (inPrefList(k.mCode, pref)) { final int dist = distanceFrom(k, x, y); if (dist < (int) (k.mWidth * OVERLAP_PERCENTAGE_HIGH_PROB) && dist < mPrefDistance) { - mPrefLetter = k.mCodes[0]; + mPrefLetter = k.mCode; mPrefLetterX = x; mPrefLetterY = y; mPrefDistance = dist; @@ -430,7 +430,7 @@ public class LatinKeyboard extends Keyboard { List keys = getKeys(); int count = keys.size(); for (int i = 0; i < count; i++) { - if (keys.get(i).mCodes[0] == code) return i; + if (keys.get(i).mCode == code) return i; } return -1; } diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 2243e93cf..cb3b430d5 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -82,7 +82,7 @@ public class LatinKeyboardView extends KeyboardView { @Override protected boolean onLongPress(Key key) { - int primaryCode = key.mCodes[0]; + int primaryCode = key.mCode; if (primaryCode == Keyboard.CODE_SETTINGS) { return invokeOnKey(Keyboard.CODE_SETTINGS_LONGPRESS); } else if (primaryCode == '0' && getLatinKeyboard().isPhoneKeyboard()) { diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java index 774b39ab7..f04991eb7 100644 --- a/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java +++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java @@ -52,7 +52,7 @@ public class MiniKeyboardKeyDetector extends KeyDetector { } if (allKeys != null && closestKeyIndex != NOT_A_KEY) - allKeys[0] = keys[closestKeyIndex].mCodes[0]; + allKeys[0] = keys[closestKeyIndex].mCode; return closestKeyIndex; } } diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index c0761117f..7928c4f8e 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -43,7 +43,6 @@ public class PointerTracker { private final int mDelayBeforeKeyRepeatStart; private final int mLongPressKeyTimeout; private final int mLongPressShiftKeyTimeout; - private final int mMultiTapKeyTimeout; // Miscellaneous constants private static final int NOT_A_KEY = KeyDetector.NOT_A_KEY; @@ -75,13 +74,6 @@ public class PointerTracker { // true if sliding key is allowed. private boolean mIsAllowedSlidingKeyInput; - // For multi-tap - private int mLastSentIndex; - private int mTapCount; - private long mLastTapTime; - private boolean mInMultiTap; - private final StringBuilder mPreviewLabel = new StringBuilder(1); - // pressed key private int mPreviousKey = NOT_A_KEY; @@ -116,8 +108,6 @@ public class PointerTracker { mDelayBeforeKeyRepeatStart = res.getInteger(R.integer.config_delay_before_key_repeat_start); mLongPressKeyTimeout = res.getInteger(R.integer.config_long_press_key_timeout); mLongPressShiftKeyTimeout = res.getInteger(R.integer.config_long_press_shift_key_timeout); - mMultiTapKeyTimeout = res.getInteger(R.integer.config_multi_tap_key_timeout); - resetMultiTap(); } public void setOnKeyboardActionListener(KeyboardActionListener listener) { @@ -184,7 +174,7 @@ public class PointerTracker { private boolean isModifierInternal(int keyIndex) { final Key key = getKey(keyIndex); - return key == null ? false : isModifierCode(key.mCodes[0]); + return key == null ? false : isModifierCode(key.mCode); } public boolean isModifier() { @@ -197,12 +187,12 @@ public class PointerTracker { public boolean isOnShiftKey(int x, int y) { final Key key = getKey(mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null)); - return key != null && key.mCodes[0] == Keyboard.CODE_SHIFT; + return key != null && key.mCode == Keyboard.CODE_SHIFT; } public boolean isSpaceKey(int keyIndex) { Key key = getKey(keyIndex); - return key != null && key.mCodes[0] == Keyboard.CODE_SPACE; + return key != null && key.mCode == Keyboard.CODE_SPACE; } public void releaseKey() { @@ -260,9 +250,8 @@ public class PointerTracker { mKeyAlreadyProcessed = false; mIsRepeatableKey = false; mIsInSlidingKeyInput = false; - checkMultiTap(eventTime, keyIndex); if (isValidKeyIndex(keyIndex)) { - callListenerOnPress(mKeys[keyIndex].mCodes[0]); + callListenerOnPress(mKeys[keyIndex].mCode); // This onPress call may have changed keyboard layout and have updated mKeyIndex. // If that's the case, mKeyIndex has been updated in setKeyboard(). keyIndex = mKeyState.getKeyIndex(); @@ -290,7 +279,7 @@ public class PointerTracker { if (oldKey == null) { // The pointer has been slid in to the new key, but the finger was not on any keys. // In this case, we must call onPress() to notify that the new key is being pressed. - callListenerOnPress(getKey(keyIndex).mCodes[0]); + callListenerOnPress(getKey(keyIndex).mCode); keyState.onMoveToNewKey(keyIndex, x, y); startLongPressTimer(keyIndex); } else if (!isMinorMoveBounce(x, y, keyIndex)) { @@ -298,11 +287,10 @@ public class PointerTracker { // onRelease() first to notify that the previous key has been released, then call // onPress() to notify that the new key is being pressed. mIsInSlidingKeyInput = true; - callListenerOnRelease(oldKey.mCodes[0]); + callListenerOnRelease(oldKey.mCode); mHandler.cancelLongPressTimers(); if (mIsAllowedSlidingKeyInput) { - resetMultiTap(); - callListenerOnPress(getKey(keyIndex).mCodes[0]); + callListenerOnPress(getKey(keyIndex).mCode); keyState.onMoveToNewKey(keyIndex, x, y); startLongPressTimer(keyIndex); } else { @@ -316,10 +304,9 @@ public class PointerTracker { // The pointer has been slid out from the previous key, we must call onRelease() to // notify that the previous key has been released. mIsInSlidingKeyInput = true; - callListenerOnRelease(oldKey.mCodes[0]); + callListenerOnRelease(oldKey.mCode); mHandler.cancelLongPressTimers(); if (mIsAllowedSlidingKeyInput) { - resetMultiTap(); keyState.onMoveToNewKey(keyIndex, x ,y); } else { setAlreadyProcessed(); @@ -351,7 +338,7 @@ public class PointerTracker { y = keyState.getKeyY(); } if (!mIsRepeatableKey) { - detectAndSendKey(keyIndex, x, y, eventTime); + detectAndSendKey(keyIndex, x, y); } if (isValidKeyIndex(keyIndex)) @@ -373,9 +360,7 @@ public class PointerTracker { public void repeatKey(int keyIndex) { Key key = getKey(keyIndex); if (key != null) { - // While key is repeating, because there is no need to handle multi-tap key, we can - // pass -1 as eventTime argument. - detectAndSendKey(keyIndex, key.mX, key.mY, -1); + detectAndSendKey(keyIndex, key.mX, key.mY); } } @@ -427,7 +412,7 @@ public class PointerTracker { private void startLongPressTimer(int keyIndex) { Key key = getKey(keyIndex); - if (key.mCodes[0] == Keyboard.CODE_SHIFT) { + if (key.mCode == Keyboard.CODE_SHIFT) { mHandler.startLongPressShiftTimer(mLongPressShiftKeyTimeout, keyIndex, this); } else if (mKeyboardSwitcher.isInMomentaryAutoModeSwitchState()) { // We use longer timeout for sliding finger input started from the symbols mode key. @@ -437,7 +422,7 @@ public class PointerTracker { } } - private void detectAndSendKey(int index, int x, int y, long eventTime) { + private void detectAndSendKey(int index, int x, int y) { final Key key = getKey(index); if (key == null) { callListenerOnCancelInput(); @@ -445,20 +430,11 @@ public class PointerTracker { } if (key.mOutputText != null) { callListenerOnTextInput(key.mOutputText); - callListenerOnRelease(key.mCodes[0]); + callListenerOnRelease(key.mCode); } else { - int code = key.mCodes[0]; + int code = key.mCode; final int[] codes = mKeyDetector.newCodeArray(); mKeyDetector.getKeyIndexAndNearbyCodes(x, y, codes); - // Multi-tap - if (mInMultiTap) { - if (mTapCount != -1) { - callListenerOnCodeInput(Keyboard.CODE_DELETE, KEY_DELETE, x, y); - } else { - mTapCount = 0; - } - code = key.mCodes[mTapCount]; - } // If keyboard is in manual temporary upper case state and key has manual temporary // shift code, alternate character code should be sent. @@ -477,51 +453,10 @@ public class PointerTracker { callListenerOnCodeInput(code, codes, x, y); callListenerOnRelease(code); } - mLastSentIndex = index; - mLastTapTime = eventTime; } - /** - * Handle multi-tap keys by producing the key label for the current multi-tap state. - */ public CharSequence getPreviewText(Key key) { - if (mInMultiTap) { - // Multi-tap - mPreviewLabel.setLength(0); - mPreviewLabel.append((char) key.mCodes[mTapCount < 0 ? 0 : mTapCount]); - return mPreviewLabel; - } else { - return key.mLabel; - } - } - - private void resetMultiTap() { - mLastSentIndex = NOT_A_KEY; - mTapCount = 0; - mLastTapTime = -1; - mInMultiTap = false; - } - - private void checkMultiTap(long eventTime, int keyIndex) { - Key key = getKey(keyIndex); - if (key == null) - return; - - final boolean isMultiTap = - (eventTime < mLastTapTime + mMultiTapKeyTimeout && keyIndex == mLastSentIndex); - if (key.mCodes.length > 1) { - mInMultiTap = true; - if (isMultiTap) { - mTapCount = (mTapCount + 1) % key.mCodes.length; - return; - } else { - mTapCount = -1; - return; - } - } - if (!isMultiTap) { - resetMultiTap(); - } + return key.mLabel; } private long mPreviousEventTime; @@ -529,7 +464,7 @@ public class PointerTracker { private void printTouchEvent(String title, int x, int y, long eventTime) { final int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null); final Key key = getKey(keyIndex); - final String code = (key == null) ? "----" : keyCodePrintable(key.mCodes[0]); + final String code = (key == null) ? "----" : keyCodePrintable(key.mCode); final long delta = eventTime - mPreviousEventTime; Log.d(TAG, String.format("%s%s[%d] %4d %4d %5d %3d(%s)", title, (mKeyAlreadyProcessed ? "-" : " "), mPointerId, x, y, delta, keyIndex, code)); diff --git a/java/src/com/android/inputmethod/keyboard/PopupCharactersParser.java b/java/src/com/android/inputmethod/keyboard/PopupCharactersParser.java index cad3da03e..32c25801d 100644 --- a/java/src/com/android/inputmethod/keyboard/PopupCharactersParser.java +++ b/java/src/com/android/inputmethod/keyboard/PopupCharactersParser.java @@ -39,7 +39,6 @@ public class PopupCharactersParser { private static final String PREFIX_AT = "@"; private static final String PREFIX_ICON = PREFIX_AT + "drawable/"; private static final String PREFIX_CODE = PREFIX_AT + "integer/"; - private static final int[] DUMMY_CODES = { 0 }; private PopupCharactersParser() { // Intentional empty constructor for utility class. @@ -126,13 +125,13 @@ public class PopupCharactersParser { final String label = getLabel(popupSpec); if (label == null) throw new PopupCharactersParserError("Empty label: " + popupSpec); - // Code is automatically generated for one letter label. See getCode(). + // Code is automatically generated for one letter label. See {@link getCode()}. if (label.length() == 1) return null; return label; } - public static int[] getCodes(Resources res, String popupSpec) { + public static int getCode(Resources res, String popupSpec) { if (hasCode(popupSpec)) { final int end = indexOfLabelEnd(popupSpec, 0); if (indexOfLabelEnd(popupSpec, end + 1) >= 0) @@ -140,15 +139,15 @@ public class PopupCharactersParser { final int resId = getResourceId(res, popupSpec.substring(end + LABEL_END.length() + PREFIX_AT.length())); final int code = res.getInteger(resId); - return new int[] { code }; + return code; } if (indexOfLabelEnd(popupSpec, 0) > 0) - return DUMMY_CODES; + return Keyboard.CODE_DUMMY; final String label = getLabel(popupSpec); // Code is automatically generated for one letter label. if (label != null && label.length() == 1) - return new int[] { label.charAt(0) }; - return DUMMY_CODES; + return label.charAt(0); + return Keyboard.CODE_DUMMY; } public static Drawable getIcon(Resources res, String popupSpec) { diff --git a/java/src/com/android/inputmethod/keyboard/ProximityKeyDetector.java b/java/src/com/android/inputmethod/keyboard/ProximityKeyDetector.java index bd4bbcd89..0920da2cb 100644 --- a/java/src/com/android/inputmethod/keyboard/ProximityKeyDetector.java +++ b/java/src/com/android/inputmethod/keyboard/ProximityKeyDetector.java @@ -46,17 +46,16 @@ public class ProximityKeyDetector extends KeyDetector { final int dist = key.squaredDistanceToEdge(touchX, touchY); if (isInside || (mProximityCorrectOn && dist < mProximityThresholdSquare)) { if (allKeys == null) continue; - final int nCodes = key.mCodes.length; // Find insertion point for (int j = 0; j < distances.length; j++) { if (distances[j] > dist) { - // Make space for nCodes codes - System.arraycopy(distances, j, distances, j + nCodes, - distances.length - (j + nCodes)); - System.arraycopy(allKeys, j, allKeys, j + nCodes, - allKeys.length - (j + nCodes)); - System.arraycopy(key.mCodes, 0, allKeys, j, nCodes); - Arrays.fill(distances, j, j + nCodes, dist); + final int nextPos = j + 1; + System.arraycopy(distances, j, distances, nextPos, + distances.length - nextPos); + System.arraycopy(allKeys, j, allKeys, nextPos, + allKeys.length - nextPos); + distances[j] = dist; + allKeys[j] = key.mCode; break; } } diff --git a/java/src/com/android/inputmethod/latin/TextEntryState.java b/java/src/com/android/inputmethod/latin/TextEntryState.java index f10b86293..f571f26d5 100644 --- a/java/src/com/android/inputmethod/latin/TextEntryState.java +++ b/java/src/com/android/inputmethod/latin/TextEntryState.java @@ -263,9 +263,9 @@ public class TextEntryState { } public static void keyPressedAt(Key key, int x, int y) { - if (LOGGING && sKeyLocationFile != null && key.mCodes[0] >= 32) { + if (LOGGING && sKeyLocationFile != null && key.mCode >= 32) { String out = - "KEY: " + (char) key.mCodes[0] + "KEY: " + (char) key.mCode + " X: " + x + " Y: " + y + " MX: " + (key.mX + key.mWidth / 2) diff --git a/tests/src/com/android/inputmethod/keyboard/KeyStylesTests.java b/tests/src/com/android/inputmethod/keyboard/KeyStylesTests.java index 3f2b7f4d5..5dff11471 100644 --- a/tests/src/com/android/inputmethod/keyboard/KeyStylesTests.java +++ b/tests/src/com/android/inputmethod/keyboard/KeyStylesTests.java @@ -22,23 +22,6 @@ import android.test.AndroidTestCase; import android.text.TextUtils; public class KeyStylesTests extends AndroidTestCase { - private static void assertNumberFormatException(String message, String value) { - try { - EmptyKeyStyle.parseCsvInt(value); - fail(message); - } catch (NumberFormatException nfe) { - // success. - } - } - - private static void assertIntArray(String message, String value, Integer ... expected) { - final int actual[] = EmptyKeyStyle.parseCsvInt(value); - assertSame(message + ": result length", expected.length, actual.length); - for (int i = 0; i < actual.length; i++) { - assertEquals(message + ": result at " + i + ":", (int)expected[i], actual[i]); - } - } - private static String format(String message, Object expected, Object actual) { return message + " expected:<" + expected + "> but was:<" + actual + ">"; } @@ -57,19 +40,6 @@ public class KeyStylesTests extends AndroidTestCase { } } - public void testParseCsvInt() { - assertIntArray("Empty string", ""); - assertNumberFormatException("Spaces", " "); - assertNumberFormatException("Non-decimal number", "abc"); - assertIntArray("Single number", "123", 123); - assertIntArray("Negative number", "-123", -123); - assertNumberFormatException("Hexadecimal number", "1b2b"); - assertIntArray("Multiple numbers", "123,456", 123, 456); - assertNumberFormatException("Non-decimal numbers", "123,abc"); - assertNumberFormatException("Escaped comma", "123\\,456"); - assertNumberFormatException("Escaped escape", "123\\\\,456"); - } - public void testParseCsvTextZero() { assertTextArray("Empty string", ""); } diff --git a/tests/src/com/android/inputmethod/keyboard/PopupCharactersParserTests.java b/tests/src/com/android/inputmethod/keyboard/PopupCharactersParserTests.java index 77b62ca5d..ae78866e6 100644 --- a/tests/src/com/android/inputmethod/keyboard/PopupCharactersParserTests.java +++ b/tests/src/com/android/inputmethod/keyboard/PopupCharactersParserTests.java @@ -32,8 +32,6 @@ public class PopupCharactersParserTests extends AndroidTestCase { private int mCodeSettings; private Drawable mIconSettings; - private static final Integer[] DUMMY_CODES = { 0 }; - @Override protected void setUp() { Resources res = getContext().getResources(); @@ -47,7 +45,7 @@ public class PopupCharactersParserTests extends AndroidTestCase { } private void assertParser(String message, String popupSpec, String expectedLabel, - String expectedOutputText, Drawable expectedIcon, Integer ... expectedCodes) { + String expectedOutputText, Drawable expectedIcon, int expectedCode) { String actualLabel = PopupCharactersParser.getLabel(popupSpec); assertEquals(message + ": label:", expectedLabel, actualLabel); @@ -62,28 +60,15 @@ public class PopupCharactersParserTests extends AndroidTestCase { assertNotNull(message + ": icon non-null:", actualIcon); } - int[] actualCodes = PopupCharactersParser.getCodes(mRes, popupSpec); - if (expectedCodes == null) { - assertNull(message + ": codes null:", actualCodes); - return; - } - assertSame(message + ": codes length:", expectedCodes.length, actualCodes.length); - for (int i = 0; i < actualCodes.length; i++) { - assertEquals(message + ": codes value at " + i + ":", (int)expectedCodes[i], - actualCodes[i]); - } + int actualCode = PopupCharactersParser.getCode(mRes, popupSpec); + assertEquals(message + ": codes value:", expectedCode, actualCode); } private void assertParserError(String message, String popupSpec, String expectedLabel, - String expectedOutputText, Drawable expectedIcon, Integer ... expectedCodes) { + String expectedOutputText, Drawable expectedIcon, int expectedCode) { try { - if (expectedCodes.length > 0) { - assertParser(message, popupSpec, expectedLabel, expectedOutputText, expectedIcon, - expectedCodes); - } else { - assertParser(message, popupSpec, expectedLabel, expectedOutputText, expectedIcon, - DUMMY_CODES); - } + assertParser(message, popupSpec, expectedLabel, expectedOutputText, expectedIcon, + expectedCode); fail(message); } catch (PopupCharactersParser.PopupCharactersParserError pcpe) { // success. @@ -91,71 +76,83 @@ public class PopupCharactersParserTests extends AndroidTestCase { } public void testSingleLetter() { - assertParser("Single letter", "a", "a", null, null, (int)'a'); - assertParser("Single escaped bar", "\\|", "|", null, null, (int)'|'); - assertParser("Single escaped escape", "\\\\", "\\", null, null, (int)'\\'); - assertParser("Single comma", ",", ",", null, null, (int)','); - assertParser("Single escaped comma", "\\,", ",", null, null, (int)','); - assertParser("Single escaped letter", "\\a", "a", null, null, (int)'a'); - assertParser("Single at", "@", "@", null, null, (int)'@'); - assertParser("Single escaped at", "\\@", "@", null, null, (int)'@'); - assertParser("Single letter with outputText", "a|abc", "a", "abc", null, DUMMY_CODES); + assertParser("Single letter", "a", "a", null, null, 'a'); + assertParser("Single escaped bar", "\\|", "|", null, null, '|'); + assertParser("Single escaped escape", "\\\\", "\\", null, null, '\\'); + assertParser("Single comma", ",", ",", null, null, ','); + assertParser("Single escaped comma", "\\,", ",", null, null, ','); + assertParser("Single escaped letter", "\\a", "a", null, null, 'a'); + assertParser("Single at", "@", "@", null, null, '@'); + assertParser("Single escaped at", "\\@", "@", null, null, '@'); + assertParser("Single letter with outputText", "a|abc", "a", "abc", null, + Keyboard.CODE_DUMMY); assertParser("Single letter with escaped outputText", "a|a\\|c", "a", "a|c", null, - DUMMY_CODES); - assertParser("Single letter with comma outputText", "a|a,b", "a", "a,b", null, DUMMY_CODES); + Keyboard.CODE_DUMMY); + assertParser("Single letter with comma outputText", "a|a,b", "a", "a,b", null, + Keyboard.CODE_DUMMY); assertParser("Single letter with escaped comma outputText", "a|a\\,b", "a", "a,b", null, - DUMMY_CODES); + Keyboard.CODE_DUMMY); assertParser("Single letter with outputText starts with at", "a|@bc", "a", "@bc", null, - DUMMY_CODES); + Keyboard.CODE_DUMMY); assertParser("Single letter with outputText contains at", "a|a@c", "a", "a@c", null, - DUMMY_CODES); + Keyboard.CODE_DUMMY); assertParser("Single letter with escaped at outputText", "a|\\@bc", "a", "@bc", null, - DUMMY_CODES); + Keyboard.CODE_DUMMY); assertParser("Single escaped escape with outputText", "\\\\|\\\\", "\\", "\\", null, - DUMMY_CODES); - assertParser("Single escaped bar with outputText", "\\||\\|", "|", "|", null, DUMMY_CODES); + Keyboard.CODE_DUMMY); + assertParser("Single escaped bar with outputText", "\\||\\|", "|", "|", null, + Keyboard.CODE_DUMMY); assertParser("Single letter with code", "a|" + CODE_SETTINGS, "a", null, null, mCodeSettings); } public void testLabel() { - assertParser("Simple label", "abc", "abc", "abc", null, DUMMY_CODES); - assertParser("Label with escaped bar", "a\\|c", "a|c", "a|c", null, DUMMY_CODES); - assertParser("Label with escaped escape", "a\\\\c", "a\\c", "a\\c", null, DUMMY_CODES); - assertParser("Label with comma", "a,c", "a,c", "a,c", null, DUMMY_CODES); - assertParser("Label with escaped comma", "a\\,c", "a,c", "a,c", null, DUMMY_CODES); - assertParser("Label starts with at", "@bc", "@bc", "@bc", null, DUMMY_CODES); - assertParser("Label contains at", "a@c", "a@c", "a@c", null, DUMMY_CODES); - assertParser("Label with escaped at", "\\@bc", "@bc", "@bc", null, DUMMY_CODES); - assertParser("Label with escaped letter", "\\abc", "abc", "abc", null, DUMMY_CODES); - assertParser("Label with outputText", "abc|def", "abc", "def", null, DUMMY_CODES); - assertParser("Label with comma and outputText", "a,c|def", "a,c", "def", null, DUMMY_CODES); + assertParser("Simple label", "abc", "abc", "abc", null, Keyboard.CODE_DUMMY); + assertParser("Label with escaped bar", "a\\|c", "a|c", "a|c", null, + Keyboard.CODE_DUMMY); + assertParser("Label with escaped escape", "a\\\\c", "a\\c", "a\\c", null, + Keyboard.CODE_DUMMY); + assertParser("Label with comma", "a,c", "a,c", "a,c", null, Keyboard.CODE_DUMMY); + assertParser("Label with escaped comma", "a\\,c", "a,c", "a,c", null, + Keyboard.CODE_DUMMY); + assertParser("Label starts with at", "@bc", "@bc", "@bc", null, Keyboard.CODE_DUMMY); + assertParser("Label contains at", "a@c", "a@c", "a@c", null, Keyboard.CODE_DUMMY); + assertParser("Label with escaped at", "\\@bc", "@bc", "@bc", null, + Keyboard.CODE_DUMMY); + assertParser("Label with escaped letter", "\\abc", "abc", "abc", null, + Keyboard.CODE_DUMMY); + assertParser("Label with outputText", "abc|def", "abc", "def", null, + Keyboard.CODE_DUMMY); + assertParser("Label with comma and outputText", "a,c|def", "a,c", "def", null, + Keyboard.CODE_DUMMY); assertParser("Escaped comma label with outputText", "a\\,c|def", "a,c", "def", null, - DUMMY_CODES); - assertParser("Escaped label with outputText", "a\\|c|def", "a|c", "def", null, DUMMY_CODES); + Keyboard.CODE_DUMMY); + assertParser("Escaped label with outputText", "a\\|c|def", "a|c", "def", null, + Keyboard.CODE_DUMMY); assertParser("Label with escaped bar outputText", "abc|d\\|f", "abc", "d|f", null, - DUMMY_CODES); + Keyboard.CODE_DUMMY); assertParser("Escaped escape label with outputText", "a\\\\|def", "a\\", "def", null, - DUMMY_CODES); + Keyboard.CODE_DUMMY); assertParser("Label starts with at and outputText", "@bc|def", "@bc", "def", null, - DUMMY_CODES); + Keyboard.CODE_DUMMY); assertParser("Label contains at label and outputText", "a@c|def", "a@c", "def", null, - DUMMY_CODES); + Keyboard.CODE_DUMMY); assertParser("Escaped at label with outputText", "\\@bc|def", "@bc", "def", null, - DUMMY_CODES); - assertParser("Label with comma outputText", "abc|a,b", "abc", "a,b", null, DUMMY_CODES); + Keyboard.CODE_DUMMY); + assertParser("Label with comma outputText", "abc|a,b", "abc", "a,b", null, + Keyboard.CODE_DUMMY); assertParser("Label with escaped comma outputText", "abc|a\\,b", "abc", "a,b", null, - DUMMY_CODES); + Keyboard.CODE_DUMMY); assertParser("Label with outputText starts with at", "abc|@bc", "abc", "@bc", null, - DUMMY_CODES); + Keyboard.CODE_DUMMY); assertParser("Label with outputText contains at", "abc|a@c", "abc", "a@c", null, - DUMMY_CODES); + Keyboard.CODE_DUMMY); assertParser("Label with escaped at outputText", "abc|\\@bc", "abc", "@bc", null, - DUMMY_CODES); + Keyboard.CODE_DUMMY); assertParser("Label with escaped bar outputText", "abc|d\\|f", "abc", "d|f", - null, DUMMY_CODES); + null, Keyboard.CODE_DUMMY); assertParser("Escaped bar label with escaped bar outputText", "a\\|c|d\\|f", "a|c", "d|f", - null, DUMMY_CODES); + null, Keyboard.CODE_DUMMY); assertParser("Label with code", "abc|" + CODE_SETTINGS, "abc", null, null, mCodeSettings); assertParser("Escaped label with code", "a\\|c|" + CODE_SETTINGS, "a|c", null, null, mCodeSettings); @@ -163,13 +160,13 @@ public class PopupCharactersParserTests extends AndroidTestCase { public void testIconAndCode() { assertParser("Icon with outputText", ICON_SETTINGS + "|abc", null, "abc", mIconSettings, - DUMMY_CODES); + Keyboard.CODE_DUMMY); assertParser("Icon with outputText starts with at", ICON_SETTINGS + "|@bc", null, "@bc", - mIconSettings, DUMMY_CODES); + mIconSettings, Keyboard.CODE_DUMMY); assertParser("Icon with outputText contains at", ICON_SETTINGS + "|a@c", null, "a@c", - mIconSettings, DUMMY_CODES); + mIconSettings, Keyboard.CODE_DUMMY); assertParser("Icon with escaped at outputText", ICON_SETTINGS + "|\\@bc", null, "@bc", - mIconSettings, DUMMY_CODES); + mIconSettings, Keyboard.CODE_DUMMY); assertParser("Label starts with at and code", "@bc|" + CODE_SETTINGS, "@bc", null, null, mCodeSettings); assertParser("Label contains at and code", "a@c|" + CODE_SETTINGS, "a@c", null, null, @@ -181,23 +178,28 @@ public class PopupCharactersParserTests extends AndroidTestCase { } public void testFormatError() { - assertParserError("Empty spec", "", null, null, null); - assertParserError("Empty label with outputText", "|a", null, "a", null); + assertParserError("Empty spec", "", null, null, null, Keyboard.CODE_UNSPECIFIED); + assertParserError("Empty label with outputText", "|a", null, "a", null, + Keyboard.CODE_DUMMY); assertParserError("Empty label with code", "|" + CODE_SETTINGS, null, null, null, mCodeSettings); - assertParserError("Empty outputText with label", "a|", "a", null, null); + assertParserError("Empty outputText with label", "a|", "a", null, null, + Keyboard.CODE_UNSPECIFIED); assertParserError("Empty outputText with icon", ICON_SETTINGS + "|", null, null, - mIconSettings); - assertParserError("Empty icon and code", "|", null, null, null); - assertParserError("Icon without code", ICON_SETTINGS, null, null, mIconSettings); - assertParserError("Non existing icon", ICON_NON_EXISTING + "|abc", null, "abc", null); - assertParserError("Non existing code", "abc|" + CODE_NON_EXISTING, "abc", null, null); - assertParserError("Third bar at end", "a|b|", "a", null, null); - assertParserError("Multiple bar", "a|b|c", "a", null, null); + mIconSettings, Keyboard.CODE_UNSPECIFIED); + assertParserError("Empty icon and code", "|", null, null, null, Keyboard.CODE_UNSPECIFIED); + assertParserError("Icon without code", ICON_SETTINGS, null, null, mIconSettings, + Keyboard.CODE_DUMMY); + assertParserError("Non existing icon", ICON_NON_EXISTING + "|abc", null, "abc", null, + Keyboard.CODE_DUMMY); + assertParserError("Non existing code", "abc|" + CODE_NON_EXISTING, "abc", null, null, + Keyboard.CODE_UNSPECIFIED); + assertParserError("Third bar at end", "a|b|", "a", null, null, Keyboard.CODE_UNSPECIFIED); + assertParserError("Multiple bar", "a|b|c", "a", null, null, Keyboard.CODE_UNSPECIFIED); assertParserError("Multiple bar with label and code", "a|" + CODE_SETTINGS + "|c", "a", null, null, mCodeSettings); assertParserError("Multiple bar with icon and outputText", ICON_SETTINGS + "|b|c", null, - null, mIconSettings); + null, mIconSettings, Keyboard.CODE_UNSPECIFIED); assertParserError("Multiple bar with icon and code", ICON_SETTINGS + "|" + CODE_SETTINGS + "|c", null, null, mIconSettings, mCodeSettings);