From 69ada2c046ca5fedfd3e4f1d3d11c0893563531d Mon Sep 17 00:00:00 2001 From: Elijah Hewer Date: Tue, 3 Jun 2025 11:16:45 -0700 Subject: [PATCH] desktop-exploded-view: Add border to desktop contents on hover Add a border to the TaskContentsView inside a DesktopTaskView when hovered with the mouse. Flag: com.android.launcher3.enable_desktop_exploded_view Test: manual Bug: 353949686 Change-Id: I49d72266f88142b012c0fd0aa32b0b17d50eaff0 --- quickstep/res/layout/task_content_view.xml | 3 +- quickstep/res/values/attrs.xml | 7 +- .../task/thumbnail/TaskContentView.kt | 123 +++++++++++++++--- .../android/quickstep/util/BorderAnimator.kt | 2 +- .../quickstep/views/DesktopTaskView.kt | 3 + 5 files changed, 112 insertions(+), 26 deletions(-) diff --git a/quickstep/res/layout/task_content_view.xml b/quickstep/res/layout/task_content_view.xml index b14e96d4d3..db85ed09bf 100644 --- a/quickstep/res/layout/task_content_view.xml +++ b/quickstep/res/layout/task_content_view.xml @@ -19,7 +19,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:importantForAccessibility="no" - app:focusBorderColor="@color/materialColorOutline"> + app:focusBorderColor="@color/materialColorOutline" + app:hoverBorderColor="@color/materialColorPrimary"> - + + diff --git a/quickstep/src/com/android/quickstep/task/thumbnail/TaskContentView.kt b/quickstep/src/com/android/quickstep/task/thumbnail/TaskContentView.kt index 09831366c3..ca8517e6a7 100644 --- a/quickstep/src/com/android/quickstep/task/thumbnail/TaskContentView.kt +++ b/quickstep/src/com/android/quickstep/task/thumbnail/TaskContentView.kt @@ -27,6 +27,7 @@ import android.graphics.Rect import android.provider.Settings import android.util.AttributeSet import android.util.FloatProperty +import android.view.MotionEvent import android.view.View import android.view.ViewOutlineProvider import android.view.ViewStub @@ -36,18 +37,23 @@ import androidx.annotation.IdRes import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.view.isInvisible import androidx.core.view.isVisible +import com.android.launcher3.Flags.enableCursorHoverStates import com.android.launcher3.Flags.enableRefactorDigitalWellbeingToast import com.android.launcher3.R import com.android.launcher3.util.KFloatProperty +import com.android.launcher3.util.MultiPropertyDelegate +import com.android.launcher3.util.MultiPropertyFactory import com.android.launcher3.util.ViewPool import com.android.quickstep.DesktopFullscreenDrawParams.Companion.computeCornerRadius import com.android.quickstep.task.apptimer.TaskAppTimerUiState import com.android.quickstep.task.apptimer.TimerTextHelper import com.android.quickstep.util.BorderAnimator import com.android.quickstep.util.BorderAnimator.Companion.DEFAULT_BORDER_COLOR +import com.android.quickstep.util.BorderAnimator.Companion.DEFAULT_INTERPOLATOR import com.android.quickstep.util.BorderAnimator.Companion.createSimpleBorderAnimator import com.android.quickstep.util.setActivityStarterClickListener import com.android.quickstep.views.TaskHeaderView +import kotlin.math.max /** * TaskContentView is a wrapper around the TaskHeaderView, TaskThumbnailView and Digital wellbeing @@ -72,13 +78,17 @@ class TaskContentView @JvmOverloads constructor(context: Context, attrs: Attribu private var onSizeChanged: ((width: Int, height: Int) -> Unit)? = null private val outlinePath = Path() - private var focusAnimator: AnimatorSet? = null + private val borderWidthPx: Int by lazy { + context.resources.getDimensionPixelSize(R.dimen.keyboard_quick_switch_border_width) + } + + private var activeFocusAnimator: AnimatorSet? = null + private var activeHoverAnimator: AnimatorSet? = null + private val focusBorderAnimator: BorderAnimator by lazy { - val borderWidth = - context.resources.getDimensionPixelSize(R.dimen.keyboard_quick_switch_border_width) createSimpleBorderAnimator( borderRadiusPx = computeCornerRadius(context).toInt(), - borderWidthPx = borderWidth, + borderWidthPx = borderWidthPx, boundsBuilder = { it.set(0, 0, width, height) }, targetView = this, borderColor = @@ -88,6 +98,31 @@ class TaskContentView @JvmOverloads constructor(context: Context, attrs: Attribu ) } + private val hoverBorderAnimator: BorderAnimator by lazy { + createSimpleBorderAnimator( + borderRadiusPx = computeCornerRadius(context).toInt(), + borderWidthPx = borderWidthPx, + boundsBuilder = { it.set(0, 0, width, height) }, + targetView = this, + borderColor = + context + .obtainStyledAttributes(attrs, R.styleable.TaskContentView) + .getColor(R.styleable.TaskContentView_hoverBorderColor, DEFAULT_BORDER_COLOR), + ) + } + + private var hoverBorderVisible = false + set(value) { + if (field == value) { + return + } + + field = value + + activeHoverAnimator?.cancel() + activeHoverAnimator = animateBorder(OUTLINE_EXPANSION_HOVER, hoverBorderAnimator, value) + } + /** * Sets the outline bounds of the view. Default to use view's bound as outline when set to null. */ @@ -111,6 +146,23 @@ class TaskContentView @JvmOverloads constructor(context: Context, attrs: Attribu invalidateOutline() } + private val outlineExpansionFactory: MultiPropertyFactory = + MultiPropertyFactory(this, OUTLINE_EXPANSION, OutlineExpansion.entries.size) { + a: Float, + b: Float -> + max(a, b) + } + private var outlineExpansionFocus by + MultiPropertyDelegate(outlineExpansionFactory, OutlineExpansion.FOCUS) + private var outlineExpansionHover by + MultiPropertyDelegate(outlineExpansionFactory, OutlineExpansion.HOVER) + + var isHoverable: Boolean = false; + + init { + setWillNotDraw(!enableCursorHoverStates()) + } + override fun onFinishInflate() { super.onFinishInflate() createTaskThumbnailView() @@ -162,6 +214,9 @@ class TaskContentView @JvmOverloads constructor(context: Context, attrs: Attribu timerUiState = TaskAppTimerUiState.Uninitialized timerTextHelper = null timerUsageAccessibilityAction = null + outlineExpansionHover = 0f + outlineExpansionFocus = 0f + hoverBorderVisible = false } fun doOnSizeChange(action: (width: Int, height: Int) -> Unit) { @@ -181,6 +236,9 @@ class TaskContentView @JvmOverloads constructor(context: Context, attrs: Attribu if (isFocusable()) { focusBorderAnimator.drawBorder(canvas) } + if (isHoverable) { + hoverBorderAnimator.drawBorder(canvas) + } } public override fun onFocusChanged( @@ -189,26 +247,23 @@ class TaskContentView @JvmOverloads constructor(context: Context, attrs: Attribu previouslyFocusedRect: Rect?, ) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect) - focusAnimator?.cancel() - val targetExpansion = - if (gainFocus) - context.resources - .getDimensionPixelSize(R.dimen.keyboard_quick_switch_border_width) - .toFloat() - else 0f + activeFocusAnimator?.cancel() + activeFocusAnimator = animateBorder(OUTLINE_EXPANSION_FOCUS, focusBorderAnimator, gainFocus) + } - val borderAnimator = focusBorderAnimator.buildAnimator(gainFocus) - val outlineExpansionAnimator = - ObjectAnimator.ofFloat(this, OUTLINE_EXPANSION, targetExpansion) - - focusAnimator = - AnimatorSet().apply { - playTogether(borderAnimator, outlineExpansionAnimator) - duration = borderAnimator.duration - interpolator = borderAnimator.interpolator - start() + override fun onHoverEvent(event: MotionEvent): Boolean { + if (enableCursorHoverStates() && isHoverable) { + when (event.action) { + MotionEvent.ACTION_HOVER_ENTER -> { + hoverBorderVisible = true + } + MotionEvent.ACTION_HOVER_EXIT -> { + hoverBorderVisible = false + } } + } + return super.onHoverEvent(event) } fun onParentAnimationProgress(progress: Float) { @@ -336,6 +391,23 @@ class TaskContentView @JvmOverloads constructor(context: Context, attrs: Attribu } } + private fun animateBorder( + outlineProperty: FloatProperty, + borderAnimator: BorderAnimator, + show: Boolean, + ): AnimatorSet? { + val targetOutlineExpansion = if (show) borderWidthPx.toFloat() else 0f + val outlineExpansionAnimator = + ObjectAnimator.ofFloat(this, outlineProperty, targetOutlineExpansion) + val borderEffectAnimator = borderAnimator.buildAnimator(show) + return AnimatorSet().apply { + playTogether(outlineExpansionAnimator, borderEffectAnimator) + duration = borderEffectAnimator.duration + interpolator = DEFAULT_INTERPOLATOR + start() + } + } + companion object { const val TAG = "TaskContentView" @@ -354,7 +426,16 @@ class TaskContentView @JvmOverloads constructor(context: Context, attrs: Attribu context.getString(R.string.split_app_usage_settings, taskDescription), ) + private enum class OutlineExpansion { + FOCUS, + HOVER, + } + private val OUTLINE_EXPANSION: FloatProperty = KFloatProperty(TaskContentView::outlineExpansion) + private val OUTLINE_EXPANSION_FOCUS: FloatProperty = + KFloatProperty(TaskContentView::outlineExpansionFocus) + private val OUTLINE_EXPANSION_HOVER: FloatProperty = + KFloatProperty(TaskContentView::outlineExpansionHover) } } diff --git a/quickstep/src/com/android/quickstep/util/BorderAnimator.kt b/quickstep/src/com/android/quickstep/util/BorderAnimator.kt index d1d47b9fa5..ac6e1ccc27 100644 --- a/quickstep/src/com/android/quickstep/util/BorderAnimator.kt +++ b/quickstep/src/com/android/quickstep/util/BorderAnimator.kt @@ -63,7 +63,7 @@ private constructor( const val DEFAULT_BORDER_COLOR = Color.WHITE private const val DEFAULT_APPEARANCE_ANIMATION_DURATION_MS = 300L private const val DEFAULT_DISAPPEARANCE_ANIMATION_DURATION_MS = 133L - private val DEFAULT_INTERPOLATOR = Interpolators.EMPHASIZED_DECELERATE + val DEFAULT_INTERPOLATOR = Interpolators.EMPHASIZED_DECELERATE /** * Creates a BorderAnimator that simply draws the border outside the bound of the target diff --git a/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt b/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt index 4845a9d01d..07fc1e6904 100644 --- a/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt +++ b/quickstep/src/com/android/quickstep/views/DesktopTaskView.kt @@ -405,6 +405,9 @@ class DesktopTaskView @JvmOverloads constructor(context: Context, attrs: Attribu taskContentView.setOnClickListener { launchTaskWithDesktopController(animated = true, task.key.id) } + if (taskContentView is TaskContentView) { + taskContentView.isHoverable = true + } } TaskContainer(