summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/binder/OngoingActivityChipBinder.kt12
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/compose/ChipContent.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/model/OngoingActivityChipModel.kt15
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/viewmodel/TimeRemainingState.kt25
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/binder/HomeStatusBarViewBinder.kt2
5 files changed, 49 insertions, 9 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/binder/OngoingActivityChipBinder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/binder/OngoingActivityChipBinder.kt
index 02e4ba4d6437..6f8552738d33 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/binder/OngoingActivityChipBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/binder/OngoingActivityChipBinder.kt
@@ -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,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/compose/ChipContent.kt b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/compose/ChipContent.kt
index ac55bf2bee1c..55d753662a65 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/compose/ChipContent.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/compose/ChipContent.kt
@@ -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 =
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/model/OngoingActivityChipModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/model/OngoingActivityChipModel.kt
index 0cfc3216beb5..8e470742f174 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/model/OngoingActivityChipModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/model/OngoingActivityChipModel.kt
@@ -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,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/viewmodel/TimeRemainingState.kt b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/viewmodel/TimeRemainingState.kt
index eb6ebcaa5796..803d422c0f0f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/viewmodel/TimeRemainingState.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/viewmodel/TimeRemainingState.kt
@@ -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 =
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/binder/HomeStatusBarViewBinder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/binder/HomeStatusBarViewBinder.kt
index cfd50973924d..6fada264e397 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/binder/HomeStatusBarViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/binder/HomeStatusBarViewBinder.kt
@@ -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,