diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
index 19c686ed1..8c514f09c 100644
--- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
+++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
@@ -67,6 +67,9 @@ import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.*
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.IO
+import java.util.*
+import kotlin.concurrent.timerTask
+
class ReadBookActivity : BaseReadBookActivity(),
View.OnTouchListener,
@@ -403,6 +406,32 @@ class ReadBookActivity : BaseReadBookActivity(),
return super.dispatchKeyEvent(event)
}
+ /**
+ * 鼠标滚轮事件
+ */
+ override fun onGenericMotionEvent(event: MotionEvent): Boolean {
+ if (0 != (event.source and InputDevice.SOURCE_CLASS_POINTER)) {
+ if (event.action == MotionEvent.ACTION_SCROLL) {
+ val axisValue = event.getAxisValue(MotionEvent.AXIS_VSCROLL)
+ LogUtils.d("onGenericMotionEvent", "axisValue = $axisValue")
+ // 获得垂直坐标上的滚动方向
+ if (axisValue < 0.0f) { // 滚轮向下滚
+ debounce {
+ LogUtils.d("onGenericMotionEvent", "down")
+ mouseWheelPage(PageDirection.NEXT)
+ }
+ } else { // 滚轮向上滚
+ debounce {
+ LogUtils.d("onGenericMotionEvent", "up")
+ mouseWheelPage(PageDirection.PREV)
+ }
+ }
+ return true
+ }
+ }
+ return super.onGenericMotionEvent(event)
+ }
+
/**
* 按键事件
*/
@@ -635,6 +664,34 @@ class ReadBookActivity : BaseReadBookActivity(),
readView.isTextSelected = false
}
+ /**
+ * 防抖函数
+ */
+ private var timer: Timer? = null
+ private fun debounce(doThing: () -> Unit) {
+ timer?.cancel()
+ timer = Timer().apply {
+ schedule(timerTask {
+ doThing.invoke()
+ timer = null
+ }, 200)
+ }
+ }
+
+ /**
+ * 鼠标滚轮翻页
+ */
+ private fun mouseWheelPage(direction: PageDirection): Boolean {
+ if (!binding.readMenu.isVisible) {
+ if (getPrefBoolean("mouseWheelPage", true)) {
+ binding.readView.pageDelegate?.isCancel = false
+ binding.readView.pageDelegate?.keyTurnPage(direction)
+ return true
+ }
+ }
+ return false
+ }
+
/**
* 音量键翻页
*/
diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml
index 3c902c6a9..26fe3f5bc 100644
--- a/app/src/main/res/values-es-rES/strings.xml
+++ b/app/src/main/res/values-es-rES/strings.xml
@@ -192,6 +192,7 @@
Portada
Libro
Botones de volumen para pasar página
+ Rueda del ratón para pasar página
Toque la pantalla para pasar página
Animación de hojeada
Animación de hojeada (libro)
diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml
index a1a09f6f7..4b808acec 100644
--- a/app/src/main/res/values-ja-rJP/strings.xml
+++ b/app/src/main/res/values-ja-rJP/strings.xml
@@ -196,6 +196,7 @@
Cover
Book
Volume keys to turn page
+ Mouse wheel to turn page
Tap screen to turn page
Flip animation
Flip animation (book)
diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml
index a3d9f12c5..ce063bdc8 100644
--- a/app/src/main/res/values-pt-rBR/strings.xml
+++ b/app/src/main/res/values-pt-rBR/strings.xml
@@ -196,6 +196,7 @@
Capa
Livro
Botões de volume para virar páginas
+ Rolagem do mouse para virar páginas
Toque a tela para virar página
Virar animação
Virar animação (livro)
diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml
index 8bd464fcb..e766a58d6 100644
--- a/app/src/main/res/values-zh-rHK/strings.xml
+++ b/app/src/main/res/values-zh-rHK/strings.xml
@@ -193,6 +193,7 @@
封面
書
音量鍵翻頁
+ 鼠标滚动翻页
點擊翻頁
翻頁動畫
翻頁動畫(本書)
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml
index 9ac815bf4..cede2c668 100644
--- a/app/src/main/res/values-zh-rTW/strings.xml
+++ b/app/src/main/res/values-zh-rTW/strings.xml
@@ -195,6 +195,7 @@
封面
書
音量鍵翻頁
+ 鼠标滚动翻页
點擊翻頁
翻頁動畫
翻頁動畫(本書)
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index 6fd055716..df1d97d84 100644
--- a/app/src/main/res/values-zh/strings.xml
+++ b/app/src/main/res/values-zh/strings.xml
@@ -195,6 +195,7 @@
封面
书
音量键翻页
+ 鼠标滚轮翻页
点击翻页
翻页动画
翻页动画(本书)
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index d32d7d058..b245e0419 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -196,6 +196,7 @@
Cover
Book
Volume keys to turn page
+ Mouse wheel to turn page
Tap screen to turn page
Flip animation
Flip animation (book)
diff --git a/app/src/main/res/xml/pref_config_read.xml b/app/src/main/res/xml/pref_config_read.xml
index 1c8a29afb..aeb572e58 100644
--- a/app/src/main/res/xml/pref_config_read.xml
+++ b/app/src/main/res/xml/pref_config_read.xml
@@ -69,6 +69,13 @@
app:iconSpaceReserved="false"
app:isBottomBackground="true" />
+
+