mirror of
https://github.com/fcitx5-android/fcitx5-android.git
synced 2026-08-02 20:16:06 +08:00
Inline shouldCollapse into NumberRow
This commit is contained in:
parent
6b938bc7a0
commit
2eefbf6b52
@ -334,12 +334,6 @@ class KawaiiBarComponent : UniqueViewComponent<KawaiiBarComponent, FrameLayout>(
|
||||
}
|
||||
}
|
||||
numberRow.apply {
|
||||
shouldCollapse = { start, current ->
|
||||
val dir = if (context.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR) 1 else -1
|
||||
val sx = start.x * dir
|
||||
val cx = current.x * dir
|
||||
cx > sx && abs(cx - sx) > dp(HEIGHT.toFloat())
|
||||
}
|
||||
onCollapseListener = {
|
||||
numberRowState = NumberRowState.ForceHide
|
||||
evalIdleUiState(fromUser = true)
|
||||
|
||||
@ -8,40 +8,35 @@ import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import org.fcitx.fcitx5.android.core.KeySym
|
||||
import org.fcitx.fcitx5.android.data.theme.Theme
|
||||
import android.graphics.PointF
|
||||
import android.view.MotionEvent
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewGroup.LayoutParams
|
||||
import org.fcitx.fcitx5.android.input.bar.KawaiiBarComponent
|
||||
import org.fcitx.fcitx5.android.input.keyboard.BaseKeyboard
|
||||
import org.fcitx.fcitx5.android.input.keyboard.KeyAction
|
||||
import org.fcitx.fcitx5.android.input.keyboard.KeyActionListener
|
||||
import org.fcitx.fcitx5.android.input.keyboard.KeyDef
|
||||
import org.fcitx.fcitx5.android.input.keyboard.CustomGestureView
|
||||
import org.fcitx.fcitx5.android.input.popup.PopupActionListener
|
||||
import kotlin.math.abs
|
||||
import splitties.dimensions.dp
|
||||
import timber.log.Timber
|
||||
import kotlin.math.abs
|
||||
|
||||
@SuppressLint("ViewConstructor")
|
||||
class NumberRow(ctx: Context, theme: Theme) : BaseKeyboard(ctx, theme, Layout) {
|
||||
|
||||
private var gestureStartEvent: MotionEvent? = null
|
||||
private var collapseGestureTriggerd: Boolean = false
|
||||
private var collapseGestureTriggered: Boolean = false
|
||||
|
||||
var onCollapseListener: (() -> Unit)? = null
|
||||
|
||||
// return true if the swipe distance is enough to trigger collapse
|
||||
var shouldCollapse: (start: PointF, current: PointF) -> Boolean = { _, _ -> false }
|
||||
|
||||
private fun checkGesture(ev: MotionEvent): Boolean {
|
||||
val startEvent = gestureStartEvent ?: return false
|
||||
val firstPointerId = startEvent.getPointerId(startEvent.actionIndex)
|
||||
if (ev.getPointerId(ev.actionIndex) == firstPointerId) {
|
||||
val start = PointF(startEvent.x, startEvent.y)
|
||||
val current = PointF(ev.getX(ev.actionIndex), ev.getY(ev.actionIndex))
|
||||
if (shouldCollapse(start, current)) {
|
||||
val dir = if (context.resources.configuration.layoutDirection == LAYOUT_DIRECTION_LTR) 1 else -1
|
||||
val sx = startEvent.x * dir
|
||||
val cx = ev.getX(ev.actionIndex) * dir
|
||||
val shouldCollapse = cx > sx && abs(cx - sx) > dp(KawaiiBarComponent.HEIGHT)
|
||||
if (shouldCollapse) {
|
||||
Timber.d("NumberRow: intercepted gesture from child keyboard to handle swipe")
|
||||
resetState()
|
||||
collapseGestureTriggerd = true
|
||||
collapseGestureTriggered = true
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -51,7 +46,7 @@ class NumberRow(ctx: Context, theme: Theme) : BaseKeyboard(ctx, theme, Layout) {
|
||||
private fun resetState() {
|
||||
gestureStartEvent?.recycle()
|
||||
gestureStartEvent = null
|
||||
collapseGestureTriggerd = false
|
||||
collapseGestureTriggered = false
|
||||
}
|
||||
|
||||
override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
|
||||
@ -65,13 +60,14 @@ class NumberRow(ctx: Context, theme: Theme) : BaseKeyboard(ctx, theme, Layout) {
|
||||
return super.onInterceptTouchEvent(ev)
|
||||
}
|
||||
|
||||
override fun onTouchEvent(ev: MotionEvent): Boolean {
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
var handled = false
|
||||
when (ev.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> gestureStartEvent = MotionEvent.obtain(ev)
|
||||
MotionEvent.ACTION_MOVE -> checkGesture(ev)
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> gestureStartEvent = MotionEvent.obtain(event)
|
||||
MotionEvent.ACTION_MOVE -> checkGesture(event)
|
||||
MotionEvent.ACTION_UP -> {
|
||||
if (collapseGestureTriggerd) {
|
||||
if (collapseGestureTriggered) {
|
||||
resetState()
|
||||
onCollapseListener?.invoke()
|
||||
handled = true
|
||||
@ -79,7 +75,7 @@ class NumberRow(ctx: Context, theme: Theme) : BaseKeyboard(ctx, theme, Layout) {
|
||||
}
|
||||
MotionEvent.ACTION_CANCEL -> resetState()
|
||||
}
|
||||
return super.onTouchEvent(ev) || handled
|
||||
return super.onTouchEvent(event) || handled
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user