Merge "Refactor KeyPreviewDrawParams a bit"
This commit is contained in:
commit
f7d682cce1
3 changed files with 59 additions and 27 deletions
|
@ -162,13 +162,11 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
// Key preview
|
// Key preview
|
||||||
private static final boolean FADE_OUT_KEY_TOP_LETTER_WHEN_KEY_IS_PRESSED = false;
|
private static final boolean FADE_OUT_KEY_TOP_LETTER_WHEN_KEY_IS_PRESSED = false;
|
||||||
private final int mKeyPreviewLayoutId;
|
private final int mKeyPreviewLayoutId;
|
||||||
private final int mKeyPreviewOffset;
|
|
||||||
private final int mKeyPreviewHeight;
|
|
||||||
// Free {@link TextView} pool that can be used for key preview.
|
// Free {@link TextView} pool that can be used for key preview.
|
||||||
private final ArrayDeque<TextView> mFreeKeyPreviewTextViews = CollectionUtils.newArrayDeque();
|
private final ArrayDeque<TextView> mFreeKeyPreviewTextViews = CollectionUtils.newArrayDeque();
|
||||||
// Map from {@link Key} to {@link TextView} that is currently being displayed as key preview.
|
// 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 HashMap<Key,TextView> mShowingKeyPreviewTextViews = CollectionUtils.newHashMap();
|
||||||
private final KeyPreviewDrawParams mKeyPreviewDrawParams = new KeyPreviewDrawParams();
|
private final KeyPreviewDrawParams mKeyPreviewDrawParams;
|
||||||
private boolean mShowKeyPreviewPopup = true;
|
private boolean mShowKeyPreviewPopup = true;
|
||||||
private int mKeyPreviewLingerTimeout;
|
private int mKeyPreviewLingerTimeout;
|
||||||
private int mKeyPreviewZoomInDuration;
|
private int mKeyPreviewZoomInDuration;
|
||||||
|
@ -267,10 +265,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
final int altCodeKeyWhileTypingFadeinAnimatorResId = mainKeyboardViewAttr.getResourceId(
|
final int altCodeKeyWhileTypingFadeinAnimatorResId = mainKeyboardViewAttr.getResourceId(
|
||||||
R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator, 0);
|
R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator, 0);
|
||||||
|
|
||||||
mKeyPreviewOffset = mainKeyboardViewAttr.getDimensionPixelOffset(
|
mKeyPreviewDrawParams = new KeyPreviewDrawParams(mainKeyboardViewAttr);
|
||||||
R.styleable.MainKeyboardView_keyPreviewOffset, 0);
|
|
||||||
mKeyPreviewHeight = mainKeyboardViewAttr.getDimensionPixelSize(
|
|
||||||
R.styleable.MainKeyboardView_keyPreviewHeight, 0);
|
|
||||||
mKeyPreviewLingerTimeout = mainKeyboardViewAttr.getInt(
|
mKeyPreviewLingerTimeout = mainKeyboardViewAttr.getInt(
|
||||||
R.styleable.MainKeyboardView_keyPreviewLingerTimeout, 0);
|
R.styleable.MainKeyboardView_keyPreviewLingerTimeout, 0);
|
||||||
mKeyPreviewLayoutId = mainKeyboardViewAttr.getResourceId(
|
mKeyPreviewLayoutId = mainKeyboardViewAttr.getResourceId(
|
||||||
|
@ -564,7 +559,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
final KeyPreviewDrawParams previewParams = mKeyPreviewDrawParams;
|
final KeyPreviewDrawParams previewParams = mKeyPreviewDrawParams;
|
||||||
final Keyboard keyboard = getKeyboard();
|
final Keyboard keyboard = getKeyboard();
|
||||||
if (!mShowKeyPreviewPopup) {
|
if (!mShowKeyPreviewPopup) {
|
||||||
previewParams.mPreviewVisibleOffset = -keyboard.mVerticalGap;
|
previewParams.setVisibleOffset(-keyboard.mVerticalGap);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -591,17 +586,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
final int keyDrawWidth = key.getDrawWidth();
|
final int keyDrawWidth = key.getDrawWidth();
|
||||||
final int previewWidth = previewTextView.getMeasuredWidth();
|
final int previewWidth = previewTextView.getMeasuredWidth();
|
||||||
final int previewHeight = mKeyPreviewHeight;
|
final int previewHeight = previewParams.mKeyPreviewHeight;
|
||||||
// The width and height of visible part of the key preview background. The content marker
|
previewParams.setGeometry(previewTextView);
|
||||||
// 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();
|
|
||||||
getLocationInWindow(mOriginCoords);
|
getLocationInWindow(mOriginCoords);
|
||||||
// The key preview is horizontally aligned with the center of the visible part of the
|
// 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
|
// 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
|
// The key preview is placed vertically above the top edge of the parent key with an
|
||||||
// arbitrary offset.
|
// arbitrary offset.
|
||||||
final int previewY = key.getY() - previewHeight + mKeyPreviewOffset
|
final int previewY = key.getY() - previewHeight + previewParams.mKeyPreviewOffset
|
||||||
+ CoordinateUtils.y(mOriginCoords);
|
+ CoordinateUtils.y(mOriginCoords);
|
||||||
|
|
||||||
if (background != null) {
|
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.
|
// aligned with the bottom edge of the visible part of the key preview.
|
||||||
// {@code mPreviewVisibleOffset} has been set appropriately in
|
// {@code mPreviewVisibleOffset} has been set appropriately in
|
||||||
// {@link KeyboardView#showKeyPreview(PointerTracker)}.
|
// {@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);
|
moreKeysPanel.showMoreKeysPanel(this, this, pointX, pointY, mKeyboardActionListener);
|
||||||
tracker.onShowMoreKeysPanel(moreKeysPanel);
|
tracker.onShowMoreKeysPanel(moreKeysPanel);
|
||||||
// TODO: Implement zoom in animation of more keys panel.
|
// TODO: Implement zoom in animation of more keys panel.
|
||||||
|
|
|
@ -285,7 +285,7 @@ public final class MoreKeysKeyboard extends Keyboard {
|
||||||
// {@link MoreKeysKeyboardParams#setParameters(int,int,int,int,int,int,boolean,int)}.
|
// {@link MoreKeysKeyboardParams#setParameters(int,int,int,int,int,int,boolean,int)}.
|
||||||
final boolean singleMoreKeyWithPreview = parentKeyboardView.isKeyPreviewPopupEnabled()
|
final boolean singleMoreKeyWithPreview = parentKeyboardView.isKeyPreviewPopupEnabled()
|
||||||
&& !parentKey.noKeyPreview() && moreKeys.length == 1
|
&& !parentKey.noKeyPreview() && moreKeys.length == 1
|
||||||
&& keyPreviewDrawParams.mPreviewVisibleWidth > 0;
|
&& keyPreviewDrawParams.getVisibleWidth() > 0;
|
||||||
if (singleMoreKeyWithPreview) {
|
if (singleMoreKeyWithPreview) {
|
||||||
// Use pre-computed width and height if this more keys keyboard has only one key to
|
// 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.
|
// 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
|
// 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
|
// be considered because the vertical positions of both backgrounds were already
|
||||||
// adjusted with their bottom paddings deducted.
|
// adjusted with their bottom paddings deducted.
|
||||||
width = keyPreviewDrawParams.mPreviewVisibleWidth;
|
width = keyPreviewDrawParams.getVisibleWidth();
|
||||||
height = keyPreviewDrawParams.mPreviewVisibleHeight + mParams.mVerticalGap;
|
height = keyPreviewDrawParams.getVisibleHeight() + mParams.mVerticalGap;
|
||||||
} else {
|
} else {
|
||||||
final float padding = context.getResources().getDimension(
|
final float padding = context.getResources().getDimension(
|
||||||
R.dimen.config_more_keys_keyboard_key_horizontal_padding)
|
R.dimen.config_more_keys_keyboard_key_horizontal_padding)
|
||||||
|
|
|
@ -16,7 +16,16 @@
|
||||||
|
|
||||||
package com.android.inputmethod.keyboard.internal;
|
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 {
|
public final class KeyPreviewDrawParams {
|
||||||
|
// XML attributes of {@link MainKeyboardView}.
|
||||||
|
public final int mKeyPreviewOffset;
|
||||||
|
public final int mKeyPreviewHeight;
|
||||||
|
|
||||||
// The graphical geometry of the key preview.
|
// The graphical geometry of the key preview.
|
||||||
// <-width->
|
// <-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
|
// 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
|
// the background, we need to record the width and height of key preview that don't include
|
||||||
// invisible paddings.
|
// invisible paddings.
|
||||||
public int mPreviewVisibleWidth;
|
private int mVisibleWidth;
|
||||||
public int mPreviewVisibleHeight;
|
private int mVisibleHeight;
|
||||||
// The key preview may have an arbitrary offset and its background that may have a bottom
|
// 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
|
// 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
|
// offset between the top edge of parent key and the bottom of the visible part of key
|
||||||
// preview background.
|
// 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue