|
|
@ -38,6 +38,9 @@ abstract class PageDelegate(protected val pageView: PageView) { |
|
|
|
|
|
|
|
|
|
|
|
protected var viewWidth: Int = pageView.width |
|
|
|
protected var viewWidth: Int = pageView.width |
|
|
|
protected var viewHeight: Int = pageView.height |
|
|
|
protected var viewHeight: Int = pageView.height |
|
|
|
|
|
|
|
//textView在顶端或低端 |
|
|
|
|
|
|
|
protected var atTop: Boolean = false |
|
|
|
|
|
|
|
protected var atBottom: Boolean = false |
|
|
|
|
|
|
|
|
|
|
|
private val scroller: Scroller by lazy { |
|
|
|
private val scroller: Scroller by lazy { |
|
|
|
Scroller( |
|
|
|
Scroller( |
|
|
@ -176,15 +179,21 @@ abstract class PageDelegate(protected val pageView: PageView) { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 触摸事件处理 |
|
|
|
* 触摸事件处理 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
open fun onTouch(event: MotionEvent): Boolean { |
|
|
|
fun onTouch(event: MotionEvent): Boolean { |
|
|
|
if (isStarted) return false |
|
|
|
if (isStarted) return false |
|
|
|
if (curPage?.isTextSelected() == true) { |
|
|
|
if (curPage?.isTextSelected() == true) { |
|
|
|
curPage?.dispatchTouchEvent(event) |
|
|
|
curPage?.dispatchTouchEvent(event) |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
if (event.action == MotionEvent.ACTION_DOWN) { |
|
|
|
if (event.action == MotionEvent.ACTION_DOWN) { |
|
|
|
curPage?.contentTextView()?.setTextIsSelectable(true) |
|
|
|
curPage?.let { |
|
|
|
curPage?.dispatchTouchEvent(event) |
|
|
|
it.contentTextView()?.let { contentTextView -> |
|
|
|
|
|
|
|
contentTextView.setTextIsSelectable(true) |
|
|
|
|
|
|
|
atTop = contentTextView.atTop() |
|
|
|
|
|
|
|
atBottom = contentTextView.atBottom() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
it.dispatchTouchEvent(event) |
|
|
|
|
|
|
|
} |
|
|
|
} else if (event.action == MotionEvent.ACTION_UP) { |
|
|
|
} else if (event.action == MotionEvent.ACTION_UP) { |
|
|
|
curPage?.dispatchTouchEvent(event) |
|
|
|
curPage?.dispatchTouchEvent(event) |
|
|
|
if (isMoved) { |
|
|
|
if (isMoved) { |
|
|
@ -276,36 +285,42 @@ abstract class PageDelegate(protected val pageView: PageView) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (pageView.isScrollDelegate()) { |
|
|
|
if (pageView.isScrollDelegate()) { |
|
|
|
//传递触摸事件到textView |
|
|
|
|
|
|
|
curPage?.dispatchTouchEvent(e2) |
|
|
|
|
|
|
|
if (!isMoved && abs(distanceX) < abs(distanceY)) { |
|
|
|
if (!isMoved && abs(distanceX) < abs(distanceY)) { |
|
|
|
if (distanceY < 0) { |
|
|
|
if (distanceY < 0) { |
|
|
|
//上一页的参数配置 |
|
|
|
if (atTop) { |
|
|
|
direction = Direction.PREV |
|
|
|
//上一页的参数配置 |
|
|
|
//判断是否上一页存在 |
|
|
|
direction = Direction.PREV |
|
|
|
val hasPrev = pageView.hasPrev() |
|
|
|
//判断是否上一页存在 |
|
|
|
//如果上一页不存在 |
|
|
|
val hasPrev = pageView.hasPrev() |
|
|
|
if (!hasPrev) { |
|
|
|
//如果上一页不存在 |
|
|
|
noNext = true |
|
|
|
if (!hasPrev) { |
|
|
|
return true |
|
|
|
noNext = true |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//上一页截图 |
|
|
|
|
|
|
|
bitmap = prevPage?.screenshot() |
|
|
|
} |
|
|
|
} |
|
|
|
//上一页截图 |
|
|
|
|
|
|
|
bitmap = prevPage?.screenshot() |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
//进行下一页的配置 |
|
|
|
if (atBottom) { |
|
|
|
direction = Direction.NEXT |
|
|
|
//进行下一页的配置 |
|
|
|
//判断是否下一页存在 |
|
|
|
direction = Direction.NEXT |
|
|
|
val hasNext = pageView.hasNext() |
|
|
|
//判断是否下一页存在 |
|
|
|
//如果不存在表示没有下一页了 |
|
|
|
val hasNext = pageView.hasNext() |
|
|
|
if (!hasNext) { |
|
|
|
//如果不存在表示没有下一页了 |
|
|
|
noNext = true |
|
|
|
if (!hasNext) { |
|
|
|
return true |
|
|
|
noNext = true |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//下一页截图 |
|
|
|
|
|
|
|
bitmap = nextPage?.screenshot() |
|
|
|
} |
|
|
|
} |
|
|
|
//下一页截图 |
|
|
|
|
|
|
|
bitmap = nextPage?.screenshot() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
isMoved = true |
|
|
|
isMoved = true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ((atTop && direction != Direction.PREV) || (atBottom && direction != Direction.NEXT) || direction == Direction.NONE) { |
|
|
|
|
|
|
|
//传递触摸事件到textView |
|
|
|
|
|
|
|
curPage?.dispatchTouchEvent(e2) |
|
|
|
|
|
|
|
} |
|
|
|
} else if (!isMoved && abs(distanceX) > abs(distanceY)) { |
|
|
|
} else if (!isMoved && abs(distanceX) > abs(distanceY)) { |
|
|
|
if (distanceX < 0) { |
|
|
|
if (distanceX < 0) { |
|
|
|
//上一页的参数配置 |
|
|
|
//上一页的参数配置 |
|
|
|