diff options
Diffstat (limited to 'java/src')
6 files changed, 135 insertions, 60 deletions
diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java index 2919e9b56..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); } @@ -365,6 +368,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 e4776f888..335778980 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -127,6 +127,7 @@ public class LatinIME extends InputMethodService public static final String PREF_SELECTED_LANGUAGES = "selected_languages"; public static final String PREF_INPUT_LANGUAGE = "input_language"; + private static final String PREF_RECORRECTION_ENABLED = "recorrection_enabled"; private static final int MSG_UPDATE_SUGGESTIONS = 0; private static final int MSG_START_TUTORIAL = 1; @@ -193,6 +194,7 @@ public class LatinIME extends InputMethodService private boolean mAutoSpace; private boolean mJustAddedAutoSpace; private boolean mAutoCorrectEnabled; + private boolean mReCorrectionEnabled; private boolean mBigramSuggestionEnabled; private boolean mAutoCorrectOn; // TODO move this state variable outside LatinIME @@ -360,6 +362,8 @@ public class LatinIME extends InputMethodService if (inputLanguage == null) { inputLanguage = conf.locale.toString(); } + mReCorrectionEnabled = prefs.getBoolean(PREF_RECORRECTION_ENABLED, + getResources().getBoolean(R.bool.default_recorrection_enabled)); LatinIMEUtil.GCUtils.getInstance().reset(); boolean tryGC = true; @@ -768,21 +772,22 @@ public class LatinIME extends InputMethodService mLastSelectionStart = newSelStart; mLastSelectionEnd = newSelEnd; - - // Don't look for corrections if the keyboard is not visible - if (mKeyboardSwitcher != null && mKeyboardSwitcher.getInputView() != null - && mKeyboardSwitcher.getInputView().isShown()) { - // Check if we should go in or out of correction mode. - if (isPredictionOn() - && mJustRevertedSeparator == null - && (candidatesStart == candidatesEnd || newSelStart != oldSelStart - || TextEntryState.isCorrecting()) - && (newSelStart < newSelEnd - 1 || (!mPredicting)) - && !mVoiceInputHighlighted) { - if (isCursorTouchingWord() || mLastSelectionStart < mLastSelectionEnd) { - postUpdateOldSuggestions(); - } else { - abortCorrection(false); + if (mReCorrectionEnabled) { + // Don't look for corrections if the keyboard is not visible + if (mKeyboardSwitcher != null && mKeyboardSwitcher.getInputView() != null + && mKeyboardSwitcher.getInputView().isShown()) { + // Check if we should go in or out of correction mode. + if (isPredictionOn() + && mJustRevertedSeparator == null + && (candidatesStart == candidatesEnd || newSelStart != oldSelStart + || TextEntryState.isCorrecting()) + && (newSelStart < newSelEnd - 1 || (!mPredicting)) + && !mVoiceInputHighlighted) { + if (isCursorTouchingWord() || mLastSelectionStart < mLastSelectionEnd) { + postUpdateOldSuggestions(); + } else { + abortCorrection(false); + } } } } @@ -1134,7 +1139,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()) { @@ -1934,7 +1941,7 @@ public class LatinIME extends InputMethodService List<CharSequence> 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) @@ -2178,6 +2185,9 @@ public class LatinIME extends InputMethodService if (PREF_SELECTED_LANGUAGES.equals(key)) { mLanguageSwitcher.loadLocales(sharedPreferences); mRefreshKeyboardRequired = true; + } else if (PREF_RECORRECTION_ENABLED.equals(key)) { + mReCorrectionEnabled = sharedPreferences.getBoolean(PREF_RECORRECTION_ENABLED, + getResources().getBoolean(R.bool.default_recorrection_enabled)); } } @@ -2195,7 +2205,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) { @@ -2209,7 +2219,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/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/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index c449b36e7..1e95e8ac4 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<PointerTracker> mPointerTrackers = new ArrayList<PointerTracker>(); 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) { @@ -564,6 +570,14 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx } /** + * 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 * @return true if the shift key state changed, false if there was no change @@ -1059,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()); @@ -1090,7 +1105,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 +1122,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 +1160,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/LatinKeyboardView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java index 71ca8b81a..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); } @@ -131,7 +113,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; 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); } |