Skip to content

Commit f18a94d

Browse files
committed
refactor:调整默认浮窗位置实现
1 parent 6b64d04 commit f18a94d

8 files changed

Lines changed: 22 additions & 22 deletions

File tree

floatingx/src/main/java/com/petterp/floatingx/imp/FxBasisControlImp.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ abstract class FxBasisControlImp<F : FxBasisHelper, P : IFxPlatformProvider<F>>(
4141
_configControl = createConfigProvider(helper, platformProvider)
4242
}
4343

44+
override fun getX() = getManagerView()?.x ?: -1f
45+
46+
override fun getY() = getManagerView()?.y ?: -1f
47+
4448
override fun show() {
4549
if (isShow()) return
4650
helper.enableFx = true

floatingx/src/main/java/com/petterp/floatingx/listener/control/IFxControl.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ interface IFxControl {
2828
*/
2929
fun cancel()
3030

31+
/** 获取x坐标 */
32+
fun getX(): Float
33+
34+
/** 获取y坐标 */
35+
fun getY(): Float
36+
3137
/** 获取正在显示的浮窗内容视图,即通过layoutId或者自定义View传递进来的 View */
3238
fun getView(): View?
3339

floatingx/src/main/java/com/petterp/floatingx/view/FxBasicContainerView.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ abstract class FxBasicContainerView @JvmOverloads constructor(
3333
internal val locationHelper = FxViewLocationHelper()
3434
private val helpers = listOf(locationHelper, touchHelper, animateHelper)
3535

36-
abstract fun currentX(): Float
37-
abstract fun currentY(): Float
3836
abstract fun updateXY(x: Float, y: Float)
3937
abstract fun parentSize(): Pair<Int, Int>?
4038

@@ -67,7 +65,7 @@ abstract class FxBasicContainerView @JvmOverloads constructor(
6765
}
6866

6967
override fun moveLocationByVector(x: Float, y: Float, useAnimation: Boolean) {
70-
safeMoveToXY(x + currentX(), y + currentY(), useAnimation)
68+
safeMoveToXY(x + this.x, y + this.y, useAnimation)
7169
}
7270

7371
override fun checkPointerDownTouch(id: Int, event: MotionEvent): Boolean {
@@ -198,8 +196,8 @@ abstract class FxBasicContainerView @JvmOverloads constructor(
198196
}
199197

200198
internal fun internalMoveToXY(endX: Float, endY: Float, useAnimation: Boolean = false) {
201-
val curX = currentX()
202-
val curY = currentY()
199+
val curX = this.x
200+
val curY = this.y
203201
if (curX == endX && curY == endY) return
204202
if (useAnimation) {
205203
animateHelper.start(endX, endY)

floatingx/src/main/java/com/petterp/floatingx/view/FxDefaultContainerView.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ class FxDefaultContainerView(helper: FxBasisHelper, context: Context, attrs: Att
3737
layoutParams = lp
3838
}
3939

40-
override fun currentX(): Float = x
41-
42-
override fun currentY(): Float = y
43-
4440
override fun updateXY(x: Float, y: Float) {
4541
this.x = x
4642
this.y = y

floatingx/src/main/java/com/petterp/floatingx/view/FxSystemContainerView.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class FxSystemContainerView @JvmOverloads constructor(
2929
private var isShowKeyBoard = false
3030
private lateinit var wl: WindowManager.LayoutParams
3131

32-
val isAttachToWM: Boolean
32+
private val isAttachToWM: Boolean
3333
get() = windowToken != null
3434

3535
override fun initView() {
@@ -46,13 +46,9 @@ class FxSystemContainerView @JvmOverloads constructor(
4646
}
4747
}
4848

49-
override fun currentX(): Float {
50-
return wl.x.toFloat()
51-
}
49+
override fun getX() = wl.x.toFloat()
5250

53-
override fun currentY(): Float {
54-
return wl.y.toFloat()
55-
}
51+
override fun getY() = wl.y.toFloat()
5652

5753
override fun preCheckPointerDownTouch(event: MotionEvent): Boolean {
5854
// 当前屏幕存在手指时,check当前手势是否真的在浮窗之上

floatingx/src/main/java/com/petterp/floatingx/view/helper/FxViewAnimationHelper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class FxViewAnimationHelper : FxViewBasicHelper() {
1515
private var endY: Float = 0f
1616

1717
fun start(endX: Float, endY: Float) {
18-
val startX = basicView?.currentX() ?: 0f
19-
val startY = basicView?.currentY() ?: 0f
18+
val startX = basicView?.x ?: 0f
19+
val startY = basicView?.y ?: 0f
2020
if (startX == endX && startY == endY) return
2121
this.startX = startX
2222
this.startY = startY

floatingx/src/main/java/com/petterp/floatingx/view/helper/FxViewLocationHelper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class FxViewLocationHelper : FxViewBasicHelper(), View.OnLayoutChangeListener {
3434

3535

3636
private val x: Float
37-
get() = basicView?.currentX() ?: 0f
37+
get() = basicView?.x ?: 0f
3838
private val y: Float
39-
get() = basicView?.currentY() ?: 0f
39+
get() = basicView?.y ?: 0f
4040

4141
private val Pair<Float, Float>.safeLocationXY: Pair<Float, Float>
4242
get() {

floatingx/src/main/java/com/petterp/floatingx/view/helper/FxViewTouchHelper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ class FxViewTouchHelper : FxViewBasicHelper() {
108108
// 不支持move时return掉
109109
if (!config.displayMode.canMove) return
110110
basicView?.onTouchMove(event)
111-
val x = basicView?.currentX() ?: -1f
112-
val y = basicView?.currentY() ?: -1f
111+
val x = basicView?.x ?: 0f
112+
val y = basicView?.y ?: 0f
113113
config.iFxTouchListener?.onDragIng(event, x, y)
114114
config.fxLog.v("fxView -> touchMove,x:$x,y:$y")
115115
}

0 commit comments

Comments
 (0)