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

Commit a9566685 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Android (Google) Code Review
Browse files

Merge changes Id1729675,I9b69ce8a into main

* changes:
  [SB][Chips] Fix up the ShortTimeDelta Compose Chips.
  [SB][Chips] Update font in chips to Label.Large.Emphasized.
parents 973c2d1a d5041211
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.chips.ui.binder
import android.annotation.IdRes
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Typeface
import android.graphics.drawable.GradientDrawable
import android.view.View
import android.view.ViewGroup
@@ -27,6 +28,7 @@ import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.UiThread
import com.android.systemui.FontStyles
import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.common.ui.binder.ContentDescriptionViewBinder
import com.android.systemui.common.ui.binder.IconViewBinder
@@ -170,6 +172,16 @@ object OngoingActivityChipBinder {
        forceLayout()
    }

    /** Updates the typefaces for any text shown in the chip. */
    fun updateTypefaces(binding: OngoingActivityChipViewBinding) {
        binding.timeView.typeface =
            Typeface.create(FontStyles.GSF_LABEL_LARGE_EMPHASIZED, Typeface.NORMAL)
        binding.textView.typeface =
            Typeface.create(FontStyles.GSF_LABEL_LARGE_EMPHASIZED, Typeface.NORMAL)
        binding.shortTimeDeltaView.typeface =
            Typeface.create(FontStyles.GSF_LABEL_LARGE_EMPHASIZED, Typeface.NORMAL)
    }

    private fun setChipIcon(
        chipModel: OngoingActivityChipModel.Active,
        backgroundView: ChipBackgroundContainer,
+3 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.chips.ui.compose

import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
@@ -44,6 +45,7 @@ import com.android.systemui.statusbar.chips.ui.viewmodel.rememberChronometerStat
import com.android.systemui.statusbar.chips.ui.viewmodel.rememberTimeRemainingState
import kotlin.math.min

@OptIn(ExperimentalMaterial3ExpressiveApi::class)
@Composable
fun ChipContent(viewModel: OngoingActivityChipModel.Active, modifier: Modifier = Modifier) {
    val context = LocalContext.current
@@ -52,7 +54,7 @@ fun ChipContent(viewModel: OngoingActivityChipModel.Active, modifier: Modifier =
    val hasEmbeddedIcon =
        viewModel.icon is OngoingActivityChipModel.ChipIcon.StatusBarView ||
            viewModel.icon is OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon
    val textStyle = MaterialTheme.typography.labelLarge
    val textStyle = MaterialTheme.typography.labelLargeEmphasized
    val textColor = Color(viewModel.colors.text(context))
    val maxTextWidth = dimensionResource(id = R.dimen.ongoing_activity_chip_max_text_width)
    val startPadding =
+11 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.statusbar.chips.ui.model

import android.annotation.CurrentTimeMillisLong
import android.annotation.ElapsedRealtimeLong
import android.view.View
import com.android.systemui.animation.Expandable
import com.android.systemui.common.shared.model.ContentDescription
@@ -102,7 +104,7 @@ sealed class OngoingActivityChipModel {
             * [ChipChronometer] is based off of elapsed realtime. See
             * [android.widget.Chronometer.setBase].
             */
            val startTimeMs: Long,
            @ElapsedRealtimeLong val startTimeMs: Long,
            override val onClickListenerLegacy: View.OnClickListener?,
            override val clickBehavior: ClickBehavior,
            override val isHidden: Boolean = false,
@@ -129,10 +131,15 @@ sealed class OngoingActivityChipModel {
            override val icon: ChipIcon,
            override val colors: ColorsModel,
            /**
             * The time of the event that this chip represents, relative to
             * [com.android.systemui.util.time.SystemClock.currentTimeMillis].
             * The time of the event that this chip represents. Relative to
             * [com.android.systemui.util.time.SystemClock.currentTimeMillis] because that's what's
             * required by [android.widget.DateTimeView].
             *
             * TODO(b/372657935): When the Compose chips are launched, we should convert this to be
             *   relative to [com.android.systemui.util.time.SystemClock.elapsedRealtime] so that
             *   this model and the [Timer] model use the same units.
             */
            val time: Long,
            @CurrentTimeMillisLong val time: Long,
            override val onClickListenerLegacy: View.OnClickListener?,
            override val clickBehavior: ClickBehavior,
            override val isHidden: Boolean = false,
+21 −4
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.statusbar.chips.ui.viewmodel

import android.os.SystemClock
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
@@ -39,7 +38,14 @@ import kotlinx.coroutines.delay
 * Manages state and updates for the duration remaining between now and a given time in the future.
 */
class TimeRemainingState(private val timeSource: TimeSource, private val futureTimeMillis: Long) {
    private var durationRemaining by mutableStateOf(Duration.ZERO)
    // Start with the right duration from the outset so we don't use "now" as an initial value.
    private var durationRemaining by
        mutableStateOf(
            calculateDurationRemaining(
                currentTimeMillis = timeSource.getCurrentTime(),
                futureTimeMillis = futureTimeMillis,
            )
        )
    private var startTimeMillis: Long = 0

    /**
@@ -56,7 +62,11 @@ class TimeRemainingState(private val timeSource: TimeSource, private val futureT
        while (true) {
            val currentTime = timeSource.getCurrentTime()
            durationRemaining =
                (futureTimeMillis - currentTime).toDuration(DurationUnit.MILLISECONDS)
                calculateDurationRemaining(
                    currentTimeMillis = currentTime,
                    futureTimeMillis = futureTimeMillis,
                )

            // No need to update if duration is more than 1 minute in the past. Because, we will
            // stop displaying anything.
            if (durationRemaining.inWholeMilliseconds < -1.minutes.inWholeMilliseconds) {
@@ -67,6 +77,13 @@ class TimeRemainingState(private val timeSource: TimeSource, private val futureT
        }
    }

    private fun calculateDurationRemaining(
        currentTimeMillis: Long,
        futureTimeMillis: Long,
    ): Duration {
        return (futureTimeMillis - currentTimeMillis).toDuration(DurationUnit.MILLISECONDS)
    }

    private fun calculateNextUpdateDelay(duration: Duration): Long {
        val durationAbsolute = duration.absoluteValue
        return when {
@@ -85,7 +102,7 @@ class TimeRemainingState(private val timeSource: TimeSource, private val futureT
@Composable
fun rememberTimeRemainingState(
    futureTimeMillis: Long,
    timeSource: TimeSource = remember { TimeSource { SystemClock.elapsedRealtime() } },
    timeSource: TimeSource = remember { TimeSource { System.currentTimeMillis() } },
): TimeRemainingState {

    val state =
+2 −0
Original line number Diff line number Diff line
@@ -203,6 +203,8 @@ constructor(
                        OngoingActivityChipBinder.createBinding(
                            view.requireViewById(R.id.ongoing_activity_chip_secondary)
                        )
                    OngoingActivityChipBinder.updateTypefaces(primaryChipViewBinding)
                    OngoingActivityChipBinder.updateTypefaces(secondaryChipViewBinding)
                    launch {
                        combine(
                                viewModel.ongoingActivityChipsLegacy,