Add TaskContentView parent to TaskThumbnailViewHeader and TTV
- Add TaskContentView parent view - Extract TaskThumbnailViewHeader logic and any related state out of TaskThumbnailView and move to TaskContentView - Use vertical LinearLayoutManager to hold the TaskThumbnailViewHeader and TaskThumbnailView - Rename TaskThumbnailViewHeader to TaskHeaderView. Rename xml and state similarly Bug: 397889146 Flag: EXEMPT. Refactor Test: Refactoring CL. Existing unit tests still pass. Change-Id: Ie31f35c6617aab272f984a6beb3e4cb8f58e3ce9
This commit is contained in:
1 parent
aee4b11336
commit
e0cc96df62
28 files changed
+700
-464
No files matched your search
@@ -19,32 +19,24 @@ package com.android.quickstep.task.thumbnail
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.Matrix
|
||||
import android.graphics.Outline
|
||||
import android.graphics.Path
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.ShapeDrawable
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewOutlineProvider
|
||||
import android.widget.FrameLayout
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.view.isInvisible
|
||||
import com.android.launcher3.Flags.enableDesktopExplodedView
|
||||
import com.android.launcher3.LauncherAnimUtils.VIEW_ALPHA
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.util.MultiPropertyFactory
|
||||
import com.android.launcher3.util.ViewPool
|
||||
import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.BackgroundOnly
|
||||
import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.LiveTile
|
||||
import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.Snapshot
|
||||
import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.SnapshotSplash
|
||||
import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.Uninitialized
|
||||
import com.android.quickstep.views.FixedSizeImageView
|
||||
import com.android.quickstep.views.TaskThumbnailViewHeader
|
||||
|
||||
class TaskThumbnailView : FrameLayout, ViewPool.Reusable {
|
||||
class TaskThumbnailView : FrameLayout {
|
||||
private val scrimView: View by lazy { findViewById(R.id.task_thumbnail_scrim) }
|
||||
private val liveTileView: LiveTileView by lazy { findViewById(R.id.task_thumbnail_live_tile) }
|
||||
private val thumbnailView: FixedSizeImageView by lazy { findViewById(R.id.task_thumbnail) }
|
||||
@@ -53,30 +45,9 @@ class TaskThumbnailView : FrameLayout, ViewPool.Reusable {
|
||||
private val dimAlpha: MultiPropertyFactory<View> by lazy {
|
||||
MultiPropertyFactory(scrimView, VIEW_ALPHA, ScrimViewAlpha.entries.size, ::maxOf)
|
||||
}
|
||||
private val outlinePath = Path()
|
||||
private var onSizeChanged: ((width: Int, height: Int) -> Unit)? = null
|
||||
|
||||
private var taskThumbnailViewHeader: TaskThumbnailViewHeader? = null
|
||||
|
||||
private var uiState: TaskThumbnailUiState = Uninitialized
|
||||
|
||||
/**
|
||||
* Sets the outline bounds of the view. Default to use view's bound as outline when set to null.
|
||||
*/
|
||||
var outlineBounds: Rect? = null
|
||||
set(value) {
|
||||
field = value
|
||||
invalidateOutline()
|
||||
}
|
||||
|
||||
private val bounds = Rect()
|
||||
|
||||
var cornerRadius: Float = 0f
|
||||
set(value) {
|
||||
field = value
|
||||
invalidateOutline()
|
||||
}
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
@@ -87,39 +58,8 @@ class TaskThumbnailView : FrameLayout, ViewPool.Reusable {
|
||||
defStyleAttr: Int,
|
||||
) : super(context, attrs, defStyleAttr)
|
||||
|
||||
override fun onFinishInflate() {
|
||||
super.onFinishInflate()
|
||||
maybeCreateHeader()
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
clipToOutline = true
|
||||
outlineProvider =
|
||||
object : ViewOutlineProvider() {
|
||||
override fun getOutline(view: View, outline: Outline) {
|
||||
val outlineRect = outlineBounds ?: bounds
|
||||
outlinePath.apply {
|
||||
rewind()
|
||||
addRoundRect(
|
||||
outlineRect.left.toFloat(),
|
||||
outlineRect.top.toFloat(),
|
||||
outlineRect.right.toFloat(),
|
||||
outlineRect.bottom.toFloat(),
|
||||
cornerRadius / scaleX,
|
||||
cornerRadius / scaleY,
|
||||
Path.Direction.CW,
|
||||
)
|
||||
}
|
||||
outline.setPath(outlinePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRecycle() {
|
||||
fun onRecycle() {
|
||||
uiState = Uninitialized
|
||||
onSizeChanged = null
|
||||
outlineBounds = null
|
||||
resetViews()
|
||||
}
|
||||
|
||||
@@ -130,7 +70,7 @@ class TaskThumbnailView : FrameLayout, ViewPool.Reusable {
|
||||
resetViews()
|
||||
when (state) {
|
||||
is Uninitialized -> {}
|
||||
is LiveTile -> drawLiveWindow(state)
|
||||
is LiveTile -> drawLiveWindow()
|
||||
is SnapshotSplash -> drawSnapshotSplash(state)
|
||||
is BackgroundOnly -> drawBackground(state.backgroundColor)
|
||||
}
|
||||
@@ -155,25 +95,12 @@ class TaskThumbnailView : FrameLayout, ViewPool.Reusable {
|
||||
splashIcon.alpha = value
|
||||
}
|
||||
|
||||
fun doOnSizeChange(action: (width: Int, height: Int) -> Unit) {
|
||||
onSizeChanged = action
|
||||
}
|
||||
|
||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||
super.onSizeChanged(w, h, oldw, oldh)
|
||||
onSizeChanged?.invoke(width, height)
|
||||
bounds.set(0, 0, w, h)
|
||||
invalidateOutline()
|
||||
}
|
||||
|
||||
override fun setScaleX(scaleX: Float) {
|
||||
super.setScaleX(scaleX)
|
||||
fun parentScaleXUpdated(scaleX: Float) {
|
||||
// Splash icon should ignore scale on TTV
|
||||
splashIcon.scaleX = 1 / scaleX
|
||||
}
|
||||
|
||||
override fun setScaleY(scaleY: Float) {
|
||||
super.setScaleY(scaleY)
|
||||
fun parentScaleYUpdated(scaleY: Float) {
|
||||
// Splash icon should ignore scale on TTV
|
||||
splashIcon.scaleY = 1 / scaleY
|
||||
}
|
||||
@@ -187,20 +114,14 @@ class TaskThumbnailView : FrameLayout, ViewPool.Reusable {
|
||||
splashIcon.setImageDrawable(null)
|
||||
scrimView.alpha = 0f
|
||||
setBackgroundColor(Color.BLACK)
|
||||
taskThumbnailViewHeader?.isInvisible = true
|
||||
}
|
||||
|
||||
private fun drawBackground(@ColorInt background: Int) {
|
||||
setBackgroundColor(background)
|
||||
}
|
||||
|
||||
private fun drawLiveWindow(liveTile: LiveTile) {
|
||||
private fun drawLiveWindow() {
|
||||
liveTileView.isInvisible = false
|
||||
|
||||
if (liveTile is LiveTile.WithHeader) {
|
||||
taskThumbnailViewHeader?.isInvisible = false
|
||||
taskThumbnailViewHeader?.setHeader(liveTile.header)
|
||||
}
|
||||
}
|
||||
|
||||
private fun drawSnapshotSplash(snapshotSplash: SnapshotSplash) {
|
||||
@@ -212,11 +133,6 @@ class TaskThumbnailView : FrameLayout, ViewPool.Reusable {
|
||||
}
|
||||
|
||||
private fun drawSnapshot(snapshot: Snapshot) {
|
||||
if (snapshot is Snapshot.WithHeader) {
|
||||
taskThumbnailViewHeader?.isInvisible = false
|
||||
taskThumbnailViewHeader?.setHeader(snapshot.header)
|
||||
}
|
||||
|
||||
drawBackground(snapshot.backgroundColor)
|
||||
thumbnailView.setImageBitmap(snapshot.bitmap)
|
||||
thumbnailView.isInvisible = false
|
||||
@@ -232,16 +148,6 @@ class TaskThumbnailView : FrameLayout, ViewPool.Reusable {
|
||||
Log.d(TAG, "[TaskThumbnailView@${Integer.toHexString(hashCode())}] $message")
|
||||
}
|
||||
|
||||
private fun maybeCreateHeader() {
|
||||
if (enableDesktopExplodedView() && taskThumbnailViewHeader == null) {
|
||||
taskThumbnailViewHeader =
|
||||
LayoutInflater.from(context)
|
||||
.inflate(R.layout.task_thumbnail_view_header, this, false)
|
||||
as TaskThumbnailViewHeader
|
||||
addView(taskThumbnailViewHeader)
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val TAG = "TaskThumbnailView"
|
||||
private const val MAX_SCRIM_ALPHA = 0.4f
|
||||
|
||||
Reference in new issue
Block a user