[6.7.0][运营面板] 代码部分提交

This commit is contained in:
renwj
2024-09-20 19:34:03 +08:00
parent b7e58d6c4e
commit 4a3fb0bb7e
34 changed files with 768 additions and 11 deletions

View File

@@ -4,6 +4,7 @@ import android.annotation.*
import android.app.Activity
import android.graphics.Rect
import android.graphics.drawable.ColorDrawable
import android.transition.Transition
import android.util.Log
import android.view.Gravity
import android.view.LayoutInflater
@@ -50,6 +51,10 @@ class MoGoPopWindow private constructor(builder: Builder){
private val onViewAttachedToWindow: ((content: View) -> Unit)? = builder.onViewAttachedToWindow
private val enterTransition: Transition? = builder.enterTransition
private val exitTransition: Transition? = builder.exitTransition
@SuppressLint("ClickableViewAccessibility") fun show() {
if (isPendingShow.get() || pop.isShowing) {
return
@@ -58,12 +63,18 @@ class MoGoPopWindow private constructor(builder: Builder){
activity.lifeCycleScope.launchWhenResumed {
val parent = activity.findViewById<View>(android.R.id.content) ?: throw AssertionError("附着的Activity上的ID为[android.R.id.content]的控件不存在.")
pop.contentView = content
pop.isAttachedInDecor = true
pop.isAttachedInDecor = false
pop.setBackgroundDrawable(ColorDrawable())
content.doOnAttach {
onViewAttachedToWindow?.invoke(content)
onShowed?.invoke()
}
if (enterTransition != null) {
pop.enterTransition = enterTransition
}
if (exitTransition != null) {
pop.exitTransition = exitTransition
}
pop.setOnDismissListener {
onDismissed?.invoke()
}
@@ -113,17 +124,11 @@ class MoGoPopWindow private constructor(builder: Builder){
val oldX = params.x
val oldY = params.y
Logger.d(TAG, "oldX: $oldX, oldY: $oldY, dx: $dx, dy:$dy")
var newX = oldX + dx
var newY = oldY + dy
val newX = oldX + dx
val newY = oldY + dy
if (outer.contains(rawX.toInt(), rawY.toInt())) {
val width = activity.resources.displayMetrics.widthPixels
val height = activity.resources.displayMetrics.heightPixels
// if (newX < 0) {
// newX += newX
// }
// if (newY < 0) {
// newY += height
// }
Logger.d(TAG, "screen_width: $width, screen_height: $height, newX: $newX, newY: $newY, rawX: ${rawX.toInt()}, rawY: ${rawY.toInt()}, width: ${content.width}, height: ${content.height}")
pop.update(newX, newY, content.width, content.height)
}
@@ -244,6 +249,16 @@ class MoGoPopWindow private constructor(builder: Builder){
*/
internal var onViewAttachedToWindow: ((content: View) -> Unit)? = null
/**
* 进场动画
*/
internal var enterTransition: Transition? = null
/**
* 出场动画
*/
internal var exitTransition: Transition? = null
fun contentView(content: View) = apply {
this.content = content
}
@@ -296,6 +311,11 @@ class MoGoPopWindow private constructor(builder: Builder){
this.onDismissed = block
}
fun transition(enter: Transition?, exit: Transition?) = apply {
this.enterTransition = enter
this.exitTransition = exit
}
fun onViewAttachedToWindow(block: (content: View) -> Unit) = apply {
this.onViewAttachedToWindow = block
}