diff --git a/packages/SystemUI/res/layout/controls_base_item.xml b/packages/SystemUI/res/layout/controls_base_item.xml index c58f572e1bbbc..7708b8e9db6c8 100644 --- a/packages/SystemUI/res/layout/controls_base_item.xml +++ b/packages/SystemUI/res/layout/controls_base_item.xml @@ -71,6 +71,8 @@ android:paddingRight="@dimen/control_padding_adjustment" android:clickable="false" android:focusable="false" + android:maxLines="1" + android:ellipsize="end" app:layout_constraintBottom_toTopOf="@+id/subtitle" app:layout_constraintStart_toStartOf="parent" /> @@ -84,6 +86,8 @@ android:paddingBottom="@dimen/control_padding_adjustment" android:clickable="false" android:focusable="false" + android:maxLines="1" + android:ellipsize="end" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent"/> diff --git a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlInfo.kt b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlInfo.kt index 6f2af1bda45c2..6e59ac162657d 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlInfo.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlInfo.kt @@ -27,11 +27,13 @@ import android.service.controls.DeviceTypes * * @property controlId unique identifier for this [Control]. * @property controlTitle last title reported for this [Control]. + * @property controlSubtitle last subtitle reported for this [Control]. * @property deviceType last reported type for this [Control]. */ data class ControlInfo( val controlId: String, val controlTitle: CharSequence, + val controlSubtitle: CharSequence, @DeviceTypes.DeviceType val deviceType: Int ) { @@ -51,8 +53,9 @@ data class ControlInfo( class Builder { lateinit var controlId: String lateinit var controlTitle: CharSequence + lateinit var controlSubtitle: CharSequence var deviceType: Int = DeviceTypes.TYPE_UNKNOWN - fun build() = ControlInfo(controlId, controlTitle, deviceType) + fun build() = ControlInfo(controlId, controlTitle, controlSubtitle, deviceType) } } diff --git a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt index 2e34ea55ebe42..6c49c82acdc0f 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt @@ -327,8 +327,9 @@ class ControlsControllerImpl @Inject constructor ( controls.forEach { val structure = it.structure ?: "" val list = structureToControls.get(structure) - ?: mutableListOf() - list.add(ControlInfo(it.controlId, it.title, it.deviceType)) + ?: mutableListOf() + list.add( + ControlInfo(it.controlId, it.title, it.subtitle, it.deviceType)) structureToControls.put(structure, list) } @@ -518,10 +519,12 @@ private object Favorites { s.controls.forEach { c -> val (sName, ci) = controlsById.get(c.controlId)?.let { updatedControl -> val controlInfo = if (updatedControl.title != c.controlTitle || + updatedControl.subtitle != c.controlSubtitle || updatedControl.deviceType != c.deviceType) { changed = true c.copy( controlTitle = updatedControl.title, + controlSubtitle = updatedControl.subtitle, deviceType = updatedControl.deviceType ) } else { c } diff --git a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapper.kt b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapper.kt index 4bea6ef3d7b9a..afd82e7fcf78b 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapper.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapper.kt @@ -51,6 +51,7 @@ class ControlsFavoritePersistenceWrapper( private const val TAG_COMPONENT = "component" private const val TAG_ID = "id" private const val TAG_TITLE = "title" + private const val TAG_SUBTITLE = "subtitle" private const val TAG_TYPE = "type" private const val TAG_VERSION = "version" @@ -102,6 +103,7 @@ class ControlsFavoritePersistenceWrapper( startTag(null, TAG_CONTROL) attribute(null, TAG_ID, c.controlId) attribute(null, TAG_TITLE, c.controlTitle.toString()) + attribute(null, TAG_SUBTITLE, c.controlSubtitle.toString()) attribute(null, TAG_TYPE, c.deviceType.toString()) endTag(null, TAG_CONTROL) } @@ -168,9 +170,10 @@ class ControlsFavoritePersistenceWrapper( } else if (type == XmlPullParser.START_TAG && tagName == TAG_CONTROL) { val id = parser.getAttributeValue(null, TAG_ID) val title = parser.getAttributeValue(null, TAG_TITLE) + val subtitle = parser.getAttributeValue(null, TAG_SUBTITLE) ?: "" val deviceType = parser.getAttributeValue(null, TAG_TYPE)?.toInt() if (id != null && title != null && deviceType != null) { - controls.add(ControlInfo(id, title, deviceType)) + controls.add(ControlInfo(id, title, subtitle, deviceType)) } } else if (type == XmlPullParser.END_TAG && tagName == TAG_STRUCTURE) { infos.add(StructureInfo(lastComponent!!, lastStructure!!, controls.toList())) diff --git a/packages/SystemUI/src/com/android/systemui/controls/management/AllModel.kt b/packages/SystemUI/src/com/android/systemui/controls/management/AllModel.kt index 01f906958fc11..3fd583fa7481c 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/management/AllModel.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/management/AllModel.kt @@ -51,6 +51,7 @@ class AllModel( ControlInfo.Builder().apply { controlId = it.controlId controlTitle = it.title + controlSubtitle = it.subtitle deviceType = it.deviceType } } @@ -120,4 +121,4 @@ class AllModel( return removed } } -} \ No newline at end of file +} diff --git a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsRequestDialog.kt b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsRequestDialog.kt index 74a6c87d754b2..9b8c036659cd4 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsRequestDialog.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsRequestDialog.kt @@ -169,8 +169,11 @@ class ControlsRequestDialog @Inject constructor( override fun onClick(dialog: DialogInterface?, which: Int) { if (which == Dialog.BUTTON_POSITIVE) { - controller.addFavorite(componentName, control.structure ?: "", - ControlInfo(control.controlId, control.title, control.deviceType)) + controller.addFavorite( + componentName, + control.structure ?: "", + ControlInfo(control.controlId, control.title, control.subtitle, control.deviceType) + ) } finish() } diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt index b4392067d9532..9f5dd02b45148 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt @@ -77,7 +77,7 @@ class ControlViewHolder( Pair(it.getStatus(), it.getControlTemplate()) } ?: run { title.setText(cws.ci.controlTitle) - subtitle.setText("") + subtitle.setText(cws.ci.controlSubtitle) Pair(Control.STATUS_UNKNOWN, ControlTemplate.NO_TEMPLATE) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsBindingControllerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsBindingControllerImplTest.kt index 2ff2b2a4eac76..88316f2d43238 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsBindingControllerImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsBindingControllerImplTest.kt @@ -266,8 +266,8 @@ class ControlsBindingControllerImplTest : SysuiTestCase() { @Test fun testSubscribe() { - val controlInfo1 = ControlInfo("id_1", "", DeviceTypes.TYPE_UNKNOWN) - val controlInfo2 = ControlInfo("id_2", "", DeviceTypes.TYPE_UNKNOWN) + val controlInfo1 = ControlInfo("id_1", "", "", DeviceTypes.TYPE_UNKNOWN) + val controlInfo2 = ControlInfo("id_2", "", "", DeviceTypes.TYPE_UNKNOWN) val structure = StructureInfo(TEST_COMPONENT_NAME_1, "Home", listOf(controlInfo1, controlInfo2)) @@ -296,8 +296,8 @@ class ControlsBindingControllerImplTest : SysuiTestCase() { @Test fun testUnsubscribe_refreshing() { - val controlInfo1 = ControlInfo("id_1", "", DeviceTypes.TYPE_UNKNOWN) - val controlInfo2 = ControlInfo("id_2", "", DeviceTypes.TYPE_UNKNOWN) + val controlInfo1 = ControlInfo("id_1", "", "", DeviceTypes.TYPE_UNKNOWN) + val controlInfo2 = ControlInfo("id_2", "", "", DeviceTypes.TYPE_UNKNOWN) val structure = StructureInfo(TEST_COMPONENT_NAME_1, "Home", listOf(controlInfo1, controlInfo2)) diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsControllerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsControllerImplTest.kt index 971d14ceafbf2..d5a654dc2b6f1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsControllerImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsControllerImplTest.kt @@ -104,20 +104,22 @@ class ControlsControllerImplTest : SysuiTestCase() { private val TEST_COMPONENT = ComponentName("test.pkg", "test.class") private const val TEST_CONTROL_ID = "control1" private const val TEST_CONTROL_TITLE = "Test" + private const val TEST_CONTROL_SUBTITLE = "TestSub" private const val TEST_DEVICE_TYPE = DeviceTypes.TYPE_AC_HEATER private const val TEST_STRUCTURE = "" private val TEST_CONTROL_INFO = ControlInfo(TEST_CONTROL_ID, - TEST_CONTROL_TITLE, TEST_DEVICE_TYPE) + TEST_CONTROL_TITLE, TEST_CONTROL_SUBTITLE, TEST_DEVICE_TYPE) private val TEST_STRUCTURE_INFO = StructureInfo(TEST_COMPONENT, TEST_STRUCTURE, listOf(TEST_CONTROL_INFO)) private val TEST_COMPONENT_2 = ComponentName("test.pkg", "test.class.2") private const val TEST_CONTROL_ID_2 = "control2" private const val TEST_CONTROL_TITLE_2 = "Test 2" + private const val TEST_CONTROL_SUBTITLE_2 = "TestSub 2" private const val TEST_DEVICE_TYPE_2 = DeviceTypes.TYPE_CAMERA private const val TEST_STRUCTURE_2 = "My House" private val TEST_CONTROL_INFO_2 = ControlInfo(TEST_CONTROL_ID_2, - TEST_CONTROL_TITLE_2, TEST_DEVICE_TYPE_2) + TEST_CONTROL_TITLE_2, TEST_CONTROL_SUBTITLE_2, TEST_DEVICE_TYPE_2) private val TEST_STRUCTURE_INFO_2 = StructureInfo(TEST_COMPONENT_2, TEST_STRUCTURE_2, listOf(TEST_CONTROL_INFO_2)) } @@ -165,7 +167,7 @@ class ControlsControllerImplTest : SysuiTestCase() { ): Control.StatelessBuilder { return Control.StatelessBuilder(controlInfo.controlId, pendingIntent) .setDeviceType(controlInfo.deviceType).setTitle(controlInfo.controlTitle) - .setStructure(structure) + .setSubtitle(controlInfo.controlSubtitle).setStructure(structure) } @Test @@ -585,7 +587,7 @@ class ControlsControllerImplTest : SysuiTestCase() { @Test fun testGetFavoritesForComponent_multipleInOrder() { - val controlInfo = ControlInfo("id", "title", 0) + val controlInfo = ControlInfo("id", "title", "subtitle", 0) controller.replaceFavoritesForStructure( StructureInfo( @@ -643,7 +645,7 @@ class ControlsControllerImplTest : SysuiTestCase() { @Test fun testReplaceFavoritesForStructure_oldFavoritesRemoved() { - val controlInfo = ControlInfo("id", "title", 0) + val controlInfo = ControlInfo("id", "title", "subtitle", 0) assertNotEquals(TEST_CONTROL_INFO, controlInfo) val newComponent = ComponentName("test.pkg", "test.class.3") @@ -669,7 +671,7 @@ class ControlsControllerImplTest : SysuiTestCase() { @Test fun testReplaceFavoritesForStructure_favoritesInOrder() { - val controlInfo = ControlInfo("id", "title", 0) + val controlInfo = ControlInfo("id", "title", "subtitle", 0) val listOrder1 = listOf(TEST_CONTROL_INFO, controlInfo) val structure1 = StructureInfo(TEST_COMPONENT, "Home", listOrder1) diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapperTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapperTest.kt index a47edf0602c70..4f6cbe11149a7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapperTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapperTest.kt @@ -59,7 +59,7 @@ class ControlsFavoritePersistenceWrapperTest : SysuiTestCase() { ComponentName.unflattenFromString("TEST_PKG/.TEST_CLS_1")!!, "", listOf( - ControlInfo("id1", "name_1", DeviceTypes.TYPE_UNKNOWN) + ControlInfo("id1", "name_1", "", DeviceTypes.TYPE_UNKNOWN) ) ) @@ -67,8 +67,8 @@ class ControlsFavoritePersistenceWrapperTest : SysuiTestCase() { ComponentName.unflattenFromString("TEST_PKG/.TEST_CLS_2")!!, "structure1", listOf( - ControlInfo("id2", "name_2", DeviceTypes.TYPE_GENERIC_ON_OFF), - ControlInfo("id3", "name_3", DeviceTypes.TYPE_GENERIC_ON_OFF) + ControlInfo("id2", "name_2", "sub2", DeviceTypes.TYPE_GENERIC_ON_OFF), + ControlInfo("id3", "name_3", "sub3", DeviceTypes.TYPE_GENERIC_ON_OFF) ) ) val list = listOf(structureInfo1, structureInfo2) diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/management/AllModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/management/AllModelTest.kt index 133df2aa203f1..9adab5d2369f1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/controls/management/AllModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/controls/management/AllModelTest.kt @@ -116,6 +116,7 @@ class AllModelTest : SysuiTestCase() { private fun sameControl(controlInfo: ControlInfo.Builder, control: Control): Boolean { return controlInfo.controlId == control.controlId && controlInfo.controlTitle == control.title && + controlInfo.controlSubtitle == control.subtitle && controlInfo.deviceType == control.deviceType }