aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java11
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java11
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardParser.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java7
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java175
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboard.java76
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java14
-rw-r--r--java/src/com/android/inputmethod/keyboard/MiniKeyboard.java35
-rw-r--r--java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java201
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java46
-rw-r--r--java/src/com/android/inputmethod/latin/ClipTouchEventWindowCallback.java75
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java95
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java12
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java81
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java6
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java22
-rw-r--r--java/src/com/android/inputmethod/latin/WindowCallbackAdapter.java168
-rw-r--r--java/src/com/android/inputmethod/voice/VoiceIMEConnector.java35
18 files changed, 533 insertions, 539 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 35bafea80..23886ad97 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -95,6 +95,8 @@ public class Key {
public boolean mPressed;
/** If this is a sticky key, is it on? */
public boolean mOn;
+ /** Key is enabled or not. */
+ public boolean mEnabled = true;
private final static int[] KEY_STATE_NORMAL_ON = {
android.R.attr.state_checkable,
@@ -385,8 +387,9 @@ public class Key {
* @see android.graphics.drawable.StateListDrawable#setState(int[])
*/
public int[] getCurrentDrawableState() {
+ final boolean pressed = mEnabled && mPressed;
if (isFunctionalKey()) {
- if (mPressed) {
+ if (pressed) {
return KEY_STATE_FUNCTIONAL_PRESSED;
} else {
return KEY_STATE_FUNCTIONAL_NORMAL;
@@ -396,20 +399,20 @@ public class Key {
int[] states = KEY_STATE_NORMAL;
if (mOn) {
- if (mPressed) {
+ if (pressed) {
states = KEY_STATE_PRESSED_ON;
} else {
states = KEY_STATE_NORMAL_ON;
}
} else {
if (mSticky) {
- if (mPressed) {
+ if (pressed) {
states = KEY_STATE_PRESSED_OFF;
} else {
states = KEY_STATE_NORMAL_OFF;
}
} else {
- if (mPressed) {
+ if (pressed) {
states = KEY_STATE_PRESSED;
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 863421f18..3a0bf53ab 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -107,11 +107,6 @@ public class Keyboard {
private final HashSet<Key> mShiftLockEnabled = new HashSet<Key>();
private final KeyboardShiftState mShiftState = new KeyboardShiftState();
- /** Space key and its icons */
- protected Key mSpaceKey;
- protected Drawable mSpaceIcon;
- protected Drawable mSpacePreviewIcon;
-
/** Total height of the keyboard, including the padding and keys */
private int mTotalHeight;
@@ -350,12 +345,6 @@ public class Keyboard {
return mId != null && mId.isNumberKeyboard();
}
- public void setSpaceKey(Key space) {
- mSpaceKey = space;
- mSpaceIcon = space.getIcon();
- mSpacePreviewIcon = space.getPreviewIcon();
- }
-
private void computeNearestNeighbors() {
// Round-up so we don't have any pixels outside the grid
mCellWidth = (getMinWidth() + GRID_WIDTH - 1) / GRID_WIDTH;
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java
index c41d57075..e8324e5fd 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java
@@ -286,8 +286,6 @@ public class KeyboardParser {
keys.add(key);
if (key.mCode == Keyboard.CODE_SHIFT)
mKeyboard.getShiftKeys().add(key);
- if (key.mCode == Keyboard.CODE_SPACE)
- mKeyboard.setSpaceKey(key);
endKey(key);
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 558de66a4..2648ff3d4 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -17,11 +17,11 @@
package com.android.inputmethod.keyboard;
import com.android.inputmethod.latin.LatinIME;
-import com.android.inputmethod.latin.Settings;
-import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.Settings;
import com.android.inputmethod.latin.SubtypeSwitcher;
+import com.android.inputmethod.latin.Utils;
import android.content.Context;
import android.content.SharedPreferences;
@@ -222,8 +222,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
keyboard.setShifted(false);
// If the cached keyboard had been switched to another keyboard while the language was
// displayed on its spacebar, it might have had arbitrary text fade factor. In such case,
- // we should reset the text fade factor.
+ // we should reset the text fade factor. It is also applicable to shortcut key.
keyboard.setSpacebarTextFadeFactor(0.0f, null);
+ keyboard.updateShortcutKey(mSubtypeSwitcher.isShortcutAvailable(), null);
return keyboard;
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 766fdf0e6..19f1fa8ee 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -125,7 +125,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
// Popup mini keyboard
private PopupWindow mMiniKeyboardPopup;
- private KeyboardView mMiniKeyboard;
+ private KeyboardView mMiniKeyboardView;
private View mMiniKeyboardParent;
private final WeakHashMap<Key, View> mMiniKeyboardCache = new WeakHashMap<Key, View>();
private int mMiniKeyboardOriginX;
@@ -134,6 +134,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
private int[] mWindowOffset;
private final float mMiniKeyboardSlideAllowance;
private int mMiniKeyboardTrackerId;
+ private final boolean mConfigShowMiniKeyboardAtTouchedPoint;
/** Listener for {@link KeyboardActionListener}. */
private KeyboardActionListener mKeyboardActionListener;
@@ -296,7 +297,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
public KeyboardView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- TypedArray a = context.obtainStyledAttributes(
+ final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
int previewLayout = 0;
int keyTextSize = 0;
@@ -381,6 +382,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
mMiniKeyboardPopup = new PopupWindow(context);
mMiniKeyboardPopup.setBackgroundDrawable(null);
mMiniKeyboardPopup.setAnimationStyle(R.style.MiniKeyboardAnimation);
+ // Allow popup window to be drawn off the screen.
+ mMiniKeyboardPopup.setClippingEnabled(false);
mPaint = new Paint();
mPaint.setAntiAlias(true);
@@ -395,10 +398,12 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
// TODO: Refer frameworks/base/core/res/res/values/config.xml
mDisambiguateSwipe = res.getBoolean(R.bool.config_swipeDisambiguation);
mMiniKeyboardSlideAllowance = res.getDimension(R.dimen.mini_keyboard_slide_allowance);
+ mConfigShowMiniKeyboardAtTouchedPoint = res.getBoolean(
+ R.bool.config_show_mini_keyboard_at_touched_point);
GestureDetector.SimpleOnGestureListener listener =
new GestureDetector.SimpleOnGestureListener() {
- private boolean mProcessingDoubleTapEvent = false;
+ private boolean mProcessingShiftDoubleTapEvent = false;
@Override
public boolean onFling(MotionEvent me1, MotionEvent me2, float velocityX,
@@ -419,25 +424,39 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
}
@Override
- public boolean onDoubleTap(MotionEvent e) {
+ public boolean onDoubleTap(MotionEvent firstDown) {
if (ENABLE_CAPSLOCK_BY_DOUBLETAP && mKeyboard instanceof LatinKeyboard
&& ((LatinKeyboard) mKeyboard).isAlphaKeyboard()) {
- final int pointerIndex = e.getActionIndex();
- final int id = e.getPointerId(pointerIndex);
+ final int pointerIndex = firstDown.getActionIndex();
+ final int id = firstDown.getPointerId(pointerIndex);
final PointerTracker tracker = getPointerTracker(id);
- if (tracker.isOnShiftKey((int)e.getX(), (int)e.getY())) {
- onDoubleTapShiftKey(tracker);
- mProcessingDoubleTapEvent = true;
+ // If the first down event is on shift key.
+ if (tracker.isOnShiftKey((int)firstDown.getX(), (int)firstDown.getY())) {
+ mProcessingShiftDoubleTapEvent = true;
return true;
}
}
- mProcessingDoubleTapEvent = false;
+ mProcessingShiftDoubleTapEvent = false;
return false;
}
@Override
- public boolean onDoubleTapEvent(MotionEvent e) {
- return mProcessingDoubleTapEvent;
+ public boolean onDoubleTapEvent(MotionEvent secondTap) {
+ if (mProcessingShiftDoubleTapEvent
+ && secondTap.getAction() == MotionEvent.ACTION_DOWN) {
+ final MotionEvent secondDown = secondTap;
+ final int pointerIndex = secondDown.getActionIndex();
+ final int id = secondDown.getPointerId(pointerIndex);
+ final PointerTracker tracker = getPointerTracker(id);
+ // If the second down event is also on shift key.
+ if (tracker.isOnShiftKey((int)secondDown.getX(), (int)secondDown.getY())) {
+ onDoubleTapShiftKey(tracker);
+ return true;
+ }
+ // Otherwise these events should not be handled as double tap.
+ mProcessingShiftDoubleTapEvent = false;
+ }
+ return mProcessingShiftDoubleTapEvent;
}
};
@@ -535,10 +554,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
return mColorScheme;
}
- public void setPopupParent(View v) {
- mMiniKeyboardParent = v;
- }
-
public void setPopupOffset(int x, int y) {
mPopupPreviewOffsetX = x;
mPopupPreviewOffsetY = y;
@@ -798,7 +813,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
mInvalidatedKey = null;
// Overlay a dark rectangle to dim the keyboard
- if (mMiniKeyboard != null) {
+ if (mMiniKeyboardView != null) {
paint.setColor((int) (mBackgroundDimAmount * 0xFF) << 24);
canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
}
@@ -1052,7 +1067,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
Key popupKey = tracker.getKey(keyIndex);
if (popupKey == null)
return false;
- boolean result = onLongPress(popupKey);
+ boolean result = onLongPress(popupKey, tracker);
if (result) {
dismissKeyPreview();
mMiniKeyboardTrackerId = tracker.mPointerId;
@@ -1077,14 +1092,13 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
}
private View inflateMiniKeyboardContainer(Key popupKey) {
- int popupKeyboardResId = mKeyboard.getPopupKeyboardResId();
- View container = LayoutInflater.from(getContext()).inflate(mPopupLayout, null);
+ final View container = LayoutInflater.from(getContext()).inflate(mPopupLayout, null);
if (container == null)
throw new NullPointerException();
- KeyboardView miniKeyboard =
+ final KeyboardView miniKeyboardView =
(KeyboardView)container.findViewById(R.id.KeyboardView);
- miniKeyboard.setOnKeyboardActionListener(new KeyboardActionListener() {
+ miniKeyboardView.setOnKeyboardActionListener(new KeyboardActionListener() {
@Override
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
mKeyboardActionListener.onCodeInput(primaryCode, keyCodes, x, y);
@@ -1117,14 +1131,14 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
}
});
// Override default ProximityKeyDetector.
- miniKeyboard.mKeyDetector = new MiniKeyboardKeyDetector(mMiniKeyboardSlideAllowance);
+ miniKeyboardView.mKeyDetector = new MiniKeyboardKeyDetector(mMiniKeyboardSlideAllowance);
// Remove gesture detector on mini-keyboard
- miniKeyboard.mGestureDetector = null;
+ miniKeyboardView.mGestureDetector = null;
- Keyboard keyboard = new MiniKeyboardBuilder(this, popupKeyboardResId, popupKey)
- .build();
- miniKeyboard.setKeyboard(keyboard);
- miniKeyboard.setPopupParent(this);
+ final Keyboard keyboard = new MiniKeyboardBuilder(this, mKeyboard.getPopupKeyboardResId(),
+ popupKey).build();
+ miniKeyboardView.setKeyboard(keyboard);
+ miniKeyboardView.mMiniKeyboardParent = this;
container.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.AT_MOST));
@@ -1152,7 +1166,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
* @return true if the long press is handled, false otherwise. Subclasses should call the
* method on the base class if the subclass doesn't wish to handle the call.
*/
- protected boolean onLongPress(Key popupKey) {
+ protected boolean onLongPress(Key popupKey, PointerTracker tracker) {
if (popupKey.mPopupCharacters == null)
return false;
@@ -1161,93 +1175,51 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
container = inflateMiniKeyboardContainer(popupKey);
mMiniKeyboardCache.put(popupKey, container);
}
- mMiniKeyboard = (KeyboardView)container.findViewById(R.id.KeyboardView);
+ mMiniKeyboardView = (KeyboardView)container.findViewById(R.id.KeyboardView);
+ final MiniKeyboard miniKeyboard = (MiniKeyboard)mMiniKeyboardView.getKeyboard();
+
if (mWindowOffset == null) {
mWindowOffset = new int[2];
getLocationInWindow(mWindowOffset);
}
-
- // Get width of a key in the mini popup keyboard = "miniKeyWidth".
- // On the other hand, "popupKey.width" is width of the pressed key on the main keyboard.
- // We adjust the position of mini popup keyboard with the edge key in it:
- // a) When we have the leftmost key in popup keyboard directly above the pressed key
- // Right edges of both keys should be aligned for consistent default selection
- // b) When we have the rightmost key in popup keyboard directly above the pressed key
- // Left edges of both keys should be aligned for consistent default selection
- final List<Key> miniKeys = mMiniKeyboard.getKeyboard().getKeys();
- final int miniKeyWidth = miniKeys.size() > 0 ? miniKeys.get(0).mWidth : 0;
-
- // HACK: Have the leftmost number in the popup characters right above the key
- boolean isNumberAtLeftmost =
- hasMultiplePopupChars(popupKey) && isNumberAtLeftmostPopupChar(popupKey);
- int popupX = popupKey.mX + mWindowOffset[0];
- popupX += getPaddingLeft();
- if (isNumberAtLeftmost) {
- popupX += popupKey.mWidth - miniKeyWidth; // adjustment for a) described above
- popupX -= container.getPaddingLeft();
- } else {
- popupX += miniKeyWidth; // adjustment for b) described above
- popupX -= container.getMeasuredWidth();
- popupX += container.getPaddingRight();
- }
- int popupY = popupKey.mY + mWindowOffset[1];
- popupY += getPaddingTop();
- popupY -= container.getMeasuredHeight();
- popupY += container.getPaddingBottom();
+ final int pointX = (mConfigShowMiniKeyboardAtTouchedPoint) ? tracker.getLastX()
+ : popupKey.mX + popupKey.mWidth / 2;
+ final int popupX = pointX - miniKeyboard.getDefaultCoordX()
+ - container.getPaddingLeft()
+ + getPaddingLeft() + mWindowOffset[0];
+ final int popupY = popupKey.mY - mKeyboard.getVerticalGap()
+ - (container.getMeasuredHeight() - container.getPaddingBottom())
+ + getPaddingTop() + mWindowOffset[1];
final int x = popupX;
- final int y = mShowPreview && isOneRowKeys(miniKeys) ? mPopupPreviewDisplayedY : popupY;
+ final int y = mShowPreview && isOneRowKeys(miniKeyboard.getKeys())
+ ? mPopupPreviewDisplayedY : popupY;
- int adjustedX = x;
- if (x < 0) {
- adjustedX = 0;
- } else if (x > (getMeasuredWidth() - container.getMeasuredWidth())) {
- adjustedX = getMeasuredWidth() - container.getMeasuredWidth();
- }
- mMiniKeyboardOriginX = adjustedX + container.getPaddingLeft() - mWindowOffset[0];
+ mMiniKeyboardOriginX = x + container.getPaddingLeft() - mWindowOffset[0];
mMiniKeyboardOriginY = y + container.getPaddingTop() - mWindowOffset[1];
- mMiniKeyboard.setPopupOffset(adjustedX, y);
- Keyboard baseMiniKeyboard = mMiniKeyboard.getKeyboard();
- if (baseMiniKeyboard != null && baseMiniKeyboard.setShifted(mKeyboard == null
- ? false : mKeyboard.isShiftedOrShiftLocked())) {
- mMiniKeyboard.invalidateAllKeys();
+ mMiniKeyboardView.setPopupOffset(x, y);
+ if (miniKeyboard.setShifted(
+ mKeyboard == null ? false : mKeyboard.isShiftedOrShiftLocked())) {
+ mMiniKeyboardView.invalidateAllKeys();
}
// Mini keyboard needs no pop-up key preview displayed.
- mMiniKeyboard.setPreviewEnabled(false);
+ mMiniKeyboardView.setPreviewEnabled(false);
mMiniKeyboardPopup.setContentView(container);
mMiniKeyboardPopup.setWidth(container.getMeasuredWidth());
mMiniKeyboardPopup.setHeight(container.getMeasuredHeight());
mMiniKeyboardPopup.showAtLocation(this, Gravity.NO_GRAVITY, x, y);
// Inject down event on the key to mini keyboard.
- long eventTime = SystemClock.uptimeMillis();
+ final long eventTime = SystemClock.uptimeMillis();
mMiniKeyboardPopupTime = eventTime;
- MotionEvent downEvent = generateMiniKeyboardMotionEvent(MotionEvent.ACTION_DOWN, popupKey.mX
- + popupKey.mWidth / 2, popupKey.mY + popupKey.mHeight / 2, eventTime);
- mMiniKeyboard.onTouchEvent(downEvent);
+ final MotionEvent downEvent = generateMiniKeyboardMotionEvent(MotionEvent.ACTION_DOWN,
+ pointX, popupKey.mY + popupKey.mHeight / 2, eventTime);
+ mMiniKeyboardView.onTouchEvent(downEvent);
downEvent.recycle();
invalidateAllKeys();
return true;
}
- private static boolean hasMultiplePopupChars(Key key) {
- if (key.mPopupCharacters != null && key.mPopupCharacters.length > 1) {
- return true;
- }
- return false;
- }
-
- private static boolean isNumberAtLeftmostPopupChar(Key key) {
- if (key.mPopupCharacters != null && isAsciiDigit(key.mPopupCharacters[0].charAt(0))) {
- return true;
- }
- return false;
- }
-
- private static boolean isAsciiDigit(char c) {
- return (c < 0x80) && Character.isDigit(c);
- }
-
private MotionEvent generateMiniKeyboardMotionEvent(int action, int x, int y, long eventTime) {
return MotionEvent.obtain(mMiniKeyboardPopupTime, eventTime, action,
x - mMiniKeyboardOriginX, y - mMiniKeyboardOriginY, 0);
@@ -1273,8 +1245,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
}
public boolean isInSlidingKeyInput() {
- if (mMiniKeyboard != null) {
- return mMiniKeyboard.isInSlidingKeyInput();
+ if (mMiniKeyboardView != null) {
+ return mMiniKeyboardView.isInSlidingKeyInput();
} else {
return mPointerQueue.isInSlidingKeyInput();
}
@@ -1302,7 +1274,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
mSwipeTracker.addMovement(me);
// Gesture detector must be enabled only when mini-keyboard is not on the screen.
- if (mMiniKeyboard == null
+ if (mMiniKeyboardView == null
&& mGestureDetector != null && mGestureDetector.onTouchEvent(me)) {
dismissKeyPreview();
mHandler.cancelKeyTimers();
@@ -1317,14 +1289,14 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
// Needs to be called after the gesture detector gets a turn, as it may have
// displayed the mini keyboard
- if (mMiniKeyboard != null) {
+ if (mMiniKeyboardView != null) {
final int miniKeyboardPointerIndex = me.findPointerIndex(mMiniKeyboardTrackerId);
if (miniKeyboardPointerIndex >= 0 && miniKeyboardPointerIndex < pointerCount) {
final int miniKeyboardX = (int)me.getX(miniKeyboardPointerIndex);
final int miniKeyboardY = (int)me.getY(miniKeyboardPointerIndex);
MotionEvent translated = generateMiniKeyboardMotionEvent(action,
miniKeyboardX, miniKeyboardY, eventTime);
- mMiniKeyboard.onTouchEvent(translated);
+ mMiniKeyboardView.onTouchEvent(translated);
translated.recycle();
}
return true;
@@ -1402,8 +1374,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
mHandler.cancelAllMessages();
dismissPopupKeyboard();
- mBuffer = null;
- mCanvas = null;
+ mDirtyRect.union(0, 0, getWidth(), getHeight());
mMiniKeyboardCache.clear();
requestLayout();
}
@@ -1422,7 +1393,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
private void dismissPopupKeyboard() {
if (mMiniKeyboardPopup.isShowing()) {
mMiniKeyboardPopup.dismiss();
- mMiniKeyboard = null;
+ mMiniKeyboardView = null;
mMiniKeyboardOriginX = 0;
mMiniKeyboardOriginY = 0;
invalidateAllKeys();
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
index 888375b93..ffb8d6410 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
@@ -45,18 +45,30 @@ public class LatinKeyboard extends Keyboard {
public static final int OPACITY_FULLY_OPAQUE = 255;
private static final int SPACE_LED_LENGTH_PERCENT = 80;
+ private final Context mContext;
+
+ /* Space key and its icons, drawables and colors. */
+ private final Key mSpaceKey;
+ private final Drawable mSpaceIcon;
+ private final Drawable mSpacePreviewIcon;
+ private final int[] mSpaceKeyIndexArray;
private final Drawable mSpaceAutoCorrectionIndicator;
private final Drawable mButtonArrowLeftIcon;
private final Drawable mButtonArrowRightIcon;
private final int mSpacebarTextColor;
private final int mSpacebarTextShadowColor;
+ private final int mSpacebarVerticalCorrection;
private float mSpacebarTextFadeFactor = 0.0f;
- private final int[] mSpaceKeyIndexArray;
private int mSpaceDragStartX;
private int mSpaceDragLastDiff;
- private final Context mContext;
private boolean mCurrentlyInSpace;
private SlidingLocaleDrawable mSlidingLocaleIcon;
+
+ /* Shortcut key and its icons if available */
+ private final Key mShortcutKey;
+ private final Drawable mEnabledShortcutIcon;
+ private final Drawable mDisabledShortcutIcon;
+
private int[] mPrefLetterFrequencies;
private int mPrefLetter;
private int mPrefLetterX;
@@ -74,8 +86,6 @@ public class LatinKeyboard extends Keyboard {
// its short language name will be used instead.
private static final float MINIMUM_SCALE_OF_LANGUAGE_NAME = 0.8f;
- private static int sSpacebarVerticalCorrection;
-
private static final String SMALL_TEXT_SIZE_OF_LANGUAGE_ON_SPACEBAR = "small";
private static final String MEDIUM_TEXT_SIZE_OF_LANGUAGE_ON_SPACEBAR = "medium";
@@ -83,21 +93,47 @@ public class LatinKeyboard extends Keyboard {
super(context, id.getXmlId(), id);
final Resources res = context.getResources();
mContext = context;
+
+ final List<Key> keys = getKeys();
+ int spaceKeyIndex = -1;
+ int shortcutKeyIndex = -1;
+ final int keyCount = keys.size();
+ for (int index = 0; index < keyCount; index++) {
+ // For now, assuming there are up to one space key and one shortcut key respectively.
+ switch (keys.get(index).mCode) {
+ case CODE_SPACE:
+ spaceKeyIndex = index;
+ break;
+ case CODE_VOICE:
+ shortcutKeyIndex = index;
+ break;
+ }
+ }
+
+ // The index of space key is available only after Keyboard constructor has finished.
+ mSpaceKey = (spaceKeyIndex >= 0) ? keys.get(spaceKeyIndex) : null;
+ mSpaceIcon = (mSpaceKey != null) ? mSpaceKey.getIcon() : null;
+ mSpacePreviewIcon = (mSpaceKey != null) ? mSpaceKey.getPreviewIcon() : null;
+ mSpaceKeyIndexArray = new int[] { spaceKeyIndex };
+
+ mShortcutKey = (shortcutKeyIndex >= 0) ? keys.get(shortcutKeyIndex) : null;
+ mEnabledShortcutIcon = (mShortcutKey != null) ? mShortcutKey.getIcon() : null;
+
mSpacebarTextColor = res.getColor(R.color.latinkeyboard_bar_language_text);
if (id.mColorScheme == KeyboardView.COLOR_SCHEME_BLACK) {
mSpacebarTextShadowColor = res.getColor(
R.color.latinkeyboard_bar_language_shadow_black);
+ mDisabledShortcutIcon = res.getDrawable(R.drawable.sym_bkeyboard_voice_off);
} else { // default color scheme is KeyboardView.COLOR_SCHEME_WHITE
mSpacebarTextShadowColor = res.getColor(
R.color.latinkeyboard_bar_language_shadow_white);
+ mDisabledShortcutIcon = res.getDrawable(R.drawable.sym_keyboard_voice_off_holo);
}
mSpaceAutoCorrectionIndicator = res.getDrawable(R.drawable.sym_keyboard_space_led);
mButtonArrowLeftIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_left);
mButtonArrowRightIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_right);
- sSpacebarVerticalCorrection = res.getDimensionPixelOffset(
+ mSpacebarVerticalCorrection = res.getDimensionPixelOffset(
R.dimen.spacebar_vertical_correction);
- // The index of space key is available only after Keyboard constructor has finished.
- mSpaceKeyIndexArray = new int[] { indexOf(CODE_SPACE) };
}
public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboardView view) {
@@ -113,6 +149,15 @@ public class LatinKeyboard extends Keyboard {
return newColor;
}
+ public void updateShortcutKey(boolean available, LatinKeyboardView view) {
+ if (mShortcutKey == null)
+ return;
+ mShortcutKey.mEnabled = available;
+ mShortcutKey.setIcon(available ? mEnabledShortcutIcon : mDisabledShortcutIcon);
+ if (view != null)
+ view.invalidateKey(mShortcutKey);
+ }
+
/**
* @return a key which should be invalidated.
*/
@@ -315,12 +360,8 @@ public class LatinKeyboard extends Keyboard {
int x = pointX;
int y = pointY;
final int code = key.mCode;
- if (code == CODE_SHIFT || code == CODE_DELETE) {
- y -= key.mHeight / 10;
- if (code == CODE_SHIFT) x += key.mWidth / 6;
- if (code == CODE_DELETE) x -= key.mWidth / 6;
- } else if (code == CODE_SPACE) {
- y += LatinKeyboard.sSpacebarVerticalCorrection;
+ if (code == CODE_SPACE) {
+ y += mSpacebarVerticalCorrection;
if (SubtypeSwitcher.getInstance().useSpacebarLanguageSwitcher()
&& SubtypeSwitcher.getInstance().getEnabledKeyboardLocaleCount() > 1) {
if (mCurrentlyInSpace) {
@@ -446,15 +487,6 @@ public class LatinKeyboard extends Keyboard {
}
}
- private int indexOf(int code) {
- List<Key> keys = getKeys();
- int count = keys.size();
- for (int i = 0; i < count; i++) {
- if (keys.get(i).mCode == code) return i;
- }
- return -1;
- }
-
private int getTextSizeFromTheme(int style, int defValue) {
TypedArray array = mContext.getTheme().obtainStyledAttributes(
style, new int[] { android.R.attr.textSize });
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
index e9d5580e8..af2fd5ce1 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -16,6 +16,7 @@
package com.android.inputmethod.keyboard;
+import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.voice.VoiceIMEConnector;
@@ -23,10 +24,13 @@ import android.content.Context;
import android.graphics.Canvas;
import android.text.TextUtils;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.MotionEvent;
// TODO: We should remove this class
public class LatinKeyboardView extends KeyboardView {
+ private static final String TAG = LatinKeyboardView.class.getSimpleName();
+ private static boolean DEBUG_MODE = LatinImeLogger.sDBG;
/** Whether we've started dropping move events because we found a big jump */
private boolean mDroppingEvents;
@@ -94,7 +98,7 @@ public class LatinKeyboardView extends KeyboardView {
}
@Override
- protected boolean onLongPress(Key key) {
+ protected boolean onLongPress(Key key, PointerTracker tracker) {
int primaryCode = key.mCode;
if (primaryCode == Keyboard.CODE_SETTINGS) {
return invokeOnKey(Keyboard.CODE_SETTINGS_LONGPRESS);
@@ -102,7 +106,7 @@ public class LatinKeyboardView extends KeyboardView {
// Long pressing on 0 in phone number keypad gives you a '+'.
return invokeOnKey('+');
} else {
- return super.onLongPress(key);
+ return super.onLongPress(key, tracker);
}
}
@@ -208,7 +212,11 @@ public class LatinKeyboardView extends KeyboardView {
if (keyboard == null) return true;
// If there was a sudden jump, return without processing the actual motion event.
- if (handleSuddenJump(me)) return true;
+ if (handleSuddenJump(me)) {
+ if (DEBUG_MODE)
+ Log.w(TAG, "onTouchEvent: ignore sudden jump " + me);
+ return true;
+ }
// Reset any bounding box controls in the keyboard
if (me.getAction() == MotionEvent.ACTION_DOWN) {
diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
new file mode 100644
index 000000000..3b1408ccf
--- /dev/null
+++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2011 Google Inc.
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+
+package com.android.inputmethod.keyboard;
+
+import android.content.Context;
+
+public class MiniKeyboard extends Keyboard {
+ private int mDefaultKeyCoordX;
+
+ public MiniKeyboard(Context context, int xmlLayoutResId, KeyboardId id) {
+ super(context, xmlLayoutResId, id);
+ }
+
+ public void setDefaultCoordX(int pos) {
+ mDefaultKeyCoordX = pos;
+ }
+
+ public int getDefaultCoordX() {
+ return mDefaultKeyCoordX;
+ }
+}
diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java
index c150baadb..53dab9440 100644
--- a/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java
@@ -27,44 +27,141 @@ import java.util.List;
public class MiniKeyboardBuilder {
private final Resources mRes;
- private final Keyboard mKeyboard;
+ private final MiniKeyboard mKeyboard;
private final CharSequence[] mPopupCharacters;
- private final int mMiniKeyboardKeyHorizontalPadding;
- private final int mKeyWidth;
- private final int mMaxColumns;
- private final int mNumRows;
- private int mColPos;
- private int mRowPos;
- private int mX;
- private int mY;
+ private final MiniKeyboardLayoutParams mParams;
+
+ /* package */ static class MiniKeyboardLayoutParams {
+ public final int mKeyWidth;
+ public final int mRowHeight;
+ /* package */ final boolean mTopRowNeedsCentering;
+ public final int mNumRows;
+ public final int mNumColumns;
+ public final int mLeftKeys;
+ public final int mRightKeys; // includes default key.
+
+ /**
+ * The object holding mini keyboard layout parameters.
+ *
+ * @param numKeys number of keys in this mini keyboard.
+ * @param maxColumns number of maximum columns of this mini keyboard.
+ * @param keyWidth mini keyboard key width in pixel, including horizontal gap.
+ * @param rowHeight mini keyboard row height in pixel, including vertical gap.
+ * @param coordXInParent coordinate x of the popup key in parent keyboard.
+ * @param parentKeyboardWidth parent keyboard width in pixel.
+ */
+ public MiniKeyboardLayoutParams(int numKeys, int maxColumns, int keyWidth, int rowHeight,
+ int coordXInParent, int parentKeyboardWidth) {
+ if (parentKeyboardWidth / keyWidth < maxColumns)
+ throw new IllegalArgumentException("Keyboard is too small to hold mini keyboard: "
+ + parentKeyboardWidth + " " + keyWidth + " " + maxColumns);
+ final int numRows = (numKeys + maxColumns - 1) / maxColumns;
+ mKeyWidth = keyWidth;
+ mRowHeight = rowHeight;
+ mNumRows = numRows;
+
+ final int numColumns = Math.min(numKeys, maxColumns);
+ final int topRowKeys = numKeys % numColumns;
+ mNumColumns = numColumns;
+ mTopRowNeedsCentering = topRowKeys != 0 && (numColumns - topRowKeys) % 2 != 0;
+
+ final int numLeftKeys = (numColumns - 1) / 2;
+ final int numRightKeys = numColumns - numLeftKeys; // including default key.
+ final int maxLeftKeys = coordXInParent / keyWidth;
+ final int maxRightKeys = Math.max(1, (parentKeyboardWidth - coordXInParent) / keyWidth);
+ if (numLeftKeys > maxLeftKeys) {
+ mLeftKeys = maxLeftKeys;
+ mRightKeys = numColumns - maxLeftKeys;
+ } else if (numRightKeys > maxRightKeys) {
+ mLeftKeys = numColumns - maxRightKeys;
+ mRightKeys = maxRightKeys;
+ } else {
+ mLeftKeys = numLeftKeys;
+ mRightKeys = numRightKeys;
+ }
+ }
+
+ // Return key position according to column count (0 is default).
+ /* package */ int getColumnPos(int n) {
+ final int col = n % mNumColumns;
+ if (col == 0) {
+ // default position.
+ return 0;
+ }
+ int pos = 0;
+ int right = 1; // include default position key.
+ int left = 0;
+ int i = 0;
+ while (true) {
+ // Assign right key if available.
+ if (right < mRightKeys) {
+ pos = right;
+ right++;
+ i++;
+ }
+ if (i >= col)
+ break;
+ // Assign left key if available.
+ if (left < mLeftKeys) {
+ left++;
+ pos = -left;
+ i++;
+ }
+ if (i >= col)
+ break;
+ }
+ return pos;
+ }
+
+ public int getDefaultKeyCoordX() {
+ return mLeftKeys * mKeyWidth;
+ }
+
+ public int getX(int n, int row) {
+ final int x = getColumnPos(n) * mKeyWidth + getDefaultKeyCoordX();
+ if (isLastRow(row) && mTopRowNeedsCentering)
+ return x - mKeyWidth / 2;
+ return x;
+ }
+
+ public int getY(int row) {
+ return (mNumRows - 1 - row) * mRowHeight;
+ }
+
+ public int getRowFlags(int row) {
+ int rowFlags = 0;
+ if (row == 0) rowFlags |= Keyboard.EDGE_TOP;
+ if (isLastRow(row)) rowFlags |= Keyboard.EDGE_BOTTOM;
+ return rowFlags;
+ }
+
+ private boolean isLastRow(int rowCount) {
+ return rowCount == mNumRows - 1;
+ }
+ }
public MiniKeyboardBuilder(KeyboardView view, int layoutTemplateResId, Key popupKey) {
final Context context = view.getContext();
mRes = context.getResources();
- final Keyboard keyboard = new Keyboard(context, layoutTemplateResId, null);
+ final MiniKeyboard keyboard = new MiniKeyboard(context, layoutTemplateResId, null);
mKeyboard = keyboard;
mPopupCharacters = popupKey.mPopupCharacters;
- mMiniKeyboardKeyHorizontalPadding = (int)mRes.getDimension(
- R.dimen.mini_keyboard_key_horizontal_padding);
- mKeyWidth = getMaxKeyWidth(view, mPopupCharacters, mKeyboard.getKeyWidth());
- final int maxColumns = popupKey.mMaxPopupColumn;
- mMaxColumns = maxColumns;
- final int numKeys = mPopupCharacters.length;
- int numRows = numKeys / maxColumns;
- if (numKeys % maxColumns != 0) numRows++;
- mNumRows = numRows;
- keyboard.setHeight((keyboard.getRowHeight() + keyboard.getVerticalGap()) * numRows
- - keyboard.getVerticalGap());
- if (numRows > 1) {
- mColPos = numKeys % maxColumns;
- if (mColPos > 0) mColPos = maxColumns - mColPos;
- // Centering top-row keys.
- mX = mColPos * (mKeyWidth + keyboard.getHorizontalGap()) / 2;
- }
- mKeyboard.setMinWidth(0);
+
+ final int keyWidth = getMaxKeyWidth(view, mPopupCharacters, keyboard.getKeyWidth());
+ final MiniKeyboardLayoutParams params = new MiniKeyboardLayoutParams(
+ mPopupCharacters.length, popupKey.mMaxPopupColumn,
+ keyWidth, keyboard.getRowHeight(),
+ popupKey.mX + (popupKey.mWidth + popupKey.mGap) / 2 - keyWidth / 2,
+ view.getMeasuredWidth());
+ mParams = params;
+
+ keyboard.setHeight(params.mNumRows * params.mRowHeight - keyboard.getVerticalGap());
+ keyboard.setMinWidth(params.mNumColumns * params.mKeyWidth);
+ keyboard.setDefaultCoordX(params.getDefaultKeyCoordX() + params.mKeyWidth / 2);
}
- private int getMaxKeyWidth(KeyboardView view, CharSequence[] popupCharacters, int minKeyWidth) {
+ private static int getMaxKeyWidth(KeyboardView view, CharSequence[] popupCharacters,
+ int minKeyWidth) {
Paint paint = null;
Rect bounds = null;
int maxWidth = 0;
@@ -84,46 +181,22 @@ public class MiniKeyboardBuilder {
maxWidth = bounds.width();
}
}
- return Math.max(minKeyWidth, maxWidth + mMiniKeyboardKeyHorizontalPadding);
+ final int horizontalPadding = (int)view.getContext().getResources().getDimension(
+ R.dimen.mini_keyboard_key_horizontal_padding);
+ return Math.max(minKeyWidth, maxWidth + horizontalPadding);
}
- public Keyboard build() {
- final Keyboard keyboard = mKeyboard;
+ public MiniKeyboard build() {
+ final MiniKeyboard keyboard = mKeyboard;
final List<Key> keys = keyboard.getKeys();
- for (CharSequence label : mPopupCharacters) {
- refresh();
- final Key key = new Key(mRes, keyboard, label, mX, mY, mKeyWidth, getRowFlags());
+ final MiniKeyboardLayoutParams params = mParams;
+ for (int n = 0; n < mPopupCharacters.length; n++) {
+ final CharSequence label = mPopupCharacters[n];
+ final int row = n / params.mNumColumns;
+ final Key key = new Key(mRes, keyboard, label, params.getX(n, row), params.getY(row),
+ params.mKeyWidth, params.getRowFlags(row));
keys.add(key);
- advance();
}
return keyboard;
}
-
- private int getRowFlags() {
- final int rowPos = mRowPos;
- int rowFlags = 0;
- if (rowPos == 0) rowFlags |= Keyboard.EDGE_TOP;
- if (rowPos == mNumRows - 1) rowFlags |= Keyboard.EDGE_BOTTOM;
- return rowFlags;
- }
-
- private void refresh() {
- if (mColPos >= mMaxColumns) {
- final Keyboard keyboard = mKeyboard;
- // TODO: Allocate key position depending the precedence of popup characters.
- mX = 0;
- mY += keyboard.getRowHeight() + keyboard.getVerticalGap();
- mColPos = 0;
- mRowPos++;
- }
- }
-
- private void advance() {
- final Keyboard keyboard = mKeyboard;
- // TODO: Allocate key position depending the precedence of popup characters.
- mX += mKeyWidth + keyboard.getHorizontalGap();
- if (mX > keyboard.getMinWidth())
- keyboard.setMinWidth(mX);
- mColPos++;
- }
}
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 49f29f923..a981f724f 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -17,6 +17,7 @@
package com.android.inputmethod.keyboard;
import com.android.inputmethod.keyboard.KeyboardView.UIHandler;
+import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import android.content.res.Resources;
@@ -31,6 +32,7 @@ public class PointerTracker {
private static final boolean DEBUG_EVENT = false;
private static final boolean DEBUG_MOVE_EVENT = false;
private static final boolean DEBUG_LISTENER = false;
+ private static boolean DEBUG_MODE = LatinImeLogger.sDBG;
public interface UIProxy {
public void invalidateKey(Key key);
@@ -62,6 +64,7 @@ public class PointerTracker {
private Keyboard mKeyboard;
private Key[] mKeys;
private int mKeyHysteresisDistanceSquared = -1;
+ private int mKeyQuarterWidthSquared;
private final PointerTrackerKeyState mKeyState;
@@ -166,6 +169,8 @@ public class PointerTracker {
mKeyboard = keyboard;
mKeys = keys;
mKeyHysteresisDistanceSquared = (int)(keyHysteresisDistance * keyHysteresisDistance);
+ final int keyQuarterWidth = keyboard.getKeyWidth() / 4;
+ mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth;
// Mark that keyboard layout has been changed.
mKeyboardLayoutHasBeenChanged = true;
}
@@ -268,10 +273,6 @@ public class PointerTracker {
if (DEBUG_EVENT)
printTouchEvent("onDownEvent:", x, y, eventTime);
- // TODO: up-to-down filter, if (down-up) is less than threshold, removeMessage(UP, this) in
- // Handler, and just ignore this down event.
- // TODO: down-to-up filter, just record down time. do not enqueue pointer now.
-
// Naive up-to-down noise filter.
final long deltaT = eventTime - mKeyState.getUpTime();
if (deltaT < mTouchNoiseThresholdMillis) {
@@ -279,8 +280,9 @@ public class PointerTracker {
final int dy = y - mKeyState.getLastY();
final int distanceSquared = (dx * dx + dy * dy);
if (distanceSquared < mTouchNoiseThresholdDistanceSquared) {
- Log.w(TAG, "onDownEvent: ignore potential noise: time=" + deltaT
- + " distance=" + distanceSquared);
+ if (DEBUG_MODE)
+ Log.w(TAG, "onDownEvent: ignore potential noise: time=" + deltaT
+ + " distance=" + distanceSquared);
setAlreadyProcessed();
return;
}
@@ -333,9 +335,8 @@ public class PointerTracker {
return;
final PointerTrackerKeyState keyState = mKeyState;
- // TODO: down-to-up filter, if (eventTime-downTime) is less than threshold, just ignore
- // this move event. Otherwise fire {@link onDownEventInternal} and continue.
-
+ final int lastX = keyState.getLastX();
+ final int lastY = keyState.getLastY();
int keyIndex = keyState.onMoveKey(x, y);
final Key oldKey = getKey(keyState.getKeyIndex());
if (isValidKeyIndex(keyIndex)) {
@@ -365,8 +366,22 @@ public class PointerTracker {
keyState.onMoveToNewKey(keyIndex, x, y);
startLongPressTimer(keyIndex);
} else {
- setAlreadyProcessed();
- showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY);
+ // HACK: On some devices, quick successive touches may be translated to sudden
+ // move by touch panel firmware. This hack detects the case and translates the
+ // move event to successive up and down events.
+ final int dx = x - lastX;
+ final int dy = y - lastY;
+ final int lastMoveSquared = dx * dx + dy * dy;
+ if (lastMoveSquared >= mKeyQuarterWidthSquared) {
+ if (DEBUG_MODE)
+ Log.w(TAG, String.format("onMoveEvent: sudden move is translated to "
+ + "up[%d,%d]/down[%d,%d] events", lastX, lastY, x, y));
+ onUpEventInternal(lastX, lastY, eventTime);
+ onDownEventInternal(x, y, eventTime);
+ } else {
+ setAlreadyProcessed();
+ showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY);
+ }
return;
}
}
@@ -389,17 +404,11 @@ public class PointerTracker {
showKeyPreviewAndUpdateKeyGraphics(mKeyState.getKeyIndex());
}
- // TODO: up-to-down filter, if delayed UP message is fired, invoke {@link onUpEventInternal}.
-
public void onUpEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
if (ENABLE_ASSERTION) checkAssertion(queue);
if (DEBUG_EVENT)
printTouchEvent("onUpEvent :", x, y, eventTime);
- // TODO: up-to-down filter, just sendDelayedMessage(UP, this) to Handler.
- // TODO: down-to-up filter, if (eventTime-downTime) is less than threshold, just ignore
- // this up event. Otherwise fire {@link onDownEventInternal} and {@link onUpEventInternal}.
-
if (queue != null) {
if (isModifier()) {
// Before processing an up event of modifier key, all pointers already being
@@ -561,7 +570,8 @@ public class PointerTracker {
codes[1] = codes[0];
codes[0] = code;
}
- callListenerOnCodeInput(code, codes, x, y);
+ if (key.mEnabled)
+ callListenerOnCodeInput(code, codes, x, y);
callListenerOnRelease(code);
}
}
diff --git a/java/src/com/android/inputmethod/latin/ClipTouchEventWindowCallback.java b/java/src/com/android/inputmethod/latin/ClipTouchEventWindowCallback.java
deleted file mode 100644
index d12c70075..000000000
--- a/java/src/com/android/inputmethod/latin/ClipTouchEventWindowCallback.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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.
- */
-
-package com.android.inputmethod.latin;
-
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.Window;
-
-public class ClipTouchEventWindowCallback extends WindowCallbackAdapter {
- private final View mDecorView;
- private final int mKeyboardBottomRowVerticalCorrection;
-
- public ClipTouchEventWindowCallback(Window window, int keyboardBottomRowVerticalCorrection) {
- super(window.getCallback());
- mDecorView = window.getDecorView();
- mKeyboardBottomRowVerticalCorrection = keyboardBottomRowVerticalCorrection;
- }
-
- @Override
- public boolean dispatchTouchEvent(MotionEvent me) {
- final int height = mDecorView.getHeight();
- final MotionEvent event = clipMotionEvent(me, height,
- height + mKeyboardBottomRowVerticalCorrection);
- return super.dispatchTouchEvent(event);
- }
-
- private static MotionEvent clipMotionEvent(MotionEvent me, int minHeight, int maxHeight) {
- final int pointerCount = me.getPointerCount();
- boolean shouldClip = false;
- for (int pointerIndex = 0; pointerIndex < pointerCount; pointerIndex++) {
- final float y = me.getY(pointerIndex);
- if (y >= minHeight && y < maxHeight) {
- shouldClip = true;
- break;
- }
- }
- if (!shouldClip)
- return me;
-
- if (pointerCount == 1) {
- me.setLocation(me.getX(), minHeight - 1);
- return me;
- }
-
- final int[] pointerIds = new int[pointerCount];
- final MotionEvent.PointerCoords[] pointerCoords =
- new MotionEvent.PointerCoords[pointerCount];
- for (int pointerIndex = 0; pointerIndex < pointerCount; pointerIndex++) {
- pointerIds[pointerIndex] = me.getPointerId(pointerIndex);
- final MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords();
- me.getPointerCoords(pointerIndex, coords);
- pointerCoords[pointerIndex] = coords;
- if (coords.y >= minHeight && coords.y < maxHeight)
- coords.y = minHeight - 1;
- }
- return MotionEvent.obtain(
- me.getDownTime(), me.getEventTime(), me.getAction(), pointerCount, pointerIds,
- pointerCoords, me.getMetaState(), me.getXPrecision(), me.getYPrecision(),
- me.getDeviceId(), me.getEdgeFlags(), me.getSource(), me.getFlags());
- }
-}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 198d34f4a..8166e0b4e 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -37,6 +37,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.inputmethodservice.InputMethodService;
import android.media.AudioManager;
+import android.net.ConnectivityManager;
import android.os.Debug;
import android.os.Handler;
import android.os.Message;
@@ -97,10 +98,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Key events coming any faster than this are long-presses.
private static final int QUICK_PRESS = 200;
- // Contextual menu positions
- private static final int POS_METHOD = 0;
- private static final int POS_SETTINGS = 1;
-
private int mSuggestionVisibility;
private static final int SUGGESTION_VISIBILILTY_SHOW_VALUE
= R.string.prefs_suggestion_visibility_show_value;
@@ -161,8 +158,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private int mConfigDelayBeforeFadeoutLanguageOnSpacebar;
private int mConfigDurationOfFadeoutLanguageOnSpacebar;
private float mConfigFinalFadeoutFactorOfLanguageOnSpacebar;
- // For example, to deal with status bar on tablet.
- private int mKeyboardBottomRowVerticalCorrection;
private int mCorrectionMode;
private int mCommittedLength;
@@ -379,8 +374,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
R.integer.config_duration_of_fadeout_language_on_spacebar);
mConfigFinalFadeoutFactorOfLanguageOnSpacebar = res.getInteger(
R.integer.config_final_fadeout_percentage_of_language_on_spacebar) / 100.0f;
- mKeyboardBottomRowVerticalCorrection = (int)res.getDimension(
- R.dimen.keyboard_bottom_row_vertical_correction);
Utils.GCUtils.getInstance().reset();
boolean tryGC = true;
@@ -396,8 +389,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mOrientation = res.getConfiguration().orientation;
initSuggestPuncList();
- // register to receive ringer mode changes for silent mode
- IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
+ // register to receive ringer mode change and network state change.
+ final IntentFilter filter = new IntentFilter();
+ filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
+ filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(mReceiver, filter);
mVoiceConnector = VoiceIMEConnector.init(this, prefs, mHandler);
prefs.registerOnSharedPreferenceChangeListener(this);
@@ -573,14 +568,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mVoiceConnector.onStartInputView(inputView.getWindowToken());
- if (mKeyboardBottomRowVerticalCorrection > 0) {
- final Window window = getWindow().getWindow();
- if (!(window.getCallback() instanceof ClipTouchEventWindowCallback)) {
- window.setCallback(new ClipTouchEventWindowCallback(
- window, mKeyboardBottomRowVerticalCorrection));
- }
- }
-
if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
}
@@ -895,13 +882,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (mCandidateViewContainer != null) {
ViewParent candidateParent = mCandidateViewContainer.getParent();
if (candidateParent instanceof FrameLayout) {
- final FrameLayout fl = (FrameLayout) candidateParent;
- // Check frame layout's visibility
- if (fl.getVisibility() == View.INVISIBLE) {
- y = fl.getHeight();
- height += y;
- } else if (fl.getVisibility() == View.VISIBLE) {
- height += fl.getHeight();
+ FrameLayout fl = (FrameLayout) candidateParent;
+ if (fl != null) {
+ // Check frame layout's visibility
+ if (fl.getVisibility() == View.INVISIBLE) {
+ y = fl.getHeight();
+ height += y;
+ } else if (fl.getVisibility() == View.VISIBLE) {
+ height += fl.getHeight();
+ }
}
}
}
@@ -1466,6 +1455,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
private boolean isCandidateStripVisible() {
+ if (mCandidateView == null)
+ return false;
if (mCandidateView.isShowingAddToDictionaryHint() || TextEntryState.isCorrecting())
return true;
if (!isShowingSuggestionsStrip())
@@ -1589,7 +1580,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) {
setSuggestions(suggestedWords);
if (suggestedWords.size() > 0) {
- if (Utils.shouldBlockedBySafetyNetForAutoCorrection(suggestedWords)) {
+ if (Utils.shouldBlockedBySafetyNetForAutoCorrection(suggestedWords, mSuggest)) {
mBestWord = typedWord;
} else if (suggestedWords.hasAutoCorrectionWord()) {
mBestWord = suggestedWords.getWord(1);
@@ -2000,11 +1991,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
- // receive ringer mode changes to detect silent mode
+ // receive ringer mode change and network state change.
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- updateRingerMode();
+ final String action = intent.getAction();
+ if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
+ updateRingerMode();
+ } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
+ mSubtypeSwitcher.onNetworkStateChanged(intent);
+ }
}
};
@@ -2226,15 +2222,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
private void showSubtypeSelectorAndSettings() {
- showOptionsMenuInternal(new DialogInterface.OnClickListener() {
+ final CharSequence title = getString(R.string.english_ime_input_options);
+ final CharSequence[] items = new CharSequence[] {
+ // TODO: Should use new string "Select active input modes".
+ getString(R.string.language_selection_title),
+ getString(R.string.english_ime_settings),
+ };
+ final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface di, int position) {
di.dismiss();
switch (position) {
- case POS_SETTINGS:
- launchSettings();
- break;
- case POS_METHOD:
+ case 0:
Intent intent = new Intent(
android.provider.Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
@@ -2244,38 +2243,46 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mInputMethodId);
startActivity(intent);
break;
+ case 1:
+ launchSettings();
+ break;
}
}
- });
+ };
+ showOptionsMenuInternal(title, items, listener);
}
private void showOptionsMenu() {
- showOptionsMenuInternal(new DialogInterface.OnClickListener() {
+ final CharSequence title = getString(R.string.english_ime_input_options);
+ final CharSequence[] items = new CharSequence[] {
+ getString(R.string.selectInputMethod),
+ getString(R.string.english_ime_settings),
+ };
+ final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface di, int position) {
di.dismiss();
switch (position) {
- case POS_SETTINGS:
+ case 0:
launchSettings();
break;
- case POS_METHOD:
+ case 1:
mImm.showInputMethodPicker();
break;
}
}
- });
+ };
+ showOptionsMenuInternal(title, items, listener);
}
- private void showOptionsMenuInternal(DialogInterface.OnClickListener listener) {
+ private void showOptionsMenuInternal(CharSequence title, CharSequence[] items,
+ DialogInterface.OnClickListener listener) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setIcon(R.drawable.ic_dialog_keyboard);
builder.setNegativeButton(android.R.string.cancel, null);
- CharSequence itemSettings = getString(R.string.english_ime_settings);
- CharSequence itemInputMethod = getString(R.string.selectInputMethod);
- builder.setItems(new CharSequence[] {
- itemInputMethod, itemSettings}, listener);
- builder.setTitle(mResources.getString(R.string.english_ime_input_options));
+ builder.setItems(items, listener);
+ builder.setTitle(title);
mOptionsDialog = builder.create();
mOptionsDialog.setCanceledOnTouchOutside(true);
Window window = mOptionsDialog.getWindow();
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index 653dbeaba..12338ce61 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -75,6 +75,7 @@ public class Settings extends PreferenceActivity
private CheckBoxPreference mQuickFixes;
private ListPreference mVoicePreference;
private ListPreference mSettingsKeyPreference;
+ private ListPreference mShowCorrectionSuggestionsPreference;
private ListPreference mAutoCorrectionThreshold;
private CheckBoxPreference mBigramSuggestion;
private boolean mVoiceOn;
@@ -102,6 +103,8 @@ public class Settings extends PreferenceActivity
mQuickFixes = (CheckBoxPreference) findPreference(PREF_QUICK_FIXES);
mVoicePreference = (ListPreference) findPreference(PREF_VOICE_SETTINGS_KEY);
mSettingsKeyPreference = (ListPreference) findPreference(PREF_SETTINGS_KEY);
+ mShowCorrectionSuggestionsPreference =
+ (ListPreference) findPreference(PREF_SHOW_SUGGESTIONS_SETTING);
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
prefs.registerOnSharedPreferenceChangeListener(this);
@@ -188,6 +191,7 @@ public class Settings extends PreferenceActivity
updateVoiceModeSummary();
}
updateSettingsKeySummary();
+ updateShowCorrectionSuggestionsSummary();
}
@Override
@@ -212,6 +216,7 @@ public class Settings extends PreferenceActivity
.equals(mVoiceModeOff));
updateVoiceModeSummary();
updateSettingsKeySummary();
+ updateShowCorrectionSuggestionsSummary();
}
@Override
@@ -230,6 +235,13 @@ public class Settings extends PreferenceActivity
return false;
}
+ private void updateShowCorrectionSuggestionsSummary() {
+ mShowCorrectionSuggestionsPreference.setSummary(
+ getResources().getStringArray(R.array.prefs_suggestion_visibilities)
+ [mShowCorrectionSuggestionsPreference.findIndexOfValue(
+ mShowCorrectionSuggestionsPreference.getValue())]);
+ }
+
private void updateSettingsKeySummary() {
mSettingsKeyPreference.setSummary(
getResources().getStringArray(R.array.settings_key_modes)
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index 7a1ac2e27..f4262cc99 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -17,16 +17,21 @@
package com.android.inputmethod.latin;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
+import com.android.inputmethod.keyboard.LatinKeyboard;
+import com.android.inputmethod.keyboard.LatinKeyboardView;
import com.android.inputmethod.voice.SettingsUtil;
import com.android.inputmethod.voice.VoiceIMEConnector;
import com.android.inputmethod.voice.VoiceInput;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
@@ -47,6 +52,8 @@ public class SubtypeSwitcher {
private static final char LOCALE_SEPARATER = '_';
private static final String KEYBOARD_MODE = "keyboard";
private static final String VOICE_MODE = "voice";
+ private static final String SUBTYPE_EXTRAVALUE_REQUIRE_NETWORK_CONNECTIVITY =
+ "requireNetworkConnectivity";
private final TextUtils.SimpleStringSplitter mLocaleSplitter =
new TextUtils.SimpleStringSplitter(LOCALE_SEPARATER);
@@ -55,17 +62,17 @@ public class SubtypeSwitcher {
private /* final */ SharedPreferences mPrefs;
private /* final */ InputMethodManager mImm;
private /* final */ Resources mResources;
+ private /* final */ ConnectivityManager mConnectivityManager;
+ private /* final */ boolean mConfigUseSpacebarLanguageSwitcher;
private final ArrayList<InputMethodSubtype> mEnabledKeyboardSubtypesOfCurrentInputMethod =
new ArrayList<InputMethodSubtype>();
private final ArrayList<String> mEnabledLanguagesOfCurrentInputMethod = new ArrayList<String>();
- private boolean mConfigUseSpacebarLanguageSwitcher;
-
/*-----------------------------------------------------------*/
// Variants which should be changed only by reload functions.
private boolean mNeedsToDisplayLanguage;
private boolean mIsSystemLanguageSameAsInputLanguage;
- private InputMethodInfo mShortcutInfo;
+ private InputMethodInfo mShortcutInputMethodInfo;
private InputMethodSubtype mShortcutSubtype;
private List<InputMethodSubtype> mAllEnabledSubtypesOfCurrentInputMethod;
private Locale mSystemLocale;
@@ -75,13 +82,14 @@ public class SubtypeSwitcher {
private VoiceInput mVoiceInput;
/*-----------------------------------------------------------*/
+ private boolean mIsNetworkConnected;
+
public static SubtypeSwitcher getInstance() {
return sInstance;
}
public static void init(LatinIME service, SharedPreferences prefs) {
- sInstance.mPrefs = prefs;
- sInstance.resetParams(service);
+ sInstance.initialize(service, prefs);
sInstance.updateAllParameters();
SubtypeLocale.init(service);
@@ -91,10 +99,13 @@ public class SubtypeSwitcher {
// Intentional empty constructor for singleton.
}
- private void resetParams(LatinIME service) {
+ private void initialize(LatinIME service, SharedPreferences prefs) {
mService = service;
+ mPrefs = prefs;
mResources = service.getResources();
mImm = (InputMethodManager) service.getSystemService(Context.INPUT_METHOD_SERVICE);
+ mConnectivityManager = (ConnectivityManager) service.getSystemService(
+ Context.CONNECTIVITY_SERVICE);
mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
mEnabledLanguagesOfCurrentInputMethod.clear();
mSystemLocale = null;
@@ -109,6 +120,9 @@ public class SubtypeSwitcher {
R.bool.config_use_spacebar_language_switcher);
if (mConfigUseSpacebarLanguageSwitcher)
initLanguageSwitcher(service);
+
+ final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
+ mIsNetworkConnected = (info != null && info.isConnected());
}
// Update all parameters stored in SubtypeSwitcher.
@@ -165,7 +179,8 @@ public class SubtypeSwitcher {
private void updateShortcutIME() {
if (DBG) {
Log.d(TAG, "Update shortcut IME from : "
- + (mShortcutInfo == null ? "<null>" : mShortcutInfo.getId()) + ", "
+ + (mShortcutInputMethodInfo == null
+ ? "<null>" : mShortcutInputMethodInfo.getId()) + ", "
+ (mShortcutSubtype == null ? "<null>" : (mShortcutSubtype.getLocale()
+ ", " + mShortcutSubtype.getMode())));
}
@@ -176,7 +191,7 @@ public class SubtypeSwitcher {
List<InputMethodSubtype> subtypes = shortcuts.get(imi);
// TODO: Returns the first found IMI for now. Should handle all shortcuts as
// appropriate.
- mShortcutInfo = imi;
+ mShortcutInputMethodInfo = imi;
// TODO: Pick up the first found subtype for now. Should handle all subtypes
// as appropriate.
mShortcutSubtype = subtypes.size() > 0 ? subtypes.get(0) : null;
@@ -184,7 +199,8 @@ public class SubtypeSwitcher {
}
if (DBG) {
Log.d(TAG, "Update shortcut IME to : "
- + (mShortcutInfo == null ? "<null>" : mShortcutInfo.getId()) + ", "
+ + (mShortcutInputMethodInfo == null
+ ? "<null>" : mShortcutInputMethodInfo.getId()) + ", "
+ (mShortcutSubtype == null ? "<null>" : (mShortcutSubtype.getLocale()
+ ", " + mShortcutSubtype.getMode())));
}
@@ -288,15 +304,22 @@ public class SubtypeSwitcher {
////////////////////////////
public void switchToShortcutIME() {
- IBinder token = mService.getWindow().getWindow().getAttributes().token;
- if (token == null || mShortcutInfo == null) {
+ final IBinder token = mService.getWindow().getWindow().getAttributes().token;
+ if (token == null || mShortcutInputMethodInfo == null) {
return;
}
- mImm.setInputMethodAndSubtype(token, mShortcutInfo.getId(), mShortcutSubtype);
+ final String imiId = mShortcutInputMethodInfo.getId();
+ final InputMethodSubtype subtype = mShortcutSubtype;
+ new Thread("SwitchToShortcutIME") {
+ @Override
+ public void run() {
+ mImm.setInputMethodAndSubtype(token, imiId, subtype);
+ }
+ }.start();
}
public Drawable getShortcutIcon() {
- return getSubtypeIcon(mShortcutInfo, mShortcutSubtype);
+ return getSubtypeIcon(mShortcutInputMethodInfo, mShortcutSubtype);
}
private Drawable getSubtypeIcon(InputMethodInfo imi, InputMethodSubtype subtype) {
@@ -325,6 +348,38 @@ public class SubtypeSwitcher {
return null;
}
+ private static boolean contains(String[] hay, String needle) {
+ for (String element : hay) {
+ if (element.equals(needle))
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isShortcutAvailable() {
+ if (mShortcutInputMethodInfo == null)
+ return false;
+ if (mShortcutSubtype != null && contains(mShortcutSubtype.getExtraValue().split(","),
+ SUBTYPE_EXTRAVALUE_REQUIRE_NETWORK_CONNECTIVITY)) {
+ return mIsNetworkConnected;
+ }
+ return true;
+ }
+
+ public void onNetworkStateChanged(Intent intent) {
+ final boolean noConnection = intent.getBooleanExtra(
+ ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
+ mIsNetworkConnected = !noConnection;
+
+ final LatinKeyboardView inputView = KeyboardSwitcher.getInstance().getInputView();
+ if (inputView != null) {
+ final LatinKeyboard keyboard = inputView.getLatinKeyboard();
+ if (keyboard != null) {
+ keyboard.updateShortcutKey(isShortcutAvailable(), inputView);
+ }
+ }
+ }
+
//////////////////////////////////
// Language Switching functions //
//////////////////////////////////
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 1772b2669..ced355bb2 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -163,6 +163,10 @@ public class Suggest implements Dictionary.WordCallback {
mAutoCorrectionThreshold = threshold;
}
+ public boolean isAggressiveAutoCorrectionMode() {
+ return (mAutoCorrectionThreshold == 0);
+ }
+
/**
* Number of suggestions to generate from the input key sequence. This has
* to be a number between 1 and 100 (inclusive).
@@ -290,7 +294,7 @@ public class Suggest implements Dictionary.WordCallback {
typedWord, mSuggestions.get(0), mPriorities[0]);
if (LatinImeLogger.sDBG) {
Log.d(TAG, "Normalized " + typedWord + "," + mSuggestions.get(0) + ","
- + mPriorities[0] + normalizedScore
+ + mPriorities[0] + ", " + normalizedScore
+ "(" + mAutoCorrectionThreshold + ")");
}
if (normalizedScore >= mAutoCorrectionThreshold) {
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index 5059860d7..e980d3a30 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -38,6 +38,7 @@ import java.util.Date;
public class Utils {
private static final String TAG = Utils.class.getSimpleName();
+ private static final int MINIMUM_SAFETY_NET_CHAR_LENGTH = 4;
private static boolean DBG = LatinImeLogger.sDBG;
/**
@@ -106,11 +107,18 @@ public class Utils {
throw new RuntimeException("Can not find input method id for " + packageName);
}
- public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions) {
+ public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions,
+ Suggest suggest) {
// Safety net for auto correction.
// Actually if we hit this safety net, it's actually a bug.
if (suggestions.size() <= 1 || suggestions.mTypedWordValid) return false;
+ // If user selected aggressive auto correction mode, there is no need to use the safety
+ // net.
+ if (suggest.isAggressiveAutoCorrectionMode()) return false;
CharSequence typedWord = suggestions.getWord(0);
+ // If the length of typed word is less than MINIMUM_SAFETY_NET_CHAR_LENGTH,
+ // we should not use net because relatively edit distance can be big.
+ if (typedWord.length() < MINIMUM_SAFETY_NET_CHAR_LENGTH) return false;
CharSequence candidateWord = suggestions.getWord(1);
final int typedWordLength = typedWord.length();
final int maxEditDistanceOfNativeDictionary = typedWordLength < 5 ? 2 : typedWordLength / 2;
@@ -120,8 +128,11 @@ public class Utils {
+ ", " + maxEditDistanceOfNativeDictionary);
}
if (distance > maxEditDistanceOfNativeDictionary) {
- Log.w(TAG, "(Error) The edit distance of this correction exceeds limit. "
- + "Turning off auto-correction.");
+ if (DBG) {
+ Log.d(TAG, "Safety net: before = " + typedWord + ", after = " + candidateWord);
+ Log.w(TAG, "(Error) The edit distance of this correction exceeds limit. "
+ + "Turning off auto-correction.");
+ }
return true;
} else {
return false;
@@ -267,9 +278,12 @@ public class Utils {
public static double calcNormalizedScore(CharSequence before, CharSequence after, int score) {
final int beforeLength = before.length();
final int afterLength = after.length();
+ if (beforeLength == 0 || afterLength == 0) return 0;
final int distance = editDistance(before, after);
+ // If afterLength < beforeLength, the algorithm is suggesting a word by excessive character
+ // correction.
final double maximumScore = MAX_INITIAL_SCORE
- * Math.pow(TYPED_LETTER_MULTIPLIER, beforeLength)
+ * Math.pow(TYPED_LETTER_MULTIPLIER, Math.min(beforeLength, afterLength))
* FULL_WORD_MULTIPLYER;
// add a weight based on edit distance.
// distance <= max(afterLength, beforeLength) == afterLength,
diff --git a/java/src/com/android/inputmethod/latin/WindowCallbackAdapter.java b/java/src/com/android/inputmethod/latin/WindowCallbackAdapter.java
deleted file mode 100644
index be9bb2bd8..000000000
--- a/java/src/com/android/inputmethod/latin/WindowCallbackAdapter.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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.
- */
-
-package com.android.inputmethod.latin;
-
-import android.view.ActionMode;
-import android.view.ActionMode.Callback;
-import android.view.KeyEvent;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.Window;
-import android.view.WindowManager.LayoutParams;
-import android.view.accessibility.AccessibilityEvent;
-
-public class WindowCallbackAdapter implements Window.Callback {
- private final Window.Callback mPreviousCallback;
-
- public WindowCallbackAdapter(Window.Callback previousCallback) {
- mPreviousCallback = previousCallback;
- }
-
- @Override
- public boolean dispatchKeyEvent(KeyEvent event) {
- if (mPreviousCallback != null)
- return mPreviousCallback.dispatchKeyEvent(event);
- return false;
- }
-
- @Override
- public boolean dispatchKeyShortcutEvent(KeyEvent event) {
- if (mPreviousCallback != null)
- return mPreviousCallback.dispatchKeyShortcutEvent(event);
- return false;
- }
-
- @Override
- public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
- if (mPreviousCallback != null)
- return mPreviousCallback.dispatchPopulateAccessibilityEvent(event);
- return false;
- }
-
- @Override
- public boolean dispatchTouchEvent(MotionEvent event) {
- if (mPreviousCallback != null)
- return mPreviousCallback.dispatchTouchEvent(event);
- return false;
- }
-
- @Override
- public boolean dispatchTrackballEvent(MotionEvent event) {
- if (mPreviousCallback != null)
- return mPreviousCallback.dispatchTrackballEvent(event);
- return false;
- }
-
- @Override
- public void onActionModeFinished(ActionMode mode) {
- if (mPreviousCallback != null)
- mPreviousCallback.onActionModeFinished(mode);
- }
-
- @Override
- public void onActionModeStarted(ActionMode mode) {
- if (mPreviousCallback != null)
- mPreviousCallback.onActionModeStarted(mode);
- }
-
- @Override
- public void onAttachedToWindow() {
- if (mPreviousCallback != null)
- mPreviousCallback.onAttachedToWindow();
- }
-
- @Override
- public void onContentChanged() {
- if (mPreviousCallback != null)
- mPreviousCallback.onContentChanged();
- }
-
- @Override
- public boolean onCreatePanelMenu(int featureId, Menu menu) {
- if (mPreviousCallback != null)
- return mPreviousCallback.onCreatePanelMenu(featureId, menu);
- return false;
- }
-
- @Override
- public View onCreatePanelView(int featureId) {
- if (mPreviousCallback != null)
- return mPreviousCallback.onCreatePanelView(featureId);
- return null;
- }
-
- @Override
- public void onDetachedFromWindow() {
- if (mPreviousCallback != null)
- mPreviousCallback.onDetachedFromWindow();
- }
-
- @Override
- public boolean onMenuItemSelected(int featureId, MenuItem item) {
- if (mPreviousCallback != null)
- return mPreviousCallback.onMenuItemSelected(featureId, item);
- return false;
- }
-
- @Override
- public boolean onMenuOpened(int featureId, Menu menu) {
- if (mPreviousCallback != null)
- return mPreviousCallback.onMenuOpened(featureId, menu);
- return false;
- }
-
- @Override
- public void onPanelClosed(int featureId, Menu menu) {
- if (mPreviousCallback != null)
- mPreviousCallback.onPanelClosed(featureId, menu);
- }
-
- @Override
- public boolean onPreparePanel(int featureId, View view, Menu menu) {
- if (mPreviousCallback != null)
- return mPreviousCallback.onPreparePanel(featureId, view, menu);
- return false;
- }
-
- @Override
- public boolean onSearchRequested() {
- if (mPreviousCallback != null)
- return mPreviousCallback.onSearchRequested();
- return false;
- }
-
- @Override
- public void onWindowAttributesChanged(LayoutParams attrs) {
- if (mPreviousCallback != null)
- mPreviousCallback.onWindowAttributesChanged(attrs);
- }
-
- @Override
- public void onWindowFocusChanged(boolean hasFocus) {
- if (mPreviousCallback != null)
- mPreviousCallback.onWindowFocusChanged(hasFocus);
- }
-
- @Override
- public ActionMode onWindowStartingActionMode(Callback callback) {
- if (mPreviousCallback != null)
- return mPreviousCallback.onWindowStartingActionMode(callback);
- return null;
- }
-}
diff --git a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java
index a3a3ea88e..61a194a8d 100644
--- a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java
+++ b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java
@@ -20,6 +20,7 @@ import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.latin.EditingUtils;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinIME.UIHandler;
+import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SharedPreferencesCompat;
import com.android.inputmethod.latin.SubtypeSwitcher;
@@ -32,6 +33,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.Uri;
+import android.os.AsyncTask;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.provider.Browser;
@@ -43,6 +45,7 @@ import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.URLSpan;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -82,6 +85,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
@SuppressWarnings("unused")
private static final String TAG = "VoiceIMEConnector";
+ private static boolean DEBUG = LatinImeLogger.sDBG;
private boolean mAfterVoiceInput;
private boolean mHasUsedVoiceInput;
@@ -564,8 +568,26 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
}
private void switchToLastInputMethod() {
- IBinder token = mService.getWindow().getWindow().getAttributes().token;
- mImm.switchToLastInputMethod(token);
+ final IBinder token = mService.getWindow().getWindow().getAttributes().token;
+ new AsyncTask<Void, Void, Boolean>() {
+ @Override
+ protected Boolean doInBackground(Void... params) {
+ return mImm.switchToLastInputMethod(token);
+ }
+
+ @Override
+ protected void onPostExecute(Boolean result) {
+ if (!result) {
+ if (DEBUG) {
+ Log.d(TAG, "Couldn't switch back to last IME.");
+ }
+ // Needs to reset here because LatinIME failed to back to any IME and
+ // the same voice subtype will be triggered in the next time.
+ mVoiceInput.reset();
+ mService.requestHideSelf(0);
+ }
+ }
+ }.execute();
}
private void reallyStartListening(boolean swipe) {
@@ -648,14 +670,17 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
}
}
- public void onStartInputView(IBinder token) {
+ public void onStartInputView(IBinder keyboardViewToken) {
+ // If keyboardViewToken is null, keyboardView is not attached but voiceView is attached.
+ IBinder windowToken = keyboardViewToken != null ? keyboardViewToken
+ : mVoiceInput.getView().getWindowToken();
// If IME is in voice mode, but still needs to show the voice warning dialog,
// keep showing the warning.
- if (mSubtypeSwitcher.isVoiceMode() && token != null) {
+ if (mSubtypeSwitcher.isVoiceMode() && windowToken != null) {
// Close keyboard view if it is been shown.
if (KeyboardSwitcher.getInstance().isInputViewShown())
KeyboardSwitcher.getInstance().getInputView().purgeKeyboardAndClosing();
- startListening(false, token);
+ startListening(false, windowToken);
}
// If we have no token, onAttachedToWindow will take care of showing dialog and start
// listening.