fix:修改房间PK面板拖拽实现方案(RTL适配问题)

fix:修改首页房间悬浮球实现方案(RTL适配问题)
This commit is contained in:
max
2024-06-14 14:55:06 +08:00
parent 634adc5f19
commit 80d852114c
5 changed files with 78 additions and 82 deletions

View File

@@ -12,10 +12,12 @@ import androidx.customview.widget.ViewDragHelper
import com.example.lib_utils.log.ILog
abstract class FloatDragWindowView : FrameLayout, ILog {
open class ViewDragLayout : FrameLayout, ILog {
private var dragHelper: ViewDragHelper? = null
private var syncPoint: Point? = null
companion object {
/**
* 新创建一个同步点
@@ -44,7 +46,7 @@ abstract class FloatDragWindowView : FrameLayout, ILog {
}
protected open fun onInitialize() {
// initDrag(this)
initDrag(this)
}
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
@@ -58,34 +60,24 @@ abstract class FloatDragWindowView : FrameLayout, ILog {
protected fun initDrag(parent: ViewGroup) {
val dragCallback = object : ViewDragCallback(parent) {
override fun onViewReleased(releasedChild: View, xvel: Float, yvel: Float) {
super.onViewReleased(releasedChild, xvel, yvel)
getDragSyncPoint()?.set(releasedChild.left, releasedChild.top)
override fun onViewPositionChanged(
changedView: View,
left: Int,
top: Int,
dx: Int,
dy: Int
) {
super.onViewPositionChanged(changedView, left, top, dx, dy)
getDragSyncPoint()?.set(left, top)
}
override fun tryCaptureView(child: View, pointerId: Int): Boolean {
return this@FloatDragWindowView.tryCaptureView(child, pointerId)
return this@ViewDragLayout.tryCaptureView(child, pointerId)
}
}
dragHelper = ViewDragHelper.create(parent, 1f, dragCallback)
}
/**
* 绑定容器
*/
internal fun bindLayout(parent: ViewGroup) {
if (parent.contains(this)) {
return
}
parent.addView(
this,
ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
)
}
/**
* 更新同步之前的位置
*/
@@ -95,22 +87,32 @@ abstract class FloatDragWindowView : FrameLayout, ILog {
// 该同步点是初始状态
return@let
}
getDragView().offsetLeftAndRight(it.x - getDragView().left)
getDragView().offsetTopAndBottom(it.y - getDragView().top)
val dragView = getDragView()?:return@let
dragView.offsetLeftAndRight(it.x - dragView.left)
dragView.offsetTopAndBottom(it.y - dragView.top)
}
}
abstract fun getDragView(): View
protected open fun getDragView(): View? {
return getChildAt(0)
}
/**
* 可以拖拽
*/
abstract fun tryCaptureView(child: View, pointerId: Int): Boolean
protected open fun tryCaptureView(child: View, pointerId: Int): Boolean{
return child == getDragView()
}
/**
* 拖拽位置同步记录
*/
abstract fun getDragSyncPoint(): Point?
protected open fun getDragSyncPoint(): Point? {
if (syncPoint == null) {
syncPoint = createDragSyncPoint()
}
return syncPoint
}
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
if (ev?.action == MotionEvent.ACTION_DOWN) {