diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2014-10-14 16:12:12 -0700 |
---|---|---|
committer | Raj Yengisetty <rajesh@cyngn.com> | 2015-09-27 14:00:43 -0700 |
commit | 89f3bb81aa18b79986621e052a8380afca246924 (patch) | |
tree | b638643d52301e5a3d3635606b86a7d7a1b914de /src | |
parent | 0e3858b5d09f5c42ec4e6e2a0d4a18822470e7af (diff) | |
download | android_packages_apps_Trebuchet-89f3bb81aa18b79986621e052a8380afca246924.tar.gz android_packages_apps_Trebuchet-89f3bb81aa18b79986621e052a8380afca246924.tar.bz2 android_packages_apps_Trebuchet-89f3bb81aa18b79986621e052a8380afca246924.zip |
Moving the focus indicator instantly to the target position, instead
of begining the next animation from the middle.
Bug: 17958897
Change-Id: Ie5a39b80ff9788edf368e0f4e23c07c2ed5b3d2c
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher3/FocusIndicatorView.java | 68 |
1 files changed, 49 insertions, 19 deletions
diff --git a/src/com/android/launcher3/FocusIndicatorView.java b/src/com/android/launcher3/FocusIndicatorView.java index 8ccef9387..1ff6c9dd7 100644 --- a/src/com/android/launcher3/FocusIndicatorView.java +++ b/src/com/android/launcher3/FocusIndicatorView.java @@ -16,6 +16,8 @@ package com.android.launcher3; +import android.animation.ObjectAnimator; +import android.animation.PropertyValuesHolder; import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; @@ -28,6 +30,7 @@ public class FocusIndicatorView extends View implements View.OnFocusChangeListen // It can be any number >0. The view is resized using scaleX and scaleY. static final int DEFAULT_LAYOUT_SIZE = 100; private static final float MIN_VISIBLE_ALPHA = 0.2f; + private static final long ANIM_DURATION = 150; private static final int[] sTempPos = new int[2]; private static final int[] sTempShift = new int[2]; @@ -35,6 +38,9 @@ public class FocusIndicatorView extends View implements View.OnFocusChangeListen private final int[] mIndicatorPos = new int[2]; private final int[] mTargetViewPos = new int[2]; + private ObjectAnimator mCurrentAnimation; + private ViewAnimState mTargetState; + private View mLastFocusedView; private boolean mInitiated; @@ -86,36 +92,56 @@ public class FocusIndicatorView extends View implements View.OnFocusChangeListen mLastFocusedView = null; // force the translation to the target position setViewAnimation(false, v); - animate().alpha(0); } } + if (mCurrentAnimation != null) { + mCurrentAnimation.setDuration(ANIM_DURATION).start(); + } + } + + private void endCurrentAnimation() { + if (mCurrentAnimation != null) { + mCurrentAnimation.cancel(); + mCurrentAnimation = null; + } + if (mTargetState != null) { + applyState(mTargetState); + mTargetState = null; + } + } + + private void applyState(ViewAnimState state) { + setTranslationX(state.x); + setTranslationY(state.y); + setScaleX(state.scaleX); + setScaleY(state.scaleY); } 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; + endCurrentAnimation(); + ViewAnimState nextState = new ViewAnimState(); + nextState.scaleX = v.getScaleX() * v.getWidth() / indicatorWidth; + nextState.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); + nextState.x = mTargetViewPos[0] - mIndicatorPos[0] - (1 - nextState.scaleX) * indicatorWidth / 2; + nextState.y = mTargetViewPos[1] - mIndicatorPos[1] - (1 - nextState.scaleY) * indicatorHeight / 2; + + if (getAlpha() > MIN_VISIBLE_ALPHA) { + mTargetState = nextState; + mCurrentAnimation = LauncherAnimUtils.ofPropertyValuesHolder(this, + PropertyValuesHolder.ofFloat(View.ALPHA, 1), + PropertyValuesHolder.ofFloat(View.TRANSLATION_X, mTargetState.x), + PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, mTargetState.y), + PropertyValuesHolder.ofFloat(View.SCALE_X, mTargetState.scaleX), + PropertyValuesHolder.ofFloat(View.SCALE_Y, mTargetState.scaleY)); } else { - setTranslationX(x); - setTranslationY(y); - setScaleX(scaleX); - setScaleY(scaleY); - animate().alpha(1); + endCurrentAnimation(); + mCurrentAnimation = LauncherAnimUtils.ofPropertyValuesHolder(this, + PropertyValuesHolder.ofFloat(View.ALPHA, 0)); } } @@ -150,4 +176,8 @@ public class FocusIndicatorView extends View implements View.OnFocusChangeListen shift[0] = shift[1] = 0; } } + + private static final class ViewAnimState { + float x, y, scaleX, scaleY; + } } |