Refactoring some animation code

Change-Id: If78b071c4fd5ac2c06d6d8ed0abaee7787273f28
This commit is contained in:
Michael Jurka 2011-03-24 15:20:26 -07:00
parent 7ef959b917
commit c2e26a028d
3 changed files with 44 additions and 29 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;