List of usage examples for android.animation Animator getDuration
public abstract long getDuration();
From source file:Main.java
public static long getAnimDuration(AnimatorSet animatorset) { Iterator iterator = animatorset.getChildAnimations().iterator(); long l1 = 0L; while (iterator.hasNext()) { Animator animator = (Animator) iterator.next(); long l2 = animator.getStartDelay() + animator.getDuration(); long l3;//from ww w . j av a2 s . c om if (l2 > l1) { l3 = l2; } else { l3 = l1; } l1 = l3; } return l1; }
From source file:Main.java
public static void startAnimationAfterNextDraw(final Animator animator, final View view) { view.getViewTreeObserver().addOnDrawListener(new ViewTreeObserver.OnDrawListener() { private boolean mStarted = false; public void onDraw() { if (mStarted) return; mStarted = true;// w w w. jav a2 s .c o m // Use this as a signal that the animation was cancelled if (animator.getDuration() == 0) { return; } animator.start(); final ViewTreeObserver.OnDrawListener listener = this; view.post(new Runnable() { public void run() { view.getViewTreeObserver().removeOnDrawListener(listener); } }); } }); }
From source file:com.flexible.flexibleadapter.AnimatorAdapter.java
/** * Performs checks to scroll animate the itemView and in case, it animates the view. * <p><b>Note:</b> If you have to change at runtime the LayoutManager <i>and</i> add * Scrollable Headers too, consider to add them in post, using a {@code delay >= 0}, * otherwise scroll animations on all items will not start correctly.</p> * * @param holder the ViewHolder just bound * @param position the current item position *//*from w w w. j a v a 2 s. c o m*/ @SuppressWarnings("ConstantConditions") protected final void animateView(final RecyclerView.ViewHolder holder, final int position) { if (mRecyclerView == null) return; // Use always the max child count reached if (mMaxChildViews < mRecyclerView.getChildCount()) { mMaxChildViews = mRecyclerView.getChildCount(); } // Animate only during initial loading? if (onlyEntryAnimation && mLastAnimatedPosition >= mMaxChildViews) { shouldAnimate = false; } int lastVisiblePosition = Utils.findLastVisibleItemPosition(mRecyclerView.getLayoutManager()); // if (DEBUG) { // Log.v(TAG, "shouldAnimate=" + shouldAnimate // + " isFastScroll=" + isFastScroll // + " isNotified=" + mAnimatorNotifierObserver.isPositionNotified() // + " isReverseEnabled=" + isReverseEnabled // + " mLastAnimatedPosition=" + mLastAnimatedPosition // + (!isReverseEnabled ? " Pos>LasVisPos=" + (position > lastVisiblePosition) : "") // + " mMaxChildViews=" + mMaxChildViews // ); // } if (holder instanceof FlexibleViewHolder && shouldAnimate && !isFastScroll && !mAnimatorNotifierObserver.isPositionNotified() && (position > lastVisiblePosition || isReverseEnabled || isScrollableHeaderOrFooter(position) || (position == 0 && mMaxChildViews == 0))) { // Cancel animation is necessary when fling int hashCode = holder.itemView.hashCode(); cancelExistingAnimation(hashCode); // User animators List<Animator> animators = new ArrayList<>(); FlexibleViewHolder flexibleViewHolder = (FlexibleViewHolder) holder; flexibleViewHolder.scrollAnimators(animators, position, position >= lastVisiblePosition); // Execute the animations together AnimatorSet set = new AnimatorSet(); set.playTogether(animators); set.setInterpolator(mInterpolator); // Single view duration long duration = mDuration; for (Animator animator : animators) { if (animator.getDuration() != DEFAULT_DURATION) { duration = animator.getDuration(); } } //Log.v(TAG, "duration=" + duration); set.setDuration(duration); set.addListener(new HelperAnimatorListener(hashCode)); if (mEntryStep) { // Stop stepDelay when screen is filled set.setStartDelay(calculateAnimationDelay(position)); } set.start(); mAnimators.put(hashCode, set); if (DEBUG) Log.v(TAG, "animateView Scroll animation on position " + position); } mAnimatorNotifierObserver.clearNotified(); // Update last animated position mLastAnimatedPosition = position; }