adding some null checks around touch events
This commit is contained in:
parent
6fc579afe2
commit
5d3a886fd1
|
@ -424,12 +424,14 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
}
|
||||
|
||||
private class MyGestureListener(private val flingListener: FlingListener) : GestureDetector.SimpleOnGestureListener() {
|
||||
override fun onSingleTapUp(event: MotionEvent): Boolean {
|
||||
(flingListener as MainActivity).homeScreenClicked(event.x, event.y)
|
||||
override fun onSingleTapUp(event: MotionEvent?): Boolean {
|
||||
if (event != null) {
|
||||
(flingListener as MainActivity).homeScreenClicked(event.x, event.y)
|
||||
}
|
||||
return super.onSingleTapUp(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 {
|
||||
// ignore fling events just after releasing an icon from dragging
|
||||
if (System.currentTimeMillis() - mLastUpEvent < 500L) {
|
||||
return true
|
||||
|
@ -443,8 +445,10 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
return true
|
||||
}
|
||||
|
||||
override fun onLongPress(event: MotionEvent) {
|
||||
(flingListener as MainActivity).homeScreenLongPressed(event.x, event.y)
|
||||
override fun onLongPress(event: MotionEvent?) {
|
||||
if (event != null) {
|
||||
(flingListener as MainActivity).homeScreenLongPressed(event.x, event.y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,11 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
setupAdapter(launchers)
|
||||
}
|
||||
|
||||
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
||||
override fun onInterceptTouchEvent(event: MotionEvent?): Boolean {
|
||||
if (event == null) {
|
||||
return super.onInterceptTouchEvent(event)
|
||||
}
|
||||
|
||||
if (ignoreTouches) {
|
||||
// some devices ACTION_MOVE keeps triggering for the whole long press duration, but we are interested in real moves only, when coords change
|
||||
if (lastTouchCoords.first != event.x || lastTouchCoords.second != event.y) {
|
||||
|
|
|
@ -53,7 +53,11 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
|||
setupAdapter(appWidgets)
|
||||
}
|
||||
|
||||
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
||||
override fun onInterceptTouchEvent(event: MotionEvent?): Boolean {
|
||||
if (event == null) {
|
||||
return super.onInterceptTouchEvent(event)
|
||||
}
|
||||
|
||||
if (ignoreTouches) {
|
||||
// some devices ACTION_MOVE keeps triggering for the whole long press duration, but we are interested in real moves only, when coords change
|
||||
if (lastTouchCoords.first != event.x || lastTouchCoords.second != event.y) {
|
||||
|
|
|
@ -28,8 +28,8 @@ class MyAppWidgetHostView(context: Context) : AppWidgetHostView(context) {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
||||
if (ignoreTouches) {
|
||||
override fun onInterceptTouchEvent(event: MotionEvent?): Boolean {
|
||||
if (ignoreTouches || event == null) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue