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

Skip to content
Commit c424d480 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Refactor DialogLaunchAnimator and remove host dialog (1/2)

This CL is a refactoring of the DialogLaunchAnimator and a major change
in how it works internally.

Before this CL, when DialogLaunchAnimator.show(originalDialog, ...) was
called, it would create a fullscreen dialog (called hostDialog) to
which we would add the content view stolen from the originalDialog (that
would then be hidden). We would then run the launch animation in the
host dialog and listen for show(), hide() or dismiss() calls to the
originalDialog to know when we should show(), hide() or dismiss() the
hostDialog.

The main reason we did that was because there was no way to override the
dismiss() behavior of the originalDialog, which we need to do given that
we want to animate the dialog into the view that showed the dialog
before actually dismissing it.

This approach had multiple downsides:
 - We were showing the dialog content view inside a different window
   than the one in which it was created, therefore any change made to or
   any listener added to the originalDialog window was lost.
 - Code calling DialogLaunchAnimator.showFromView needed to know that
   their dialog content will be moved to another window, which is
   unexpected and can lead to subtle bugs.
 - We were waiting for 2 dialogs to be shown instead of 1 before being
   able to start the animation.

This CL does what we should have done since the beginning: it adds a
hidden API to Dialog so that we can override what happens when
Dialog.dismiss() is called. This allows the DialogLaunchAnimator to run
the exit animation into the view that triggered the dialog before
actually dismissing it. The only modification that
DialogLaunchAnimator.show(originalDialog, ...) now does to the
originalDialog is making its window fullscreen and inserting two views
between the originalDialog DecorView and its children. The first
inserted view is a fullscreen transparent background used to dismiss the
dialog when the user taps outside the dialog content. The second
inserted view is a View that we size and position the same way that the
DecorView was before we made it fullscreen, and to which we set the
originalDialog background. This view now serves as a "fake window" with
the same size, background and position as the original window
(DecorView).

This CL improves the time to start the launch animation by 20-25%
(measured in a totally unrigorous logcat way).

Bug: 193634619
Test: atest DialogLaunchAnimatorTest
Change-Id: If09eda7b06e83b3ed7714cec97afef08b3d9fd3e
parent a5f83144
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment