将warning划分到hmi

This commit is contained in:
董宏宇
2021-08-05 12:16:30 +08:00
parent be361ca514
commit e8d3bc0612
47 changed files with 23 additions and 21 deletions

View File

@@ -0,0 +1,81 @@
package com.mogo.module.hmi.warning;
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.module.hmi.warning.ui.MoGoWarningFragment;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.module.ModuleType;
import com.mogo.service.warning.IMoGoWaringProvider;
import com.mogo.utils.logger.Logger;
/**
* @author xiaoyuzhou
* @date 2021/8/2 5:52 下午
* 预警模块
*/
@Route(path = MogoServicePaths.PATH_V2X_WARNING)
public class MoGoWarningProvider implements IMoGoWaringProvider {
private String TAG = "MoGoWarningProvider";
private MoGoWarningFragment mMoGoWarningFragment;
private Context mContext;
@Override
public void init(Context context) {
Logger.d(TAG, "初始化蘑菇预警模块 ……");
mContext = context;
}
@Override
public Fragment createFragment(Context context, Bundle data) {
Logger.d(TAG, "初始化蘑菇预警模块 Fragment……");
mMoGoWarningFragment = new MoGoWarningFragment();
return mMoGoWarningFragment;
}
@NonNull
@Override
public String getModuleName() {
return WaringConst.MODULE_NAME;
}
@Override
public int getType() {
return ModuleType.TYPE_CARD_FRAGMENT;
}
@Override
public void showWarningTrafficLight(int checkLightId) {
mMoGoWarningFragment.showWarningTrafficLight(checkLightId);
}
@Override
public void disableWarningTrafficLight() {
mMoGoWarningFragment.disableWarningTrafficLight();
}
@Override
public void showLimitingVelocity(int limitingSpeed) {
mMoGoWarningFragment.showLimitingVelocity(limitingSpeed);
}
@Override
public void disableLimitingVelocity() {
mMoGoWarningFragment.disableLimitingVelocity();
}
@Override
public void showWarningV2X(int v2xType, @NonNull String alertMessage, @NonNull String tag) {
mMoGoWarningFragment.showWarningV2X(v2xType, alertMessage, tag);
}
@Override
public void disableWarningV2X(@NonNull String tag) {
}
}

View File

@@ -0,0 +1,12 @@
package com.mogo.module.hmi.warning;
/**
* @author xiaoyuzhou
* @date 2021/8/3 4:26 下午
*/
public class WaringConst {
public static String MODULE_NAME = "MODULE_LEFT_PANEL";
public static String BROADCAST_TEST_CONTROL_TYPE_EXTRA_KEY = "warningType";
}

View File

@@ -0,0 +1,76 @@
package com.mogo.module.hmi.warning;
/**
* author : donghongyu
* e-mail : 1358506549@qq.com
* date : 2020-01-1514:47
* desc : 车机启动状态
* version: 1.0
*/
public interface WarningTypeEnum {
/**
* 前向碰撞
*/
int WARING_TYPE_PRIOR_COLLISION = 20001;
/**
* 交叉路口碰撞
*/
int WARING_TYPE_INTERSECTION_COLLISION = 20002;
/**
* 左转辅助
*/
int WARING_TYPE_LEFT_AUXILIARY = 20003;
/**
* 盲区/变道辅助
*/
int WARING_TYPE_BLIND_AREA_COLLISION = 20004;
/**
* 逆向超车
*/
int WARING_TYPE_REVERSE_OVERTAKING = 20005;
/**
* 紧急制动-前车急刹
*/
int WARING_TYPE_VEHICLE_BRAKES = 20006;
/**
* 异常车辆提醒
*/
int WARING_TYPE_ABNORMAL_VEHICLE = 20007;
/**
* 车辆失控预警
*/
int WARING_TYPE_VEHICLE_CONTROL = 20008;
/**
* 道路危险情况预警
*/
int WARING_TYPE_ROAD_HAZARDS = 20009;
/**
* 限速预警
*/
int WARING_TYPE_SPEED_LIMIT = 20010;
/**
* 闯红灯预警
*/
int WARING_TYPE_RED_LIGHT = 20011;
/**
* 弱势交通参与者预警
*/
int WARING_TYPE_VULNERABLE_TRANSPORT_PARTICIPANT = 20012;
/**
* 绿波通行车速引导
*/
int WARING_TYPE_TRAFFIC_SPEED_GUIDE = 20013;
/**
* 车内标牌
*/
int WARING_TYPE_CAR_PLATE = 20014;
/**
* 前方道路拥堵
*/
int WARING_TYPE_TRAFFIC_JAM_AHEAD = 20015;
/**
* 特种车辆通行
*/
int WARING_TYPE_SPECIAL_VEHICLE_ACCESS = 20016;
}

View File

