/*
* Copyright (C) 2010 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.nineoldandroids.animation;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.AndroidRuntimeException;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import java.util.ArrayList;
import java.util.HashMap;
/**
* This class provides a simple timing engine for running animations
* which calculate animated values and set them on target objects.
*
* <p>There is a single timing pulse that all animations use. It runs in a
* custom handler to ensure that property changes happen on the UI thread.</p>
*
* <p>By default, ValueAnimator uses non-linear time interpolation, via the
* {@link AccelerateDecelerateInterpolator} class, which accelerates into and decelerates
* out of an animation. This behavior can be changed by calling
* {@link ValueAnimator#setInterpolator(TimeInterpolator)}.</p>
*/
public class ValueAnimator extends Animator {
/**
* Internal constants
*/
/*
* The default amount of time in ms between animation frames
*/
private static final long DEFAULT_FRAME_DELAY = 10;
/**
* Messages sent to timing handler: START is sent when an animation first begins, FRAME is sent
* by the handler to itself to process the next animation frame
*/
static final int ANIMATION_START = 0;
static final int ANIMATION_FRAME = 1;
/**
* Values used with internal variable mPlayingState to indicate the current state of an
* animation.
*/
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
* NOTE: This object implements the clone() method, making a deep copy of any referenced
* objects. As other non-trivial fields are added to this class, make sure to add logic
* to clone() to make deep copies of them.
*/
// 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()
long mStartTime;
/**
* Set when setCurrentPlayTime() is called. If negative, animation is not currently seeked
* to a value.
*/
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
// fields into a structure sot hat we just access ThreadLocal once to get the reference
// to that structure, then access the structure directly for each field.
// The static sAnimationHandler processes the internal timing loop on which all animations
// are based
private static ThreadLocal<AnimationHandler> sAnimationHandler =
new ThreadLocal<AnimationHandler>();
// The per-thread list of all active animations
private static final ThreadLocal<ArrayList<ValueAnimator>> sAnimations =
new ThreadLocal<ArrayList<ValueAnimator>>() {
@Override
protected ArrayList<ValueAnimator> initialValue() {
return new ArrayList<ValueAnimator>();
}
};
// The per-thread set of animations to be started on the next animation frame
private static final ThreadLocal<ArrayList<ValueAnimator>> sPendingAnimations =
new ThreadLocal<ArrayList<ValueAnimator>>() {
@Override
protected ArrayList<ValueAnimator> initialValue() {
return new ArrayList<ValueAnimator>();
}
};
/**
* Internal per-thread collections used to avoid set collisions as animations start and end
* while being processed.
*/
private static final ThreadLocal<ArrayList<ValueAnimator>> sDelayedAnims =
new ThreadLocal<ArrayList<ValueAnimator>>() {
@Override
protected ArrayList<ValueAnimator> initialValue() {
return new ArrayList<ValueAnimator>();
}
};
private static final ThreadLocal<ArrayList<ValueAnimator>> sEndingAnims =
new ThreadLocal<ArrayList<ValueAnimator>>() {
@Override
protected ArrayList<ValueAnimator> initialValue() {
return new ArrayList<ValueAnimator>();
}
};
private static final ThreadLocal<ArrayList<ValueAnimator>> sReadyAnims =
new ThreadLocal<ArrayList<ValueAnimator>>() {
@Override
protected ArrayList<ValueAnimator> initialValue() {
return new ArrayList<ValueAnimator>();
}
};
// The time interpolator to be used if none is set on the animation
private static final /*Time*/Interpolator sDefaultInterpolator =
new AccelerateDecelerateInterpolator();
// type evaluators for the primitive types handled by this implementation
private static final TypeEvaluator sIntEvaluator = new IntEvaluator();
private static final TypeEvaluator sFloatEvaluator = new FloatEvaluator();
/**
* Used to indicate whether the animation is currently playing in reverse. This causes the
* elapsed fraction to be inverted to calculate the appropriate values.
*/
private boolean mPlayingBackwards = false;
/**
* This variable tracks the current iteration that is playing. When mCurrentIteration exceeds the
* repeatCount (if repeatCount!=INFINITE), the animation ends
*/
private int mCurrentIteration = 0;
/**
* Tracks current elapsed/eased fraction, for querying in getAnimatedFraction().
*/
private float mCurrentFraction = 0f;
/**
* Tracks whether a startDelay'd animation has begun playing through the startDelay.
*/
private boolean mStartedDelay = false;
/**
* Tracks the time at which the animation began playing through its startDelay. This is
* different from the mStartTime variable, which is used to track when the animation became
* active (which is when the startDelay expired and the animation was added to the active
* animations list).
*/
private long mDelayStartTime;
/**
* Flag that represents the current state of the animation. Used to figure out when to start
* an animation (if state == STOPPED). Also used to end an animation that
* has been cancel()'d or end()'d since the last animation frame. Possible values are
* STOPPED, RUNNING, SEEKED.
*/
int mPlayingState = STOPPED;
/**
* Additional playing state to indicate whether an animator has been start()'d. There is
* some lag between a call to start() and the first animation frame. We should still note
* that the animation has been started, even if it's first animation frame has not yet
* happened, and reflect that state in isRunning().
* Note that delayed animations are different: they are not started until their first
* animation frame, which occurs after their delay elapses.
*/
private boolean mRu
没有合适的资源?快使用搜索试试~ 我知道了~
MaterialDesignLibrary_Code and Lib合集
共128个文件
java:56个
xml:39个
png:21个
5星 · 超过95%的资源 需积分: 10 85 下载量 96 浏览量
2015-09-21
15:36:10
上传
评论
收藏 300KB ZIP 举报
温馨提示
MaterialDesignLibrary_Code and Lib 内含:NineOldAndroidsLibrary包和一个测试项目:MaterialDesignActivity
资源推荐
资源详情
资源评论
收起资源包目录
MaterialDesignLibrary_Code and Lib合集 (128个子文件)
.classpath 475B
.classpath 475B
.classpath 475B
ValueAnimator.java 52KB
PropertyValuesHolder.java 45KB
AnimatorSet.java 45KB
ViewPropertyAnimatorHC.java 27KB
ViewPropertyAnimatorPreHC.java 27KB
ObjectAnimator.java 23KB
ViewPropertyAnimator.java 15KB
Slider.java 15KB
Keyframe.java 13KB
AnimatorInflater.java 13KB
Animator.java 10KB
KeyframeSet.java 10KB
AnimatorProxy.java 9KB
ReflectiveProperty.java 8KB
ViewHelper.java 8KB
ViewPropertyAnimatorICS.java 8KB
CheckBox.java 7KB
Switch.java 7KB
FloatKeyframeSet.java 6KB
IntKeyframeSet.java 6KB
ButtonFloat.java 6KB
Dialog.java 6KB
ButtonRectangle.java 6KB
PreHoneycombCompat.java 5KB
LayoutRipple.java 5KB
ProgressBarCircularIndeterminate.java 5KB
Button.java 5KB
SnackBar.java 5KB
Property.java 4KB
ColorSelector.java 4KB
MainActivity.java 4KB
ProgressDialog.java 4KB
ProgressBarDeterminate.java 4KB
ButtonFlat.java 3KB
ProgressActivity.java 3KB
AutoHideButtonFloat.java 3KB
TimeAnimator.java 3KB
ArgbEvaluator.java 2KB
WidgetActivity.java 2KB
Card.java 2KB
ProgressBarIndeterminateDeterminate.java 2KB
FloatEvaluator.java 2KB
IntEvaluator.java 2KB
ProgressBarIndeterminate.java 2KB
TypeEvaluator.java 2KB
IntProperty.java 2KB
FloatProperty.java 2KB
ButtonIcon.java 2KB
AnimatorListenerAdapter.java 1KB
CustomView.java 1KB
ButtonFloatSmall.java 1KB
ButtonsActivity.java 995B
NoSuchPropertyException.java 993B
ScrollView.java 929B
Utils.java 922B
SwitchActivity.java 795B
ic_launcher.png 20KB
ic_launcher.png 20KB
ic_launcher.png 20KB
ic_launcher.png 20KB
float_button1_shadowp.png 20KB
icn_progress.png 5KB
icn_switch.png 5KB
sprite_check.png 4KB
sprite_check.png 4KB
sprite_check.png 4KB
sprite_check.png 4KB
sprite_check.png 4KB
icn_widget.png 4KB
icn_button.png 4KB
icn_select_color.png 4KB
ic_reloj_max.png 4KB
dialog_background.9.png 3KB
ic_next.png 3KB
float_button_shadow1.png 1KB
background_button.9.png 450B
ic_action_new.png 318B
org.eclipse.jdt.core.prefs 177B
org.eclipse.jdt.core.prefs 177B
org.eclipse.jdt.core.prefs 177B
.project 858B
.project 858B
.project 857B
project.properties 638B
project.properties 616B
project.properties 382B
activity_progress.xml 7KB
activity_buttons.xml 6KB
activity_main.xml 5KB
color_selector.xml 4KB
activity_switchs.xml 4KB
activity_widgets.xml 4KB
dialog.xml 3KB
attributes.xml 2KB
snackbar.xml 2KB
AndroidManifest.xml 1KB
pom.xml 1KB
共 128 条
- 1
- 2
资源评论
- 陌颜啊2015-11-16功能很强大,挺不错的
zhangphil
- 粉丝: 1w+
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功