2009-03-13 22:11:42 +00:00
|
|
|
/*
|
2010-03-26 22:07:10 +00:00
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
2011-12-20 08:52:29 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-12-20 08:52:29 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-12-20 08:52:29 +00:00
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-01-21 12:52:57 +00:00
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2009-03-13 22:11:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
2014-03-14 13:50:20 +00:00
|
|
|
import com.android.inputmethod.event.CombinerChain;
|
2014-03-13 08:37:16 +00:00
|
|
|
import com.android.inputmethod.event.Event;
|
2013-12-27 11:58:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.CoordinateUtils;
|
2013-07-17 09:20:03 +00:00
|
|
|
import com.android.inputmethod.latin.utils.StringUtils;
|
2011-02-10 11:53:58 +00:00
|
|
|
|
2014-03-13 08:37:16 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
2009-03-13 22:11:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A place to store the currently composing word with information such as adjacent key codes as well
|
|
|
|
*/
|
2012-09-27 09:16:16 +00:00
|
|
|
public final class WordComposer {
|
2013-07-26 03:35:11 +00:00
|
|
|
private static final int MAX_WORD_LENGTH = Constants.DICTIONARY_MAX_WORD_LENGTH;
|
2013-04-10 09:30:11 +00:00
|
|
|
private static final boolean DBG = LatinImeLogger.sDBG;
|
2011-02-22 08:28:55 +00:00
|
|
|
|
2012-08-21 10:49:25 +00:00
|
|
|
public static final int CAPS_MODE_OFF = 0;
|
|
|
|
// 1 is shift bit, 2 is caps bit, 4 is auto bit but this is just a convention as these bits
|
|
|
|
// aren't used anywhere in the code
|
|
|
|
public static final int CAPS_MODE_MANUAL_SHIFTED = 0x1;
|
|
|
|
public static final int CAPS_MODE_MANUAL_SHIFT_LOCKED = 0x3;
|
|
|
|
public static final int CAPS_MODE_AUTO_SHIFTED = 0x5;
|
|
|
|
public static final int CAPS_MODE_AUTO_SHIFT_LOCKED = 0x7;
|
|
|
|
|
2014-03-14 13:50:20 +00:00
|
|
|
private CombinerChain mCombinerChain;
|
2014-05-08 05:53:56 +00:00
|
|
|
private String mCombiningSpec; // Memory so that we don't uselessly recreate the combiner chain
|
2014-03-14 13:50:20 +00:00
|
|
|
|
2014-03-13 08:37:16 +00:00
|
|
|
// The list of events that served to compose this string.
|
|
|
|
private final ArrayList<Event> mEvents;
|
2012-12-17 08:43:09 +00:00
|
|
|
private final InputPointers mInputPointers = new InputPointers(MAX_WORD_LENGTH);
|
2014-05-19 04:55:40 +00:00
|
|
|
// The information of previous words (before the composing word). Must not be null. Used as
|
|
|
|
// context for suggestions.
|
|
|
|
private PrevWordsInfo mPrevWordsInfo;
|
2012-10-03 06:19:43 +00:00
|
|
|
private String mAutoCorrection;
|
2012-04-26 09:01:13 +00:00
|
|
|
private boolean mIsResumed;
|
2012-07-10 01:46:13 +00:00
|
|
|
private boolean mIsBatchMode;
|
2013-04-12 11:45:18 +00:00
|
|
|
// A memory of the last rejected batch mode suggestion, if any. This goes like this: the user
|
|
|
|
// gestures a word, is displeased with the results and hits backspace, then gestures again.
|
|
|
|
// At the very least we should avoid re-suggesting the same thing, and to do that we memorize
|
|
|
|
// the rejected suggestion in this variable.
|
|
|
|
// TODO: this should be done in a comprehensive way by the User History feature instead of
|
|
|
|
// as an ad-hockery here.
|
|
|
|
private String mRejectedBatchModeSuggestion;
|
2009-07-23 19:17:48 +00:00
|
|
|
|
2012-01-26 08:29:57 +00:00
|
|
|
// Cache these values for performance
|
2014-03-25 12:59:53 +00:00
|
|
|
private CharSequence mTypedWordCache;
|
2009-07-23 19:17:48 +00:00
|
|
|
private int mCapsCount;
|
2012-07-27 14:13:28 +00:00
|
|
|
private int mDigitsCount;
|
2012-08-21 10:49:25 +00:00
|
|
|
private int mCapitalizedMode;
|
2013-07-17 09:20:03 +00:00
|
|
|
// This is the number of code points entered so far. This is not limited to MAX_WORD_LENGTH.
|
|
|
|
// In general, this contains the size of mPrimaryKeyCodes, except when this is greater than
|
|
|
|
// MAX_WORD_LENGTH in which case mPrimaryKeyCodes only contain the first MAX_WORD_LENGTH
|
|
|
|
// code points.
|
2012-03-27 06:21:54 +00:00
|
|
|
private int mCodePointSize;
|
2013-04-10 07:38:37 +00:00
|
|
|
private int mCursorPositionWithinWord;
|
2011-11-18 11:03:38 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
/**
|
2010-09-27 15:32:35 +00:00
|
|
|
* Whether the user chose to capitalize the first char of the word.
|
2009-03-13 22:11:42 +00:00
|
|
|
*/
|
2010-09-27 15:32:35 +00:00
|
|
|
private boolean mIsFirstCharCapitalized;
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
public WordComposer() {
|
2014-05-14 11:19:16 +00:00
|
|
|
mCombinerChain = new CombinerChain("");
|
2014-05-23 11:18:17 +00:00
|
|
|
mEvents = new ArrayList<>();
|
2012-01-26 08:29:57 +00:00
|
|
|
mAutoCorrection = null;
|
2012-04-26 09:01:13 +00:00
|
|
|
mIsResumed = false;
|
2012-07-10 01:46:13 +00:00
|
|
|
mIsBatchMode = false;
|
2013-04-10 07:38:37 +00:00
|
|
|
mCursorPositionWithinWord = 0;
|
2013-04-12 11:45:18 +00:00
|
|
|
mRejectedBatchModeSuggestion = null;
|
2014-05-23 14:19:33 +00:00
|
|
|
mPrevWordsInfo = PrevWordsInfo.EMPTY_PREV_WORDS_INFO;
|
2014-03-25 12:59:53 +00:00
|
|
|
refreshTypedWordCache();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2014-05-08 05:53:56 +00:00
|
|
|
/**
|
2014-05-14 11:19:16 +00:00
|
|
|
* Restart the combiners, possibly with a new spec.
|
2014-05-08 05:53:56 +00:00
|
|
|
* @param combiningSpec The spec string for combining. This is found in the extra value.
|
|
|
|
*/
|
2014-05-14 11:19:16 +00:00
|
|
|
public void restartCombining(final String combiningSpec) {
|
2014-05-08 05:53:56 +00:00
|
|
|
final String nonNullCombiningSpec = null == combiningSpec ? "" : combiningSpec;
|
2014-05-14 11:19:16 +00:00
|
|
|
if (!nonNullCombiningSpec.equals(mCombiningSpec)) {
|
|
|
|
mCombinerChain = new CombinerChain(
|
|
|
|
mCombinerChain.getComposingWordWithCombiningFeedback().toString(),
|
|
|
|
CombinerChain.createCombiners(nonNullCombiningSpec));
|
2014-05-08 05:53:56 +00:00
|
|
|
mCombiningSpec = nonNullCombiningSpec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
/**
|
|
|
|
* Clear out the keys registered so far.
|
|
|
|
*/
|
|
|
|
public void reset() {
|
2014-03-20 08:55:30 +00:00
|
|
|
mCombinerChain.reset();
|
2014-03-13 08:37:16 +00:00
|
|
|
mEvents.clear();
|
2012-01-26 08:29:57 +00:00
|
|
|
mAutoCorrection = null;
|
2009-07-23 19:17:48 +00:00
|
|
|
mCapsCount = 0;
|
2012-07-27 14:13:28 +00:00
|
|
|
mDigitsCount = 0;
|
2011-09-13 08:46:23 +00:00
|
|
|
mIsFirstCharCapitalized = false;
|
2012-04-26 09:01:13 +00:00
|
|
|
mIsResumed = false;
|
2012-07-10 01:46:13 +00:00
|
|
|
mIsBatchMode = false;
|
2013-04-10 07:38:37 +00:00
|
|
|
mCursorPositionWithinWord = 0;
|
2013-04-12 11:45:18 +00:00
|
|
|
mRejectedBatchModeSuggestion = null;
|
2014-05-23 14:19:33 +00:00
|
|
|
mPrevWordsInfo = PrevWordsInfo.EMPTY_PREV_WORDS_INFO;
|
2014-03-25 12:59:53 +00:00
|
|
|
refreshTypedWordCache();
|
2012-03-27 06:21:54 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 12:59:53 +00:00
|
|
|
private final void refreshTypedWordCache() {
|
|
|
|
mTypedWordCache = mCombinerChain.getComposingWordWithCombiningFeedback();
|
|
|
|
mCodePointSize = Character.codePointCount(mTypedWordCache, 0, mTypedWordCache.length());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of keystrokes in the composing word.
|
|
|
|
* @return the number of keystrokes
|
|
|
|
*/
|
2014-03-28 05:35:38 +00:00
|
|
|
// This may be made public if need be, but right now it's not used anywhere
|
|
|
|
/* package for tests */ int size() {
|
2012-03-27 06:21:54 +00:00
|
|
|
return mCodePointSize;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 14:41:29 +00:00
|
|
|
/**
|
|
|
|
* Copy the code points in the typed word to a destination array of ints.
|
|
|
|
*
|
|
|
|
* If the array is too small to hold the code points in the typed word, nothing is copied and
|
|
|
|
* -1 is returned.
|
|
|
|
*
|
|
|
|
* @param destination the array of ints.
|
|
|
|
* @return the number of copied code points.
|
|
|
|
*/
|
|
|
|
public int copyCodePointsExceptTrailingSingleQuotesAndReturnCodePointCount(
|
2014-04-18 17:52:15 +00:00
|
|
|
final int[] destination) {
|
|
|
|
// lastIndex is exclusive
|
2014-05-16 06:32:12 +00:00
|
|
|
final int lastIndex = mTypedWordCache.length()
|
|
|
|
- StringUtils.getTrailingSingleQuotesCount(mTypedWordCache);
|
2014-04-18 17:52:15 +00:00
|
|
|
if (lastIndex <= 0) {
|
2014-04-07 14:41:29 +00:00
|
|
|
// The string is empty or contains only single quotes.
|
|
|
|
return 0;
|
|
|
|
}
|
2014-04-18 17:52:15 +00:00
|
|
|
|
|
|
|
// The following function counts the number of code points in the text range which begins
|
|
|
|
// at index 0 and extends to the character at lastIndex.
|
|
|
|
final int codePointSize = Character.codePointCount(mTypedWordCache, 0, lastIndex);
|
|
|
|
if (codePointSize > destination.length) {
|
2014-04-07 14:41:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return StringUtils.copyCodePointsAndReturnCodePointCount(destination, mTypedWordCache, 0,
|
2014-04-18 17:52:15 +00:00
|
|
|
lastIndex, true /* downCase */);
|
2014-03-28 05:35:38 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 14:41:29 +00:00
|
|
|
public boolean isSingleLetter() {
|
|
|
|
return size() == 1;
|
2014-03-28 04:25:04 +00:00
|
|
|
}
|
|
|
|
|
2011-12-13 14:24:37 +00:00
|
|
|
public final boolean isComposingWord() {
|
2012-03-27 06:21:54 +00:00
|
|
|
return size() > 0;
|
2011-12-13 14:24:37 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 09:42:15 +00:00
|
|
|
public InputPointers getInputPointers() {
|
|
|
|
return mInputPointers;
|
2011-02-22 08:28:55 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 06:19:43 +00:00
|
|
|
private static boolean isFirstCharCapitalized(final int index, final int codePoint,
|
|
|
|
final boolean previous) {
|
2011-09-13 08:46:23 +00:00
|
|
|
if (index == 0) return Character.isUpperCase(codePoint);
|
2011-09-16 03:28:13 +00:00
|
|
|
return previous && !Character.isUpperCase(codePoint);
|
2011-09-13 08:46:23 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
/**
|
2014-03-27 07:12:58 +00:00
|
|
|
* Process an input event.
|
|
|
|
*
|
|
|
|
* All input events should be supported, including software/hardware events, characters as well
|
|
|
|
* as deletions, multiple inputs and gestures.
|
|
|
|
*
|
|
|
|
* @param event the event to process.
|
2009-03-13 22:11:42 +00:00
|
|
|
*/
|
2014-03-27 07:12:58 +00:00
|
|
|
public void processEvent(final Event event) {
|
2014-03-25 13:44:59 +00:00
|
|
|
final int primaryCode = event.mCodePoint;
|
|
|
|
final int keyX = event.mX;
|
|
|
|
final int keyY = event.mY;
|
|
|
|
final int newIndex = size();
|
2014-03-25 13:43:13 +00:00
|
|
|
mCombinerChain.processEvent(mEvents, event);
|
|
|
|
mEvents.add(event);
|
|
|
|
refreshTypedWordCache();
|
2014-03-25 13:44:59 +00:00
|
|
|
mCursorPositionWithinWord = mCodePointSize;
|
|
|
|
// We may have deleted the last one.
|
|
|
|
if (0 == mCodePointSize) {
|
|
|
|
mIsFirstCharCapitalized = false;
|
|
|
|
}
|
2014-04-08 07:42:24 +00:00
|
|
|
if (Constants.CODE_DELETE != event.mKeyCode) {
|
2014-03-27 05:34:45 +00:00
|
|
|
if (newIndex < MAX_WORD_LENGTH) {
|
|
|
|
// In the batch input mode, the {@code mInputPointers} holds batch input points and
|
|
|
|
// shouldn't be overridden by the "typed key" coordinates
|
|
|
|
// (See {@link #setBatchInputWord}).
|
|
|
|
if (!mIsBatchMode) {
|
|
|
|
// TODO: Set correct pointer id and time
|
|
|
|
mInputPointers.addPointerAt(newIndex, keyX, keyY, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mIsFirstCharCapitalized = isFirstCharCapitalized(
|
|
|
|
newIndex, primaryCode, mIsFirstCharCapitalized);
|
|
|
|
if (Character.isUpperCase(primaryCode)) mCapsCount++;
|
|
|
|
if (Character.isDigit(primaryCode)) mDigitsCount++;
|
2014-03-25 13:47:05 +00:00
|
|
|
}
|
2014-03-25 13:44:59 +00:00
|
|
|
mAutoCorrection = null;
|
2014-03-25 13:43:13 +00:00
|
|
|
}
|
|
|
|
|
2013-04-10 07:38:37 +00:00
|
|
|
public void setCursorPositionWithinWord(final int posWithinWord) {
|
|
|
|
mCursorPositionWithinWord = posWithinWord;
|
2014-03-13 08:37:16 +00:00
|
|
|
// TODO: compute where that puts us inside the events
|
2013-04-10 07:38:37 +00:00
|
|
|
}
|
|
|
|
|
2013-04-10 09:30:11 +00:00
|
|
|
public boolean isCursorFrontOrMiddleOfComposingWord() {
|
|
|
|
if (DBG && mCursorPositionWithinWord > mCodePointSize) {
|
|
|
|
throw new RuntimeException("Wrong cursor position : " + mCursorPositionWithinWord
|
|
|
|
+ "in a word of size " + mCodePointSize);
|
|
|
|
}
|
|
|
|
return mCursorPositionWithinWord != mCodePointSize;
|
2013-04-10 07:38:37 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 10:26:30 +00:00
|
|
|
/**
|
|
|
|
* When the cursor is moved by the user, we need to update its position.
|
|
|
|
* If it falls inside the currently composing word, we don't reset the composition, and
|
|
|
|
* only update the cursor position.
|
|
|
|
*
|
|
|
|
* @param expectedMoveAmount How many java chars to move the cursor. Negative values move
|
|
|
|
* the cursor backward, positive values move the cursor forward.
|
|
|
|
* @return true if the cursor is still inside the composing word, false otherwise.
|
|
|
|
*/
|
|
|
|
public boolean moveCursorByAndReturnIfInsideComposingWord(final int expectedMoveAmount) {
|
2014-03-20 08:55:30 +00:00
|
|
|
// TODO: should uncommit the composing feedback
|
|
|
|
mCombinerChain.reset();
|
2013-06-25 10:26:30 +00:00
|
|
|
int actualMoveAmountWithinWord = 0;
|
|
|
|
int cursorPos = mCursorPositionWithinWord;
|
2014-04-08 07:42:24 +00:00
|
|
|
// TODO: Don't make that copy. We can do this directly from mTypedWordCache.
|
|
|
|
final int[] codePoints = StringUtils.toCodePointArray(mTypedWordCache);
|
2013-06-25 10:26:30 +00:00
|
|
|
if (expectedMoveAmount >= 0) {
|
|
|
|
// Moving the cursor forward for the expected amount or until the end of the word has
|
|
|
|
// been reached, whichever comes first.
|
|
|
|
while (actualMoveAmountWithinWord < expectedMoveAmount && cursorPos < mCodePointSize) {
|
2013-07-17 09:20:03 +00:00
|
|
|
actualMoveAmountWithinWord += Character.charCount(codePoints[cursorPos]);
|
2013-06-25 10:26:30 +00:00
|
|
|
++cursorPos;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Moving the cursor backward for the expected amount or until the start of the word
|
|
|
|
// has been reached, whichever comes first.
|
|
|
|
while (actualMoveAmountWithinWord > expectedMoveAmount && cursorPos > 0) {
|
|
|
|
--cursorPos;
|
2013-07-17 09:20:03 +00:00
|
|
|
actualMoveAmountWithinWord -= Character.charCount(codePoints[cursorPos]);
|
2013-06-25 10:26:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// If the actual and expected amounts differ, we crossed the start or the end of the word
|
|
|
|
// so the result would not be inside the composing word.
|
|
|
|
if (actualMoveAmountWithinWord != expectedMoveAmount) return false;
|
|
|
|
mCursorPositionWithinWord = cursorPos;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-03 06:19:43 +00:00
|
|
|
public void setBatchInputPointers(final InputPointers batchPointers) {
|
2012-06-12 10:40:37 +00:00
|
|
|
mInputPointers.set(batchPointers);
|
2012-07-10 01:46:13 +00:00
|
|
|
mIsBatchMode = true;
|
|
|
|
}
|
|
|
|
|
2012-10-03 06:19:43 +00:00
|
|
|
public void setBatchInputWord(final String word) {
|
2012-06-12 10:40:37 +00:00
|
|
|
reset();
|
|
|
|
mIsBatchMode = true;
|
|
|
|
final int length = word.length();
|
|
|
|
for (int i = 0; i < length; i = Character.offsetByCodePoints(word, i, 1)) {
|
|
|
|
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)}).
|
2014-03-27 07:12:58 +00:00
|
|
|
processEvent(Event.createEventForCodePointFromUnknownSource(codePoint));
|
2012-06-12 10:40:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-22 02:35:40 +00:00
|
|
|
/**
|
|
|
|
* Set the currently composing word to the one passed as an argument.
|
|
|
|
* This will register NOT_A_COORDINATE for X and Ys, and use the passed keyboard for proximity.
|
2013-12-27 11:58:32 +00:00
|
|
|
* @param codePoints the code points to set as the composing word.
|
|
|
|
* @param coordinates the x, y coordinates of the key in the CoordinateUtils format
|
2014-05-21 02:15:38 +00:00
|
|
|
* @param prevWordsInfo the information of previous words, to use as context for suggestions
|
2011-11-22 02:35:40 +00:00
|
|
|
*/
|
2013-12-27 11:58:32 +00:00
|
|
|
public void setComposingWord(final int[] codePoints, final int[] coordinates,
|
2014-05-21 02:15:38 +00:00
|
|
|
final PrevWordsInfo prevWordsInfo) {
|
2011-11-22 02:35:40 +00:00
|
|
|
reset();
|
2013-12-27 11:58:32 +00:00
|
|
|
final int length = codePoints.length;
|
|
|
|
for (int i = 0; i < length; ++i) {
|
2014-03-27 07:12:58 +00:00
|
|
|
processEvent(Event.createEventForCodePointFromAlreadyTypedText(codePoints[i],
|
2014-03-13 08:37:16 +00:00
|
|
|
CoordinateUtils.xFromArray(coordinates, i),
|
|
|
|
CoordinateUtils.yFromArray(coordinates, i)));
|
2011-11-22 02:35:40 +00:00
|
|
|
}
|
2012-04-26 09:01:13 +00:00
|
|
|
mIsResumed = true;
|
2014-05-21 02:15:38 +00:00
|
|
|
mPrevWordsInfo = prevWordsInfo;
|
2011-11-22 02:35:40 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
/**
|
|
|
|
* Returns the word as it was typed, without any correction applied.
|
2011-12-13 10:38:36 +00:00
|
|
|
* @return the word that was typed so far. Never returns null.
|
2009-03-13 22:11:42 +00:00
|
|
|
*/
|
2011-09-15 06:42:21 +00:00
|
|
|
public String getTypedWord() {
|
2014-03-25 12:59:53 +00:00
|
|
|
return mTypedWordCache.toString();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 04:55:40 +00:00
|
|
|
public PrevWordsInfo getPrevWordsInfoForSuggestion() {
|
|
|
|
return mPrevWordsInfo;
|
2013-12-13 08:09:16 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the user typed a capital letter as the first letter in the word
|
|
|
|
* @return capitalization preference
|
|
|
|
*/
|
2010-09-27 15:32:35 +00:00
|
|
|
public boolean isFirstCharCapitalized() {
|
|
|
|
return mIsFirstCharCapitalized;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-09-27 15:32:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not all of the user typed chars are upper case
|
|
|
|
* @return true if all user typed chars are upper case, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean isAllUpperCase() {
|
2012-09-19 03:52:06 +00:00
|
|
|
if (size() <= 1) {
|
|
|
|
return mCapitalizedMode == CAPS_MODE_AUTO_SHIFT_LOCKED
|
|
|
|
|| mCapitalizedMode == CAPS_MODE_MANUAL_SHIFT_LOCKED;
|
|
|
|
} else {
|
|
|
|
return mCapsCount == size();
|
|
|
|
}
|
2012-08-21 10:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean wasShiftedNoLock() {
|
|
|
|
return mCapitalizedMode == CAPS_MODE_AUTO_SHIFTED
|
|
|
|
|| mCapitalizedMode == CAPS_MODE_MANUAL_SHIFTED;
|
2010-09-27 15:32:35 +00:00
|
|
|
}
|
|
|
|
|
2009-07-23 19:17:48 +00:00
|
|
|
/**
|
|
|
|
* Returns true if more than one character is upper case, otherwise returns false.
|
|
|
|
*/
|
|
|
|
public boolean isMostlyCaps() {
|
|
|
|
return mCapsCount > 1;
|
|
|
|
}
|
2010-01-24 15:34:07 +00:00
|
|
|
|
2012-07-27 14:13:28 +00:00
|
|
|
/**
|
|
|
|
* Returns true if we have digits in the composing word.
|
|
|
|
*/
|
|
|
|
public boolean hasDigits() {
|
|
|
|
return mDigitsCount > 0;
|
|
|
|
}
|
|
|
|
|
2011-12-20 08:52:29 +00:00
|
|
|
/**
|
2013-12-13 08:09:16 +00:00
|
|
|
* Saves the caps mode and the previous word at the start of composing.
|
2012-08-21 10:49:25 +00:00
|
|
|
*
|
2013-12-13 08:09:16 +00:00
|
|
|
* WordComposer needs to know about the caps mode for several reasons. The first is, we need
|
|
|
|
* to know after the fact what the reason was, to register the correct form into the user
|
|
|
|
* history dictionary: if the word was automatically capitalized, we should insert it in
|
|
|
|
* all-lower case but if it's a manual pressing of shift, then it should be inserted as is.
|
2012-08-21 10:49:25 +00:00
|
|
|
* Also, batch input needs to know about the current caps mode to display correctly
|
|
|
|
* capitalized suggestions.
|
|
|
|
* @param mode the mode at the time of start
|
2014-05-21 06:40:08 +00:00
|
|
|
* @param prevWordsInfo the information of previous words
|
2010-01-24 15:34:07 +00:00
|
|
|
*/
|
2013-12-13 08:09:16 +00:00
|
|
|
public void setCapitalizedModeAndPreviousWordAtStartComposingTime(final int mode,
|
2014-05-21 06:40:08 +00:00
|
|
|
final PrevWordsInfo prevWordsInfo) {
|
2012-08-21 10:49:25 +00:00
|
|
|
mCapitalizedMode = mode;
|
2014-05-21 06:40:08 +00:00
|
|
|
mPrevWordsInfo = prevWordsInfo;
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the word was automatically capitalized.
|
|
|
|
* @return whether the word was automatically capitalized
|
|
|
|
*/
|
2012-08-21 10:49:25 +00:00
|
|
|
public boolean wasAutoCapitalized() {
|
|
|
|
return mCapitalizedMode == CAPS_MODE_AUTO_SHIFT_LOCKED
|
|
|
|
|| mCapitalizedMode == CAPS_MODE_AUTO_SHIFTED;
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
2011-12-13 10:38:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the auto-correction for this word.
|
|
|
|
*/
|
2012-10-03 06:19:43 +00:00
|
|
|
public void setAutoCorrection(final String correction) {
|
2012-01-26 08:29:57 +00:00
|
|
|
mAutoCorrection = correction;
|
2011-12-13 10:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-12-13 14:08:12 +00:00
|
|
|
* @return the auto-correction for this word, or null if none.
|
2011-12-13 10:38:36 +00:00
|
|
|
*/
|
2012-10-03 06:19:43 +00:00
|
|
|
public String getAutoCorrectionOrNull() {
|
2012-01-26 08:29:57 +00:00
|
|
|
return mAutoCorrection;
|
2011-12-13 10:38:36 +00:00
|
|
|
}
|
2011-12-13 14:12:22 +00:00
|
|
|
|
2012-04-26 09:01:13 +00:00
|
|
|
/**
|
|
|
|
* @return whether we started composing this word by resuming suggestion on an existing string
|
|
|
|
*/
|
|
|
|
public boolean isResumed() {
|
|
|
|
return mIsResumed;
|
|
|
|
}
|
|
|
|
|
2012-01-26 06:52:55 +00:00
|
|
|
// `type' should be one of the LastComposedWord.COMMIT_TYPE_* constants above.
|
2014-01-09 09:36:23 +00:00
|
|
|
// committedWord should contain suggestion spans if applicable.
|
|
|
|
public LastComposedWord commitWord(final int type, final CharSequence committedWord,
|
2014-05-21 02:15:38 +00:00
|
|
|
final String separatorString, final PrevWordsInfo prevWordsInfo) {
|
2012-02-22 08:05:19 +00:00
|
|
|
// Note: currently, we come here whenever we commit a word. If it's a MANUAL_PICK
|
|
|
|
// or a DECIDED_WORD we may cancel the commit later; otherwise, we should deactivate
|
|
|
|
// the last composed word to ensure this does not happen.
|
2014-04-08 07:42:24 +00:00
|
|
|
final LastComposedWord lastComposedWord = new LastComposedWord(mEvents,
|
2014-03-25 12:59:53 +00:00
|
|
|
mInputPointers, mTypedWordCache.toString(), committedWord, separatorString,
|
2014-05-21 02:15:38 +00:00
|
|
|
prevWordsInfo, mCapitalizedMode);
|
2012-06-29 09:42:15 +00:00
|
|
|
mInputPointers.reset();
|
2012-02-22 08:05:19 +00:00
|
|
|
if (type != LastComposedWord.COMMIT_TYPE_DECIDED_WORD
|
|
|
|
&& type != LastComposedWord.COMMIT_TYPE_MANUAL_PICK) {
|
2012-01-26 10:05:59 +00:00
|
|
|
lastComposedWord.deactivate();
|
|
|
|
}
|
2012-07-13 04:31:27 +00:00
|
|
|
mCapsCount = 0;
|
2012-07-27 14:13:28 +00:00
|
|
|
mDigitsCount = 0;
|
2012-07-13 04:31:27 +00:00
|
|
|
mIsBatchMode = false;
|
2014-05-19 04:55:40 +00:00
|
|
|
mPrevWordsInfo = new PrevWordsInfo(committedWord.toString());
|
2014-03-20 08:55:30 +00:00
|
|
|
mCombinerChain.reset();
|
2014-03-13 08:37:16 +00:00
|
|
|
mEvents.clear();
|
2013-01-17 11:39:09 +00:00
|
|
|
mCodePointSize = 0;
|
2012-07-13 04:31:27 +00:00
|
|
|
mIsFirstCharCapitalized = false;
|
2013-01-17 11:39:09 +00:00
|
|
|
mCapitalizedMode = CAPS_MODE_OFF;
|
2014-03-25 12:59:53 +00:00
|
|
|
refreshTypedWordCache();
|
2012-01-26 08:29:57 +00:00
|
|
|
mAutoCorrection = null;
|
2013-04-10 07:38:37 +00:00
|
|
|
mCursorPositionWithinWord = 0;
|
2012-04-26 09:01:13 +00:00
|
|
|
mIsResumed = false;
|
2013-04-12 11:45:18 +00:00
|
|
|
mRejectedBatchModeSuggestion = null;
|
2012-01-26 07:05:09 +00:00
|
|
|
return lastComposedWord;
|
2011-12-13 14:12:22 +00:00
|
|
|
}
|
2013-12-13 11:42:29 +00:00
|
|
|
|
2013-12-16 12:41:03 +00:00
|
|
|
// Call this when the recorded previous word should be discarded. This is typically called
|
|
|
|
// when the user inputs a separator that's not whitespace (including the case of the
|
|
|
|
// double-space-to-period feature).
|
|
|
|
public void discardPreviousWordForSuggestion() {
|
2014-05-23 14:19:33 +00:00
|
|
|
mPrevWordsInfo = PrevWordsInfo.EMPTY_PREV_WORDS_INFO;
|
2013-12-13 11:42:29 +00:00
|
|
|
}
|
2011-12-13 14:12:22 +00:00
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
public void resumeSuggestionOnLastComposedWord(final LastComposedWord lastComposedWord,
|
2014-05-19 04:55:40 +00:00
|
|
|
final PrevWordsInfo prevWordsInfo) {
|
2014-03-13 08:37:16 +00:00
|
|
|
mEvents.clear();
|
|
|
|
Collections.copy(mEvents, lastComposedWord.mEvents);
|
2012-06-29 09:42:15 +00:00
|
|
|
mInputPointers.set(lastComposedWord.mInputPointers);
|
2014-03-20 08:55:30 +00:00
|
|
|
mCombinerChain.reset();
|
2014-03-25 12:59:53 +00:00
|
|
|
refreshTypedWordCache();
|
2013-01-16 10:39:04 +00:00
|
|
|
mCapitalizedMode = lastComposedWord.mCapitalizedMode;
|
2012-02-22 07:11:07 +00:00
|
|
|
mAutoCorrection = null; // This will be filled by the next call to updateSuggestion.
|
2013-04-10 07:38:37 +00:00
|
|
|
mCursorPositionWithinWord = mCodePointSize;
|
2013-04-12 11:45:18 +00:00
|
|
|
mRejectedBatchModeSuggestion = null;
|
2012-04-26 09:01:13 +00:00
|
|
|
mIsResumed = true;
|
2014-05-19 04:55:40 +00:00
|
|
|
mPrevWordsInfo = prevWordsInfo;
|
2011-12-14 11:13:16 +00:00
|
|
|
}
|
2012-07-10 01:46:13 +00:00
|
|
|
|
|
|
|
public boolean isBatchMode() {
|
|
|
|
return mIsBatchMode;
|
|
|
|
}
|
2013-04-12 11:45:18 +00:00
|
|
|
|
|
|
|
public void setRejectedBatchModeSuggestion(final String rejectedSuggestion) {
|
|
|
|
mRejectedBatchModeSuggestion = rejectedSuggestion;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getRejectedBatchModeSuggestion() {
|
|
|
|
return mRejectedBatchModeSuggestion;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|