pull/37/head
kunfei 5 years ago
parent a01a2ac7a6
commit beb5850010
  1. 2
      app/src/main/java/io/legado/app/ui/widget/page/delegate/CoverPageDelegate.kt
  2. 53
      app/src/main/java/io/legado/app/ui/widget/page/delegate/HorizontalPageDelegate.kt
  3. 2
      app/src/main/java/io/legado/app/ui/widget/page/delegate/NoAnimPageDelegate.kt
  4. 87
      app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt
  5. 56
      app/src/main/java/io/legado/app/ui/widget/page/delegate/ScrollPageDelegate.kt
  6. 4
      app/src/main/java/io/legado/app/ui/widget/page/delegate/SimulationPageDelegate.kt
  7. 2
      app/src/main/java/io/legado/app/ui/widget/page/delegate/SlidePageDelegate.kt

@ -5,7 +5,7 @@ import android.graphics.Matrix
import android.graphics.drawable.GradientDrawable import android.graphics.drawable.GradientDrawable
import io.legado.app.ui.widget.page.PageView import io.legado.app.ui.widget.page.PageView
class CoverPageDelegate(pageView: PageView) : PageDelegate(pageView) { class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) {
private val shadowDrawableR: GradientDrawable private val shadowDrawableR: GradientDrawable
private val bitmapMatrix = Matrix() private val bitmapMatrix = Matrix()

@ -0,0 +1,53 @@
package io.legado.app.ui.widget.page.delegate
import android.view.MotionEvent
import io.legado.app.ui.widget.page.PageView
import io.legado.app.utils.screenshot
import kotlin.math.abs
abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageView) {
override fun onScroll(
e1: MotionEvent,
e2: MotionEvent,
distanceX: Float,
distanceY: Float
): Boolean {
if (!isMoved) {
val event = e1.toAction(MotionEvent.ACTION_UP)
curPage?.dispatchTouchEvent(event)
event.recycle()
if (abs(distanceX) > abs(distanceY)) {
if (distanceX < 0) {
//如果上一页不存在
if (!hasPrev()) {
noNext = true
return true
}
//上一页截图
bitmap = prevPage?.screenshot()
} else {
//如果不存在表示没有下一页了
if (!hasNext()) {
noNext = true
return true
}
//下一页截图
bitmap = nextPage?.screenshot()
}
isMoved = true
}
}
if (isMoved) {
isCancel = if (pageView.isScrollDelegate) {
if (direction == Direction.NEXT) distanceY < 0 else distanceY > 0
} else {
if (direction == Direction.NEXT) distanceX < 0 else distanceX > 0
}
isRunning = true
//设置触摸点
setTouchPoint(e2.x, e2.y)
}
return isMoved
}
}

