Confusion on resolve gesture conflict

164 Views Asked by At

I am now trying to resolve the conflict of gesture and DrawLayout. According to the document, to resolve the conflict, I should call DrawerLayout.setSystemGestureExclusionRects to specify the exclusion area Rect.

So I write the code like this:

override fun onDraw(c: Canvas?) {
    super.onDraw(c)

    updateGestureExclusion()
}

override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
    super.onLayout(changed, l, t, r, b)

    if (!changed) {
        return
    }
    updateGestureExclusion()
}

private fun updateGestureExclusion() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
        return
    }

    systemGestureExclusionRects = listOf(createSystemGestureExclusionRect())
}

private fun createSystemGestureExclusionRect(): Rect {
    val screenSize = ScreenUtils.getScreenSize()
    val height = screenSize.y
    val heightInDp = SizeUtils.px2dp(height.toFloat())

    return if (heightInDp <= 200) {
        Rect(0, 0, SizeUtils.dp2px(56f), height)
    } else {
        val topInDp = (heightInDp - 200) / 2f
        val top = SizeUtils.dp2px(topInDp)
        val bottom = top + SizeUtils.dp2px(199f)
        Rect(0, top, SizeUtils.dp2px(56f), bottom)
    }
}

I clip an 56dp * 200dp at the center-left of screen as systemGestureExclusionRect. Unforetunately, For Realme RMX2020 device, Android System recognize the area of left-top screen as systemGestureExclusionRect. Even if I change the exclusionRect, Android System still recognize the area of left-top screen as systemGestureExclusionRect.

I also checked the size of the rect area and it did not exceed the limit in the document.

What's wrong with my code and how to resolve the conflict correctly? Thank you! :)

0

There are 0 best solutions below