Merge "[Media TTT] Re-display the chip when the density/font changes." into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2b94054351
@@ -33,11 +33,13 @@ import android.view.accessibility.AccessibilityManager
|
|||||||
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_CONTROLS
|
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_CONTROLS
|
||||||
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_ICONS
|
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_ICONS
|
||||||
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_TEXT
|
import android.view.accessibility.AccessibilityManager.FLAG_CONTENT_TEXT
|
||||||
|
import androidx.annotation.CallSuper
|
||||||
import com.android.internal.widget.CachingIconView
|
import com.android.internal.widget.CachingIconView
|
||||||
import com.android.settingslib.Utils
|
import com.android.settingslib.Utils
|
||||||
import com.android.systemui.R
|
import com.android.systemui.R
|
||||||
import com.android.systemui.dagger.qualifiers.Main
|
import com.android.systemui.dagger.qualifiers.Main
|
||||||
import com.android.systemui.statusbar.gesture.TapGestureDetector
|
import com.android.systemui.statusbar.gesture.TapGestureDetector
|
||||||
|
import com.android.systemui.statusbar.policy.ConfigurationController
|
||||||
import com.android.systemui.util.concurrency.DelayableExecutor
|
import com.android.systemui.util.concurrency.DelayableExecutor
|
||||||
import com.android.systemui.util.view.ViewUtil
|
import com.android.systemui.util.view.ViewUtil
|
||||||
|
|
||||||
@@ -52,17 +54,17 @@ import com.android.systemui.util.view.ViewUtil
|
|||||||
* display the chip in a certain state, since they receive <T> in [updateChipView].
|
* display the chip in a certain state, since they receive <T> in [updateChipView].
|
||||||
*/
|
*/
|
||||||
abstract class MediaTttChipControllerCommon<T : ChipInfoCommon>(
|
abstract class MediaTttChipControllerCommon<T : ChipInfoCommon>(
|
||||||
internal val context: Context,
|
internal val context: Context,
|
||||||
internal val logger: MediaTttLogger,
|
internal val logger: MediaTttLogger,
|
||||||
internal val windowManager: WindowManager,
|
internal val windowManager: WindowManager,
|
||||||
private val viewUtil: ViewUtil,
|
private val viewUtil: ViewUtil,
|
||||||
@Main private val mainExecutor: DelayableExecutor,
|
@Main private val mainExecutor: DelayableExecutor,
|
||||||
private val accessibilityManager: AccessibilityManager,
|
private val accessibilityManager: AccessibilityManager,
|
||||||
private val tapGestureDetector: TapGestureDetector,
|
private val configurationController: ConfigurationController,
|
||||||
private val powerManager: PowerManager,
|
private val tapGestureDetector: TapGestureDetector,
|
||||||
@LayoutRes private val chipLayoutRes: Int
|
private val powerManager: PowerManager,
|
||||||
|
@LayoutRes private val chipLayoutRes: Int,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Window layout params that will be used as a starting point for the [windowLayoutParams] of
|
* Window layout params that will be used as a starting point for the [windowLayoutParams] of
|
||||||
* all subclasses.
|
* all subclasses.
|
||||||
@@ -89,42 +91,40 @@ abstract class MediaTttChipControllerCommon<T : ChipInfoCommon>(
|
|||||||
/** The chip view currently being displayed. Null if the chip is not being displayed. */
|
/** The chip view currently being displayed. Null if the chip is not being displayed. */
|
||||||
private var chipView: ViewGroup? = null
|
private var chipView: ViewGroup? = null
|
||||||
|
|
||||||
|
/** The chip info currently being displayed. Null if the chip is not being displayed. */
|
||||||
|
internal var chipInfo: T? = null
|
||||||
|
|
||||||
/** A [Runnable] that, when run, will cancel the pending timeout of the chip. */
|
/** A [Runnable] that, when run, will cancel the pending timeout of the chip. */
|
||||||
private var cancelChipViewTimeout: Runnable? = null
|
private var cancelChipViewTimeout: Runnable? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the chip with the current state.
|
* Displays the chip with the provided [newChipInfo].
|
||||||
*
|
*
|
||||||
* This method handles inflating and attaching the view, then delegates to [updateChipView] to
|
* This method handles inflating and attaching the view, then delegates to [updateChipView] to
|
||||||
* display the correct information in the chip.
|
* display the correct information in the chip.
|
||||||
*/
|
*/
|
||||||
fun displayChip(chipInfo: T) {
|
fun displayChip(newChipInfo: T) {
|
||||||
val oldChipView = chipView
|
val currentChipView = chipView
|
||||||
if (chipView == null) {
|
|
||||||
chipView = LayoutInflater
|
|
||||||
.from(context)
|
|
||||||
.inflate(chipLayoutRes, null) as ViewGroup
|
|
||||||
}
|
|
||||||
val currentChipView = chipView!!
|
|
||||||
|
|
||||||
updateChipView(chipInfo, currentChipView)
|
if (currentChipView != null) {
|
||||||
|
updateChipView(newChipInfo, currentChipView)
|
||||||
// Add view if necessary
|
} else {
|
||||||
if (oldChipView == null) {
|
// The chip is new, so set up all our callbacks and inflate the view
|
||||||
|
configurationController.addCallback(displayScaleListener)
|
||||||
tapGestureDetector.addOnGestureDetectedCallback(TAG, this::onScreenTapped)
|
tapGestureDetector.addOnGestureDetectedCallback(TAG, this::onScreenTapped)
|
||||||
windowManager.addView(chipView, windowLayoutParams)
|
|
||||||
// Wake the screen so the user will see the chip
|
// Wake the screen so the user will see the chip
|
||||||
powerManager.wakeUp(
|
powerManager.wakeUp(
|
||||||
SystemClock.uptimeMillis(),
|
SystemClock.uptimeMillis(),
|
||||||
PowerManager.WAKE_REASON_APPLICATION,
|
PowerManager.WAKE_REASON_APPLICATION,
|
||||||
"com.android.systemui:media_tap_to_transfer_activated"
|
"com.android.systemui:media_tap_to_transfer_activated"
|
||||||
)
|
)
|
||||||
animateChipIn(currentChipView)
|
|
||||||
|
inflateAndUpdateChip(newChipInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel and re-set the chip timeout each time we get a new state.
|
// Cancel and re-set the chip timeout each time we get a new state.
|
||||||
val timeout = accessibilityManager.getRecommendedTimeoutMillis(
|
val timeout = accessibilityManager.getRecommendedTimeoutMillis(
|
||||||
chipInfo.getTimeoutMs().toInt(),
|
newChipInfo.getTimeoutMs().toInt(),
|
||||||
// Not all chips have controls so FLAG_CONTENT_CONTROLS might be superfluous, but
|
// Not all chips have controls so FLAG_CONTENT_CONTROLS might be superfluous, but
|
||||||
// include it just to be safe.
|
// include it just to be safe.
|
||||||
FLAG_CONTENT_ICONS or FLAG_CONTENT_TEXT or FLAG_CONTENT_CONTROLS
|
FLAG_CONTENT_ICONS or FLAG_CONTENT_TEXT or FLAG_CONTENT_CONTROLS
|
||||||
@@ -136,6 +136,32 @@ abstract class MediaTttChipControllerCommon<T : ChipInfoCommon>(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Inflates a new chip view, updates it with [newChipInfo], and adds the view to the window. */
|
||||||
|
private fun inflateAndUpdateChip(newChipInfo: T) {
|
||||||
|
val newChipView = LayoutInflater
|
||||||
|
.from(context)
|
||||||
|
.inflate(chipLayoutRes, null) as ViewGroup
|
||||||
|
chipView = newChipView
|
||||||
|
updateChipView(newChipInfo, newChipView)
|
||||||
|
windowManager.addView(newChipView, windowLayoutParams)
|
||||||
|
animateChipIn(newChipView)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Removes then re-inflates the chip. */
|
||||||
|
private fun reinflateChip() {
|
||||||
|
val currentChipInfo = chipInfo
|
||||||
|
if (chipView == null || currentChipInfo == null) { return }
|
||||||
|
|
||||||
|
windowManager.removeView(chipView)
|
||||||
|
inflateAndUpdateChip(currentChipInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val displayScaleListener = object : ConfigurationController.ConfigurationListener {
|
||||||
|
override fun onDensityOrFontScaleChanged() {
|
||||||
|
reinflateChip()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hides the chip.
|
* Hides the chip.
|
||||||
*
|
*
|
||||||
@@ -145,17 +171,22 @@ abstract class MediaTttChipControllerCommon<T : ChipInfoCommon>(
|
|||||||
open fun removeChip(removalReason: String) {
|
open fun removeChip(removalReason: String) {
|
||||||
if (chipView == null) { return }
|
if (chipView == null) { return }
|
||||||
logger.logChipRemoval(removalReason)
|
logger.logChipRemoval(removalReason)
|
||||||
|
configurationController.removeCallback(displayScaleListener)
|
||||||
tapGestureDetector.removeOnGestureDetectedCallback(TAG)
|
tapGestureDetector.removeOnGestureDetectedCallback(TAG)
|
||||||
windowManager.removeView(chipView)
|
windowManager.removeView(chipView)
|
||||||
chipView = null
|
chipView = null
|
||||||
|
chipInfo = null
|
||||||
// No need to time the chip out since it's already gone
|
// No need to time the chip out since it's already gone
|
||||||
cancelChipViewTimeout?.run()
|
cancelChipViewTimeout?.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A method implemented by subclasses to update [currentChipView] based on [chipInfo].
|
* A method implemented by subclasses to update [currentChipView] based on [newChipInfo].
|
||||||
*/
|
*/
|
||||||
abstract fun updateChipView(chipInfo: T, currentChipView: ViewGroup)
|
@CallSuper
|
||||||
|
open fun updateChipView(newChipInfo: T, currentChipView: ViewGroup) {
|
||||||
|
chipInfo = newChipInfo
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A method that can be implemented by subclcasses to do custom animations for when the chip
|
* A method that can be implemented by subclcasses to do custom animations for when the chip
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import com.android.systemui.media.taptotransfer.common.MediaTttChipControllerCom
|
|||||||
import com.android.systemui.media.taptotransfer.common.MediaTttLogger
|
import com.android.systemui.media.taptotransfer.common.MediaTttLogger
|
||||||
import com.android.systemui.statusbar.CommandQueue
|
import com.android.systemui.statusbar.CommandQueue
|
||||||
import com.android.systemui.statusbar.gesture.TapGestureDetector
|
import com.android.systemui.statusbar.gesture.TapGestureDetector
|
||||||
|
import com.android.systemui.statusbar.policy.ConfigurationController
|
||||||
import com.android.systemui.util.animation.AnimationUtil.Companion.frames
|
import com.android.systemui.util.animation.AnimationUtil.Companion.frames
|
||||||
import com.android.systemui.util.concurrency.DelayableExecutor
|
import com.android.systemui.util.concurrency.DelayableExecutor
|
||||||
import com.android.systemui.util.view.ViewUtil
|
import com.android.systemui.util.view.ViewUtil
|
||||||
@@ -54,27 +55,29 @@ import javax.inject.Inject
|
|||||||
*/
|
*/
|
||||||
@SysUISingleton
|
@SysUISingleton
|
||||||
class MediaTttChipControllerReceiver @Inject constructor(
|
class MediaTttChipControllerReceiver @Inject constructor(
|
||||||
commandQueue: CommandQueue,
|
commandQueue: CommandQueue,
|
||||||
context: Context,
|
context: Context,
|
||||||
@MediaTttReceiverLogger logger: MediaTttLogger,
|
@MediaTttReceiverLogger logger: MediaTttLogger,
|
||||||
windowManager: WindowManager,
|
windowManager: WindowManager,
|
||||||
viewUtil: ViewUtil,
|
viewUtil: ViewUtil,
|
||||||
mainExecutor: DelayableExecutor,
|
mainExecutor: DelayableExecutor,
|
||||||
accessibilityManager: AccessibilityManager,
|
accessibilityManager: AccessibilityManager,
|
||||||
tapGestureDetector: TapGestureDetector,
|
configurationController: ConfigurationController,
|
||||||
powerManager: PowerManager,
|
tapGestureDetector: TapGestureDetector,
|
||||||
@Main private val mainHandler: Handler,
|
powerManager: PowerManager,
|
||||||
private val uiEventLogger: MediaTttReceiverUiEventLogger,
|
@Main private val mainHandler: Handler,
|
||||||
|
private val uiEventLogger: MediaTttReceiverUiEventLogger,
|
||||||
) : MediaTttChipControllerCommon<ChipReceiverInfo>(
|
) : MediaTttChipControllerCommon<ChipReceiverInfo>(
|
||||||
context,
|
context,
|
||||||
logger,
|
logger,
|
||||||
windowManager,
|
windowManager,
|
||||||
viewUtil,
|
viewUtil,
|
||||||
mainExecutor,
|
mainExecutor,
|
||||||
accessibilityManager,
|
accessibilityManager,
|
||||||
tapGestureDetector,
|
configurationController,
|
||||||
powerManager,
|
tapGestureDetector,
|
||||||
R.layout.media_ttt_chip_receiver
|
powerManager,
|
||||||
|
R.layout.media_ttt_chip_receiver,
|
||||||
) {
|
) {
|
||||||
@SuppressLint("WrongConstant") // We're allowed to use LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
|
@SuppressLint("WrongConstant") // We're allowed to use LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
|
||||||
override val windowLayoutParams = commonWindowLayoutParams.apply {
|
override val windowLayoutParams = commonWindowLayoutParams.apply {
|
||||||
@@ -140,12 +143,13 @@ class MediaTttChipControllerReceiver @Inject constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateChipView(chipInfo: ChipReceiverInfo, currentChipView: ViewGroup) {
|
override fun updateChipView(newChipInfo: ChipReceiverInfo, currentChipView: ViewGroup) {
|
||||||
|
super.updateChipView(newChipInfo, currentChipView)
|
||||||
setIcon(
|
setIcon(
|
||||||
currentChipView,
|
currentChipView,
|
||||||
chipInfo.routeInfo.packageName,
|
newChipInfo.routeInfo.packageName,
|
||||||
chipInfo.appIconDrawableOverride,
|
newChipInfo.appIconDrawableOverride,
|
||||||
chipInfo.appNameOverride
|
newChipInfo.appNameOverride
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import com.android.systemui.media.taptotransfer.common.MediaTttLogger
|
|||||||
import com.android.systemui.media.taptotransfer.common.MediaTttRemovalReason
|
import com.android.systemui.media.taptotransfer.common.MediaTttRemovalReason
|
||||||
import com.android.systemui.statusbar.CommandQueue
|
import com.android.systemui.statusbar.CommandQueue
|
||||||
import com.android.systemui.statusbar.gesture.TapGestureDetector
|
import com.android.systemui.statusbar.gesture.TapGestureDetector
|
||||||
|
import com.android.systemui.statusbar.policy.ConfigurationController
|
||||||
import com.android.systemui.util.concurrency.DelayableExecutor
|
import com.android.systemui.util.concurrency.DelayableExecutor
|
||||||
import com.android.systemui.util.view.ViewUtil
|
import com.android.systemui.util.view.ViewUtil
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -49,33 +50,33 @@ import javax.inject.Inject
|
|||||||
*/
|
*/
|
||||||
@SysUISingleton
|
@SysUISingleton
|
||||||
class MediaTttChipControllerSender @Inject constructor(
|
class MediaTttChipControllerSender @Inject constructor(
|
||||||
commandQueue: CommandQueue,
|
commandQueue: CommandQueue,
|
||||||
context: Context,
|
context: Context,
|
||||||
@MediaTttSenderLogger logger: MediaTttLogger,
|
@MediaTttSenderLogger logger: MediaTttLogger,
|
||||||
windowManager: WindowManager,
|
windowManager: WindowManager,
|
||||||
viewUtil: ViewUtil,
|
viewUtil: ViewUtil,
|
||||||
@Main mainExecutor: DelayableExecutor,
|
@Main mainExecutor: DelayableExecutor,
|
||||||
accessibilityManager: AccessibilityManager,
|
accessibilityManager: AccessibilityManager,
|
||||||
tapGestureDetector: TapGestureDetector,
|
configurationController: ConfigurationController,
|
||||||
powerManager: PowerManager,
|
tapGestureDetector: TapGestureDetector,
|
||||||
private val uiEventLogger: MediaTttSenderUiEventLogger
|
powerManager: PowerManager,
|
||||||
|
private val uiEventLogger: MediaTttSenderUiEventLogger
|
||||||
) : MediaTttChipControllerCommon<ChipSenderInfo>(
|
) : MediaTttChipControllerCommon<ChipSenderInfo>(
|
||||||
context,
|
context,
|
||||||
logger,
|
logger,
|
||||||
windowManager,
|
windowManager,
|
||||||
viewUtil,
|
viewUtil,
|
||||||
mainExecutor,
|
mainExecutor,
|
||||||
accessibilityManager,
|
accessibilityManager,
|
||||||
tapGestureDetector,
|
configurationController,
|
||||||
powerManager,
|
tapGestureDetector,
|
||||||
R.layout.media_ttt_chip
|
powerManager,
|
||||||
|
R.layout.media_ttt_chip,
|
||||||
) {
|
) {
|
||||||
override val windowLayoutParams = commonWindowLayoutParams.apply {
|
override val windowLayoutParams = commonWindowLayoutParams.apply {
|
||||||
gravity = Gravity.TOP.or(Gravity.CENTER_HORIZONTAL)
|
gravity = Gravity.TOP.or(Gravity.CENTER_HORIZONTAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var currentlyDisplayedChipState: ChipStateSender? = null
|
|
||||||
|
|
||||||
private val commandQueueCallbacks = object : CommandQueue.Callbacks {
|
private val commandQueueCallbacks = object : CommandQueue.Callbacks {
|
||||||
override fun updateMediaTapToTransferSenderDisplay(
|
override fun updateMediaTapToTransferSenderDisplay(
|
||||||
@StatusBarManager.MediaTransferSenderState displayState: Int,
|
@StatusBarManager.MediaTransferSenderState displayState: Int,
|
||||||
@@ -116,16 +117,18 @@ class MediaTttChipControllerSender @Inject constructor(
|
|||||||
|
|
||||||
/** Displays the chip view for the given state. */
|
/** Displays the chip view for the given state. */
|
||||||
override fun updateChipView(
|
override fun updateChipView(
|
||||||
chipInfo: ChipSenderInfo,
|
newChipInfo: ChipSenderInfo,
|
||||||
currentChipView: ViewGroup) {
|
currentChipView: ViewGroup
|
||||||
val chipState = chipInfo.state
|
) {
|
||||||
currentlyDisplayedChipState = chipState
|
super.updateChipView(newChipInfo, currentChipView)
|
||||||
|
|
||||||
|
val chipState = newChipInfo.state
|
||||||
|
|
||||||
// App icon
|
// App icon
|
||||||
setIcon(currentChipView, chipInfo.routeInfo.packageName)
|
setIcon(currentChipView, newChipInfo.routeInfo.packageName)
|
||||||
|
|
||||||
// Text
|
// Text
|
||||||
val otherDeviceName = chipInfo.routeInfo.name.toString()
|
val otherDeviceName = newChipInfo.routeInfo.name.toString()
|
||||||
currentChipView.requireViewById<TextView>(R.id.text).apply {
|
currentChipView.requireViewById<TextView>(R.id.text).apply {
|
||||||
text = chipState.getChipTextString(context, otherDeviceName)
|
text = chipState.getChipTextString(context, otherDeviceName)
|
||||||
}
|
}
|
||||||
@@ -137,7 +140,7 @@ class MediaTttChipControllerSender @Inject constructor(
|
|||||||
// Undo
|
// Undo
|
||||||
val undoView = currentChipView.requireViewById<View>(R.id.undo)
|
val undoView = currentChipView.requireViewById<View>(R.id.undo)
|
||||||
val undoClickListener = chipState.undoClickListener(
|
val undoClickListener = chipState.undoClickListener(
|
||||||
this, chipInfo.routeInfo, chipInfo.undoCallback, uiEventLogger
|
this, newChipInfo.routeInfo, newChipInfo.undoCallback, uiEventLogger
|
||||||
)
|
)
|
||||||
undoView.setOnClickListener(undoClickListener)
|
undoView.setOnClickListener(undoClickListener)
|
||||||
undoView.visibility = (undoClickListener != null).visibleIfTrue()
|
undoView.visibility = (undoClickListener != null).visibleIfTrue()
|
||||||
@@ -161,12 +164,11 @@ class MediaTttChipControllerSender @Inject constructor(
|
|||||||
override fun removeChip(removalReason: String) {
|
override fun removeChip(removalReason: String) {
|
||||||
// Don't remove the chip if we're mid-transfer since the user should still be able to
|
// Don't remove the chip if we're mid-transfer since the user should still be able to
|
||||||
// see the status of the transfer. (But do remove it if it's finally timed out.)
|
// see the status of the transfer. (But do remove it if it's finally timed out.)
|
||||||
if (currentlyDisplayedChipState?.isMidTransfer == true
|
if (chipInfo?.state?.isMidTransfer == true &&
|
||||||
&& removalReason != MediaTttRemovalReason.REASON_TIMEOUT) {
|
removalReason != MediaTttRemovalReason.REASON_TIMEOUT) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
super.removeChip(removalReason)
|
super.removeChip(removalReason)
|
||||||
currentlyDisplayedChipState = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Boolean.visibleIfTrue(): Int {
|
private fun Boolean.visibleIfTrue(): Int {
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ import com.android.systemui.R
|
|||||||
import com.android.systemui.SysuiTestCase
|
import com.android.systemui.SysuiTestCase
|
||||||
import com.android.systemui.dagger.qualifiers.Main
|
import com.android.systemui.dagger.qualifiers.Main
|
||||||
import com.android.systemui.statusbar.gesture.TapGestureDetector
|
import com.android.systemui.statusbar.gesture.TapGestureDetector
|
||||||
|
import com.android.systemui.statusbar.policy.ConfigurationController
|
||||||
|
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener
|
||||||
import com.android.systemui.util.concurrency.DelayableExecutor
|
import com.android.systemui.util.concurrency.DelayableExecutor
|
||||||
import com.android.systemui.util.concurrency.FakeExecutor
|
import com.android.systemui.util.concurrency.FakeExecutor
|
||||||
import com.android.systemui.util.mockito.any
|
import com.android.systemui.util.mockito.any
|
||||||
@@ -53,7 +55,7 @@ import org.mockito.MockitoAnnotations
|
|||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
class MediaTttChipControllerCommonTest : SysuiTestCase() {
|
class MediaTttChipControllerCommonTest : SysuiTestCase() {
|
||||||
private lateinit var controllerCommon: MediaTttChipControllerCommon<ChipInfo>
|
private lateinit var controllerCommon: TestControllerCommon
|
||||||
|
|
||||||
private lateinit var fakeClock: FakeSystemClock
|
private lateinit var fakeClock: FakeSystemClock
|
||||||
private lateinit var fakeExecutor: FakeExecutor
|
private lateinit var fakeExecutor: FakeExecutor
|
||||||
@@ -68,6 +70,8 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
|
|||||||
@Mock
|
@Mock
|
||||||
private lateinit var accessibilityManager: AccessibilityManager
|
private lateinit var accessibilityManager: AccessibilityManager
|
||||||
@Mock
|
@Mock
|
||||||
|
private lateinit var configurationController: ConfigurationController
|
||||||
|
@Mock
|
||||||
private lateinit var windowManager: WindowManager
|
private lateinit var windowManager: WindowManager
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var viewUtil: ViewUtil
|
private lateinit var viewUtil: ViewUtil
|
||||||
@@ -98,14 +102,15 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
|
|||||||
fakeExecutor = FakeExecutor(fakeClock)
|
fakeExecutor = FakeExecutor(fakeClock)
|
||||||
|
|
||||||
controllerCommon = TestControllerCommon(
|
controllerCommon = TestControllerCommon(
|
||||||
context,
|
context,
|
||||||
logger,
|
logger,
|
||||||
windowManager,
|
windowManager,
|
||||||
viewUtil,
|
viewUtil,
|
||||||
fakeExecutor,
|
fakeExecutor,
|
||||||
accessibilityManager,
|
accessibilityManager,
|
||||||
tapGestureDetector,
|
configurationController,
|
||||||
powerManager
|
tapGestureDetector,
|
||||||
|
powerManager,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,6 +190,19 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
|
|||||||
verify(windowManager).removeView(any())
|
verify(windowManager).removeView(any())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun displayScaleChange_chipReinflatedWithMostRecentState() {
|
||||||
|
controllerCommon.displayChip(getState(name = "First name"))
|
||||||
|
controllerCommon.displayChip(getState(name = "Second name"))
|
||||||
|
reset(windowManager)
|
||||||
|
|
||||||
|
getConfigurationListener().onDensityOrFontScaleChanged()
|
||||||
|
|
||||||
|
verify(windowManager).removeView(any())
|
||||||
|
verify(windowManager).addView(any(), any())
|
||||||
|
assertThat(controllerCommon.mostRecentChipInfo?.name).isEqualTo("Second name")
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun removeChip_chipRemovedAndGestureDetectionStoppedAndRemovalLogged() {
|
fun removeChip_chipRemovedAndGestureDetectionStoppedAndRemovalLogged() {
|
||||||
// First, add the chip
|
// First, add the chip
|
||||||
@@ -341,7 +359,7 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
|
|||||||
verify(windowManager, never()).removeView(any())
|
verify(windowManager, never()).removeView(any())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getState() = ChipInfo()
|
private fun getState(name: String = "name") = ChipInfo(name)
|
||||||
|
|
||||||
private fun getChipView(): ViewGroup {
|
private fun getChipView(): ViewGroup {
|
||||||
val viewCaptor = ArgumentCaptor.forClass(View::class.java)
|
val viewCaptor = ArgumentCaptor.forClass(View::class.java)
|
||||||
@@ -351,6 +369,12 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
|
|||||||
|
|
||||||
private fun ViewGroup.getAppIconView() = this.requireViewById<ImageView>(R.id.app_icon)
|
private fun ViewGroup.getAppIconView() = this.requireViewById<ImageView>(R.id.app_icon)
|
||||||
|
|
||||||
|
private fun getConfigurationListener(): ConfigurationListener {
|
||||||
|
val callbackCaptor = argumentCaptor<ConfigurationListener>()
|
||||||
|
verify(configurationController).addCallback(capture(callbackCaptor))
|
||||||
|
return callbackCaptor.value
|
||||||
|
}
|
||||||
|
|
||||||
inner class TestControllerCommon(
|
inner class TestControllerCommon(
|
||||||
context: Context,
|
context: Context,
|
||||||
logger: MediaTttLogger,
|
logger: MediaTttLogger,
|
||||||
@@ -358,8 +382,9 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
|
|||||||
viewUtil: ViewUtil,
|
viewUtil: ViewUtil,
|
||||||
@Main mainExecutor: DelayableExecutor,
|
@Main mainExecutor: DelayableExecutor,
|
||||||
accessibilityManager: AccessibilityManager,
|
accessibilityManager: AccessibilityManager,
|
||||||
|
configurationController: ConfigurationController,
|
||||||
tapGestureDetector: TapGestureDetector,
|
tapGestureDetector: TapGestureDetector,
|
||||||
powerManager: PowerManager
|
powerManager: PowerManager,
|
||||||
) : MediaTttChipControllerCommon<ChipInfo>(
|
) : MediaTttChipControllerCommon<ChipInfo>(
|
||||||
context,
|
context,
|
||||||
logger,
|
logger,
|
||||||
@@ -367,16 +392,22 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() {
|
|||||||
viewUtil,
|
viewUtil,
|
||||||
mainExecutor,
|
mainExecutor,
|
||||||
accessibilityManager,
|
accessibilityManager,
|
||||||
|
configurationController,
|
||||||
tapGestureDetector,
|
tapGestureDetector,
|
||||||
powerManager,
|
powerManager,
|
||||||
R.layout.media_ttt_chip
|
R.layout.media_ttt_chip,
|
||||||
) {
|
) {
|
||||||
|
var mostRecentChipInfo: ChipInfo? = null
|
||||||
|
|
||||||
override val windowLayoutParams = commonWindowLayoutParams
|
override val windowLayoutParams = commonWindowLayoutParams
|
||||||
override fun updateChipView(chipInfo: ChipInfo, currentChipView: ViewGroup) {}
|
override fun updateChipView(newChipInfo: ChipInfo, currentChipView: ViewGroup) {
|
||||||
|
super.updateChipView(newChipInfo, currentChipView)
|
||||||
|
mostRecentChipInfo = newChipInfo
|
||||||
|
}
|
||||||
override fun getIconSize(isAppIcon: Boolean): Int = ICON_SIZE
|
override fun getIconSize(isAppIcon: Boolean): Int = ICON_SIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class ChipInfo : ChipInfoCommon {
|
inner class ChipInfo(val name: String) : ChipInfoCommon {
|
||||||
override fun getTimeoutMs() = 1L
|
override fun getTimeoutMs() = 1L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import com.android.systemui.SysuiTestCase
|
|||||||
import com.android.systemui.media.taptotransfer.common.MediaTttLogger
|
import com.android.systemui.media.taptotransfer.common.MediaTttLogger
|
||||||
import com.android.systemui.statusbar.CommandQueue
|
import com.android.systemui.statusbar.CommandQueue
|
||||||
import com.android.systemui.statusbar.gesture.TapGestureDetector
|
import com.android.systemui.statusbar.gesture.TapGestureDetector
|
||||||
|
import com.android.systemui.statusbar.policy.ConfigurationController
|
||||||
import com.android.systemui.util.concurrency.FakeExecutor
|
import com.android.systemui.util.concurrency.FakeExecutor
|
||||||
import com.android.systemui.util.mockito.any
|
import com.android.systemui.util.mockito.any
|
||||||
import com.android.systemui.util.mockito.eq
|
import com.android.systemui.util.mockito.eq
|
||||||
@@ -68,6 +69,8 @@ class MediaTttChipControllerReceiverTest : SysuiTestCase() {
|
|||||||
@Mock
|
@Mock
|
||||||
private lateinit var accessibilityManager: AccessibilityManager
|
private lateinit var accessibilityManager: AccessibilityManager
|
||||||
@Mock
|
@Mock
|
||||||
|
private lateinit var configurationController: ConfigurationController
|
||||||
|
@Mock
|
||||||
private lateinit var powerManager: PowerManager
|
private lateinit var powerManager: PowerManager
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var windowManager: WindowManager
|
private lateinit var windowManager: WindowManager
|
||||||
@@ -103,6 +106,7 @@ class MediaTttChipControllerReceiverTest : SysuiTestCase() {
|
|||||||
viewUtil,
|
viewUtil,
|
||||||
FakeExecutor(FakeSystemClock()),
|
FakeExecutor(FakeSystemClock()),
|
||||||
accessibilityManager,
|
accessibilityManager,
|
||||||
|
configurationController,
|
||||||
TapGestureDetector(context),
|
TapGestureDetector(context),
|
||||||
powerManager,
|
powerManager,
|
||||||
Handler.getMain(),
|
Handler.getMain(),
|
||||||
|
|||||||
@@ -38,12 +38,12 @@ import com.android.systemui.SysuiTestCase
|
|||||||
import com.android.systemui.media.taptotransfer.common.MediaTttLogger
|
import com.android.systemui.media.taptotransfer.common.MediaTttLogger
|
||||||
import com.android.systemui.statusbar.CommandQueue
|
import com.android.systemui.statusbar.CommandQueue
|
||||||
import com.android.systemui.statusbar.gesture.TapGestureDetector
|
import com.android.systemui.statusbar.gesture.TapGestureDetector
|
||||||
|
import com.android.systemui.statusbar.policy.ConfigurationController
|
||||||
import com.android.systemui.util.concurrency.FakeExecutor
|
import com.android.systemui.util.concurrency.FakeExecutor
|
||||||
import com.android.systemui.util.mockito.any
|
import com.android.systemui.util.mockito.any
|
||||||
import com.android.systemui.util.mockito.eq
|
import com.android.systemui.util.mockito.eq
|
||||||
import com.android.systemui.util.time.FakeSystemClock
|
import com.android.systemui.util.time.FakeSystemClock
|
||||||
import com.android.systemui.util.view.ViewUtil
|
import com.android.systemui.util.view.ViewUtil
|
||||||
|
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@@ -52,8 +52,8 @@ import org.mockito.ArgumentCaptor
|
|||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito.never
|
import org.mockito.Mockito.never
|
||||||
import org.mockito.Mockito.verify
|
import org.mockito.Mockito.verify
|
||||||
import org.mockito.Mockito.`when` as whenever
|
|
||||||
import org.mockito.MockitoAnnotations
|
import org.mockito.MockitoAnnotations
|
||||||
|
import org.mockito.Mockito.`when` as whenever
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
@RunWith(AndroidTestingRunner::class)
|
@RunWith(AndroidTestingRunner::class)
|
||||||
@@ -70,6 +70,8 @@ class MediaTttChipControllerSenderTest : SysuiTestCase() {
|
|||||||
@Mock
|
@Mock
|
||||||
private lateinit var accessibilityManager: AccessibilityManager
|
private lateinit var accessibilityManager: AccessibilityManager
|
||||||
@Mock
|
@Mock
|
||||||
|
private lateinit var configurationController: ConfigurationController
|
||||||
|
@Mock
|
||||||
private lateinit var powerManager: PowerManager
|
private lateinit var powerManager: PowerManager
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var windowManager: WindowManager
|
private lateinit var windowManager: WindowManager
|
||||||
@@ -112,6 +114,7 @@ class MediaTttChipControllerSenderTest : SysuiTestCase() {
|
|||||||
viewUtil,
|
viewUtil,
|
||||||
fakeExecutor,
|
fakeExecutor,
|
||||||
accessibilityManager,
|
accessibilityManager,
|
||||||
|
configurationController,
|
||||||
TapGestureDetector(context),
|
TapGestureDetector(context),
|
||||||
powerManager,
|
powerManager,
|
||||||
senderUiEventLogger
|
senderUiEventLogger
|
||||||
|
|||||||
Reference in New Issue
Block a user