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.java63
1 files changed, 17 insertions, 46 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index 3a2869950..c6dae3253 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -161,18 +161,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 boolean mShowKeyPreviewPopup = true;
- private int mKeyPreviewLingerTimeout;
- private int mKeyPreviewZoomInDuration;
- private int mKeyPreviewZoomOutDuration;
+ private final KeyPreviewDrawParams mKeyPreviewDrawParams;
private static final float KEY_PREVIEW_START_ZOOM_IN_SCALE = 0.7f;
private static final float KEY_PREVIEW_END_ZOOM_IN_SCALE = 1.0f;
private static final float KEY_PREVIEW_END_ZOOM_OUT_SCALE = 0.7f;
@@ -267,21 +260,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);
- mKeyPreviewLingerTimeout = mainKeyboardViewAttr.getInt(
- R.styleable.MainKeyboardView_keyPreviewLingerTimeout, 0);
- mKeyPreviewLayoutId = mainKeyboardViewAttr.getResourceId(
- R.styleable.MainKeyboardView_keyPreviewLayout, 0);
- if (mKeyPreviewLayoutId == 0) {
- mShowKeyPreviewPopup = false;
- }
- mKeyPreviewZoomInDuration = mainKeyboardViewAttr.getInt(
- R.styleable.MainKeyboardView_keyPreviewZoomInDuration, 0);
- mKeyPreviewZoomOutDuration = mainKeyboardViewAttr.getInt(
- R.styleable.MainKeyboardView_keyPreviewZoomOutDuration, 0);
+ mKeyPreviewDrawParams = new KeyPreviewDrawParams(mainKeyboardViewAttr);
final int moreKeysKeyboardLayoutId = mainKeyboardViewAttr.getResourceId(
R.styleable.MainKeyboardView_moreKeysKeyboardLayout, 0);
mConfigShowMoreKeysKeyboardAtTouchedPoint = mainKeyboardViewAttr.getBoolean(
@@ -455,8 +434,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
* @see #isKeyPreviewPopupEnabled()
*/
public void setKeyPreviewPopupEnabled(final boolean previewEnabled, final int delay) {
- mShowKeyPreviewPopup = previewEnabled;
- mKeyPreviewLingerTimeout = delay;
+ mKeyPreviewDrawParams.setPopupEnabled(previewEnabled, delay);
}
private void locatePreviewPlacerView() {
@@ -496,7 +474,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
* @see #setKeyPreviewPopupEnabled(boolean, int)
*/
public boolean isKeyPreviewPopupEnabled() {
- return mShowKeyPreviewPopup;
+ return mKeyPreviewDrawParams.isPopupEnabled();
}
private TextView getKeyPreviewTextView(final Key key) {
@@ -509,9 +487,10 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
return previewTextView;
}
final Context context = getContext();
- if (mKeyPreviewLayoutId != 0) {
+ final int previewLayoutId = mKeyPreviewDrawParams.mLayoutId;
+ if (previewLayoutId != 0) {
previewTextView = (TextView)LayoutInflater.from(context)
- .inflate(mKeyPreviewLayoutId, null);
+ .inflate(previewLayoutId, null);
} else {
previewTextView = new TextView(context);
}
@@ -563,8 +542,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
final KeyPreviewDrawParams previewParams = mKeyPreviewDrawParams;
final Keyboard keyboard = getKeyboard();
- if (!mShowKeyPreviewPopup) {
- previewParams.mPreviewVisibleOffset = -keyboard.mVerticalGap;
+ if (!previewParams.isPopupEnabled()) {
+ previewParams.setVisibleOffset(-keyboard.mVerticalGap);
return;
}
@@ -591,17 +570,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.mPreviewHeight;
+ 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 +590,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.mPreviewOffset
+ CoordinateUtils.y(mOriginCoords);
if (background != null) {
@@ -684,7 +654,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
final AnimatorSet zoomInAnimation = new AnimatorSet();
zoomInAnimation.play(scaleXAnimation).with(scaleYAnimation);
// TODO: Implement preference option to control key preview animation duration.
- zoomInAnimation.setDuration(mKeyPreviewZoomInDuration);
+ zoomInAnimation.setDuration(mKeyPreviewDrawParams.mZoomInDuration);
zoomInAnimation.setInterpolator(DECELERATE_INTERPOLATOR);
zoomInAnimation.addListener(new AnimatorListenerAdapter() {
@Override
@@ -705,7 +675,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
final AnimatorSet zoomOutAnimation = new AnimatorSet();
zoomOutAnimation.play(scaleXAnimation).with(scaleYAnimation);
// TODO: Implement preference option to control key preview animation duration.
- final int zoomOutDuration = Math.min(mKeyPreviewZoomOutDuration, mKeyPreviewLingerTimeout);
+ final int zoomOutDuration = Math.min(mKeyPreviewDrawParams.mZoomOutDuration,
+ mKeyPreviewDrawParams.getLingerTimeout());
zoomOutAnimation.setDuration(zoomOutDuration);
zoomOutAnimation.setInterpolator(ACCELERATE_INTERPOLATOR);
zoomOutAnimation.addListener(new AnimatorListenerAdapter() {
@@ -747,7 +718,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
if (!isHardwareAccelerated()) {
// TODO: Implement preference option to control key preview method and duration.
- mDrawingHandler.dismissKeyPreview(mKeyPreviewLingerTimeout, key);
+ mDrawingHandler.dismissKeyPreview(mKeyPreviewDrawParams.getLingerTimeout(), key);
return;
}
final Object tag = previewTextView.getTag();
@@ -914,7 +885,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.