[CB04] Add an event array to WordComposer.
Bug: 13406701 Change-Id: I9ecd2709c8f1c678a85b0cfaf7c5ed4f78459821main
parent
309773c322
commit
f8accd8839
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -29,32 +29,34 @@ include $(CLEAR_VARS)
|
|||
LATINIME_LOCAL_DIR := ../..
|
||||
LATINIME_BASE_SOURCE_DIRECTORY := $(LATINIME_LOCAL_DIR)/java/src/com/android/inputmethod
|
||||
LATINIME_ANNOTATIONS_SOURCE_DIRECTORY := $(LATINIME_BASE_SOURCE_DIRECTORY)/annotations
|
||||
LATINIME_CORE_SOURCE_DIRECTORY := $(LATINIME_BASE_SOURCE_DIRECTORY)/latin
|
||||
MAKEDICT_CORE_SOURCE_DIRECTORY := $(LATINIME_CORE_SOURCE_DIRECTORY)/makedict
|
||||
MAKEDICT_CORE_SOURCE_DIRECTORY := $(LATINIME_BASE_SOURCE_DIRECTORY)/latin/makedict
|
||||
|
||||
# Dependencies for Dicttool. Most of these files are needed by BinaryDictionary.java. Note that
|
||||
# a significant part of the dependencies are mocked in the compat/ directory, with empty or
|
||||
# nearly-empty implementations, for parts that we don't use in Dicttool.
|
||||
USED_TARGETTED_UTILS := \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/BinaryDictionary.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/DicTraverseSession.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/Dictionary.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/InputPointers.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/LastComposedWord.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/LatinImeLogger.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/SuggestedWords.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/WordComposer.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/settings/NativeSuggestOptions.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/BinaryDictionaryUtils.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/ByteArrayDictBuffer.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/CollectionUtils.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/CombinedFormatUtils.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/CoordinateUtils.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/FileUtils.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/JniUtils.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/LocaleUtils.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/ResizableIntArray.java \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/utils/StringUtils.java
|
||||
LATINIME_SRCS_FOR_DICTTOOL := \
|
||||
event/Event.java \
|
||||
latin/BinaryDictionary.java \
|
||||
latin/DicTraverseSession.java \
|
||||
latin/Dictionary.java \
|
||||
latin/InputPointers.java \
|
||||
latin/LastComposedWord.java \
|
||||
latin/LatinImeLogger.java \
|
||||
latin/SuggestedWords.java \
|
||||
latin/WordComposer.java \
|
||||
latin/settings/NativeSuggestOptions.java \
|
||||
latin/utils/BinaryDictionaryUtils.java \
|
||||
latin/utils/ByteArrayDictBuffer.java \
|
||||
latin/utils/CollectionUtils.java \
|
||||
latin/utils/CombinedFormatUtils.java \
|
||||
latin/utils/CoordinateUtils.java \
|
||||
latin/utils/FileUtils.java \
|
||||
latin/utils/JniUtils.java \
|
||||
latin/utils/LocaleUtils.java \
|
||||
latin/utils/ResizableIntArray.java \
|
||||
latin/utils/StringUtils.java
|
||||
USED_TARGETED_SRCS := $(addprefix $(LATINIME_BASE_SOURCE_DIRECTORY)/, \
|
||||
$(LATINIME_SRCS_FOR_DICTTOOL))
|
||||
|
||||
DICTTOOL_ONDEVICE_TESTS_DIRECTORY := \
|
||||
$(LATINIME_LOCAL_DIR)/tests/src/com/android/inputmethod/latin/makedict/
|
||||
|
@ -68,11 +70,11 @@ LOCAL_ANNOTATIONS_SRC_FILES := \
|
|||
LOCAL_SRC_FILES := $(LOCAL_TOOL_SRC_FILES) \
|
||||
$(filter-out $(addprefix %/, $(notdir $(LOCAL_TOOL_SRC_FILES))), $(LOCAL_MAIN_SRC_FILES)) \
|
||||
$(LOCAL_ANNOTATIONS_SRC_FILES) \
|
||||
$(LATINIME_CORE_SOURCE_DIRECTORY)/Constants.java \
|
||||
$(LATINIME_BASE_SOURCE_DIRECTORY)/latin/Constants.java \
|
||||
$(call all-java-files-under, tests) \
|
||||
$(call all-java-files-under, $(DICTTOOL_ONDEVICE_TESTS_DIRECTORY)) \
|
||||
$(call all-java-files-under, $(DICTTOOL_COMPAT_TESTS_DIRECTORY)) \
|
||||
$(USED_TARGETTED_UTILS)
|
||||
$(USED_TARGETED_SRCS)
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := junit
|
||||
LOCAL_ADDITIONAL_DEPENDENCIES := $(LATINIME_HOST_NATIVE_LIBNAME)
|
||||
|
|
Loading…
Reference in New Issue