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

Commit ef3876e1 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

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
parent e5b54057
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -15,7 +15,14 @@
     limitations under the License.
-->
<resources>
  <style name="Animation.LaunchHostDialog" parent="@android:style/Animation">
  <style name="HostDialogTheme">
    <item name="android:windowAnimationStyle">@style/Animation.HostDialog</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:navigationBarColor">@android:color/transparent</item>
  </style>

  <style name="Animation.HostDialog" parent="@android:style/Animation">
    <item name="android:windowEnterAnimation">@anim/launch_host_dialog_enter</item>
    <item name="android:windowExitAnimation">@anim/launch_host_dialog_exit</item>
  </style>
+25 −7
Original line number Diff line number Diff line
@@ -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) {
+0 −23
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2020 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<inset xmlns:android="http://schemas.android.com/apk/res/android">
    <shape android:shape="rectangle">
        <corners android:radius="8dp" />
        <solid android:color="?android:attr/colorBackground" />
    </shape>
</inset>
+1 −1
Original line number Diff line number Diff line
@@ -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">
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/media_output_dialog"
    android:layout_width="match_parent"
    android:layout_width="@dimen/large_dialog_width"
    android:layout_height="wrap_content"
    android:orientation="vertical">

Loading