List of usage examples for android.animation ObjectAnimator addListener
public void addListener(AnimatorListener listener)
From source file:android.support.transition.ChangeBounds.java
@Override @Nullable// ww w. jav a2 s. co m public Animator createAnimator(@NonNull final ViewGroup sceneRoot, @Nullable TransitionValues startValues, @Nullable TransitionValues endValues) { if (startValues == null || endValues == null) { return null; } Map<String, Object> startParentVals = startValues.values; Map<String, Object> endParentVals = endValues.values; ViewGroup startParent = (ViewGroup) startParentVals.get(PROPNAME_PARENT); ViewGroup endParent = (ViewGroup) endParentVals.get(PROPNAME_PARENT); if (startParent == null || endParent == null) { return null; } final View view = endValues.view; if (parentMatches(startParent, endParent)) { Rect startBounds = (Rect) startValues.values.get(PROPNAME_BOUNDS); Rect endBounds = (Rect) endValues.values.get(PROPNAME_BOUNDS); final int startLeft = startBounds.left; final int endLeft = endBounds.left; final int startTop = startBounds.top; final int endTop = endBounds.top; final int startRight = startBounds.right; final int endRight = endBounds.right; final int startBottom = startBounds.bottom; final int endBottom = endBounds.bottom; final int startWidth = startRight - startLeft; final int startHeight = startBottom - startTop; final int endWidth = endRight - endLeft; final int endHeight = endBottom - endTop; Rect startClip = (Rect) startValues.values.get(PROPNAME_CLIP); Rect endClip = (Rect) endValues.values.get(PROPNAME_CLIP); int numChanges = 0; if ((startWidth != 0 && startHeight != 0) || (endWidth != 0 && endHeight != 0)) { if (startLeft != endLeft || startTop != endTop) ++numChanges; if (startRight != endRight || startBottom != endBottom) ++numChanges; } if ((startClip != null && !startClip.equals(endClip)) || (startClip == null && endClip != null)) { ++numChanges; } if (numChanges > 0) { Animator anim; if (!mResizeClip) { ViewUtils.setLeftTopRightBottom(view, startLeft, startTop, startRight, startBottom); if (numChanges == 2) { if (startWidth == endWidth && startHeight == endHeight) { Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); anim = ObjectAnimatorUtils.ofPointF(view, POSITION_PROPERTY, topLeftPath); } else { final ViewBounds viewBounds = new ViewBounds(view); Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); ObjectAnimator topLeftAnimator = ObjectAnimatorUtils.ofPointF(viewBounds, TOP_LEFT_PROPERTY, topLeftPath); Path bottomRightPath = getPathMotion().getPath(startRight, startBottom, endRight, endBottom); ObjectAnimator bottomRightAnimator = ObjectAnimatorUtils.ofPointF(viewBounds, BOTTOM_RIGHT_PROPERTY, bottomRightPath); AnimatorSet set = new AnimatorSet(); set.playTogether(topLeftAnimator, bottomRightAnimator); anim = set; set.addListener(new AnimatorListenerAdapter() { // We need a strong reference to viewBounds until the // animator ends (The ObjectAnimator holds only a weak reference). @SuppressWarnings("unused") private ViewBounds mViewBounds = viewBounds; }); } } else if (startLeft != endLeft || startTop != endTop) { Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); anim = ObjectAnimatorUtils.ofPointF(view, TOP_LEFT_ONLY_PROPERTY, topLeftPath); } else { Path bottomRight = getPathMotion().getPath(startRight, startBottom, endRight, endBottom); anim = ObjectAnimatorUtils.ofPointF(view, BOTTOM_RIGHT_ONLY_PROPERTY, bottomRight); } } else { int maxWidth = Math.max(startWidth, endWidth); int maxHeight = Math.max(startHeight, endHeight); ViewUtils.setLeftTopRightBottom(view, startLeft, startTop, startLeft + maxWidth, startTop + maxHeight); ObjectAnimator positionAnimator = null; if (startLeft != endLeft || startTop != endTop) { Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); positionAnimator = ObjectAnimatorUtils.ofPointF(view, POSITION_PROPERTY, topLeftPath); } final Rect finalClip = endClip; if (startClip == null) { startClip = new Rect(0, 0, startWidth, startHeight); } if (endClip == null) { endClip = new Rect(0, 0, endWidth, endHeight); } ObjectAnimator clipAnimator = null; if (!startClip.equals(endClip)) { ViewCompat.setClipBounds(view, startClip); clipAnimator = ObjectAnimator.ofObject(view, "clipBounds", sRectEvaluator, startClip, endClip); clipAnimator.addListener(new AnimatorListenerAdapter() { private boolean mIsCanceled; @Override public void onAnimationCancel(Animator animation) { mIsCanceled = true; } @Override public void onAnimationEnd(Animator animation) { if (!mIsCanceled) { ViewCompat.setClipBounds(view, finalClip); ViewUtils.setLeftTopRightBottom(view, endLeft, endTop, endRight, endBottom); } } }); } anim = TransitionUtils.mergeAnimators(positionAnimator, clipAnimator); } if (view.getParent() instanceof ViewGroup) { final ViewGroup parent = (ViewGroup) view.getParent(); ViewGroupUtils.suppressLayout(parent, true); TransitionListener transitionListener = new TransitionListenerAdapter() { boolean mCanceled = false; @Override public void onTransitionCancel(@NonNull Transition transition) { ViewGroupUtils.suppressLayout(parent, false); mCanceled = true; } @Override public void onTransitionEnd(@NonNull Transition transition) { if (!mCanceled) { ViewGroupUtils.suppressLayout(parent, false); } transition.removeListener(this); } @Override public void onTransitionPause(@NonNull Transition transition) { ViewGroupUtils.suppressLayout(parent, false); } @Override public void onTransitionResume(@NonNull Transition transition) { ViewGroupUtils.suppressLayout(parent, true); } }; addListener(transitionListener); } return anim; } } else { int startX = (Integer) startValues.values.get(PROPNAME_WINDOW_X); int startY = (Integer) startValues.values.get(PROPNAME_WINDOW_Y); int endX = (Integer) endValues.values.get(PROPNAME_WINDOW_X); int endY = (Integer) endValues.values.get(PROPNAME_WINDOW_Y); // TODO: also handle size changes: check bounds and animate size changes if (startX != endX || startY != endY) { sceneRoot.getLocationInWindow(mTempLocation); Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.draw(canvas); @SuppressWarnings("deprecation") final BitmapDrawable drawable = new BitmapDrawable(bitmap); final float transitionAlpha = ViewUtils.getTransitionAlpha(view); ViewUtils.setTransitionAlpha(view, 0); ViewUtils.getOverlay(sceneRoot).add(drawable); Path topLeftPath = getPathMotion().getPath(startX - mTempLocation[0], startY - mTempLocation[1], endX - mTempLocation[0], endY - mTempLocation[1]); PropertyValuesHolder origin = PropertyValuesHolderUtils.ofPointF(DRAWABLE_ORIGIN_PROPERTY, topLeftPath); ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(drawable, origin); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { ViewUtils.getOverlay(sceneRoot).remove(drawable); ViewUtils.setTransitionAlpha(view, transitionAlpha); } }); return anim; } } return null; }
From source file:com.serenegiant.aceparrot.BaseFragment.java
/** * 01??(View)??/* w ww. j a va2s.c o m*/ * @param target * @param startDelay */ @SuppressLint("NewApi") protected final void fadeIn(final View target, final long duration, final long startDelay) { // if (DEBUG) Log.v(TAG, "fadeIn:target=" + target); if (target == null) return; target.clearAnimation(); target.setVisibility(View.VISIBLE); target.setTag(R.id.anim_type, ANIM_FADE_IN); // ??? target.setScaleX(1.0f); target.setScaleY(1.0f); target.setAlpha(0.0f); final ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(target, "alpha", 0f, 1f); objectAnimator.addListener(mAnimatorListener); if (BuildCheck.isJellyBeanMR2()) objectAnimator.setAutoCancel(true); // API >= 18 ??????Animator???? objectAnimator.setDuration(duration > 0 ? duration : 500); // 0.5??? objectAnimator.setStartDelay(startDelay > 0 ? startDelay : 0); // ??? objectAnimator.start(); // }
From source file:com.serenegiant.aceparrot.BaseFragment.java
/** * 10??(View)??/*from w w w. j av a 2s .c o m*/ * @param target * @param startDelay */ @SuppressLint("NewApi") protected final void fadeOut(final View target, final long duration, final long startDelay) { // if (DEBUG) Log.v(TAG, "fadeOut,target=" + target); if (target == null) return; target.clearAnimation(); if (target.getVisibility() == View.VISIBLE) { target.setTag(R.id.anim_type, ANIM_FADE_OUT); // ?? target.setScaleX(1.0f); target.setScaleY(1.0f); target.setAlpha(1.0f); final ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(target, "alpha", 1f, 0f); objectAnimator.addListener(mAnimatorListener); if (BuildCheck.isAndroid4_3()) objectAnimator.setAutoCancel(true); // API >= 18 ??????Animator???? objectAnimator.setDuration(duration > 0 ? duration : 500); // 0.5??? objectAnimator.setStartDelay(startDelay > 0 ? startDelay : 0); // ??? objectAnimator.start(); // } }
From source file:me.lizheng.deckview.views.DeckChildView.java
/** * Animates this task view as it enters recents *//*from w w w .j av a 2s . co m*/ void startEnterRecentsAnimation(final ViewAnimation.TaskViewEnterContext ctx) { Log.i(getClass().getSimpleName(), "startEnterRecentsAnimation"); final DeckChildViewTransform transform = ctx.currentTaskTransform; int startDelay = 0; if (mConfig.launchedFromHome) { Log.i(getClass().getSimpleName(), "mConfig.launchedFromHome false"); // Animate the tasks up int frontIndex = (ctx.currentStackViewCount - ctx.currentStackViewIndex - 1); int delay = mConfig.transitionEnterFromHomeDelay + frontIndex * mConfig.taskViewEnterFromHomeStaggerDelay; setScaleX(transform.scale); setScaleY(transform.scale); ObjectAnimator animator = ObjectAnimator.ofFloat(this, "TranslationY", getTranslationY(), transform.translationY); animator.addUpdateListener(ctx.updateListener); animator.setDuration( mConfig.taskViewEnterFromHomeDuration + frontIndex * mConfig.taskViewEnterFromHomeStaggerDelay); animator.setStartDelay(delay); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // Decrement the post animation trigger ctx.postAnimationTrigger.decrement(); } }); animator.start(); ctx.postAnimationTrigger.increment(); startDelay = delay; } // Enable the focus animations from this point onwards so that they aren't affected by the // window transitions postDelayed(new Runnable() { @Override public void run() { enableFocusAnimations(); } }, startDelay); }
From source file:com.serenegiant.aceparrot.BaseFragment.java
/** * start?stop????/*from www.ja va 2 s .c om*/ * @param target * @param type ??????? * @param start [0.0f-1.0f] * @param stop [0.0f-1.0f] * @param duration [] * @param startDelay [] */ @SuppressLint("NewApi") protected final void alphaAnimation(final View target, final int type, final float start, final float stop, final long duration, final long startDelay, final AnimationCallback callback) { // if (DEBUG) Log.v(TAG, "fadeOut,target=" + target); if (target == null) return; target.clearAnimation(); if (target.getVisibility() == View.VISIBLE) { target.setTag(R.id.anim_type, type); target.setTag(R.id.anim_callback, callback); target.setScaleX(1.0f); target.setScaleY(1.0f); target.setAlpha(start); final ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(target, "alpha", start, stop); objectAnimator.addListener(mAnimatorListener); if (BuildCheck.isAndroid4_3()) objectAnimator.setAutoCancel(true); // API >= 18 ??????Animator???? objectAnimator.setDuration(duration > 0 ? duration : 500); // 0.5??? objectAnimator.setStartDelay(startDelay > 0 ? startDelay : 0); // ??? objectAnimator.start(); // } }
From source file:com.serenegiant.aceparrot.BaseFragment.java
/** * 01??(View)??// w w w.ja v a 2 s . c om * @param target * @param startDelay */ @SuppressLint("NewApi") protected final void zoomIn(final View target, final long duration, final long startDelay) { // if (DEBUG) Log.v(TAG, "zoomIn:target=" + target); if (target == null) return; target.clearAnimation(); target.setVisibility(View.VISIBLE); target.setTag(R.id.anim_type, ANIM_ZOOM_IN); // ??? target.setScaleX(0.0f); target.setScaleY(0.0f); target.setAlpha(1.0f); final PropertyValuesHolder scale_x = PropertyValuesHolder.ofFloat("scaleX", 0.01f, 1f); final PropertyValuesHolder scale_y = PropertyValuesHolder.ofFloat("scaleY", 0.01f, 1f); final ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(target, scale_x, scale_y); objectAnimator.addListener(mAnimatorListener); if (BuildCheck.isJellyBeanMR2()) objectAnimator.setAutoCancel(true); // API >= 18 ??????Animator???? objectAnimator.setDuration(duration > 0 ? duration : 500); // 0.5??? objectAnimator.setStartDelay(startDelay > 0 ? startDelay : 0); // ??? objectAnimator.start(); // }
From source file:com.serenegiant.aceparrot.BaseFragment.java
/** * 10??(View)??/* ww w .j a v a 2 s . co m*/ * @param target * @param startDelay */ @SuppressLint("NewApi") protected final void zoomOut(final View target, final long duration, final long startDelay) { // if (DEBUG) Log.v(TAG, "zoomIn:target=" + target); if (target == null) return; target.clearAnimation(); target.setVisibility(View.VISIBLE); target.setTag(R.id.anim_type, ANIM_ZOOM_OUT); // ??? target.setScaleX(1.0f); target.setScaleY(1.0f); target.setAlpha(1.0f); final PropertyValuesHolder scale_x = PropertyValuesHolder.ofFloat("scaleX", 1f, 0f); final PropertyValuesHolder scale_y = PropertyValuesHolder.ofFloat("scaleY", 1f, 0f); final ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(target, scale_x, scale_y); objectAnimator.addListener(mAnimatorListener); if (BuildCheck.isJellyBeanMR2()) objectAnimator.setAutoCancel(true); // API >= 18 ??????Animator???? objectAnimator.setDuration(duration > 0 ? duration : 500); // 0.5??? objectAnimator.setStartDelay(startDelay > 0 ? startDelay : 0); // ??? objectAnimator.start(); // }
From source file:com.dgnt.dominionCardPicker.view.DynamicListView.java
/** * Resets all the appropriate fields to a default state while also animating * the hover cell back to its correct location. *///from www. ja v a2 s . c o m private void touchEventsEnded() { final View mobileView = getViewForID(mMobileItemId); if (mCellIsMobile || mIsWaitingForScrollFinish) { mCellIsMobile = false; mIsWaitingForScrollFinish = false; mIsMobileScrolling = false; mActivePointerId = INVALID_POINTER_ID; // If the autoscroller has not completed scrolling, we need to wait for it to // finish in order to determine the final location of where the hover cell // should be animated to. if (mScrollState != OnScrollListener.SCROLL_STATE_IDLE) { mIsWaitingForScrollFinish = true; return; } mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left, mobileView.getTop()); ObjectAnimator hoverViewAnimator = ObjectAnimator.ofObject(mHoverCell, "bounds", sBoundEvaluator, mHoverCellCurrentBounds); hoverViewAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { invalidate(); } }); hoverViewAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { setEnabled(false); } @Override public void onAnimationEnd(Animator animation) { mAboveItemId = INVALID_ID; mMobileItemId = INVALID_ID; mBelowItemId = INVALID_ID; mobileView.setVisibility(VISIBLE); mHoverCell = null; setEnabled(true); invalidate(); } }); hoverViewAnimator.start(); } else { touchEventsCancelled(); } }
From source file:com.waz.zclient.pages.main.conversation.views.row.footer.FooterViewController.java
private ObjectAnimator getViewTextViewAnimator(final View view, boolean animateIn, float to) { ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, to); animator.setDuration(//from w w w . java 2 s .c o m context.getResources().getInteger(com.waz.zclient.ui.R.integer.wire__animation__duration__short)); if (animateIn) { animator.setInterpolator(new Expo.EaseOut()); } else { animator.setInterpolator(new Expo.EaseIn()); } if (animateIn) { animator.setStartDelay( context.getResources().getInteger(com.waz.zclient.ui.R.integer.animation_delay_short)); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { view.setVisibility(View.VISIBLE); } }); } else { animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationCancel(Animator animation) { view.setVisibility(View.GONE); } @Override public void onAnimationEnd(Animator animation) { view.setVisibility(View.GONE); } }); } return animator; }
From source file:com.waz.zclient.views.menus.ConfirmationMenu.java
public void animateToShow(boolean show) { if (show) {/*from w w w.j a v a 2 s. c o m*/ confirmed = false; cancelled = false; // Init views and post animations to get measured height of message container backgroundView.setAlpha(0); messageContainerView.setVisibility(INVISIBLE); setVisibility(VISIBLE); messageContainerView.post(new Runnable() { @Override public void run() { ObjectAnimator showBackgroundAnimator = ObjectAnimator.ofFloat(backgroundView, View.ALPHA, 0, 1); showBackgroundAnimator.setInterpolator(new Quart.EaseOut()); showBackgroundAnimator .setDuration(getResources().getInteger(R.integer.framework_animation_duration_short)); ObjectAnimator showMessageAnimator = ObjectAnimator.ofFloat(messageContainerView, View.TRANSLATION_Y, messageContainerView.getMeasuredHeight(), 0); showMessageAnimator.setInterpolator(new Expo.EaseOut()); showMessageAnimator .setDuration(getResources().getInteger(R.integer.framework_animation_duration_medium)); showMessageAnimator.setStartDelay(getResources() .getInteger(R.integer.framework_animation__confirmation_menu__show_message_delay)); showMessageAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { messageContainerView.setVisibility(VISIBLE); } }); AnimatorSet showSet = new AnimatorSet(); showSet.playTogether(showBackgroundAnimator, showMessageAnimator); showSet.setDuration(getResources() .getInteger(R.integer.background_accent_color_transition_animation_duration)); showSet.start(); } }); } else { ObjectAnimator hideBackgroundAnimator = ObjectAnimator.ofFloat(backgroundView, View.ALPHA, 1, 0); hideBackgroundAnimator.setInterpolator(new Quart.EaseOut()); hideBackgroundAnimator .setDuration(getResources().getInteger(R.integer.framework_animation_duration_short)); hideBackgroundAnimator.setStartDelay(getResources() .getInteger(R.integer.framework_animation__confirmation_menu__hide_background_delay)); hideBackgroundAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { setVisibility(GONE); boolean checkboxIsSelected = checkBoxView.getVisibility() == VISIBLE && checkBoxView.isSelected(); if (callback != null) { callback.onHideAnimationEnd(confirmed, cancelled, checkboxIsSelected); } } }); ObjectAnimator hideMessageAnimator = ObjectAnimator.ofFloat(messageContainerView, View.TRANSLATION_Y, 0, messageContainerView.getMeasuredHeight()); hideMessageAnimator.setInterpolator(new Expo.EaseIn()); hideMessageAnimator .setDuration(getResources().getInteger(R.integer.framework_animation_duration_medium)); AnimatorSet hideSet = new AnimatorSet(); hideSet.playTogether(hideMessageAnimator, hideBackgroundAnimator); hideSet.start(); } }