Skip to content

Commit

Permalink
Merge pull request #202 from Petterpx/2.3.4
Browse files Browse the repository at this point in the history
2.3.4
  • Loading branch information
Petterpx authored Feb 10, 2025
2 parents f11d98f + 632200d commit 7ec8900
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import java.lang.ref.WeakReference
* @author petterp
*/
class FxAppLifecycleProvider : Application.ActivityLifecycleCallbacks {
override fun onActivityPostCreated(activity: Activity, savedInstanceState: Bundle?) {
updateTopActivity(activity)
}

override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
updateTopActivity(activity)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ abstract class FxBasisControlImp<F : FxBasisHelper, P : IFxPlatformProvider<F>>(
get() = platformProvider.internalView

override val configControl: IFxConfigControl get() = _configControl
override fun getX() = getManagerView()?.x ?: 0f
override fun getY() = getManagerView()?.y ?: 0f
override fun isShow() = platformProvider.isShow()
override fun getView() = internalView?.childView
override fun getViewHolder() = internalView?.viewHolder
override fun getManagerView() = internalView?.containerView
Expand Down Expand Up @@ -55,6 +58,7 @@ abstract class FxBasisControlImp<F : FxBasisHelper, P : IFxPlatformProvider<F>>(
}

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

override fun isShow() = platformProvider.isShow() == true

override fun updateView(@LayoutRes resource: Int) {
check(resource != INVALID_LAYOUT_ID) { "resource cannot be INVALID_LAYOUT_ID!" }
helper.layoutView = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ class FxSystemPlatformProvider(
internalView.isVisibility = false
}

override fun isShow(): Boolean {
val internalView = _internalView ?: return false
return internalView.isAttachToWM && internalView.visibility == View.VISIBLE
}

override fun checkOrInit(): Boolean {
if (_internalView != null) return true
checkOrRegisterActivityLifecycle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ interface IFxControl {
*/
fun cancel()

/** 获取相对浮窗容器的 x坐标 */
fun getX(): Float

/** 获取相对浮窗容器的 y坐标 */
fun getY(): Float

/** 获取正在显示的浮窗内容视图,即通过layoutId或者自定义View传递进来的 View */
fun getView(): View?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ package com.petterp.floatingx.listener.provider
import android.content.Context
import com.petterp.floatingx.assist.helper.FxBasisHelper
import com.petterp.floatingx.listener.control.IFxControl
import com.petterp.floatingx.util.isVisibility
import com.petterp.floatingx.view.IFxInternalHelper

interface IFxPlatformProvider<F : FxBasisHelper> : IFxBasicProvider<F> {
val context: Context?
val control: IFxControl?
val internalView: IFxInternalHelper?

fun isShow(): Boolean {
val containerView = internalView?.containerView ?: return false
return containerView.isAttachedToWindow && containerView.isVisibility
}

fun show()
fun hide()
fun isShow(): Boolean? = null
fun checkOrInit(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ abstract class FxBasicContainerView @JvmOverloads constructor(
internal val locationHelper = FxViewLocationHelper()
private val helpers = listOf(locationHelper, touchHelper, animateHelper)

abstract fun currentX(): Float
abstract fun currentY(): Float
abstract fun updateXY(x: Float, y: Float)
abstract fun parentSize(): Pair<Int, Int>?

Expand Down Expand Up @@ -67,7 +65,7 @@ abstract class FxBasicContainerView @JvmOverloads constructor(
}

override fun moveLocationByVector(x: Float, y: Float, useAnimation: Boolean) {
safeMoveToXY(x + currentX(), y + currentY(), useAnimation)
safeMoveToXY(x + this.x, y + this.y, useAnimation)
}

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

internal fun internalMoveToXY(endX: Float, endY: Float, useAnimation: Boolean = false) {
val curX = currentX()
val curY = currentY()
val curX = this.x
val curY = this.y
if (curX == endX && curY == endY) return
if (useAnimation) {
animateHelper.start(endX, endY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ class FxDefaultContainerView(helper: FxBasisHelper, context: Context, attrs: Att
layoutParams = lp
}

override fun currentX(): Float = x

override fun currentY(): Float = y

override fun updateXY(x: Float, y: Float) {
this.x = x
this.y = y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FxSystemContainerView @JvmOverloads constructor(
private var isShowKeyBoard = false
private lateinit var wl: WindowManager.LayoutParams

val isAttachToWM: Boolean
private val isAttachToWM: Boolean
get() = windowToken != null

override fun initView() {
Expand All @@ -46,13 +46,9 @@ class FxSystemContainerView @JvmOverloads constructor(
}
}

override fun currentX(): Float {
return wl.x.toFloat()
}
override fun getX() = wl.x.toFloat()

override fun currentY(): Float {
return wl.y.toFloat()
}
override fun getY() = wl.y.toFloat()

override fun preCheckPointerDownTouch(event: MotionEvent): Boolean {
// 当前屏幕存在手指时,check当前手势是否真的在浮窗之上
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class FxViewAnimationHelper : FxViewBasicHelper() {
private var endY: Float = 0f

fun start(endX: Float, endY: Float) {
val startX = basicView?.currentX() ?: 0f
val startY = basicView?.currentY() ?: 0f
val startX = basicView?.x ?: 0f
val startY = basicView?.y ?: 0f
if (startX == endX && startY == endY) return
this.startX = startX
this.startY = startY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class FxViewLocationHelper : FxViewBasicHelper(), View.OnLayoutChangeListener {


private val x: Float
get() = basicView?.currentX() ?: 0f
get() = basicView?.x ?: 0f
private val y: Float
get() = basicView?.currentY() ?: 0f
get() = basicView?.y ?: 0f

private val Pair<Float, Float>.safeLocationXY: Pair<Float, Float>
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ class FxViewTouchHelper : FxViewBasicHelper() {
// 不支持move时return掉
if (!config.displayMode.canMove) return
basicView?.onTouchMove(event)
val x = basicView?.currentX() ?: -1f
val y = basicView?.currentY() ?: -1f
val x = basicView?.x ?: 0f
val y = basicView?.y ?: 0f
config.iFxTouchListener?.onDragIng(event, x, y)
config.fxLog.v("fxView -> touchMove,x:$x,y:$y")
}
Expand Down

0 comments on commit 7ec8900

Please sign in to comment.