diff options
author | 2014-03-13 17:37:16 +0900 | |
---|---|---|
committer | 2014-03-14 12:44:49 +0900 | |
commit | f8accd8839d291f10b218e64aa6b8eb154c92c4c (patch) | |
tree | fb28ac4319eb6cc49791bb50cb9aedc9f6b32a69 /java/src/com/android/inputmethod | |
parent | 309773c322adb383a05cf673fd8d8a8339dcb076 (diff) | |
download | latinime-f8accd8839d291f10b218e64aa6b8eb154c92c4c.tar.gz latinime-f8accd8839d291f10b218e64aa6b8eb154c92c4c.tar.xz latinime-f8accd8839d291f10b218e64aa6b8eb154c92c4c.zip |
[CB04] Add an event array to WordComposer.
Bug: 13406701
Change-Id: I9ecd2709c8f1c678a85b0cfaf7c5ed4f78459821
Diffstat (limited to 'java/src/com/android/inputmethod')
4 files changed, 67 insertions, 12 deletions
diff --git a/java/src/com/android/inputmethod/event/Event.java b/java/src/com/android/inputmethod/event/Event.java index a4a17e12d..ed487e13f 100644 --- a/java/src/com/android/inputmethod/event/Event.java +++ b/java/src/com/android/inputmethod/event/Event.java @@ -120,6 +120,34 @@ public class Event { FLAG_DEAD, next); } + /** + * Create an input event with nothing but a code point. This is the most basic possible input + * event; it contains no information on many things the IME requires to function correctly, + * so avoid using it unless really nothing is known about this input. + * @param codePoint the code point. + * @return an event for this code point. + */ + public static Event createEventForCodePointFromUnknownSource(final int codePoint) { + // TODO: should we have a different type of event for this? After all, it's not a key press. + return new Event(EVENT_INPUT_KEYPRESS, codePoint, NOT_A_KEY_CODE, + Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, FLAG_NONE, null /* next */); + } + + /** + * Creates an input event with a code point and x, y coordinates. This is typically used when + * resuming a previously-typed word, when the coordinates are still known. + * @param codePoint the code point to input. + * @param x the X coordinate. + * @param y the Y coordinate. + * @return an event for this code point and coordinates. + */ + public static Event createEventForCodePointFromAlreadyTypedText(final int codePoint, + final int x, final int y) { + // TODO: should we have a different type of event for this? After all, it's not a key press. + return new Event(EVENT_INPUT_KEYPRESS, codePoint, NOT_A_KEY_CODE, x, y, FLAG_NONE, + null /* next */); + } + public static Event createNotHandledEvent() { return new Event(EVENT_NOT_HANDLED, NOT_A_CODE_POINT, NOT_A_KEY_CODE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, FLAG_NONE, null); diff --git a/java/src/com/android/inputmethod/latin/LastComposedWord.java b/java/src/com/android/inputmethod/latin/LastComposedWord.java index 8546cebd5..2a16ab5ab 100644 --- a/java/src/com/android/inputmethod/latin/LastComposedWord.java +++ b/java/src/com/android/inputmethod/latin/LastComposedWord.java @@ -18,6 +18,10 @@ package com.android.inputmethod.latin; import android.text.TextUtils; +import com.android.inputmethod.event.Event; + +import java.util.ArrayList; + /** * This class encapsulates data about a word previously composed, but that has been * committed already. This is used for resuming suggestion, and cancel auto-correction. @@ -41,6 +45,7 @@ public final class LastComposedWord { public static final String NOT_A_SEPARATOR = ""; public final int[] mPrimaryKeyCodes; + public final ArrayList<Event> mEvents; public final String mTypedWord; public final CharSequence mCommittedWord; public final String mSeparatorString; @@ -52,19 +57,21 @@ public final class LastComposedWord { private boolean mActive; public static final LastComposedWord NOT_A_COMPOSED_WORD = - new LastComposedWord(null, null, "", "", NOT_A_SEPARATOR, null, - WordComposer.CAPS_MODE_OFF); + new LastComposedWord(null, new ArrayList<Event>(), null, "", "", + NOT_A_SEPARATOR, null, WordComposer.CAPS_MODE_OFF); // Warning: this is using the passed objects as is and fully expects them to be // immutable. Do not fiddle with their contents after you passed them to this constructor. - public LastComposedWord(final int[] primaryKeyCodes, final InputPointers inputPointers, - final String typedWord, final CharSequence committedWord, final String separatorString, + public LastComposedWord(final int[] primaryKeyCodes, final ArrayList<Event> events, + final InputPointers inputPointers, final String typedWord, + final CharSequence committedWord, final String separatorString, final String prevWord, final int capitalizedMode) { mPrimaryKeyCodes = primaryKeyCodes; if (inputPointers != null) { mInputPointers.copy(inputPointers); } mTypedWord = typedWord; + mEvents = new ArrayList<Event>(events); mCommittedWord = committedWord; mSeparatorString = separatorString; mActive = true; diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 125976932..2ac11aa29 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -16,10 +16,14 @@ package com.android.inputmethod.latin; +import com.android.inputmethod.event.Event; +import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CoordinateUtils; import com.android.inputmethod.latin.utils.StringUtils; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; /** * A place to store the currently composing word with information such as adjacent key codes as well @@ -41,6 +45,8 @@ public final class WordComposer { // and mCodePointSize can go past that. If mCodePointSize is greater than MAX_WORD_LENGTH, // this just does not contain the associated code points past MAX_WORD_LENGTH. private int[] mPrimaryKeyCodes; + // The list of events that served to compose this string. + private final ArrayList<Event> mEvents; private final InputPointers mInputPointers = new InputPointers(MAX_WORD_LENGTH); // This is the typed word, as a StringBuilder. This has the same contents as mPrimaryKeyCodes // but under a StringBuilder representation for ease of use, depending on what is more useful @@ -82,6 +88,7 @@ public final class WordComposer { public WordComposer() { mPrimaryKeyCodes = new int[MAX_WORD_LENGTH]; + mEvents = CollectionUtils.newArrayList(); mTypedWord = new StringBuilder(MAX_WORD_LENGTH); mAutoCorrection = null; mTrailingSingleQuotesCount = 0; @@ -95,6 +102,7 @@ public final class WordComposer { public WordComposer(final WordComposer source) { mPrimaryKeyCodes = Arrays.copyOf(source.mPrimaryKeyCodes, source.mPrimaryKeyCodes.length); + mEvents = new ArrayList<Event>(source.mEvents); mTypedWord = new StringBuilder(source.mTypedWord); mInputPointers.copy(source.mInputPointers); mCapsCount = source.mCapsCount; @@ -115,6 +123,7 @@ public final class WordComposer { */ public void reset() { mTypedWord.setLength(0); + mEvents.clear(); mAutoCorrection = null; mCapsCount = 0; mDigitsCount = 0; @@ -170,11 +179,16 @@ public final class WordComposer { } /** - * Add a new keystroke, with the pressed key's code point with the touch point coordinates. + * Add a new event for a key stroke, with the pressed key's code point with the touch point + * coordinates. */ - public void add(final int primaryCode, final int keyX, final int keyY) { + public void add(final Event event) { + final int primaryCode = event.mCodePoint; + final int keyX = event.mX; + final int keyY = event.mY; final int newIndex = size(); mTypedWord.appendCodePoint(primaryCode); + mEvents.add(event); refreshSize(); mCursorPositionWithinWord = mCodePointSize; if (newIndex < MAX_WORD_LENGTH) { @@ -202,6 +216,7 @@ public final class WordComposer { public void setCursorPositionWithinWord(final int posWithinWord) { mCursorPositionWithinWord = posWithinWord; + // TODO: compute where that puts us inside the events } public boolean isCursorFrontOrMiddleOfComposingWord() { @@ -268,7 +283,7 @@ public final class WordComposer { final int codePoint = Character.codePointAt(word, i); // We don't want to override the batch input points that are held in mInputPointers // (See {@link #add(int,int,int)}). - add(codePoint, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); + add(Event.createEventForCodePointFromUnknownSource(codePoint)); } } @@ -285,8 +300,9 @@ public final class WordComposer { reset(); final int length = codePoints.length; for (int i = 0; i < length; ++i) { - add(codePoints[i], CoordinateUtils.xFromArray(coordinates, i), - CoordinateUtils.yFromArray(coordinates, i)); + add(Event.createEventForCodePointFromAlreadyTypedText(codePoints[i], + CoordinateUtils.xFromArray(coordinates, i), + CoordinateUtils.yFromArray(coordinates, i))); } mIsResumed = true; mPreviousWordForSuggestion = null == previousWord ? null : previousWord.toString(); @@ -305,6 +321,8 @@ public final class WordComposer { "In WordComposer: mCodes and mTypedWords have non-matching lengths"); } final int lastChar = mTypedWord.codePointBefore(stringBuilderLength); + // TODO: with events and composition, this is absolutely not necessarily true. + mEvents.remove(mEvents.size() - 1); if (Character.isSupplementaryCodePoint(lastChar)) { mTypedWord.delete(stringBuilderLength - 2, stringBuilderLength); } else { @@ -445,7 +463,7 @@ public final class WordComposer { // the last composed word to ensure this does not happen. final int[] primaryKeyCodes = mPrimaryKeyCodes; mPrimaryKeyCodes = new int[MAX_WORD_LENGTH]; - final LastComposedWord lastComposedWord = new LastComposedWord(primaryKeyCodes, + final LastComposedWord lastComposedWord = new LastComposedWord(primaryKeyCodes, mEvents, mInputPointers, mTypedWord.toString(), committedWord, separatorString, prevWord, mCapitalizedMode); mInputPointers.reset(); @@ -458,6 +476,7 @@ public final class WordComposer { mIsBatchMode = false; mPreviousWordForSuggestion = committedWord.toString(); mTypedWord.setLength(0); + mEvents.clear(); mCodePointSize = 0; mTrailingSingleQuotesCount = 0; mIsFirstCharCapitalized = false; @@ -480,6 +499,8 @@ public final class WordComposer { public void resumeSuggestionOnLastComposedWord(final LastComposedWord lastComposedWord, final String previousWord) { mPrimaryKeyCodes = lastComposedWord.mPrimaryKeyCodes; + mEvents.clear(); + Collections.copy(mEvents, lastComposedWord.mEvents); mInputPointers.set(lastComposedWord.mInputPointers); mTypedWord.setLength(0); mTypedWord.append(lastComposedWord.mTypedWord); diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index cc5611b0c..cb55aa06c 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -730,8 +730,7 @@ public final class InputLogic { resetComposingState(false /* alsoResetLastComposedWord */); } if (isComposingWord) { - // TODO: pass the entire event to the word composer. - mWordComposer.add(codePoint, inputTransaction.mEvent.mX, inputTransaction.mEvent.mY); + mWordComposer.add(inputTransaction.mEvent); // If it's the first letter, make note of auto-caps state if (mWordComposer.size() == 1) { // We pass 1 to getPreviousWordForSuggestion because we were not composing a word |