Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0abbc4af authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add scrim to TaskThumbnailView" into main

parents f53b40e1 0d9b5474
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -228,6 +228,7 @@ public interface TaskShortcutFactory {

                // Take the thumbnail of the task without a scrim and apply it back after
                float alpha = mThumbnailView.getDimAlpha();
                // TODO(b/348643341) add ability to get override the scrim for this Bitmap retrieval
                mThumbnailView.setDimAlpha(0);
                Bitmap thumbnail = RecentsTransition.drawViewIntoHardwareBitmap(
                        taskBounds.width(), taskBounds.height(), mThumbnailView, 1f,
+23 −0
Original line number Diff line number Diff line
@@ -53,25 +53,31 @@ class TaskThumbnailView : View {
        TaskThumbnailViewModel(
            recentsView.mRecentsViewData,
            (parent as TaskView).taskViewData,
            (parent as TaskView).getTaskContainerForTaskThumbnailView(this)!!.taskContainerData,
            recentsView.mTasksRepository,
        )
    }

    private var uiState: TaskThumbnailUiState = Uninitialized
    private var inheritedScale: Float = 1f
    private var dimProgress: Float = 0f

    private val backgroundPaint = Paint(Paint.ANTI_ALIAS_FLAG)
    private val scrimPaint = Paint().apply { color = Color.BLACK }
    private val _measuredBounds = Rect()
    private val measuredBounds: Rect
        get() {
            _measuredBounds.set(0, 0, measuredWidth, measuredHeight)
            return _measuredBounds
        }

    private var cornerRadius: Float = TaskCornerRadius.get(context)
    private var fullscreenCornerRadius: Float = QuickStepContract.getWindowCornerRadius(context)

    constructor(context: Context?) : super(context)

    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)

    constructor(
        context: Context?,
        attrs: AttributeSet?,
@@ -87,6 +93,13 @@ class TaskThumbnailView : View {
                invalidate()
            }
        }
        MainScope().launch {
            viewModel.dimProgress.collect { dimProgress ->
                // TODO(b/348195366) Add fade in/out for scrim
                this@TaskThumbnailView.dimProgress = dimProgress
                invalidate()
            }
        }
        MainScope().launch { viewModel.recentsFullscreenProgress.collect { invalidateOutline() } }
        MainScope().launch {
            viewModel.inheritedScale.collect { viewModelInheritedScale ->
@@ -111,6 +124,10 @@ class TaskThumbnailView : View {
            is Snapshot -> drawSnapshotState(canvas, uiStateVal)
            is BackgroundOnly -> drawBackgroundOnly(canvas, uiStateVal.backgroundColor)
        }

        if (dimProgress > 0) {
            drawScrim(canvas)
        }
    }

    private fun drawBackgroundOnly(canvas: Canvas, @ColorInt backgroundColor: Int) {
@@ -135,6 +152,11 @@ class TaskThumbnailView : View {
        canvas.drawBitmap(snapshot.bitmap, snapshot.drawnRect, measuredBounds, null)
    }

    private fun drawScrim(canvas: Canvas) {
        scrimPaint.alpha = (dimProgress * MAX_SCRIM_ALPHA).toInt()
        canvas.drawRect(measuredBounds, scrimPaint)
    }

    private fun getCurrentCornerRadius() =
        Utilities.mapRange(
            viewModel.recentsFullscreenProgress.value,
@@ -145,5 +167,6 @@ class TaskThumbnailView : View {
    companion object {
        private val CLEAR_PAINT =
            Paint().apply { xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR) }
        private const val MAX_SCRIM_ALPHA = (0.4f * 255).toInt()
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ 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.Uninitialized
import com.android.quickstep.task.viewmodel.TaskContainerData
import com.android.quickstep.task.viewmodel.TaskViewData
import com.android.systemui.shared.recents.model.Task
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -40,6 +41,7 @@ import kotlinx.coroutines.flow.map
class TaskThumbnailViewModel(
    recentsViewData: RecentsViewData,
    taskViewData: TaskViewData,
    taskContainerData: TaskContainerData,
    private val tasksRepository: RecentTasksRepository,
) {
    private val task = MutableStateFlow<Flow<Task?>>(flowOf(null))
@@ -50,6 +52,7 @@ class TaskThumbnailViewModel(
        combine(recentsViewData.scale, taskViewData.scale) { recentsScale, taskScale ->
            recentsScale * taskScale
        }
    val dimProgress: Flow<Float> = taskContainerData.taskMenuOpenProgress
    val uiState: Flow<TaskThumbnailUiState> =
        task
            .flatMapLatest { taskFlow ->
+23 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.quickstep.task.viewmodel

import kotlinx.coroutines.flow.MutableStateFlow

class TaskContainerData {
    val taskMenuOpenProgress = MutableStateFlow(0f)
}
+12 −12
Original line number Diff line number Diff line
@@ -204,12 +204,12 @@ class DesktopTaskView @JvmOverloads constructor(context: Context, attrs: Attribu
                    showWindowsView = null,
                    taskOverlayFactory
                )
                    .apply { thumbnailViewDeprecated.bind(task, overlay) }
            if (index >= taskContainers.size) {
                taskContainers.add(taskContainer)
            } else {
                taskContainers[index] = taskContainer
            }
            taskContainer.bind()
        }
        repeat(taskContainers.size - tasks.size) {
            with(taskContainers.removeLast()) {
Loading