From c652dad8f4520205dba1311ebbe80c458225293c Mon Sep 17 00:00:00 2001 From: Caitlin Cassidy Date: Tue, 21 Jun 2022 20:27:46 +0000 Subject: [PATCH 1/2] [Media TTT] Move receiver chip to the bottom of the screen. Fixes: 225897586 Test: manual (see screenshots in bug) Test: media.taptotransfer tests Change-Id: I726019760fa32450c5aa096a9ce2b2118859fd56 --- .../res/layout/media_ttt_chip_receiver.xml | 1 - .../common/MediaTttChipControllerCommon.kt | 20 +++++++++++++------ .../MediaTttChipControllerReceiver.kt | 6 ++++++ .../sender/MediaTttChipControllerSender.kt | 5 +++++ .../MediaTttChipControllerCommonTest.kt | 10 ++++------ 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/packages/SystemUI/res/layout/media_ttt_chip_receiver.xml b/packages/SystemUI/res/layout/media_ttt_chip_receiver.xml index 5e8b892018eb9..4c7cd294ad67e 100644 --- a/packages/SystemUI/res/layout/media_ttt_chip_receiver.xml +++ b/packages/SystemUI/res/layout/media_ttt_chip_receiver.xml @@ -14,7 +14,6 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> - ( private val powerManager: PowerManager, @LayoutRes private val chipLayoutRes: Int ) { - /** The window layout parameters we'll use when attaching the view to a window. */ + + /** + * Window layout params that will be used as a starting point for the [windowLayoutParams] of + * all subclasses. + */ @SuppressLint("WrongConstant") // We're allowed to use TYPE_VOLUME_OVERLAY - private val windowLayoutParams = WindowManager.LayoutParams().apply { + internal val commonWindowLayoutParams = WindowManager.LayoutParams().apply { width = WindowManager.LayoutParams.WRAP_CONTENT height = WindowManager.LayoutParams.WRAP_CONTENT - gravity = Gravity.TOP.or(Gravity.CENTER_HORIZONTAL) type = WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL title = WINDOW_TITLE @@ -78,6 +78,14 @@ abstract class MediaTttChipControllerCommon( setTrustedOverlay() } + /** + * The window layout parameters we'll use when attaching the view to a window. + * + * Subclasses must override this to provide their specific layout params, and they should use + * [commonWindowLayoutParams] as part of their layout params. + */ + internal abstract val windowLayoutParams: WindowManager.LayoutParams + /** The chip view currently being displayed. Null if the chip is not being displayed. */ private var chipView: ViewGroup? = null diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt index a5d763c5327bd..f6431c5d2a9ca 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt @@ -24,6 +24,7 @@ import android.media.MediaRoute2Info import android.os.Handler import android.os.PowerManager import android.util.Log +import android.view.Gravity import android.view.ViewGroup import android.view.WindowManager import android.view.accessibility.AccessibilityManager @@ -69,6 +70,11 @@ class MediaTttChipControllerReceiver @Inject constructor( powerManager, R.layout.media_ttt_chip_receiver ) { + override val windowLayoutParams = commonWindowLayoutParams.apply { + gravity = Gravity.BOTTOM.or(Gravity.CENTER_HORIZONTAL) + verticalMargin = 0.1f + } + private val commandQueueCallbacks = object : CommandQueue.Callbacks { override fun updateMediaTapToTransferReceiverDisplay( @StatusBarManager.MediaTransferReceiverState displayState: Int, diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttChipControllerSender.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttChipControllerSender.kt index 943604cff8879..797a7701413b6 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttChipControllerSender.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttChipControllerSender.kt @@ -21,6 +21,7 @@ import android.content.Context import android.media.MediaRoute2Info import android.os.PowerManager import android.util.Log +import android.view.Gravity import android.view.View import android.view.ViewGroup import android.view.WindowManager @@ -69,6 +70,10 @@ class MediaTttChipControllerSender @Inject constructor( powerManager, R.layout.media_ttt_chip ) { + override val windowLayoutParams = commonWindowLayoutParams.apply { + gravity = Gravity.TOP.or(Gravity.CENTER_HORIZONTAL) + } + private var currentlyDisplayedChipState: ChipStateSender? = null private val commandQueueCallbacks = object : CommandQueue.Callbacks { diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt index 1527f0d0d71f5..2eb478303cb2b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt @@ -371,11 +371,9 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() { powerManager, R.layout.media_ttt_chip ) { - override fun updateChipView(chipInfo: ChipInfo, currentChipView: ViewGroup) { - - } - - override fun getIconSize(isAppIcon: Boolean): Int? = ICON_SIZE + override val windowLayoutParams = commonWindowLayoutParams + override fun updateChipView(chipInfo: ChipInfo, currentChipView: ViewGroup) {} + override fun getIconSize(isAppIcon: Boolean): Int = ICON_SIZE } inner class ChipInfo : ChipInfoCommon { @@ -386,4 +384,4 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() { private const val PACKAGE_NAME = "com.android.systemui" private const val APP_NAME = "Fake App Name" private const val TIMEOUT_MS = 10000L -private const val ICON_SIZE = 47 \ No newline at end of file +private const val ICON_SIZE = 47 From 80432d00569975a2c66067e33bd0ccd6a3a0df32 Mon Sep 17 00:00:00 2001 From: Caitlin Cassidy Date: Tue, 21 Jun 2022 20:28:13 +0000 Subject: [PATCH 2/2] [Media TTT] Animate in the receiver chip. Bug: 203800342 Test: manual (see video attached to bug TODO) Change-Id: I07729e8be62fc36216e8a698393fa70c64c23a85 --- .../res/layout/media_ttt_chip_receiver.xml | 4 +-- packages/SystemUI/res/values/dimens.xml | 1 + .../MediaTttChipControllerReceiver.kt | 28 ++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/res/layout/media_ttt_chip_receiver.xml b/packages/SystemUI/res/layout/media_ttt_chip_receiver.xml index 4c7cd294ad67e..2b3d11b0e1912 100644 --- a/packages/SystemUI/res/layout/media_ttt_chip_receiver.xml +++ b/packages/SystemUI/res/layout/media_ttt_chip_receiver.xml @@ -19,14 +19,14 @@ android:id="@+id/media_ttt_receiver_chip" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:background="@drawable/media_ttt_chip_background_receiver" > diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 4d365412828ed..36a2d6469ec8d 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -1060,6 +1060,7 @@ 70dp + 20dp 35dp diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt index f6431c5d2a9ca..f9818f0ad8bee 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt @@ -25,6 +25,7 @@ import android.os.Handler import android.os.PowerManager import android.util.Log import android.view.Gravity +import android.view.View import android.view.ViewGroup import android.view.WindowManager import android.view.accessibility.AccessibilityManager @@ -37,6 +38,7 @@ import com.android.systemui.media.taptotransfer.common.MediaTttChipControllerCom import com.android.systemui.media.taptotransfer.common.MediaTttLogger import com.android.systemui.statusbar.CommandQueue import com.android.systemui.statusbar.gesture.TapGestureDetector +import com.android.systemui.util.animation.AnimationUtil.Companion.frames import com.android.systemui.util.concurrency.DelayableExecutor import com.android.systemui.util.view.ViewUtil import javax.inject.Inject @@ -71,8 +73,8 @@ class MediaTttChipControllerReceiver @Inject constructor( R.layout.media_ttt_chip_receiver ) { override val windowLayoutParams = commonWindowLayoutParams.apply { + height = getWindowHeight() gravity = Gravity.BOTTOM.or(Gravity.CENTER_HORIZONTAL) - verticalMargin = 0.1f } private val commandQueueCallbacks = object : CommandQueue.Callbacks { @@ -137,6 +139,19 @@ class MediaTttChipControllerReceiver @Inject constructor( ) } + override fun animateChipIn(chipView: ViewGroup) { + val appIconView = chipView.requireViewById(R.id.app_icon) + appIconView.animate() + .translationYBy(-1 * getTranslationAmount().toFloat()) + .setDuration(30.frames) + .start() + appIconView.animate() + .alpha(1f) + .setDuration(5.frames) + .start() + + } + override fun getIconSize(isAppIcon: Boolean): Int? = context.resources.getDimensionPixelSize( if (isAppIcon) { @@ -145,6 +160,17 @@ class MediaTttChipControllerReceiver @Inject constructor( R.dimen.media_ttt_generic_icon_size_receiver } ) + + private fun getWindowHeight(): Int { + return context.resources.getDimensionPixelSize(R.dimen.media_ttt_icon_size_receiver) + + // Make the window large enough to accommodate the animation amount + getTranslationAmount() + } + + /** Returns the amount that the chip will be translated by in its intro animation. */ + private fun getTranslationAmount(): Int { + return context.resources.getDimensionPixelSize(R.dimen.media_ttt_receiver_vert_translation) + } } data class ChipReceiverInfo(