@@ -0,0 +1,57 @@
package com.mogo.module.hmi.warning.notification;
import android.app.Service;
import android.content.Context;
import android.graphics.PixelFormat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import com.mogo.module.hmi.warning.R;
/**
* @author xiaoyuzhou
* @date 2021/8/3 5:50 下午
* 通知管理
*/
public class WarningNotificationManager {
// 这里采用添加View的方式,配合动画完成弹窗的效果,仅限应用内部弹窗,伴随着Activity后台也会隐藏
private static WindowManager mWindowManager;
private static WindowManager.LayoutParams mLayoutParams;
private static View mView;
public static void show(Context context) {
// 获取 WindowManager
mWindowManager = (WindowManager) context.getSystemService(Service.WINDOW_SERVICE);
mLayoutParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
0, 0,
PixelFormat.TRANSPARENT);
// flag 设置 Window 属性,悬浮窗的行为,比如说不可聚焦,非模态对话框等等
mLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
// type 设置 Window 类别(层级),悬浮窗的类型一般设为2002表示在所有应用程序之上但在状态栏之下
mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
// 悬浮窗的对齐方式
mLayoutParams.gravity = Gravity.TOP;
//
mLayoutParams.format = PixelFormat.RGBA_8888;
// 悬浮窗X的位置
mLayoutParams.x = 0;
//悬浮窗Y的位置此时需要减去statusBar的高度
mLayoutParams.y = 110;
//添加动画
mLayoutParams.windowAnimations = R.style.notice_dialog_anim_bottom2top;
if (mView != null) {
mWindowManager.removeView(mView);
}
mView = LayoutInflater.from(context).inflate(R.layout.notification_v2x_msg_vr, null, false);
mWindowManager.addView(mView, mLayoutParams);
}
}

View File

@@ -0,0 +1,87 @@
package com.mogo.module.hmi.warning.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.alibaba.android.arouter.launcher.ARouter
import com.mogo.module.hmi.warning.WaringConst
import com.mogo.module.hmi.warning.WarningTypeEnum
import com.mogo.service.IMogoServiceApis
import com.mogo.service.MogoServicePaths
import com.mogo.service.warning.IMoGoWaringProvider
import com.mogo.utils.logger.Logger
import kotlin.random.Random
/**
* V2X 测试面板广播接收,目的是可以通过广播调用起来面板
*
* @author donghongyu
*/
class TestWarningBroadcastReceiver : BroadcastReceiver() {
private var mContext: Context? = null
override fun onReceive(context: Context, intent: Intent) {
try {
mMogoServiceApis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS)
.navigation(context) as IMogoServiceApis
mIMoGoWaringProvider = mMogoServiceApis!!.waringProviderApi
mContext = context
val warningType =
intent.getIntExtra(WaringConst.BROADCAST_TEST_CONTROL_TYPE_EXTRA_KEY, 0)
Logger.d(TAG, "warningType:$warningType")
// 分发场景
dispatchWaring(warningType)
} catch (e: Exception) {
e.printStackTrace()
}
}
/**
* 分发处理场景
*
* @param warningType 场景类型
*/
private fun dispatchWaring(warningType: Int) {
mIMoGoWaringProvider!!.showWarningV2X(warningType, "预警消息", Random.nextDouble().toString())
when (warningType) {
WarningTypeEnum.WARING_TYPE_PRIOR_COLLISION -> {
}
WarningTypeEnum.WARING_TYPE_INTERSECTION_COLLISION -> {
}
WarningTypeEnum.WARING_TYPE_LEFT_AUXILIARY -> {
}
WarningTypeEnum.WARING_TYPE_BLIND_AREA_COLLISION -> {
}
WarningTypeEnum.WARING_TYPE_REVERSE_OVERTAKING -> {
}
WarningTypeEnum.WARING_TYPE_VEHICLE_BRAKES -> {
}
WarningTypeEnum.WARING_TYPE_ABNORMAL_VEHICLE -> {
}
WarningTypeEnum.WARING_TYPE_VEHICLE_CONTROL -> {
}
WarningTypeEnum.WARING_TYPE_ROAD_HAZARDS -> {
}
WarningTypeEnum.WARING_TYPE_SPEED_LIMIT -> {
}
WarningTypeEnum.WARING_TYPE_RED_LIGHT -> {
}
WarningTypeEnum.WARING_TYPE_VULNERABLE_TRANSPORT_PARTICIPANT -> {
}
WarningTypeEnum.WARING_TYPE_TRAFFIC_SPEED_GUIDE -> {
}
WarningTypeEnum.WARING_TYPE_CAR_PLATE -> {
}
WarningTypeEnum.WARING_TYPE_TRAFFIC_JAM_AHEAD -> {
}
WarningTypeEnum.WARING_TYPE_SPECIAL_VEHICLE_ACCESS -> {
}
}
}
companion object {
private const val TAG = "TestPanelBroadcastReceiver"
private var mMogoServiceApis: IMogoServiceApis? = null
private var mIMoGoWaringProvider: IMoGoWaringProvider? = null
}
}

