Search in sources :

Example 1 with AnimatorListenerAdapter

use of android.animation.AnimatorListenerAdapter in project Launcher3 by chislon.

the class PagedView method createPostDeleteAnimationRunnable.

private Runnable createPostDeleteAnimationRunnable(final View dragView) {
    return new Runnable() {

        @Override
        public void run() {
            int dragViewIndex = indexOfChild(dragView);
            // For each of the pages around the drag view, animate them from the previous
            // position to the new position in the layout (as a result of the drag view moving
            // in the layout)
            // NOTE: We can make an assumption here because we have side-bound pages that we
            //       will always have pages to animate in from the left
            getOverviewModePages(mTempVisiblePagesRange);
            boolean isLastWidgetPage = (mTempVisiblePagesRange[0] == mTempVisiblePagesRange[1]);
            boolean slideFromLeft = (isLastWidgetPage || dragViewIndex > mTempVisiblePagesRange[0]);
            // Setup the scroll to the correct page before we swap the views
            if (slideFromLeft) {
                snapToPageImmediately(dragViewIndex - 1);
            }
            int firstIndex = (isLastWidgetPage ? 0 : mTempVisiblePagesRange[0]);
            int lastIndex = Math.min(mTempVisiblePagesRange[1], getPageCount() - 1);
            int lowerIndex = (slideFromLeft ? firstIndex : dragViewIndex + 1);
            int upperIndex = (slideFromLeft ? dragViewIndex - 1 : lastIndex);
            ArrayList<Animator> animations = new ArrayList<Animator>();
            for (int i = lowerIndex; i <= upperIndex; ++i) {
                View v = getChildAt(i);
                // dragViewIndex < pageUnderPointIndex, so after we remove the
                // drag view all subsequent views to pageUnderPointIndex will
                // shift down.
                int oldX = 0;
                int newX = 0;
                if (slideFromLeft) {
                    if (i == 0) {
                        // Simulate the page being offscreen with the page spacing
                        oldX = getViewportOffsetX() + getChildOffset(i) - getChildWidth(i) - mPageSpacing;
                    } else {
                        oldX = getViewportOffsetX() + getChildOffset(i - 1);
                    }
                    newX = getViewportOffsetX() + getChildOffset(i);
                } else {
                    oldX = getChildOffset(i) - getChildOffset(i - 1);
                    newX = 0;
                }
                // Animate the view translation from its old position to its new
                // position
                AnimatorSet anim = (AnimatorSet) v.getTag();
                if (anim != null) {
                    anim.cancel();
                }
                // Note: Hacky, but we want to skip any optimizations to not draw completely
                // hidden views
                v.setAlpha(Math.max(v.getAlpha(), 0.01f));
                v.setTranslationX(oldX - newX);
                anim = new AnimatorSet();
                anim.playTogether(ObjectAnimator.ofFloat(v, "translationX", 0f), ObjectAnimator.ofFloat(v, "alpha", 1f));
                animations.add(anim);
                v.setTag(ANIM_TAG_KEY, anim);
            }
            AnimatorSet slideAnimations = new AnimatorSet();
            slideAnimations.playTogether(animations);
            slideAnimations.setDuration(DELETE_SLIDE_IN_SIDE_PAGE_DURATION);
            slideAnimations.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    mDeferringForDelete = false;
                    onEndReordering();
                    onRemoveViewAnimationCompleted();
                }
            });
            slideAnimations.start();
            removeView(dragView);
            onRemoveView(dragView, true);
        }
    };
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) View(android.view.View)

Example 2 with AnimatorListenerAdapter

use of android.animation.AnimatorListenerAdapter in project Launcher3 by chislon.

the class PagedView method onFlingToDelete.

public void onFlingToDelete(PointF vel) {
    final long startTime = AnimationUtils.currentAnimationTimeMillis();
    // NOTE: Because it takes time for the first frame of animation to actually be
    // called and we expect the animation to be a continuation of the fling, we have
    // to account for the time that has elapsed since the fling finished.  And since
    // we don't have a startDelay, we will always get call to update when we call
    // start() (which we want to ignore).
    final TimeInterpolator tInterpolator = new TimeInterpolator() {

        private int mCount = -1;

        private long mStartTime;

        private float mOffset;

        /* Anonymous inner class ctor */
        {
            mStartTime = startTime;
        }

        @Override
        public float getInterpolation(float t) {
            if (mCount < 0) {
                mCount++;
            } else if (mCount == 0) {
                mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime) / FLING_TO_DELETE_FADE_OUT_DURATION);
                mCount++;
            }
            return Math.min(1f, mOffset + t);
        }
    };
    final Rect from = new Rect();
    final View dragView = mDragView;
    from.left = (int) dragView.getTranslationX();
    from.top = (int) dragView.getTranslationY();
    AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime, FLING_TO_DELETE_FRICTION);
    final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView);
    // Create and start the animation
    ValueAnimator mDropAnim = new ValueAnimator();
    mDropAnim.setInterpolator(tInterpolator);
    mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION);
    mDropAnim.setFloatValues(0f, 1f);
    mDropAnim.addUpdateListener(updateCb);
    mDropAnim.addListener(new AnimatorListenerAdapter() {

        public void onAnimationEnd(Animator animation) {
            onAnimationEndRunnable.run();
        }
    });
    mDropAnim.start();
    mDeferringForDelete = true;
}
Also used : Rect(android.graphics.Rect) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) TimeInterpolator(android.animation.TimeInterpolator) View(android.view.View)

