aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/MainKeyboardView.java')
-rw-r--r--java/src/com/android/inputmethod/keyboard/MainKeyboardView.java256
1 files changed, 62 insertions, 194 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index 6aa43b994..6782317d0 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -53,16 +53,15 @@ import com.android.inputmethod.keyboard.internal.GestureFloatingPreviewText;
import com.android.inputmethod.keyboard.internal.GestureTrailsPreview;
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams;
+import com.android.inputmethod.keyboard.internal.NonDistinctMultitouchHelper;
import com.android.inputmethod.keyboard.internal.PreviewPlacerView;
import com.android.inputmethod.keyboard.internal.SlidingKeyInputPreview;
-import com.android.inputmethod.keyboard.internal.TouchScreenRegulator;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.settings.DebugSettings;
-import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.CoordinateUtils;
import com.android.inputmethod.latin.utils.StaticInnerHandlerWrapper;
@@ -116,13 +115,9 @@ import java.util.WeakHashMap;
* @attr ref R.styleable#MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration
*/
public final class MainKeyboardView extends KeyboardView implements PointerTracker.KeyEventHandler,
- PointerTracker.DrawingProxy, MoreKeysPanel.Controller,
- TouchScreenRegulator.ProcessMotionEvent {
+ PointerTracker.DrawingProxy, MoreKeysPanel.Controller {
private static final String TAG = MainKeyboardView.class.getSimpleName();
- // TODO: Kill process when the usability study mode was changed.
- private static final boolean ENABLE_USABILITY_STUDY_LOG = LatinImeLogger.sUsabilityStudy;
-
/** Listener for {@link KeyboardActionListener}. */
private KeyboardActionListener mKeyboardActionListener;
@@ -184,12 +179,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
// TODO: Make this parameter customizable by user via settings.
private int mGestureFloatingPreviewTextLingerTimeout;
- private final TouchScreenRegulator mTouchScreenRegulator;
-
private KeyDetector mKeyDetector;
- private final boolean mHasDistinctMultitouch;
- private int mOldPointerCount = 1;
- private Key mOldKey;
+ private final NonDistinctMultitouchHelper mNonDistinctMultitouchHelper;
private final KeyTimerHandler mKeyTimerHandler;
@@ -201,9 +192,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
private static final int MSG_DOUBLE_TAP_SHIFT_KEY = 3;
private static final int MSG_UPDATE_BATCH_INPUT = 4;
- private final int mKeyRepeatStartTimeout;
- private final int mKeyRepeatInterval;
- private final int mLongPressShiftLockTimeout;
private final int mIgnoreAltCodeKeyTimeout;
private final int mGestureRecognitionUpdateTime;
@@ -211,12 +199,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
final TypedArray mainKeyboardViewAttr) {
super(outerInstance);
- mKeyRepeatStartTimeout = mainKeyboardViewAttr.getInt(
- R.styleable.MainKeyboardView_keyRepeatStartTimeout, 0);
- mKeyRepeatInterval = mainKeyboardViewAttr.getInt(
- R.styleable.MainKeyboardView_keyRepeatInterval, 0);
- mLongPressShiftLockTimeout = mainKeyboardViewAttr.getInt(
- R.styleable.MainKeyboardView_longPressShiftLockTimeout, 0);
mIgnoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
mGestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt(
@@ -235,17 +217,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
startWhileTypingFadeinAnimation(keyboardView);
break;
case MSG_REPEAT_KEY:
- final Key currentKey = tracker.getKey();
- final int code = msg.arg1;
- if (currentKey != null && currentKey.mCode == code) {
- startKeyRepeatTimer(tracker, mKeyRepeatInterval);
- startTypingStateTimer(currentKey);
- final KeyboardActionListener listener =
- keyboardView.getKeyboardActionListener();
- listener.onPressKey(code, true /* isRepeatKey */, true /* isSinglePointer */);
- listener.onCodeInput(code,
- Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
- }
+ tracker.onKeyRepeat(msg.arg1);
break;
case MSG_LONGPRESS_KEY:
keyboardView.onLongPress(tracker);
@@ -257,19 +229,15 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
}
- private void startKeyRepeatTimer(final PointerTracker tracker, final long delay) {
+ @Override
+ public void startKeyRepeatTimer(final PointerTracker tracker, final int delay) {
final Key key = tracker.getKey();
- if (key == null) {
+ if (key == null || delay == 0) {
return;
}
sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY, key.mCode, 0, tracker), delay);
}
- @Override
- public void startKeyRepeatTimer(final PointerTracker tracker) {
- startKeyRepeatTimer(tracker, mKeyRepeatStartTimeout);
- }
-
public void cancelKeyRepeatTimer() {
removeMessages(MSG_REPEAT_KEY);
}
@@ -280,31 +248,10 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
@Override
- public void startLongPressTimer(final PointerTracker tracker) {
+ public void startLongPressTimer(final PointerTracker tracker, final int delay) {
cancelLongPressTimer();
- if (tracker == null) {
- return;
- }
- final Key key = tracker.getKey();
- final int delay;
- switch (key.mCode) {
- case Constants.CODE_SHIFT:
- delay = mLongPressShiftLockTimeout;
- break;
- default:
- final int longpressTimeout =
- Settings.getInstance().getCurrent().mKeyLongpressTimeout;
- if (tracker.isInSlidingKeyInputFromModifier()) {
- // We use longer timeout for sliding finger input started from the modifier key.
- delay = longpressTimeout * 3;
- } else {
- delay = longpressTimeout;
- }
- break;
- }
- if (delay > 0) {
- sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, tracker), delay);
- }
+ if (delay <= 0) return;
+ sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, tracker), delay);
}
@Override
@@ -475,15 +422,16 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
public MainKeyboardView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
- mTouchScreenRegulator = new TouchScreenRegulator(context, this);
-
+ PointerTracker.init(getResources());
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final boolean forceNonDistinctMultitouch = prefs.getBoolean(
DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, false);
final boolean hasDistinctMultitouch = context.getPackageManager()
- .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT);
- mHasDistinctMultitouch = hasDistinctMultitouch && !forceNonDistinctMultitouch;
- PointerTracker.init(getResources());
+ .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT)
+ && !forceNonDistinctMultitouch;
+ mNonDistinctMultitouchHelper = hasDistinctMultitouch ? null
+ : new NonDistinctMultitouchHelper();
+
mPreviewPlacerView = new PreviewPlacerView(context, attrs);
final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes(
@@ -564,6 +512,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mKeyboardActionListener = KeyboardActionListener.EMPTY_LISTENER;
}
+ @Override
+ public void setHardwareAcceleratedDrawingEnabled(final boolean enabled) {
+ super.setHardwareAcceleratedDrawingEnabled(enabled);
+ mPreviewPlacerView.setHardwareAcceleratedDrawingEnabled(enabled);
+ }
+
private ObjectAnimator loadObjectAnimator(final int resId, final Object target) {
if (resId == 0) {
// TODO: Stop returning null.
@@ -653,7 +607,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mKeyDetector.setKeyboard(
keyboard, -getPaddingLeft(), -getPaddingTop() + getVerticalCorrection());
PointerTracker.setKeyDetector(mKeyDetector);
- mTouchScreenRegulator.setKeyboardGeometry(keyboard.mOccupiedWidth);
mMoreKeysKeyboardCache.clear();
mSpaceKey = keyboard.getKey(Constants.CODE_SPACE);
@@ -901,9 +854,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
@Override
- public void showGestureTrail(final PointerTracker tracker) {
+ public void showGestureTrail(final PointerTracker tracker,
+ final boolean showsFloatingPreviewText) {
locatePreviewPlacerView();
- mGestureFloatingPreviewText.setPreviewPosition(tracker);
+ if (showsFloatingPreviewText) {
+ mGestureFloatingPreviewText.setPreviewPosition(tracker);
+ }
mGestureTrailsPreview.setPreviewPosition(tracker);
}
@@ -1059,6 +1015,18 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
}
+ public void startDoubleTapShiftKeyTimer() {
+ mKeyTimerHandler.startDoubleTapShiftKeyTimer();
+ }
+
+ public void cancelDoubleTapShiftKeyTimer() {
+ mKeyTimerHandler.cancelDoubleTapShiftKeyTimer();
+ }
+
+ public boolean isInDoubleTapShiftKeyTimeout() {
+ return mKeyTimerHandler.isInDoubleTapShiftKeyTimeout();
+ }
+
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) {
@@ -1072,140 +1040,34 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
if (getKeyboard() == null) {
return false;
}
- return mTouchScreenRegulator.onTouchEvent(me);
- }
-
- @Override
- public boolean processMotionEvent(final MotionEvent me) {
- final boolean nonDistinctMultitouch = !mHasDistinctMultitouch;
- final int action = me.getActionMasked();
- final int pointerCount = me.getPointerCount();
- final int oldPointerCount = mOldPointerCount;
- mOldPointerCount = pointerCount;
-
- // 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 (nonDistinctMultitouch && pointerCount > 1 && oldPointerCount > 1) {
+ if (mNonDistinctMultitouchHelper != null) {
+ if (me.getPointerCount() > 1 && mKeyTimerHandler.isInKeyRepeat()) {
+ // Key repeating timer will be canceled if 2 or more keys are in action.
+ mKeyTimerHandler.cancelKeyRepeatTimer();
+ }
+ // Non distinct multitouch screen support
+ mNonDistinctMultitouchHelper.processMotionEvent(me, this);
return true;
}
+ return processMotionEvent(me);
+ }
- final long eventTime = me.getEventTime();
- final int index = me.getActionIndex();
- final int id = me.getPointerId(index);
- final int x = (int)me.getX(index);
- final int y = (int)me.getY(index);
-
- // TODO: This might be moved to the tracker.processMotionEvent() call below.
- if (ENABLE_USABILITY_STUDY_LOG && action != MotionEvent.ACTION_MOVE) {
- writeUsabilityStudyLog(me, action, eventTime, index, id, x, y);
+ public boolean processMotionEvent(final MotionEvent me) {
+ if (LatinImeLogger.sUsabilityStudy) {
+ UsabilityStudyLogUtils.writeMotionEvent(me);
}
- // TODO: This should be moved to the tracker.processMotionEvent() call below.
// Currently the same "move" event is being logged twice.
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
- ResearchLogger.mainKeyboardView_processMotionEvent(
- me, action, eventTime, index, id, x, y);
- }
-
- if (mKeyTimerHandler.isInKeyRepeat()) {
- final PointerTracker tracker = PointerTracker.getPointerTracker(id, this);
- // Key repeating timer will be canceled if 2 or more keys are in action, and current
- // event (UP or DOWN) is non-modifier key.
- if (pointerCount > 1 && !tracker.isModifier()) {
- mKeyTimerHandler.cancelKeyRepeatTimer();
- }
- // 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 (nonDistinctMultitouch) {
- // Use only main (id=0) pointer tracker.
- final PointerTracker tracker = PointerTracker.getPointerTracker(0, this);
- if (pointerCount == 1 && oldPointerCount == 2) {
- // Multi-touch to single touch transition.
- // Send a down event for the latest pointer if the key is different from the
- // previous key.
- final Key newKey = tracker.getKeyOn(x, y);
- if (mOldKey != newKey) {
- tracker.onDownEvent(x, y, eventTime, this);
- if (action == MotionEvent.ACTION_UP) {
- tracker.onUpEvent(x, y, eventTime);
- }
- }
- } else if (pointerCount == 2 && oldPointerCount == 1) {
- // Single-touch to multi-touch transition.
- // Send an up event for the last pointer.
- final int[] lastCoords = CoordinateUtils.newInstance();
- mOldKey = tracker.getKeyOn(
- CoordinateUtils.x(lastCoords), CoordinateUtils.y(lastCoords));
- tracker.onUpEvent(
- CoordinateUtils.x(lastCoords), CoordinateUtils.y(lastCoords), eventTime);
- } else if (pointerCount == 1 && oldPointerCount == 1) {
- tracker.processMotionEvent(action, x, y, eventTime, this);
- } else {
- Log.w(TAG, "Unknown touch panel behavior: pointer count is " + pointerCount
- + " (old " + oldPointerCount + ")");
- }
- return true;
- }
-
- if (action == MotionEvent.ACTION_MOVE) {
- for (int i = 0; i < pointerCount; i++) {
- final int pointerId = me.getPointerId(i);
- final PointerTracker tracker = PointerTracker.getPointerTracker(
- pointerId, this);
- final int px = (int)me.getX(i);
- final int py = (int)me.getY(i);
- tracker.onMoveEvent(px, py, eventTime, me);
- if (ENABLE_USABILITY_STUDY_LOG) {
- writeUsabilityStudyLog(me, action, eventTime, i, pointerId, px, py);
- }
- // TODO: This seems to be no longer necessary, and confusing because it leads to
- // duplicate MotionEvents being recorded.
- // if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
- // ResearchLogger.mainKeyboardView_processMotionEvent(
- // me, action, eventTime, i, pointerId, px, py);
- // }
- }
- } else {
- final PointerTracker tracker = PointerTracker.getPointerTracker(id, this);
- tracker.processMotionEvent(action, x, y, eventTime, this);
+ ResearchLogger.mainKeyboardView_processMotionEvent(me);
}
+ final int index = me.getActionIndex();
+ final int id = me.getPointerId(index);
+ final PointerTracker tracker = PointerTracker.getPointerTracker(id, this);
+ tracker.processMotionEvent(me, this);
return true;
}
- private static void writeUsabilityStudyLog(final MotionEvent me, final int action,
- final long eventTime, final int index, final int id, final int x, final int y) {
- final String eventTag;
- switch (action) {
- case MotionEvent.ACTION_UP:
- eventTag = "[Up]";
- break;
- case MotionEvent.ACTION_DOWN:
- eventTag = "[Down]";
- break;
- case MotionEvent.ACTION_POINTER_UP:
- eventTag = "[PointerUp]";
- break;
- case MotionEvent.ACTION_POINTER_DOWN:
- eventTag = "[PointerDown]";
- break;
- case MotionEvent.ACTION_MOVE:
- eventTag = "[Move]";
- break;
- default:
- eventTag = "[Action" + action + "]";
- break;
- }
- final float size = me.getSize(index);
- final float pressure = me.getPressure(index);
- UsabilityStudyLogUtils.getInstance().write(
- eventTag + eventTime + "," + id + "," + x + "," + y + "," + size + "," + pressure);
- }
-
public void cancelAllOngoingEvents() {
mKeyTimerHandler.cancelAllMessages();
mDrawingHandler.cancelAllMessages();
@@ -1398,4 +1260,10 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
drawIcon(canvas, mSpaceIcon, x, y, iconWidth, iconHeight);
}
}
+
+ @Override
+ public void deallocateMemory() {
+ super.deallocateMemory();
+ mGestureTrailsPreview.deallocateMemory();
+ }
}