2 Commity 5033b31495 ... d732c32ae7

Autor SHA1 Wiadomość Data
  Wayne Huang d732c32ae7 Merge branch '135-IllegalArgumentException-from-AdditionalPageReaderView-OnScroll' into 'master' 4 lat temu
  cooperku_kdanmobile 647a666fc6 Fix IllegalArgumentException from AdditionalPageReaderView::OnScroll 4 lat temu

+ 5 - 3
src/main/java/com/kdanmobile/reader/additionalpage/AdditionalPageReaderView.kt

@@ -4,6 +4,7 @@ import android.content.Context
 import android.graphics.PointF
 import android.view.MotionEvent
 import com.kdanmobile.kmpdfkit.pdfcommon.KMPDFReaderView
+import kotlin.math.abs
 
 /**
  * 客製化KMPDFReaderView
@@ -30,7 +31,7 @@ open class AdditionalPageReaderView(
     //  是否剛點擊螢幕?
     private var isJustTouch = false
 
-    override fun onScroll(e1: MotionEvent, e2: MotionEvent, distanceX: Float, distanceY: Float): Boolean {
+    override fun onScroll(e1: MotionEvent?, e2: MotionEvent?, distanceX: Float, distanceY: Float): Boolean {
         //  若使用者剛點擊螢幕,忽略該事件,避免畫面跳動
         if (mMode == Mode.Viewing && isJustTouch) {
             isJustTouch = false
@@ -39,7 +40,8 @@ open class AdditionalPageReaderView(
         return super.onScroll(e1, e2, distanceX, distanceY)
     }
 
-    override fun onInterceptTouchEvent(motionEvent: MotionEvent): Boolean {
+    override fun onInterceptTouchEvent(motionEvent: MotionEvent?): Boolean {
+        motionEvent ?: return true
         //  僅閱覽模式需要判斷
         val intercept = if (mMode == Mode.Viewing) {
             //  按下螢幕
@@ -52,7 +54,7 @@ open class AdditionalPageReaderView(
                 dragDistance = 0f
             }
             //  計算累計拖曳距離
-            dragDistance += Math.abs(motionEvent.x - touchPoint.x) + Math.abs(motionEvent.y - touchPoint.y)
+            dragDistance += abs(motionEvent.x - touchPoint.x) + abs(motionEvent.y - touchPoint.y)
             //  重設點擊位置
             touchPoint.set(motionEvent.x, motionEvent.y)