public void startAnimation(View focused) { if (mAnimatorSet == null || focused == null) { return; } mAnimatorSet.end(); focused.getGlobalVisibleRect(rect); mXAnimator.setFloatValues(rect.left + mLeftOffset); mYAnimator.setFloatValues(rect.top + mTopOffset); mWAnimator.setIntValues(rect.width()); mHAnimator.setIntValues(rect.height()); mAnimatorSet.start(); }
private void fadeOutDragView() { mFadeOutAnim = new ValueAnimator(); mFadeOutAnim.setDuration(150); mFadeOutAnim.setFloatValues(0f, 1f); mFadeOutAnim.removeAllUpdateListeners(); mFadeOutAnim.addUpdateListener( new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { final float percent = (Float) animation.getAnimatedValue(); float alpha = 1 - percent; mDropView.setAlpha(alpha); } }); mFadeOutAnim.addListener( new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { if (mDropView != null) { mDragController.onDeferredEndDrag(mDropView); } mDropView = null; invalidate(); } }); mFadeOutAnim.start(); }
public void animateView( final DragView view, AnimatorUpdateListener updateCb, int duration, TimeInterpolator interpolator, final Runnable onCompleteRunnable, final int animationEndStyle, View anchorView) { // Clean up the previous animations if (mDropAnim != null) mDropAnim.cancel(); if (mFadeOutAnim != null) mFadeOutAnim.cancel(); // Show the drop view if it was previously hidden mDropView = view; mDropView.cancelAnimation(); mDropView.resetLayoutParams(); // Set the anchor view if the page is scrolling if (anchorView != null) { mAnchorViewInitialScrollX = anchorView.getScrollX(); } mAnchorView = anchorView; // Create and start the animation mDropAnim = new ValueAnimator(); mDropAnim.setInterpolator(interpolator); mDropAnim.setDuration(duration); mDropAnim.setFloatValues(0f, 1f); mDropAnim.addUpdateListener(updateCb); mDropAnim.addListener( new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { if (onCompleteRunnable != null) { onCompleteRunnable.run(); } switch (animationEndStyle) { case ANIMATION_END_DISAPPEAR: clearAnimatedView(); break; case ANIMATION_END_FADE_OUT: fadeOutDragView(); break; case ANIMATION_END_REMAIN_VISIBLE: break; } } }); mDropAnim.start(); }
private ValueAnimator createAnimator(float... values) { ValueAnimator animator = new ValueAnimator(); animator.setDuration(1250); animator.setInterpolator(INTERPOLATOR); animator.setFloatValues(values); animator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { mCurrentValue = (Float) valueAnimator.getAnimatedValue(); invalidateSelf(); } }); return animator; }
public void open(ImageView srcImageView) { if (animator.isRunning()) { return; } if (parentView == null) { parentView = (View) getParent(); parentWidth = parentView.getWidth(); parentHeight = parentView.getHeight(); parentView.getLocationInWindow(parentLocation); } Drawable drawable = srcImageView.getDrawable(); right = drawableOriginWidth = drawable.getIntrinsicWidth(); bottom = drawableOriginHeight = drawable.getIntrinsicHeight(); setImageDrawable(drawable); if (parentView.getWidth() / (float) drawableOriginWidth > parentView.getHeight() / (float) drawableOriginHeight) scaleDirection = VERTICAL; // 以垂直方向参考 else scaleDirection = HORIZON; srcImageView.getLocationInWindow(srcLocation); beginLeft = srcLocation[0] - parentLocation[0]; beginTop = srcLocation[1] - parentLocation[1]; if (scaleDirection == VERTICAL) { finalTop = 0; finalLeft = (parentWidth - parentHeight * drawableOriginWidth / drawableOriginHeight) / 2; } else { finalTop = mWindowHeight / 2 - mLocation[1] - parentWidth / drawableOriginWidth * drawableOriginHeight / 2; finalLeft = 0; } mIsOpen = true; mFirstAnimPlay = true; parentView.setVisibility(VISIBLE); animator.setFloatValues(0, 1); animator.start(); }
private void animate(int direction) { final long currentPlayTime = mAnimator.getCurrentPlayTime(); final float toValue = (direction == IN) ? mOriginalToValue : mOriginalFromValue; final float startValue = mFirstRun ? mOriginalFromValue : ((Float) mAnimator.getAnimatedValue()).floatValue(); // Make sure it's stopped before we modify any values cancel(); mDirection = direction; // Ensure we don't calculate a non-sensical duration long duration = mOriginalDuration - currentPlayTime; mAnimator.setDuration(Math.max(0, Math.min(duration, mOriginalDuration))); mAnimator.setFloatValues(startValue, toValue); mAnimator.start(); mFirstRun = false; }
private void animate(int direction) { final long currentPlayTime = mAnimator.getCurrentPlayTime(); final float toValue = (direction == IN) ? mOriginalToValue : mOriginalFromValue; final float startValue = mFirstRun ? mOriginalFromValue : ((Float) mAnimator.getAnimatedValue()).floatValue(); // Make sure it's stopped before we modify any values cancel(); // TODO: We don't really need to do the animation if startValue == toValue, but // somehow that doesn't seem to work, possibly a quirk of the animation framework mDirection = direction; // Ensure we don't calculate a non-sensical duration long duration = mOriginalDuration - currentPlayTime; mAnimator.setDuration(Math.max(0, Math.min(duration, mOriginalDuration))); mAnimator.setFloatValues(startValue, toValue); mAnimator.start(); mFirstRun = false; }
private void d() { ValueAnimator localValueAnimator = new ValueAnimator(); localValueAnimator.setInterpolator(new AccelerateInterpolator()); localValueAnimator.setDuration(420L); localValueAnimator.setStartDelay(400L); localValueAnimator.setFloatValues(new float[] { 1.0F, 0.15F }); localValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator paramAnonymousValueAnimator) { s.c(s.this).setPercentFull(((Float)paramAnonymousValueAnimator.getAnimatedValue()).floatValue()); } }); localValueAnimator.addListener(new br() { public void onAnimationEnd(Animator paramAnonymousAnimator) { paramAnonymousAnimator = new ValueAnimator(); paramAnonymousAnimator.setRepeatMode(2); paramAnonymousAnimator.setRepeatCount(-1); paramAnonymousAnimator.setInterpolator(new DecelerateInterpolator()); paramAnonymousAnimator.setDuration(510L); paramAnonymousAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator paramAnonymous2ValueAnimator) { s.c(s.this).setPercentFull(((Float)paramAnonymous2ValueAnimator.getAnimatedValue()).floatValue()); } }); paramAnonymousAnimator.setFloatValues(new float[] { 0.15F, 0.2F }); paramAnonymousAnimator.start(); } }); localValueAnimator.start(); }
public void close() { if (animator.isRunning()) return; mIsOpen = false; animator.setFloatValues(1, 0); animator.start(); }
@Override public Animator createAnimator( ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) { if (startValues == null || endValues == null) { return null; } Log.i(LOG_TAG, "Creating animator for view = " + startValues.view.getTransitionName()); final View view = endValues.view; final float startRotation = (float) startValues.values.get(getPropKey(PROP_ROTATION, view)); final float endRotation = (float) endValues.values.get(getPropKey(PROP_ROTATION, view)); final float startX = (float) startValues.values.get(getPropKey(PROP_X, view)); final float endX = (float) endValues.values.get(getPropKey(PROP_X, view)); final float startY = (float) startValues.values.get(getPropKey(PROP_Y, view)); final float endY = (float) endValues.values.get(getPropKey(PROP_Y, view)); Log.i( LOG_TAG, "start rotation = " + startRotation + ", endRotation = " + endRotation + ", startX = " + startX + ", endX = " + endX + ", startY = " + startY + ", endY = " + endY); // no animation needed. if (startRotation == endRotation && startX == endX && startY == endY) { Log.w(LOG_TAG, "No animation for view"); return null; } ValueAnimator rotateAnimator = new ValueAnimator(); rotateAnimator.setFloatValues(startRotation, endRotation); rotateAnimator.setTarget(view); rotateAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { view.setRotation((float) animation.getAnimatedValue()); } }); ValueAnimator xAnimator = new ValueAnimator(); xAnimator.setFloatValues(startX, endX); xAnimator.setTarget(view); xAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { view.setX((float) animation.getAnimatedValue()); } }); ValueAnimator yAnimator = new ValueAnimator(); yAnimator.setFloatValues(startY, endY); yAnimator.setTarget(view); yAnimator.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { view.setY((float) animation.getAnimatedValue()); } }); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(rotateAnimator, xAnimator, yAnimator); return animatorSet; }
public static ValueAnimator ofFloat(View target, float... values) { ValueAnimator anim = new ValueAnimator(); anim.setFloatValues(values); cancelOnDestroyActivity(anim); return anim; }