From b073b4937d3cd30ce0ff48d34ce68a9995baf3b6 Mon Sep 17 00:00:00 2001 From: Linus Lee Date: Tue, 11 Aug 2015 14:26:46 -0700 Subject: 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 (cherry picked from commit 4319d899e32d7fb4c385c4ac5f9b7d61a0a873e0) --- src/com/android/launcher3/FocusIndicatorView.java | 55 +++++++++++++---------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/com/android/launcher3/FocusIndicatorView.java b/src/com/android/launcher3/FocusIndicatorView.java index 12b7a4076..8ccef9387 100644 --- a/src/com/android/launcher3/FocusIndicatorView.java +++ b/src/com/android/launcher3/FocusIndicatorView.java @@ -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) { -- cgit v1.2.3