Skip to content
Snippets Groups Projects
Commit 4319d899 authored by Linus Lee's avatar Linus Lee Committed by Gerrit Code Review
Browse files

Trebuchet: Make focus animate and move faster

If you use a keyboard and hold the tab key, the focus
animation looks weird. The fix is when we focus to a new item,
jump to the item being focused out and animate from there as
opposed to animating from where the focus is currently is

ref: QRDL-978

Change-Id: I007c7566b6524dbbf748475e98ad53f9c3cbbcf5
parent ba2f9eb8
No related branches found
No related tags found
No related merge requests found
......@@ -79,39 +79,46 @@ public class FocusIndicatorView extends View implements View.OnFocusChangeListen
}
if (hasFocus) {
int indicatorWidth = getWidth();
int indicatorHeight = getHeight();
float scaleX = v.getScaleX() * v.getWidth() / indicatorWidth;
float scaleY = v.getScaleY() * v.getHeight() / indicatorHeight;
getLocationRelativeToParentPagedView(v, mTargetViewPos);
float x = mTargetViewPos[0] - mIndicatorPos[0] - (1 - scaleX) * indicatorWidth / 2;
float y = mTargetViewPos[1] - mIndicatorPos[1] - (1 - scaleY) * indicatorHeight / 2;
if (getAlpha() > MIN_VISIBLE_ALPHA) {
animate()
.translationX(x)
.translationY(y)
.scaleX(scaleX)
.scaleY(scaleY)
.alpha(1);
} else {
setTranslationX(x);
setTranslationY(y);
setScaleX(scaleX);
setScaleY(scaleY);
animate().alpha(1);
}
setViewAnimation(getAlpha() > MIN_VISIBLE_ALPHA, v);
mLastFocusedView = v;
} else {
if (mLastFocusedView == v) {
mLastFocusedView = null;
// force the translation to the target position
setViewAnimation(false, v);
animate().alpha(0);
}
}
}
private void setViewAnimation(boolean animate, View v) {
int indicatorWidth = getWidth();
int indicatorHeight = getHeight();
float scaleX = v.getScaleX() * v.getWidth() / indicatorWidth;
float scaleY = v.getScaleY() * v.getHeight() / indicatorHeight;
getLocationRelativeToParentPagedView(v, mTargetViewPos);
float x = mTargetViewPos[0] - mIndicatorPos[0] - (1 - scaleX) * indicatorWidth / 2;
float y = mTargetViewPos[1] - mIndicatorPos[1] - (1 - scaleY) * indicatorHeight / 2;
if (animate) {
animate()
.translationX(x)
.translationY(y)
.scaleX(scaleX)
.scaleY(scaleY)
.alpha(1)
.setDuration(100);
} else {
setTranslationX(x);
setTranslationY(y);
setScaleX(scaleX);
setScaleY(scaleY);
animate().alpha(1);
}
}
@Override
protected void onDraw(Canvas canvas) {
if (mPendingCall != null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment