diff options
author | Michael Jurka <mikejurka@google.com> | 2011-03-24 15:20:26 -0700 |
---|---|---|
committer | Michael Jurka <mikejurka@google.com> | 2011-03-24 15:54:19 -0700 |
commit | c2e26a028d1829bdddb1e47aac12951e12ef83e0 (patch) | |
tree | 0a9a1fa439de6a906c97a70a26a01fb3c161680f | |
parent | 7ef959b9177e1e715b0afe010904455a3d961fc4 (diff) | |
download | android_packages_apps_Trebuchet-c2e26a028d1829bdddb1e47aac12951e12ef83e0.tar.gz android_packages_apps_Trebuchet-c2e26a028d1829bdddb1e47aac12951e12ef83e0.tar.bz2 android_packages_apps_Trebuchet-c2e26a028d1829bdddb1e47aac12951e12ef83e0.zip |
Refactoring some animation code
Change-Id: If78b071c4fd5ac2c06d6d8ed0abaee7787273f28
-rw-r--r-- | src/com/android/launcher2/Launcher.java | 25 | ||||
-rw-r--r-- | src/com/android/launcher2/LauncherAnimatorUpdateListener.java | 30 | ||||
-rw-r--r-- | src/com/android/launcher2/Workspace.java | 18 |
3 files changed, 44 insertions, 29 deletions
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index f74710e8b..fc17643b1 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -2713,10 +2713,8 @@ public final class Launcher extends Activity if (animated) { final ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration); scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator()); - scaleAnim.addUpdateListener(new AnimatorUpdateListener() { - public void onAnimationUpdate(ValueAnimator animation) { - final float b = (Float) animation.getAnimatedValue(); - final float a = 1f - b; + scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { + public void onAnimationUpdate(float a, float b) { ((View) toView.getParent()).fastInvalidate(); toView.setFastScaleX(a * scale + b * 1f); toView.setFastScaleY(a * scale + b * 1f); @@ -2727,10 +2725,8 @@ public final class Launcher extends Activity toView.setFastAlpha(0f); ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(fadeDuration); alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f)); - alphaAnim.addUpdateListener(new AnimatorUpdateListener() { - public void onAnimationUpdate(ValueAnimator animation) { - final float b = (Float) animation.getAnimatedValue(); - final float a = 1f - b; + alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { + public void onAnimationUpdate(float a, float b) { // don't need to invalidate because we do so above toView.setFastAlpha(a * 0f + b * 1f); } @@ -2827,7 +2823,6 @@ public final class Launcher extends Activity if (!springLoaded) { mWorkspace.unshrink(animated); } - if (animated) { if (mStateAnimation != null) mStateAnimation.cancel(); mStateAnimation = new AnimatorSet(); @@ -2837,10 +2832,8 @@ public final class Launcher extends Activity ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration); scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator()); - scaleAnim.addUpdateListener(new AnimatorUpdateListener() { - public void onAnimationUpdate(ValueAnimator animation) { - final float b = (Float) animation.getAnimatedValue(); - final float a = 1f - b; + scaleAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { + public void onAnimationUpdate(float a, float b) { ((View)fromView.getParent()).fastInvalidate(); fromView.setFastScaleX(a * oldScaleX + b * scaleFactor); fromView.setFastScaleY(a * oldScaleY + b * scaleFactor); @@ -2849,10 +2842,8 @@ public final class Launcher extends Activity final ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f); alphaAnim.setDuration(res.getInteger(R.integer.config_allAppsFadeOutTime)); alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f)); - alphaAnim.addUpdateListener(new AnimatorUpdateListener() { - public void onAnimationUpdate(ValueAnimator animation) { - final float b = (Float) animation.getAnimatedValue(); - final float a = 1f - b; + alphaAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { + public void onAnimationUpdate(float a, float b) { // don't need to invalidate because we do so above fromView.setFastAlpha(a * 1f + b * 0f); } diff --git a/src/com/android/launcher2/LauncherAnimatorUpdateListener.java b/src/com/android/launcher2/LauncherAnimatorUpdateListener.java new file mode 100644 index 000000000..dd821134d --- /dev/null +++ b/src/com/android/launcher2/LauncherAnimatorUpdateListener.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher2; + +import android.animation.ValueAnimator; +import android.animation.ValueAnimator.AnimatorUpdateListener; + +abstract class LauncherAnimatorUpdateListener implements AnimatorUpdateListener { + public void onAnimationUpdate(ValueAnimator animation) { + final float b = (Float) animation.getAnimatedValue(); + final float a = 1f - b; + onAnimationUpdate(a, b); + } + + abstract void onAnimationUpdate(float a, float b); +}
\ No newline at end of file diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 6b68c5ab7..92be5dc77 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -1597,10 +1597,8 @@ public class Workspace extends SmoothPagedView final float oldVerticalWallpaperOffset = getVerticalWallpaperOffset(); final float newHorizontalWallpaperOffset = 0.5f; final float newVerticalWallpaperOffset = wallpaperOffset; - animWithInterpolator.addUpdateListener(new AnimatorUpdateListener() { - public void onAnimationUpdate(ValueAnimator animation) { - final float b = (Float) animation.getAnimatedValue(); - final float a = 1f - b; + animWithInterpolator.addUpdateListener(new LauncherAnimatorUpdateListener() { + public void onAnimationUpdate(float a, float b) { if (b == 0f) { // an optimization, and required for correct behavior. return; @@ -1942,10 +1940,8 @@ public class Workspace extends SmoothPagedView final float oldVerticalWallpaperOffset = getVerticalWallpaperOffset(); final float newHorizontalWallpaperOffset = wallpaperOffsetForCurrentScroll(); final float newVerticalWallpaperOffset = 0.5f; - animWithInterpolator.addUpdateListener(new AnimatorUpdateListener() { - public void onAnimationUpdate(ValueAnimator animation) { - final float b = (Float) animation.getAnimatedValue(); - final float a = 1f - b; + animWithInterpolator.addUpdateListener(new LauncherAnimatorUpdateListener() { + public void onAnimationUpdate(float a, float b) { if (b == 0f) { // an optimization, but not required return; @@ -1976,11 +1972,9 @@ public class Workspace extends SmoothPagedView ValueAnimator rotationAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration); rotationAnim.setInterpolator(new DecelerateInterpolator(2.0f)); - rotationAnim.addUpdateListener(new AnimatorUpdateListener() { - public void onAnimationUpdate(ValueAnimator animation) { + rotationAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { + public void onAnimationUpdate(float a, float b) { // don't invalidate workspace because we did it above - final float b = (Float) animation.getAnimatedValue(); - final float a = 1f - b; if (b == 0f) { // an optimization, but not required return; |