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

Commit afa8cc15 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB][Screen Chips] Re-add animation from chip -> stop dialog, and CUJs.

It turns out there's a workaround that lets SysUI do a nice animate-in
from view -> dialog, and then do a standard animate-out so that the
dialog doesn't try to animate out into a view that's about to disappear.
This CL re-adds that nice animate-in and includes the workound. It also
adds CUJ tracking.

Fixes: 353249803
Bug: 332662551
Flag: com.android.systemui.status_bar_screen_sharing_chips

Test: start a screen share, then tap chip -> verify the chip animates
nicely into the dialog. Tap "stop" on the dialog -> verify the dialog
does *not* animate out into the chip
Test: All tests in statusbar.chips package

Change-Id: I84993c7135152cf3f50d22975abd97438fb84824
parent 3b17f3fd
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -44,9 +44,10 @@ class EndCastScreenToOtherDeviceDialogDelegate(
            // No custom on-click, because the dialog will automatically be dismissed when the
            // button is clicked anyway.
            setNegativeButton(R.string.close_dialog_button, /* onClick= */ null)
            setPositiveButton(R.string.cast_to_other_device_stop_dialog_button) { _, _ ->
                stopAction.invoke()
            }
            setPositiveButton(
                R.string.cast_to_other_device_stop_dialog_button,
                endMediaProjectionDialogHelper.wrapStopAction(stopAction),
            )
        }
    }

+4 −3
Original line number Diff line number Diff line
@@ -55,9 +55,10 @@ class EndGenericCastToOtherDeviceDialogDelegate(
            // No custom on-click, because the dialog will automatically be dismissed when the
            // button is clicked anyway.
            setNegativeButton(R.string.close_dialog_button, /* onClick= */ null)
            setPositiveButton(R.string.cast_to_other_device_stop_dialog_button) { _, _ ->
                stopAction.invoke()
            }
            setPositiveButton(
                R.string.cast_to_other_device_stop_dialog_button,
                endMediaProjectionDialogHelper.wrapStopAction(stopAction),
            )
        }
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -18,6 +18,9 @@ package com.android.systemui.statusbar.chips.casttootherdevice.ui.viewmodel

import android.content.Context
import androidx.annotation.DrawableRes
import com.android.internal.jank.Cuj
import com.android.systemui.animation.DialogCuj
import com.android.systemui.animation.DialogTransitionAnimator
import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.dagger.SysUISingleton
@@ -60,6 +63,7 @@ constructor(
    private val mediaProjectionChipInteractor: MediaProjectionChipInteractor,
    private val mediaRouterChipInteractor: MediaRouterChipInteractor,
    private val systemClock: SystemClock,
    private val dialogTransitionAnimator: DialogTransitionAnimator,
    private val endMediaProjectionDialogHelper: EndMediaProjectionDialogHelper,
    @StatusBarChipsLog private val logger: LogBuffer,
) : OngoingActivityChipViewModel {
@@ -190,6 +194,8 @@ constructor(
            startTimeMs = systemClock.elapsedRealtime(),
            createDialogLaunchOnClickListener(
                createCastScreenToOtherDeviceDialogDelegate(state),
                dialogTransitionAnimator,
                DialogCuj(Cuj.CUJ_STATUS_BAR_LAUNCH_DIALOG_FROM_CHIP, tag = "Cast to other device"),
                logger,
                TAG,
            ),
@@ -207,6 +213,11 @@ constructor(
            colors = ColorsModel.Red,
            createDialogLaunchOnClickListener(
                createGenericCastToOtherDeviceDialogDelegate(deviceName),
                dialogTransitionAnimator,
                DialogCuj(
                    Cuj.CUJ_STATUS_BAR_LAUNCH_DIALOG_FROM_CHIP,
                    tag = "Cast to other device audio only",
                ),
                logger,
                TAG,
            ),
+25 −0
Original line number Diff line number Diff line
@@ -17,7 +17,9 @@
package com.android.systemui.statusbar.chips.mediaprojection.ui.view

import android.app.ActivityManager
import android.content.DialogInterface
import android.content.pm.PackageManager
import com.android.systemui.animation.DialogTransitionAnimator
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.mediaprojection.data.model.MediaProjectionState
import com.android.systemui.statusbar.phone.SystemUIDialog
@@ -29,6 +31,7 @@ class EndMediaProjectionDialogHelper
@Inject
constructor(
    private val dialogFactory: SystemUIDialog.Factory,
    private val dialogTransitionAnimator: DialogTransitionAnimator,
    private val packageManager: PackageManager,
) {
    /** Creates a new [SystemUIDialog] using the given delegate. */
@@ -36,6 +39,28 @@ constructor(
        return dialogFactory.create(delegate)
    }

    /**
     * Returns the click listener that should be invoked if a user clicks "Stop" on the end media
     * projection dialog.
     *
     * The click listener will invoke [stopAction] and also do some UI manipulation.
     *
     * @param stopAction an action that, when invoked, should notify system API(s) that the media
     *   projection should be stopped.
     */
    fun wrapStopAction(stopAction: () -> Unit): DialogInterface.OnClickListener {
        return DialogInterface.OnClickListener { _, _ ->
            // If the projection is stopped, then the chip will disappear, so we don't want the
            // dialog to animate back into the chip just for the chip to disappear in a few frames.
            dialogTransitionAnimator.disableAllCurrentDialogsExitAnimations()
            stopAction.invoke()
            // TODO(b/332662551): If the projection is stopped, there's a brief moment where the
            // dialog closes and the chip re-shows because the system APIs haven't come back and
            // told SysUI that the projection has officially stopped. It would be great for the chip
            // to not re-show at all.
        }
    }

    fun getAppName(state: MediaProjectionState.Projecting): CharSequence? {
        val specificTaskInfo =
            if (state is MediaProjectionState.Projecting.SingleTask) {
+4 −3
Original line number Diff line number Diff line
@@ -52,9 +52,10 @@ class EndScreenRecordingDialogDelegate(
            // No custom on-click, because the dialog will automatically be dismissed when the
            // button is clicked anyway.
            setNegativeButton(R.string.close_dialog_button, /* onClick= */ null)
            setPositiveButton(R.string.screenrecord_stop_dialog_button) { _, _ ->
                stopAction.invoke()
            }
            setPositiveButton(
                R.string.screenrecord_stop_dialog_button,
                endMediaProjectionDialogHelper.wrapStopAction(stopAction),
            )
        }
    }
}
Loading