@ -3,7 +3,7 @@ package io.legado.app.ui.widget.page.delegate
import android.graphics.Canvas import android.graphics.Canvas
import io.legado.app.ui.widget.page.PageView import io.legado.app.ui.widget.page.PageView
class NoAnimPageDelegate(pageView: PageView) : PageDelegate(pageView) { class NoAnimPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) {
override fun onScrollStart() { override fun onScrollStart() {
startScroll(touchX.toInt(), 0, 0, 0) startScroll(touchX.toInt(), 0, 0, 0)
} }

@ -56,8 +56,8 @@ abstract class PageDelegate(protected val pageView: PageView) {
) )
} }
private var isMoved = false var isMoved = false
private var noNext = true var noNext = true
//移动方向 //移动方向
var direction = Direction.NONE var direction = Direction.NONE
@ -212,6 +212,13 @@ abstract class PageDelegate(protected val pageView: PageView) {
open fun onPageUp() { open fun onPageUp() {
} }
abstract fun onScroll(
e1: MotionEvent,
e2: MotionEvent,
distanceX: Float,
distanceY: Float
): Boolean
enum class Direction { enum class Direction {
NONE, PREV, NEXT NONE, PREV, NEXT
} }
@ -271,87 +278,17 @@ abstract class PageDelegate(protected val pageView: PageView) {
distanceX: Float, distanceX: Float,
distanceY: Float distanceY: Float
): Boolean { ): Boolean {
if (pageView.isScrollDelegate) { return this@PageDelegate.onScroll(e1, e2, distanceX, distanceY)
if (!isMoved && abs(distanceX) < abs(distanceY)) {
if (distanceY < 0) {
if (atTop) {
val event = e1.toAction(MotionEvent.ACTION_UP)
curPage?.dispatchTouchEvent(event)
event.recycle()
//如果上一页不存在
if (!hasPrev()) {
noNext = true
return true
}
//上一页截图
bitmap = prevPage?.screenshot()
}
} else {
if (atBottom) {
val event = e1.toAction(MotionEvent.ACTION_UP)
curPage?.dispatchTouchEvent(event)
event.recycle()
//如果不存在表示没有下一页了
if (!hasNext()) {
noNext = true
return true
}
//下一页截图
bitmap = nextPage?.screenshot()
}
}
isMoved = true
}
if ((atTop && direction != Direction.PREV) || (atBottom && direction != Direction.NEXT) || direction == Direction.NONE) {
//传递触摸事件到textView
curPage?.dispatchTouchEvent(e2)
}
} else if (!isMoved) {
val event = e1.toAction(MotionEvent.ACTION_UP)
curPage?.dispatchTouchEvent(event)
event.recycle()
if (abs(distanceX) > abs(distanceY)) {
if (distanceX < 0) {
//如果上一页不存在
if (!hasPrev()) {
noNext = true
return true
}
//上一页截图
bitmap = prevPage?.screenshot()
} else {
//如果不存在表示没有下一页了
if (!hasNext()) {
noNext = true
return true
}
//下一页截图
bitmap = nextPage?.screenshot()
}
isMoved = true
}
}
if (isMoved) {
isCancel = if (pageView.isScrollDelegate) {
if (direction == Direction.NEXT) distanceY < 0 else distanceY > 0
} else {
if (direction == Direction.NEXT) distanceX < 0 else distanceX > 0
}
isRunning = true
//设置触摸点
setTouchPoint(e2.x, e2.y)
}
return isMoved
} }
} }
private fun hasPrev(): Boolean { fun hasPrev(): Boolean {
//上一页的参数配置 //上一页的参数配置
direction = Direction.PREV direction = Direction.PREV
return pageView.pageFactory?.hasPrev() == true return pageView.pageFactory?.hasPrev() == true
} }
private fun hasNext(): Boolean { fun hasNext(): Boolean {
//进行下一页的配置 //进行下一页的配置
direction = Direction.NEXT direction = Direction.NEXT
return pageView.pageFactory?.hasNext() == true return pageView.pageFactory?.hasNext() == true

@ -2,7 +2,10 @@ package io.legado.app.ui.widget.page.delegate
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.Matrix import android.graphics.Matrix
import android.view.MotionEvent
import io.legado.app.ui.widget.page.PageView import io.legado.app.ui.widget.page.PageView
import io.legado.app.utils.screenshot
import kotlin.math.abs
class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
@ -65,4 +68,57 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
} }
} }
override fun onScroll(
e1: MotionEvent,
e2: MotionEvent,
distanceX: Float,
distanceY: Float
): Boolean {
if (!isMoved && abs(distanceX) < abs(distanceY)) {
if (distanceY < 0) {
if (atTop) {
val event = e1.toAction(MotionEvent.ACTION_UP)
curPage?.dispatchTouchEvent(event)
event.recycle()
//如果上一页不存在
if (!hasPrev()) {
noNext = true
return true
}
//上一页截图
bitmap = prevPage?.screenshot()
}
} else {
if (atBottom) {
val event = e1.toAction(MotionEvent.ACTION_UP)
curPage?.dispatchTouchEvent(event)
event.recycle()
//如果不存在表示没有下一页了
if (!hasNext()) {
noNext = true
return true
}
//下一页截图
bitmap = nextPage?.screenshot()
}
}
isMoved = true
}
if ((atTop && direction != Direction.PREV) || (atBottom && direction != Direction.NEXT) || direction == Direction.NONE) {
//传递触摸事件到textView
curPage?.dispatchTouchEvent(e2)
}
if (isMoved) {
isCancel = if (pageView.isScrollDelegate) {
if (direction == Direction.NEXT) distanceY < 0 else distanceY > 0
} else {
if (direction == Direction.NEXT) distanceX < 0 else distanceX > 0
}
isRunning = true
//设置触摸点
setTouchPoint(e2.x, e2.y)
}
return isMoved
}
} }

@ -5,13 +5,15 @@ import android.view.MotionEvent
import io.legado.app.ui.widget.page.PageView import io.legado.app.ui.widget.page.PageView
import io.legado.app.ui.widget.page.curl.CurlPage import io.legado.app.ui.widget.page.curl.CurlPage
import io.legado.app.ui.widget.page.curl.CurlView import io.legado.app.ui.widget.page.curl.CurlView
import io.legado.app.utils.invisible
import io.legado.app.utils.screenshot import io.legado.app.utils.screenshot
class SimulationPageDelegate(pageView: PageView) : PageDelegate(pageView) { class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) {
init { init {
pageView.curlView ?: let { pageView.curlView ?: let {
pageView.curlView = CurlView(pageView.context) pageView.curlView = CurlView(pageView.context)
pageView.curlView?.invisible()
pageView.addView(pageView.curlView) pageView.addView(pageView.curlView)
pageView.curlView?.mPageProvider = PageProvider() pageView.curlView?.mPageProvider = PageProvider()
pageView.curlView?.setSizeChangedObserver(SizeChangedObserver()) pageView.curlView?.setSizeChangedObserver(SizeChangedObserver())

@ -4,7 +4,7 @@ import android.graphics.Canvas
import android.graphics.Matrix import android.graphics.Matrix
import io.legado.app.ui.widget.page.PageView import io.legado.app.ui.widget.page.PageView
class SlidePageDelegate(pageView: PageView) : PageDelegate(pageView) { class SlidePageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) {
private val bitmapMatrix = Matrix() private val bitmapMatrix = Matrix()

Loading…
Cancel
Save