diff options
Diffstat (limited to 'src/com/android/launcher3/folder')
4 files changed, 58 insertions, 66 deletions
diff --git a/src/com/android/launcher3/folder/FolderAnimationManager.java b/src/com/android/launcher3/folder/FolderAnimationManager.java index 9ae377535..0c77f9ed1 100644 --- a/src/com/android/launcher3/folder/FolderAnimationManager.java +++ b/src/com/android/launcher3/folder/FolderAnimationManager.java @@ -27,7 +27,6 @@ import android.animation.ObjectAnimator; import android.animation.TimeInterpolator; import android.content.Context; import android.content.res.Resources; -import android.graphics.Color; import android.graphics.Rect; import android.graphics.drawable.GradientDrawable; import android.support.v4.graphics.ColorUtils; @@ -38,7 +37,6 @@ import android.view.animation.AnimationUtils; import com.android.launcher3.BubbleTextView; import com.android.launcher3.CellLayout; import com.android.launcher3.Launcher; -import com.android.launcher3.LauncherAnimUtils; import com.android.launcher3.R; import com.android.launcher3.ShortcutAndWidgetContainer; import com.android.launcher3.Utilities; @@ -170,7 +168,7 @@ public class FolderAnimationManager { float finalRadius = Utilities.pxFromDp(2, mContext.getResources().getDisplayMetrics()); // Create the animators. - AnimatorSet a = LauncherAnimUtils.createAnimatorSet(); + AnimatorSet a = new AnimatorSet(); // Initialize the Folder items' text. PropertyResetListener colorResetListener = diff --git a/src/com/android/launcher3/folder/FolderPreviewItemAnim.java b/src/com/android/launcher3/folder/FolderPreviewItemAnim.java index be075bc9a..1e56f7d15 100644 --- a/src/com/android/launcher3/folder/FolderPreviewItemAnim.java +++ b/src/com/android/launcher3/folder/FolderPreviewItemAnim.java @@ -17,22 +17,41 @@ package com.android.launcher3.folder; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; -import android.animation.ValueAnimator; +import android.animation.FloatArrayEvaluator; +import android.animation.ObjectAnimator; +import android.util.Property; -import com.android.launcher3.LauncherAnimUtils; +import java.util.Arrays; /** * Animates a Folder preview item. */ class FolderPreviewItemAnim { + private static final Property<FolderPreviewItemAnim, float[]> PARAMS = + new Property<FolderPreviewItemAnim, float[]>(float[].class, "params") { + @Override + public float[] get(FolderPreviewItemAnim anim) { + sTempParamsArray[0] = anim.mParams.scale; + sTempParamsArray[1] = anim.mParams.transX; + sTempParamsArray[2] = anim.mParams.transY; + return sTempParamsArray; + } + + @Override + public void set(FolderPreviewItemAnim anim, float[] value) { + anim.setParams(value); + } + }; + private static PreviewItemDrawingParams sTmpParams = new PreviewItemDrawingParams(0, 0, 0, 0); + private static final float[] sTempParamsArray = new float[3]; - private ValueAnimator mValueAnimator; + private final ObjectAnimator mAnimator; + private final PreviewItemManager mItemManager; + private final PreviewItemDrawingParams mParams; - float finalScale; - float finalTransX; - float finalTransY; + public final float[] finalState; /** * @param params layout params to animate @@ -43,33 +62,21 @@ class FolderPreviewItemAnim { * @param duration duration in ms of the animation * @param onCompleteRunnable runnable to execute upon animation completion */ - FolderPreviewItemAnim(final PreviewItemManager previewItemManager, - final PreviewItemDrawingParams params, int index0, int items0, int index1, int items1, + FolderPreviewItemAnim(PreviewItemManager itemManager, + PreviewItemDrawingParams params, int index0, int items0, int index1, int items1, int duration, final Runnable onCompleteRunnable) { - previewItemManager.computePreviewItemDrawingParams(index1, items1, sTmpParams); - - finalScale = sTmpParams.scale; - finalTransX = sTmpParams.transX; - finalTransY = sTmpParams.transY; + mItemManager = itemManager; + mParams = params; - previewItemManager.computePreviewItemDrawingParams(index0, items0, sTmpParams); + mItemManager.computePreviewItemDrawingParams(index1, items1, sTmpParams); + finalState = new float[] {sTmpParams.scale, sTmpParams.transX, sTmpParams.transY}; - final float scale0 = sTmpParams.scale; - final float transX0 = sTmpParams.transX; - final float transY0 = sTmpParams.transY; + mItemManager.computePreviewItemDrawingParams(index0, items0, sTmpParams); + float[] startState = new float[] {sTmpParams.scale, sTmpParams.transX, sTmpParams.transY}; - mValueAnimator = LauncherAnimUtils.ofFloat(0f, 1.0f); - mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener(){ - public void onAnimationUpdate(ValueAnimator animation) { - float progress = animation.getAnimatedFraction(); - - params.transX = transX0 + progress * (finalTransX - transX0); - params.transY = transY0 + progress * (finalTransY - transY0); - params.scale = scale0 + progress * (finalScale - scale0); - previewItemManager.onParamsChanged(); - } - }); - mValueAnimator.addListener(new AnimatorListenerAdapter() { + mAnimator = ObjectAnimator.ofObject(this, PARAMS, new FloatArrayEvaluator(), + startState, finalState); + mAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (onCompleteRunnable != null) { @@ -78,20 +85,26 @@ class FolderPreviewItemAnim { params.anim = null; } }); - mValueAnimator.setDuration(duration); + mAnimator.setDuration(duration); + } + + private void setParams(float[] values) { + mParams.scale = values[0]; + mParams.transX = values[1]; + mParams.transY = values[2]; + mItemManager.onParamsChanged(); } public void start() { - mValueAnimator.start(); + mAnimator.start(); } public void cancel() { - mValueAnimator.cancel(); + mAnimator.cancel(); } public boolean hasEqualFinalState(FolderPreviewItemAnim anim) { - return finalTransY == anim.finalTransY && finalTransX == anim.finalTransX && - finalScale == anim.finalScale; + return Arrays.equals(finalState, anim.finalState); } } diff --git a/src/com/android/launcher3/folder/PreviewBackground.java b/src/com/android/launcher3/folder/PreviewBackground.java index b162fcf32..86266e625 100644 --- a/src/com/android/launcher3/folder/PreviewBackground.java +++ b/src/com/android/launcher3/folder/PreviewBackground.java @@ -37,7 +37,6 @@ import android.view.View; import com.android.launcher3.CellLayout; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Launcher; -import com.android.launcher3.LauncherAnimUtils; import com.android.launcher3.R; import com.android.launcher3.util.Themes; @@ -368,7 +367,7 @@ public class PreviewBackground { mScaleAnimator.cancel(); } - mScaleAnimator = LauncherAnimUtils.ofFloat(0f, 1.0f); + mScaleAnimator = ValueAnimator.ofFloat(0f, 1.0f); mScaleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override @@ -400,37 +399,19 @@ public class PreviewBackground { mScaleAnimator.start(); } - public void animateToAccept(final CellLayout cl, final int cellX, final int cellY) { - Runnable onStart = new Runnable() { - @Override - public void run() { - delegateDrawing(cl, cellX, cellY); - } - }; - animateScale(ACCEPT_SCALE_FACTOR, ACCEPT_COLOR_MULTIPLIER, onStart, null); + public void animateToAccept(CellLayout cl, int cellX, int cellY) { + animateScale(ACCEPT_SCALE_FACTOR, ACCEPT_COLOR_MULTIPLIER, + () -> delegateDrawing(cl, cellX, cellY), null); } public void animateToRest() { // This can be called multiple times -- we need to make sure the drawing delegate // is saved and restored at the beginning of the animation, since cancelling the // existing animation can clear the delgate. - final CellLayout cl = mDrawingDelegate; - final int cellX = delegateCellX; - final int cellY = delegateCellY; - - Runnable onStart = new Runnable() { - @Override - public void run() { - delegateDrawing(cl, cellX, cellY); - } - }; - Runnable onEnd = new Runnable() { - @Override - public void run() { - clearDrawingDelegate(); - } - }; - animateScale(1f, 1f, onStart, onEnd); + CellLayout cl = mDrawingDelegate; + int cellX = delegateCellX; + int cellY = delegateCellY; + animateScale(1f, 1f, () -> delegateDrawing(cl, cellX, cellY), this::clearDrawingDelegate); } public int getBackgroundAlpha() { diff --git a/src/com/android/launcher3/folder/PreviewItemDrawingParams.java b/src/com/android/launcher3/folder/PreviewItemDrawingParams.java index 607b7caec..c81846256 100644 --- a/src/com/android/launcher3/folder/PreviewItemDrawingParams.java +++ b/src/com/android/launcher3/folder/PreviewItemDrawingParams.java @@ -40,8 +40,8 @@ class PreviewItemDrawingParams { // We ensure the update will not interfere with an animation on the layout params // If the final values differ, we cancel the animation. if (anim != null) { - if (anim.finalTransX == transX || anim.finalTransY == transY - || anim.finalScale == scale) { + if (anim.finalState[1] == transX || anim.finalState[2] == transY + || anim.finalState[0] == scale) { return; } anim.cancel(); |