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

Commit 240dbab0 authored by Fengjiang Li's avatar Fengjiang Li Committed by Android (Google) Code Review
Browse files

Merge "[Predictive Back] Swipe back within taskbar all apps should only scale...

Merge "[Predictive Back] Swipe back within taskbar all apps should only scale down content view, rather than whole all apps sheet" into main
parents ef051ce9 1529052d
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -206,13 +206,6 @@ public class TaskbarAllAppsSlideInView extends AbstractSlideInView<TaskbarOverla
        super.dispatchDraw(canvas);
    }

    @Override
    protected void onUserSwipeToDismissProgressChanged() {
        super.onUserSwipeToDismissProgressChanged();
        mAppsView.setClipChildren(!mIsDismissInProgress);
        mAppsView.getAppsRecyclerViewContainer().setClipChildren(!mIsDismissInProgress);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
@@ -259,12 +252,28 @@ public class TaskbarAllAppsSlideInView extends AbstractSlideInView<TaskbarOverla
        return getPopupContainer().isEventOverView(mAppsView.getVisibleContainerView(), ev);
    }

    /**
     * In taskbar all apps search mode, we should scale down content inside all apps, rather
     * than the whole all apps bottom sheet, to indicate we will navigate back within the all apps.
     */
    @Override
    public boolean shouldAnimateContentViewInBackSwipe() {
        return mAllAppsCallbacks.canHandleSearchBackInvoked();
    }

    @Override
    protected void onUserSwipeToDismissProgressChanged() {
        super.onUserSwipeToDismissProgressChanged();
        mAppsView.setClipChildren(!mIsDismissInProgress);
        mAppsView.getAppsRecyclerViewContainer().setClipChildren(!mIsDismissInProgress);
    }

    @Override
    public void onBackInvoked() {
        if (mAllAppsCallbacks.handleSearchBackInvoked()) {
            // We need to scale back taskbar all apps if we navigate back within search inside all
            // apps
            animateSwipeToDismissProgressToStart();
            post(this::animateSwipeToDismissProgressToStart);
        } else {
            super.onBackInvoked();
        }
+5 −0
Original line number Diff line number Diff line
@@ -143,6 +143,11 @@ final class TaskbarAllAppsViewController {
            }
        }

        /** Check if search session can handle back. This check doesn't perform any action. */
        boolean canHandleSearchBackInvoked() {
            return mSearchSessionController.canHandleBackInvoked();
        }

        /** Invoked on back press, returning {@code true} if the search session handled it. */
        boolean handleSearchBackInvoked() {
            return mSearchSessionController.handleBackInvoked();
+2 −0
Original line number Diff line number Diff line
@@ -49,6 +49,8 @@ open class TaskbarSearchSessionController : ResourceBasedOverride, AllAppsTransi
    /** Creates a [PreDragCondition] for [view], if it is a search result that requires one. */
    open fun createPreDragConditionForSearch(view: View): PreDragCondition? = null

    open fun canHandleBackInvoked(): Boolean = false

    open fun handleBackInvoked(): Boolean = false

    open fun onAllAppsAnimationPending(
+19 −0
Original line number Diff line number Diff line
@@ -287,6 +287,13 @@ public abstract class AbstractSlideInView<T extends Context & ActivityContext>
        return true;
    }

    @Override
    @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
    public void onBackStarted(BackEvent backEvent) {
        super.onBackStarted(backEvent);
        mViewToAnimateInSwipeToDismiss = shouldAnimateContentViewInBackSwipe() ? mContent : this;
    }

    @Override
    @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
    public void onBackProgressed(BackEvent backEvent) {
@@ -295,6 +302,18 @@ public abstract class AbstractSlideInView<T extends Context & ActivityContext>
        mSwipeToDismissProgress.updateValue(deceleratedProgress);
    }

    /**
     * During predictive back swipe, the default behavior is to scale {@link AbstractSlideInView}
     * during back swipe. This method allow subclass to scale {@link #mContent}, typically to exit
     * search mode.
     *
     * <p>Note that this method can be expensive, and should only be called from
     * {@link #onBackStarted(BackEvent)}, not from {@link #onBackProgressed(BackEvent)}.
     */
    protected boolean shouldAnimateContentViewInBackSwipe() {
        return false;
    }

    protected void onUserSwipeToDismissProgressChanged() {
        float progress = mSwipeToDismissProgress.value;
        mIsDismissInProgress = progress > 0f;
+10 −10
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import android.view.animation.Interpolator;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.window.BackEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -903,22 +902,23 @@ public class WidgetsFullSheet extends BaseWidgetSheet
        return isFoldUnFold || useDifferentLayoutOnOrientationChange;
    }

    /**
     * In widget search mode, we should scale down content inside widget bottom sheet, rather
     * than the whole bottom sheet, to indicate we will navigate back within the widget
     * bottom sheet.
     */
    @Override
    public void onBackStarted(BackEvent backEvent) {
        super.onBackStarted(backEvent);
        // In widget search mode, we should scale down content inside widget bottom sheet, rather
        // than the whole bottom sheet, to indicate we will navigate back within the widget
        // bottom sheet.
        if (mIsInSearchMode) {
            mViewToAnimateInSwipeToDismiss = mContent;
        }
    public boolean shouldAnimateContentViewInBackSwipe() {
        return mIsInSearchMode;
    }

    @Override
    public void onBackInvoked() {
        if (mIsInSearchMode) {
            mSearchBar.reset();
            animateSwipeToDismissProgressToStart();
            // Posting animation to next frame will let widget sheet finish updating UI first, and
            // make animation smoother.
            post(this::animateSwipeToDismissProgressToStart);
        } else {
            super.onBackInvoked();
        }