Search in sources :

Example 1 with SpringObjectAnimator

use of com.android.launcher3.anim.SpringObjectAnimator in project Neo-Launcher by NeoApplications.

the class RecentsView method createTaskDismissAnimation.

public PendingAnimation createTaskDismissAnimation(TaskView taskView, boolean animateTaskView, boolean shouldRemoveTask, long duration) {
    if (mPendingAnimation != null) {
        mPendingAnimation.finish(false, Touch.SWIPE);
    }
    AnimatorSet anim = new AnimatorSet();
    PendingAnimation pendingAnimation = new PendingAnimation(anim);
    int count = getPageCount();
    if (count == 0) {
        return pendingAnimation;
    }
    int[] oldScroll = new int[count];
    getPageScrolls(oldScroll, false, SIMPLE_SCROLL_LOGIC);
    int[] newScroll = new int[count];
    getPageScrolls(newScroll, false, (v) -> v.getVisibility() != GONE && v != taskView);
    int taskCount = getTaskViewCount();
    int scrollDiffPerPage = 0;
    if (count > 1) {
        scrollDiffPerPage = Math.abs(oldScroll[1] - oldScroll[0]);
    }
    int draggedIndex = indexOfChild(taskView);
    boolean needsCurveUpdates = false;
    for (int i = 0; i < count; i++) {
        View child = getChildAt(i);
        if (child == taskView) {
            if (animateTaskView) {
                addDismissedTaskAnimations(taskView, anim, duration);
            }
        } else {
            // If we just take newScroll - oldScroll, everything to the right of dragged task
            // translates to the left. We need to offset this in some cases:
            // - In RTL, add page offset to all pages, since we want pages to move to the right
            // Additionally, add a page offset if:
            // - Current page is rightmost page (leftmost for RTL)
            // - Dragging an adjacent page on the left side (right side for RTL)
            int offset = mIsRtl ? scrollDiffPerPage : 0;
            if (mCurrentPage == draggedIndex) {
                int lastPage = taskCount - 1;
                if (mCurrentPage == lastPage) {
                    offset += mIsRtl ? -scrollDiffPerPage : scrollDiffPerPage;
                }
            } else {
                // Dragging an adjacent page.
                // (Right in RTL, left in LTR)
                int negativeAdjacent = mCurrentPage - 1;
                if (draggedIndex == negativeAdjacent) {
                    offset += mIsRtl ? -scrollDiffPerPage : scrollDiffPerPage;
                }
            }
            int scrollDiff = newScroll[i] - oldScroll[i] + offset;
            if (scrollDiff != 0) {
                if (QUICKSTEP_SPRINGS.get() && child instanceof TaskView) {
                    addAnim(new SpringObjectAnimator<>(child, VIEW_TRANSLATE_X, MIN_VISIBLE_CHANGE_PIXELS, SpringForce.DAMPING_RATIO_MEDIUM_BOUNCY, SpringForce.STIFFNESS_MEDIUM, 0, scrollDiff), duration, ACCEL, anim);
                } else {
                    addAnim(ObjectAnimator.ofFloat(child, TRANSLATION_X, scrollDiff), duration, ACCEL, anim);
                }
                needsCurveUpdates = true;
            }
        }
    }
    if (needsCurveUpdates) {
        ValueAnimator va = ValueAnimator.ofFloat(0, 1);
        va.addUpdateListener((a) -> updateCurveProperties());
        anim.play(va);
    }
    // Add a tiny bit of translation Z, so that it draws on top of other views
    if (animateTaskView) {
        taskView.setTranslationZ(0.1f);
    }
    mPendingAnimation = pendingAnimation;
    mPendingAnimation.addEndListener(new Consumer<PendingAnimation.OnEndListener>() {

        @Override
        public void accept(PendingAnimation.OnEndListener onEndListener) {
            if (ENABLE_QUICKSTEP_LIVE_TILE.get() && taskView.isRunningTask() && onEndListener.isSuccess) {
                finishRecentsAnimation(true, /* toHome */
                () -> onEnd(onEndListener));
            } else {
                onEnd(onEndListener);
            }
        }

        private void onEnd(PendingAnimation.OnEndListener onEndListener) {
            if (onEndListener.isSuccess) {
                if (shouldRemoveTask) {
                    removeTask(taskView.getTask(), draggedIndex, onEndListener, true);
                }
                int pageToSnapTo = mCurrentPage;
                if (draggedIndex < pageToSnapTo || pageToSnapTo == (getTaskViewCount() - 1)) {
                    pageToSnapTo -= 1;
                }
                removeView(taskView);
                if (getTaskViewCount() == 0) {
                    removeView(mClearAllButton);
                    startHome();
                } else {
                    snapToPageImmediately(pageToSnapTo);
                }
            }
            resetTaskVisuals();
            mPendingAnimation = null;
        }
    });
    return pendingAnimation;
}
Also used : PendingAnimation(com.android.launcher3.util.PendingAnimation) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) View(android.view.View) ListView(android.widget.ListView) PagedView(com.android.launcher3.PagedView) TextPaint(android.text.TextPaint) Point(android.graphics.Point)

Example 2 with SpringObjectAnimator

use of com.android.launcher3.anim.SpringObjectAnimator in project Neo-Launcher by NeoApplications.

the class StaggeredWorkspaceAnim method addStaggeredAnimationForView.

/**
 * Adds an alpha/trans animator for {@param v}, with a start delay based on the view's row.
 *
 * @param v A view on the workspace.
 * @param row The bottom-most row that contains the view.
 * @param totalRows Total number of rows.
 */
private void addStaggeredAnimationForView(View v, int row, int totalRows) {
    // Invert the rows, because we stagger starting from the bottom of the screen.
    int invertedRow = totalRows - row;
    // Add 1 to the inverted row so that the bottom most row has a start delay.
    long startDelay = (long) ((invertedRow + 1) * APP_CLOSE_ROW_START_DELAY_MS);
    v.setTranslationY(mSpringTransY);
    SpringObjectAnimator springTransY = new SpringObjectAnimator<>(v, VIEW_TRANSLATE_Y, 1f, DAMPING_RATIO, STIFFNESS, mSpringTransY, 0);
    springTransY.setStartDelay(startDelay);
    mAnimators.add(springTransY);
    v.setAlpha(0);
    ObjectAnimator alpha = ObjectAnimator.ofFloat(v, View.ALPHA, 0f, 1f);
    alpha.setInterpolator(LINEAR);
    alpha.setDuration(ALPHA_DURATION_MS);
    alpha.setStartDelay(startDelay);
    mAnimators.add(alpha);
}
Also used : SpringObjectAnimator(com.android.launcher3.anim.SpringObjectAnimator) ObjectAnimator(android.animation.ObjectAnimator) SpringObjectAnimator(com.android.launcher3.anim.SpringObjectAnimator)

Aggregations

AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 ValueAnimator (android.animation.ValueAnimator)1 Point (android.graphics.Point)1 TextPaint (android.text.TextPaint)1 View (android.view.View)1 ListView (android.widget.ListView)1 PagedView (com.android.launcher3.PagedView)1 SpringObjectAnimator (com.android.launcher3.anim.SpringObjectAnimator)1 PendingAnimation (com.android.launcher3.util.PendingAnimation)1