Created
July 19, 2020 06:26
-
-
Save drakeet/a5c703a5ce39555034b5f08a82d0a022 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.graphics.Canvas | |
import android.graphics.Rect | |
import android.os.Build | |
import android.util.AttributeSet | |
import android.view.View | |
import java.util.* | |
/** | |
* @author Drakeet Xu | |
*/ | |
class GestureExclusionDemoView @JvmOverloads constructor( | |
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 | |
) : View(context, attrs, defStyleAttr) { | |
private val exRect = Collections.singletonList(Rect()) | |
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { | |
super.onLayout(changed, left, top, right, bottom) | |
if (changed) { | |
updateGestureExclusion() | |
} | |
} | |
override fun onDraw(canvas: Canvas?) { | |
super.onDraw(canvas) | |
updateGestureExclusion() | |
} | |
private fun updateGestureExclusion() { | |
// Skip this call if we're not running on Android 10+ | |
if (Build.VERSION.SDK_INT < 29) return | |
// Now lets work out which areas should be excluded | |
exRect.first().set(0, 0, width, height) | |
// Finally pass our updated list of rectangles to the system | |
systemGestureExclusionRects = exRect | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment