summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chelsea Hao <chelseahao@google.com> 2024-08-13 03:24:20 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-08-13 03:24:20 +0000
commit5a99de071a9895783a112edfaf6b83183ae01ff6 (patch)
tree7bbd792c166278902bca6d5ec765fad79b215b0f
parent919147186819423ef4fd088fa9c7f546ae5a4b88 (diff)
parentb36d91d1279e338d291594eec38ab53318657a85 (diff)
Merge "Highlight audio sharing button when audio sharing is on." into main
-rw-r--r--packages/SystemUI/res/color/audio_sharing_btn_text_color.xml21
-rw-r--r--packages/SystemUI/res/drawable/audio_sharing_btn_background.xml21
-rw-r--r--packages/SystemUI/res/layout/bluetooth_tile_dialog.xml3
-rw-r--r--packages/SystemUI/res/values/styles.xml6
-rw-r--r--packages/SystemUI/src/com/android/systemui/bluetooth/qsdialog/AudioSharingInteractor.kt10
-rw-r--r--packages/SystemUI/src/com/android/systemui/bluetooth/qsdialog/BluetoothTileDialogDelegate.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/bluetooth/qsdialog/BluetoothTileDialogViewModel.kt32
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/bluetooth/qsdialog/AudioSharingInteractorTest.kt6
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/bluetooth/qsdialog/BluetoothTileDialogDelegateTest.kt66
9 files changed, 151 insertions, 18 deletions
diff --git a/packages/SystemUI/res/color/audio_sharing_btn_text_color.xml b/packages/SystemUI/res/color/audio_sharing_btn_text_color.xml
new file mode 100644
index 000000000000..b72835e6475a
--- /dev/null
+++ b/packages/SystemUI/res/color/audio_sharing_btn_text_color.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ ~ 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.
+ -->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android" >
+ <item android:state_activated="true"
+ android:color="@color/qs_dialog_btn_filled_text_color" />
+ <item android:color="@color/qs_dialog_btn_outline_text" />
+</selector> \ No newline at end of file
diff --git a/packages/SystemUI/res/drawable/audio_sharing_btn_background.xml b/packages/SystemUI/res/drawable/audio_sharing_btn_background.xml
new file mode 100644
index 000000000000..310e095205a0
--- /dev/null
+++ b/packages/SystemUI/res/drawable/audio_sharing_btn_background.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ -->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_activated="true" android:drawable="@drawable/qs_dialog_btn_filled" />
+ <item android:drawable="@drawable/qs_dialog_btn_outline" />
+</selector> \ No newline at end of file
diff --git a/packages/SystemUI/res/layout/bluetooth_tile_dialog.xml b/packages/SystemUI/res/layout/bluetooth_tile_dialog.xml
index 27b80066e0f4..b4eaa407889a 100644
--- a/packages/SystemUI/res/layout/bluetooth_tile_dialog.xml
+++ b/packages/SystemUI/res/layout/bluetooth_tile_dialog.xml
@@ -258,7 +258,7 @@
<Button
android:id="@+id/audio_sharing_button"
- style="@style/Widget.Dialog.Button.BorderButton"
+ style="@style/BluetoothTileDialog.AudioSharingButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
@@ -270,7 +270,6 @@
android:text="@string/quick_settings_bluetooth_audio_sharing_button"
android:drawableStart="@drawable/ic_bt_le_audio_sharing_18dp"
android:drawablePadding="10dp"
- android:drawableTint="?android:attr/textColorPrimary"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintEnd_toStartOf="@+id/done_button"
diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml
index 7fa70881acd9..3ef624365594 100644
--- a/packages/SystemUI/res/values/styles.xml
+++ b/packages/SystemUI/res/values/styles.xml
@@ -1455,6 +1455,12 @@
<item name="android:textColor">?androidprv:attr/materialColorOnPrimaryContainer</item>
</style>
+ <style name="BluetoothTileDialog.AudioSharingButton" parent="Widget.Dialog.Button">
+ <item name="android:background">@drawable/audio_sharing_btn_background</item>
+ <item name="android:textColor">@color/audio_sharing_btn_text_color</item>
+ <item name="android:drawableTint">@color/audio_sharing_btn_text_color</item>
+ </style>
+
<style name="BroadcastDialog">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
diff --git a/packages/SystemUI/src/com/android/systemui/bluetooth/qsdialog/AudioSharingInteractor.kt b/packages/SystemUI/src/com/android/systemui/bluetooth/qsdialog/AudioSharingInteractor.kt
index e44f0543fc87..817f2d7f6f70 100644
--- a/packages/SystemUI/src/com/android/systemui/bluetooth/qsdialog/AudioSharingInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/bluetooth/qsdialog/AudioSharingInteractor.kt
@@ -34,7 +34,9 @@ import kotlinx.coroutines.flow.stateIn
internal sealed class AudioSharingButtonState {
object Gone : AudioSharingButtonState()
- data class Visible(@StringRes val resId: Int) : AudioSharingButtonState()
+
+ data class Visible(@StringRes val resId: Int, val isActive: Boolean) :
+ AudioSharingButtonState()
}
/** Holds business logic for the audio sharing state. */
@@ -73,7 +75,8 @@ constructor(
// Show sharing audio when broadcasting
BluetoothUtils.isBroadcasting(localBluetoothManager) ->
AudioSharingButtonState.Visible(
- R.string.quick_settings_bluetooth_audio_sharing_button_sharing
+ R.string.quick_settings_bluetooth_audio_sharing_button_sharing,
+ isActive = true
)
// When not broadcasting, don't show button if there's connected source in any device
deviceItem.any {
@@ -85,7 +88,8 @@ constructor(
// Show audio sharing when there's a connected LE audio device
deviceItem.any { BluetoothUtils.isActiveLeAudioDevice(it.cachedBluetoothDevice) } ->
AudioSharingButtonState.Visible(
- R.string.quick_settings_bluetooth_audio_sharing_button
+ R.string.quick_settings_bluetooth_audio_sharing_button,
+ isActive = false
)
else -> AudioSharingButtonState.Gone
}
diff --git a/packages/SystemUI/src/com/android/systemui/bluetooth/qsdialog/BluetoothTileDialogDelegate.kt b/packages/SystemUI/src/com/android/systemui/bluetooth/qsdialog/BluetoothTileDialogDelegate.kt
index f5b9a050f33e..d90b82c9a003 100644
--- a/packages/SystemUI/src/com/android/systemui/bluetooth/qsdialog/BluetoothTileDialogDelegate.kt
+++ b/packages/SystemUI/src/com/android/systemui/bluetooth/qsdialog/BluetoothTileDialogDelegate.kt
@@ -212,11 +212,13 @@ internal constructor(
internal fun onAudioSharingButtonUpdated(
dialog: SystemUIDialog,
visibility: Int,
- label: String?
+ label: String?,
+ isActive: Boolean
) {
getAudioSharingButtonView(dialog).apply {
this.visibility = visibility
label?.let { text = it }
+ this.isActivated = isActive
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/bluetooth/qsdialog/BluetoothTileDialogViewModel.kt b/packages/SystemUI/src/com/android/systemui/bluetooth/qsdialog/BluetoothTileDialogViewModel.kt
index eaddc42dcd5a..985b1588807b 100644
--- a/packages/SystemUI/src/com/android/systemui/bluetooth/qsdialog/BluetoothTileDialogViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/bluetooth/qsdialog/BluetoothTileDialogViewModel.kt
@@ -104,8 +104,7 @@ constructor(
)
controller?.let {
dialogTransitionAnimator.show(dialog, it, animateBackgroundBoundsChange = true)
- }
- ?: dialog.show()
+ } ?: dialog.show()
updateDeviceItemJob = launch {
deviceItemInteractor.updateDeviceItems(context, DeviceFetchTrigger.FIRST_LOAD)
@@ -149,14 +148,23 @@ constructor(
if (BluetoothUtils.isAudioSharingEnabled()) {
audioSharingInteractor.audioSharingButtonStateUpdate
.onEach {
- if (it is AudioSharingButtonState.Visible) {
- dialogDelegate.onAudioSharingButtonUpdated(
- dialog,
- VISIBLE,
- context.getString(it.resId)
- )
- } else {
- dialogDelegate.onAudioSharingButtonUpdated(dialog, GONE, null)
+ when (it) {
+ is AudioSharingButtonState.Visible -> {
+ dialogDelegate.onAudioSharingButtonUpdated(
+ dialog,
+ VISIBLE,
+ context.getString(it.resId),
+ it.isActive
+ )
+ }
+ is AudioSharingButtonState.Gone -> {
+ dialogDelegate.onAudioSharingButtonUpdated(
+ dialog,
+ GONE,
+ label = null,
+ isActive = false
+ )
+ }
}
}
.launchIn(this)
@@ -305,6 +313,7 @@ constructor(
companion object {
private const val INTERACTION_JANK_TAG = "bluetooth_tile_dialog"
private const val CONTENT_HEIGHT_PREF_KEY = Prefs.Key.BLUETOOTH_TILE_DIALOG_CONTENT_HEIGHT
+
private fun getSubtitleResId(isBluetoothEnabled: Boolean) =
if (isBluetoothEnabled) R.string.quick_settings_bluetooth_tile_subtitle
else R.string.bt_is_off
@@ -336,7 +345,10 @@ constructor(
interface BluetoothTileDialogCallback {
fun onDeviceItemGearClicked(deviceItem: DeviceItem, view: View)
+
fun onSeeAllClicked(view: View)
+
fun onPairNewDeviceClicked(view: View)
+
fun onAudioSharingButtonClicked(view: View)
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/bluetooth/qsdialog/AudioSharingInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/bluetooth/qsdialog/AudioSharingInteractorTest.kt
index 4d7c49973605..2c53fd67c89d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/bluetooth/qsdialog/AudioSharingInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/bluetooth/qsdialog/AudioSharingInteractorTest.kt
@@ -113,7 +113,8 @@ class AudioSharingInteractorTest : SysuiTestCase() {
assertThat(actual)
.isEqualTo(
AudioSharingButtonState.Visible(
- R.string.quick_settings_bluetooth_audio_sharing_button_sharing
+ R.string.quick_settings_bluetooth_audio_sharing_button_sharing,
+ isActive = true
)
)
}
@@ -163,7 +164,8 @@ class AudioSharingInteractorTest : SysuiTestCase() {
assertThat(actual)
.isEqualTo(
AudioSharingButtonState.Visible(
- R.string.quick_settings_bluetooth_audio_sharing_button
+ R.string.quick_settings_bluetooth_audio_sharing_button,
+ isActive = false
)
)
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/bluetooth/qsdialog/BluetoothTileDialogDelegateTest.kt b/packages/SystemUI/tests/src/com/android/systemui/bluetooth/qsdialog/BluetoothTileDialogDelegateTest.kt
index d01fac36230e..fb0fd23fab24 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/bluetooth/qsdialog/BluetoothTileDialogDelegateTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/bluetooth/qsdialog/BluetoothTileDialogDelegateTest.kt
@@ -328,4 +328,70 @@ class BluetoothTileDialogDelegateTest : SysuiTestCase() {
dialog.dismiss()
}
}
+
+ @Test
+ fun testOnAudioSharingButtonUpdated_visibleActive_activateButton() {
+ testScope.runTest {
+ val dialog = mBluetoothTileDialogDelegate.createDialog()
+ dialog.show()
+ fakeSystemClock.setElapsedRealtime(Long.MAX_VALUE)
+ mBluetoothTileDialogDelegate.onAudioSharingButtonUpdated(
+ dialog,
+ visibility = VISIBLE,
+ label = null,
+ isActive = true
+ )
+
+ val audioSharingButton = dialog.requireViewById<View>(R.id.audio_sharing_button)
+
+ assertThat(audioSharingButton).isNotNull()
+ assertThat(audioSharingButton.visibility).isEqualTo(VISIBLE)
+ assertThat(audioSharingButton.isActivated).isTrue()
+ dialog.dismiss()
+ }
+ }
+
+ @Test
+ fun testOnAudioSharingButtonUpdated_visibleNotActive_inactivateButton() {
+ testScope.runTest {
+ val dialog = mBluetoothTileDialogDelegate.createDialog()
+ dialog.show()
+ fakeSystemClock.setElapsedRealtime(Long.MAX_VALUE)
+ mBluetoothTileDialogDelegate.onAudioSharingButtonUpdated(
+ dialog,
+ visibility = VISIBLE,
+ label = null,
+ isActive = false
+ )
+
+ val audioSharingButton = dialog.requireViewById<View>(R.id.audio_sharing_button)
+
+ assertThat(audioSharingButton).isNotNull()
+ assertThat(audioSharingButton.visibility).isEqualTo(VISIBLE)
+ assertThat(audioSharingButton.isActivated).isFalse()
+ dialog.dismiss()
+ }
+ }
+
+ @Test
+ fun testOnAudioSharingButtonUpdated_gone_inactivateButton() {
+ testScope.runTest {
+ val dialog = mBluetoothTileDialogDelegate.createDialog()
+ dialog.show()
+ fakeSystemClock.setElapsedRealtime(Long.MAX_VALUE)
+ mBluetoothTileDialogDelegate.onAudioSharingButtonUpdated(
+ dialog,
+ visibility = GONE,
+ label = null,
+ isActive = false
+ )
+
+ val audioSharingButton = dialog.requireViewById<View>(R.id.audio_sharing_button)
+
+ assertThat(audioSharingButton).isNotNull()
+ assertThat(audioSharingButton.visibility).isEqualTo(GONE)
+ assertThat(audioSharingButton.isActivated).isFalse()
+ dialog.dismiss()
+ }
+ }
}