Example 3 with AnimatorListenerAdapter

use of android.animation.AnimatorListenerAdapter in project Launcher3 by chislon.

the class PagedView method animateDragViewToOriginalPosition.

// Animate the drag view back to the original position
void animateDragViewToOriginalPosition() {
    if (mDragView != null) {
        AnimatorSet anim = new AnimatorSet();
        anim.setDuration(REORDERING_DROP_REPOSITION_DURATION);
        anim.playTogether(ObjectAnimator.ofFloat(mDragView, "translationX", 0f), ObjectAnimator.ofFloat(mDragView, "translationY", 0f), ObjectAnimator.ofFloat(mDragView, "scaleX", 1f), ObjectAnimator.ofFloat(mDragView, "scaleY", 1f));
        anim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                onPostReorderingAnimationCompleted();
            }
        });
        anim.start();
    }
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorSet(android.animation.AnimatorSet)

Example 4 with AnimatorListenerAdapter

use of android.animation.AnimatorListenerAdapter in project Launcher3 by chislon.

the class Workspace method enableOverviewMode.

private void enableOverviewMode(boolean enable, int snapPage, boolean animated) {
    State finalState = Workspace.State.OVERVIEW;
    if (!enable) {
        finalState = Workspace.State.NORMAL;
    }
    Animator workspaceAnim = getChangeStateAnimation(finalState, animated, 0, snapPage);
    if (workspaceAnim != null) {
        onTransitionPrepare();
        workspaceAnim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator arg0) {
                onTransitionEnd();
            }
        });
        workspaceAnim.start();
    }
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) FolderRingAnimator(com.android.launcher3.FolderIcon.FolderRingAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Example 5 with AnimatorListenerAdapter

use of android.animation.AnimatorListenerAdapter in project kickmaterial by byoutline.

the class CategoriesListActivity method runFinishAnimation.

private void runFinishAnimation(Runnable finishAction) {
    if (summaryScrolledValue > 0) {
        binding.categoriesRv.smoothScrollToPosition(0);
    }
    ViewUtils.showView(binding.selectCategoryTv, false);
    ObjectAnimator imageFade = ObjectAnimator.ofFloat(binding.selectedCategoryIv, View.ALPHA, 1, 0);
    AnimatorSet set = new AnimatorSet();
    AnimatorSet closeButtonScale = AnimatorUtils.getScaleAnimator(binding.closeCategoriesIv, 1, 0.1f);
    set.playTogether(closeButtonScale, imageFade);
    set.setDuration(FINISH_ANIMATION_DURATION);
    set.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            if (revealAnimation != null) {
                revealAnimation.cancel();
            }
            ViewUtils.showView(binding.categoryCircleRevealIv, false);
            binding.closeCategoriesIv.setScaleX(0);
            binding.closeCategoriesIv.setScaleY(0);
            finishAction.run();
        }
    });
    binding.categoriesRv.startAnimation(LUtils.loadAnimationWithLInterpolator(getApplicationContext(), R.anim.slide_to_bottom));
    set.start();
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorSet(android.animation.AnimatorSet)

Aggregations

Animator (android.animation.Animator)848 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)848 ValueAnimator (android.animation.ValueAnimator)458 ObjectAnimator (android.animation.ObjectAnimator)456 AnimatorSet (android.animation.AnimatorSet)139 View (android.view.View)130 ViewGroup (android.view.ViewGroup)92 PropertyValuesHolder (android.animation.PropertyValuesHolder)70 StackStateAnimator (com.android.systemui.statusbar.stack.StackStateAnimator)70 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)62 ImageView (android.widget.ImageView)45 TextView (android.widget.TextView)43 Interpolator (android.view.animation.Interpolator)42 Paint (android.graphics.Paint)41 Rect (android.graphics.Rect)39 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)39 RenderNodeAnimator (android.view.RenderNodeAnimator)36 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)36 TimeAnimator (android.animation.TimeAnimator)30 ArrayList (java.util.ArrayList)26