diff --git a/aconfig/launcher.aconfig b/aconfig/launcher.aconfig index aafa1f61a8..ffde0d186d 100644 --- a/aconfig/launcher.aconfig +++ b/aconfig/launcher.aconfig @@ -471,3 +471,10 @@ flag { description: "Shows filtered set of widgets by default and an option to show all widgets in the widget picker" bug: "356127021" } + +flag { + name: "show_taskbar_pinning_popup_from_anywhere" + namespace: "launcher" + description: "Shows the pinning popup view after long-pressing or right-clicking anywhere on the pinned taskbar" + bug: "297325541" +} diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml index 8957e0d16e..9836172cb3 100644 --- a/quickstep/res/values/dimens.xml +++ b/quickstep/res/values/dimens.xml @@ -424,6 +424,7 @@ 300dp 16dp + 16dp 60dp diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt index b5a33147ce..69bc6bdb3d 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt @@ -31,21 +31,21 @@ import android.widget.LinearLayout import android.widget.Switch import androidx.core.view.postDelayed import com.android.app.animation.Interpolators.EMPHASIZED_ACCELERATE +import com.android.launcher3.Flags import com.android.launcher3.R import com.android.launcher3.popup.ArrowPopup import com.android.launcher3.popup.RoundedArrowDrawable import com.android.launcher3.util.DisplayController import com.android.launcher3.util.Themes import com.android.launcher3.views.ActivityContext +import kotlin.math.max +import kotlin.math.min /** Popup view with arrow for taskbar pinning */ class TaskbarDividerPopupView @JvmOverloads -constructor( - context: Context, - attrs: AttributeSet? = null, - defStyleAttr: Int = 0, -) : ArrowPopup(context, attrs, defStyleAttr) { +constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : + ArrowPopup(context, attrs, defStyleAttr) { companion object { private const val TAG = "TaskbarDividerPopupView" private const val DIVIDER_POPUP_CLOSING_DELAY = 333L @@ -55,24 +55,28 @@ constructor( fun createAndPopulate( view: View, taskbarActivityContext: TaskbarActivityContext, + horizontalPosition: Float, ): TaskbarDividerPopupView<*> { val taskMenuViewWithArrow = taskbarActivityContext.layoutInflater.inflate( R.layout.taskbar_divider_popup_menu, taskbarActivityContext.dragLayer, - false + false, ) as TaskbarDividerPopupView<*> - return taskMenuViewWithArrow.populateForView(view) + return taskMenuViewWithArrow.populateForView(view, horizontalPosition) } } private lateinit var dividerView: View + private var horizontalPosition = 0.0f private val popupCornerRadius = Themes.getDialogCornerRadius(context) private val arrowWidth = resources.getDimension(R.dimen.popup_arrow_width) private val arrowHeight = resources.getDimension(R.dimen.popup_arrow_height) private val arrowPointRadius = resources.getDimension(R.dimen.popup_arrow_corner_radius) + private val minPaddingFromScreenEdge = + resources.getDimension(R.dimen.taskbar_pinning_popup_menu_min_padding_from_screen_edge) private var alwaysShowTaskbarOn = !DisplayController.isTransientTaskbar(context) private var didPreferenceChange = false @@ -128,7 +132,15 @@ constructor( /** Orient object as usual and then center object horizontally. */ override fun orientAboutObject() { super.orientAboutObject() - x = mTempRect.centerX() - measuredWidth / 2f + x = + if (Flags.showTaskbarPinningPopupFromAnywhere()) { + min( + max(minPaddingFromScreenEdge, horizontalPosition - measuredWidth / 2f), + popupContainer.getWidth() - measuredWidth - minPaddingFromScreenEdge, + ) + } else { + mTempRect.centerX() - measuredWidth / 2f + } } override fun onControllerInterceptTouchEvent(ev: MotionEvent?): Boolean { @@ -142,8 +154,9 @@ constructor( return false } - private fun populateForView(view: View): TaskbarDividerPopupView<*> { + private fun populateForView(view: View, horizontalPosition: Float): TaskbarDividerPopupView<*> { dividerView = view + this@TaskbarDividerPopupView.horizontalPosition = horizontalPosition tryUpdateBackground() return this } @@ -169,15 +182,21 @@ constructor( override fun addArrow() { super.addArrow() - val location = IntArray(2) - popupContainer.getLocationInDragLayer(dividerView, location) - val dividerViewX = location[0].toFloat() - // Change arrow location to the middle of popup. - mArrow.x = (dividerViewX + dividerView.width / 2) - (mArrowWidth / 2) + if (Flags.showTaskbarPinningPopupFromAnywhere()) { + mArrow.x = horizontalPosition - mArrowWidth / 2 + } else { + val location = IntArray(2) + popupContainer.getLocationInDragLayer(dividerView, location) + val dividerViewX = location[0].toFloat() + // Change arrow location to the middle of popup. + mArrow.x = (dividerViewX + dividerView.width / 2) - (mArrowWidth / 2) + } } override fun updateArrowColor() { - if (!Gravity.isVertical(mGravity)) { + if (Flags.showTaskbarPinningPopupFromAnywhere()) { + super.updateArrowColor() + } else if (!Gravity.isVertical(mGravity)) { mArrow.background = RoundedArrowDrawable( arrowWidth, @@ -227,13 +246,13 @@ constructor( ObjectAnimator.ofFloat( this, TRANSLATION_Y, - *floatArrayOf(this.translationY, this.translationY + translateYValue) + *floatArrayOf(this.translationY, this.translationY + translateYValue), ) val arrowTranslateY = ObjectAnimator.ofFloat( mArrow, TRANSLATION_Y, - *floatArrayOf(mArrow.translationY, mArrow.translationY + translateYValue) + *floatArrayOf(mArrow.translationY, mArrow.translationY + translateYValue), ) val animatorSet = AnimatorSet() animatorSet.playTogether(alpha, arrowAlpha, translateY, arrowTranslateY) @@ -243,7 +262,7 @@ constructor( private fun getAnimatorOfFloat( view: View, property: Property, - vararg values: Float + vararg values: Float, ): Animator { val animator: Animator = ObjectAnimator.ofFloat(view, property, *values) animator.setDuration(DIVIDER_POPUP_CLOSING_ANIMATION_DURATION) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarPinningController.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarPinningController.kt index 1867cd08c0..7848b7e238 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarPinningController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarPinningController.kt @@ -76,10 +76,10 @@ class TaskbarPinningController(private val context: TaskbarActivityContext) : } } - fun showPinningView(view: View) { + fun showPinningView(view: View, horizontalPosition: Float = -1f) { context.isTaskbarWindowFullscreen = true view.post { - val popupView = getPopupView(view) + val popupView = getPopupView(view, horizontalPosition) popupView.requestFocus() popupView.onCloseCallback = onCloseCallback context.onPopupVisibilityChanged(true) @@ -89,8 +89,8 @@ class TaskbarPinningController(private val context: TaskbarActivityContext) : } @VisibleForTesting - fun getPopupView(view: View): TaskbarDividerPopupView<*> { - return createAndPopulate(view, context) + fun getPopupView(view: View, horizontalPosition: Float = -1f): TaskbarDividerPopupView<*> { + return createAndPopulate(view, context, horizontalPosition) } @VisibleForTesting diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java index 70dcfe8cf9..34b6a4ec0d 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java @@ -317,7 +317,8 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar if (mAllAppsButtonContainer != null) { mAllAppsButtonContainer.setUpCallbacks(callbacks); } - if (mTaskbarDividerContainer != null && callbacks.supportsDividerLongPress()) { + if (mTaskbarDividerContainer != null + && mActivityContext.getTaskbarFeatureEvaluator().getSupportsPinningPopup()) { mTaskbarDividerContainer.setUpCallbacks(callbacks); } if (mTaskbarOverflowView != null) { @@ -326,6 +327,10 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar mTaskbarOverflowView.setOnLongClickListener( mControllerCallbacks.getOverflowOnLongClickListener()); } + if (Flags.showTaskbarPinningPopupFromAnywhere() + && mActivityContext.getTaskbarFeatureEvaluator().getSupportsPinningPopup()) { + setOnTouchListener(mControllerCallbacks.getTaskbarTouchListener()); + } } private void removeAndRecycle(View view) { diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java index 8bc1e12395..4591f9b8bf 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java @@ -19,15 +19,19 @@ package com.android.launcher3.taskbar; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_ALLAPPS_BUTTON_LONG_PRESS; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_ALLAPPS_BUTTON_TAP; +import android.annotation.SuppressLint; import android.content.Context; +import android.view.GestureDetector; import android.view.InputDevice; import android.view.MotionEvent; import android.view.View; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.internal.jank.Cuj; import com.android.launcher3.taskbar.bubbles.BubbleBarViewController; +import com.android.launcher3.util.DisplayController; import com.android.systemui.shared.system.InteractionJankMonitorWrapper; import com.android.wm.shell.Flags; import com.android.wm.shell.shared.bubbles.BubbleBarLocation; @@ -40,12 +44,14 @@ public class TaskbarViewCallbacks { private final TaskbarActivityContext mActivity; private final TaskbarControllers mControllers; private final TaskbarView mTaskbarView; + private final GestureDetector mGestureDetector; public TaskbarViewCallbacks(TaskbarActivityContext activity, TaskbarControllers controllers, TaskbarView taskbarView) { mActivity = activity; mControllers = controllers; mTaskbarView = taskbarView; + mGestureDetector = new GestureDetector(activity, new TaskbarViewGestureListener()); } public View.OnClickListener getIconOnClickListener() { @@ -70,23 +76,23 @@ public class TaskbarViewCallbacks { return false; } - public View.OnLongClickListener getTaskbarDividerLongClickListener() { - return v -> { - mControllers.taskbarPinningController.showPinningView(v); - return true; - }; + @SuppressLint("ClickableViewAccessibility") + public View.OnTouchListener getTaskbarTouchListener() { + return (view, event) -> mGestureDetector.onTouchEvent(event); } - /** Check to see if we support long press on taskbar divider */ - public boolean supportsDividerLongPress() { - return !mActivity.isThreeButtonNav(); + public View.OnLongClickListener getTaskbarDividerLongClickListener() { + return v -> { + mControllers.taskbarPinningController.showPinningView(v, getDividerCenterX()); + return true; + }; } public View.OnTouchListener getTaskbarDividerRightClickListener() { return (v, event) -> { if (event.isFromSource(InputDevice.SOURCE_MOUSE) && event.getButtonState() == MotionEvent.BUTTON_SECONDARY) { - mControllers.taskbarPinningController.showPinningView(v); + mControllers.taskbarPinningController.showPinningView(v, getDividerCenterX()); return true; } return false; @@ -159,4 +165,32 @@ public class TaskbarViewCallbacks { } }; } + + private float getDividerCenterX() { + View divider = mTaskbarView.getTaskbarDividerViewContainer(); + if (divider == null) { + return 0.0f; + } + return divider.getX() + (float) divider.getWidth() / 2; + } + + private class TaskbarViewGestureListener extends GestureDetector.SimpleOnGestureListener { + @Override + public boolean onDown(@NonNull MotionEvent event) { + return true; + } + + @Override + public boolean onSingleTapUp(@NonNull MotionEvent event) { + return true; + } + + @Override + public void onLongPress(MotionEvent event) { + if (DisplayController.isPinnedTaskbar(mActivity)) { + mControllers.taskbarPinningController.showPinningView(mTaskbarView, + event.getRawX()); + } + } + } } diff --git a/quickstep/src/com/android/launcher3/taskbar/customization/TaskbarFeatureEvaluator.kt b/quickstep/src/com/android/launcher3/taskbar/customization/TaskbarFeatureEvaluator.kt index 7739a0e3df..f130d29ec1 100644 --- a/quickstep/src/com/android/launcher3/taskbar/customization/TaskbarFeatureEvaluator.kt +++ b/quickstep/src/com/android/launcher3/taskbar/customization/TaskbarFeatureEvaluator.kt @@ -23,9 +23,7 @@ import com.android.launcher3.util.DisplayController /** Evaluates all the features taskbar can have. */ class TaskbarFeatureEvaluator -private constructor( - private val taskbarActivityContext: TaskbarActivityContext, -) { +private constructor(private val taskbarActivityContext: TaskbarActivityContext) { val hasAllApps = true val hasAppIcons = true val hasBubbles = false @@ -43,6 +41,9 @@ private constructor( val isLandscape: Boolean get() = taskbarActivityContext.deviceProfile.isLandscape + val supportsPinningPopup: Boolean + get() = !hasNavButtons + fun onDestroy() { taskbarFeatureEvaluator = null } @@ -51,9 +52,7 @@ private constructor( @Volatile private var taskbarFeatureEvaluator: TaskbarFeatureEvaluator? = null @JvmStatic - fun getInstance( - taskbarActivityContext: TaskbarActivityContext, - ): TaskbarFeatureEvaluator { + fun getInstance(taskbarActivityContext: TaskbarActivityContext): TaskbarFeatureEvaluator { synchronized(this) { if (taskbarFeatureEvaluator == null) { taskbarFeatureEvaluator = TaskbarFeatureEvaluator(taskbarActivityContext)