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

Commit 7d6cb913 authored by Ned Burns's avatar Ned Burns
Browse files

Modify SwipeDismissLayout to perform its own exit animation

Instead of relying on the window animation system, in the special
case of a swipe-dismiss, disable any default window exit animation
and perform a custom animation. This bypasses some bugs in the
window animator codebase and allows us to have a nice "rebound"
animation if the user doesn't swipe far/fast enough to trigger a
dismiss.

Bug: 33041168
Change-Id: Ied45700d35a59950bacef1ba0650eaa5bc60fadb
parent f7964be9
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -2946,8 +2946,11 @@ public class Activity extends ContextThemeWrapper
     * @hide
     */
    @Override
    public void onWindowDismissed(boolean finishTask) {
    public void onWindowDismissed(boolean finishTask, boolean suppressWindowTransition) {
        finish(finishTask ? FINISH_TASK_WITH_ACTIVITY : DONT_FINISH_TASK_WITH_ACTIVITY);
        if (suppressWindowTransition) {
            overridePendingTransition(0, 0);
        }
    }


+1 −1
Original line number Diff line number Diff line
@@ -744,7 +744,7 @@ public class Dialog implements DialogInterface, Window.Callback,

    /** @hide */
    @Override
    public void onWindowDismissed(boolean finishTask) {
    public void onWindowDismissed(boolean finishTask, boolean suppressWindowTransition) {
        dismiss();
    }

+6 −3
Original line number Diff line number Diff line
@@ -581,8 +581,10 @@ public abstract class Window {
         * Called when a window is dismissed. This informs the callback that the
         * window is gone, and it should finish itself.
         * @param finishTask True if the task should also be finished.
         * @param suppressWindowTransition True if the resulting exit and enter window transition
         * animations should be suppressed.
         */
        void onWindowDismissed(boolean finishTask);
        void onWindowDismissed(boolean finishTask, boolean suppressWindowTransition);
    }

    /** @hide */
@@ -871,9 +873,10 @@ public abstract class Window {
    }

    /** @hide */
    public final void dispatchOnWindowDismissed(boolean finishTask) {
    public final void dispatchOnWindowDismissed(
            boolean finishTask, boolean suppressWindowTransition) {
        if (mOnWindowDismissedCallback != null) {
            mOnWindowDismissedCallback.onWindowDismissed(finishTask);
            mOnWindowDismissedCallback.onWindowDismissed(finishTask, suppressWindowTransition);
        }
    }

+3 −5
Original line number Diff line number Diff line
@@ -2990,19 +2990,17 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
        swipeDismiss.setOnDismissedListener(new SwipeDismissLayout.OnDismissedListener() {
            @Override
            public void onDismissed(SwipeDismissLayout layout) {
                dispatchOnWindowDismissed(false /*finishTask*/);
                dispatchOnWindowDismissed(false /*finishTask*/, true /*suppressWindowTransition*/);
            }
        });
        swipeDismiss.setOnSwipeProgressChangedListener(
                new SwipeDismissLayout.OnSwipeProgressChangedListener() {
                    private static final float ALPHA_DECREASE = 0.5f;
                    private boolean mIsTranslucent = false;
                    @Override
                    public void onSwipeProgressChanged(
                            SwipeDismissLayout layout, float progress, float translate) {
                            SwipeDismissLayout layout, float alpha, float translate) {
                        WindowManager.LayoutParams newParams = getAttributes();
                        newParams.x = (int) translate;
                        newParams.alpha = 1 - (progress * ALPHA_DECREASE);
                        newParams.alpha = alpha;
                        setAttributes(newParams);

                        int flags = 0;
+2 −1
Original line number Diff line number Diff line
@@ -416,7 +416,8 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener,
        if (mClickTarget == mMaximize) {
            maximizeWindow();
        } else if (mClickTarget == mClose) {
            mOwner.dispatchOnWindowDismissed(true /*finishTask*/);
            mOwner.dispatchOnWindowDismissed(
                    true /*finishTask*/, false /*suppressWindowTransition*/);
        }
        return true;
    }
Loading