pass grid clicks at the custom view

This commit is contained in:
tibbi 2022-09-17 19:31:04 +02:00
parent 889e70468e
commit 69dc2bcfcd
2 changed files with 15 additions and 0 deletions

View File

@ -150,11 +150,22 @@ class MainActivity : SimpleActivity(), FlingListener {
} }
} }
fun homeScreenClicked(x: Float, y: Float) {
if (x >= home_screen_grid.left && x <= home_screen_grid.right && y >= home_screen_grid.top && y <= home_screen_grid.bottom) {
home_screen_grid.gridClicked(x, y)
}
}
private fun showWidgetsFragment() { private fun showWidgetsFragment() {
showFragment(widgets_fragment) showFragment(widgets_fragment)
} }
private class MyGestureListener(private val flingListener: FlingListener) : GestureDetector.SimpleOnGestureListener() { private class MyGestureListener(private val flingListener: FlingListener) : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapConfirmed(event: MotionEvent): Boolean {
(flingListener as MainActivity).homeScreenClicked(event.x, event.y)
return super.onSingleTapConfirmed(event)
}
override fun onFling(event1: MotionEvent, event2: MotionEvent, velocityX: Float, velocityY: Float): Boolean { override fun onFling(event1: MotionEvent, event2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
if (velocityY > 0) { if (velocityY > 0) {
flingListener.onFlingDown() flingListener.onFlingDown()

View File

@ -59,4 +59,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
} }
} }
} }
fun gridClicked(x: Float, y: Float) {
}
} }