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

Commit a87fbcb0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add UMO onClick implementation" into main

parents 30cf72e2 6a2ef2fe
Loading
Loading
Loading
Loading
+51 −2
Original line number Diff line number Diff line
@@ -16,13 +16,18 @@

package com.android.systemui.media.remedia.domain.interactor

import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.provider.Settings
import android.util.Log
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import com.android.internal.jank.Cuj
import com.android.internal.logging.InstanceId
import com.android.settingslib.media.LocalMediaManager.MediaDeviceState
import com.android.systemui.ActivityIntentHelper
import com.android.systemui.animation.Expandable
import com.android.systemui.biometrics.Utils.toBitmap
import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.common.shared.model.Icon
@@ -43,6 +48,8 @@ import com.android.systemui.media.remedia.shared.model.MediaColorScheme
import com.android.systemui.media.remedia.shared.model.MediaSessionState
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.res.R
import com.android.systemui.statusbar.NotificationLockscreenUserManager
import com.android.systemui.statusbar.policy.KeyguardStateController
import javax.inject.Inject

/**
@@ -71,7 +78,10 @@ constructor(
    @Application val applicationContext: Context,
    val repository: MediaRepository,
    val mediaDataProcessor: MediaDataProcessor,
    private val keyguardStateController: KeyguardStateController,
    private val activityStarter: ActivityStarter,
    private val activityIntentHelper: ActivityIntentHelper,
    private val lockscreenUserManager: NotificationLockscreenUserManager,
) : MediaInteractor {

    override val sessions: List<MediaSessionModel>
@@ -115,8 +125,10 @@ constructor(
            override val subtitle: String
                get() = dataModel.subtitle

            override val onClick: () -> Unit
                get() = TODO("Not yet implemented")
            override val onClick: (Expandable) -> Unit
                get() = { expandable ->
                    dataModel.clickIntent?.let { startClickIntent(expandable, it) }
                }

            override val isActive: Boolean
                get() = dataModel.isActive
@@ -228,7 +240,44 @@ constructor(
        )
    }

    fun startClickIntent(expandable: Expandable, clickIntent: PendingIntent) {
        if (!launchOverLockscreen(expandable, clickIntent)) {
            activityStarter.postStartActivityDismissingKeyguard(
                clickIntent,
                expandable.activityTransitionController(Cuj.CUJ_SHADE_APP_LAUNCH_FROM_MEDIA_PLAYER),
            )
        }
    }

    private fun launchOverLockscreen(
        expandable: Expandable,
        pendingIntent: PendingIntent,
    ): Boolean {
        val showOverLockscreen =
            keyguardStateController.isShowing &&
                activityIntentHelper.wouldPendingShowOverLockscreen(
                    pendingIntent,
                    lockscreenUserManager.currentUserId,
                )
        if (showOverLockscreen) {
            try {
                activityStarter.startPendingIntentMaybeDismissingKeyguard(
                    pendingIntent,
                    /* intentSentUiThreadCallback = */ null,
                    expandable.activityTransitionController(
                        Cuj.CUJ_SHADE_APP_LAUNCH_FROM_MEDIA_PLAYER
                    ),
                )
            } catch (e: PendingIntent.CanceledException) {
                Log.e(TAG, "pending intent was canceled")
            }
            return true
        }
        return false
    }

    companion object {
        private const val TAG = "MediaInteractor"
        private val settingsIntent: Intent = Intent(Settings.ACTION_MEDIA_CONTROLS_SETTINGS)
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.media.remedia.domain.model

import androidx.compose.runtime.Stable
import androidx.compose.ui.graphics.ImageBitmap
import com.android.systemui.animation.Expandable
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.media.remedia.shared.model.MediaCardActionButtonLayout
import com.android.systemui.media.remedia.shared.model.MediaColorScheme
@@ -41,7 +42,7 @@ interface MediaSessionModel {

    val subtitle: String

    val onClick: () -> Unit
    val onClick: (Expandable) -> Unit

    /**
     * Whether the session is currently active. Under some UIs, only currently active session should
+45 −13
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.CompositingStrategy
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.drawscope.clipRect
@@ -123,6 +124,8 @@ import androidx.compose.ui.util.fastRoundToInt
import com.android.compose.PlatformButton
import com.android.compose.PlatformIconButton
import com.android.compose.PlatformOutlinedButton
import com.android.compose.animation.Expandable
import com.android.compose.animation.rememberExpandableController
import com.android.compose.animation.scene.ContentScope
import com.android.compose.animation.scene.ElementKey
import com.android.compose.animation.scene.SceneKey
@@ -135,6 +138,7 @@ import com.android.compose.modifiers.thenIf
import com.android.compose.theme.LocalAndroidColorScheme
import com.android.compose.ui.graphics.painter.rememberDrawablePainter
import com.android.mechanics.spec.builder.rememberMotionBuilderContext
import com.android.systemui.animation.Expandable
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.common.ui.compose.Icon
import com.android.systemui.common.ui.compose.PagerDots
@@ -327,17 +331,35 @@ private fun Card(
            CardBackground(image = viewModel.background, modifier = Modifier.matchParentSize())
        }

        Expandable(
            controller =
                rememberExpandableController(color = Color.Transparent, shape = RectangleShape),
            useModifierBasedImplementation = true,
        ) {
            key(stlState) {
                SceneTransitionLayout(state = stlState) {
                    scene(Media.Scenes.Default) {
                    CardForeground(viewModel = viewModel, threeRows = true, fillHeight = false)
                        CardForeground(
                            expandable = it,
                            viewModel = viewModel,
                            threeRows = true,
                            fillHeight = false,
                        )
                    }

                    scene(Media.Scenes.Compressed) {
                    CardForeground(viewModel = viewModel, threeRows = false, fillHeight = false)
                        CardForeground(
                            expandable = it,
                            viewModel = viewModel,
                            threeRows = false,
                            fillHeight = false,
                        )
                    }

                scene(Media.Scenes.Compact) { CompactCardForeground(viewModel = viewModel) }
                    scene(Media.Scenes.Compact) {
                        CompactCardForeground(expandable = it, viewModel = viewModel)
                    }
                }
            }
        }
    }
@@ -372,6 +394,7 @@ private fun rememberAnimatedColorScheme(colorScheme: MediaColorScheme?): Animate
 */
@Composable
private fun ContentScope.CardForeground(
    expandable: Expandable,
    viewModel: MediaCardViewModel,
    threeRows: Boolean,
    fillHeight: Boolean,
@@ -391,6 +414,7 @@ private fun ContentScope.CardForeground(
    Layout(
        content = {
            CardForegroundContent(
                expandable = expandable,
                viewModel = viewModel,
                threeRows = threeRows,
                fillHeight = fillHeight,
@@ -436,16 +460,18 @@ private fun ContentScope.CardForeground(

@Composable
private fun ContentScope.CardForegroundContent(
    expandable: Expandable,
    viewModel: MediaCardViewModel,
    threeRows: Boolean,
    fillHeight: Boolean,
    colorScheme: AnimatedColorScheme,
    modifier: Modifier = Modifier,
) {

    Column(
        modifier =
            modifier.combinedClickable(
                onClick = viewModel.onClick,
                onClick = { viewModel.onClick(expandable) },
                onLongClick = viewModel.onLongClick,
                onClickLabel = viewModel.onClickLabel,
            )
@@ -468,10 +494,12 @@ private fun ContentScope.CardForegroundContent(
                horizontalArrangement = Arrangement.spacedBy(8.dp),
                modifier =
                    Modifier.align(Alignment.TopEnd)
                        // Output switcher chip must be limited to at most 40% of the maximum width
                        // Output switcher chip must be limited to at most 40% of the maximum
                        // width
                        // of the card.
                        //
                        // This saves the maximum possible width of the card so it can be referred
                        // This saves the maximum possible width of the card so it can be
                        // referred
                        // to by child custom layout code below.
                        //
                        // The assumption is that the row can be as wide as the entire card.
@@ -646,6 +674,7 @@ private fun ContentScope.CardForegroundContent(
 */
@Composable
private fun ContentScope.CompactCardForeground(
    expandable: Expandable,
    viewModel: MediaCardViewModel,
    modifier: Modifier = Modifier,
) {
@@ -654,7 +683,10 @@ private fun ContentScope.CompactCardForeground(
        verticalAlignment = Alignment.CenterVertically,
        modifier =
            modifier
                .clickable(onClick = viewModel.onClick, onClickLabel = viewModel.onClickLabel)
                .clickable(
                    onClick = { viewModel.onClick(expandable) },
                    onClickLabel = viewModel.onClickLabel,
                )
                .background(MaterialTheme.colorScheme.surfaceContainer)
                .padding(16.dp),
    ) {
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.media.remedia.ui.viewmodel

import androidx.compose.runtime.Stable
import androidx.compose.ui.graphics.ImageBitmap
import com.android.systemui.animation.Expandable
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.media.remedia.shared.model.MediaCardActionButtonLayout
import com.android.systemui.media.remedia.shared.model.MediaColorScheme
@@ -58,7 +59,7 @@ interface MediaCardViewModel {
    /** Simple icon-only version of the output switcher for use in compact UIs. */
    val outputSwitcherChipButton: MediaSecondaryActionViewModel.Action

    val onClick: () -> Unit
    val onClick: (Expandable) -> Unit

    /** Accessibility string for the click action of the card. */
    val onClickLabel: String?
+5 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.ImageBitmap
import com.android.systemui.animation.Expandable
import com.android.systemui.classifier.Classifier
import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.common.shared.model.Icon
@@ -266,8 +267,10 @@ constructor(
                        )
                    }

                override val onClick = {
                    falsingSystem.runIfNotFalseTap(FalsingManager.LOW_PENALTY) { session.onClick() }
                override val onClick = { expandable: Expandable ->
                    falsingSystem.runIfNotFalseTap(FalsingManager.LOW_PENALTY) {
                        session.onClick(expandable)
                    }
                }
                override val onClickLabel =
                    context.getString(R.string.controls_media_playing_item_description)
Loading