PropertyValuesHolder实现机制
2016-05-19 09:12
483 查看
一.使用
二.实现
/*
该类维护一个属性和该属性对应的一堆的KeyframeSet
*/
PropertyValuesHolder {
String mPropertyName;
KeyframeSet mKeyframeSet = null;
protected Property mProperty;
Method mSetter = null;
private Method mGetter = null;
Class mValueType;
}
public abstract class Property<T, V> {
private final String mName;
private final Class<V> mType;
}
/*
维护Keyframe的链表
*/
class KeyframeSet {
int mNumKeyframes;
Keyframe mFirstKeyframe;
Keyframe mLastKeyframe;
TimeInterpolator mInterpolator; // only used in the 2-keyframe case
ArrayList<Keyframe> mKeyframes; // only used when there are not 2 keyframes
TypeEvaluator mEvaluator;
public KeyframeSet(Keyframe... keyframes) {
mNumKeyframes = keyframes.length;
mKeyframes = new ArrayList<Keyframe>();
mKeyframes.addAll(Arrays.asList(keyframes));
mFirstKeyframe = mKeyframes.get(0);
mLastKeyframe = mKeyframes.get(mNumKeyframes - 1);
mInterpolator = mLastKeyframe.getInterpolator();
}
public static KeyframeSet ofInt(int... values) {
int numKeyframes = values.length;
IntKeyframe keyframes[] = new IntKeyframe[Math.max(numKeyframes,2)];
if (numKeyframes == 1) {
// 传进来的只有最终动画的值(1个value)-->保存0和结束的值
keyframes[0] = (IntKeyframe) Keyframe.ofInt(0f);
keyframes[1] = (IntKeyframe) Keyframe.ofInt(1f, values[0]);
} else {
keyframes[0] = (IntKeyframe) Keyframe.ofInt(0f, values[0]);
for (int i = 1; i < numKeyframes; ++i) {
keyframes[i] =
(IntKeyframe) Keyframe.ofInt((float) i / (numKeyframes - 1), values[i]);
}
}
return new IntKeyframeSet(keyframes);
}
}
/*
维护两个成员:mFraction, mValue的Item
*/
public abstract class Keyframe implements Cloneable {
/**
* The time at which mValue will hold true.
*/
float mFraction;
/**
* The type of the value in this Keyframe. This type is determined at construction time,
* based on the type of the <code>value</code> object passed into the constructor.
*/
Class mValueType;
/**
* The optional time interpolator for the interval preceding this keyframe. A null interpolator
* (the default) results in linear interpolation over the interval.
*/
private TimeInterpolator mInterpolator = null;
public static Keyframe ofInt(float fraction, int value) {
return new IntKeyframe(fraction, value);
}
}
/**
* Internal subclass used when the keyframe value is of type int.
*/
static class IntKeyframe extends Keyframe {
/**
* The value of the animation at the time mFraction.
*/
int mValue;
IntKeyframe(float fraction, int value) {
mFraction = fraction;
mValue = value;
mValueType = int.class;
mHasValue = true;
}
IntKeyframe(float fraction) {
mFraction = fraction;
mValueType = int.class;
}
public int getIntValue() {
return mValue;
}
public Object getValue() {
return mValue;
}
public void setValue(Object value) {
if (value != null && value.getClass() == Integer.class) {
mValue = ((Integer)value).intValue();
mHasValue = true;
}
}
}
三.总结
二.实现
/*
该类维护一个属性和该属性对应的一堆的KeyframeSet
*/
PropertyValuesHolder {
String mPropertyName;
KeyframeSet mKeyframeSet = null;
protected Property mProperty;
Method mSetter = null;
private Method mGetter = null;
Class mValueType;
}
public abstract class Property<T, V> {
private final String mName;
private final Class<V> mType;
}
/*
维护Keyframe的链表
*/
class KeyframeSet {
int mNumKeyframes;
Keyframe mFirstKeyframe;
Keyframe mLastKeyframe;
TimeInterpolator mInterpolator; // only used in the 2-keyframe case
ArrayList<Keyframe> mKeyframes; // only used when there are not 2 keyframes
TypeEvaluator mEvaluator;
public KeyframeSet(Keyframe... keyframes) {
mNumKeyframes = keyframes.length;
mKeyframes = new ArrayList<Keyframe>();
mKeyframes.addAll(Arrays.asList(keyframes));
mFirstKeyframe = mKeyframes.get(0);
mLastKeyframe = mKeyframes.get(mNumKeyframes - 1);
mInterpolator = mLastKeyframe.getInterpolator();
}
public static KeyframeSet ofInt(int... values) {
int numKeyframes = values.length;
IntKeyframe keyframes[] = new IntKeyframe[Math.max(numKeyframes,2)];
if (numKeyframes == 1) {
// 传进来的只有最终动画的值(1个value)-->保存0和结束的值
keyframes[0] = (IntKeyframe) Keyframe.ofInt(0f);
keyframes[1] = (IntKeyframe) Keyframe.ofInt(1f, values[0]);
} else {
keyframes[0] = (IntKeyframe) Keyframe.ofInt(0f, values[0]);
for (int i = 1; i < numKeyframes; ++i) {
keyframes[i] =
(IntKeyframe) Keyframe.ofInt((float) i / (numKeyframes - 1), values[i]);
}
}
return new IntKeyframeSet(keyframes);
}
}
/*
维护两个成员:mFraction, mValue的Item
*/
public abstract class Keyframe implements Cloneable {
/**
* The time at which mValue will hold true.
*/
float mFraction;
/**
* The type of the value in this Keyframe. This type is determined at construction time,
* based on the type of the <code>value</code> object passed into the constructor.
*/
Class mValueType;
/**
* The optional time interpolator for the interval preceding this keyframe. A null interpolator
* (the default) results in linear interpolation over the interval.
*/
private TimeInterpolator mInterpolator = null;
public static Keyframe ofInt(float fraction, int value) {
return new IntKeyframe(fraction, value);
}
}
/**
* Internal subclass used when the keyframe value is of type int.
*/
static class IntKeyframe extends Keyframe {
/**
* The value of the animation at the time mFraction.
*/
int mValue;
IntKeyframe(float fraction, int value) {
mFraction = fraction;
mValue = value;
mValueType = int.class;
mHasValue = true;
}
IntKeyframe(float fraction) {
mFraction = fraction;
mValueType = int.class;
}
public int getIntValue() {
return mValue;
}
public Object getValue() {
return mValue;
}
public void setValue(Object value) {
if (value != null && value.getClass() == Integer.class) {
mValue = ((Integer)value).intValue();
mHasValue = true;
}
}
}
三.总结
相关文章推荐
- ValueAnimator实现机制_源码分析
- window运行gradle build -- --stacktrace出现找不到文件framework-4.3.0.BUILD-SNAPSHOT-schema.zip异常
- hdu 1159Common Subsequence(dp 最大不连续的子序列)
- android Activity runOnUiThread() 方法使用
- UICollectionView-网格视图
- 02.LoT.UI 前后台通用框架分解系列之——灵活的菜单栏
- AdapterView.AdapterContextMenuInfo
- 01.LoT.UI 前后台通用框架分解系列之——小图片背景全屏显示(可自动切换背景)
- complex类 序列化时 IsRequired = true 问题
- Android异步更新UI的四种方式
- 更换证书后 打包异常 "UUID not found"/ "xxxx描述文件 not found"
- 125_ListView和UI卡顿
- hibernateTransactionManager 与REQUIRES_NEW的问题
- 2016 UESTC Training for Search Algorithm & String(A B C E I K)
- POJ 1947-Rebuilding Roads-(树形DP)
- 用JS代码怎么实现两个文本框的Value相乘
- UITableView 抽取及控制器的调用整合
- Query采用each方法遍历
- Exception in thread "main" org.hibernate.QueryException: illegal attempt to dereference collection
- LeetCode 334. Increasing Triplet Subsequence