From c01bd1167a1b08d59557f214ddc48cf24d3b8d0a Mon Sep 17 00:00:00 2001 From: John Reck Date: Fri, 18 Jul 2014 16:22:09 -0700 Subject: [PATCH] Return Animator instead of ValueAnimator Change-Id: I29a7cfdc7ffbb3a4d33f9e64f9d7ca791f5c947c --- api/current.txt | 2 +- core/java/android/animation/Animator.java | 35 +++++++++++++++++++ .../android/animation/RevealAnimator.java | 31 +--------------- .../java/android/animation/ValueAnimator.java | 1 + core/java/android/view/View.java | 18 ---------- .../java/android/view/ViewAnimationUtils.java | 4 +-- .../android/systemui/qs/CircularClipper.java | 3 +- .../ActivatableNotificationView.java | 2 +- .../com/android/test/hwui/RevealActivity.java | 4 +-- 9 files changed, 44 insertions(+), 56 deletions(-) diff --git a/api/current.txt b/api/current.txt index fdf9b843d114c..7777db8753c36 100644 --- a/api/current.txt +++ b/api/current.txt @@ -34414,7 +34414,7 @@ package android.view { } public final class ViewAnimationUtils { - method public static final android.animation.ValueAnimator createCircularReveal(android.view.View, int, int, float, float); + method public static final android.animation.Animator createCircularReveal(android.view.View, int, int, float, float); } public class ViewConfiguration { diff --git a/core/java/android/animation/Animator.java b/core/java/android/animation/Animator.java index 95f83aca3eccb..5f80ed783d509 100644 --- a/core/java/android/animation/Animator.java +++ b/core/java/android/animation/Animator.java @@ -433,4 +433,39 @@ public abstract class Animator implements Cloneable { */ void onAnimationResume(Animator animation); } + + /** + *

Whether or not the Animator is allowed to run asynchronously off of + * the UI thread. This is a hint that informs the Animator that it is + * OK to run the animation off-thread, however the Animator may decide + * that it must run the animation on the UI thread anyway. + * + *

Regardless of whether or not the animation runs asynchronously, all + * listener callbacks will be called on the UI thread.

+ * + *

To be able to use this hint the following must be true:

+ *
    + *
  1. The animator is immutable while {@link #isStarted()} is true. Requests + * to change duration, delay, etc... may be ignored.
  2. + *
  3. Lifecycle callback events may be asynchronous. Events such as + * {@link Animator.AnimatorListener#onAnimationEnd(Animator)} or + * {@link Animator.AnimatorListener#onAnimationRepeat(Animator)} may end up delayed + * as they must be posted back to the UI thread, and any actions performed + * by those callbacks (such as starting new animations) will not happen + * in the same frame.
  4. + *
  5. State change requests ({@link #cancel()}, {@link #end()}, {@link #reverse()}, etc...) + * may be asynchronous. It is guaranteed that all state changes that are + * performed on the UI thread in the same frame will be applied as a single + * atomic update, however that frame may be the current frame, + * the next frame, or some future frame. This will also impact the observed + * state of the Animator. For example, {@link #isStarted()} may still return true + * after a call to {@link #end()}. Using the lifecycle callbacks is preferred over + * queries to {@link #isStarted()}, {@link #isRunning()}, and {@link #isPaused()} + * for this reason.
  6. + *
+ * @hide + */ + public void setAllowRunningAsynchronously(boolean mayRunAsync) { + // It is up to subclasses to support this, if they can. + } } diff --git a/core/java/android/animation/RevealAnimator.java b/core/java/android/animation/RevealAnimator.java index a1cbd45a656e8..53d92e6d6a955 100644 --- a/core/java/android/animation/RevealAnimator.java +++ b/core/java/android/animation/RevealAnimator.java @@ -167,38 +167,9 @@ public class RevealAnimator extends ValueAnimator { } @Override - public ValueAnimator clone() { + public RevealAnimator clone() { RevealAnimator anim = (RevealAnimator) super.clone(); anim.mRtAnimator = null; return anim; } - - // ---------------------------------------- - // All the things we don't allow - // ---------------------------------------- - - @Override - public void setValues(PropertyValuesHolder... values) { - throw new IllegalStateException("Cannot change the values of RevealAnimator"); - } - - @Override - public void setFloatValues(float... values) { - throw new IllegalStateException("Cannot change the values of RevealAnimator"); - } - - @Override - public void setIntValues(int... values) { - throw new IllegalStateException("Cannot change the values of RevealAnimator"); - } - - @Override - public void setObjectValues(Object... values) { - throw new IllegalStateException("Cannot change the values of RevealAnimator"); - } - - @Override - public void setEvaluator(TypeEvaluator value) { - throw new IllegalStateException("Cannot change the evaluator of RevealAnimator"); - } } diff --git a/core/java/android/animation/ValueAnimator.java b/core/java/android/animation/ValueAnimator.java index b13838aa9bb38..9435dfb66b1d5 100644 --- a/core/java/android/animation/ValueAnimator.java +++ b/core/java/android/animation/ValueAnimator.java @@ -1409,6 +1409,7 @@ public class ValueAnimator extends Animator { * * @hide */ + @Override public void setAllowRunningAsynchronously(boolean mayRunAsync) { // It is up to subclasses to support this, if they can. } diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index a5899de92f778..e138345c37190 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -10710,24 +10710,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } - /** - * Returns a ValueAnimator which can animate a clearing circle. - *

- * The View is prevented from drawing within the circle, so the content - * behind the View shows through. - * - * @param centerX The x coordinate of the center of the animating circle. - * @param centerY The y coordinate of the center of the animating circle. - * @param startRadius The starting radius of the animating circle. - * @param endRadius The ending radius of the animating circle. - * - * @hide - */ - public final ValueAnimator createClearCircleAnimator(int centerX, int centerY, - float startRadius, float endRadius) { - return new RevealAnimator(this, centerX, centerY, startRadius, endRadius, true); - } - /** * Returns the current StateListAnimator if exists. * diff --git a/core/java/android/view/ViewAnimationUtils.java b/core/java/android/view/ViewAnimationUtils.java index bee35ae1c3ef3..0a53b91819061 100644 --- a/core/java/android/view/ViewAnimationUtils.java +++ b/core/java/android/view/ViewAnimationUtils.java @@ -16,8 +16,8 @@ package android.view; +import android.animation.Animator; import android.animation.RevealAnimator; -import android.animation.ValueAnimator; /** * Defines common utilities for working with View's animations. @@ -36,7 +36,7 @@ public final class ViewAnimationUtils { * @param startRadius The starting radius of the animating circle. * @param endRadius The ending radius of the animating circle. */ - public static final ValueAnimator createCircularReveal(View view, + public static final Animator createCircularReveal(View view, int centerX, int centerY, float startRadius, float endRadius) { return new RevealAnimator(view, centerX, centerY, startRadius, endRadius, false); } diff --git a/packages/SystemUI/src/com/android/systemui/qs/CircularClipper.java b/packages/SystemUI/src/com/android/systemui/qs/CircularClipper.java index 327ed6a4e6d61..90275c1fc1fb2 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/CircularClipper.java +++ b/packages/SystemUI/src/com/android/systemui/qs/CircularClipper.java @@ -19,7 +19,6 @@ package com.android.systemui.qs; import android.animation.Animator; import android.animation.Animator.AnimatorListener; import android.animation.AnimatorListenerAdapter; -import android.animation.ValueAnimator; import android.view.View; import android.view.ViewAnimationUtils; @@ -28,7 +27,7 @@ public class CircularClipper { private final View mTarget; - private ValueAnimator mAnimator; + private Animator mAnimator; public CircularClipper(View target) { mTarget = target; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java b/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java index c02a5987b94e8..944a407972014 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java @@ -244,7 +244,7 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView int widthHalf = mBackgroundNormal.getWidth()/2; int heightHalf = mBackgroundNormal.getActualHeight()/2; float radius = (float) Math.sqrt(widthHalf*widthHalf + heightHalf*heightHalf); - ValueAnimator animator = + Animator animator = ViewAnimationUtils.createCircularReveal(mBackgroundNormal, widthHalf, heightHalf, 0, radius); mBackgroundNormal.setVisibility(View.VISIBLE); diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/RevealActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/RevealActivity.java index d27be6932530c..3360e3036205b 100644 --- a/tests/HwAccelerationTest/src/com/android/test/hwui/RevealActivity.java +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/RevealActivity.java @@ -16,7 +16,7 @@ package com.android.test.hwui; -import android.animation.ValueAnimator; +import android.animation.Animator; import android.app.Activity; import android.content.Context; import android.graphics.Canvas; @@ -54,7 +54,7 @@ public class RevealActivity extends Activity implements OnClickListener { @Override public void onClick(View view) { - ValueAnimator animator = ViewAnimationUtils.createCircularReveal(view, + Animator animator = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, 0, Math.max(view.getWidth(), view.getHeight())); animator.setDuration(DURATION);