Java Code Examples for android.animation.Animator#getDuration()

The following examples show how to use android.animation.Animator#getDuration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Banner.java    From MaterialBanner with Apache License 2.0 6 votes vote down vote up
@Override
public void onAnimationEnd(Animator animation) {
    mIsAnimating = false;
    if (animation.getDuration() == ANIM_DURATION_DISMISS) {
        setVisibility(GONE);

        // Reset to default
        MarginLayoutParams layoutParams = (MarginLayoutParams) getLayoutParams();
        layoutParams.bottomMargin = mMarginBottom;
        setLayoutParams(layoutParams);
        setTranslationY(0);
    }

    if (isShown()) {
        dispatchOnShow();
    } else {
        dispatchOnDismiss();
    }
}
 
Example 2
Source File: AnimUtil.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
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;
        if (l2 > l1)
        {
            l3 = l2;
        } else
        {
            l3 = l1;
        }
        l1 = l3;
    }
    return l1;
}
 
Example 3
Source File: RepeatAction.java    From AndroidAnimationsActions with MIT License 5 votes vote down vote up
private long countDuration(Animator animator) {
    long duration = 0;
    if (animator instanceof AnimatorSet) {
        for (Animator child : ((AnimatorSet) animator).getChildAnimations()) {
            duration += countDuration(child);
        }
    } else if (animator instanceof RepeatAction) {
        duration += countDuration(((RepeatAction) animator).animator);
    } else {
        duration += animator.getDuration();
    }
    return Math.max(duration, 0);
}
 
Example 4
Source File: AnimatorHelper.java    From tns-core-modules-widgets with Apache License 2.0 5 votes vote down vote up
static long getAnimatorTotalDuration(Animator animator) {
    long totalDuration;
    if (version >= 24) {
        totalDuration = animator.getTotalDuration();
    } else {
        long duration = animator.getDuration();
        if (duration == Animator.DURATION_INFINITE) {
            totalDuration = Animator.DURATION_INFINITE;
        } else {
            totalDuration = animator.getStartDelay() + duration;
        }
    }

    return totalDuration;
}
 
Example 5
Source File: AnimatorAdapter.java    From FlexibleAdapter with Apache License 2.0 4 votes vote down vote up
/**
     * 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
     * @since 5.0.0-b1
     */
    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) {
            isForwardEnabled = false;
        }
        int lastVisiblePosition = getFlexibleLayoutManager().findLastVisibleItemPosition();
//        log.v("animateView isForwardEnabled=%s isReverseEnabled=%s isFastScroll=%s isNotified=%s mLastAnimatedPosition=%s mMaxChildViews=%s %s",
//                isForwardEnabled, isReverseEnabled, isFastScroll, mAnimatorNotifierObserver.isPositionNotified(), mLastAnimatedPosition,
//                mMaxChildViews, (!isReverseEnabled ? " Pos>LasVisPos=" + (position > lastVisiblePosition) : "")
//        );
        if ((isForwardEnabled || isReverseEnabled)
                && !isFastScroll && holder instanceof FlexibleViewHolder
                && (!mAnimatorNotifierObserver.isPositionNotified() || isScrollableHeaderOrFooter(position))
                && (isScrollableHeaderOrFooter(position)
                || (isForwardEnabled && position > lastVisiblePosition)
                || (isReverseEnabled && position < lastVisiblePosition)
                || (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();
                }
            }
            set.setDuration(duration);
            set.addListener(new HelperAnimatorListener(hashCode));
            if (mEntryStep) {
                // Stop stepDelay when screen is filled
                set.setStartDelay(calculateAnimationDelay(holder, position));
            }
            set.start();
            mAnimators.put(hashCode, set);
            //log.v("animateView    Scroll animation on position %s", position);
        }
        mAnimatorNotifierObserver.clearNotified();
        // Update last animated position
        mLastAnimatedPosition = position;
    }