From c8b9afe0378e3f33c3f83271bd1df9678a70c2a2 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 6 Sep 2010 14:26:46 +0900 Subject: Support multi-touch only when device has distinct multi-touch panel Bug: 2973373 Change-Id: I9871c09ec8c1c2aa945d97392e61ee1ec585baef --- .../inputmethod/latin/KeyboardSwitcher.java | 4 ++ .../com/android/inputmethod/latin/LatinIME.java | 10 +++-- .../inputmethod/latin/LatinKeyboardBaseView.java | 51 +++++++++++++++++++++- .../android/inputmethod/latin/PointerTracker.java | 34 +++++++++++++-- 4 files changed, 90 insertions(+), 9 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java index 2919e9b56..3fb74b238 100644 --- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java @@ -365,6 +365,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } } + public boolean hasDistinctMultitouch() { + return mInputView != null && mInputView.hasDistinctMultitouch(); + } + /** * Updates state machine to figure out when to automatically switch back to alpha mode. * Returns true if the keyboard needs to switch back diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index ea8c93934..2cff232a6 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1135,7 +1135,9 @@ public class LatinIME extends InputMethodService LatinImeLogger.logOnDelete(); break; case Keyboard.KEYCODE_SHIFT: - // Shift key is handled in onPress(). + // Shift key is handled in onPress() when device has distinct multi-touch panel. + if (!mKeyboardSwitcher.hasDistinctMultitouch()) + handleShift(); break; case Keyboard.KEYCODE_CANCEL: if (!isShowingOptionDialog()) { @@ -1935,7 +1937,7 @@ public class LatinIME extends InputMethodService List suggestions = mWordToSuggestions.get(selectedWord); // If the first letter of touching is capitalized, make all the suggestions // start with a capital letter. - if (Character.isUpperCase((char) touching.word.charAt(0))) { + if (Character.isUpperCase(touching.word.charAt(0))) { for (int i = 0; i < suggestions.size(); i++) { String origSugg = (String) suggestions.get(i); String capsSugg = origSugg.toUpperCase().charAt(0) @@ -2196,7 +2198,7 @@ public class LatinIME extends InputMethodService public void onPress(int primaryCode) { vibrate(); playKeyClick(primaryCode); - if (primaryCode == Keyboard.KEYCODE_SHIFT) { + if (mKeyboardSwitcher.hasDistinctMultitouch() && primaryCode == Keyboard.KEYCODE_SHIFT) { mShiftKeyState.onPress(); handleShift(); } else if (primaryCode == Keyboard.KEYCODE_MODE_CHANGE) { @@ -2210,7 +2212,7 @@ public class LatinIME extends InputMethodService // Reset any drag flags in the keyboard ((LatinKeyboard) mKeyboardSwitcher.getInputView().getKeyboard()).keyReleased(); //vibrate(); - if (primaryCode == Keyboard.KEYCODE_SHIFT) { + if (mKeyboardSwitcher.hasDistinctMultitouch() && primaryCode == Keyboard.KEYCODE_SHIFT) { if (mShiftKeyState.isMomentary()) resetShift(); mShiftKeyState.onRelease(); diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index c449b36e7..51bdc2c0c 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -17,6 +17,7 @@ package com.android.inputmethod.latin; import android.content.Context; +import android.content.pm.PackageManager; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; @@ -204,6 +205,8 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx private final ArrayList mPointerTrackers = new ArrayList(); private final PointerQueue mPointerQueue = new PointerQueue(); private final float mDebounceHysteresis; + private final boolean mHasDistinctMultitouch; + private int mOldPointerCount = 1; protected KeyDetector mKeyDetector = new ProximityKeyDetector(); @@ -508,6 +511,9 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx final boolean ignoreMultitouch = true; mGestureDetector = new GestureDetector(getContext(), listener, null, ignoreMultitouch); mGestureDetector.setIsLongpressEnabled(false); + + mHasDistinctMultitouch = context.getPackageManager() + .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT); } public void setOnKeyboardActionListener(OnKeyboardActionListener listener) { @@ -563,6 +569,14 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx return mKeyboard; } + /** + * Return whether the device has distinct multi-touch panel. + * @return true if the device has distinct multi-touch panel. + */ + public boolean hasDistinctMultitouch() { + return mHasDistinctMultitouch; + } + /** * Sets the state of the shift key of the keyboard, if any. * @param shifted whether or not to enable the state of the shift key @@ -1090,7 +1104,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx // Create pointer trackers until we can get 'id+1'-th tracker, if needed. for (int i = pointers.size(); i <= id; i++) { final PointerTracker tracker = - new PointerTracker(i, mHandler, mKeyDetector, this); + new PointerTracker(i, mHandler, mKeyDetector, this, mHasDistinctMultitouch); if (keys != null) tracker.setKeyboard(keys, mDebounceHysteresis); if (listener != null) @@ -1107,6 +1121,13 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx final int action = me.getActionMasked(); final long eventTime = me.getEventTime(); + // TODO: cleanup this code into a multi-touch to single-touch event converter class? + // If the device does not have distinct multi-touch support panel, ignore all multi-touch + // events except a transition from/to single-touch. + if (!mHasDistinctMultitouch && pointerCount > 1 && mOldPointerCount > 1) { + return true; + } + // Track the last few movements to look for spurious swipes. mSwipeTracker.addMovement(me); @@ -1138,6 +1159,34 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx // Up event will pass through. } + // TODO: cleanup this code into a multi-touch to single-touch event converter class? + // Translate mutli-touch event to single-touch events on the device that has no distinct + // multi-touch panel. + if (!mHasDistinctMultitouch) { + // Use only main (id=0) pointer tracker. + PointerTracker tracker = getPointerTracker(0); + int index = me.getActionIndex(); + int x = (int)me.getX(index); + int y = (int)me.getY(index); + int oldPointerCount = mOldPointerCount; + if (pointerCount == 1 && oldPointerCount == 2) { + // Multi-touch to single touch transition. + // Send a down event for the latest pointer. + tracker.onDownEvent(x, y, eventTime); + } else if (pointerCount == 2 && oldPointerCount == 1) { + // Single-touch to multi-touch transition. + // Send an up event for the last pointer. + tracker.onUpEvent(tracker.getLastX(), tracker.getLastY(), eventTime); + } else if (pointerCount == 1 && oldPointerCount == 1) { + tracker.onTouchEvent(action, x, y, eventTime); + } else { + Log.w(TAG, "Unknown touch panel behavior: pointer count is " + pointerCount + + " (old " + oldPointerCount + ")"); + } + mOldPointerCount = pointerCount; + return true; + } + if (action == MotionEvent.ACTION_MOVE) { for (int index = 0; index < pointerCount; index++) { int x = (int)me.getX(index); diff --git a/java/src/com/android/inputmethod/latin/PointerTracker.java b/java/src/com/android/inputmethod/latin/PointerTracker.java index 2685e87c6..1f6005621 100644 --- a/java/src/com/android/inputmethod/latin/PointerTracker.java +++ b/java/src/com/android/inputmethod/latin/PointerTracker.java @@ -22,12 +22,13 @@ import com.android.inputmethod.latin.LatinKeyboardBaseView.UIHandler; import android.inputmethodservice.Keyboard; import android.inputmethodservice.Keyboard.Key; import android.util.Log; +import android.view.MotionEvent; import android.view.ViewConfiguration; public class PointerTracker { private static final String TAG = "PointerTracker"; private static final boolean DEBUG = false; - private static final boolean DEBUG_MOVE = DEBUG && true; + private static final boolean DEBUG_MOVE = false; public interface UIProxy { public void invalidateKey(Key key); @@ -51,6 +52,7 @@ public class PointerTracker { private final UIHandler mHandler; private final KeyDetector mKeyDetector; private OnKeyboardActionListener mListener; + private final boolean mHasDistinctMultitouch; private Key[] mKeys; private int mKeyDebounceThresholdSquared = -1; @@ -85,13 +87,15 @@ public class PointerTracker { // pressed key private int mPreviousKey = NOT_A_KEY; - public PointerTracker(int id, UIHandler handler, KeyDetector keyDetector, UIProxy proxy) { + public PointerTracker(int id, UIHandler handler, KeyDetector keyDetector, UIProxy proxy, + boolean hasDistinctMultitouch) { if (proxy == null || handler == null || keyDetector == null) throw new NullPointerException(); mPointerId = id; mProxy = proxy; mHandler = handler; mKeyDetector = keyDetector; + mHasDistinctMultitouch = hasDistinctMultitouch; resetMultiTap(); } @@ -146,6 +150,25 @@ public class PointerTracker { mKeyAlreadyProcessed = true; } + public void onTouchEvent(int action, int x, int y, long eventTime) { + switch (action) { + case MotionEvent.ACTION_MOVE: + onMoveEvent(x, y, eventTime); + break; + case MotionEvent.ACTION_DOWN: + case MotionEvent.ACTION_POINTER_DOWN: + onDownEvent(x, y, eventTime); + break; + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_POINTER_UP: + onUpEvent(x, y, eventTime); + break; + case MotionEvent.ACTION_CANCEL: + onCancelEvent(x, y, eventTime); + break; + } + } + public void onDownEvent(int x, int y, long eventTime) { int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null); mCurrentKey = keyIndex; @@ -242,7 +265,7 @@ public class PointerTracker { showKeyPreviewAndUpdateKey(NOT_A_KEY); // If we're not on a repeating key (which sends on a DOWN event) if (!wasInKeyRepeat) { - detectAndSendKey(mCurrentKey, (int)x, (int)y, eventTime); + detectAndSendKey(mCurrentKey, x, y, eventTime); } if (isValidKeyIndex(keyIndex)) mProxy.invalidateKey(mKeys[keyIndex]); @@ -355,7 +378,10 @@ public class PointerTracker { private void showKeyPreviewAndUpdateKey(int keyIndex) { updateKey(keyIndex); - if (!isModifier()) + // The modifier key, such as shift key, should not be shown as preview when multi-touch is + // supported. On thge other hand, if multi-touch is not supported, the modifier key should + // be shown as preview. + if (!isModifier() || !mHasDistinctMultitouch) mProxy.showPreview(keyIndex, this); } -- cgit v1.2.3-83-g751a From 12659d4c0ce04aaf3d8479e44f9230881b964000 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 6 Sep 2010 14:50:50 +0900 Subject: Fix ALT key light behavior This change also cleanups some imports, unnecessary cast and null check. Bug: 2977256 Change-Id: I81b9e539ff8a13ae0cc1eb5c4fb2246732cca3e9 --- .../inputmethod/latin/KeyboardSwitcher.java | 25 ++++++++++++---------- .../android/inputmethod/latin/LatinKeyboard.java | 10 ++++----- .../inputmethod/latin/LatinKeyboardView.java | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java index 3fb74b238..284b29305 100644 --- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java @@ -16,10 +16,6 @@ package com.android.inputmethod.latin; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; @@ -27,6 +23,10 @@ import android.content.res.Resources; import android.preference.PreferenceManager; import android.view.InflateException; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceChangeListener { public static final int MODE_NONE = 0; @@ -197,8 +197,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } mHasVoice = enableVoice; mVoiceOnPrimary = voiceOnPrimary; - setKeyboardMode(mMode, mImeOptions, mHasVoice, - mIsSymbols); + setKeyboardMode(mMode, mImeOptions, mHasVoice, mIsSymbols); } boolean hasVoiceButton(boolean isSymbols) { @@ -338,19 +337,23 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha void toggleShift() { if (mCurrentId.equals(mSymbolsId)) { - LatinKeyboard symbolsKeyboard = getKeyboard(mSymbolsId); LatinKeyboard symbolsShiftedKeyboard = getKeyboard(mSymbolsShiftedId); - symbolsKeyboard.setShifted(true); mCurrentId = mSymbolsShiftedId; mInputView.setKeyboard(symbolsShiftedKeyboard); - symbolsShiftedKeyboard.setShifted(true); + // Symbol shifted keyboard has an ALT key that has a caps lock style indicator. To + // enable the indicator, we need to call enableShiftLock() and setShiftLocked(true). + // Thus we can keep the ALT key's Key.on value true while LatinKey.onRelease() is + // called. + symbolsShiftedKeyboard.enableShiftLock(); + symbolsShiftedKeyboard.setShiftLocked(true); symbolsShiftedKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions); } else if (mCurrentId.equals(mSymbolsShiftedId)) { LatinKeyboard symbolsKeyboard = getKeyboard(mSymbolsId); - LatinKeyboard symbolsShiftedKeyboard = getKeyboard(mSymbolsShiftedId); - symbolsShiftedKeyboard.setShifted(false); mCurrentId = mSymbolsId; mInputView.setKeyboard(symbolsKeyboard); + // Symbol keyboard has an ALT key that has a caps lock style indicator. To disable the + // indicator, we need to call enableShiftLock() and setShiftLocked(false). + symbolsKeyboard.enableShiftLock(); symbolsKeyboard.setShifted(false); symbolsKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions); } diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboard.java b/java/src/com/android/inputmethod/latin/LatinKeyboard.java index c7ca67727..caae92363 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboard.java @@ -16,9 +16,6 @@ package com.android.inputmethod.latin; -import java.util.List; -import java.util.Locale; - import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; @@ -27,10 +24,10 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.ColorFilter; import android.graphics.Paint; +import android.graphics.Paint.Align; import android.graphics.PixelFormat; import android.graphics.PorterDuff; import android.graphics.Rect; -import android.graphics.Paint.Align; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.inputmethodservice.Keyboard; @@ -39,6 +36,9 @@ import android.util.Log; import android.view.ViewConfiguration; import android.view.inputmethod.EditorInfo; +import java.util.List; +import java.util.Locale; + public class LatinKeyboard extends Keyboard { private static final boolean DEBUG_PREFERRED_LETTER = false; @@ -128,7 +128,7 @@ public class LatinKeyboard extends Keyboard { R.dimen.spacebar_vertical_correction); mIsAlphaKeyboard = xmlLayoutResId == R.xml.kbd_qwerty || xmlLayoutResId == R.xml.kbd_qwerty_black; - mSpaceKeyIndex = indexOf((int) ' '); + mSpaceKeyIndex = indexOf(' '); } public LatinKeyboard(Context context, int layoutTemplateResId, diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java index 71ca8b81a..4295427e3 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java @@ -131,7 +131,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { public boolean setShiftLocked(boolean shiftLocked) { Keyboard keyboard = getKeyboard(); - if (keyboard != null && keyboard instanceof LatinKeyboard) { + if (keyboard instanceof LatinKeyboard) { ((LatinKeyboard)keyboard).setShiftLocked(shiftLocked); invalidateAllKeys(); return true; -- cgit v1.2.3-83-g751a From 8d7ffcb2ac3a8cdd051c7e493ff17b6bf1ded9c0 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 6 Sep 2010 22:16:11 +0900 Subject: Disable pop-up preview on mini keyboard This change also disable the special behavior of long press a key that has only one digit alternate. If the visual design of both the pop-up preview and the mini keyboard will look like same, I think that showing mini keyboard is enough for the key that has one digit alternate. Bug: 2973546 Change-Id: I04f138c120aa58526fe054626dac856171fb7a58 --- .../inputmethod/latin/LatinKeyboardBaseView.java | 3 ++- .../android/inputmethod/latin/LatinKeyboardView.java | 18 ------------------ 2 files changed, 2 insertions(+), 19 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index 51bdc2c0c..1e95e8ac4 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -1073,7 +1073,8 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx mMiniKeyboardOriginY = y + container.getPaddingTop(); mMiniKeyboard.setPopupOffset((x < 0) ? 0 : x, y); mMiniKeyboard.setShifted(isShifted()); - mMiniKeyboard.setPreviewEnabled(isPreviewEnabled()); + // Mini keyboard needs no pop-up key preview displayed. + mMiniKeyboard.setPreviewEnabled(false); mMiniKeyboardPopup.setContentView(container); mMiniKeyboardPopup.setWidth(container.getMeasuredWidth()); mMiniKeyboardPopup.setHeight(container.getMeasuredHeight()); diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java index 4295427e3..8f20a22d0 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java @@ -78,17 +78,6 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { setKeyboardLocal(k); } - private static boolean hasOneDigitAlternate(Key key) { - final CharSequence alternates = key.popupCharacters; - if (alternates == null) - return false; - final String altChars = alternates.toString(); - if (altChars.codePointCount(0, altChars.length()) != 1) - return false; - final int altCode = altChars.codePointAt(0); - return altCode >= '0' && altCode <= '9'; - } - @Override protected boolean onLongPress(Key key) { int primaryCode = key.codes[0]; @@ -104,13 +93,6 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { LatinKeyboardBaseView.NOT_A_TOUCH_COORDINATE, LatinKeyboardBaseView.NOT_A_TOUCH_COORDINATE); return true; - } else if (hasOneDigitAlternate(key)) { - mKeyCodes[0] = primaryCode = key.popupCharacters.charAt(0); - // when there is only one alternate character, send it as key action. - getOnKeyboardActionListener().onKey(primaryCode, mKeyCodes, - LatinKeyboardBaseView.NOT_A_TOUCH_COORDINATE, - LatinKeyboardBaseView.NOT_A_TOUCH_COORDINATE); - return true; } else { return super.onLongPress(key); } -- cgit v1.2.3-83-g751a From 66b42a1c2d38813be104a7f0435ec6e6ec1c6e65 Mon Sep 17 00:00:00 2001 From: satok Date: Mon, 6 Sep 2010 19:18:38 +0900 Subject: Add shared preference for re-correction Change-Id: Ie5b2e0d2f9739dd33524c2688e172e77aac1f243 --- java/res/values/bools.xml | 1 + java/res/values/strings.xml | 4 +++ java/res/xml/prefs.xml | 7 ++++ .../com/android/inputmethod/latin/LatinIME.java | 38 +++++++++++++--------- 4 files changed, 35 insertions(+), 15 deletions(-) (limited to 'java/src') diff --git a/java/res/values/bools.xml b/java/res/values/bools.xml index f5f2c3d0e..1f8051bfd 100644 --- a/java/res/values/bools.xml +++ b/java/res/values/bools.xml @@ -28,4 +28,5 @@ true true + true diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index 7b760f002..456151b62 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -339,6 +339,10 @@ Enable user feedback Help improve this input method editor by automatically sending usage statistics and crash reports to Google. + + Tap to re-correction + + You can re-correct words by tapping words you have typed Keyboard Theme diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml index b4d2d903d..762ada00c 100644 --- a/java/res/xml/prefs.xml +++ b/java/res/xml/prefs.xml @@ -37,6 +37,13 @@ android:defaultValue="@bool/default_popup_preview" /> + +