[Android] Catch all exceptions on onFling callback

Geoffrey Métais git at videolan.org
Fri Jan 18 13:59:16 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jan 18 10:29:58 2019 +0100| [114d6c3fabbb3ee2bc7121dbf0088a4da8119b2d] | committer: Geoffrey Métais

Catch all exceptions on onFling callback

> https://code.videolan.org/videolan/vlc-android/commit/114d6c3fabbb3ee2bc7121dbf0088a4da8119b2d
---

 .../videolan/vlc/gui/video/VideoTouchDelegate.kt   | 30 ++++++++++++----------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt b/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt
index 869b74c3e..533d59b76 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt
@@ -8,6 +8,7 @@ import androidx.core.view.GestureDetectorCompat
 import androidx.core.view.ScaleGestureDetectorCompat
 import org.videolan.libvlc.MediaPlayer
 import org.videolan.medialibrary.Tools
+import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.R
 import org.videolan.vlc.util.AndroidDevices
 
@@ -362,24 +363,25 @@ class VideoTouchDelegate(private val player: VideoPlayerActivity,
             return false
         }
 
-        override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float ) = if (e1.x < screenConfig.metrics.widthPixels * 0.95) false
-        else try {
-            val diffY = e2.y - e1.y
-            val diffX = e2.x - e1.x
-            if (Math.abs(diffX) > Math.abs(diffY)) {
-                if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
-                    if (diffX > 0) onSwipeRight()
-                    else onSwipeLeft()
+        override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float ) = try {
+            if (e1.x < screenConfig.metrics.widthPixels * 0.95) false
+            else {
+                val diffY = e2.y - e1.y
+                val diffX = e2.x - e1.x
+                if (Math.abs(diffX) > Math.abs(diffY)) {
+                    if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
+                        if (diffX > 0) onSwipeRight()
+                        else onSwipeLeft()
+                        true
+                    } else false
+                } else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
+                    if (diffY > 0) onSwipeBottom()
+                    else onSwipeTop()
                     true
                 } else false
             }
-            else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
-                if (diffY > 0) onSwipeBottom()
-                else onSwipeTop()
-                true
-            } else false
         } catch (exception: Exception) {
-            exception.printStackTrace()
+            if (BuildConfig.DEBUG) exception.printStackTrace()
             false
         }
 



More information about the Android mailing list