Merge "Cleaning up animation code"

This commit is contained in:
Michael Jurka 2012-01-17 12:07:24 -08:00 committed by Android (Google) Code Review
commit df871fe8d9
2 changed files with 34 additions and 46 deletions

View File

@ -2235,13 +2235,10 @@ public final class Launcher extends Activity
toView.setVisibility(View.VISIBLE);
toView.setAlpha(0f);
ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(fadeDuration);
final ObjectAnimator alphaAnim = ObjectAnimator
.ofFloat(toView, "alpha", 0f, 1f)
.setDuration(fadeDuration);
alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
public void onAnimationUpdate(float a, float b) {
toView.setAlpha(a * 0f + b * 1f);
}
});
// toView should appear right at the end of the workspace shrink
// animation
@ -2263,11 +2260,6 @@ public final class Launcher extends Activity
}
@Override
public void onAnimationEnd(Animator animation) {
// If we don't set the final scale values here, if this animation is cancelled
// it will have the wrong scale value and subsequent cameraPan animations will
// not fix that
toView.setScaleX(1.0f);
toView.setScaleY(1.0f);
if (toView instanceof LauncherTransitionable) {
((LauncherTransitionable) toView).onLauncherTransitionEnd(instance,
scaleAnim, false);
@ -2369,6 +2361,8 @@ public final class Launcher extends Activity
final Launcher instance = this;
final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
final int fadeOutDuration =
res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
final float scaleFactor = (float)
res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
final View fromView = mAppsCustomizeTabHost;
@ -2390,22 +2384,18 @@ public final class Launcher extends Activity
final float oldScaleX = fromView.getScaleX();
final float oldScaleY = fromView.getScaleY();
ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator());
scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
public void onAnimationUpdate(float a, float b) {
fromView.setScaleX(a * oldScaleX + b * scaleFactor);
fromView.setScaleY(a * oldScaleY + b * scaleFactor);
}
});
final ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f);
alphaAnim.setDuration(res.getInteger(R.integer.config_appsCustomizeFadeOutTime));
final LauncherViewPropertyAnimator scaleAnim =
new LauncherViewPropertyAnimator(fromView);
scaleAnim.
scaleX(scaleFactor).scaleY(scaleFactor).
setDuration(duration).
setInterpolator(new Workspace.ZoomInInterpolator());
final ObjectAnimator alphaAnim = ObjectAnimator
.ofFloat(fromView, "alpha", 1f, 0f)
.setDuration(fadeOutDuration);
alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
public void onAnimationUpdate(float a, float b) {
fromView.setAlpha(a * 1f + b * 0f);
}
});
if (fromView instanceof LauncherTransitionable) {
((LauncherTransitionable) fromView).onLauncherTransitionStart(instance, alphaAnim,
true);

View File

@ -50,19 +50,17 @@ public class LauncherViewPropertyAnimator extends Animator implements AnimatorLi
long mStartDelay;
long mDuration;
TimeInterpolator mInterpolator;
Animator.AnimatorListener mListener;
ArrayList<Animator.AnimatorListener> mListeners;
boolean mRunning = false;
public LauncherViewPropertyAnimator(View target) {
mTarget = target;
mListeners = new ArrayList<Animator.AnimatorListener>();
}
@Override
public void addListener(Animator.AnimatorListener listener) {
if (mListener != null) {
throw new RuntimeException("Only one listener supported");
}
mListener = listener;
mListeners.add(listener);
}
@Override
@ -89,7 +87,7 @@ public class LauncherViewPropertyAnimator extends Animator implements AnimatorLi
@Override
public ArrayList<Animator.AnimatorListener> getListeners() {
return null;
return mListeners;
}
@Override
@ -99,31 +97,35 @@ public class LauncherViewPropertyAnimator extends Animator implements AnimatorLi
@Override
public void onAnimationCancel(Animator animation) {
if (mListener != null) {
mListener.onAnimationCancel(this);
for (int i = 0; i < mListeners.size(); i++) {
Animator.AnimatorListener listener = mListeners.get(i);
listener.onAnimationCancel(this);
}
mRunning = false;
}
@Override
public void onAnimationEnd(Animator animation) {
if (mListener != null) {
mListener.onAnimationEnd(this);
for (int i = 0; i < mListeners.size(); i++) {
Animator.AnimatorListener listener = mListeners.get(i);
listener.onAnimationEnd(this);
}
mRunning = false;
}
@Override
public void onAnimationRepeat(Animator animation) {
if (mListener != null) {
mListener.onAnimationRepeat(this);
for (int i = 0; i < mListeners.size(); i++) {
Animator.AnimatorListener listener = mListeners.get(i);
listener.onAnimationRepeat(this);
}
}
@Override
public void onAnimationStart(Animator animation) {
if (mListener != null) {
mListener.onAnimationStart(this);
for (int i = 0; i < mListeners.size(); i++) {
Animator.AnimatorListener listener = mListeners.get(i);
listener.onAnimationStart(this);
}
mRunning = true;
}
@ -140,16 +142,12 @@ public class LauncherViewPropertyAnimator extends Animator implements AnimatorLi
@Override
public void removeAllListeners() {
mListener = null;
mListeners.clear();
}
@Override
public void removeListener(Animator.AnimatorListener listener) {
if (mListener == listener) {
mListener = null;
} else {
throw new RuntimeException("Removing listener that wasn't set");
}
mListeners.remove(listener);
}
@Override