aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java6
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java53
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java3
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java22
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java15
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java35
-rw-r--r--java/src/com/android/inputmethod/keyboard/PopupPanel.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/ProximityInfo.java69
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java183
-rw-r--r--java/src/com/android/inputmethod/latin/TextEntryState.java3
10 files changed, 206 insertions, 185 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
index de1e3963d..8ca834148 100644
--- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
+++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
@@ -29,7 +29,7 @@ import com.android.inputmethod.compat.AccessibilityEventCompatUtils;
import com.android.inputmethod.compat.MotionEventCompatUtils;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.KeyDetector;
-import com.android.inputmethod.keyboard.KeyboardView;
+import com.android.inputmethod.keyboard.LatinKeyboardBaseView;
import com.android.inputmethod.keyboard.PointerTracker;
public class AccessibleKeyboardViewProxy {
@@ -40,7 +40,7 @@ public class AccessibleKeyboardViewProxy {
private static final long DELAY_KEY_PRESS = 10;
private int mScaledEdgeSlop;
- private KeyboardView mView;
+ private LatinKeyboardBaseView mView;
private AccessibleKeyboardActionListener mListener;
private FlickGestureDetector mGestureDetector;
@@ -57,7 +57,7 @@ public class AccessibleKeyboardViewProxy {
return sInstance;
}
- public static void setView(KeyboardView view) {
+ public static void setView(LatinKeyboardBaseView view) {
sInstance.mView = view;
}
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 280c0c9d8..0b4fce417 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -141,14 +141,6 @@ public class Keyboard {
// TODO: Change GRID_WIDTH and GRID_HEIGHT to private.
public final int GRID_WIDTH;
public final int GRID_HEIGHT;
- private final int GRID_SIZE;
- private int mCellWidth;
- private int mCellHeight;
- private int[][] mGridNeighbors;
- private int mProximityThreshold;
- private static int[] EMPTY_INT_ARRAY = new int[0];
- /** Number of key widths from current touch point to search for nearest keys. */
- private static float SEARCH_DISTANCE = 1.2f;
private final ProximityInfo mProximityInfo;
@@ -164,7 +156,6 @@ public class Keyboard {
final Resources res = context.getResources();
GRID_WIDTH = res.getInteger(R.integer.config_keyboard_grid_width);
GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height);
- GRID_SIZE = GRID_WIDTH * GRID_HEIGHT;
final int horizontalEdgesPadding = (int)res.getDimension(
R.dimen.keyboard_horizontal_edges_padding);
@@ -177,12 +168,13 @@ public class Keyboard {
mDefaultVerticalGap = 0;
mDefaultHeight = mDefaultWidth;
mId = id;
- mProximityInfo = new ProximityInfo(GRID_WIDTH, GRID_HEIGHT);
loadKeyboard(context, xmlLayoutResId);
+ mProximityInfo = new ProximityInfo(
+ GRID_WIDTH, GRID_HEIGHT, getMinWidth(), getHeight(), getKeyWidth(), mKeys);
}
public int getProximityInfo() {
- return mProximityInfo.getNativeProximityInfo(this);
+ return mProximityInfo.getNativeProximityInfo();
}
public List<Key> getKeys() {
@@ -219,8 +211,6 @@ public class Keyboard {
public void setKeyWidth(int width) {
mDefaultWidth = width;
- final int threshold = (int) (width * SEARCH_DISTANCE);
- mProximityThreshold = threshold * threshold;
}
/**
@@ -365,34 +355,6 @@ public class Keyboard {
return label;
}
- // TODO: Move this function to ProximityInfo and make this private.
- public void computeNearestNeighbors() {
- // Round-up so we don't have any pixels outside the grid
- mCellWidth = (getMinWidth() + GRID_WIDTH - 1) / GRID_WIDTH;
- mCellHeight = (getHeight() + GRID_HEIGHT - 1) / GRID_HEIGHT;
- mGridNeighbors = new int[GRID_SIZE][];
- final int[] indices = new int[mKeys.size()];
- final int gridWidth = GRID_WIDTH * mCellWidth;
- final int gridHeight = GRID_HEIGHT * mCellHeight;
- final int threshold = mProximityThreshold;
- for (int x = 0; x < gridWidth; x += mCellWidth) {
- for (int y = 0; y < gridHeight; y += mCellHeight) {
- final int centerX = x + mCellWidth / 2;
- final int centerY = y + mCellHeight / 2;
- int count = 0;
- for (int i = 0; i < mKeys.size(); i++) {
- final Key key = mKeys.get(i);
- if (key.squaredDistanceToEdge(centerX, centerY) < threshold)
- indices[count++] = i;
- }
- final int[] cell = new int[count];
- System.arraycopy(indices, 0, cell, 0, count);
- mGridNeighbors[(y / mCellHeight) * GRID_WIDTH + (x / mCellWidth)] = cell;
- }
- }
- mProximityInfo.setProximityInfo(mGridNeighbors, getMinWidth(), getHeight(), mKeys);
- }
-
/**
* Returns the indices of the keys that are closest to the given point.
* @param x the x-coordinate of the point
@@ -401,14 +363,7 @@ public class Keyboard {
* point is out of range, then an array of size zero is returned.
*/
public int[] getNearestKeys(int x, int y) {
- if (mGridNeighbors == null) computeNearestNeighbors();
- if (x >= 0 && x < getMinWidth() && y >= 0 && y < getHeight()) {
- int index = (y / mCellHeight) * GRID_WIDTH + (x / mCellWidth);
- if (index < GRID_SIZE) {
- return mGridNeighbors[index];
- }
- }
- return EMPTY_INT_ARRAY;
+ return mProximityInfo.getNearestKeys(x, y);
}
/**
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 7ad947c67..bb21d7a63 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -152,7 +152,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
boolean voiceButtonOnPrimary) {
mSwitchState = SWITCH_STATE_ALPHA;
try {
- loadKeyboardInternal(attribute, voiceKeyEnabled, voiceButtonOnPrimary, false);
+ final boolean isSymbols = (mCurrentId != null) ? mCurrentId.isSymbolsKeyboard() : false;
+ loadKeyboardInternal(attribute, voiceKeyEnabled, voiceButtonOnPrimary, isSymbols);
} catch (RuntimeException e) {
// Get KeyboardId to record which keyboard has been failed to load.
final KeyboardId id = getKeyboardId(attribute, false);
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 56e4dc871..e31aa8478 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -38,7 +38,6 @@ import android.view.ViewGroup;
import android.widget.TextView;
import com.android.inputmethod.compat.FrameLayoutCompatUtils;
-import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
@@ -73,7 +72,7 @@ import java.util.HashMap;
* @attr ref R.styleable#KeyboardView_shadowColor
* @attr ref R.styleable#KeyboardView_shadowRadius
*/
-public abstract class KeyboardView extends View implements PointerTracker.DrawingProxy {
+public class KeyboardView extends View implements PointerTracker.DrawingProxy {
private static final boolean DEBUG_KEYBOARD_GRID = false;
// Miscellaneous constants
@@ -918,23 +917,4 @@ public abstract class KeyboardView extends View implements PointerTracker.Drawin
super.onDetachedFromWindow();
closing();
}
-
- /**
- * Get KeyDetector object that is used for the Keyboard of this KeyboardView.
- * @return the KeyDetector object that is used for the Keyboard
- */
- public abstract KeyDetector getKeyDetector();
-
- /**
- * Get KeyboardActionListener object that is used to register key code and so on.
- * @return the KeyboardActionListner for this KeyboardView
- */
- public abstract KeyboardActionListener getKeyboardActionListener();
-
- /**
- * Get TimerProxy object that handles key repeat and long press timer event for the Keyboard
- * of this KeyboardView.
- * @return the TimerProxy object that handles key repeat and long press timer event.
- */
- public abstract TimerProxy getTimerProxy();
}
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java
index 318e454d3..b512f5ac7 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java
@@ -33,6 +33,7 @@ import android.widget.PopupWindow;
import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
+import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder;
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
@@ -49,7 +50,7 @@ import java.util.WeakHashMap;
* @attr ref R.styleable#KeyboardView_verticalCorrection
* @attr ref R.styleable#KeyboardView_popupLayout
*/
-public class LatinKeyboardBaseView extends KeyboardView {
+public class LatinKeyboardBaseView extends KeyboardView implements PointerTracker.KeyEventHandler {
private static final String TAG = LatinKeyboardBaseView.class.getSimpleName();
private static final boolean ENABLE_CAPSLOCK_BY_LONGPRESS = true;
@@ -278,6 +279,11 @@ public class LatinKeyboardBaseView extends KeyboardView {
}
@Override
+ public DrawingProxy getDrawingProxy() {
+ return this;
+ }
+
+ @Override
public TimerProxy getTimerProxy() {
return mKeyTimerHandler;
}
@@ -589,16 +595,19 @@ public class LatinKeyboardBaseView extends KeyboardView {
}
private static void processMotionEvent(PointerTracker tracker, int action, int x, int y,
- long eventTime, KeyboardView keyboardView) {
+ long eventTime, PointerTracker.KeyEventHandler handler) {
switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
- tracker.onDownEvent(x, y, eventTime, keyboardView);
+ tracker.onDownEvent(x, y, eventTime, handler);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
tracker.onUpEvent(x, y, eventTime);
break;
+ case MotionEvent.ACTION_MOVE:
+ tracker.onMoveEvent(x, y, eventTime);
+ break;
case MotionEvent.ACTION_CANCEL:
tracker.onCancelEvent(x, y, eventTime);
break;
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 95574258e..29a575ad0 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -36,6 +36,33 @@ public class PointerTracker {
private static final boolean DEBUG_LISTENER = false;
private static boolean DEBUG_MODE = LatinImeLogger.sDBG;
+ public interface KeyEventHandler {
+ /**
+ * Get KeyDetector object that is used for this PointerTracker.
+ * @return the KeyDetector object that is used for this PointerTracker
+ */
+ public KeyDetector getKeyDetector();
+
+ /**
+ * Get KeyboardActionListener object that is used to register key code and so on.
+ * @return the KeyboardActionListner for this PointerTracker
+ */
+ public KeyboardActionListener getKeyboardActionListener();
+
+ /**
+ * Get DrawingProxy object that is used for this PointerTracker.
+ * @return the DrawingProxy object that is used for this PointerTracker
+ */
+ public DrawingProxy getDrawingProxy();
+
+ /**
+ * Get TimerProxy object that handles key repeat and long press timer event for this
+ * PointerTracker.
+ * @return the TimerProxy object that handles key repeat and long press timer event.
+ */
+ public TimerProxy getTimerProxy();
+ }
+
public interface DrawingProxy {
public void invalidateKey(Key key);
public void showKeyPreview(int keyIndex, PointerTracker tracker);
@@ -329,13 +356,13 @@ public class PointerTracker {
return onMoveKeyInternal(x, y);
}
- public void onDownEvent(int x, int y, long eventTime, KeyboardView keyboardView) {
+ public void onDownEvent(int x, int y, long eventTime, KeyEventHandler handler) {
if (DEBUG_EVENT)
printTouchEvent("onDownEvent:", x, y, eventTime);
- mDrawingProxy = keyboardView;
- setKeyboardActionListener(keyboardView.getKeyboardActionListener());
- setKeyDetectorInner(keyboardView.getKeyDetector());
+ mDrawingProxy = handler.getDrawingProxy();
+ setKeyboardActionListener(handler.getKeyboardActionListener());
+ setKeyDetectorInner(handler.getKeyDetector());
// Naive up-to-down noise filter.
final long deltaT = eventTime - mUpTime;
if (deltaT < mTouchNoiseThresholdMillis) {
diff --git a/java/src/com/android/inputmethod/keyboard/PopupPanel.java b/java/src/com/android/inputmethod/keyboard/PopupPanel.java
index 386e11f2c..2d9130fcb 100644
--- a/java/src/com/android/inputmethod/keyboard/PopupPanel.java
+++ b/java/src/com/android/inputmethod/keyboard/PopupPanel.java
@@ -19,7 +19,7 @@ package com.android.inputmethod.keyboard;
import android.view.MotionEvent;
import android.widget.PopupWindow;
-public interface PopupPanel {
+public interface PopupPanel extends PointerTracker.KeyEventHandler {
/**
* Show popup panel.
* @param parentKeyboardView the parent KeyboardView that has the parent key.
diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
index 33acc6907..aadedc69d 100644
--- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
+++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
@@ -23,15 +23,35 @@ import java.util.List;
public class ProximityInfo {
public static final int MAX_PROXIMITY_CHARS_SIZE = 16;
+ /** Number of key widths from current touch point to search for nearest keys. */
+ private static float SEARCH_DISTANCE = 1.2f;
+ private static final int[] EMPTY_INT_ARRAY = new int[0];
private final int mGridWidth;
private final int mGridHeight;
private final int mGridSize;
+ private final int mCellWidth;
+ private final int mCellHeight;
+ // TODO: Find a proper name for mKeyboardMinWidth
+ private final int mKeyboardMinWidth;
+ private final int mKeyboardHeight;
+ private final int[][] mGridNeighbors;
- ProximityInfo(int gridWidth, int gridHeight) {
+ ProximityInfo(
+ int gridWidth, int gridHeight, int minWidth, int height, int keyWidth, List<Key> keys) {
mGridWidth = gridWidth;
mGridHeight = gridHeight;
mGridSize = mGridWidth * mGridHeight;
+ mCellWidth = (minWidth + mGridWidth - 1) / mGridWidth;
+ mCellHeight = (height + mGridHeight - 1) / mGridHeight;
+ mKeyboardMinWidth = minWidth;
+ mKeyboardHeight = height;
+ mGridNeighbors = new int[mGridSize][];
+ if (minWidth == 0 || height == 0) {
+ // No proximity required. Keyboard might be mini keyboard.
+ return;
+ }
+ computeNearestNeighbors(keyWidth, keys);
}
private int mNativeProximityInfo;
@@ -42,7 +62,7 @@ public class ProximityInfo {
int displayHeight, int gridWidth, int gridHeight, int[] proximityCharsArray);
private native void releaseProximityInfoNative(int nativeProximityInfo);
- public final void setProximityInfo(int[][] gridNeighborKeyIndexes, int keyboardWidth,
+ private final void setProximityInfo(int[][] gridNeighborKeyIndexes, int keyboardWidth,
int keyboardHeight, List<Key> keys) {
int[] proximityCharsArray = new int[mGridSize * MAX_PROXIMITY_CHARS_SIZE];
Arrays.fill(proximityCharsArray, KeyDetector.NOT_A_CODE);
@@ -57,12 +77,7 @@ public class ProximityInfo {
keyboardWidth, keyboardHeight, mGridWidth, mGridHeight, proximityCharsArray);
}
- // TODO: Get rid of this function's input (keyboard).
- public int getNativeProximityInfo(Keyboard keyboard) {
- if (mNativeProximityInfo == 0) {
- // TODO: Move this function to ProximityInfo and make this private.
- keyboard.computeNearestNeighbors();
- }
+ public int getNativeProximityInfo() {
return mNativeProximityInfo;
}
@@ -77,4 +92,42 @@ public class ProximityInfo {
super.finalize();
}
}
+
+ private void computeNearestNeighbors(int defaultWidth, List<Key> keys) {
+ final int thresholdBase = (int) (defaultWidth * SEARCH_DISTANCE);
+ final int threshold = thresholdBase * thresholdBase;
+ // Round-up so we don't have any pixels outside the grid
+ final int[] indices = new int[keys.size()];
+ final int gridWidth = mGridWidth * mCellWidth;
+ final int gridHeight = mGridHeight * mCellHeight;
+ for (int x = 0; x < gridWidth; x += mCellWidth) {
+ for (int y = 0; y < gridHeight; y += mCellHeight) {
+ final int centerX = x + mCellWidth / 2;
+ final int centerY = y + mCellHeight / 2;
+ int count = 0;
+ for (int i = 0; i < keys.size(); i++) {
+ final Key key = keys.get(i);
+ if (key.squaredDistanceToEdge(centerX, centerY) < threshold)
+ indices[count++] = i;
+ }
+ final int[] cell = new int[count];
+ System.arraycopy(indices, 0, cell, 0, count);
+ mGridNeighbors[(y / mCellHeight) * mGridWidth + (x / mCellWidth)] = cell;
+ }
+ }
+ setProximityInfo(mGridNeighbors, mKeyboardMinWidth, mKeyboardHeight, keys);
+ }
+
+ public int[] getNearestKeys(int x, int y) {
+ if (mGridNeighbors == null) {
+ return EMPTY_INT_ARRAY;
+ }
+ if (x >= 0 && x < mKeyboardMinWidth && y >= 0 && y < mKeyboardHeight) {
+ int index = (y / mCellHeight) * mGridWidth + (x / mCellWidth);
+ if (index < mGridSize) {
+ return mGridNeighbors[index];
+ }
+ }
+ return EMPTY_INT_ARRAY;
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index c41ff0ee6..cec30eaab 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -164,8 +164,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private boolean mIsSettingsSuggestionStripOn;
private boolean mApplicationSpecifiedCompletionOn;
- private final StringBuilder mComposing = new StringBuilder();
- private WordComposer mWord = new WordComposer();
+ private final StringBuilder mComposingStringBuilder = new StringBuilder();
+ private WordComposer mWordComposer = new WordComposer();
private CharSequence mBestWord;
private boolean mHasUncommittedTypedChars;
private boolean mHasDictionary;
@@ -233,7 +233,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
case MSG_UPDATE_OLD_SUGGESTIONS:
latinIme.mRecorrection.fetchAndDisplayRecorrectionSuggestions(
latinIme.mVoiceProxy, latinIme.mCandidateView,
- latinIme.mSuggest, latinIme.mKeyboardSwitcher, latinIme.mWord,
+ latinIme.mSuggest, latinIme.mKeyboardSwitcher, latinIme.mWordComposer,
latinIme.mHasUncommittedTypedChars, latinIme.mLastSelectionStart,
latinIme.mLastSelectionEnd, latinIme.mSettingsValues.mWordSeparators);
break;
@@ -555,7 +555,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
inputView.closing();
mEnteredText = null;
- mComposing.setLength(0);
+ mComposingStringBuilder.setLength(0);
mHasUncommittedTypedChars = false;
mDeleteCount = 0;
mJustAddedMagicSpace = false;
@@ -717,16 +717,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final boolean selectionChanged = (newSelStart != candidatesEnd
|| newSelEnd != candidatesEnd) && mLastSelectionStart != newSelStart;
final boolean candidatesCleared = candidatesStart == -1 && candidatesEnd == -1;
- if (((mComposing.length() > 0 && mHasUncommittedTypedChars)
+ if (((mComposingStringBuilder.length() > 0 && mHasUncommittedTypedChars)
|| mVoiceProxy.isVoiceInputHighlighted())
&& (selectionChanged || candidatesCleared)) {
if (candidatesCleared) {
// If the composing span has been cleared, save the typed word in the history for
// recorrection before we reset the candidate strip. Then, we'll be able to show
// suggestions for recorrection right away.
- mRecorrection.saveRecorrectionSuggestion(mWord, mComposing);
+ mRecorrection.saveRecorrectionSuggestion(mWordComposer, mComposingStringBuilder);
}
- mComposing.setLength(0);
+ mComposingStringBuilder.setLength(0);
mHasUncommittedTypedChars = false;
if (isCursorTouchingWord()) {
mHandler.cancelUpdateBigramPredictions();
@@ -740,15 +740,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
ic.finishComposingText();
}
mVoiceProxy.setVoiceInputHighlighted(false);
- } else if (!mHasUncommittedTypedChars && !mExpectingUpdateSelection) {
- if (TextEntryState.isAcceptedDefault() || TextEntryState.isSpaceAfterPicked()) {
- if (TextEntryState.isAcceptedDefault())
- TextEntryState.reset();
- }
+ } else if (!mHasUncommittedTypedChars && !mExpectingUpdateSelection
+ && TextEntryState.isAcceptedDefault()) {
+ TextEntryState.reset();
}
if (!mExpectingUpdateSelection) {
- mJustAddedMagicSpace = false; // The user moved the cursor.
- mJustReplacedDoubleSpace = false;
+ mJustAddedMagicSpace = false; // The user moved the cursor.
+ mJustReplacedDoubleSpace = false;
}
mExpectingUpdateSelection = false;
mHandler.postUpdateShiftKeyState();
@@ -945,18 +943,18 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
public void commitTyped(InputConnection inputConnection) {
- if (mHasUncommittedTypedChars) {
- mHasUncommittedTypedChars = false;
- if (mComposing.length() > 0) {
- if (inputConnection != null) {
- inputConnection.commitText(mComposing, 1);
- }
- mCommittedLength = mComposing.length();
- TextEntryState.acceptedTyped(mComposing);
- addToAutoAndUserBigramDictionaries(mComposing, AutoDictionary.FREQUENCY_FOR_TYPED);
+ if (!mHasUncommittedTypedChars) return;
+ mHasUncommittedTypedChars = false;
+ if (mComposingStringBuilder.length() > 0) {
+ if (inputConnection != null) {
+ inputConnection.commitText(mComposingStringBuilder, 1);
}
- updateSuggestions();
+ mCommittedLength = mComposingStringBuilder.length();
+ TextEntryState.acceptedTyped(mComposingStringBuilder);
+ addToAutoAndUserBigramDictionaries(mComposingStringBuilder,
+ AutoDictionary.FREQUENCY_FOR_TYPED);
}
+ updateSuggestions();
}
public boolean getCurrentAutoCapsState() {
@@ -1185,12 +1183,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final boolean deleteChar = !mHasUncommittedTypedChars;
if (mHasUncommittedTypedChars) {
- final int length = mComposing.length();
+ final int length = mComposingStringBuilder.length();
if (length > 0) {
- mComposing.delete(length - 1, length);
- mWord.deleteLast();
- ic.setComposingText(mComposing, 1);
- if (mComposing.length() == 0) {
+ mComposingStringBuilder.delete(length - 1, length);
+ mWordComposer.deleteLast();
+ ic.setComposingText(mComposingStringBuilder, 1);
+ if (mComposingStringBuilder.length() == 0) {
mHasUncommittedTypedChars = false;
}
if (1 == length) {
@@ -1280,9 +1278,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (isAlphabet(code) && isSuggestionsRequested() && !isCursorTouchingWord()) {
if (!mHasUncommittedTypedChars) {
mHasUncommittedTypedChars = true;
- mComposing.setLength(0);
- mRecorrection.saveRecorrectionSuggestion(mWord, mBestWord);
- mWord.reset();
+ mComposingStringBuilder.setLength(0);
+ mRecorrection.saveRecorrectionSuggestion(mWordComposer, mBestWord);
+ mWordComposer.reset();
clearSuggestions();
}
}
@@ -1308,19 +1306,19 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
if (mHasUncommittedTypedChars) {
- if (mComposing.length() == 0 && switcher.isAlphabetMode()
+ if (mComposingStringBuilder.length() == 0 && switcher.isAlphabetMode()
&& switcher.isShiftedOrShiftLocked()) {
- mWord.setFirstCharCapitalized(true);
+ mWordComposer.setFirstCharCapitalized(true);
}
- mComposing.append((char) code);
- mWord.add(code, keyCodes, x, y);
+ mComposingStringBuilder.append((char) code);
+ mWordComposer.add(code, keyCodes, x, y);
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
// If it's the first letter, make note of auto-caps state
- if (mWord.size() == 1) {
- mWord.setAutoCapitalized(getCurrentAutoCapsState());
+ if (mWordComposer.size() == 1) {
+ mWordComposer.setAutoCapitalized(getCurrentAutoCapsState());
}
- ic.setComposingText(mComposing, 1);
+ ic.setComposingText(mComposingStringBuilder, 1);
}
mHandler.postUpdateSuggestions();
} else {
@@ -1388,7 +1386,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
TextEntryState.typedCharacter((char) primaryCode, true, x, y);
if (pickedDefault) {
- CharSequence typedWord = mWord.getTypedWord();
+ CharSequence typedWord = mWordComposer.getTypedWord();
TextEntryState.backToAcceptedDefault(typedWord);
if (!TextUtils.isEmpty(typedWord) && !typedWord.equals(mBestWord)) {
InputConnectionCompatUtils.commitCorrection(
@@ -1491,28 +1489,26 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
setPunctuationSuggestions();
return;
}
- showSuggestions(mWord);
- }
- private void showSuggestions(WordComposer word) {
+ final WordComposer wordComposer = mWordComposer;
// TODO: May need a better way of retrieving previous word
CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(),
mSettingsValues.mWordSeparators);
SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(
- mKeyboardSwitcher.getKeyboardView(), word, prevWord);
+ mKeyboardSwitcher.getKeyboardView(), wordComposer, prevWord);
- boolean correctionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasAutoCorrection();
- final CharSequence typedWord = word.getTypedWord();
+ boolean autoCorrectionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasAutoCorrection();
+ final CharSequence typedWord = wordComposer.getTypedWord();
// Here, we want to promote a whitelisted word if exists.
final boolean typedWordValid = AutoCorrection.isValidWordForAutoCorrection(
mSuggest.getUnigramDictionaries(), typedWord, preferCapitalization());
if (mCorrectionMode == Suggest.CORRECTION_FULL
|| mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM) {
- correctionAvailable |= typedWordValid;
+ autoCorrectionAvailable |= typedWordValid;
}
// Don't auto-correct words with multiple capital letter
- correctionAvailable &= !word.isMostlyCaps();
- correctionAvailable &= !TextEntryState.isRecorrecting();
+ autoCorrectionAvailable &= !wordComposer.isMostlyCaps();
+ autoCorrectionAvailable &= !TextEntryState.isRecorrecting();
// Basically, we update the suggestion strip only when suggestion count > 1. However,
// there is an exception: We update the suggestion strip whenever typed word's length
@@ -1524,7 +1520,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (builder.size() > 1 || typedWord.length() == 1 || typedWordValid
|| mCandidateView.isShowingAddToDictionaryHint()) {
builder.setTypedWordValid(typedWordValid).setHasMinimalSuggestion(
- correctionAvailable);
+ autoCorrectionAvailable);
} else {
final SuggestedWords previousSuggestions = mCandidateView.getSuggestions();
if (previousSuggestions == mSettingsValues.mSuggestPuncList)
@@ -1558,7 +1554,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
updateSuggestions();
}
if (mBestWord != null && mBestWord.length() > 0) {
- TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord, separatorCode);
+ TextEntryState.acceptedDefault(mWordComposer.getTypedWord(), mBestWord, separatorCode);
mExpectingUpdateSelection = true;
commitBestWord(mBestWord);
// Add the word to the auto dictionary if it's not a known word
@@ -1625,7 +1621,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (!mHasUncommittedTypedChars) {
// If we are not composing a word, then it was a suggestion inferred from
// context - no user input. We should reset the word composer.
- mWord.reset();
+ mWordComposer.reset();
}
mExpectingUpdateSelection = true;
commitBestWord(suggestion);
@@ -1635,9 +1631,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} else {
addToOnlyBigramDictionary(suggestion, 1);
}
- LatinImeLogger.logOnManualSuggestion(mComposing.toString(), suggestion.toString(),
- index, suggestions.mWords);
- TextEntryState.acceptedSuggestion(mComposing.toString(), suggestion);
+ LatinImeLogger.logOnManualSuggestion(mComposingStringBuilder.toString(),
+ suggestion.toString(), index, suggestions.mWords);
+ TextEntryState.acceptedSuggestion(mComposingStringBuilder.toString(), suggestion);
// Follow it with a space
if (mShouldInsertMagicSpace && !recorrecting) {
sendMagicSpace();
@@ -1682,8 +1678,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
/**
- * Commits the chosen word to the text field and saves it for later
- * retrieval.
+ * Commits the chosen word to the text field and saves it for later retrieval.
*/
private void commitBestWord(CharSequence bestWord) {
KeyboardSwitcher switcher = mKeyboardSwitcher;
@@ -1696,7 +1691,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
ic.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
this, bestWord, suggestedWords), 1);
}
- mRecorrection.saveRecorrectionSuggestion(mWord, bestWord);
+ mRecorrection.saveRecorrectionSuggestion(mWordComposer, bestWord);
mHasUncommittedTypedChars = false;
mCommittedLength = bestWord.length();
}
@@ -1800,41 +1795,41 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
private void revertLastWord(boolean deleteChar) {
- final int length = mComposing.length();
- if (!mHasUncommittedTypedChars && length > 0) {
- final InputConnection ic = getCurrentInputConnection();
- final CharSequence punctuation = ic.getTextBeforeCursor(1, 0);
- if (deleteChar) ic.deleteSurroundingText(1, 0);
- int toDelete = mCommittedLength;
- final CharSequence toTheLeft = ic.getTextBeforeCursor(mCommittedLength, 0);
- if (!TextUtils.isEmpty(toTheLeft)
- && mSettingsValues.isWordSeparator(toTheLeft.charAt(0))) {
- toDelete--;
- }
- ic.deleteSurroundingText(toDelete, 0);
- // Re-insert punctuation only when the deleted character was word separator and the
- // composing text wasn't equal to the auto-corrected text.
- if (deleteChar
- && !TextUtils.isEmpty(punctuation)
- && mSettingsValues.isWordSeparator(punctuation.charAt(0))
- && !TextUtils.equals(mComposing, toTheLeft)) {
- ic.commitText(mComposing, 1);
- TextEntryState.acceptedTyped(mComposing);
- ic.commitText(punctuation, 1);
- TextEntryState.typedCharacter(punctuation.charAt(0), true,
- WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
- // Clear composing text
- mComposing.setLength(0);
- } else {
- mHasUncommittedTypedChars = true;
- ic.setComposingText(mComposing, 1);
- TextEntryState.backspace();
- }
- mHandler.cancelUpdateBigramPredictions();
- mHandler.postUpdateSuggestions();
- } else {
+ if (mHasUncommittedTypedChars || mComposingStringBuilder.length() <= 0) {
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
+ return;
}
+
+ final InputConnection ic = getCurrentInputConnection();
+ final CharSequence punctuation = ic.getTextBeforeCursor(1, 0);
+ if (deleteChar) ic.deleteSurroundingText(1, 0);
+ int toDelete = mCommittedLength;
+ final CharSequence toTheLeft = ic.getTextBeforeCursor(mCommittedLength, 0);
+ if (!TextUtils.isEmpty(toTheLeft)
+ && mSettingsValues.isWordSeparator(toTheLeft.charAt(0))) {
+ toDelete--;
+ }
+ ic.deleteSurroundingText(toDelete, 0);
+ // Re-insert punctuation only when the deleted character was word separator and the
+ // composing text wasn't equal to the auto-corrected text.
+ if (deleteChar
+ && !TextUtils.isEmpty(punctuation)
+ && mSettingsValues.isWordSeparator(punctuation.charAt(0))
+ && !TextUtils.equals(mComposingStringBuilder, toTheLeft)) {
+ ic.commitText(mComposingStringBuilder, 1);
+ TextEntryState.acceptedTyped(mComposingStringBuilder);
+ ic.commitText(punctuation, 1);
+ TextEntryState.typedCharacter(punctuation.charAt(0), true,
+ WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
+ // Clear composing text
+ mComposingStringBuilder.setLength(0);
+ } else {
+ mHasUncommittedTypedChars = true;
+ ic.setComposingText(mComposingStringBuilder, 1);
+ TextEntryState.backspace();
+ }
+ mHandler.cancelUpdateBigramPredictions();
+ mHandler.postUpdateSuggestions();
}
private boolean revertDoubleSpace() {
@@ -1863,7 +1858,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
public boolean preferCapitalization() {
- return mWord.isFirstCharCapitalized();
+ return mWordComposer.isFirstCharCapitalized();
}
// Notify that language or mode have been changed and toggleLanguage will update KeyboardID
@@ -1987,7 +1982,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
public WordComposer getCurrentWord() {
- return mWord;
+ return mWordComposer;
}
boolean isSoundOn() {
@@ -2123,7 +2118,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final Printer p = new PrintWriterPrinter(fout);
p.println("LatinIME state :");
p.println(" Keyboard mode = " + mKeyboardSwitcher.getKeyboardMode());
- p.println(" mComposing=" + mComposing.toString());
+ p.println(" mComposingStringBuilder=" + mComposingStringBuilder.toString());
p.println(" mIsSuggestionsRequested=" + mIsSettingsSuggestionStripOn);
p.println(" mCorrectionMode=" + mCorrectionMode);
p.println(" mHasUncommittedTypedChars=" + mHasUncommittedTypedChars);
diff --git a/java/src/com/android/inputmethod/latin/TextEntryState.java b/java/src/com/android/inputmethod/latin/TextEntryState.java
index b6e261114..79b3bdebb 100644
--- a/java/src/com/android/inputmethod/latin/TextEntryState.java
+++ b/java/src/com/android/inputmethod/latin/TextEntryState.java
@@ -16,6 +16,7 @@
package com.android.inputmethod.latin;
+import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.Utils.RingCharBuffer;
import android.util.Log;
@@ -100,7 +101,7 @@ public class TextEntryState {
}
public static void typedCharacter(char c, boolean isSeparator, int x, int y) {
- final boolean isSpace = (c == ' ');
+ final boolean isSpace = (c == Keyboard.CODE_SPACE);
switch (sState) {
case IN_WORD:
if (isSpace || isSeparator) {