diff options
Diffstat (limited to 'java/src')
5 files changed, 126 insertions, 169 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java index 60af1ecc2..06cd319de 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java @@ -33,6 +33,7 @@ import android.widget.PopupWindow; import com.android.inputmethod.accessibility.AccessibilityUtils; import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; +import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder; import com.android.inputmethod.keyboard.internal.PointerTrackerQueue; import com.android.inputmethod.latin.R; @@ -86,7 +87,8 @@ public class LatinKeyboardBaseView extends KeyboardView { private final KeyTimerHandler mKeyTimerHandler = new KeyTimerHandler(this); - public static class KeyTimerHandler extends StaticInnerHandlerWrapper<LatinKeyboardBaseView> { + private static class KeyTimerHandler extends StaticInnerHandlerWrapper<LatinKeyboardBaseView> + implements TimerProxy { private static final int MSG_REPEAT_KEY = 1; private static final int MSG_LONGPRESS_KEY = 2; private static final int MSG_LONGPRESS_SHIFT_KEY = 3; @@ -116,6 +118,7 @@ public class LatinKeyboardBaseView extends KeyboardView { } } + @Override public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker) { mInKeyRepeat = true; sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY, keyIndex, 0, tracker), delay); @@ -130,11 +133,13 @@ public class LatinKeyboardBaseView extends KeyboardView { return mInKeyRepeat; } + @Override public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker) { cancelLongPressTimers(); sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, keyIndex, 0, tracker), delay); } + @Override public void startLongPressShiftTimer(long delay, int keyIndex, PointerTracker tracker) { cancelLongPressTimers(); if (ENABLE_CAPSLOCK_BY_LONGPRESS) { @@ -143,11 +148,13 @@ public class LatinKeyboardBaseView extends KeyboardView { } } + @Override public void cancelLongPressTimers() { removeMessages(MSG_LONGPRESS_KEY); removeMessages(MSG_LONGPRESS_SHIFT_KEY); } + @Override public void cancelKeyTimers() { cancelKeyRepeatTimer(); cancelLongPressTimers(); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 19cedc41d..c960c7613 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -22,8 +22,6 @@ import android.os.SystemClock; import android.util.Log; import android.view.MotionEvent; -import com.android.inputmethod.keyboard.LatinKeyboardBaseView.KeyTimerHandler; -import com.android.inputmethod.keyboard.internal.PointerTrackerKeyState; import com.android.inputmethod.keyboard.internal.PointerTrackerQueue; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; @@ -46,6 +44,14 @@ public class PointerTracker { public void dismissKeyPreview(PointerTracker tracker); } + public interface TimerProxy { + public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker); + public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker); + public void startLongPressShiftTimer(long delay, int keyIndex, PointerTracker tracker); + public void cancelLongPressTimers(); + public void cancelKeyTimers(); + } + public final int mPointerId; // Timing constants @@ -54,7 +60,7 @@ public class PointerTracker { private final int mLongPressShiftKeyTimeout; private final DrawingProxy mDrawingProxy; - private final KeyTimerHandler mKeyTimerHandler; + private final TimerProxy mTimerProxy; private final PointerTrackerQueue mPointerTrackerQueue; private KeyDetector mKeyDetector; private KeyboardActionListener mListener = EMPTY_LISTENER; @@ -68,7 +74,19 @@ public class PointerTracker { private List<Key> mKeys; private int mKeyQuarterWidthSquared; - private final PointerTrackerKeyState mKeyState; + // The position and time at which first down event occurred. + private long mDownTime; + private long mUpTime; + + // The current key index where this pointer is. + private int mKeyIndex = KeyDetector.NOT_A_KEY; + // The position where mKeyIndex was recognized for the first time. + private int mKeyX; + private int mKeyY; + + // Last pointer position. + private int mLastX; + private int mLastY; // true if keyboard layout has been changed. private boolean mKeyboardLayoutHasBeenChanged; @@ -108,15 +126,14 @@ public class PointerTracker { public void onCancelInput() {} }; - public PointerTracker(int id, Context context, KeyTimerHandler keyTimerHandler, - KeyDetector keyDetector, DrawingProxy drawingProxy, PointerTrackerQueue queue) { - if (drawingProxy == null || keyTimerHandler == null || keyDetector == null) + public PointerTracker(int id, Context context, TimerProxy timerProxy, KeyDetector keyDetector, + DrawingProxy drawingProxy, PointerTrackerQueue queue) { + if (drawingProxy == null || timerProxy == null || keyDetector == null) throw new NullPointerException(); mPointerId = id; mDrawingProxy = drawingProxy; - mKeyTimerHandler = keyTimerHandler; + mTimerProxy = timerProxy; mPointerTrackerQueue = queue; // This is null for non-distinct multi-touch device. - mKeyState = new PointerTrackerKeyState(keyDetector); setKeyDetectorInner(keyDetector); mKeyboardSwitcher = KeyboardSwitcher.getInstance(); final Resources res = context.getResources(); @@ -197,7 +214,6 @@ public class PointerTracker { mKeyDetector = keyDetector; mKeyboard = keyDetector.getKeyboard(); mKeys = mKeyboard.getKeys(); - mKeyState.setKeyDetector(keyDetector); final int keyQuarterWidth = mKeyboard.getKeyWidth() / 4; mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth; } @@ -233,7 +249,7 @@ public class PointerTracker { } public boolean isModifier() { - return isModifierInternal(mKeyState.getKeyIndex()); + return isModifierInternal(mKeyIndex); } private boolean isOnModifierKey(int x, int y) { @@ -255,7 +271,7 @@ public class PointerTracker { } public void setReleasedKeyGraphics() { - setReleasedKeyGraphics(mKeyState.getKeyIndex()); + setReleasedKeyGraphics(mKeyIndex); } private void setReleasedKeyGraphics(int keyIndex) { @@ -274,6 +290,46 @@ public class PointerTracker { } } + public int getLastX() { + return mLastX; + } + + public int getLastY() { + return mLastY; + } + + public long getDownTime() { + return mDownTime; + } + + private int onDownKey(int x, int y, long eventTime) { + mDownTime = eventTime; + return onMoveToNewKey(onMoveKeyInternal(x, y), x, y); + } + + private int onMoveKeyInternal(int x, int y) { + mLastX = x; + mLastY = y; + return mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null); + } + + private int onMoveKey(int x, int y) { + return onMoveKeyInternal(x, y); + } + + private int onMoveToNewKey(int keyIndex, int x, int y) { + mKeyIndex = keyIndex; + mKeyX = x; + mKeyY = y; + return keyIndex; + } + + private int onUpKey(int x, int y, long eventTime) { + mUpTime = eventTime; + mKeyIndex = KeyDetector.NOT_A_KEY; + return onMoveKeyInternal(x, y); + } + public void onTouchEvent(int action, int x, int y, long eventTime) { switch (action) { case MotionEvent.ACTION_MOVE: @@ -298,10 +354,10 @@ public class PointerTracker { printTouchEvent("onDownEvent:", x, y, eventTime); // Naive up-to-down noise filter. - final long deltaT = eventTime - mKeyState.getUpTime(); + final long deltaT = eventTime - mUpTime; if (deltaT < mTouchNoiseThresholdMillis) { - final int dx = x - mKeyState.getLastX(); - final int dy = y - mKeyState.getLastY(); + final int dx = x - mLastX; + final int dy = y - mLastY; final int distanceSquared = (dx * dx + dy * dy); if (distanceSquared < mTouchNoiseThresholdDistanceSquared) { if (DEBUG_MODE) @@ -325,7 +381,7 @@ public class PointerTracker { } private void onDownEventInternal(int x, int y, long eventTime) { - int keyIndex = mKeyState.onDownKey(x, y, eventTime); + int keyIndex = onDownKey(x, y, eventTime); // Sliding key is allowed when 1) enabled by configuration, 2) this pointer starts sliding // from modifier key, or 3) this pointer is on mini-keyboard. mIsAllowedSlidingKeyInput = mConfigSlidingKeyInputEnabled || isModifierInternal(keyIndex) @@ -341,7 +397,7 @@ public class PointerTracker { // {@link #setKeyboard}. In those cases, we should update keyIndex according to the new // keyboard layout. if (callListenerOnPressAndCheckKeyboardLayoutChange(getKey(keyIndex), false)) - keyIndex = mKeyState.onDownKey(x, y, eventTime); + keyIndex = onDownKey(x, y, eventTime); startRepeatKey(keyIndex); startLongPressTimer(keyIndex); @@ -361,19 +417,18 @@ public class PointerTracker { printTouchEvent("onMoveEvent:", x, y, eventTime); if (mKeyAlreadyProcessed) return; - final PointerTrackerKeyState keyState = mKeyState; // TODO: Remove this hacking code if (mIsInSlidingLanguageSwitch) { - ((LatinKeyboard)mKeyboard).updateSpacebarPreviewIcon(x - keyState.getKeyX()); + ((LatinKeyboard)mKeyboard).updateSpacebarPreviewIcon(x - mKeyX); showKeyPreview(mSpaceKeyIndex); return; } - final int lastX = keyState.getLastX(); - final int lastY = keyState.getLastY(); - final int oldKeyIndex = keyState.getKeyIndex(); + final int lastX = mLastX; + final int lastY = mLastY; + final int oldKeyIndex = mKeyIndex; final Key oldKey = getKey(oldKeyIndex); - int keyIndex = keyState.onMoveKey(x, y); + int keyIndex = onMoveKey(x, y); if (isValidKeyIndex(keyIndex)) { if (oldKey == null) { // The pointer has been slid in to the new key, but the finger was not on any keys. @@ -382,8 +437,8 @@ public class PointerTracker { // {@link #setKeyboard}. In those cases, we should update keyIndex according to the // new keyboard layout. if (callListenerOnPressAndCheckKeyboardLayoutChange(getKey(keyIndex), true)) - keyIndex = keyState.onMoveKey(x, y); - keyState.onMoveToNewKey(keyIndex, x, y); + keyIndex = onMoveKey(x, y); + onMoveToNewKey(keyIndex, x, y); startLongPressTimer(keyIndex); showKeyPreview(keyIndex); setPressedKeyGraphics(keyIndex); @@ -394,15 +449,15 @@ public class PointerTracker { setReleasedKeyGraphics(oldKeyIndex); callListenerOnRelease(oldKey, oldKey.mCode, true); startSlidingKeyInput(oldKey); - mKeyTimerHandler.cancelKeyTimers(); + mTimerProxy.cancelKeyTimers(); startRepeatKey(keyIndex); if (mIsAllowedSlidingKeyInput) { // This onPress call may have changed keyboard layout. Those cases are detected // at {@link #setKeyboard}. In those cases, we should update keyIndex according // to the new keyboard layout. if (callListenerOnPressAndCheckKeyboardLayoutChange(getKey(keyIndex), true)) - keyIndex = keyState.onMoveKey(x, y); - keyState.onMoveToNewKey(keyIndex, x, y); + keyIndex = onMoveKey(x, y); + onMoveToNewKey(keyIndex, x, y); startLongPressTimer(keyIndex); setPressedKeyGraphics(keyIndex); showKeyPreview(keyIndex); @@ -432,7 +487,7 @@ public class PointerTracker { final LatinKeyboard keyboard = ((LatinKeyboard)mKeyboard); if (mSubtypeSwitcher.useSpacebarLanguageSwitcher() && mSubtypeSwitcher.getEnabledKeyboardLocaleCount() > 1) { - final int diff = x - keyState.getKeyX(); + final int diff = x - mKeyX; if (keyboard.shouldTriggerSpacebarSlidingLanguageSwitch(diff)) { // Detect start sliding language switch. mIsInSlidingLanguageSwitch = true; @@ -453,9 +508,9 @@ public class PointerTracker { setReleasedKeyGraphics(oldKeyIndex); callListenerOnRelease(oldKey, oldKey.mCode, true); startSlidingKeyInput(oldKey); - mKeyTimerHandler.cancelLongPressTimers(); + mTimerProxy.cancelLongPressTimers(); if (mIsAllowedSlidingKeyInput) { - keyState.onMoveToNewKey(keyIndex, x, y); + onMoveToNewKey(keyIndex, x, y); } else { mKeyAlreadyProcessed = true; dismissKeyPreview(); @@ -494,20 +549,19 @@ public class PointerTracker { private void onUpEventInternal(int x, int y, long eventTime, boolean updateReleasedKeyGraphics) { - mKeyTimerHandler.cancelKeyTimers(); + mTimerProxy.cancelKeyTimers(); mDrawingProxy.cancelShowKeyPreview(this); mIsInSlidingKeyInput = false; - final PointerTrackerKeyState keyState = mKeyState; final int keyX, keyY; - if (isMajorEnoughMoveToBeOnNewKey(x, y, keyState.onMoveKey(x, y))) { + if (isMajorEnoughMoveToBeOnNewKey(x, y, onMoveKey(x, y))) { keyX = x; keyY = y; } else { // Use previous fixed key coordinates. - keyX = keyState.getKeyX(); - keyY = keyState.getKeyY(); + keyX = mKeyX; + keyY = mKeyY; } - final int keyIndex = keyState.onUpKey(keyX, keyY, eventTime); + final int keyIndex = onUpKey(keyX, keyY, eventTime); dismissKeyPreview(); if (updateReleasedKeyGraphics) setReleasedKeyGraphics(keyIndex); @@ -555,10 +609,10 @@ public class PointerTracker { } private void onCancelEventInternal() { - mKeyTimerHandler.cancelKeyTimers(); + mTimerProxy.cancelKeyTimers(); mDrawingProxy.cancelShowKeyPreview(this); dismissKeyPreview(); - setReleasedKeyGraphics(mKeyState.getKeyIndex()); + setReleasedKeyGraphics(mKeyIndex); mIsInSlidingKeyInput = false; } @@ -567,7 +621,7 @@ public class PointerTracker { if (key != null && key.mRepeatable) { dismissKeyPreview(); onRepeatKey(keyIndex); - mKeyTimerHandler.startKeyRepeatTimer(mDelayBeforeKeyRepeatStart, keyIndex, this); + mTimerProxy.startKeyRepeatTimer(mDelayBeforeKeyRepeatStart, keyIndex, this); mIsRepeatableKey = true; } else { mIsRepeatableKey = false; @@ -581,22 +635,10 @@ public class PointerTracker { } } - public int getLastX() { - return mKeyState.getLastX(); - } - - public int getLastY() { - return mKeyState.getLastY(); - } - - public long getDownTime() { - return mKeyState.getDownTime(); - } - private boolean isMajorEnoughMoveToBeOnNewKey(int x, int y, int newKey) { if (mKeys == null || mKeyDetector == null) throw new NullPointerException("keyboard and/or key detector not set"); - int curKey = mKeyState.getKeyIndex(); + int curKey = mKeyIndex; if (newKey == curKey) { return false; } else if (isValidKeyIndex(curKey)) { @@ -633,16 +675,16 @@ public class PointerTracker { private void startLongPressTimer(int keyIndex) { Key key = getKey(keyIndex); if (key.mCode == Keyboard.CODE_SHIFT) { - mKeyTimerHandler.startLongPressShiftTimer(mLongPressShiftKeyTimeout, keyIndex, this); + mTimerProxy.startLongPressShiftTimer(mLongPressShiftKeyTimeout, keyIndex, this); } else if (key.hasUppercaseLetter() && mKeyboard.isManualTemporaryUpperCase()) { // We need not start long press timer on the key which has manual temporary upper case // code defined and the keyboard is in manual temporary upper case mode. return; } else if (mKeyboardSwitcher.isInMomentarySwitchState()) { // We use longer timeout for sliding finger input started from the symbols mode key. - mKeyTimerHandler.startLongPressTimer(mLongPressKeyTimeout * 3, keyIndex, this); + mTimerProxy.startLongPressTimer(mLongPressKeyTimeout * 3, keyIndex, this); } else { - mKeyTimerHandler.startLongPressTimer(mLongPressKeyTimeout, keyIndex, this); + mTimerProxy.startLongPressTimer(mLongPressKeyTimeout, keyIndex, this); } } diff --git a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java deleted file mode 100644 index 5a12db248..000000000 --- a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerKeyState.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2010 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.keyboard.internal; - -import com.android.inputmethod.keyboard.KeyDetector; -import com.android.inputmethod.keyboard.PointerTracker; - -/** - * This class keeps track of a key index and a position where {@link PointerTracker} is. - */ -public class PointerTrackerKeyState { - private KeyDetector mKeyDetector; - - // The position and time at which first down event occurred. - private long mDownTime; - private long mUpTime; - - // The current key index where this pointer is. - private int mKeyIndex = KeyDetector.NOT_A_KEY; - // The position where mKeyIndex was recognized for the first time. - private int mKeyX; - private int mKeyY; - - // Last pointer position. - private int mLastX; - private int mLastY; - - public PointerTrackerKeyState(KeyDetector keyDetector) { - if (keyDetector == null) - throw new NullPointerException(); - mKeyDetector = keyDetector; - } - - public void setKeyDetector(KeyDetector keyDetector) { - mKeyDetector = keyDetector; - } - - public int getKeyIndex() { - return mKeyIndex; - } - - public int getKeyX() { - return mKeyX; - } - - public int getKeyY() { - return mKeyY; - } - - public long getDownTime() { - return mDownTime; - } - - public long getUpTime() { - return mUpTime; - } - - public int getLastX() { - return mLastX; - } - - public int getLastY() { - return mLastY; - } - - public int onDownKey(int x, int y, long eventTime) { - mDownTime = eventTime; - return onMoveToNewKey(onMoveKeyInternal(x, y), x, y); - } - - private int onMoveKeyInternal(int x, int y) { - mLastX = x; - mLastY = y; - return mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null); - } - - public int onMoveKey(int x, int y) { - return onMoveKeyInternal(x, y); - } - - public int onMoveToNewKey(int keyIndex, int x, int y) { - mKeyIndex = keyIndex; - mKeyX = x; - mKeyY = y; - return keyIndex; - } - - public int onUpKey(int x, int y, long eventTime) { - mUpTime = eventTime; - mKeyIndex = KeyDetector.NOT_A_KEY; - return onMoveKeyInternal(x, y); - } -} diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index aba72d320..9b8199723 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -18,8 +18,10 @@ package com.android.inputmethod.latin; import com.android.inputmethod.compat.CompatUtils; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; +import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.compat.VibratorCompatWrapper; +import com.android.inputmethodcommon.InputMethodSettingsFragment; import android.app.Activity; import android.app.AlertDialog; @@ -48,7 +50,7 @@ import android.widget.TextView; import java.util.Arrays; import java.util.Locale; -public class Settings extends PreferenceActivity +public class Settings extends InputMethodSettingsFragment implements SharedPreferences.OnSharedPreferenceChangeListener, DialogInterface.OnDismissListener, OnPreferenceClickListener { private static final String TAG = "Settings"; @@ -289,7 +291,6 @@ public class Settings extends PreferenceActivity } private PreferenceScreen mInputLanguageSelection; - private CheckBoxPreference mQuickFixes; private ListPreference mVoicePreference; private ListPreference mSettingsKeyPreference; private ListPreference mShowCorrectionSuggestionsPreference; @@ -331,13 +332,14 @@ public class Settings extends PreferenceActivity @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); + setInputMethodSettingsCategoryTitle(R.string.language_selection_title); + setSubtypeEnablerTitle(R.string.select_language); final Resources res = getResources(); final Context context = getActivityInternal(); addPreferencesFromResource(R.xml.prefs); mInputLanguageSelection = (PreferenceScreen) findPreference(PREF_SUBTYPES); mInputLanguageSelection.setOnPreferenceClickListener(this); - mQuickFixes = (CheckBoxPreference) findPreference(PREF_QUICK_FIXES); mVoicePreference = (ListPreference) findPreference(PREF_VOICE_SETTINGS_KEY); mSettingsKeyPreference = (ListPreference) findPreference(PREF_SETTINGS_KEY); mShowCorrectionSuggestionsPreference = @@ -384,6 +386,10 @@ public class Settings extends PreferenceActivity generalSettings.removePreference(findPreference(PREF_VIBRATE_ON)); } + if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) { + generalSettings.removePreference(findPreference(PREF_SUBTYPES)); + } + final boolean showPopupOption = res.getBoolean( R.bool.config_enable_show_popup_on_keypress_option); if (!showPopupOption) { @@ -536,7 +542,6 @@ public class Settings extends PreferenceActivity [mVoicePreference.findIndexOfValue(mVoicePreference.getValue())]); } - @Override protected Dialog onCreateDialog(int id) { switch (id) { case VOICE_INPUT_CONFIRM_DIALOG: diff --git a/java/src/com/android/inputmethod/latin/SettingsActivity.java b/java/src/com/android/inputmethod/latin/SettingsActivity.java index 2da171a63..7a6c2efd0 100644 --- a/java/src/com/android/inputmethod/latin/SettingsActivity.java +++ b/java/src/com/android/inputmethod/latin/SettingsActivity.java @@ -16,5 +16,15 @@ package com.android.inputmethod.latin; -public class SettingsActivity extends Settings { +import android.content.Intent; +import android.preference.PreferenceActivity; + +public class SettingsActivity extends PreferenceActivity { + @Override + public Intent getIntent() { + final Intent modIntent = new Intent(super.getIntent()); + modIntent.putExtra(EXTRA_SHOW_FRAGMENT, Settings.class.getName()); + modIntent.putExtra(EXTRA_NO_HEADERS, true); + return modIntent; + } } |