diff options
11 files changed, 123 insertions, 1 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModel.kt index ad09aa3ca3a0..ba3fde60de73 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModel.kt @@ -24,6 +24,7 @@ import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.plugins.ActivityStarter import com.android.systemui.res.R import com.android.systemui.statusbar.chips.call.domain.interactor.CallChipInteractor +import com.android.systemui.statusbar.chips.ui.model.ColorsModel import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel import com.android.systemui.statusbar.chips.ui.view.ChipBackgroundContainer import com.android.systemui.statusbar.chips.ui.viewmodel.OngoingActivityChipViewModel @@ -65,6 +66,7 @@ constructor( com.android.internal.R.drawable.ic_phone, contentDescription = null, ), + colors = ColorsModel.Themed, startTimeMs = startTimeInElapsedRealtime, ) { if (state.intent != null) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/chips/casttootherdevice/ui/viewmodel/CastToOtherDeviceChipViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/chips/casttootherdevice/ui/viewmodel/CastToOtherDeviceChipViewModel.kt index a1678bf3d452..53b1e756c3ac 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/chips/casttootherdevice/ui/viewmodel/CastToOtherDeviceChipViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/chips/casttootherdevice/ui/viewmodel/CastToOtherDeviceChipViewModel.kt @@ -27,6 +27,7 @@ import com.android.systemui.statusbar.chips.casttootherdevice.ui.view.EndCastToO import com.android.systemui.statusbar.chips.mediaprojection.domain.interactor.MediaProjectionChipInteractor import com.android.systemui.statusbar.chips.mediaprojection.domain.model.ProjectionChipModel import com.android.systemui.statusbar.chips.mediaprojection.ui.view.EndMediaProjectionDialogHelper +import com.android.systemui.statusbar.chips.ui.model.ColorsModel import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel import com.android.systemui.statusbar.chips.ui.viewmodel.OngoingActivityChipViewModel import com.android.systemui.statusbar.chips.ui.viewmodel.OngoingActivityChipViewModel.Companion.createDialogLaunchOnClickListener @@ -85,6 +86,7 @@ constructor( CAST_TO_OTHER_DEVICE_ICON, ContentDescription.Resource(R.string.accessibility_casting), ), + colors = ColorsModel.Red, // TODO(b/332662551): Maybe use a MediaProjection API to fetch this time. startTimeMs = systemClock.elapsedRealtime(), createDialogLaunchOnClickListener( diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/chips/screenrecord/ui/viewmodel/ScreenRecordChipViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/chips/screenrecord/ui/viewmodel/ScreenRecordChipViewModel.kt index d190cfdd1175..9d54c757b4fb 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/chips/screenrecord/ui/viewmodel/ScreenRecordChipViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/chips/screenrecord/ui/viewmodel/ScreenRecordChipViewModel.kt @@ -27,6 +27,7 @@ import com.android.systemui.statusbar.chips.mediaprojection.ui.view.EndMediaProj import com.android.systemui.statusbar.chips.screenrecord.domain.interactor.ScreenRecordChipInteractor import com.android.systemui.statusbar.chips.screenrecord.domain.model.ScreenRecordChipModel import com.android.systemui.statusbar.chips.screenrecord.ui.view.EndScreenRecordingDialogDelegate +import com.android.systemui.statusbar.chips.ui.model.ColorsModel import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel import com.android.systemui.statusbar.chips.ui.viewmodel.OngoingActivityChipViewModel import com.android.systemui.statusbar.chips.ui.viewmodel.OngoingActivityChipViewModel.Companion.createDialogLaunchOnClickListener @@ -60,6 +61,7 @@ constructor( OngoingActivityChipModel.Shown( // TODO(b/332662551): Also provide a content description. icon = Icon.Resource(ICON, contentDescription = null), + colors = ColorsModel.Red, startTimeMs = systemClock.elapsedRealtime(), createDialogLaunchOnClickListener( createDelegate(state.recordedTask), diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/chips/sharetoapp/ui/viewmodel/ShareToAppChipViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/chips/sharetoapp/ui/viewmodel/ShareToAppChipViewModel.kt index dc4100269702..0c24a709de63 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/chips/sharetoapp/ui/viewmodel/ShareToAppChipViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/chips/sharetoapp/ui/viewmodel/ShareToAppChipViewModel.kt @@ -26,6 +26,7 @@ import com.android.systemui.statusbar.chips.mediaprojection.domain.interactor.Me import com.android.systemui.statusbar.chips.mediaprojection.domain.model.ProjectionChipModel import com.android.systemui.statusbar.chips.mediaprojection.ui.view.EndMediaProjectionDialogHelper import com.android.systemui.statusbar.chips.sharetoapp.ui.view.EndShareToAppDialogDelegate +import com.android.systemui.statusbar.chips.ui.model.ColorsModel import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel import com.android.systemui.statusbar.chips.ui.viewmodel.OngoingActivityChipViewModel import com.android.systemui.statusbar.chips.ui.viewmodel.OngoingActivityChipViewModel.Companion.createDialogLaunchOnClickListener @@ -78,6 +79,7 @@ constructor( return OngoingActivityChipModel.Shown( // TODO(b/332662551): Use the right content description. icon = Icon.Resource(SHARE_TO_APP_ICON, contentDescription = null), + colors = ColorsModel.Red, // TODO(b/332662551): Maybe use a MediaProjection API to fetch this time. startTimeMs = systemClock.elapsedRealtime(), createDialogLaunchOnClickListener( diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/model/ColorsModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/model/ColorsModel.kt new file mode 100644 index 000000000000..b2140f793ced --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/chips/ui/model/ColorsModel.kt @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2024 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. + */ + +package com.android.systemui.statusbar.chips.ui.model + +import android.content.Context +import android.content.res.ColorStateList +import androidx.annotation.ColorInt +import com.android.settingslib.Utils +import com.android.systemui.res.R + +/** Model representing how the chip in the status bar should be colored. */ +sealed interface ColorsModel { + /** The color for the background of the chip. */ + fun background(context: Context): ColorStateList + + /** The color for the text (and icon) on the chip. */ + @ColorInt fun text(context: Context): Int + + /** The chip should match the theme's primary color. */ + data object Themed : ColorsModel { + override fun background(context: Context): ColorStateList = + Utils.getColorAttr(context, com.android.internal.R.attr.colorAccent) + + override fun text(context: Context) = + Utils.getColorAttrDefaultColor(context, com.android.internal.R.attr.colorPrimary) + } + + /** The chip should have a red background with white text. */ + data object Red : ColorsModel { + override fun background(context: Context): ColorStateList = + ColorStateList.valueOf(context.getColor(R.color.GM2_red_600)) + + override fun text(context: Context) = context.getColor(android.R.color.white) + } +} 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 e63713bf1602..4ea674a0fd40 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 @@ -28,6 +28,8 @@ sealed class OngoingActivityChipModel { data class Shown( /** The icon to show on the chip. */ val icon: Icon, + /** What colors to use for the chip. */ + val colors: ColorsModel, /** * The time this event started, used to show the timer. * diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/binder/CollapsedStatusBarViewBinder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/binder/CollapsedStatusBarViewBinder.kt index 7644653306be..d607ce08eeeb 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/binder/CollapsedStatusBarViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ui/binder/CollapsedStatusBarViewBinder.kt @@ -18,6 +18,8 @@ package com.android.systemui.statusbar.pipeline.shared.ui.binder import android.animation.Animator import android.animation.AnimatorListenerAdapter +import android.content.res.ColorStateList +import android.graphics.drawable.GradientDrawable import android.view.View import android.widget.ImageView import androidx.lifecycle.Lifecycle @@ -29,6 +31,7 @@ import com.android.systemui.lifecycle.repeatWhenAttached import com.android.systemui.res.R import com.android.systemui.statusbar.chips.ui.binder.ChipChronometerBinder import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel +import com.android.systemui.statusbar.chips.ui.view.ChipBackgroundContainer import com.android.systemui.statusbar.chips.ui.view.ChipChronometer import com.android.systemui.statusbar.notification.shared.NotificationsLiveDataStoreRefactor import com.android.systemui.statusbar.pipeline.shared.ui.viewmodel.CollapsedStatusBarViewModel @@ -84,18 +87,31 @@ class CollapsedStatusBarViewBinderImpl @Inject constructor() : CollapsedStatusBa if (Flags.statusBarScreenSharingChips()) { val chipView: View = view.requireViewById(R.id.ongoing_activity_chip) + val chipContext = chipView.context val chipIconView: ImageView = chipView.requireViewById(R.id.ongoing_activity_chip_icon) val chipTimeView: ChipChronometer = chipView.requireViewById(R.id.ongoing_activity_chip_time) + val chipBackgroundView = + chipView.requireViewById<ChipBackgroundContainer>( + R.id.ongoing_activity_chip_background + ) launch { viewModel.ongoingActivityChip.collect { chipModel -> when (chipModel) { is OngoingActivityChipModel.Shown -> { + // Data IconViewBinder.bind(chipModel.icon, chipIconView) ChipChronometerBinder.bind(chipModel.startTimeMs, chipTimeView) chipView.setOnClickListener(chipModel.onClickListener) + // Colors + val textColor = chipModel.colors.text(chipContext) + chipIconView.imageTintList = ColorStateList.valueOf(textColor) + chipTimeView.setTextColor(textColor) + (chipBackgroundView.background as GradientDrawable).color = + chipModel.colors.background(chipContext) + listener.onOngoingActivityStatusChanged( hasOngoingActivity = true ) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModelTest.kt index 6cac30a75c2a..3606b1b1823b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModelTest.kt @@ -26,6 +26,7 @@ import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.testScope import com.android.systemui.plugins.activityStarter import com.android.systemui.res.R +import com.android.systemui.statusbar.chips.ui.model.ColorsModel import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel import com.android.systemui.statusbar.chips.ui.view.ChipBackgroundContainer import com.android.systemui.statusbar.phone.ongoingcall.data.repository.ongoingCallRepository @@ -95,7 +96,7 @@ class CallChipViewModelTest : SysuiTestCase() { } @Test - fun chip_inCall_iconIsPhone() = + fun chip_iconIsPhone() = testScope.runTest { val latest by collectLastValue(underTest.chip) @@ -106,6 +107,17 @@ class CallChipViewModelTest : SysuiTestCase() { } @Test + fun chip_colorsAreThemed() = + testScope.runTest { + val latest by collectLastValue(underTest.chip) + + repo.setOngoingCallState(OngoingCallModel.InCall(startTimeMs = 1000, intent = null)) + + assertThat((latest as OngoingActivityChipModel.Shown).colors) + .isEqualTo(ColorsModel.Themed) + } + + @Test fun chip_resetsCorrectly() = testScope.runTest { val latest by collectLastValue(underTest.chip) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/casttootherdevice/ui/viewmodel/CastToOtherDeviceChipViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/casttootherdevice/ui/viewmodel/CastToOtherDeviceChipViewModelTest.kt index 93d781f6817e..d7935e558992 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/casttootherdevice/ui/viewmodel/CastToOtherDeviceChipViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/casttootherdevice/ui/viewmodel/CastToOtherDeviceChipViewModelTest.kt @@ -33,6 +33,7 @@ import com.android.systemui.statusbar.chips.casttootherdevice.ui.view.EndCastToO import com.android.systemui.statusbar.chips.mediaprojection.domain.interactor.MediaProjectionChipInteractorTest.Companion.CAST_TO_OTHER_DEVICES_PACKAGE import com.android.systemui.statusbar.chips.mediaprojection.domain.interactor.MediaProjectionChipInteractorTest.Companion.NORMAL_PACKAGE import com.android.systemui.statusbar.chips.mediaprojection.domain.interactor.MediaProjectionChipInteractorTest.Companion.setUpPackageManagerForMediaProjection +import com.android.systemui.statusbar.chips.ui.model.ColorsModel import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel import com.android.systemui.statusbar.chips.ui.view.ChipBackgroundContainer import com.android.systemui.statusbar.phone.SystemUIDialog @@ -119,6 +120,17 @@ class CastToOtherDeviceChipViewModelTest : SysuiTestCase() { } @Test + fun chip_colorsAreRed() = + testScope.runTest { + val latest by collectLastValue(underTest.chip) + + mediaProjectionRepo.mediaProjectionState.value = + MediaProjectionState.Projecting.EntireScreen(CAST_TO_OTHER_DEVICES_PACKAGE) + + assertThat((latest as OngoingActivityChipModel.Shown).colors).isEqualTo(ColorsModel.Red) + } + + @Test fun chip_singleTaskState_normalPackage_isHidden() = testScope.runTest { val latest by collectLastValue(underTest.chip) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/screenrecord/ui/viewmodel/ScreenRecordChipViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/screenrecord/ui/viewmodel/ScreenRecordChipViewModelTest.kt index 45044f74e864..fdf0e5d1f74f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/screenrecord/ui/viewmodel/ScreenRecordChipViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/screenrecord/ui/viewmodel/ScreenRecordChipViewModelTest.kt @@ -32,6 +32,7 @@ import com.android.systemui.res.R import com.android.systemui.screenrecord.data.model.ScreenRecordModel import com.android.systemui.screenrecord.data.repository.screenRecordRepository import com.android.systemui.statusbar.chips.screenrecord.ui.view.EndScreenRecordingDialogDelegate +import com.android.systemui.statusbar.chips.ui.model.ColorsModel import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel import com.android.systemui.statusbar.chips.ui.view.ChipBackgroundContainer import com.android.systemui.statusbar.phone.SystemUIDialog @@ -109,6 +110,16 @@ class ScreenRecordChipViewModelTest : SysuiTestCase() { } @Test + fun chip_colorsAreRed() = + testScope.runTest { + val latest by collectLastValue(underTest.chip) + + screenRecordRepo.screenRecordState.value = ScreenRecordModel.Recording + + assertThat((latest as OngoingActivityChipModel.Shown).colors).isEqualTo(ColorsModel.Red) + } + + @Test fun chip_timeResetsOnEachNewRecording() = testScope.runTest { val latest by collectLastValue(underTest.chip) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/sharetoapp/ui/viewmodel/ShareToAppChipViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/sharetoapp/ui/viewmodel/ShareToAppChipViewModelTest.kt index 9aef526932df..8ea3f4aae46c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/sharetoapp/ui/viewmodel/ShareToAppChipViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/chips/sharetoapp/ui/viewmodel/ShareToAppChipViewModelTest.kt @@ -33,6 +33,7 @@ import com.android.systemui.statusbar.chips.mediaprojection.domain.interactor.Me import com.android.systemui.statusbar.chips.mediaprojection.domain.interactor.MediaProjectionChipInteractorTest.Companion.NORMAL_PACKAGE import com.android.systemui.statusbar.chips.mediaprojection.domain.interactor.MediaProjectionChipInteractorTest.Companion.setUpPackageManagerForMediaProjection import com.android.systemui.statusbar.chips.sharetoapp.ui.view.EndShareToAppDialogDelegate +import com.android.systemui.statusbar.chips.ui.model.ColorsModel import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel import com.android.systemui.statusbar.chips.ui.view.ChipBackgroundContainer import com.android.systemui.statusbar.phone.SystemUIDialog @@ -144,6 +145,17 @@ class ShareToAppChipViewModelTest : SysuiTestCase() { } @Test + fun chip_colorsAreRed() = + testScope.runTest { + val latest by collectLastValue(underTest.chip) + + mediaProjectionRepo.mediaProjectionState.value = + MediaProjectionState.Projecting.EntireScreen(NORMAL_PACKAGE) + + assertThat((latest as OngoingActivityChipModel.Shown).colors).isEqualTo(ColorsModel.Red) + } + + @Test fun chip_timeResetsOnEachNewShare() = testScope.runTest { val latest by collectLastValue(underTest.chip) |