修复弹窗提示bug
The specified child already has a parent. You must call removeView() on the child's parent first.

Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
donghongyu
2022-03-24 14:26:39 +08:00
parent 31e4ee1681
commit 01fc438a61
2 changed files with 13 additions and 9 deletions

View File

@@ -19,7 +19,7 @@ adb pull /sdcard/Android/data/com.mogo.launcher.f/log/20211022
// (新的HMI)使用命令行触发 V2X 预警场景
// 顶部弹窗场景,控制展示
adb shell am broadcast -a com.hmi.v2x.notification --ez v2xIsShow true --es tag "200011" --ei v2xType 20011 --es alertContent "测试外部传入数据" --es ttsContent "测试TTS"
adb shell am broadcast -a com.hmi.v2x.notification --ez v2xIsShow true --es tag "200012" --ei v2xType 20012 --es alertContent "测试外部传入数据2" --es ttsContent "测试TTS2"
// 关闭顶部弹窗
adb shell am broadcast -a com.hmi.v2x.notification --ez v2xIsShow false --es tag "200011"

View File

@@ -7,17 +7,15 @@ import android.app.Service
import android.content.Context
import android.graphics.PixelFormat
import android.graphics.Rect
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import com.mogo.eagle.core.function.hmi.notification.anim.AnimatorManager
import android.view.*
import com.mogo.eagle.core.data.enums.ShowPattern
import com.mogo.eagle.core.function.hmi.notification.anim.AnimatorManager
import com.mogo.eagle.core.function.hmi.notification.widget.ParentFrameLayout
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_HMI
import com.mogo.eagle.core.utilcode.util.WindowUtils
/**
* @author donghongyu
* @date 2021/8/5 5:29 下午
@@ -89,12 +87,18 @@ internal class WarningFloatWindowHelper(
frameLayout = ParentFrameLayout(context, config)
frameLayout?.tag = config.floatTag
// 将浮窗布局文件添加到父容器frameLayout中并返回该浮窗文件
val floatingView = config.layoutView?.also { frameLayout?.addView(it) }
?: LayoutInflater.from(context).inflate(config.layoutId!!, frameLayout, true)
val floatingView = config.layoutView?.also {
try {
val parent = (it.parent as ViewGroup)
parent.removeView(it)
} catch (e: Exception) {
e.printStackTrace()
}
frameLayout?.addView(it)
} ?: LayoutInflater.from(context).inflate(config.layoutId!!, frameLayout, true)
// 为了避免创建的时候闪一下我们先隐藏视图不能直接设置GONE否则定位会出现问题
floatingView.visibility = View.INVISIBLE
// 将frameLayout添加到系统windowManager中
windowManager.addView(frameLayout, params)
// 在浮窗绘制完成的时候,设置初始坐标、执行入场动画