下面列出了android.view.animation.LinearInterpolator#android.animation.Animator 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void setAutoCancel(final ObjectAnimator animator) {
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
for (WeakReference<ObjectAnimator> wa : sRunningAnimators) {
ObjectAnimator a = wa.get();
if (a == null) {
continue;
}
if (hasSameTargetAndProperties(animator, a)) {
a.cancel();
}
}
}
});
}
private void animateInFrameDetails() {
frameDetails.setVisibility(View.VISIBLE);
ViewUtils.onLaidOut(frameDetails, new Runnable() {
@Override
public void run() {
ObjectAnimator alpha = ObjectAnimator.ofFloat(frameDetails, View.ALPHA, 0.4f, 1f);
ObjectAnimator translate = ofFloat(frameDetails, View.TRANSLATION_Y, frameDetails.getHeight() * 0.3f, 0f);
AnimatorSet set = new AnimatorSet();
set.playTogether(alpha, translate);
set.setDuration(ANIM_DURATION);
set.setInterpolator(new LinearOutSlowInInterpolator());
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
frameMaster.setVisibility(View.GONE);
}
});
set.start();
}
});
}
@Override
public void onDragDismiss(final ArtboardView view, boolean isDragDown) {
mIsDragDismiss = true;
switchToArtboardListView();
view.animate().alpha(0.0F)
.translationY(isDragDown ? -view.getHeight() : view.getHeight())
.setDuration(AnimUtils.DURATION)
.setInterpolator(new AccelerateInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animator) {
mIsDragDismiss = false;
mArtboardPagerView.getBackground().mutate().setAlpha(255);
view.setTranslationY(0.0F);
view.setAlpha(1.0F);
}
})
.start();
}
/**
* Call to execute the animation
*/
public void execute(){
mValueAnimator = ValueAnimator.ofFloat(mStartValue, mEndValue);
mValueAnimator.setDuration(mDuration);
mValueAnimator.setInterpolator(mInterpolator);
mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float current = Float.valueOf(valueAnimator.getAnimatedValue().toString());
if(mListener!=null)mListener.onValueUpdate(current);
// mView.setText(String.format("%." + mPrecision + "f", current));
}
});
mValueAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (mListener != null) {
mListener.onAnimateCounterEnd();
}
}
});
mValueAnimator.start();
}
/**
* 显示内容布局
*/
@SuppressLint("NewApi")
final void showContentView() {
if (mContentView == null)
return;
mContentView.setTranslationY(getHeight() - mMonthView.getHeight());
mContentView.setVisibility(VISIBLE);
mContentView.animate()
.translationY(0)
.setDuration(180)
.setInterpolator(new LinearInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
}
});
}
private void shareViewTranslationAnimator(final float start, final float end) {
if (Build.VERSION.SDK_INT >= 11) {
ObjectAnimator bottomAnim = ObjectAnimator.ofFloat(llContent, "translationY", start, end);
bottomAnim.setDuration(duration);
bottomAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
if (start < end) {//close ShareView
shareView.setVisibility(View.GONE);
} else {//show ShareView
}
}
});
bottomAnim.start();
}
}
/**
* Animate appearance of a view
*
* @param view View to animate
* @param toVisibility Visibility at the end of animation
* @param toAlpha Alpha at the end of animation
* @param duration Animation duration in ms
*/
public static void animateView(final View view, final int toVisibility, float toAlpha, int duration) {
boolean show = toVisibility == View.VISIBLE;
if (show) {
view.setAlpha(0);
}
view.setVisibility(View.VISIBLE);
view.animate()
.setDuration(duration)
.alpha(show ? toAlpha : 0)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
view.setVisibility(toVisibility);
}
});
}
@Override
public void hideLoading() {
progress.animate()
.scaleX(0)
.scaleY(0)
.setDuration(300)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
//if the animation is still running when the back button has been pressed
if (progress != null) {
progress.setVisibility(View.GONE);
}
}
}).start();
}
public void startShimmerAnimation() {
if (isAnimationStarted) {
return;
}
if (getWidth() == 0) {
startAnimationPreDrawListener = new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
getViewTreeObserver().removeOnPreDrawListener(this);
startShimmerAnimation();
return true;
}
};
getViewTreeObserver().addOnPreDrawListener(startAnimationPreDrawListener);
return;
}
Animator animator = getShimmerAnimation();
animator.start();
isAnimationStarted = true;
}
/**
* 向四周伸张,直到完成显示。
*/
@SuppressLint("NewApi")
public static void show(View myView, float startRadius, long durationMills) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
myView.setVisibility(View.VISIBLE);
return;
}
int cx = (myView.getLeft() + myView.getRight()) / 2;
int cy = (myView.getTop() + myView.getBottom()) / 2;
int w = myView.getWidth();
int h = myView.getHeight();
// 勾股定理 & 进一法
int finalRadius = (int) Math.sqrt(w * w + h * h) + 1;
Animator anim =
ViewAnimationUtils.createCircularReveal(myView, cx, cy, startRadius, finalRadius);
myView.setVisibility(View.VISIBLE);
anim.setDuration(durationMills);
anim.start();
}
private void rotateIconAndChangeState()
{
IS_ANIMATING = true;
_indicatorIcon.clearAnimation();
ObjectAnimator anim = ObjectAnimator.ofFloat(_indicatorIcon, View.ROTATION, _isExpanded ? 0 : 180);
anim.setDuration(200);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
_indicatorIcon.setHasTransientState(true);
anim.addListener(new AnimatorListenerAdapter()
{
@Override
public void onAnimationEnd(Animator animation)
{
if(_isExpanded)
collapse();
else
expand();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
_indicatorIcon.setHasTransientState(false);
IS_ANIMATING = false;
}
});
anim.start();
}
private ObjectAnimator createExitTabSwitcherAnimation(
final boolean animateNormalToolbar) {
ObjectAnimator exitAnimation =
ObjectAnimator.ofFloat(this, mTabSwitcherModePercentProperty, 0.f);
exitAnimation.setDuration(animateNormalToolbar
? TAB_SWITCHER_MODE_EXIT_NORMAL_ANIMATION_DURATION_MS
: TAB_SWITCHER_MODE_EXIT_FADE_ANIMATION_DURATION_MS);
exitAnimation.setInterpolator(new LinearInterpolator());
exitAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
updateViewsForTabSwitcherMode();
}
});
return exitAnimation;
}
/**
* Rotate the contentView to x degree with animation.
*
* @param degree
* @param alpha
* @param listener
* @param duration
*/
public void animateContentViewRotationX(float degree, float alpha,
Animator.AnimatorListener listener,
int duration) {
if (DBG) Log.v(TAG, "animateContentViewRotationX - " +
"degree=" + degree + ", alpha=" + alpha);
mContentView.animate().cancel();
mContentView.animate()
.alpha(alpha)
.rotationX(degree)
.setListener(listener)
.setDuration(duration)
.start();
}
private void revealOn() {
if (binding.mapListContainer.getVisibility() == VISIBLE) return;
View container = binding.mapListContainer;
Animator animator = ViewAnimationUtils.createCircularReveal(
container,
getRevealCenterX(container),
container.getTop(),
0,
(float) Math.hypot(container.getWidth(), container.getHeight()));
animator.setInterpolator(INTERPOLATOR);
animator.setDuration(getResources().getInteger(R.integer.view_reveal_mills));
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
binding.mapListContainer.setVisibility(VISIBLE);
if (onVisibilityChangeListener != null) {
onVisibilityChangeListener.onChange();
}
}
});
animator.start();
}
public void setEmptyContainerState(boolean shouldShow) {
Animator nextAnimator = null;
if (shouldShow && getVisibility() != View.VISIBLE
&& mCurrentTransitionAnimation != mAnimateInAnimation) {
nextAnimator = mAnimateInAnimation;
UiUtils.hideKeyboard(this);
} else if (!shouldShow && getVisibility() != View.GONE
&& mCurrentTransitionAnimation != mAnimateOutAnimation) {
nextAnimator = mAnimateOutAnimation;
}
if (nextAnimator != null) {
if (mCurrentTransitionAnimation != null) mCurrentTransitionAnimation.cancel();
mCurrentTransitionAnimation = nextAnimator;
mCurrentTransitionAnimation.start();
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Animator createCircularReveal(View view,
int centerX, int centerY, float startRadius, float endRadius) {
if (API_SUPPORT_CIRCULAR_REVEAL) {
return android.view.ViewAnimationUtils.createCircularReveal(
view, centerX, centerY, startRadius, endRadius);
} else if (view instanceof Reveal){
return createRevealAnimator((Reveal) view, centerX, centerY,
startRadius, endRadius);
} else {
throw new IllegalStateException("Only View implements CircularReveal or" +
" api >= 21 can create circular reveal");
}
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void animateClose() {
mBalloonMarkerDrawable.stop();
ViewPropertyAnimator animator = mNumber.animate();
animator.alpha(0f);
animator.setDuration(100);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
animator.withEndAction(new Runnable() {
@Override
public void run() {
//We use INVISIBLE instead of GONE to avoid a requestLayout
mNumber.setVisibility(View.INVISIBLE);
mBalloonMarkerDrawable.animateToNormal();
}
});
} else {
animator.setListener(new AnimatorListener() {
@Override
public void onAnimationEnd(Animator animation) {
//We use INVISIBLE instead of GONE to avoid a requestLayout
mNumber.setVisibility(View.INVISIBLE);
mBalloonMarkerDrawable.animateToNormal();
}
});
}
animator.start();
}
public void setOutAnimator(Animator outAnim) {
if (this.outAnim != null)
this.outAnim.setTarget(null);
this.outAnim = outAnim;
if (outAnim != null)
outAnim.setTarget(this);
}
private boolean onItemLongClick(MessageObject item, View view, int a) {
if (actionBar.isActionModeShowed() || getParentActivity() == null) {
return false;
}
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
selectedFiles[item.getDialogId() == dialog_id ? 0 : 1].put(item.getId(), item);
if (!item.canDeleteMessage(false, null)) {
cantDeleteMessagesCount++;
}
actionBar.createActionMode().getItem(delete).setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE);
if (gotoItem != null) {
gotoItem.setVisibility(View.VISIBLE);
}
selectedMessagesCountTextView.setNumber(1, false);
AnimatorSet animatorSet = new AnimatorSet();
ArrayList<Animator> animators = new ArrayList<>();
for (int i = 0; i < actionModeViews.size(); i++) {
View view2 = actionModeViews.get(i);
AndroidUtilities.clearDrawableAnimation(view2);
animators.add(ObjectAnimator.ofFloat(view2, View.SCALE_Y, 0.1f, 1.0f));
}
animatorSet.playTogether(animators);
animatorSet.setDuration(250);
animatorSet.start();
scrolling = false;
if (view instanceof SharedDocumentCell) {
((SharedDocumentCell) view).setChecked(true, true);
} else if (view instanceof SharedPhotoVideoCell) {
((SharedPhotoVideoCell) view).setChecked(a, true, true);
} else if (view instanceof SharedLinkCell) {
((SharedLinkCell) view).setChecked(true, true);
} else if (view instanceof SharedAudioCell) {
((SharedAudioCell) view).setChecked(true, true);
}
if (!actionBar.isActionModeShowed()) {
actionBar.showActionMode(null, actionModeBackground, null, null, null, 0);
resetScroll();
}
return true;
}
@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
TransitionValues endValues) {
if (startValues == null || endValues == null) {
return null;
}
float initialTextSize = (float) startValues.values.get(PROPERTY_NAME_TEXT_RESIZE);
float targetTextSize = (float) endValues.values.get(PROPERTY_NAME_TEXT_RESIZE);
TextView targetView = (TextView) endValues.view;
targetView.setTextSize(TypedValue.COMPLEX_UNIT_PX, initialTextSize);
int initialPaddingStart = (int) startValues.values.get(PROPERTY_NAME_PADDING_RESIZE);
int targetPaddingStart = (int) endValues.values.get(PROPERTY_NAME_PADDING_RESIZE);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(
ObjectAnimator.ofFloat(targetView,
ViewUtils.PROPERTY_TEXT_SIZE,
initialTextSize,
targetTextSize),
ObjectAnimator.ofInt(targetView,
ViewUtils.PROPERTY_TEXT_PADDING_START,
initialPaddingStart,
targetPaddingStart));
return animatorSet;
}
public static void applyAlpha(View view, long delay, float alpha, Animator.AnimatorListener animatorListener){
ViewPropertyAnimator animator2 = view.animate();
animator2.alpha(alpha);
animator2.setInterpolator(new DecelerateInterpolator());
animator2.setStartDelay(delay);
animator2.setListener(animatorListener);
animator2.start();
}
private void removeViewInternal(final View child) {
if (child.getVisibility() != VISIBLE) {
super.removeView(child);
return;
}
executeRemoveViewTask();
View current = findNextTopView(child);
if (current == null) {
mRemoveViewReference = new WeakReference<View>(child);
sendRemoveViewMessage();
return;
}
final TransitionAdapter adapter = switchView(current, true);
if (mHandler.hasMessages(MESSAGE_REMOVE_VIEW)) {
mHandler.removeMessages(MESSAGE_REMOVE_VIEW);
}
mRemoveViewReference = new WeakReference<View>(child);
mValueAnimator = adapter.getAnimator();
mValueAnimator.setInterpolator(new DecelerateInterpolator());
mValueAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
sendRemoveViewMessage();
}
});
startAnimator();
return;
}
protected boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, RecyclerView.ViewHolder item) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("end change if necessary");
}
Animator a = animators.remove(item);
if (a != null) {
a.cancel();
}
boolean oldItem = false;
if (changeInfo.newHolder == item) {
changeInfo.newHolder = null;
} else if (changeInfo.oldHolder == item) {
changeInfo.oldHolder = null;
oldItem = true;
} else {
return false;
}
item.itemView.setAlpha(1);
if (item.itemView instanceof ChatMessageCell) {
((ChatMessageCell) item.itemView).setAnimationOffsetX(0);
((ChatMessageCell) item.itemView).getTransitionParams().resetAnimation();
} else {
item.itemView.setTranslationX(0);
}
item.itemView.setTranslationY(0);
dispatchChangeFinished(item, oldItem);
return true;
}
@Override
public Animator createAnimationFor(AnimationBody animationBody, final View view) {
final AnimatorSet animatorSet = new AnimatorSet();
final Animator animationClose = getCloseReveal(view);
final Animator animationOpen = getOpenReveal(view);
animationClose.addListener(
SimpleAnimatorListener.forEnd(animation -> ((FloatingActionButton) view).setImageResource(newIconResId)));
animatorSet.play(animationOpen).after(animationClose);
return animatorSet;
}
@Override
public void startAnimation(Animator.AnimatorListener listener)
{
if (mPeepHoleAnimator != null && mPeepHoleAnimator.isRunning())
{
return;
}
if (mPeepHoleCenterY == UNSET || mPeepHoleCenterX == UNSET)
{
mPeepHoleCenterX = mWidth / 2;
mPeepHoleCenterY = mHeight / 2;
}
mCirclePaint.setAlpha(255);
mCoverPaint.setAlpha(255);
// add peephole and reveal animators to a set, so we can
// freely add the listener without having to worry about
// listener dupes
AnimatorSet s = new AnimatorSet();
s.play(mPeepHoleAnimator).with(mRevealAlphaAnimator);
if (listener != null)
{
s.addListener(listener);
}
s.start();
}
/**
* Creates an AnimatorListenerAdapter that cleans up after an animation is completed.
* @return {@link AnimatorListenerAdapter} to use for animations.
*/
private AnimatorListener createAnimatorListener() {
return new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mGestureState = GESTURE_NONE;
mCurrentAnimation = null;
mIsBeingDisplayedForFirstTime = false;
}
};
}
@Override
public void setInterpolator(Interpolator value) {
Animator a = mAnimator.get();
if(a != null) {
a.setInterpolator(value);
}
}
@Override
public void setInterpolator(Interpolator value) {
Animator a = mNativeAnimator.get();
if(a != null) {
a.setInterpolator(value);
}
}
public static void onDestroyActivity() {
HashSet<Animator> animators = new HashSet<Animator>(sAnimators.keySet());
for (Animator a : animators) {
if (a.isRunning()) {
a.cancel();
}
sAnimators.remove(a);
}
}
public void playLevelEndAnimation() {
Vector2 destPos = _gameLevel.getSinkholeLocation();
// if level doesn't have a sink, don't bother with the animation
if (_ballSprite == null || destPos == null) {
_gameLevelStateListener.onOutAnimationComplete();
return;
}
_isAnimating = true;
long duration = 200;
ObjectAnimator.ofFloat(_ballSprite, "x", destPos.x).setDuration(duration).start();
ObjectAnimator animator = ObjectAnimator.ofFloat(_ballSprite, "y", destPos.y).setDuration(duration);
animator.start();
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
_ballSprite.hide(100);
_sinkHole.hide(200, null);
_sinkHoleBorder.hide(300, new AnimationCallback() {
@Override
public void onComplete() {
if (_gameLevelStateListener != null) {
_gameLevelStateListener.onOutAnimationComplete();
}
_isAnimating = false;
}
});
}
});
}