From 443d0600d5d24b65133b2559e3eda2d66dc216f2 Mon Sep 17 00:00:00 2001 From: Saumya Prakash Date: Fri, 28 Jun 2024 19:04:26 +0000 Subject: [PATCH] Prevent Taskbar edu dismissal from touching outside of the window. In an effort to encourage users to look at Taskbar edu more thoroughly, this change makes it so users have to press the 'Done' button explicitly to close the taskbar edu window. This change also adds the ability for it to be dismissed by the back gesture. It only applies to the features edu, and not other taskbar educations. Fix: 349612575 Test: Manually run all versions of taskbar edu and ensure that the edu only goes away with back gesture, swipe up or clicking on the DONE button Flag: EXEMPT bugfix Change-Id: I9c456b9efddc6de5f292d6a14b1ce9daee7efaa3 Merged-In: I9c456b9efddc6de5f292d6a14b1ce9daee7efaa3 --- .../launcher3/taskbar/TaskbarEduTooltip.kt | 17 ++++++++++++++++- .../taskbar/TaskbarEduTooltipController.kt | 10 +++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltip.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltip.kt index c45c66741d..7f9d8a390e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltip.kt +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltip.kt @@ -27,6 +27,7 @@ import android.view.View import android.view.ViewGroup import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.animation.Interpolator +import android.window.OnBackInvokedDispatcher import androidx.core.view.updateLayoutParams import com.android.app.animation.Interpolators.EMPHASIZED_ACCELERATE import com.android.app.animation.Interpolators.EMPHASIZED_DECELERATE @@ -66,11 +67,14 @@ constructor( /** Container where the tooltip's body should be inflated. */ lateinit var content: ViewGroup private set + private lateinit var arrow: View /** Callback invoked when the tooltip is being closed. */ var onCloseCallback: () -> Unit = {} private var openCloseAnimator: AnimatorSet? = null + /** Used to set whether users can tap outside the current tooltip window to dismiss it */ + var allowTouchDismissal = true /** Animates the tooltip into view. */ fun show() { @@ -134,14 +138,25 @@ constructor( override fun isOfType(type: Int): Boolean = type and TYPE_TASKBAR_EDUCATION_DIALOG != 0 override fun onControllerInterceptTouchEvent(ev: MotionEvent?): Boolean { - if (ev?.action == ACTION_DOWN && !activityContext.dragLayer.isEventOverView(this, ev)) { + if ( + ev?.action == ACTION_DOWN && + !activityContext.dragLayer.isEventOverView(this, ev) && + allowTouchDismissal + ) { close(true) } return false } + override fun onAttachedToWindow() { + super.onAttachedToWindow() + findOnBackInvokedDispatcher() + ?.registerOnBackInvokedCallback(OnBackInvokedDispatcher.PRIORITY_DEFAULT, this) + } + override fun onDetachedFromWindow() { super.onDetachedFromWindow() + findOnBackInvokedDispatcher()?.unregisterOnBackInvokedCallback(this) Settings.Secure.putInt(mContext.contentResolver, LAUNCHER_TASKBAR_EDUCATION_SHOWING, 0) } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt index d43055d56a..19322c66a0 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt @@ -82,10 +82,13 @@ open class TaskbarEduTooltipController(context: Context) : open val shouldShowSearchEdu = false private val isTooltipEnabled: Boolean get() = !Utilities.isRunningInTestHarness() && !activityContext.isPhoneMode + private val isOpen: Boolean get() = tooltip?.isOpen ?: false + val isBeforeTooltipFeaturesStep: Boolean get() = isTooltipEnabled && tooltipStep <= TOOLTIP_STEP_FEATURES + private lateinit var controllers: TaskbarControllers // Keep track of whether the user has seen the Search Edu @@ -148,6 +151,7 @@ open class TaskbarEduTooltipController(context: Context) : tooltipStep = TOOLTIP_STEP_NONE inflateTooltip(R.layout.taskbar_edu_features) tooltip?.run { + allowTouchDismissal = false val splitscreenAnim = requireViewById(R.id.splitscreen_animation) val suggestionsAnim = requireViewById(R.id.suggestions_animation) val pinningAnim = requireViewById(R.id.pinning_animation) @@ -212,6 +216,7 @@ open class TaskbarEduTooltipController(context: Context) : inflateTooltip(R.layout.taskbar_edu_pinning) tooltip?.run { + allowTouchDismissal = true requireViewById(R.id.standalone_pinning_animation) .supportLightTheme() @@ -256,6 +261,7 @@ open class TaskbarEduTooltipController(context: Context) : userHasSeenSearchEdu = true inflateTooltip(R.layout.taskbar_edu_search) tooltip?.run { + allowTouchDismissal = true requireViewById(R.id.search_edu_animation).supportLightTheme() val eduSubtitle: TextView = requireViewById(R.id.search_edu_text) showDisclosureText(eduSubtitle) @@ -328,7 +334,9 @@ open class TaskbarEduTooltipController(context: Context) : } /** Closes the current [tooltip]. */ - fun hide() = tooltip?.close(true) + fun hide() { + tooltip?.close(true) + } /** Initializes [tooltip] with content from [contentResId]. */ private fun inflateTooltip(@LayoutRes contentResId: Int) {