aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/MainKeyboardView.java28
-rw-r--r--java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java6
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyPreviewDrawParams.java52
-rw-r--r--java/src/com/android/inputmethod/latin/InputPointers.java11
4 files changed, 68 insertions, 29 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index 3a2869950..54cff3723 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -162,13 +162,11 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
// Key preview
private static final boolean FADE_OUT_KEY_TOP_LETTER_WHEN_KEY_IS_PRESSED = false;
private final int mKeyPreviewLayoutId;
- private final int mKeyPreviewOffset;
- private final int mKeyPreviewHeight;
// Free {@link TextView} pool that can be used for key preview.
private final ArrayDeque<TextView> mFreeKeyPreviewTextViews = CollectionUtils.newArrayDeque();
// Map from {@link Key} to {@link TextView} that is currently being displayed as key preview.
private final HashMap<Key,TextView> mShowingKeyPreviewTextViews = CollectionUtils.newHashMap();
- private final KeyPreviewDrawParams mKeyPreviewDrawParams = new KeyPreviewDrawParams();
+ private final KeyPreviewDrawParams mKeyPreviewDrawParams;
private boolean mShowKeyPreviewPopup = true;
private int mKeyPreviewLingerTimeout;
private int mKeyPreviewZoomInDuration;
@@ -267,10 +265,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
final int altCodeKeyWhileTypingFadeinAnimatorResId = mainKeyboardViewAttr.getResourceId(
R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator, 0);
- mKeyPreviewOffset = mainKeyboardViewAttr.getDimensionPixelOffset(
- R.styleable.MainKeyboardView_keyPreviewOffset, 0);
- mKeyPreviewHeight = mainKeyboardViewAttr.getDimensionPixelSize(
- R.styleable.MainKeyboardView_keyPreviewHeight, 0);
+ mKeyPreviewDrawParams = new KeyPreviewDrawParams(mainKeyboardViewAttr);
mKeyPreviewLingerTimeout = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_keyPreviewLingerTimeout, 0);
mKeyPreviewLayoutId = mainKeyboardViewAttr.getResourceId(
@@ -564,7 +559,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
final KeyPreviewDrawParams previewParams = mKeyPreviewDrawParams;
final Keyboard keyboard = getKeyboard();
if (!mShowKeyPreviewPopup) {
- previewParams.mPreviewVisibleOffset = -keyboard.mVerticalGap;
+ previewParams.setVisibleOffset(-keyboard.mVerticalGap);
return;
}
@@ -591,17 +586,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final int keyDrawWidth = key.getDrawWidth();
final int previewWidth = previewTextView.getMeasuredWidth();
- final int previewHeight = mKeyPreviewHeight;
- // The width and height of visible part of the key preview background. The content marker
- // of the background 9-patch have to cover the visible part of the background.
- previewParams.mPreviewVisibleWidth = previewWidth - previewTextView.getPaddingLeft()
- - previewTextView.getPaddingRight();
- previewParams.mPreviewVisibleHeight = previewHeight - previewTextView.getPaddingTop()
- - previewTextView.getPaddingBottom();
- // The distance between the top edge of the parent key and the bottom of the visible part
- // of the key preview background.
- previewParams.mPreviewVisibleOffset =
- mKeyPreviewOffset - previewTextView.getPaddingBottom();
+ final int previewHeight = previewParams.mKeyPreviewHeight;
+ previewParams.setGeometry(previewTextView);
getLocationInWindow(mOriginCoords);
// The key preview is horizontally aligned with the center of the visible part of the
// parent key. If it doesn't fit in this {@link KeyboardView}, it is moved inward to fit and
@@ -620,7 +606,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
// The key preview is placed vertically above the top edge of the parent key with an
// arbitrary offset.
- final int previewY = key.getY() - previewHeight + mKeyPreviewOffset
+ final int previewY = key.getY() - previewHeight + previewParams.mKeyPreviewOffset
+ CoordinateUtils.y(mOriginCoords);
if (background != null) {
@@ -914,7 +900,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
// aligned with the bottom edge of the visible part of the key preview.
// {@code mPreviewVisibleOffset} has been set appropriately in
// {@link KeyboardView#showKeyPreview(PointerTracker)}.
- final int pointY = key.getY() + mKeyPreviewDrawParams.mPreviewVisibleOffset;
+ final int pointY = key.getY() + mKeyPreviewDrawParams.getVisibleOffset();
moreKeysPanel.showMoreKeysPanel(this, this, pointX, pointY, mKeyboardActionListener);
tracker.onShowMoreKeysPanel(moreKeysPanel);
// TODO: Implement zoom in animation of more keys panel.
diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java
index 670524380..2bff107eb 100644
--- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java
@@ -285,7 +285,7 @@ public final class MoreKeysKeyboard extends Keyboard {
// {@link MoreKeysKeyboardParams#setParameters(int,int,int,int,int,int,boolean,int)}.
final boolean singleMoreKeyWithPreview = parentKeyboardView.isKeyPreviewPopupEnabled()
&& !parentKey.noKeyPreview() && moreKeys.length == 1
- && keyPreviewDrawParams.mPreviewVisibleWidth > 0;
+ && keyPreviewDrawParams.getVisibleWidth() > 0;
if (singleMoreKeyWithPreview) {
// Use pre-computed width and height if this more keys keyboard has only one key to
// mitigate visual flicker between key preview and more keys keyboard.
@@ -294,8 +294,8 @@ public final class MoreKeysKeyboard extends Keyboard {
// left/right/top paddings. The bottom paddings of both backgrounds don't need to
// be considered because the vertical positions of both backgrounds were already
// adjusted with their bottom paddings deducted.
- width = keyPreviewDrawParams.mPreviewVisibleWidth;
- height = keyPreviewDrawParams.mPreviewVisibleHeight + mParams.mVerticalGap;
+ width = keyPreviewDrawParams.getVisibleWidth();
+ height = keyPreviewDrawParams.getVisibleHeight() + mParams.mVerticalGap;
} else {
final float padding = context.getResources().getDimension(
R.dimen.config_more_keys_keyboard_key_horizontal_padding)
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewDrawParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewDrawParams.java
index 609d1a57f..d7518ee7c 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewDrawParams.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewDrawParams.java
@@ -16,7 +16,16 @@
package com.android.inputmethod.keyboard.internal;
+import android.content.res.TypedArray;
+import android.view.View;
+
+import com.android.inputmethod.latin.R;
+
public final class KeyPreviewDrawParams {
+ // XML attributes of {@link MainKeyboardView}.
+ public final int mKeyPreviewOffset;
+ public final int mKeyPreviewHeight;
+
// The graphical geometry of the key preview.
// <-width->
// +-------+ ^
@@ -34,11 +43,48 @@ public final class KeyPreviewDrawParams {
// paddings. To align the more keys keyboard panel's visible part with the visible part of
// the background, we need to record the width and height of key preview that don't include
// invisible paddings.
- public int mPreviewVisibleWidth;
- public int mPreviewVisibleHeight;
+ private int mVisibleWidth;
+ private int mVisibleHeight;
// The key preview may have an arbitrary offset and its background that may have a bottom
// padding. To align the more keys keyboard and the key preview we also need to record the
// offset between the top edge of parent key and the bottom of the visible part of key
// preview background.
- public int mPreviewVisibleOffset;
+ private int mVisibleOffset;
+
+ public KeyPreviewDrawParams(final TypedArray mainKeyboardViewAttr) {
+ mKeyPreviewOffset = mainKeyboardViewAttr.getDimensionPixelOffset(
+ R.styleable.MainKeyboardView_keyPreviewOffset, 0);
+ mKeyPreviewHeight = mainKeyboardViewAttr.getDimensionPixelSize(
+ R.styleable.MainKeyboardView_keyPreviewHeight, 0);
+ }
+
+ public void setVisibleOffset(final int previewVisibleOffset) {
+ mVisibleOffset = previewVisibleOffset;
+ }
+
+ public int getVisibleOffset() {
+ return mVisibleOffset;
+ }
+
+ public void setGeometry(final View previewTextView) {
+ final int previewWidth = previewTextView.getMeasuredWidth();
+ final int previewHeight = mKeyPreviewHeight;
+ // The width and height of visible part of the key preview background. The content marker
+ // of the background 9-patch have to cover the visible part of the background.
+ mVisibleWidth = previewWidth - previewTextView.getPaddingLeft()
+ - previewTextView.getPaddingRight();
+ mVisibleHeight = previewHeight - previewTextView.getPaddingTop()
+ - previewTextView.getPaddingBottom();
+ // The distance between the top edge of the parent key and the bottom of the visible part
+ // of the key preview background.
+ setVisibleOffset(mKeyPreviewOffset - previewTextView.getPaddingBottom());
+ }
+
+ public int getVisibleWidth() {
+ return mVisibleWidth;
+ }
+
+ public int getVisibleHeight() {
+ return mVisibleHeight;
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/InputPointers.java b/java/src/com/android/inputmethod/latin/InputPointers.java
index c3bcf3785..47bc6b078 100644
--- a/java/src/com/android/inputmethod/latin/InputPointers.java
+++ b/java/src/com/android/inputmethod/latin/InputPointers.java
@@ -17,6 +17,7 @@
package com.android.inputmethod.latin;
import android.util.Log;
+import android.util.SparseIntArray;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.utils.ResizableIntArray;
@@ -160,15 +161,21 @@ public final class InputPointers {
private boolean isValidTimeStamps() {
final int[] times = mTimes.getPrimitiveArray();
+ final int[] pointerIds = mPointerIds.getPrimitiveArray();
+ final SparseIntArray lastTimeOfPointers = new SparseIntArray();
final int size = getPointerSize();
- for (int i = 1; i < size; ++i) {
- if (times[i] < times[i - 1]) {
+ for (int i = 0; i < size; ++i) {
+ final int pointerId = pointerIds[i];
+ final int time = times[i];
+ final int lastTime = lastTimeOfPointers.get(pointerId, time);
+ if (time < lastTime) {
// dump
for (int j = 0; j < size; ++j) {
Log.d(TAG, "--- (" + j + ") " + times[j]);
}
return false;
}
+ lastTimeOfPointers.put(pointerId, time);
}
return true;
}