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

Commit b41574aa authored by Juan Sebastian Martinez's avatar Juan Sebastian Martinez
Browse files

Avoiding click dispatching after long-clicks on QS tiles.

When the QSLongPressEffect is enabled, the a no-op long-click listener
is added to the view so that the long-click gesture is fully consumed.
This avoids clicks from being dispacthed by the View when the tiles are
long-pressed.

Test: manual. Verified no clicks are detected after a long-press is
  processed.
Test: atest QSTileViewImplTest
Flag: com.android.systemui.quick_settings_visual_haptics_longpress
Bug: 367952297
Change-Id: Idebe980e23bcba41a69e1f0f27f137d4607116c0
parent 20792fe6
Loading
Loading
Loading
Loading
+15 −18
Original line number Original line Diff line number Diff line
@@ -126,12 +126,12 @@ constructor(
    private val overlayColorActive =
    private val overlayColorActive =
        Utils.applyAlpha(
        Utils.applyAlpha(
            /* alpha= */ 0.11f,
            /* alpha= */ 0.11f,
            Utils.getColorAttrDefaultColor(context, R.attr.onShadeActive)
            Utils.getColorAttrDefaultColor(context, R.attr.onShadeActive),
        )
        )
    private val overlayColorInactive =
    private val overlayColorInactive =
        Utils.applyAlpha(
        Utils.applyAlpha(
            /* alpha= */ 0.08f,
            /* alpha= */ 0.08f,
            Utils.getColorAttrDefaultColor(context, R.attr.onShadeInactive)
            Utils.getColorAttrDefaultColor(context, R.attr.onShadeInactive),
        )
        )


    private val colorLabelActive = Utils.getColorAttrDefaultColor(context, R.attr.onShadeActive)
    private val colorLabelActive = Utils.getColorAttrDefaultColor(context, R.attr.onShadeActive)
@@ -188,10 +188,7 @@ constructor(
    private var lastState = INVALID
    private var lastState = INVALID
    private var lastIconTint = 0
    private var lastIconTint = 0
    private val launchableViewDelegate =
    private val launchableViewDelegate =
        LaunchableViewDelegate(
        LaunchableViewDelegate(this, superSetVisibility = { super.setVisibility(it) })
            this,
            superSetVisibility = { super.setVisibility(it) },
        )
    private var lastDisabledByPolicy = false
    private var lastDisabledByPolicy = false


    private val locInScreen = IntArray(2)
    private val locInScreen = IntArray(2)
@@ -418,7 +415,7 @@ constructor(
            initLongPressEffectCallback()
            initLongPressEffectCallback()
            init(
            init(
                { _: View -> longPressEffect.onTileClick() },
                { _: View -> longPressEffect.onTileClick() },
                null, // Haptics and long-clicks will be handled by the [QSLongPressEffect]
                { _: View -> true }, // Haptics and long-clicks are handled by [QSLongPressEffect]
            )
            )
        } else {
        } else {
            val expandable = Expandable.fromView(this)
            val expandable = Expandable.fromView(this)
@@ -583,7 +580,7 @@ constructor(
                    AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK.id,
                    AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK.id,
                    resources.getString(
                    resources.getString(
                        R.string.accessibility_tile_disabled_by_policy_action_description
                        R.string.accessibility_tile_disabled_by_policy_action_description
                    )
                    ),
                )
                )
            )
            )
        } else {
        } else {
@@ -591,7 +588,7 @@ constructor(
                info.addAction(
                info.addAction(
                    AccessibilityNodeInfo.AccessibilityAction(
                    AccessibilityNodeInfo.AccessibilityAction(
                        AccessibilityNodeInfo.AccessibilityAction.ACTION_LONG_CLICK.id,
                        AccessibilityNodeInfo.AccessibilityAction.ACTION_LONG_CLICK.id,
                        resources.getString(R.string.accessibility_long_click_tile)
                        resources.getString(R.string.accessibility_long_click_tile),
                    )
                    )
                )
                )
            }
            }
@@ -716,35 +713,35 @@ constructor(
                state.spec,
                state.spec,
                state.state,
                state.state,
                state.disabledByPolicy,
                state.disabledByPolicy,
                getBackgroundColorForState(state.state, state.disabledByPolicy)
                getBackgroundColorForState(state.state, state.disabledByPolicy),
            )
            )
            if (allowAnimations) {
            if (allowAnimations) {
                singleAnimator.setValues(
                singleAnimator.setValues(
                    colorValuesHolder(
                    colorValuesHolder(
                        BACKGROUND_NAME,
                        BACKGROUND_NAME,
                        backgroundColor,
                        backgroundColor,
                        getBackgroundColorForState(state.state, state.disabledByPolicy)
                        getBackgroundColorForState(state.state, state.disabledByPolicy),
                    ),
                    ),
                    colorValuesHolder(
                    colorValuesHolder(
                        LABEL_NAME,
                        LABEL_NAME,
                        label.currentTextColor,
                        label.currentTextColor,
                        getLabelColorForState(state.state, state.disabledByPolicy)
                        getLabelColorForState(state.state, state.disabledByPolicy),
                    ),
                    ),
                    colorValuesHolder(
                    colorValuesHolder(
                        SECONDARY_LABEL_NAME,
                        SECONDARY_LABEL_NAME,
                        secondaryLabel.currentTextColor,
                        secondaryLabel.currentTextColor,
                        getSecondaryLabelColorForState(state.state, state.disabledByPolicy)
                        getSecondaryLabelColorForState(state.state, state.disabledByPolicy),
                    ),
                    ),
                    colorValuesHolder(
                    colorValuesHolder(
                        CHEVRON_NAME,
                        CHEVRON_NAME,
                        chevronView.imageTintList?.defaultColor ?: 0,
                        chevronView.imageTintList?.defaultColor ?: 0,
                        getChevronColorForState(state.state, state.disabledByPolicy)
                        getChevronColorForState(state.state, state.disabledByPolicy),
                    ),
                    ),
                    colorValuesHolder(
                    colorValuesHolder(
                        OVERLAY_NAME,
                        OVERLAY_NAME,
                        backgroundOverlayColor,
                        backgroundOverlayColor,
                        getOverlayColorForState(state.state)
                        getOverlayColorForState(state.state),
                    )
                    ),
                )
                )
                singleAnimator.start()
                singleAnimator.start()
            } else {
            } else {
@@ -753,7 +750,7 @@ constructor(
                    getLabelColorForState(state.state, state.disabledByPolicy),
                    getLabelColorForState(state.state, state.disabledByPolicy),
                    getSecondaryLabelColorForState(state.state, state.disabledByPolicy),
                    getSecondaryLabelColorForState(state.state, state.disabledByPolicy),
                    getChevronColorForState(state.state, state.disabledByPolicy),
                    getChevronColorForState(state.state, state.disabledByPolicy),
                    getOverlayColorForState(state.state)
                    getOverlayColorForState(state.state),
                )
                )
            }
            }
        }
        }
@@ -1077,7 +1074,7 @@ constructor(
            backgroundColor,
            backgroundColor,
            label.currentTextColor,
            label.currentTextColor,
            secondaryLabel.currentTextColor,
            secondaryLabel.currentTextColor,
            chevronView.imageTintList?.defaultColor ?: 0
            chevronView.imageTintList?.defaultColor ?: 0,
        )
        )


    inner class StateChangeRunnable(private val state: QSTile.State) : Runnable {
    inner class StateChangeRunnable(private val state: QSTile.State) : Runnable {