summaryrefslogtreecommitdiffstats
path: root/core/java/android/animation
diff options
context:
space:
mode:
authorChet Haase <chet@google.com>2010-12-14 09:18:33 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-12-14 09:18:33 -0800
commit48ea8d836276c04528d8e7dfebd59d27a627ce66 (patch)
treebf5cf953d95a66a265455f2360483120f3a635a8 /core/java/android/animation
parent6cb3b52df4f2ec4cc5f361886377657986e9dd19 (diff)
parent051d35e41f7b21cd8a1608bdce10cf70952c6be4 (diff)
downloadframeworks_base-48ea8d836276c04528d8e7dfebd59d27a627ce66.zip
frameworks_base-48ea8d836276c04528d8e7dfebd59d27a627ce66.tar.gz
frameworks_base-48ea8d836276c04528d8e7dfebd59d27a627ce66.tar.bz2
Merge "Adding TimeAnimator capability (hidden for now)"
Diffstat (limited to 'core/java/android/animation')
-rw-r--r--core/java/android/animation/TimeAnimator.java78
-rwxr-xr-xcore/java/android/animation/ValueAnimator.java14
2 files changed, 85 insertions, 7 deletions
diff --git a/core/java/android/animation/TimeAnimator.java b/core/java/android/animation/TimeAnimator.java
new file mode 100644
index 0000000..0a96d59
--- /dev/null
+++ b/core/java/android/animation/TimeAnimator.java
@@ -0,0 +1,78 @@
+package android.animation;
+
+/**
+ * This class provides a simple callback mechanism to listeners that is synchronized with other
+ * animators in the system. There is no duration, interpolation, or object value-setting
+ * with this Animator. Instead, it is simply started and proceeds to send out events on every
+ * animation frame to its TimeListener (if set), with information about this animator,
+ * the total elapsed time, and the time since the last animation frame.
+ *
+ * @hide
+ */
+public class TimeAnimator extends ValueAnimator {
+
+ private TimeListener mListener;
+ private long mPreviousTime = -1;
+
+ @Override
+ boolean animationFrame(long currentTime) {
+ if (mPlayingState == STOPPED) {
+ mPlayingState = RUNNING;
+ if (mSeekTime < 0) {
+ mStartTime = currentTime;
+ } else {
+ mStartTime = currentTime - mSeekTime;
+ // Now that we're playing, reset the seek time
+ mSeekTime = -1;
+ }
+ }
+ if (mListener != null) {
+ long totalTime = currentTime - mStartTime;
+ long deltaTime = (mPreviousTime < 0) ? 0 : (currentTime - mPreviousTime);
+ mPreviousTime = currentTime;
+ mListener.onTimeUpdate(this, totalTime, deltaTime);
+ }
+ return false;
+ }
+
+ /**
+ * Sets a listener that is sent update events throughout the life of
+ * an animation.
+ *
+ * @param listener the listener to be set.
+ */
+ public void setTimeListener(TimeListener listener) {
+ mListener = listener;
+ }
+
+ @Override
+ void animateValue(float fraction) {
+ // Noop
+ }
+
+ @Override
+ void initAnimation() {
+ // noop
+ }
+
+ /**
+ * Implementors of this interface can set themselves as update listeners
+ * to a <code>TimeAnimator</code> instance to receive callbacks on every animation
+ * frame to receive the total time since the animator started and the delta time
+ * since the last frame. The first time the listener is called, totalTime and
+ * deltaTime should both be zero.
+ *
+ * @hide
+ */
+ public static interface TimeListener {
+ /**
+ * <p>Notifies listeners of the occurrence of another frame of the animation,
+ * along with information about the elapsed time.</p>
+ *
+ * @param animation The animator sending out the notification.
+ * @param totalTime The
+ */
+ void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime);
+
+ }
+}
diff --git a/core/java/android/animation/ValueAnimator.java b/core/java/android/animation/ValueAnimator.java
index 1542c49..50082f9 100755
--- a/core/java/android/animation/ValueAnimator.java
+++ b/core/java/android/animation/ValueAnimator.java
@@ -60,9 +60,9 @@ public class ValueAnimator extends Animator {
* Values used with internal variable mPlayingState to indicate the current state of an
* animation.
*/
- private static final int STOPPED = 0; // Not yet playing
- private static final int RUNNING = 1; // Playing normally
- private static final int SEEKED = 2; // Seeked to some time value
+ static final int STOPPED = 0; // Not yet playing
+ static final int RUNNING = 1; // Playing normally
+ static final int SEEKED = 2; // Seeked to some time value
/**
* Internal variables
@@ -74,13 +74,13 @@ public class ValueAnimator extends Animator {
// The first time that the animation's animateFrame() method is called. This time is used to
// determine elapsed time (and therefore the elapsed fraction) in subsequent calls
// to animateFrame()
- private long mStartTime;
+ long mStartTime;
/**
* Set when setCurrentPlayTime() is called. If negative, animation is not currently seeked
* to a value.
*/
- private long mSeekTime = -1;
+ long mSeekTime = -1;
// TODO: We access the following ThreadLocal variables often, some of them on every update.
// If ThreadLocal access is significantly expensive, we may want to put all of these
@@ -178,7 +178,7 @@ public class ValueAnimator extends Animator {
* has been cancel()'d or end()'d since the last animation frame. Possible values are
* STOPPED, RUNNING, SEEKED.
*/
- private int mPlayingState = STOPPED;
+ int mPlayingState = STOPPED;
/**
* Flag that denotes whether the animation is set up and ready to go. Used to
@@ -1051,7 +1051,7 @@ public class ValueAnimator extends Animator {
* @return true if the animation's duration, including any repetitions due to
* <code>repeatCount</code> has been exceeded and the animation should be ended.
*/
- private boolean animationFrame(long currentTime) {
+ boolean animationFrame(long currentTime) {
boolean done = false;
if (mPlayingState == STOPPED) {