diff --git a/packages/SystemUI/res/drawable/media_ttt_undo_background.xml b/packages/SystemUI/res/drawable/media_ttt_undo_background.xml new file mode 100644 index 0000000000000..ec74ee1fcbf17 --- /dev/null +++ b/packages/SystemUI/res/drawable/media_ttt_undo_background.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/packages/SystemUI/res/layout/media_ttt_chip.xml b/packages/SystemUI/res/layout/media_ttt_chip.xml index 2fe55477af967..6fbc41c7e20d8 100644 --- a/packages/SystemUI/res/layout/media_ttt_chip.xml +++ b/packages/SystemUI/res/layout/media_ttt_chip.xml @@ -44,4 +44,21 @@ style="?android:attr/progressBarStyleSmall" /> + + diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index a09f94d872acc..0b562644434f4 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -980,6 +980,8 @@ 16dp 16sp 16dp + 8dp + -8dp 35dp diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/MediaTttChipController.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/MediaTttChipController.kt index e733ff1c88004..af8fc0e3c7f9a 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/MediaTttChipController.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/MediaTttChipController.kt @@ -84,6 +84,11 @@ class MediaTttChipController @Inject constructor( currentChipView.requireViewById(R.id.loading).visibility = if (showLoading) { View.VISIBLE } else { View.GONE } + // Undo + val showUndo = chipType == ChipType.TRANSFER_SUCCEEDED + currentChipView.requireViewById(R.id.undo).visibility = + if (showUndo) { View.VISIBLE } else { View.GONE } + if (oldChipView == null) { windowManager.addView(chipView, windowLayoutParams) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/MediaTttChipControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/MediaTttChipControllerTest.kt index f5a4649d30744..923f018f8bcdc 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/MediaTttChipControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/MediaTttChipControllerTest.kt @@ -110,30 +110,33 @@ class MediaTttChipControllerTest : SysuiTestCase() { } @Test - fun moveCloserToTransfer_chipTextContainsDeviceName_noLoadingIcon() { + fun moveCloserToTransfer_chipTextContainsDeviceName_noLoadingIcon_noUndo() { commandRegistry.onShellCommand(pw, getMoveCloserToTransferCommand()) val chipView = getChipView() assertThat(chipView.getChipText()).contains(DEVICE_NAME) assertThat(chipView.getLoadingIconVisibility()).isEqualTo(View.GONE) + assertThat(chipView.getUndoButtonVisibility()).isEqualTo(View.GONE) } @Test - fun transferInitiated_chipTextContainsDeviceName_loadingIcon() { + fun transferInitiated_chipTextContainsDeviceName_loadingIcon_noUndo() { commandRegistry.onShellCommand(pw, getTransferInitiatedCommand()) val chipView = getChipView() assertThat(chipView.getChipText()).contains(DEVICE_NAME) assertThat(chipView.getLoadingIconVisibility()).isEqualTo(View.VISIBLE) + assertThat(chipView.getUndoButtonVisibility()).isEqualTo(View.GONE) } @Test - fun transferSucceeded_chipTextContainsDeviceName_noLoadingIcon() { + fun transferSucceeded_chipTextContainsDeviceName_noLoadingIcon_undo() { commandRegistry.onShellCommand(pw, getTransferSucceededCommand()) val chipView = getChipView() assertThat(chipView.getChipText()).contains(DEVICE_NAME) assertThat(chipView.getLoadingIconVisibility()).isEqualTo(View.GONE) + assertThat(chipView.getUndoButtonVisibility()).isEqualTo(View.VISIBLE) } @Test @@ -152,6 +155,22 @@ class MediaTttChipControllerTest : SysuiTestCase() { assertThat(getChipView().getLoadingIconVisibility()).isEqualTo(View.GONE) } + @Test + fun changeFromTransferInitiatedToTransferSucceeded_undoButtonAppears() { + commandRegistry.onShellCommand(pw, getTransferInitiatedCommand()) + commandRegistry.onShellCommand(pw, getTransferSucceededCommand()) + + assertThat(getChipView().getUndoButtonVisibility()).isEqualTo(View.VISIBLE) + } + + @Test + fun changeFromTransferSucceededToMoveCloser_undoButtonDisappears() { + commandRegistry.onShellCommand(pw, getTransferSucceededCommand()) + commandRegistry.onShellCommand(pw, getMoveCloserToTransferCommand()) + + assertThat(getChipView().getUndoButtonVisibility()).isEqualTo(View.GONE) + } + private fun getMoveCloserToTransferCommand(): Array = arrayOf( MediaTttChipController.ADD_CHIP_COMMAND_TAG, @@ -179,6 +198,9 @@ class MediaTttChipControllerTest : SysuiTestCase() { private fun LinearLayout.getLoadingIconVisibility(): Int = this.requireViewById(R.id.loading).visibility + private fun LinearLayout.getUndoButtonVisibility(): Int = + this.requireViewById(R.id.undo).visibility + private fun getChipView(): LinearLayout { val viewCaptor = ArgumentCaptor.forClass(View::class.java) verify(windowManager).addView(viewCaptor.capture(), any())