From ef3876e165396d56e7ddddab0a947a7baa486979 Mon Sep 17 00:00:00 2001 From: Jordan Demeulenaere Date: Wed, 25 Aug 2021 12:54:37 +0200 Subject: [PATCH] Animate media dialogs This CL applies the DialogLaunchAnimator to the media output and media output group dialogs. See b/200781817#comment2 for before/after videos. Bug: 200781817 Test: Open media output dialog Change-Id: I1bff28cc7647db6b97b8933e5b7605d7df15c63f --- .../SystemUI/animation/res/values/styles.xml | 9 +++- .../animation/DialogLaunchAnimator.kt | 32 ++++++++++--- .../media_output_dialog_background.xml | 23 ---------- .../layout/internet_connectivity_dialog.xml | 2 +- .../res/layout/media_output_dialog.xml | 2 +- packages/SystemUI/res/layout/media_view.xml | 1 + .../SystemUI/res/values-sw600dp/dimens.xml | 4 +- packages/SystemUI/res/values/dimens.xml | 4 +- packages/SystemUI/res/values/styles.xml | 7 --- .../systemui/media/MediaControlPanel.java | 6 +-- .../systemui/media/PlayerViewHolder.kt | 1 + .../media/dialog/MediaOutputAdapter.java | 13 +++--- .../media/dialog/MediaOutputBaseDialog.java | 12 +++-- .../media/dialog/MediaOutputController.java | 45 +++++++++++++++---- .../media/dialog/MediaOutputDialog.java | 3 +- .../media/dialog/MediaOutputDialogFactory.kt | 24 +++++++--- .../media/dialog/MediaOutputGroupDialog.java | 5 ++- .../qs/tiles/dialog/InternetDialog.java | 5 +-- .../systemui/statusbar/phone/StatusBar.java | 3 +- .../phone/SystemUIHostDialogProvider.kt | 6 ++- .../animation/DialogLaunchAnimatorTest.kt | 1 + .../media/dialog/MediaOutputAdapterTest.java | 3 +- .../dialog/MediaOutputBaseDialogTest.java | 4 +- .../dialog/MediaOutputControllerTest.java | 10 +++-- .../media/dialog/MediaOutputDialogTest.java | 6 ++- .../dialog/MediaOutputGroupDialogTest.java | 5 ++- 26 files changed, 147 insertions(+), 89 deletions(-) delete mode 100644 packages/SystemUI/res/drawable/media_output_dialog_background.xml diff --git a/packages/SystemUI/animation/res/values/styles.xml b/packages/SystemUI/animation/res/values/styles.xml index 89f93b81fa994..ad06c9192bc3e 100644 --- a/packages/SystemUI/animation/res/values/styles.xml +++ b/packages/SystemUI/animation/res/values/styles.xml @@ -15,7 +15,14 @@ limitations under the License. --> - + + diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt index fbf466e8cebe4..c2b36089d0a7b 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt @@ -118,6 +118,20 @@ class DialogLaunchAnimator( fun onDozeAmountChanged(amount: Float) { currentAnimations.forEach { it.onDozeAmountChanged(amount) } } + + /** + * Ensure that all dialogs currently shown won't animate into their touch surface when + * dismissed. + * + * This is a temporary API meant to be called right before we both dismiss a dialog and start + * an activity, which currently does not look good if we animate the dialog into the touch + * surface at the same time as the activity starts. + * + * TODO(b/193634619): Remove this function and animate dialog into opening activity instead. + */ + fun disableAllCurrentDialogsExitAnimations() { + currentAnimations.forEach { it.exitAnimationDisabled = true } + } } interface HostDialogProvider { @@ -133,6 +147,7 @@ interface HostDialogProvider { */ fun createHostDialog( context: Context, + theme: Int, onCreateCallback: () -> Unit, dismissOverride: (() -> Unit) -> Unit ): Dialog @@ -180,7 +195,7 @@ private class DialogLaunchAnimation( * [originalDialog]. */ val hostDialog = hostDialogProvider.createHostDialog( - context, this::onHostDialogCreated, this::onHostDialogDismissed) + context, R.style.HostDialogTheme, this::onHostDialogCreated, this::onHostDialogDismissed) /** The root content view of [hostDialog]. */ private val hostDialogRoot = FrameLayout(context) @@ -208,6 +223,7 @@ private class DialogLaunchAnimation( private var dismissRequested = false private var drawHostDialog = false var ignoreNextCallToHide = false + var exitAnimationDisabled = false fun start() { // Show the host (fullscreen) dialog, to which we will add the stolen dialog view. @@ -236,10 +252,6 @@ private class DialogLaunchAnimation( WindowManager.LayoutParams.MATCH_PARENT ) - // The host dialog animation is a translation of 0px so that it is shown directly. The - // translation lasts X ms, so that the scrim fades in during that amount of time. - window.attributes.windowAnimations = R.style.Animation_LaunchHostDialog - // Prevent the host dialog from drawing until the animation starts. hostDialogRoot.viewTreeObserver.addOnPreDrawListener( object : ViewTreeObserver.OnPreDrawListener { @@ -318,9 +330,11 @@ private class DialogLaunchAnimation( (dialogView.parent as? ViewGroup)?.removeView(dialogView) hostDialogRoot.addView( dialogView, + + // We give it the size of its original dialog window. FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT, + originalDialog.window.attributes.width, + originalDialog.window.attributes.height, Gravity.CENTER ) ) @@ -496,6 +510,10 @@ private class DialogLaunchAnimation( } private fun shouldAnimateDialogIntoView(): Boolean { + if (exitAnimationDisabled) { + return false + } + // The touch surface should be invisible by now, if it's not then something else changed its // visibility and we probably don't want to run the animation. if (touchSurface.visibility != View.INVISIBLE) { diff --git a/packages/SystemUI/res/drawable/media_output_dialog_background.xml b/packages/SystemUI/res/drawable/media_output_dialog_background.xml deleted file mode 100644 index 3ceb0f6ac06ae..0000000000000 --- a/packages/SystemUI/res/drawable/media_output_dialog_background.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - diff --git a/packages/SystemUI/res/layout/internet_connectivity_dialog.xml b/packages/SystemUI/res/layout/internet_connectivity_dialog.xml index b841419c1c752..6743fca61441d 100644 --- a/packages/SystemUI/res/layout/internet_connectivity_dialog.xml +++ b/packages/SystemUI/res/layout/internet_connectivity_dialog.xml @@ -19,7 +19,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" android:id="@+id/internet_connectivity_dialog" - android:layout_width="@dimen/internet_dialog_list_max_width" + android:layout_width="@dimen/large_dialog_width" android:layout_height="@dimen/internet_dialog_list_max_height" android:background="@drawable/internet_dialog_rounded_top_corner_background" android:orientation="vertical"> diff --git a/packages/SystemUI/res/layout/media_output_dialog.xml b/packages/SystemUI/res/layout/media_output_dialog.xml index d996cee4b39e5..b33889469f489 100644 --- a/packages/SystemUI/res/layout/media_output_dialog.xml +++ b/packages/SystemUI/res/layout/media_output_dialog.xml @@ -18,7 +18,7 @@ diff --git a/packages/SystemUI/res/layout/media_view.xml b/packages/SystemUI/res/layout/media_view.xml index 566cd25e86a5a..b546a9cbe90e6 100644 --- a/packages/SystemUI/res/layout/media_view.xml +++ b/packages/SystemUI/res/layout/media_view.xml @@ -134,6 +134,7 @@ android:background="@drawable/qs_media_light_source" android:forceHasOverlappingRendering="false"> 0dp - - 624dp + + 624dp diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 26ee5ea7f914a..3ec8b06bdb2c8 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -1600,7 +1600,9 @@ 12dp 646dp - @dimen/match_parent + + + @dimen/match_parent 24dp diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml index d25474255bfc5..702e0da4cffa6 100644 --- a/packages/SystemUI/res/values/styles.xml +++ b/packages/SystemUI/res/values/styles.xml @@ -331,9 +331,6 @@ - - @@ -434,10 +431,6 @@ true - -