mirror of
https://github.com/fcitx5-android/fcitx5-android.git
synced 2026-08-02 04:44:35 +08:00
Merge b24280c815a012c99187e72bfd54042332a71302 into bcb694384de8462302448cab6a3dfb1853ba5d5e
This commit is contained in:
commit
726718a843
@ -85,6 +85,9 @@ abstract class BaseKeyboard(
|
||||
*/
|
||||
private val touchTarget = hashMapOf<Int, View>()
|
||||
|
||||
private data class KeyActionState(val viewId: Int, val action: KeyAction)
|
||||
private var keyActionStateBuffer: KeyActionState? = null
|
||||
|
||||
init {
|
||||
isMotionEventSplittingEnabled = true
|
||||
keyRows = keyLayout.map { row ->
|
||||
@ -208,8 +211,27 @@ abstract class BaseKeyboard(
|
||||
def.behaviors.forEach {
|
||||
when (it) {
|
||||
is KeyDef.Behavior.Press -> {
|
||||
setOnClickListener { _ ->
|
||||
onAction(it.action)
|
||||
keyPressListener = object : CustomGestureView.KeyPressListener {
|
||||
override fun onKeyDown(view: CustomGestureView) {
|
||||
keyActionStateBuffer?.let { state ->
|
||||
onAction(state.action)
|
||||
keyActionStateBuffer = null
|
||||
}
|
||||
keyActionStateBuffer = KeyActionState(view.id, it.action)
|
||||
}
|
||||
override fun onKeyUp(view: CustomGestureView) {
|
||||
keyActionStateBuffer?.let { state ->
|
||||
if (view.id == state.viewId) {
|
||||
onAction(state.action)
|
||||
keyActionStateBuffer = null
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun onLongPress(view: CustomGestureView) {
|
||||
if (view.id == keyActionStateBuffer?.viewId) {
|
||||
keyActionStateBuffer = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
is KeyDef.Behavior.LongPress -> {
|
||||
@ -280,7 +302,10 @@ abstract class BaseKeyboard(
|
||||
is KeyDef.Popup.Keyboard -> {
|
||||
setOnLongClickListener { view ->
|
||||
view as KeyView
|
||||
onPopupAction(PopupAction.ShowKeyboardAction(view.id, it, view.bounds))
|
||||
// only last key pressed will show the popup
|
||||
if (view.id == keyActionStateBuffer?.viewId) {
|
||||
onPopupAction(PopupAction.ShowKeyboardAction(view.id, it, view.bounds))
|
||||
}
|
||||
// do not consume this LongClick gesture
|
||||
false
|
||||
}
|
||||
|
||||
@ -23,6 +23,14 @@ import org.fcitx.fcitx5.android.input.keyboard.CustomGestureView.OnGestureListen
|
||||
|
||||
open class CustomGestureView(ctx: Context) : FrameLayout(ctx) {
|
||||
|
||||
interface KeyPressListener {
|
||||
fun onKeyDown(view: CustomGestureView)
|
||||
fun onKeyUp(view: CustomGestureView)
|
||||
fun onLongPress(view: CustomGestureView)
|
||||
}
|
||||
|
||||
var keyPressListener: KeyPressListener? = null
|
||||
|
||||
enum class SwipeAxis { X, Y }
|
||||
|
||||
enum class GestureType { Down, Move, Up }
|
||||
@ -177,6 +185,7 @@ open class CustomGestureView(ctx: Context) : FrameLayout(ctx) {
|
||||
swipeLastX = x
|
||||
swipeLastY = y
|
||||
}
|
||||
keyPressListener?.onKeyDown(this)
|
||||
}
|
||||
MotionEvent.ACTION_UP -> {
|
||||
isPressed = false
|
||||
@ -202,6 +211,10 @@ open class CustomGestureView(ctx: Context) : FrameLayout(ctx) {
|
||||
} else {
|
||||
performClick()
|
||||
}
|
||||
keyPressListener?.onKeyUp(this)
|
||||
}
|
||||
if (longPressEnabled) {
|
||||
keyPressListener?.onLongPress(this)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user