Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 97b658f2 authored by Tony Wickham's avatar Tony Wickham Committed by Android (Google) Code Review
Browse files

Merge "Can now swipe away to dismiss second task" into ub-launcher3-master

parents 3db09e5b 52c7b8c6
Loading
Loading
Loading
Loading
+24 −12
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.BaseDraggingActivity;
@@ -106,7 +105,7 @@ public abstract class TaskViewTouchController<T extends BaseDraggingActivity>

            // Now figure out which direction scroll events the controller will start
            // calling the callbacks.
            final int directionsToDetectScroll;
            int directionsToDetectScroll = 0;
            boolean ignoreSlopWhenSettling = false;
            if (mCurrentAnimation != null) {
                directionsToDetectScroll = SwipeDetector.DIRECTION_BOTH;
@@ -114,12 +113,19 @@ public abstract class TaskViewTouchController<T extends BaseDraggingActivity>
            } else {
                mTaskBeingDragged = null;

                View view = mRecentsView.getChildAt(mRecentsView.getCurrentPage());
                if (view instanceof TaskView && mActivity.getDragLayer().isEventOverView(view, ev)) {
                    // The tile can be dragged down to open the task.
                    mTaskBeingDragged = (TaskView) view;
                    directionsToDetectScroll = SwipeDetector.DIRECTION_BOTH;
                } else {
                for (int i = 0; i < mRecentsView.getChildCount(); i++) {
                    TaskView view = mRecentsView.getPageAt(i);
                    if (mRecentsView.isTaskViewVisible(view) && mActivity.getDragLayer()
                            .isEventOverView(view, ev)) {
                        // The task can be dragged up to dismiss it,
                        // and down to open if it's the current page.
                        mTaskBeingDragged = view;
                        directionsToDetectScroll = i == mRecentsView.getCurrentPage()
                                ? SwipeDetector.DIRECTION_BOTH : SwipeDetector.DIRECTION_POSITIVE;
                        break;
                    }
                }
                if (mTaskBeingDragged == null) {
                    mNoIntercept = true;
                    return false;
                }
@@ -142,10 +148,16 @@ public abstract class TaskViewTouchController<T extends BaseDraggingActivity>
        return mDetector.onTouchEvent(ev);
    }

    private void reInitAnimationController(boolean goingUp) {
    private boolean reInitAnimationController(boolean goingUp) {
        if (mCurrentAnimation != null && mCurrentAnimationIsGoingUp == goingUp) {
            // No need to init
            return;
            return false;
        }
        int scrollDirections = mDetector.getScrollDirections();
        if (goingUp && ((scrollDirections & SwipeDetector.DIRECTION_POSITIVE) == 0)
                || !goingUp && ((scrollDirections & SwipeDetector.DIRECTION_NEGATIVE) == 0)) {
            // Trying to re-init in an unsupported direction.
            return false;
        }
        if (mCurrentAnimation != null) {
            mCurrentAnimation.setPlayFraction(0);
@@ -179,6 +191,7 @@ public abstract class TaskViewTouchController<T extends BaseDraggingActivity>
        mCurrentAnimation.getTarget().addListener(this);
        mCurrentAnimation.dispatchOnStart();
        mProgressMultiplier = 1 / mEndDisplacement;
        return true;
    }

    @Override
@@ -219,8 +232,7 @@ public abstract class TaskViewTouchController<T extends BaseDraggingActivity>
                    // Not allowed
                    goingToEnd = false;
                } else {
                    reInitAnimationController(goingUp);
                    goingToEnd = true;
                    goingToEnd = reInitAnimationController(goingUp);
                }
            } else {
                goingToEnd = true;
+33 −8
Original line number Diff line number Diff line
@@ -659,14 +659,14 @@ public abstract class RecentsView<T extends BaseActivity>
        int[] newScroll = new int[count];
        getPageScrolls(newScroll, false, (v) -> v.getVisibility() != GONE && v != taskView);

        int maxScrollDiff = 0;
        int lastPage = mIsRtl ? 0 : count - 1;
        if (getChildAt(lastPage) == taskView) {
        int scrollDiffPerPage = 0;
        int leftmostPage = mIsRtl ? count -1 : 0;
        int rightmostPage = mIsRtl ? 0 : count - 1;
        if (count > 1) {
                int secondLastPage = mIsRtl ? 1 : count - 2;
                maxScrollDiff = oldScroll[lastPage] - newScroll[secondLastPage];
            }
            int secondRightmostPage = mIsRtl ? 1 : count - 2;
            scrollDiffPerPage = oldScroll[rightmostPage] - oldScroll[secondRightmostPage];
        }
        int draggedIndex = indexOfChild(taskView);

        boolean needsCurveUpdates = false;
        for (int i = 0; i < count; i++) {
@@ -678,7 +678,26 @@ public abstract class RecentsView<T extends BaseActivity>
                            duration, LINEAR, anim);
                }
            } else {
                int scrollDiff = newScroll[i] - oldScroll[i] + maxScrollDiff;
                // 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 = mIsRtl ? leftmostPage : rightmostPage;
                    if (mCurrentPage == lastPage) {
                        offset += mIsRtl ? -scrollDiffPerPage : scrollDiffPerPage;
                    }
                } else {
                    // Dragging an adjacent page.
                    int negativeAdjacent = mCurrentPage - 1; // (Right in RTL, left in LTR)
                    if (draggedIndex == negativeAdjacent) {
                        offset += mIsRtl ? -scrollDiffPerPage : scrollDiffPerPage;
                    }
                }
                int scrollDiff = newScroll[i] - oldScroll[i] + offset;
                if (scrollDiff != 0) {
                    addAnim(ObjectAnimator.ofFloat(child, TRANSLATION_X, scrollDiff),
                            duration, ACCEL, anim);
@@ -710,9 +729,15 @@ public abstract class RecentsView<T extends BaseActivity>
                               TaskUtils.getComponentKeyForTask(task.key));
                   }
               }
               int pageToSnapTo = mCurrentPage;
               if (draggedIndex < pageToSnapTo) {
                   pageToSnapTo -= 1;
               }
               removeView(taskView);
               if (getChildCount() == 0) {
                   onAllTasksRemoved();
               } else {
                   snapToPageImmediately(pageToSnapTo);
               }
           }
           resetTaskVisuals();
+4 −0
Original line number Diff line number Diff line
@@ -194,6 +194,10 @@ public class SwipeDetector {
        mIgnoreSlopWhenSettling = ignoreSlop;
    }

    public int getScrollDirections() {
        return mScrollConditions;
    }

    private boolean shouldScrollStart(MotionEvent ev, int pointerIndex) {
        // reject cases where the angle or slop condition is not met.
        if (Math.max(mDir.getActiveTouchSlop(ev, pointerIndex, mDownPos), mTouchSlop)