From 9810e1844e902c18bb6e3a94d2e276a5878f0e71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Fri, 6 Aug 2021 20:55:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DAndroid=2011=20=E9=80=82?= =?UTF-8?q?=E9=85=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +- .../notification/WarningFloatWindowHelper.kt | 162 +++++++++--------- .../mogo/module/hmi/ui/MoGoWarningFragment.kt | 1 + 3 files changed, 88 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 5fd1a290e3..1317da39a7 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ adb shell // (新的HMI)使用命令行触发 V2X 预警场景 // 顶部弹窗场景,控制展示 -adb shell am broadcast -a com.hmi.v2x.notification --ez v2xIsShow true --es tag "20008" --ei v2xType 20008 --es alertContent "测试外部传入数据" --es ttsContent "测试TTS" +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 false --es tag "20008" @@ -32,3 +32,6 @@ adb shell am broadcast -a com.v2x.adas_data_broadcast --es ADASData right // 调用应用内的模拟 adb shell am broadcast -a com.mogo.mock --ei oper 46 + +// 小智语音 +adb shell am broadcast -a com.zhidao.auto.txz.receiver --es text "欢迎乘坐’蘑菇车联‘无人驾驶小巴车" --ei speakType 5 \ No newline at end of file diff --git a/modules/mogo-module-hmi/src/main/java/com/mogo/module/hmi/notification/WarningFloatWindowHelper.kt b/modules/mogo-module-hmi/src/main/java/com/mogo/module/hmi/notification/WarningFloatWindowHelper.kt index 6d33cdd2b4..be7baaefd5 100644 --- a/modules/mogo-module-hmi/src/main/java/com/mogo/module/hmi/notification/WarningFloatWindowHelper.kt +++ b/modules/mogo-module-hmi/src/main/java/com/mogo/module/hmi/notification/WarningFloatWindowHelper.kt @@ -70,79 +70,6 @@ internal class WarningFloatWindowHelper( } } - /** - * 设置浮窗的对齐方式,支持上下左右、居中、上中、下中、左中和右中,默认左上角 - * 支持手动设置的偏移量 - */ - @SuppressLint("RtlHardcoded") - private fun setGravity(view: View?) { - if (config.locationPair != Pair(0, 0) || view == null) return - val parentRect = Rect() - // 获取浮窗所在的矩形 - windowManager.defaultDisplay.getRectSize(parentRect) - val location = IntArray(2) - // 获取在整个屏幕内的绝对坐标 - view.getLocationOnScreen(location) - // 通过绝对高度和相对高度比较,判断包含顶部状态栏 - val statusBarHeight = - if (location[1] > params.y) WindowUtils.getStatusBarHeight(view.context.applicationContext) else 0 - val parentBottom = - WindowUtils.getScreenHeight(view.context.applicationContext) - statusBarHeight - when (config.gravity) { - // 右上 - Gravity.END, Gravity.END or Gravity.TOP, Gravity.RIGHT, Gravity.RIGHT or Gravity.TOP -> - params.x = parentRect.right - view.width - // 左下 - Gravity.START or Gravity.BOTTOM, Gravity.BOTTOM, Gravity.LEFT or Gravity.BOTTOM -> - params.y = parentBottom - view.height - // 右下 - Gravity.END or Gravity.BOTTOM, Gravity.RIGHT or Gravity.BOTTOM -> { - params.x = parentRect.right - view.width - params.y = parentBottom - view.height - } - // 居中 - Gravity.CENTER -> { - params.x = (parentRect.right - view.width).shr(1) - params.y = (parentBottom - view.height).shr(1) - } - // 上中 - Gravity.CENTER_HORIZONTAL, Gravity.TOP or Gravity.CENTER_HORIZONTAL -> - params.x = (parentRect.right - view.width).shr(1) - // 下中 - Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL -> { - params.x = (parentRect.right - view.width).shr(1) - params.y = parentBottom - view.height - } - // 左中 - Gravity.CENTER_VERTICAL, Gravity.START or Gravity.CENTER_VERTICAL, Gravity.LEFT or Gravity.CENTER_VERTICAL -> - params.y = (parentBottom - view.height).shr(1) - // 右中 - Gravity.END or Gravity.CENTER_VERTICAL, Gravity.RIGHT or Gravity.CENTER_VERTICAL -> { - params.x = parentRect.right - view.width - params.y = (parentBottom - view.height).shr(1) - } - // 其他情况,均视为左上 - else -> { - } - } - - // 设置偏移量 - params.x += config.offsetPair.first - params.y += config.offsetPair.second - - if (config.immersionStatusBar) { - if (config.showPattern != ShowPattern.CURRENT_ACTIVITY) { - params.y -= statusBarHeight - } - } else { - if (config.showPattern == ShowPattern.CURRENT_ACTIVITY) { - params.y += statusBarHeight - } - } - // 更新浮窗位置信息 - windowManager.updateViewLayout(view, params) - } - /** * 添加视图 */ @@ -162,12 +89,14 @@ internal class WarningFloatWindowHelper( frameLayout?.layoutListener = object : ParentFrameLayout.OnLayoutListener { override fun onLayout() { setGravity(frameLayout) - config.apply { - enterAnim(floatingView) - // 设置callbacks - layoutView = floatingView - callbacks?.createdResult(true, null, floatingView) - } + frameLayout?.postDelayed({ + config.apply { + enterAnim(floatingView) + // 设置callbacks + layoutView = floatingView + callbacks?.createdResult(true, null, floatingView) + } + }, 100) } } @@ -263,4 +192,79 @@ internal class WarningFloatWindowHelper( Logger.e(TAG, "浮窗关闭出现异常:$e") } + + /** + * 设置浮窗的对齐方式,支持上下左右、居中、上中、下中、左中和右中,默认左上角 + * 支持手动设置的偏移量 + */ + @SuppressLint("RtlHardcoded") + private fun setGravity(view: View?) { + if (config.locationPair != Pair(0, 0) || view == null) return + val parentRect = Rect() + // 获取浮窗所在的矩形 + windowManager.defaultDisplay.getRectSize(parentRect) + val location = IntArray(2) + // 获取在整个屏幕内的绝对坐标 + view.getLocationOnScreen(location) + // 通过绝对高度和相对高度比较,判断包含顶部状态栏 + val statusBarHeight = + if (location[1] > params.y) WindowUtils.getStatusBarHeight(view.context.applicationContext) else 0 + val parentBottom = + WindowUtils.getScreenHeight(view.context.applicationContext) - statusBarHeight + when (config.gravity) { + // 右上 + Gravity.END, Gravity.END or Gravity.TOP, Gravity.RIGHT, Gravity.RIGHT or Gravity.TOP -> + params.x = parentRect.right - view.width + // 左下 + Gravity.START or Gravity.BOTTOM, Gravity.BOTTOM, Gravity.LEFT or Gravity.BOTTOM -> + params.y = parentBottom - view.height + // 右下 + Gravity.END or Gravity.BOTTOM, Gravity.RIGHT or Gravity.BOTTOM -> { + params.x = parentRect.right - view.width + params.y = parentBottom - view.height + } + // 居中 + Gravity.CENTER -> { + params.x = (parentRect.right - view.width).shr(1) + params.y = (parentBottom - view.height).shr(1) + } + // 上中 + Gravity.CENTER_HORIZONTAL, Gravity.TOP or Gravity.CENTER_HORIZONTAL -> + params.x = (parentRect.right - view.width).shr(1) + // 下中 + Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL -> { + params.x = (parentRect.right - view.width).shr(1) + params.y = parentBottom - view.height + } + // 左中 + Gravity.CENTER_VERTICAL, Gravity.START or Gravity.CENTER_VERTICAL, Gravity.LEFT or Gravity.CENTER_VERTICAL -> + params.y = (parentBottom - view.height).shr(1) + // 右中 + Gravity.END or Gravity.CENTER_VERTICAL, Gravity.RIGHT or Gravity.CENTER_VERTICAL -> { + params.x = parentRect.right - view.width + params.y = (parentBottom - view.height).shr(1) + } + // 其他情况,均视为左上 + else -> { + } + } + + // 设置偏移量 + params.x += config.offsetPair.first + params.y += config.offsetPair.second + + if (config.immersionStatusBar) { + if (config.showPattern != ShowPattern.CURRENT_ACTIVITY) { + params.y -= statusBarHeight + } + } else { + if (config.showPattern == ShowPattern.CURRENT_ACTIVITY) { + params.y += statusBarHeight + } + } + // 更新浮窗位置信息 + windowManager.updateViewLayout(view, params) + } + + } \ No newline at end of file diff --git a/modules/mogo-module-hmi/src/main/java/com/mogo/module/hmi/ui/MoGoWarningFragment.kt b/modules/mogo-module-hmi/src/main/java/com/mogo/module/hmi/ui/MoGoWarningFragment.kt index cd771b1afc..c0e603c89e 100644 --- a/modules/mogo-module-hmi/src/main/java/com/mogo/module/hmi/ui/MoGoWarningFragment.kt +++ b/modules/mogo-module-hmi/src/main/java/com/mogo/module/hmi/ui/MoGoWarningFragment.kt @@ -64,6 +64,7 @@ class MoGoWarningFragment : MvpFragment