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

Commit a1826751 authored by Artsiom Mitrokhin's avatar Artsiom Mitrokhin Committed by Android (Google) Code Review
Browse files

Merge "Open taskbar pinning popup view from anywhere" into main

parents fb172faa ab7220c3
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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"
}
+1 −0
Original line number Diff line number Diff line
@@ -424,6 +424,7 @@
    <!--- Taskbar Pinning -->
    <dimen name="taskbar_pinning_popup_menu_width">300dp</dimen>
    <dimen name="taskbar_pinning_popup_menu_vertical_margin">16dp</dimen>
    <dimen name="taskbar_pinning_popup_menu_min_padding_from_screen_edge">16dp</dimen>

    <!--- Floating Ime Inset height-->
    <dimen name="floating_ime_inset_height">60dp</dimen>
+37 −18
Original line number Diff line number Diff line
@@ -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<T : TaskbarActivityContext>
@JvmOverloads
constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0,
) : ArrowPopup<T>(context, attrs, defStyleAttr) {
constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
    ArrowPopup<T>(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()
        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<View, Float>,
        vararg values: Float
        vararg values: Float,
    ): Animator {
        val animator: Animator = ObjectAnimator.ofFloat(view, property, *values)
        animator.setDuration(DIVIDER_POPUP_CLOSING_ANIMATION_DURATION)
+4 −4
Original line number Diff line number Diff line
@@ -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
+6 −1
Original line number Diff line number Diff line
@@ -316,7 +316,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) {
@@ -325,6 +326,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) {
Loading