Skip to content

Commit 7ec8900

Browse files
authored
Merge pull request #202 from Petterpx/2.3.4
2.3.4
2 parents f11d98f + 632200d commit 7ec8900

11 files changed

Lines changed: 33 additions & 30 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import java.lang.ref.WeakReference
1010
* @author petterp
1111
*/
1212
class FxAppLifecycleProvider : Application.ActivityLifecycleCallbacks {
13+
override fun onActivityPostCreated(activity: Activity, savedInstanceState: Bundle?) {
14+
updateTopActivity(activity)
15+
}
16+
1317
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
1418
updateTopActivity(activity)
1519
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ abstract class FxBasisControlImp<F : FxBasisHelper, P : IFxPlatformProvider<F>>(
2727
get() = platformProvider.internalView
2828

2929
override val configControl: IFxConfigControl get() = _configControl
30+
override fun getX() = getManagerView()?.x ?: 0f
31+
override fun getY() = getManagerView()?.y ?: 0f
32+
override fun isShow() = platformProvider.isShow()
3033
override fun getView() = internalView?.childView
3134
override fun getViewHolder() = internalView?.viewHolder
3235
override fun getManagerView() = internalView?.containerView
@@ -55,6 +58,7 @@ abstract class FxBasisControlImp<F : FxBasisHelper, P : IFxPlatformProvider<F>>(
5558
}
5659

5760
override fun hide() {
61+
// 这里同时增加判断状态,因为有可能view正在等待postAttach
5862
if (!isShow()) return
5963
helper.enableFx = false
6064
val fxView = getManagerView() ?: return
@@ -80,8 +84,6 @@ abstract class FxBasisControlImp<F : FxBasisHelper, P : IFxPlatformProvider<F>>(
8084
}
8185
}
8286

83-
override fun isShow() = platformProvider.isShow() == true
84-
8587
override fun updateView(@LayoutRes resource: Int) {
8688
check(resource != INVALID_LAYOUT_ID) { "resource cannot be INVALID_LAYOUT_ID!" }
8789
helper.layoutView = null

floatingx/src/main/java/com/petterp/floatingx/imp/system/FxSystemPlatformProvider.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ class FxSystemPlatformProvider(
4747
internalView.isVisibility = false
4848
}
4949

50-
override fun isShow(): Boolean {
51-
val internalView = _internalView ?: return false
52-
return internalView.isAttachToWM && internalView.visibility == View.VISIBLE
53-
}
54-
5550
override fun checkOrInit(): Boolean {
5651
if (_internalView != null) return true
5752
checkOrRegisterActivityLifecycle()

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/listener/provider/IFxPlatformProvider.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@ package com.petterp.floatingx.listener.provider
33
import android.content.Context
44
import com.petterp.floatingx.assist.helper.FxBasisHelper
55
import com.petterp.floatingx.listener.control.IFxControl
6+
import com.petterp.floatingx.util.isVisibility
67
import com.petterp.floatingx.view.IFxInternalHelper
78

89
interface IFxPlatformProvider<F : FxBasisHelper> : IFxBasicProvider<F> {
910
val context: Context?
1011
val control: IFxControl?
1112
val internalView: IFxInternalHelper?
13+
14+
fun isShow(): Boolean {
15+
val containerView = internalView?.containerView ?: return false
16+
return containerView.isAttachedToWindow && containerView.isVisibility
17+
}
18+
1219
fun show()
1320
fun hide()
14-
fun isShow(): Boolean? = null
1521
fun checkOrInit(): Boolean
1622
}

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() {

0 commit comments

Comments
 (0)