新增 "鼠标滚轮翻页"

Add 'Mouse wheel page'
pull/2016/head
Kevin SuTJ 2 years ago
parent b17e5c7043
commit 0e55d89101
  1. 57
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 1
      app/src/main/res/values-es-rES/strings.xml
  3. 1
      app/src/main/res/values-ja-rJP/strings.xml
  4. 1
      app/src/main/res/values-pt-rBR/strings.xml
  5. 1
      app/src/main/res/values-zh-rHK/strings.xml
  6. 1
      app/src/main/res/values-zh-rTW/strings.xml
  7. 1
      app/src/main/res/values-zh/strings.xml
  8. 1
      app/src/main/res/values/strings.xml
  9. 7
      app/src/main/res/xml/pref_config_read.xml

@ -67,6 +67,9 @@ import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import java.util.*
import kotlin.concurrent.timerTask
class ReadBookActivity : BaseReadBookActivity(), class ReadBookActivity : BaseReadBookActivity(),
View.OnTouchListener, View.OnTouchListener,
@ -403,6 +406,32 @@ class ReadBookActivity : BaseReadBookActivity(),
return super.dispatchKeyEvent(event) 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 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
}
/** /**
* 音量键翻页 * 音量键翻页
*/ */

@ -192,6 +192,7 @@
<string name="img_cover">Portada</string> <string name="img_cover">Portada</string>
<string name="book">Libro</string> <string name="book">Libro</string>
<string name="volume_key_page">Botones de volumen para pasar página</string> <string name="volume_key_page">Botones de volumen para pasar página</string>
<string name="mouse_wheel_page">Rueda del ratón para pasar página</string>
<string name="click_turn_page">Toque la pantalla para pasar página</string> <string name="click_turn_page">Toque la pantalla para pasar página</string>
<string name="page_anim">Animación de hojeada</string> <string name="page_anim">Animación de hojeada</string>
<string name="book_page_anim">Animación de hojeada (libro)</string> <string name="book_page_anim">Animación de hojeada (libro)</string>

@ -196,6 +196,7 @@
<string name="img_cover">Cover</string> <string name="img_cover">Cover</string>
<string name="book">Book</string> <string name="book">Book</string>
<string name="volume_key_page">Volume keys to turn page</string> <string name="volume_key_page">Volume keys to turn page</string>
<string name="mouse_wheel_page">Mouse wheel to turn page</string>
<string name="click_turn_page">Tap screen to turn page</string> <string name="click_turn_page">Tap screen to turn page</string>
<string name="page_anim">Flip animation</string> <string name="page_anim">Flip animation</string>
<string name="book_page_anim">Flip animation (book)</string> <string name="book_page_anim">Flip animation (book)</string>

@ -196,6 +196,7 @@
<string name="img_cover">Capa</string> <string name="img_cover">Capa</string>
<string name="book">Livro</string> <string name="book">Livro</string>
<string name="volume_key_page">Botões de volume para virar páginas</string> <string name="volume_key_page">Botões de volume para virar páginas</string>
<string name="mouse_wheel_page">Rolagem do mouse para virar páginas</string>
<string name="click_turn_page">Toque a tela para virar página</string> <string name="click_turn_page">Toque a tela para virar página</string>
<string name="page_anim">Virar animação</string> <string name="page_anim">Virar animação</string>
<string name="book_page_anim">Virar animação (livro)</string> <string name="book_page_anim">Virar animação (livro)</string>

@ -193,6 +193,7 @@
<string name="img_cover">封面</string> <string name="img_cover">封面</string>
<string name="book"></string> <string name="book"></string>
<string name="volume_key_page">音量鍵翻頁</string> <string name="volume_key_page">音量鍵翻頁</string>
<string name="mouse_wheel_page">鼠标滚动翻页</string>
<string name="click_turn_page">點擊翻頁</string> <string name="click_turn_page">點擊翻頁</string>
<string name="page_anim">翻頁動畫</string> <string name="page_anim">翻頁動畫</string>
<string name="book_page_anim">翻頁動畫(本書)</string> <string name="book_page_anim">翻頁動畫(本書)</string>

@ -195,6 +195,7 @@
<string name="img_cover">封面</string> <string name="img_cover">封面</string>
<string name="book"></string> <string name="book"></string>
<string name="volume_key_page">音量鍵翻頁</string> <string name="volume_key_page">音量鍵翻頁</string>
<string name="mouse_wheel_page">鼠标滚动翻页</string>
<string name="click_turn_page">點擊翻頁</string> <string name="click_turn_page">點擊翻頁</string>
<string name="page_anim">翻頁動畫</string> <string name="page_anim">翻頁動畫</string>
<string name="book_page_anim">翻頁動畫(本書)</string> <string name="book_page_anim">翻頁動畫(本書)</string>

@ -195,6 +195,7 @@
<string name="img_cover">封面</string> <string name="img_cover">封面</string>
<string name="book"></string> <string name="book"></string>
<string name="volume_key_page">音量键翻页</string> <string name="volume_key_page">音量键翻页</string>
<string name="mouse_wheel_page">鼠标滚轮翻页</string>
<string name="click_turn_page">点击翻页</string> <string name="click_turn_page">点击翻页</string>
<string name="page_anim">翻页动画</string> <string name="page_anim">翻页动画</string>
<string name="book_page_anim">翻页动画(本书)</string> <string name="book_page_anim">翻页动画(本书)</string>

@ -196,6 +196,7 @@
<string name="img_cover">Cover</string> <string name="img_cover">Cover</string>
<string name="book">Book</string> <string name="book">Book</string>
<string name="volume_key_page">Volume keys to turn page</string> <string name="volume_key_page">Volume keys to turn page</string>
<string name="mouse_wheel_page">Mouse wheel to turn page</string>
<string name="click_turn_page">Tap screen to turn page</string> <string name="click_turn_page">Tap screen to turn page</string>
<string name="page_anim">Flip animation</string> <string name="page_anim">Flip animation</string>
<string name="book_page_anim">Flip animation (book)</string> <string name="book_page_anim">Flip animation (book)</string>

@ -69,6 +69,13 @@
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
app:isBottomBackground="true" /> app:isBottomBackground="true" />
<io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="true"
android:title="@string/mouse_wheel_page"
android:key="mouseWheelPage"
app:iconSpaceReserved="false"
app:isBottomBackground="true" />
<io.legado.app.lib.prefs.SwitchPreference <io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:title="@string/volume_key_page" android:title="@string/volume_key_page"

Loading…
Cancel
Save