增加手柄支持
增加手柄方向键及左摇杆翻页的支持
This commit is contained in:
1 parent
0b9ce9ddef
commit
fa64ca6b1f
1 file changed
+25
@@ -780,6 +780,21 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 手柄摇杆控制翻页
|
||||||
|
if (0 != (event.source and InputDevice.SOURCE_CLASS_JOYSTICK)) {
|
||||||
|
if (event.action == MotionEvent.ACTION_MOVE) {
|
||||||
|
// 左摇杆上下移动控制翻页
|
||||||
|
val yAxis = event.getAxisValue(MotionEvent.AXIS_Y)
|
||||||
|
if (Math.abs(yAxis) > 0.5f) { // 死区设置
|
||||||
|
if (yAxis > 0) { // 摇杆向下
|
||||||
|
handleKeyPage(PageDirection.NEXT, false)
|
||||||
|
} else { // 摇杆向上
|
||||||
|
handleKeyPage(PageDirection.PREV, false)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return super.onGenericMotionEvent(event)
|
return super.onGenericMotionEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -825,6 +840,16 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
handleKeyPage(PageDirection.NEXT, longPress)
|
handleKeyPage(PageDirection.NEXT, longPress)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
// 手柄方向键控制翻页
|
||||||
|
KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_LEFT -> {
|
||||||
|
handleKeyPage(PageDirection.PREV, longPress)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT -> {
|
||||||
|
handleKeyPage(PageDirection.NEXT, longPress)
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onKeyDown(keyCode, event)
|
return super.onKeyDown(keyCode, event)
|
||||||
|
|||||||
Reference in new issue
Block a user