View File

@@ -0,0 +1,56 @@
package com.mogo.module.hmi.warning.ui
import com.mogo.commons.mvp.IView
/**
*@author xiaoyuzhou
*@date 2021/8/4 3:38 下午
*/
interface MoGoWarningContract {
/**
*
*/
interface View : IView {
/**
* 展示VR下V2X预警
*
* @param v2xType V2X类型
* @param alertMessage 提醒文本
*/
fun showWarningV2X(v2xType: Int, alertMessage: String, tag: String)
/**
* 关闭指定floatTag 的 VR下V2X预警弹窗
* @param tag 弹窗标识
*/
fun disableWarningV2X(tag: String)
/**
* 展示红绿灯预警
*
* @param checkLightId 0-都是默认1-红2-黄3-绿
*/
fun showWarningTrafficLight(checkLightId: Int)
/**
* 关闭红绿灯预警
*/
fun disableWarningTrafficLight()
/**
* 展示限速预警
*
* @param limitingSpeed 限速速度
*/
fun showLimitingVelocity(limitingSpeed: Int)
/**
* 关闭限速预警
*/
fun disableLimitingVelocity()
}
}

View File

@@ -0,0 +1,48 @@
package com.mogo.module.hmi.warning.ui
import com.mogo.commons.mvp.MvpFragment
import com.mogo.module.hmi.warning.R
import com.mogo.module.hmi.warning.notification.WarningNotificationManager
/**
* @author xiaoyuzhou
* @date 2021/8/3 2:40 下午
* 预警图层
*/
class MoGoWarningFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>(),
MoGoWarningContract.View {
override fun initViews() {}
override fun getLayoutId(): Int {
return R.layout.fragment_warning
}
override fun createPresenter(): WaringPresenter {
return WaringPresenter(this)
}
override fun showWarningV2X(v2xType: Int, alertMessage: String, tag: String) {
WarningNotificationManager.show(activity)
}
override fun disableWarningV2X(tag: String) {
}
override fun showWarningTrafficLight(checkLightId: Int) {
}
override fun disableWarningTrafficLight() {
}
override fun showLimitingVelocity(limitingSpeed: Int) {
}
override fun disableLimitingVelocity() {
}
}

View File

@@ -0,0 +1,57 @@
package com.mogo.module.hmi.warning.ui
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import com.mogo.module.hmi.warning.R
import kotlinx.android.synthetic.main.view_traffic_light_vr.view.*
/**
* @author xiaoyuzhou
* @date 2021/8/4 3:16 下午
* 红绿灯控件
*/
class ViewTrafficLight @JvmOverloads constructor(
context: Context?,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
init {
LayoutInflater.from(context).inflate(R.layout.view_traffic_light_vr, this, true)
}
/**
* 展示红绿灯预警
*
* @param checkLightId 0-都是默认1-红2-黄3-绿
*/
fun showWarningTrafficLight(checkLightId: Int) {
when (checkLightId) {
0 -> {
ctvRedTrafficLight.isChecked = false
ctvYellowTrafficLight.isChecked = false
ctvGreenTrafficLight.isChecked = false
}
1 -> {
ctvRedTrafficLight.isChecked = true
ctvYellowTrafficLight.isChecked = false
ctvGreenTrafficLight.isChecked = false
}
2 -> {
ctvRedTrafficLight.isChecked = false
ctvYellowTrafficLight.isChecked = true
ctvGreenTrafficLight.isChecked = false
}
3 -> {
ctvRedTrafficLight.isChecked = false
ctvYellowTrafficLight.isChecked = false
ctvGreenTrafficLight.isChecked = true
}
}
}
}

View File

@@ -0,0 +1,36 @@
package com.mogo.module.hmi.warning.ui
import com.mogo.commons.mvp.Presenter
/**
* @author xiaoyuzhou
* @date 2021/8/3 3:55 下午
*/
class WaringPresenter(view: MoGoWarningContract.View?) :
Presenter<MoGoWarningContract.View?>(view) {
fun showWarningV2X(v2xType: Int, alertMessage: String, tag: String) {
mView?.showWarningV2X(v2xType, alertMessage, tag)
}
fun disableWarningV2X(tag: String) {
mView?.disableWarningV2X(tag)
}
fun showWarningTrafficLight(checkLightId: Int) {
mView?.showWarningTrafficLight(checkLightId)
}
fun disableWarningTrafficLight() {
mView?.disableWarningTrafficLight()
}
fun showLimitingVelocity(limitingSpeed: Int) {
mView?.showLimitingVelocity(limitingSpeed)
}
fun disableLimitingVelocity() {
mView?.disableLimitingVelocity()
}
}