mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Merge "Refactor KeyPreviewDrawParams a bit"
This commit is contained in:
commit
f7d682cce1
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user