Merge changes I07729e8b,I72601976 into tm-qpr-dev

* changes:
  [Media TTT] Animate in the receiver chip.
  [Media TTT] Move receiver chip to the bottom of the screen.
This commit is contained in:
TreeHugger Robot
2022-06-29 20:08:24 +00:00
committed by Android (Google) Code Review
6 changed files with 58 additions and 15 deletions

View File

@@ -14,20 +14,19 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!-- TODO(b/203800646): layout_marginTop doesn't seem to work on some large screens. -->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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"
>
<com.android.internal.widget.CachingIconView
android:id="@+id/app_icon"
android:layout_width="@dimen/media_ttt_icon_size_receiver"
android:layout_height="@dimen/media_ttt_icon_size_receiver"
android:layout_gravity="center"
android:layout_gravity="center|bottom"
android:alpha="0.0"
/>
</FrameLayout>

View File

@@ -1060,6 +1060,7 @@
<!-- Since the generic icon isn't circular, we need to scale it down so it still fits within
the circular chip. -->
<dimen name="media_ttt_generic_icon_size_receiver">70dp</dimen>
<dimen name="media_ttt_receiver_vert_translation">20dp</dimen>
<!-- Window magnification -->
<dimen name="magnification_border_drag_size">35dp</dimen>

View File

@@ -25,17 +25,14 @@ import android.graphics.drawable.Drawable
import android.os.PowerManager
import android.os.SystemClock
import android.util.Log
import android.view.Gravity
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.view.accessibility.AccessibilityManager
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_CONTROLS
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_ICONS
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_TEXT
import android.widget.LinearLayout
import com.android.internal.widget.CachingIconView
import com.android.settingslib.Utils
import com.android.systemui.R
@@ -65,12 +62,15 @@ abstract class MediaTttChipControllerCommon<T : ChipInfoCommon>(
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<T : ChipInfoCommon>(
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

View File

@@ -24,6 +24,8 @@ import android.media.MediaRoute2Info
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
@@ -36,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
@@ -69,6 +72,11 @@ class MediaTttChipControllerReceiver @Inject constructor(
powerManager,
R.layout.media_ttt_chip_receiver
) {
override val windowLayoutParams = commonWindowLayoutParams.apply {
height = getWindowHeight()
gravity = Gravity.BOTTOM.or(Gravity.CENTER_HORIZONTAL)
}
private val commandQueueCallbacks = object : CommandQueue.Callbacks {
override fun updateMediaTapToTransferReceiverDisplay(
@StatusBarManager.MediaTransferReceiverState displayState: Int,
@@ -131,6 +139,19 @@ class MediaTttChipControllerReceiver @Inject constructor(
)
}
override fun animateChipIn(chipView: ViewGroup) {
val appIconView = chipView.requireViewById<View>(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) {
@@ -139,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(

View File

@@ -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 {

View File

@@ -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
private const val ICON_SIZE = 47