|
@@ -4,6 +4,7 @@ import android.content.Context
|
|
import android.graphics.PointF
|
|
import android.graphics.PointF
|
|
import android.view.MotionEvent
|
|
import android.view.MotionEvent
|
|
import com.kdanmobile.kmpdfkit.pdfcommon.KMPDFReaderView
|
|
import com.kdanmobile.kmpdfkit.pdfcommon.KMPDFReaderView
|
|
|
|
+import kotlin.math.abs
|
|
|
|
|
|
/**
|
|
/**
|
|
* 客製化KMPDFReaderView
|
|
* 客製化KMPDFReaderView
|
|
@@ -30,7 +31,7 @@ open class AdditionalPageReaderView(
|
|
// 是否剛點擊螢幕?
|
|
// 是否剛點擊螢幕?
|
|
private var isJustTouch = false
|
|
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) {
|
|
if (mMode == Mode.Viewing && isJustTouch) {
|
|
isJustTouch = false
|
|
isJustTouch = false
|
|
@@ -39,7 +40,8 @@ open class AdditionalPageReaderView(
|
|
return super.onScroll(e1, e2, distanceX, distanceY)
|
|
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) {
|
|
val intercept = if (mMode == Mode.Viewing) {
|
|
// 按下螢幕
|
|
// 按下螢幕
|
|
@@ -52,7 +54,7 @@ open class AdditionalPageReaderView(
|
|
dragDistance = 0f
|
|
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)
|
|
touchPoint.set(motionEvent.x, motionEvent.y)
|
|
|
|
|