feat(ui): 添加触摸事件处理以推进叠层阶段
- 在 CompositeLayupResultActivity 中添加 MotionEvent 和 ViewConfiguration 导入 - 移除原有的 main 点击监听器逻辑 - 新增 advanceLayupStage 函数用于在不同 UI 模式间切换 - 实现触摸事件分发处理,支持通过触摸推进叠层阶段 - 添加触摸距离判断避免误触,使用 ViewConfiguration 的触摸范围阈值 - 在触摸抬起且未移动时触发叠层阶段推进功能
这个提交包含在:
父节点
19906ad222
当前提交
f3e32cc006
@ -4,6 +4,8 @@ import android.content.Intent
|
||||
import android.os.Environment
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.MotionEvent
|
||||
import android.view.ViewConfiguration
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@ -131,11 +133,6 @@ class CompositeLayupResultActivity : BaseActivity<ActivityCompositeLayupResultBi
|
||||
window.addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
binding.baseRecyclerView.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false)
|
||||
binding.baseRecyclerView.adapter = actionAdapter
|
||||
binding.main.setOnClickListener {
|
||||
if (uiMode == UiMode.LAYUP_WORKING) {
|
||||
applyMode(UiMode.CONFIRM_FINISH)
|
||||
}
|
||||
}
|
||||
viewModel.resultState.observe(this) { state ->
|
||||
when (state) {
|
||||
CompositeLayupResultState.LOADING -> {
|
||||
@ -253,6 +250,20 @@ class CompositeLayupResultActivity : BaseActivity<ActivityCompositeLayupResultBi
|
||||
applyMode(UiMode.LAYUP_PROMPT)
|
||||
}
|
||||
|
||||
private fun advanceLayupStage(): Boolean {
|
||||
return when (uiMode) {
|
||||
UiMode.LAYUP_PROMPT -> {
|
||||
applyMode(UiMode.LAYUP_WORKING)
|
||||
true
|
||||
}
|
||||
UiMode.LAYUP_WORKING -> {
|
||||
applyMode(UiMode.CONFIRM_FINISH)
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private fun retake() {
|
||||
binding.hint.text = "拍照中,请稍后..."
|
||||
isPhoto = true
|
||||
@ -291,6 +302,42 @@ class CompositeLayupResultActivity : BaseActivity<ActivityCompositeLayupResultBi
|
||||
private fun dpToPx(dp: Int): Int =
|
||||
(dp * resources.displayMetrics.density).toInt()
|
||||
|
||||
private var touchDownX = 0f
|
||||
private var touchDownY = 0f
|
||||
private var touchMoved = false
|
||||
private val touchSlop by lazy { ViewConfiguration.get(this).scaledTouchSlop.toFloat() }
|
||||
|
||||
override fun dispatchTouchEvent(event: MotionEvent?): Boolean {
|
||||
if (uiMode != UiMode.LAYUP_PROMPT && uiMode != UiMode.LAYUP_WORKING) {
|
||||
return super.dispatchTouchEvent(event)
|
||||
}
|
||||
when (event?.action) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
touchDownX = event.x
|
||||
touchDownY = event.y
|
||||
touchMoved = false
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
if (!touchMoved) {
|
||||
val deltaX = kotlin.math.abs(event.x - touchDownX)
|
||||
val deltaY = kotlin.math.abs(event.y - touchDownY)
|
||||
touchMoved = deltaX > touchSlop || deltaY > touchSlop
|
||||
}
|
||||
}
|
||||
MotionEvent.ACTION_UP -> {
|
||||
if (!touchMoved && advanceLayupStage()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
MotionEvent.ACTION_CANCEL -> touchMoved = true
|
||||
}
|
||||
return super.dispatchTouchEvent(event)
|
||||
}
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent?): Boolean {
|
||||
return super.onTouchEvent(event)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
GlassMediaServiceHelper.addPhotoCallback(photoCallback)
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户