Skip to content

Instantly share code, notes, and snippets.

@drakeet
Created July 19, 2020 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drakeet/a5c703a5ce39555034b5f08a82d0a022 to your computer and use it in GitHub Desktop.
Save drakeet/a5c703a5ce39555034b5f08a82d0a022 to your computer and use it in GitHub Desktop.
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