add support for S Pen actions (#4029)

This commit is contained in:
Dominik Chrástecký
2020-11-21 04:25:24 +01:00
committed by GitHub
parent 122b2b1a8e
commit c9b1a425a7
6 changed files with 96 additions and 3 deletions

View File

@ -261,6 +261,17 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
super.onBackPressed()
}
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
if (keyCode == KeyEvent.KEYCODE_N) {
presenter.loadNextChapter()
return true
} else if (keyCode == KeyEvent.KEYCODE_P) {
presenter.loadPreviousChapter()
return true
}
return super.onKeyUp(keyCode, event)
}
/**
* Dispatches a key event. If the viewer doesn't handle it, call the default implementation.
*/

View File

@ -324,6 +324,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
*/
override fun handleKeyEvent(event: KeyEvent): Boolean {
val isUp = event.action == KeyEvent.ACTION_UP
val ctrlPressed = event.metaState.and(KeyEvent.META_CTRL_ON) > 0
when (event.keyCode) {
KeyEvent.KEYCODE_VOLUME_DOWN -> {
@ -340,8 +341,16 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
if (!config.volumeKeysInverted) moveUp() else moveDown()
}
}
KeyEvent.KEYCODE_DPAD_RIGHT -> if (isUp) moveRight()
KeyEvent.KEYCODE_DPAD_LEFT -> if (isUp) moveLeft()
KeyEvent.KEYCODE_DPAD_RIGHT -> {
if (isUp) {
if (ctrlPressed) moveToNext() else moveRight()
}
}
KeyEvent.KEYCODE_DPAD_LEFT -> {
if (isUp) {
if (ctrlPressed) moveToPrevious() else moveLeft()
}
}
KeyEvent.KEYCODE_DPAD_DOWN -> if (isUp) moveDown()
KeyEvent.KEYCODE_DPAD_UP -> if (isUp) moveUp()
KeyEvent.KEYCODE_PAGE_DOWN -> if (isUp) moveDown()