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() {
|
private class MyGestureListener(private val flingListener: FlingListener) : GestureDetector.SimpleOnGestureListener() {
|
||||||
override fun onSingleTapUp(event: MotionEvent): Boolean {
|
override fun onSingleTapUp(event: MotionEvent?): Boolean {
|
||||||
(flingListener as MainActivity).homeScreenClicked(event.x, event.y)
|
if (event != null) {
|
||||||
|
(flingListener as MainActivity).homeScreenClicked(event.x, event.y)
|
||||||
|
}
|
||||||
return super.onSingleTapUp(event)
|
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
|
// ignore fling events just after releasing an icon from dragging
|
||||||
if (System.currentTimeMillis() - mLastUpEvent < 500L) {
|
if (System.currentTimeMillis() - mLastUpEvent < 500L) {
|
||||||
return true
|
return true
|
||||||
|
@ -443,8 +445,10 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLongPress(event: MotionEvent) {
|
override fun onLongPress(event: MotionEvent?) {
|
||||||
(flingListener as MainActivity).homeScreenLongPressed(event.x, event.y)
|
if (event != null) {
|
||||||
|
(flingListener as MainActivity).homeScreenLongPressed(event.x, event.y)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,11 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
||||||
setupAdapter(launchers)
|
setupAdapter(launchers)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
override fun onInterceptTouchEvent(event: MotionEvent?): Boolean {
|
||||||
|
if (event == null) {
|
||||||
|
return super.onInterceptTouchEvent(event)
|
||||||
|
}
|
||||||
|
|
||||||
if (ignoreTouches) {
|
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
|
// 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) {
|
if (lastTouchCoords.first != event.x || lastTouchCoords.second != event.y) {
|
||||||
|
|
|
@ -53,7 +53,11 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
|
||||||
setupAdapter(appWidgets)
|
setupAdapter(appWidgets)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
override fun onInterceptTouchEvent(event: MotionEvent?): Boolean {
|
||||||
|
if (event == null) {
|
||||||
|
return super.onInterceptTouchEvent(event)
|
||||||
|
}
|
||||||
|
|
||||||
if (ignoreTouches) {
|
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
|
// 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) {
|
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 {
|
override fun onInterceptTouchEvent(event: MotionEvent?): Boolean {
|
||||||
if (ignoreTouches) {
|
if (ignoreTouches || event == null) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue