Java 类android.animation.FloatEvaluator 实例源码
项目:Android-AudioRecorder-App
文件:RecordFragment.java
private void initViews(View recordView) {
chronometer = recordView.findViewById(R.id.chronometer);
audioVisualization = recordView.findViewById(R.id.visualizer_view);
mSettingsButton = recordView.findViewById(R.id.settings_btn);
mPlayListBtn = recordView.findViewById(R.id.play_list_btn);
mRecordButton = recordView.findViewById(R.id.btnRecord);
mPauseButton = recordView.findViewById(R.id.btnPause);
mPauseButton.setVisibility(View.GONE); //hide pause button before recording starts
alphaAnimator =
ObjectAnimator.ofObject(chronometer, "alpha", new FloatEvaluator(), 0.2f);
alphaAnimator.setRepeatMode(ValueAnimator.REVERSE);
alphaAnimator.setRepeatCount(ValueAnimator.INFINITE);
audioRecordPresenter.onViewInitialised();
}
项目:ScreenLocker2
文件:LockView.java
private void unlockAnim() {
final ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mUnlockIcon, View.ALPHA, 0.2f, 1, 1);
alphaAnimator.setRepeatCount(ValueAnimator.INFINITE);
alphaAnimator.setRepeatMode(ValueAnimator.REVERSE);
alphaAnimator.setEvaluator(new FloatEvaluator());
alphaAnimator.setDuration(1500);
alphaAnimator.start();
if (mRollingAnim == null) {
mRollingAnim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF,
0, Animation.RELATIVE_TO_SELF, -0.3f);
mRollingAnim.setRepeatCount(Animation.INFINITE);
mRollingAnim.setRepeatMode(Animation.REVERSE);
mRollingAnim.setDuration(1500);
}
mUnlockIcon.startAnimation(mRollingAnim);
}
项目:ScrollingBackgroundView
文件:ParallaxFragment.java
private void setUp(final ScrollingBackgroundView view, final int step, final float speed) {
view.postOnAnimation(new Runnable() {
@Override
public void run() {
final ValueAnimator animator = ValueAnimator.ofFloat(.0F, 1.F);
animator.setEvaluator(new FloatEvaluator());
animator.setDuration(400L);
animator.setRepeatMode(ValueAnimator.RESTART);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
view.scrollBy(
(int) (step * speed + .5F),
0
);
}
});
animator.start();
}
});
}
项目:ScrollingBackgroundView
文件:SpaceExplorerFragment.java
private void animate() {
if (mValueAnimator == null
|| !mValueAnimator.isRunning()) {
final ScrollingBackgroundView backgroundView = scrollingBackgroundView();
mValueAnimator = ValueAnimator.ofFloat(.0F, 1.F);
mValueAnimator.setRepeatCount(ValueAnimator.INFINITE);
mValueAnimator.setRepeatMode(ValueAnimator.RESTART);
mValueAnimator.setEvaluator(new FloatEvaluator());
mValueAnimator.setInterpolator(new LinearInterpolator());
mValueAnimator.setDuration(400L);
mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
final int x = (int) (mHorizontalStep * mSpeed + .5F);
final int y = (int) (mVerticalStep * mSpeed + .5F);
backgroundView.scrollBy(x, y);
mShipView.setRotation(shipRotation(x, y));
}
});
mValueAnimator.start();
}
}
项目:crate
文件:CrateRecyclerView.java
private void setFlingScale(float scale) {
if (mFlingScale != scale) {
if (BuildConfig.DEBUG) {
if (mBackgroundAnimator != null) {
mBackgroundAnimator.cancel();
}
mBackgroundAnimator = ValueAnimator.ofObject(new FloatEvaluator(), mFlingScale, scale);
mBackgroundAnimator.setDuration(BACKGROUND_COLOR_TRANSITION_MILLIS);
mBackgroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
mFlingScale = (float) animator.getAnimatedValue();
int newColor = (int) mArgbEvaluator.evaluate(mFlingScale, IDLE_BACKGROUND_COLOR, FLING_BACKGROUND_COLOR);
setBackgroundColor(newColor);
}
});
mBackgroundAnimator.start();
}
}
}
项目:DragBadgeView
文件:DragBadgeView.java
public void reset() {
final PointF tempDragPoint = new PointF(mDragPoint.x, mDragPoint.y);
if (tempDragPoint.x == mOriginPoint.x && tempDragPoint.y == mOriginPoint.y) {
return;
}
final FloatEvaluator evaluator = new FloatEvaluator();
mAnimator = ValueAnimator.ofFloat(1.0f);
mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator mAnim) {
float percent = mAnim.getAnimatedFraction();
updateDragPoint(evaluator.evaluate(percent, tempDragPoint.x, mOriginPoint.x),
evaluator.evaluate(percent, tempDragPoint.y, mOriginPoint.y));
}
});
mAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
clearAnimation();//结束时清除动画
ViewGroup rootView = (ViewGroup) BadgeView.this.getParent();
if (rootView != null) {
rootView.removeView(BadgeView.this);
DragBadgeView.this.setVisibility(VISIBLE);
}
recycleCacheBitmap();
}
});
mAnimator.setInterpolator(new OvershootInterpolator());
mAnimator.setDuration(500);
mAnimator.start();
}
项目:LQRBiliBlili
文件:LQRRefreshButton.java
public LQRRefreshButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// 获取自定义属性值
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.LQRRefreshButton);
borderColor = ta.getColor(R.styleable.LQRRefreshButton_refresh_btn_borderColor, Color.parseColor("#fb7299"));
borderWidth = ta.getDimension(R.styleable.LQRRefreshButton_refresh_btn_borderWidth, dipToPx(0));
borderRadius = ta.getDimension(R.styleable.LQRRefreshButton_refresh_btn_borderRadius, dipToPx(60));
text = ta.getString(R.styleable.LQRRefreshButton_refresh_btn_text);
if (text == null)
text = "";
textColor = ta.getColor(R.styleable.LQRRefreshButton_refresh_btn_textColor, Color.parseColor("#fb7299"));
textSize = ta.getDimension(R.styleable.LQRRefreshButton_refresh_btn_textSize, spToPx(14));
iconSrc = ta.getResourceId(R.styleable.LQRRefreshButton_refresh_btn_iconSrc, R.mipmap.tag_center_refresh_icon);
iconSize = ta.getDimension(R.styleable.LQRRefreshButton_refresh_btn_iconSize, dipToPx(14));
space4TextAndIcon = ta.getDimension(R.styleable.LQRRefreshButton_refresh_btn_space4TextAndIcon, dipToPx(10));
ta.recycle();
// icon
iconBitmap = BitmapFactory.decodeResource(getResources(), iconSrc);
iconBitmap = zoomImg(iconBitmap, iconSize, iconSize);
// 旋转动画
mAnimator = ObjectAnimator.ofObject(this, "degress", new FloatEvaluator(), 360, 0);
mAnimator.setDuration(2000);
mAnimator.setRepeatMode(ObjectAnimator.RESTART);
mAnimator.setInterpolator(new LinearInterpolator());
mAnimator.setRepeatCount(ObjectAnimator.INFINITE);
}
项目:SmileyRating
文件:BaseRating.java
private void createGreatSmile() {
float div = 0.10f;
FloatEvaluator f = new FloatEvaluator();
createSmile(new Point(mCenterSmile, mCenterY),
new Point(f.evaluate(div, mCenterSmile * 0.295, mCenterSmile), f.evaluate(div, mCenterY - (mCenterSmile * 0.23), mCenterY)), // Top control
new Point(f.evaluate(div, mCenterSmile * 0.295, mCenterSmile), f.evaluate(div, mCenterY - (mCenterSmile * 0.088), mCenterY)), // Bottom control
new Point(f.evaluate(div, mCenterSmile * 0.591, mCenterSmile), f.evaluate(div, mCenterY - (mCenterSmile * 0.23), mCenterY)), // Top Point
new Point(f.evaluate(div, mCenterSmile * 0.591, mCenterSmile), f.evaluate(div, mCenterY + (mCenterSmile * 0.118), mCenterY)), // Bottom point
Smile.MIRROR, GREAT, -1f, -1f, -1f);
}
项目:SmileyRating
文件:BaseRating.java
private void createGoodSmile() {
float div = 0.20f;
FloatEvaluator f = new FloatEvaluator();
createSmile(new Point(mCenterSmile, mCenterY),
new Point(f.evaluate(div, mCenterSmile * 0.414, mCenterSmile), f.evaluate(div, mCenterY - (mCenterSmile * 0.24), mCenterY)), // Top control
new Point(f.evaluate(div, mCenterSmile * 0.355, mCenterSmile), f.evaluate(div, mCenterY - (mCenterSmile * 0.029), mCenterY)), // Bottom control
new Point(f.evaluate(div, mCenterSmile * 0.65, mCenterSmile), f.evaluate(div, mCenterY - (mCenterSmile * 0.118), mCenterY)), // Top Point
new Point(f.evaluate(div, mCenterSmile * 0.591, mCenterSmile), f.evaluate(div, mCenterY + (mCenterSmile * 0.118), mCenterY)), // Bottom point
Smile.MIRROR, GOOD, -1f, -1f, -1f);
}
项目:SmileyRating
文件:BaseRating.java
private void createBadSmile() {
float div = 0.20f;
FloatEvaluator f = new FloatEvaluator();
createSmile(new Point(mCenterSmile, mCenterY),
new Point(f.evaluate(div, mCenterSmile * 0.414, mCenterSmile), f.evaluate(div, mCenterY - (mCenterSmile * 0.24), mCenterY)), // Top control
new Point(f.evaluate(div, mCenterSmile * 0.355, mCenterSmile), f.evaluate(div, mCenterY - (mCenterSmile * 0.029), mCenterY)), // Bottom control
new Point(f.evaluate(div, mCenterSmile * 0.65, mCenterSmile), f.evaluate(div, mCenterY - (mCenterSmile * 0.118), mCenterY)), // Top Point
new Point(f.evaluate(div, mCenterSmile * 0.591, mCenterSmile), f.evaluate(div, mCenterY + (mCenterSmile * 0.118), mCenterY)), // Bottom point
Smile.MIRROR_INVERSE, BAD, -1f, -1f, -1f);
}
项目:SmileyRating
文件:BaseRating.java
private void createTerribleSmile() {
float div = 0.20f;
FloatEvaluator f = new FloatEvaluator();
createSmile(new Point(mCenterSmile, mCenterY),
new Point(f.evaluate(div, mCenterSmile * 0.414, mCenterSmile), f.evaluate(div, mCenterY - (mCenterSmile * 0.24), mCenterY)), // Top control
new Point(f.evaluate(div, mCenterSmile * 0.355, mCenterSmile), f.evaluate(div, mCenterY - (mCenterSmile * 0.029), mCenterY)), // Bottom control
new Point(f.evaluate(div, mCenterSmile * 0.65, mCenterSmile), f.evaluate(div, mCenterY - (mCenterSmile * 0.118), mCenterY)), // Top Point
new Point(f.evaluate(div, mCenterSmile * 0.591, mCenterSmile), f.evaluate(div, mCenterY + (mCenterSmile * 0.118), mCenterY)), // Bottom point
Smile.MIRROR_INVERSE, TERRIBLE, -1f, -1f, -1f);
}
项目:OSchina_resources_android
文件:SolarSystemView.java
private ValueAnimator getAccelerateAnimator() {
if (mAccelerateAnimator != null) return mAccelerateAnimator;
mAccelerateAnimator = ValueAnimator.ofFloat(mFlushRate, FLUSH_RATE_LIMITATION);
mAccelerateAnimator.setEvaluator(new FloatEvaluator());
mAccelerateAnimator.setInterpolator(new DecelerateInterpolator());
mAccelerateAnimator.setDuration(1000);
mAccelerateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mFlushRate = ((Float) animation.getAnimatedValue()).intValue();
}
});
return mAccelerateAnimator;
}
项目:OSchina_resources_android
文件:SolarSystemView.java
private ValueAnimator getDecelerateAnimator() {
if (mDecelerateAnimator != null) return mDecelerateAnimator;
mDecelerateAnimator = ValueAnimator.ofFloat(mFlushRate, FLUSH_RATE);
mDecelerateAnimator.setEvaluator(new FloatEvaluator());
mDecelerateAnimator.setInterpolator(new AccelerateInterpolator());
mDecelerateAnimator.setDuration(1000);
mDecelerateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mFlushRate = ((Float) animation.getAnimatedValue()).intValue();
}
});
return mDecelerateAnimator;
}
项目:FuckingVolumeSlider
文件:Speaker.java
private void createSmallWawe(float centerX, float centerY) {
float fraction = 0.2f;
FloatEvaluator evaluator = new FloatEvaluator();
Point rightControll = new Point(evaluator.evaluate(fraction, centerX, centerX * 1.45), centerY);
Point rightPoint = new Point(evaluator.evaluate(fraction, centerX * 0.95, centerX), evaluator.evaluate(fraction, centerY * 0.35 * 1.5, centerY));
Wawe wawe = createWawe(
rightControll, //right controll
new Point(rightControll.x - gap * 0.45f, centerY), //left controll
rightPoint, //right point
new Point(rightPoint.x - gap * 0.7f, rightPoint.y), //left point
new Point(rightPoint.x - gap * 0.4f, rightPoint.y - gap * 0.6f), //top right controll
new Point(rightPoint.x - gap * 0.9f, rightPoint.y - gap * 0.4f) //top left controll
);
wawes.put(0, wawe);
}
项目:FuckingVolumeSlider
文件:Speaker.java
private void createBigWawe(float centerX, float centerY) {
float fraction = 0.2f;
FloatEvaluator evaluator = new FloatEvaluator();
Point rightControll = new Point(evaluator.evaluate(fraction, centerX, centerX * 1.45), centerY);
Point rightPoint = new Point(evaluator.evaluate(fraction, centerX * 0.95, centerX), evaluator.evaluate(fraction, centerY * 0.35, centerY));
Wawe wawe = createWawe(
rightControll, //right controll
new Point(rightControll.x - gap * 0.45f, centerY), //left controll
rightPoint, //right point
new Point(rightPoint.x - gap * 0.7f, rightPoint.y), //left point
new Point(rightPoint.x - gap * 0.4f, rightPoint.y - gap * 0.6f), //top right controll
new Point(rightPoint.x - gap * 0.9f, rightPoint.y - gap * 0.4f) //top left controll
);
wawes.put(1, wawe);
}
项目:ScreenLocker2
文件:LockView.java
public void batteryChargingAnim() {
if (PhoneStateHelper.isPowerConnected(mContext)) {
final ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(mBatteryCharging, View.ALPHA, 0.2f, 1, 1);
alphaAnimation.setRepeatCount(ValueAnimator.INFINITE);
alphaAnimation.setRepeatMode(ValueAnimator.REVERSE);
alphaAnimation.setEvaluator(new FloatEvaluator());
alphaAnimation.setDuration(1500);
alphaAnimation.start();
ViewU.show(mBatteryCharging);
} else {
ViewU.hide(mBatteryCharging);
cancelAnimation(mBatteryCharging);
}
}
项目:ViewPagerAnimator
文件:ViewPagerAnimator.java
public static ViewPagerAnimator<Number> ofFloat(ViewPager viewPager, Provider<Number> provider, Property<Number> property) {
final FloatEvaluator evaluator = new FloatEvaluator();
final Interpolator interpolator = new LinearInterpolator();
return ofFloat(viewPager, provider, property, evaluator, interpolator);
}
项目:PopupCircleMenu
文件:AnimUtil.java
public static ObjectAnimator toAlphaOne(View view, int duration) {
ObjectAnimator objectAnimator = ObjectAnimator.ofObject(view, "alpha", new FloatEvaluator(), 0.0f, 1.0f);
objectAnimator.setDuration(duration);
return objectAnimator;
}
项目:PopupCircleMenu
文件:AnimUtil.java
public static ObjectAnimator toAlphaZero(View view, int duration) {
ObjectAnimator objectAnimator = ObjectAnimator.ofObject(view, "alpha", new FloatEvaluator(), 1.0f, 0f);
objectAnimator.setDuration(duration);
return objectAnimator;
}
项目:SmileyRating
文件:BaseRating.java
protected Path transformSmile(float trans, float fraction, Path path, Smile s1, Smile s2, FloatEvaluator evaluator) {
path.reset();
path.moveTo(
evaluator.evaluate(fraction, s1.START_POINT.x, s2.START_POINT.x) + trans,
evaluator.evaluate(fraction, s1.START_POINT.y, s2.START_POINT.y)
);
path.cubicTo(
evaluator.evaluate(fraction, s1.TOP_CURVE[0].x, s2.TOP_CURVE[0].x) + trans,
evaluator.evaluate(fraction, s1.TOP_CURVE[0].y, s2.TOP_CURVE[0].y),
evaluator.evaluate(fraction, s1.TOP_CURVE[1].x, s2.TOP_CURVE[1].x) + trans,
evaluator.evaluate(fraction, s1.TOP_CURVE[1].y, s2.TOP_CURVE[1].y),
evaluator.evaluate(fraction, s1.TOP_CURVE[2].x, s2.TOP_CURVE[2].x) + trans,
evaluator.evaluate(fraction, s1.TOP_CURVE[2].y, s2.TOP_CURVE[2].y)
);
path.cubicTo(
evaluator.evaluate(fraction, s1.RIGHT_CURVE[0].x, s2.RIGHT_CURVE[0].x) + trans,
evaluator.evaluate(fraction, s1.RIGHT_CURVE[0].y, s2.RIGHT_CURVE[0].y),
evaluator.evaluate(fraction, s1.RIGHT_CURVE[1].x, s2.RIGHT_CURVE[1].x) + trans,
evaluator.evaluate(fraction, s1.RIGHT_CURVE[1].y, s2.RIGHT_CURVE[1].y),
evaluator.evaluate(fraction, s1.RIGHT_CURVE[2].x, s2.RIGHT_CURVE[2].x) + trans,
evaluator.evaluate(fraction, s1.RIGHT_CURVE[2].y, s2.RIGHT_CURVE[2].y)
);
path.cubicTo(
evaluator.evaluate(fraction, s1.BOTTOM_CURVE[0].x, s2.BOTTOM_CURVE[0].x) + trans,
evaluator.evaluate(fraction, s1.BOTTOM_CURVE[0].y, s2.BOTTOM_CURVE[0].y),
evaluator.evaluate(fraction, s1.BOTTOM_CURVE[1].x, s2.BOTTOM_CURVE[1].x) + trans,
evaluator.evaluate(fraction, s1.BOTTOM_CURVE[1].y, s2.BOTTOM_CURVE[1].y),
evaluator.evaluate(fraction, s1.BOTTOM_CURVE[2].x, s2.BOTTOM_CURVE[2].x) + trans,
evaluator.evaluate(fraction, s1.BOTTOM_CURVE[2].y, s2.BOTTOM_CURVE[2].y)
);
path.cubicTo(
evaluator.evaluate(fraction, s1.LEFT_CURVE[0].x, s2.LEFT_CURVE[0].x) + trans,
evaluator.evaluate(fraction, s1.LEFT_CURVE[0].y, s2.LEFT_CURVE[0].y),
evaluator.evaluate(fraction, s1.LEFT_CURVE[1].x, s2.LEFT_CURVE[1].x) + trans,
evaluator.evaluate(fraction, s1.LEFT_CURVE[1].y, s2.LEFT_CURVE[1].y),
evaluator.evaluate(fraction, s1.LEFT_CURVE[2].x, s2.LEFT_CURVE[2].x) + trans,
evaluator.evaluate(fraction, s1.LEFT_CURVE[2].y, s2.LEFT_CURVE[2].y)
);
path.close();
return path;
}
项目:AmenEye
文件:VideoInfoActivity.java
private void initView() {
Bundle bundle = getIntent().getExtras();
String title = bundle.getString(Constants.BUNDLE_KEY_TITLE);
String idOrUrl = bundle.getString(Constants.BUNDLE_KEY_ID);
String pic = bundle.getString(Constants.BUNDLE_KEY_IMG_URL);
mToolbarTitle.setText(title);
mJcVideoPlayer.backButton.setVisibility(View.GONE);
mJcVideoPlayer.titleTextView.setVisibility(View.GONE);
mJcVideoPlayer.tinyBackImageView.setVisibility(View.GONE);
mJcVideoPlayer.thumbImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
// new PicassoTarget(this, mJcVideoPlayer.thumbImageView, mToolbar)
Glide.with(this)
.load(pic)
.into( mJcVideoPlayer.thumbImageView);
final ArrayList<Fragment> fragments = new ArrayList<>();
//将首次需要加载的电影Id传递过去
VideoInfoFragment videoInfoFragment = new VideoInfoFragment();
Bundle arg = new Bundle();
arg.putString(Constants.BUNDLE_KEY_DATAID, idOrUrl);
videoInfoFragment.setArguments(arg);
VideoCommentFrag videoCommentFrag = new VideoCommentFrag();
videoCommentFrag.setArguments(arg);
fragments.add(videoInfoFragment);
fragments.add(videoCommentFrag);
mVpVideoInfo.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}
@Override
public int getCount() {
return fragments.size();
}
});
mVpVideoInfo.addOnPageChangeListener(this);
mVpVideoInfo.setCurrentItem(0);
argbEvaluator = new ArgbEvaluator();
floatEvaluator = new FloatEvaluator();
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finishAfterTransition();
}
});
}
项目:hintcase
文件:RevealRectangularShapeAnimator.java
private void init() {
floatEvaluator = new FloatEvaluator();
}
项目:hintcase
文件:UnrevealRectangularShapeAnimator.java
private void init() {
floatEvaluator = new FloatEvaluator();
}
项目:MaterialPreference
文件:SimpleMenuAnimation.java
@SuppressWarnings("unchecked")
private static Animator createElevationAnimator(View view, float elevation) {
Animator animator = ObjectAnimator.ofObject(view, View.TRANSLATION_Z, (TypeEvaluator) new FloatEvaluator(), -elevation, 0f);
animator.setInterpolator(new FastOutSlowInInterpolator());
return animator;
}
项目:Android-Support-Preference-V7-Fix
文件:SimpleMenuAnimation.java
@SuppressWarnings("unchecked")
private static Animator createElevationAnimator(View view, float elevation) {
Animator animator = ObjectAnimator.ofObject(view, View.TRANSLATION_Z, (TypeEvaluator) new FloatEvaluator(), -elevation, 0f);
animator.setInterpolator(new FastOutSlowInInterpolator());
return animator;
}
项目:Scrollable
文件:ScrollableLayout.java
/**
* Helper method to animate scroll state of ScrollableLayout.
* Please note, that returned {@link ValueAnimator} is not fully configured -
* it needs at least `duration` property.
* Also, there is no checks if the current scrollY is equal to the requested one.
* @param scrollY the final scroll y to animate to
* @return {@link ValueAnimator} configured to animate scroll state
*/
public ValueAnimator animateScroll(final int scrollY) {
// create an instance of this animator that is shared between calls
if (mManualScrollAnimator == null) {
mManualScrollAnimator = ValueAnimator.ofFloat(.0F, 1.F);
mManualScrollAnimator.setEvaluator(new FloatEvaluator());
mManualScrollAnimator.addListener(new SelfUpdateAnimationListener());
} else {
// unregister our update listener
if (mManualScrollUpdateListener != null) {
mManualScrollAnimator.removeUpdateListener(mManualScrollUpdateListener);
}
// cancel if running
if (mManualScrollAnimator.isRunning()) {
mManualScrollAnimator.end();
}
}
final int y;
if (scrollY < 0) {
y = 0;
} else if (scrollY > mMaxScrollY) {
y = mMaxScrollY;
} else {
y = scrollY;
}
final int startY = getScrollY();
final int diff = y - startY;
mManualScrollUpdateListener = new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
final float fraction = animation.getAnimatedFraction();
scrollTo(0, (int) (startY + (diff * fraction) + .5F));
}
};
mManualScrollAnimator.addUpdateListener(mManualScrollUpdateListener);
return mManualScrollAnimator;
}
项目:Scrollable
文件:ScrollableLayout.java
@Override
public void run() {
cancelIdleAnimationIfRunning(false);
if (mSelfUpdateScroll || mSelfUpdateFling) {
return;
}
final int nowY = getScrollY();
if (nowY == 0
|| nowY == mMaxScrollY) {
return;
}
final int endY = mCloseUpAlgorithm.getIdleFinalY(ScrollableLayout.this, nowY, mMaxScrollY);
if (nowY == endY) {
return;
}
if (mCloseUpAnimator == null) {
mCloseUpAnimator = ValueAnimator.ofFloat(.0F, 1.F);
mCloseUpAnimator.setEvaluator(new FloatEvaluator());
mCloseUpAnimator.addListener(new SelfUpdateAnimationListener());
} else {
if (mCloseUpUpdateListener != null) {
mCloseUpAnimator.removeUpdateListener(mCloseUpUpdateListener);
}
if (mCloseUpAnimator.isRunning()) {
mCloseUpAnimator.end();
}
}
final int diff = endY - nowY;
mCloseUpUpdateListener = new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
final float fraction = animation.getAnimatedFraction();
scrollTo(0, (int) (nowY + (diff * fraction) + .5F));
}
};
mCloseUpAnimator.addUpdateListener(mCloseUpUpdateListener);
final long duration = mCloseUpIdleAnimationTime != null
? mCloseUpIdleAnimationTime.compute(ScrollableLayout.this, nowY, endY, mMaxScrollY)
: DEFAULT_IDLE_CLOSE_UP_ANIMATION;
mCloseUpAnimator.setDuration(duration);
if (mCloseAnimatorConfigurator != null) {
mCloseAnimatorConfigurator.configure(mCloseUpAnimator);
}
mCloseUpAnimator.start();
}
项目:AndroidPercentageGadget
文件:AndroidPercentageGadget.java
private void addAnimation(View v) {
AnimatorSet set = new AnimatorSet();
if (v == null) {
return;
}
FloatEvaluator eval = new FloatEvaluator() {
/**
* This function returns the result of linearly interpolating the start and end values, with
* <code>fraction</code> representing the proportion between the start and end values. The
* calculation is a simple parametric calculation: <code>result = x0 + t * (v1 - v0)</code>,
* where <code>x0</code> is <code>startValue</code>, <code>x1</code> is <code>endValue</code>,
* and <code>t</code> is <code>fraction</code>.
*
* @param fraction The fraction from the starting to the ending values
* @param startValue The start value; should be of type <code>float</code> or
* <code>Float</code>
* @param endValue The end value; should be of type <code>float</code> or <code>Float</code>
* @return A linear interpolation between the start and end values, given the
* <code>fraction</code> parameter.
*/
@Override
public Float evaluate(float fraction, Number startValue, Number endValue) {
//return super.evaluate(fraction, startValue, endValue);
double sine = Math.sin(Math.PI * fraction) * 0.2;
return Float.valueOf((float)(startValue.floatValue() * (1.0 + sine)));
}
};
ObjectAnimator animator1 = ObjectAnimator.ofFloat(v, "scaleX", 1f, 1f);
animator1.setInterpolator(new LinearInterpolator());
animator1.setEvaluator(eval);
animator1.setDuration(250);
ObjectAnimator animator2 = ObjectAnimator.ofFloat(v, "scaleY", 1f, 1f);
animator2.setInterpolator(new LinearInterpolator());
animator2.setEvaluator(eval);
animator2.setDuration(250);
set.playTogether(animator1, animator2);
set.start();
}