From 472b281d5cb4f5660df981a6c912266b9f5703fe Mon Sep 17 00:00:00 2001 From: Chet Haase Date: Thu, 14 Oct 2010 07:02:04 -0700 Subject: Updating code to use new non-generified animator APIs Change-Id: Ie1928a22f774b226d90fa0918f61dba35d183dd6 --- src/com/android/launcher2/AllAppsTabbed.java | 8 ++-- src/com/android/launcher2/CellLayout.java | 25 ++++++----- .../launcher2/InterruptibleInOutAnimator.java | 36 +++++++++------- src/com/android/launcher2/Launcher.java | 34 +++++++++------ src/com/android/launcher2/Workspace.java | 50 +++++++++++----------- 5 files changed, 84 insertions(+), 69 deletions(-) diff --git a/src/com/android/launcher2/AllAppsTabbed.java b/src/com/android/launcher2/AllAppsTabbed.java index aff8ddd20..cc6a14907 100644 --- a/src/com/android/launcher2/AllAppsTabbed.java +++ b/src/com/android/launcher2/AllAppsTabbed.java @@ -103,7 +103,8 @@ public class AllAppsTabbed extends TabHost implements AllAppsView { // animate the changing of the tab content by fading pages in and out final int duration = 150; final float alpha = mAllApps.getAlpha(); - ValueAnimator alphaAnim = new ObjectAnimator(duration, mAllApps, "alpha", alpha, 0.0f); + ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 0.0f). + setDuration(duration); alphaAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { String tag = getCurrentTabTag(); @@ -118,9 +119,8 @@ public class AllAppsTabbed extends TabHost implements AllAppsView { } final float alpha = mAllApps.getAlpha(); - ValueAnimator alphaAnim = - new ObjectAnimator(duration, mAllApps, "alpha", alpha, 1.0f); - alphaAnim.start(); + ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 1.0f). + setDuration(duration).start(); } }); alphaAnim.start(); diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java index 3c6a8aaed..c7c850b65 100644 --- a/src/com/android/launcher2/CellLayout.java +++ b/src/com/android/launcher2/CellLayout.java @@ -94,7 +94,7 @@ public class CellLayout extends ViewGroup implements Dimmable { // These arrays are used to implement the drag visualization on x-large screens. // They are used as circular arrays, indexed by mDragOutlineCurrent. private Point[] mDragOutlines = new Point[8]; - private int[] mDragOutlineAlphas = new int[mDragOutlines.length]; + private float[] mDragOutlineAlphas = new float[mDragOutlines.length]; private InterruptibleInOutAnimator[] mDragOutlineAnims = new InterruptibleInOutAnimator[mDragOutlines.length]; @@ -175,13 +175,13 @@ public class CellLayout extends ViewGroup implements Dimmable { // Set up the animation for fading the crosshairs in and out int animDuration = res.getInteger(R.integer.config_crosshairsFadeInTime); mCrosshairsAnimator = new InterruptibleInOutAnimator(animDuration, 0.0f, 1.0f); - mCrosshairsAnimator.addUpdateListener(new AnimatorUpdateListener() { + mCrosshairsAnimator.getAnimator().addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { mCrosshairsVisibility = ((Float) animation.getAnimatedValue()).floatValue(); CellLayout.this.invalidate(); } }); - mCrosshairsAnimator.setInterpolator(interp); + mCrosshairsAnimator.getAnimator().setInterpolator(interp); for (int i = 0; i < mDragOutlines.length; i++) { mDragOutlines[i] = new Point(-1, -1); @@ -192,8 +192,8 @@ public class CellLayout extends ViewGroup implements Dimmable { // behind the drag path. // Set up all the animations that are used to implement this fading. final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime); - final int fromAlphaValue = 0; - final int toAlphaValue = res.getInteger(R.integer.config_dragOutlineMaxAlpha); + final float fromAlphaValue = 0; + final float toAlphaValue = (float)res.getInteger(R.integer.config_dragOutlineMaxAlpha); for (int i = 0; i < mDragOutlineAlphas.length; i++) { mDragOutlineAlphas[i] = fromAlphaValue; @@ -202,10 +202,9 @@ public class CellLayout extends ViewGroup implements Dimmable { for (int i = 0; i < mDragOutlineAnims.length; i++) { final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(duration, fromAlphaValue, toAlphaValue); - anim.setInterpolator(interp); - + anim.getAnimator().setInterpolator(interp); final int thisIndex = i; - anim.addUpdateListener(new AnimatorUpdateListener() { + anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { final Bitmap outline = (Bitmap)anim.getTag(); @@ -221,7 +220,7 @@ public class CellLayout extends ViewGroup implements Dimmable { // Try to prevent it from continuing to run animation.cancel(); } else { - mDragOutlineAlphas[thisIndex] = (Integer) animation.getAnimatedValue(); + mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue(); final int left = mDragOutlines[thisIndex].x; final int top = mDragOutlines[thisIndex].y; CellLayout.this.invalidate(left, top, @@ -231,9 +230,9 @@ public class CellLayout extends ViewGroup implements Dimmable { }); // The animation holds a reference to the drag outline bitmap as long is it's // running. This way the bitmap can be GCed when the animations are complete. - anim.addListener(new AnimatorListenerAdapter() { + anim.getAnimator().addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { - if ((Integer) anim.getAnimatedValue() == 0) { + if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) { anim.setTag(null); } } @@ -311,11 +310,11 @@ public class CellLayout extends ViewGroup implements Dimmable { final Paint paint = new Paint(); for (int i = 0; i < mDragOutlines.length; i++) { - final int alpha = mDragOutlineAlphas[i]; + final float alpha = mDragOutlineAlphas[i]; if (alpha > 0) { final Point p = mDragOutlines[i]; final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag(); - paint.setAlpha(alpha); + paint.setAlpha((int)(alpha + .5f)); canvas.drawBitmap(b, p.x, p.y, paint); } } diff --git a/src/com/android/launcher2/InterruptibleInOutAnimator.java b/src/com/android/launcher2/InterruptibleInOutAnimator.java index 0b2f34561..bed7e6b28 100644 --- a/src/com/android/launcher2/InterruptibleInOutAnimator.java +++ b/src/com/android/launcher2/InterruptibleInOutAnimator.java @@ -18,6 +18,7 @@ package com.android.launcher2; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; +import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.util.Log; @@ -28,10 +29,11 @@ import android.util.Log; * be exactly reversed. Using this class, both the 'in' and the 'out' animation use the * interpolator in the same direction. */ -public class InterruptibleInOutAnimator extends ValueAnimator { +public class InterruptibleInOutAnimator { private long mOriginalDuration; - private Object mOriginalFromValue; - private Object mOriginalToValue; + private float mOriginalFromValue; + private float mOriginalToValue; + private ValueAnimator mAnimator; private boolean mFirstRun = true; @@ -41,41 +43,41 @@ public class InterruptibleInOutAnimator extends ValueAnimator { private static final int IN = 1; private static final int OUT = 2; + private int mDirection = STOPPED; - public InterruptibleInOutAnimator(long duration, Object fromValue, Object toValue) { - super(duration, fromValue, toValue); + public InterruptibleInOutAnimator(long duration, float fromValue, float toValue) { + mAnimator = ValueAnimator.ofFloat(fromValue, toValue).setDuration(duration); mOriginalDuration = duration; mOriginalFromValue = fromValue; mOriginalToValue = toValue; } private void animate(int direction) { - final long currentPlayTime = getCurrentPlayTime(); - final Object toValue = (direction == IN) ? mOriginalToValue : mOriginalFromValue; - final Object startValue = mFirstRun ? mOriginalFromValue : getAnimatedValue(); + final long currentPlayTime = mAnimator.getCurrentPlayTime(); + final float toValue = (direction == IN) ? mOriginalToValue : mOriginalFromValue; + final float startValue = mFirstRun ? mOriginalFromValue : + ((Float) mAnimator.getAnimatedValue()).floatValue(); // Make sure it's stopped before we modify any values cancel(); if (startValue != toValue) { mDirection = direction; - setDuration(mOriginalDuration - currentPlayTime); - setValues(startValue, toValue); - start(); + mAnimator.setDuration(mOriginalDuration - currentPlayTime); + mAnimator.setFloatValues(startValue, toValue); + mAnimator.start(); mFirstRun = false; } } - @Override public void cancel() { - super.cancel(); + mAnimator.cancel(); mDirection = STOPPED; } - @Override public void end() { - super.end(); + mAnimator.end(); mDirection = STOPPED; } @@ -112,4 +114,8 @@ public class InterruptibleInOutAnimator extends ValueAnimator { public Object getTag() { return mTag; } + + public ValueAnimator getAnimator() { + return mAnimator; + } } diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index d7c2f5bb5..6fcf4329b 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -318,8 +318,9 @@ public final class Launcher extends Activity // animate the changing of the tab content by fading pages in and out final int duration = 150; final float alpha = mCustomizePagedView.getAlpha(); - ValueAnimator alphaAnim = new ObjectAnimator(duration, mCustomizePagedView, + ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mCustomizePagedView, "alpha", alpha, 0.0f); + alphaAnim.setDuration(duration); alphaAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { String tag = mHomeCustomizationDrawer.getCurrentTabTag(); @@ -341,8 +342,9 @@ public final class Launcher extends Activity } final float alpha = mCustomizePagedView.getAlpha(); - ValueAnimator alphaAnim = new ObjectAnimator(duration, + ValueAnimator alphaAnim = ObjectAnimator.ofFloat( mCustomizePagedView, "alpha", alpha, 1.0f); + alphaAnim.setDuration(duration); alphaAnim.start(); } }); @@ -2284,7 +2286,8 @@ public final class Launcher extends Activity getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime); if (seq != null) { - Animator anim = new ObjectAnimator(duration, view, "alpha", show ? 1.0f : 0.0f); + Animator anim = ObjectAnimator.ofFloat(view, "alpha", show ? 1.0f : 0.0f); + anim.setDuration(duration); anim.addListener(new AnimatorListenerAdapter() { public void onAnimationStart(Animator animation) { if (showing) showToolbarButton(view); @@ -2383,9 +2386,10 @@ public final class Launcher extends Activity } if (animated) { - ValueAnimator scaleAnim = new ObjectAnimator(duration, toView, - new PropertyValuesHolder("scaleX", scale, 1.0f), - new PropertyValuesHolder("scaleY", scale, 1.0f)); + ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(toView, + PropertyValuesHolder.ofFloat("scaleX", scale, 1.0f), + PropertyValuesHolder.ofFloat("scaleY", scale, 1.0f)); + scaleAnim.setDuration(duration); scaleAnim.setInterpolator(new DecelerateInterpolator()); scaleAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationStart(Animator animation) { @@ -2445,9 +2449,10 @@ public final class Launcher extends Activity if (animated) { if (mStateAnimation != null) mStateAnimation.cancel(); mStateAnimation = new AnimatorSet(); - ValueAnimator scaleAnim = new ObjectAnimator(duration, fromView, - new PropertyValuesHolder("scaleX", scaleFactor), - new PropertyValuesHolder("scaleY", scaleFactor)); + ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(fromView, + PropertyValuesHolder.ofFloat("scaleX", scaleFactor), + PropertyValuesHolder.ofFloat("scaleY", scaleFactor)); + scaleAnim.setDuration(duration); scaleAnim.setInterpolator(new AccelerateInterpolator()); mStateAnimation.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { @@ -2522,10 +2527,13 @@ public final class Launcher extends Activity AnimatorSet toolbarShowAnim = new AnimatorSet(); hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim); - mStateAnimation.playTogether( - toolbarHideAnim, - new ObjectAnimator(duration, fromView, "y", fromViewStartY, fromViewEndY), - new ObjectAnimator(duration, toView, "y", toViewStartY, toViewEndY)); + ObjectAnimator fromAnim = ObjectAnimator.ofFloat(fromView, "y", + fromViewStartY, fromViewEndY); + fromAnim.setDuration(duration); + ObjectAnimator toAnim = ObjectAnimator.ofFloat(toView, "y", + toViewStartY, toViewEndY); + fromAnim.setDuration(duration); + mStateAnimation.playTogether(toolbarHideAnim, fromAnim, toAnim); // Show the new toolbar buttons just as the main animation is ending final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime); diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 75e39e0c6..4de182218 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -16,6 +16,7 @@ package com.android.launcher2; +import android.animation.AnimatorListenerAdapter; import com.android.launcher.R; import android.animation.Animator; @@ -80,8 +81,8 @@ public class Workspace extends SmoothPagedView private static final int BACKGROUND_FADE_IN_DURATION = 100; // These animators are used to fade the background - private ObjectAnimator mBackgroundFadeInAnimation; - private ObjectAnimator mBackgroundFadeOutAnimation; + private ObjectAnimator mBackgroundFadeInAnimation; + private ObjectAnimator mBackgroundFadeOutAnimation; private float mBackgroundAlpha = 0; private final WallpaperManager mWallpaperManager; @@ -194,15 +195,13 @@ public class Workspace extends SmoothPagedView LauncherApplication app = (LauncherApplication)context.getApplicationContext(); mIconCache = app.getIconCache(); - mUnshrinkAnimationListener = new AnimatorListener() { + mUnshrinkAnimationListener = new AnimatorListenerAdapter() { public void onAnimationStart(Animator animation) { mIsInUnshrinkAnimation = true; } public void onAnimationEnd(Animator animation) { mIsInUnshrinkAnimation = false; } - public void onAnimationCancel(Animator animation) {} - public void onAnimationRepeat(Animator animation) {} }; mSnapVelocity = 600; @@ -477,8 +476,8 @@ public class Workspace extends SmoothPagedView if (!mIsSmall && !mIsInUnshrinkAnimation) { if (mBackgroundFadeOutAnimation != null) mBackgroundFadeOutAnimation.cancel(); if (mBackgroundFadeInAnimation != null) mBackgroundFadeInAnimation.cancel(); - mBackgroundFadeInAnimation = new ObjectAnimator(BACKGROUND_FADE_IN_DURATION, - this, new PropertyValuesHolder("backgroundAlpha", 1.0f)); + mBackgroundFadeInAnimation = ObjectAnimator.ofFloat(this, "backgroundAlpha", 1.0f); + mBackgroundFadeInAnimation.setDuration(BACKGROUND_FADE_IN_DURATION); mBackgroundFadeInAnimation.start(); } } @@ -487,8 +486,8 @@ public class Workspace extends SmoothPagedView if (!mIsSmall && !mIsInUnshrinkAnimation) { if (mBackgroundFadeInAnimation != null) mBackgroundFadeInAnimation.cancel(); if (mBackgroundFadeOutAnimation != null) mBackgroundFadeOutAnimation.cancel(); - mBackgroundFadeOutAnimation = new ObjectAnimator(BACKGROUND_FADE_OUT_DURATION, - this, new PropertyValuesHolder("backgroundAlpha", 0.0f)); + mBackgroundFadeOutAnimation = ObjectAnimator.ofFloat(this, "backgroundAlpha", 0.0f); + mBackgroundFadeOutAnimation.setDuration(BACKGROUND_FADE_OUT_DURATION); mBackgroundFadeOutAnimation.setStartDelay(BACKGROUND_FADE_OUT_DELAY); mBackgroundFadeOutAnimation.start(); } @@ -750,16 +749,18 @@ public class Workspace extends SmoothPagedView if (animated) { final int duration = res.getInteger(R.integer.config_workspaceShrinkTime); - new ObjectAnimator(duration, cl, - new PropertyValuesHolder("x", newX), - new PropertyValuesHolder("y", newY), - new PropertyValuesHolder("scaleX", + ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(cl, + PropertyValuesHolder.ofFloat("x", newX), + PropertyValuesHolder.ofFloat("y", newY), + PropertyValuesHolder.ofFloat("scaleX", SHRINK_FACTOR * rotationScaleX * extraShrinkFactor), - new PropertyValuesHolder("scaleY", + PropertyValuesHolder.ofFloat("scaleY", SHRINK_FACTOR * rotationScaleY * extraShrinkFactor), - new PropertyValuesHolder("backgroundAlpha", finalAlpha), - new PropertyValuesHolder("alpha", finalAlpha), - new PropertyValuesHolder("rotationY", rotation)).start(); + PropertyValuesHolder.ofFloat("backgroundAlpha", finalAlpha), + PropertyValuesHolder.ofFloat("alpha", finalAlpha), + PropertyValuesHolder.ofFloat("rotationY", rotation)); + anim.setDuration(duration); + anim.start(); } else { cl.setX((int)newX); cl.setY((int)newY); @@ -902,14 +903,15 @@ public class Workspace extends SmoothPagedView } if (animated) { + s.playTogether( - new ObjectAnimator(duration, cl, "translationX", 0.0f), - new ObjectAnimator(duration, cl, "translationY", 0.0f), - new ObjectAnimator(duration, cl, "scaleX", 1.0f), - new ObjectAnimator(duration, cl, "scaleY", 1.0f), - new ObjectAnimator(duration, cl, "backgroundAlpha", 0.0f), - new ObjectAnimator(duration, cl, "alpha", finalAlphaValue), - new ObjectAnimator(duration, cl, "rotationY", rotation)); + ObjectAnimator.ofFloat(cl, "translationX", 0.0f).setDuration(duration), + ObjectAnimator.ofFloat(cl, "translationY", 0.0f).setDuration(duration), + ObjectAnimator.ofFloat(cl, "scaleX", 1.0f).setDuration(duration), + ObjectAnimator.ofFloat(cl, "scaleY", 1.0f).setDuration(duration), + ObjectAnimator.ofFloat(cl, "backgroundAlpha", 0.0f).setDuration(duration), + ObjectAnimator.ofFloat(cl, "alpha", finalAlphaValue).setDuration(duration), + ObjectAnimator.ofFloat(cl, "rotationY", rotation).setDuration(duration)); } else { cl.setTranslationX(0.0f); cl.setTranslationY(0.0f); -- cgit v1.2.3