Move some XML attributes to KeyPreviewDrawParams
Change-Id: I0e040b3aed63f8da983fcc51d55b55ac9294a16amain
parent
992c521909
commit
7d09b56812
|
@ -161,16 +161,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;
|
|
||||||
// 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;
|
private final KeyPreviewDrawParams mKeyPreviewDrawParams;
|
||||||
private boolean mShowKeyPreviewPopup = true;
|
|
||||||
private int mKeyPreviewLingerTimeout;
|
|
||||||
private int mKeyPreviewZoomInDuration;
|
|
||||||
private int mKeyPreviewZoomOutDuration;
|
|
||||||
private static final float KEY_PREVIEW_START_ZOOM_IN_SCALE = 0.7f;
|
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_IN_SCALE = 1.0f;
|
||||||
private static final float KEY_PREVIEW_END_ZOOM_OUT_SCALE = 0.7f;
|
private static final float KEY_PREVIEW_END_ZOOM_OUT_SCALE = 0.7f;
|
||||||
|
@ -266,17 +261,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator, 0);
|
R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator, 0);
|
||||||
|
|
||||||
mKeyPreviewDrawParams = new KeyPreviewDrawParams(mainKeyboardViewAttr);
|
mKeyPreviewDrawParams = new KeyPreviewDrawParams(mainKeyboardViewAttr);
|
||||||
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);
|
|
||||||
final int moreKeysKeyboardLayoutId = mainKeyboardViewAttr.getResourceId(
|
final int moreKeysKeyboardLayoutId = mainKeyboardViewAttr.getResourceId(
|
||||||
R.styleable.MainKeyboardView_moreKeysKeyboardLayout, 0);
|
R.styleable.MainKeyboardView_moreKeysKeyboardLayout, 0);
|
||||||
mConfigShowMoreKeysKeyboardAtTouchedPoint = mainKeyboardViewAttr.getBoolean(
|
mConfigShowMoreKeysKeyboardAtTouchedPoint = mainKeyboardViewAttr.getBoolean(
|
||||||
|
@ -450,8 +434,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
* @see #isKeyPreviewPopupEnabled()
|
* @see #isKeyPreviewPopupEnabled()
|
||||||
*/
|
*/
|
||||||
public void setKeyPreviewPopupEnabled(final boolean previewEnabled, final int delay) {
|
public void setKeyPreviewPopupEnabled(final boolean previewEnabled, final int delay) {
|
||||||
mShowKeyPreviewPopup = previewEnabled;
|
mKeyPreviewDrawParams.setPopupEnabled(previewEnabled, delay);
|
||||||
mKeyPreviewLingerTimeout = delay;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void locatePreviewPlacerView() {
|
private void locatePreviewPlacerView() {
|
||||||
|
@ -491,7 +474,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
* @see #setKeyPreviewPopupEnabled(boolean, int)
|
* @see #setKeyPreviewPopupEnabled(boolean, int)
|
||||||
*/
|
*/
|
||||||
public boolean isKeyPreviewPopupEnabled() {
|
public boolean isKeyPreviewPopupEnabled() {
|
||||||
return mShowKeyPreviewPopup;
|
return mKeyPreviewDrawParams.isPopupEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
private TextView getKeyPreviewTextView(final Key key) {
|
private TextView getKeyPreviewTextView(final Key key) {
|
||||||
|
@ -504,9 +487,10 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
return previewTextView;
|
return previewTextView;
|
||||||
}
|
}
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (mKeyPreviewLayoutId != 0) {
|
final int previewLayoutId = mKeyPreviewDrawParams.mLayoutId;
|
||||||
|
if (previewLayoutId != 0) {
|
||||||
previewTextView = (TextView)LayoutInflater.from(context)
|
previewTextView = (TextView)LayoutInflater.from(context)
|
||||||
.inflate(mKeyPreviewLayoutId, null);
|
.inflate(previewLayoutId, null);
|
||||||
} else {
|
} else {
|
||||||
previewTextView = new TextView(context);
|
previewTextView = new TextView(context);
|
||||||
}
|
}
|
||||||
|
@ -558,7 +542,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 (!previewParams.isPopupEnabled()) {
|
||||||
previewParams.setVisibleOffset(-keyboard.mVerticalGap);
|
previewParams.setVisibleOffset(-keyboard.mVerticalGap);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -586,7 +570,7 @@ 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 = previewParams.mKeyPreviewHeight;
|
final int previewHeight = previewParams.mPreviewHeight;
|
||||||
previewParams.setGeometry(previewTextView);
|
previewParams.setGeometry(previewTextView);
|
||||||
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
|
||||||
|
@ -606,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
|
// 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 + previewParams.mKeyPreviewOffset
|
final int previewY = key.getY() - previewHeight + previewParams.mPreviewOffset
|
||||||
+ CoordinateUtils.y(mOriginCoords);
|
+ CoordinateUtils.y(mOriginCoords);
|
||||||
|
|
||||||
if (background != null) {
|
if (background != null) {
|
||||||
|
@ -670,7 +654,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
final AnimatorSet zoomInAnimation = new AnimatorSet();
|
final AnimatorSet zoomInAnimation = new AnimatorSet();
|
||||||
zoomInAnimation.play(scaleXAnimation).with(scaleYAnimation);
|
zoomInAnimation.play(scaleXAnimation).with(scaleYAnimation);
|
||||||
// TODO: Implement preference option to control key preview animation duration.
|
// TODO: Implement preference option to control key preview animation duration.
|
||||||
zoomInAnimation.setDuration(mKeyPreviewZoomInDuration);
|
zoomInAnimation.setDuration(mKeyPreviewDrawParams.mZoomInDuration);
|
||||||
zoomInAnimation.setInterpolator(DECELERATE_INTERPOLATOR);
|
zoomInAnimation.setInterpolator(DECELERATE_INTERPOLATOR);
|
||||||
zoomInAnimation.addListener(new AnimatorListenerAdapter() {
|
zoomInAnimation.addListener(new AnimatorListenerAdapter() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -691,7 +675,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
final AnimatorSet zoomOutAnimation = new AnimatorSet();
|
final AnimatorSet zoomOutAnimation = new AnimatorSet();
|
||||||
zoomOutAnimation.play(scaleXAnimation).with(scaleYAnimation);
|
zoomOutAnimation.play(scaleXAnimation).with(scaleYAnimation);
|
||||||
// TODO: Implement preference option to control key preview animation duration.
|
// 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.setDuration(zoomOutDuration);
|
||||||
zoomOutAnimation.setInterpolator(ACCELERATE_INTERPOLATOR);
|
zoomOutAnimation.setInterpolator(ACCELERATE_INTERPOLATOR);
|
||||||
zoomOutAnimation.addListener(new AnimatorListenerAdapter() {
|
zoomOutAnimation.addListener(new AnimatorListenerAdapter() {
|
||||||
|
@ -733,7 +718,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
}
|
}
|
||||||
if (!isHardwareAccelerated()) {
|
if (!isHardwareAccelerated()) {
|
||||||
// TODO: Implement preference option to control key preview method and duration.
|
// TODO: Implement preference option to control key preview method and duration.
|
||||||
mDrawingHandler.dismissKeyPreview(mKeyPreviewLingerTimeout, key);
|
mDrawingHandler.dismissKeyPreview(mKeyPreviewDrawParams.getLingerTimeout(), key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Object tag = previewTextView.getTag();
|
final Object tag = previewTextView.getTag();
|
||||||
|
|
|
@ -23,8 +23,13 @@ import com.android.inputmethod.latin.R;
|
||||||
|
|
||||||
public final class KeyPreviewDrawParams {
|
public final class KeyPreviewDrawParams {
|
||||||
// XML attributes of {@link MainKeyboardView}.
|
// XML attributes of {@link MainKeyboardView}.
|
||||||
public final int mKeyPreviewOffset;
|
public final int mLayoutId;
|
||||||
public final int mKeyPreviewHeight;
|
public final int mPreviewOffset;
|
||||||
|
public final int mPreviewHeight;
|
||||||
|
public final int mZoomInDuration;
|
||||||
|
public final int mZoomOutDuration;
|
||||||
|
private int mLingerTimeout;
|
||||||
|
private boolean mShowPopup = true;
|
||||||
|
|
||||||
// The graphical geometry of the key preview.
|
// The graphical geometry of the key preview.
|
||||||
// <-width->
|
// <-width->
|
||||||
|
@ -52,10 +57,21 @@ public final class KeyPreviewDrawParams {
|
||||||
private int mVisibleOffset;
|
private int mVisibleOffset;
|
||||||
|
|
||||||
public KeyPreviewDrawParams(final TypedArray mainKeyboardViewAttr) {
|
public KeyPreviewDrawParams(final TypedArray mainKeyboardViewAttr) {
|
||||||
mKeyPreviewOffset = mainKeyboardViewAttr.getDimensionPixelOffset(
|
mPreviewOffset = mainKeyboardViewAttr.getDimensionPixelOffset(
|
||||||
R.styleable.MainKeyboardView_keyPreviewOffset, 0);
|
R.styleable.MainKeyboardView_keyPreviewOffset, 0);
|
||||||
mKeyPreviewHeight = mainKeyboardViewAttr.getDimensionPixelSize(
|
mPreviewHeight = mainKeyboardViewAttr.getDimensionPixelSize(
|
||||||
R.styleable.MainKeyboardView_keyPreviewHeight, 0);
|
R.styleable.MainKeyboardView_keyPreviewHeight, 0);
|
||||||
|
mLingerTimeout = mainKeyboardViewAttr.getInt(
|
||||||
|
R.styleable.MainKeyboardView_keyPreviewLingerTimeout, 0);
|
||||||
|
mLayoutId = mainKeyboardViewAttr.getResourceId(
|
||||||
|
R.styleable.MainKeyboardView_keyPreviewLayout, 0);
|
||||||
|
if (mLayoutId == 0) {
|
||||||
|
mShowPopup = false;
|
||||||
|
}
|
||||||
|
mZoomInDuration = mainKeyboardViewAttr.getInt(
|
||||||
|
R.styleable.MainKeyboardView_keyPreviewZoomInDuration, 0);
|
||||||
|
mZoomOutDuration = mainKeyboardViewAttr.getInt(
|
||||||
|
R.styleable.MainKeyboardView_keyPreviewZoomOutDuration, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisibleOffset(final int previewVisibleOffset) {
|
public void setVisibleOffset(final int previewVisibleOffset) {
|
||||||
|
@ -68,7 +84,7 @@ public final class KeyPreviewDrawParams {
|
||||||
|
|
||||||
public void setGeometry(final View previewTextView) {
|
public void setGeometry(final View previewTextView) {
|
||||||
final int previewWidth = previewTextView.getMeasuredWidth();
|
final int previewWidth = previewTextView.getMeasuredWidth();
|
||||||
final int previewHeight = mKeyPreviewHeight;
|
final int previewHeight = mPreviewHeight;
|
||||||
// The width and height of visible part of the key preview background. The content marker
|
// 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.
|
// of the background 9-patch have to cover the visible part of the background.
|
||||||
mVisibleWidth = previewWidth - previewTextView.getPaddingLeft()
|
mVisibleWidth = previewWidth - previewTextView.getPaddingLeft()
|
||||||
|
@ -77,7 +93,7 @@ public final class KeyPreviewDrawParams {
|
||||||
- previewTextView.getPaddingBottom();
|
- previewTextView.getPaddingBottom();
|
||||||
// The distance between the top edge of the parent key and the bottom of the visible part
|
// The distance between the top edge of the parent key and the bottom of the visible part
|
||||||
// of the key preview background.
|
// of the key preview background.
|
||||||
setVisibleOffset(mKeyPreviewOffset - previewTextView.getPaddingBottom());
|
setVisibleOffset(mPreviewOffset - previewTextView.getPaddingBottom());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getVisibleWidth() {
|
public int getVisibleWidth() {
|
||||||
|
@ -87,4 +103,17 @@ public final class KeyPreviewDrawParams {
|
||||||
public int getVisibleHeight() {
|
public int getVisibleHeight() {
|
||||||
return mVisibleHeight;
|
return mVisibleHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPopupEnabled(final boolean enabled, final int lingerTimeout) {
|
||||||
|
mShowPopup = enabled;
|
||||||
|
mLingerTimeout = lingerTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPopupEnabled() {
|
||||||
|
return mShowPopup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLingerTimeout() {
|
||||||
|
return mLingerTimeout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue