diff options
Diffstat (limited to 'java/src')
13 files changed, 122 insertions, 77 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 7396f0518..59c132e91 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -83,8 +83,8 @@ public class Key { * {@link Keyboard#EDGE_TOP} and {@link Keyboard#EDGE_BOTTOM}. */ public final int mEdgeFlags; - /** Whether this is a modifier key, such as Shift or Alt */ - public final boolean mModifier; + /** Whether this is a functional key which has different key top than normal key */ + public final boolean mFunctional; /** Whether this key repeats itself when held down */ public final boolean mRepeatable; @@ -93,8 +93,8 @@ public class Key { /** The current pressed state of this key */ public boolean mPressed; - /** If this is a sticky key, is it on? */ - public boolean mOn; + /** If this is a sticky key, is its highlight on? */ + public boolean mHighlightOn; /** Key is enabled and responds on press */ public boolean mEnabled = true; @@ -150,7 +150,7 @@ public class Key { mManualTemporaryUpperCaseHintIcon = null; mManualTemporaryUpperCaseCode = Keyboard.CODE_DUMMY; mLabelOption = 0; - mModifier = false; + mFunctional = false; mSticky = false; mRepeatable = false; mPopupCharacters = null; @@ -224,7 +224,7 @@ public class Key { mKeyboard.getMaxPopupKeyboardColumn()); mRepeatable = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable, false); - mModifier = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isModifier, false); + mFunctional = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isFunctional, false); mSticky = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky, false); mEnabled = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_enabled, true); mEdgeFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyEdgeFlags, 0) @@ -315,22 +315,19 @@ public class Key { /** * Informs the key that it has been pressed, in case it needs to change its appearance or * state. - * @see #onReleased(boolean) + * @see #onReleased() */ public void onPressed() { - mPressed = !mPressed; + mPressed = true; } /** - * Changes the pressed state of the key. If it is a sticky key, it will also change the - * toggled state of the key if the finger was release inside. - * @param inside whether the finger was released inside the key + * Informs the key that it has been released, in case it needs to change its appearance or + * state. * @see #onPressed() */ - public void onReleased(boolean inside) { - mPressed = !mPressed; - if (mSticky && !mKeyboard.isShiftLockEnabled(this)) - mOn = !mOn; + public void onReleased() { + mPressed = false; } public boolean isInside(int x, int y) { @@ -376,20 +373,14 @@ public class Key { return dx * dx + dy * dy; } - // sticky is used for shift key. If a key is not sticky and is modifier, - // the key will be treated as functional. - private boolean isFunctionalKey() { - return !mSticky && mModifier; - } - /** * Returns the drawable state for the key, based on the current state and type of the key. * @return the drawable state of the key. * @see android.graphics.drawable.StateListDrawable#setState(int[]) */ public int[] getCurrentDrawableState() { - final boolean pressed = mEnabled && mPressed; - if (isFunctionalKey()) { + final boolean pressed = mPressed; + if (!mSticky && mFunctional) { if (pressed) { return KEY_STATE_FUNCTIONAL_PRESSED; } else { @@ -399,7 +390,7 @@ public class Key { int[] states = KEY_STATE_NORMAL; - if (mOn) { + if (mHighlightOn) { if (pressed) { states = KEY_STATE_PRESSED_ON; } else { diff --git a/java/src/com/android/inputmethod/keyboard/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/KeyStyles.java index 169f2e6c3..d464c2029 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyStyles.java +++ b/java/src/com/android/inputmethod/keyboard/KeyStyles.java @@ -185,7 +185,7 @@ public class KeyStyles { readDrawable(keyAttr, R.styleable.Keyboard_Key_iconPreview); readDrawable(keyAttr, R.styleable.Keyboard_Key_keyHintIcon); readDrawable(keyAttr, R.styleable.Keyboard_Key_shiftedIcon); - readBoolean(keyAttr, R.styleable.Keyboard_Key_isModifier); + readBoolean(keyAttr, R.styleable.Keyboard_Key_isFunctional); readBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky); readBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable); readBoolean(keyAttr, R.styleable.Keyboard_Key_enabled); diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 06d44680d..f720334f1 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -165,7 +165,9 @@ public class Keyboard { GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height); GRID_SIZE = GRID_WIDTH * GRID_HEIGHT; - mDisplayWidth = width; + final int horizontalEdgesPadding = (int)res.getDimension( + R.dimen.keyboard_horizontal_edges_padding); + mDisplayWidth = width - horizontalEdgesPadding * 2; mDisplayHeight = height; mDefaultHorizontalGap = 0; @@ -293,7 +295,7 @@ public class Keyboard { public boolean setShiftLocked(boolean newShiftLockState) { final Map<Key, Drawable> shiftedIcons = getShiftedIcons(); for (final Key key : getShiftKeys()) { - key.mOn = newShiftLockState; + key.mHighlightOn = newShiftLockState; key.setIcon(newShiftLockState ? shiftedIcons.get(key) : mNormalShiftIcons.get(key)); } mShiftState.setShiftLocked(newShiftLockState); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java index 62e6f302d..9c556c309 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java @@ -122,6 +122,7 @@ public class KeyboardParser { private final Keyboard mKeyboard; private final Resources mResources; + private int mHorizontalEdgesPadding; private int mCurrentX = 0; private int mCurrentY = 0; private int mMaxRowWidth = 0; @@ -132,6 +133,7 @@ public class KeyboardParser { public KeyboardParser(Keyboard keyboard, Resources res) { mKeyboard = keyboard; mResources = res; + mHorizontalEdgesPadding = (int)res.getDimension(R.dimen.keyboard_horizontal_edges_padding); } public int getMaxRowWidth() { @@ -151,6 +153,7 @@ public class KeyboardParser { final String tag = parser.getName(); if (TAG_KEYBOARD.equals(tag)) { parseKeyboardAttributes(parser); + startKeyboard(); parseKeyboardContent(parser, mKeyboard.getKeys()); break; } else { @@ -520,25 +523,32 @@ public class KeyboardParser { throw new NonEmptyTag(tag, parser); } + private void startKeyboard() { + mCurrentY += (int)mResources.getDimension(R.dimen.keyboard_top_padding); + } + private void startRow(Row row) { mCurrentX = 0; + setSpacer(mHorizontalEdgesPadding); mCurrentRow = row; } private void endRow() { if (mCurrentRow == null) throw new InflateException("orphant end row tag"); + setSpacer(mHorizontalEdgesPadding); + if (mCurrentX > mMaxRowWidth) + mMaxRowWidth = mCurrentX; mCurrentY += mCurrentRow.mDefaultHeight; mCurrentRow = null; } private void endKey(Key key) { mCurrentX += key.mGap + key.mWidth; - if (mCurrentX > mMaxRowWidth) - mMaxRowWidth = mCurrentX; } private void endKeyboard(int defaultVerticalGap) { + mCurrentY += (int)mResources.getDimension(R.dimen.keyboard_bottom_padding); mTotalHeight = mCurrentY - defaultVerticalGap; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index cfa3c446e..dd25b3427 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -263,10 +263,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha int xmlId = mode == KeyboardId.MODE_PHONE ? R.xml.kbd_phone : R.xml.kbd_symbols; final String xmlName = res.getResourceEntryName(xmlId); mSymbolsId = new KeyboardId(xmlName, xmlId, colorScheme, locale, orientation, mode, - attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, true); + attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, false); xmlId = mode == KeyboardId.MODE_PHONE ? R.xml.kbd_phone_symbols : R.xml.kbd_symbols_shift; mSymbolsShiftedId = new KeyboardId(xmlName, xmlId, colorScheme, locale, orientation, mode, - attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, true); + attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, false); } public int getKeyboardMode() { @@ -565,16 +565,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha mCurrentId = mSymbolsShiftedId; keyboard = getKeyboard(mCurrentId); // Symbol shifted keyboard has an ALT key that has a caps lock style indicator. To - // enable the indicator, we need to call enableShiftLock() and setShiftLocked(true). - // Thus we can keep the ALT key's Key.on value true while LatinKey.onRelease() is - // called. + // enable the indicator, we need to call setShiftLocked(true). keyboard.setShiftLocked(true); } else { mCurrentId = mSymbolsId; keyboard = getKeyboard(mCurrentId); // Symbol keyboard has an ALT key that has a caps lock style indicator. To disable the - // indicator, we need to call enableShiftLock() and setShiftLocked(false). - keyboard.setShifted(false); + // indicator, we need to call setShiftLocked(false). + keyboard.setShiftLocked(false); } setKeyboard(keyboard); } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 61af15b1d..e82796bf4 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -37,7 +37,6 @@ import android.graphics.drawable.Drawable; import android.os.Handler; import android.os.Message; import android.os.SystemClock; -import android.provider.Settings; import android.util.AttributeSet; import android.util.Log; import android.util.TypedValue; @@ -378,6 +377,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { } mPreviewPopup.setTouchable(false); mPreviewPopup.setAnimationStyle(R.style.KeyPreviewAnimation); + mPreviewPopup.setClippingEnabled(false); mDelayBeforePreview = res.getInteger(R.integer.config_delay_before_preview); mDelayAfterPreview = res.getInteger(R.integer.config_delay_after_preview); mKeyLabelHorizontalPadding = (int)res.getDimension( @@ -1056,7 +1056,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0); } - private void onDoubleTapShiftKey(PointerTracker tracker) { + private void onDoubleTapShiftKey(@SuppressWarnings("unused") PointerTracker tracker) { // When shift key is double tapped, the first tap is correctly processed as usual tap. And // the second tap is treated as this double tap event, so that we need not mark tracker // calling setAlreadyProcessed() nor remove the tracker from mPointerQueueueue. diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 5820049bb..9b87df3fe 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -229,7 +229,7 @@ public class LatinKeyboard extends Keyboard { final Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(buffer); final Resources res = mContext.getResources(); - canvas.drawColor(res.getColor(R.color.latinkeyboard_transparent), PorterDuff.Mode.CLEAR); + canvas.drawColor(res.getColor(android.R.color.transparent), PorterDuff.Mode.CLEAR); SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance(); // If application locales are explicitly selected. diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 746857819..eb5335ffd 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -87,6 +87,9 @@ public class PointerTracker { // true if sliding key is allowed. private boolean mIsAllowedSlidingKeyInput; + // ignore modifier key if true + private boolean mIgnoreModifierKey; + // pressed key private int mPreviousKey = NOT_A_KEY; @@ -139,8 +142,12 @@ public class PointerTracker { // Returns true if keyboard has been changed by this callback. private boolean callListenerOnPressAndCheckKeyboardLayoutChange(Key key, boolean withSliding) { + final boolean ignoreModifierKey = mIgnoreModifierKey && isModifierCode(key.mCode); if (DEBUG_LISTENER) - Log.d(TAG, "onPress : " + keyCodePrintable(key.mCode) + " sliding=" + withSliding); + Log.d(TAG, "onPress : " + keyCodePrintable(key.mCode) + " sliding=" + withSliding + + " ignoreModifier=" + ignoreModifierKey); + if (ignoreModifierKey) + return false; if (key.mEnabled) { mListener.onPress(key.mCode, withSliding); final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged; @@ -153,9 +160,13 @@ public class PointerTracker { // Note that we need primaryCode argument because the keyboard may in shifted state and the // primaryCode is different from {@link Key#mCode}. private void callListenerOnCodeInput(Key key, int primaryCode, int[] keyCodes, int x, int y) { + final boolean ignoreModifierKey = mIgnoreModifierKey && isModifierCode(key.mCode); if (DEBUG_LISTENER) Log.d(TAG, "onCodeInput: " + keyCodePrintable(primaryCode) - + " codes="+ Arrays.toString(keyCodes) + " x=" + x + " y=" + y); + + " codes="+ Arrays.toString(keyCodes) + " x=" + x + " y=" + y + + " ignoreModifier=" + ignoreModifierKey); + if (ignoreModifierKey) + return; if (key.mEnabled) mListener.onCodeInput(primaryCode, keyCodes, x, y); } @@ -170,8 +181,12 @@ public class PointerTracker { // Note that we need primaryCode argument because the keyboard may in shifted state and the // primaryCode is different from {@link Key#mCode}. private void callListenerOnRelease(Key key, int primaryCode, boolean withSliding) { + final boolean ignoreModifierKey = mIgnoreModifierKey && isModifierCode(key.mCode); if (DEBUG_LISTENER) - Log.d(TAG, "onRelease : " + keyCodePrintable(primaryCode) + " sliding=" + withSliding); + Log.d(TAG, "onRelease : " + keyCodePrintable(primaryCode) + " sliding=" + + withSliding + " ignoreModifier=" + ignoreModifierKey); + if (ignoreModifierKey) + return; if (key.mEnabled) mListener.onRelease(primaryCode, withSliding); } @@ -243,9 +258,7 @@ public class PointerTracker { mPreviousKey = keyIndex; if (keyIndex != oldKeyIndex) { if (isValidKeyIndex(oldKeyIndex)) { - // if new key index is not a key, old key was just released inside of the key. - final boolean inside = (keyIndex == NOT_A_KEY); - mKeys[oldKeyIndex].onReleased(inside); + mKeys[oldKeyIndex].onReleased(); mProxy.invalidateKey(mKeys[oldKeyIndex]); } if (isValidKeyIndex(keyIndex)) { @@ -329,17 +342,18 @@ public class PointerTracker { mKeyAlreadyProcessed = false; mIsRepeatableKey = false; mIsInSlidingKeyInput = false; - if (isValidKeyIndex(keyIndex)) { + mIgnoreModifierKey = false; + final Key key = getKey(keyIndex); + if (key != null) { // This onPress call may have changed keyboard layout. Those cases are detected at // {@link #setKeyboard}. In those cases, we should update keyIndex according to the new // keyboard layout. - if (callListenerOnPressAndCheckKeyboardLayoutChange(mKeys[keyIndex], false)) + if (callListenerOnPressAndCheckKeyboardLayoutChange(key, false)) keyIndex = mKeyState.onDownKey(x, y, eventTime); - } - if (isValidKeyIndex(keyIndex)) { + // Accessibility disables key repeat because users may need to pause on a key to hear // its spoken description. - if (mKeys[keyIndex].mRepeatable && !mIsAccessibilityEnabled) { + if (key.mRepeatable && !mIsAccessibilityEnabled) { repeatKey(keyIndex); mHandler.startKeyRepeatTimer(mDelayBeforeKeyRepeatStart, keyIndex, this); mIsRepeatableKey = true; @@ -349,6 +363,12 @@ public class PointerTracker { showKeyPreviewAndUpdateKeyGraphics(keyIndex); } + private void startSlidingKeyInput(Key key) { + if (!mIsInSlidingKeyInput) + mIgnoreModifierKey = isModifierCode(key.mCode); + mIsInSlidingKeyInput = true; + } + public void onMoveEvent(int x, int y, long eventTime, PointerTrackerQueue queue) { if (ENABLE_ASSERTION) checkAssertion(queue); if (DEBUG_MOVE_EVENT) @@ -376,8 +396,8 @@ public class PointerTracker { // The pointer has been slid in to the new key from the previous key, we must call // 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, oldKey.mCode, true); + startSlidingKeyInput(oldKey); mHandler.cancelLongPressTimers(); if (mIsAllowedSlidingKeyInput) { // This onPress call may have changed keyboard layout. Those cases are detected @@ -411,8 +431,8 @@ public class PointerTracker { if (oldKey != null && !isMinorMoveBounce(x, y, keyIndex)) { // 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, oldKey.mCode, true); + startSlidingKeyInput(oldKey); mHandler.cancelLongPressTimers(); if (mIsAllowedSlidingKeyInput) { keyState.onMoveToNewKey(keyIndex, x ,y); @@ -423,7 +443,7 @@ public class PointerTracker { } } } - showKeyPreviewAndUpdateKeyGraphics(mKeyState.getKeyIndex()); + showKeyPreviewAndUpdateKeyGraphics(keyState.getKeyIndex()); } public void onUpEvent(int x, int y, long eventTime, PointerTrackerQueue queue) { @@ -526,6 +546,9 @@ public class PointerTracker { } private void showKeyPreviewAndUpdateKeyGraphics(int keyIndex) { + final Key key = getKey(keyIndex); + if (key != null && !key.mEnabled) + return; updateKeyGraphics(keyIndex); // The modifier key, such as shift key, should not be shown as preview when multi-touch is // supported. On the other hand, if multi-touch is not supported, the modifier key should @@ -545,6 +568,8 @@ public class PointerTracker { return; } Key key = getKey(keyIndex); + if (!key.mEnabled) + return; if (key.mCode == Keyboard.CODE_SHIFT) { mHandler.startLongPressShiftTimer(mLongPressShiftKeyTimeout, keyIndex, this); } else if (key.mManualTemporaryUpperCaseCode != Keyboard.CODE_DUMMY diff --git a/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java b/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java index 41f8c2a7c..eee0ac61b 100644 --- a/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java +++ b/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java @@ -63,7 +63,7 @@ public class SlidingLocaleDrawable extends Drawable { mHeight = height; final TextPaint textPaint = new TextPaint(); textPaint.setTextSize(getTextSizeFromTheme(android.R.style.TextAppearance_Medium, 18)); - textPaint.setColor(R.color.latinkeyboard_transparent); + textPaint.setColor(android.R.color.transparent); textPaint.setTextAlign(Align.CENTER); textPaint.setAlpha(LatinKeyboard.OPACITY_FULLY_OPAQUE); textPaint.setAntiAlias(true); diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 35f43124d..6a858fe99 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -30,7 +30,6 @@ import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.LatinKeyboard; import com.android.inputmethod.keyboard.LatinKeyboardView; -import com.android.inputmethod.latin.Utils.RingCharBuffer; import android.app.AlertDialog; import android.content.BroadcastReceiver; @@ -1174,10 +1173,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (primaryCode != Keyboard.CODE_ENTER) { mJustAddedAutoSpace = false; } - RingCharBuffer.getInstance().push((char)primaryCode, x, y); - LatinImeLogger.logOnInputChar(); if (isWordSeparator(primaryCode)) { - handleSeparator(primaryCode); + handleSeparator(primaryCode, x, y); } else { handleCharacter(primaryCode, keyCodes, x, y); } @@ -1357,10 +1354,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } switcher.updateShiftState(); if (LatinIME.PERF_DEBUG) measureCps(); - TextEntryState.typedCharacter((char) code, isWordSeparator(code)); + TextEntryState.typedCharacter((char) code, isWordSeparator(code), x, y); } - private void handleSeparator(int primaryCode) { + private void handleSeparator(int primaryCode, int x, int y) { mVoiceProxy.handleSeparator(); // Should dismiss the "Touch again to save" message when handling separator @@ -1381,7 +1378,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // in Italian dov' should not be expanded to dove' because the elision // requires the last vowel to be removed. if (mAutoCorrectOn && primaryCode != '\'') { - pickedDefault = pickDefaultSuggestion(); + pickedDefault = pickDefaultSuggestion(primaryCode); // Picked the suggestion by the space key. We consider this // as "added an auto space". if (primaryCode == Keyboard.CODE_SPACE) { @@ -1403,7 +1400,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar reswapPeriodAndSpace(); } - TextEntryState.typedCharacter((char) primaryCode, true); + TextEntryState.typedCharacter((char) primaryCode, true, x, y); if (TextEntryState.isPunctuationAfterAccepted() && primaryCode != Keyboard.CODE_ENTER) { swapPunctuationAndSpace(); } else if (isSuggestionsRequested() && primaryCode == Keyboard.CODE_SPACE) { @@ -1592,14 +1589,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar setCandidatesViewShown(isCandidateStripVisible()); } - private boolean pickDefaultSuggestion() { + private boolean pickDefaultSuggestion(int separatorCode) { // Complete any pending candidate query first if (mHandler.hasPendingUpdateSuggestions()) { mHandler.cancelUpdateSuggestions(); updateSuggestions(); } if (mBestWord != null && mBestWord.length() > 0) { - TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord); + TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord, separatorCode); mJustAccepted = true; pickSuggestion(mBestWord); // Add the word to the auto dictionary if it's not a known word @@ -1688,7 +1685,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Fool the state watcher so that a subsequent backspace will not do a revert, unless // we just did a correction, in which case we need to stay in // TextEntryState.State.PICKED_SUGGESTION state. - TextEntryState.typedCharacter((char) Keyboard.CODE_SPACE, true); + TextEntryState.typedCharacter((char) Keyboard.CODE_SPACE, true, + WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE); setPunctuationSuggestions(); } else if (!showingAddToDictionaryHint) { // If we're not showing the "Touch again to save", then show corrections again. @@ -1895,7 +1893,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar ic.commitText(mComposing, 1); TextEntryState.acceptedTyped(mComposing); ic.commitText(punctuation, 1); - TextEntryState.typedCharacter(punctuation.charAt(0), true); + TextEntryState.typedCharacter(punctuation.charAt(0), true, + WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE); // Clear composing text mComposing.setLength(0); } else { diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java index aaecfffdd..e460471a5 100644 --- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java +++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java @@ -45,10 +45,10 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang String before, String after, int position, List<CharSequence> suggestions) { } - public static void logOnAutoSuggestion(String before, String after) { + public static void logOnAutoCorrection(String before, String after, int separatorCode) { } - public static void logOnAutoSuggestionCanceled() { + public static void logOnAutoCorrectionCancelled() { } public static void logOnDelete() { @@ -57,6 +57,9 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang public static void logOnInputChar() { } + public static void logOnInputSeparator() { + } + public static void logOnException(String metaData, Throwable e) { } diff --git a/java/src/com/android/inputmethod/latin/TextEntryState.java b/java/src/com/android/inputmethod/latin/TextEntryState.java index 63196430b..de13f3ae4 100644 --- a/java/src/com/android/inputmethod/latin/TextEntryState.java +++ b/java/src/com/android/inputmethod/latin/TextEntryState.java @@ -16,6 +16,8 @@ package com.android.inputmethod.latin; +import com.android.inputmethod.latin.Utils.RingCharBuffer; + import android.util.Log; public class TextEntryState { @@ -43,10 +45,12 @@ public class TextEntryState { sState = newState; } - public static void acceptedDefault(CharSequence typedWord, CharSequence actualWord) { + public static void acceptedDefault(CharSequence typedWord, CharSequence actualWord, + int separatorCode) { if (typedWord == null) return; setState(ACCEPTED_DEFAULT); - LatinImeLogger.logOnAutoSuggestion(typedWord.toString(), actualWord.toString()); + LatinImeLogger.logOnAutoCorrection( + typedWord.toString(), actualWord.toString(), separatorCode); if (DEBUG) displayState("acceptedDefault", "typedWord", typedWord, "actualWord", actualWord); } @@ -95,7 +99,7 @@ public class TextEntryState { if (DEBUG) displayState("onAbortRecorrection"); } - public static void typedCharacter(char c, boolean isSeparator) { + public static void typedCharacter(char c, boolean isSeparator, int x, int y) { final boolean isSpace = (c == ' '); switch (sState) { case IN_WORD: @@ -149,13 +153,19 @@ public class TextEntryState { setState(START); break; } + RingCharBuffer.getInstance().push(c, x, y); + if (isSeparator) { + LatinImeLogger.logOnInputSeparator(); + } else { + LatinImeLogger.logOnInputChar(); + } if (DEBUG) displayState("typedCharacter", "char", c, "isSeparator", isSeparator); } public static void backspace() { if (sState == ACCEPTED_DEFAULT) { setState(UNDO_COMMIT); - LatinImeLogger.logOnAutoSuggestionCanceled(); + LatinImeLogger.logOnAutoCorrectionCancelled(); } else if (sState == UNDO_COMMIT) { setState(IN_WORD); } diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 3e092d938..7b334ac0a 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -209,11 +209,11 @@ public class Utils { return mCharBuf[mEnd]; } } - public char getLastChar() { - if (mLength < 1) { + public char getBackwardNthChar(int n) { + if (mLength <= n || n < 0) { return PLACEHOLDER_DELIMITER_CHAR; } else { - return mCharBuf[normalize(mEnd - 1)]; + return mCharBuf[normalize(mEnd - n - 1)]; } } public int getPreviousX(char c, int back) { @@ -234,9 +234,16 @@ public class Utils { return mYBuf[index]; } } - public String getLastString() { + public String getLastWord(int ignoreCharCount) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < mLength; ++i) { + int i = ignoreCharCount; + for (; i < mLength; ++i) { + char c = mCharBuf[normalize(mEnd - 1 - i)]; + if (!((LatinIME)mContext).isWordSeparator(c)) { + break; + } + } + for (; i < mLength; ++i) { char c = mCharBuf[normalize(mEnd - 1 - i)]; if (!((LatinIME)mContext).isWordSeparator(c)) { sb.append(c); |