diff --git a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/AdasNoticeHelper.java b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/AdasNoticeHelper.java index 4a0a1cba9c..0d2eb539ee 100644 --- a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/AdasNoticeHelper.java +++ b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/AdasNoticeHelper.java @@ -52,7 +52,7 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca private TextView tvSelfSpeed, tvTrafficLight, tvLimitSpeed; - private int limitSpeed; + private int limitSpeed = -1; private int currentSpeed = 0; private String lightStatus = "G"; private String surplusTime; @@ -87,6 +87,7 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca if (!isVrMode) { isVrMode = true; IntentFilter filter = new IntentFilter("com.mogo.launcher.adas.app.biz"); + filter.addAction("com.mogo.launcher.adas"); context.registerReceiver(adasReceiver, filter); MogoApisHandler.getInstance().getApis().getAdasControllerApi().addAdasWarnMessageCallback(this); MogoApisHandler.getInstance().getApis().getRegisterCenterApi().registerMogoLocationListener(TAG, this); @@ -111,6 +112,7 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca tvLimitSpeed.setVisibility(View.GONE); MogoApisHandler.getInstance().getApis().getAdasControllerApi().removeAdasWarnMessageCallback(this); MogoApisHandler.getInstance().getApis().getRegisterCenterApi().unregisterMogoLocationListener(TAG); + MogoApisHandler.getInstance().getApis().getWebSocketManagerApi(context).unregisterOnWebSocketMessageListener(this); context.unregisterReceiver(adasReceiver); } @@ -125,19 +127,22 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca if (msg.type == MogoADASWarnType.ADAS_WARNING_LIMIT_SPEED) { // 收到限速信息,更新界面 - if (tvLimitSpeed != null) { - tvLimitSpeed.post(() -> { - handler.removeMessages(MSG_HIDE_LIMIT_SPEED); + limitSpeed = Integer.parseInt(msg.value); + drawLimitSpeed(); + } + } - if (tvLimitSpeed.getVisibility() == View.GONE) { - tvLimitSpeed.setVisibility(View.VISIBLE); - } - tvLimitSpeed.setText(msg.value); - limitSpeed = Integer.parseInt(msg.value); + private void drawLimitSpeed(){ + if (tvLimitSpeed != null) { + tvLimitSpeed.post(() -> { + handler.removeMessages(MSG_HIDE_LIMIT_SPEED); - handler.sendEmptyMessageDelayed(MSG_HIDE_LIMIT_SPEED, HIDE_LIMIT_SPEED_DELAY); - }); - } + if (tvLimitSpeed.getVisibility() == View.GONE) { + tvLimitSpeed.setVisibility(View.VISIBLE); + } + tvLimitSpeed.setText(limitSpeed+""); + handler.sendEmptyMessageDelayed(MSG_HIDE_LIMIT_SPEED, HIDE_LIMIT_SPEED_DELAY); + }); } } @@ -153,6 +158,15 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca if (tvSelfSpeed.getVisibility() == View.GONE) { tvSelfSpeed.setVisibility(View.VISIBLE); } + if (limitSpeed != -1 && currentSpeed > limitSpeed) { + // 显示红色 + tvSelfSpeed.setTextColor(context.getResources().getColor(R.color.module_ext_vr_mode_left_traffic_light_red)); + tvSelfSpeed.setBackgroundResource(R.drawable.module_ext_vr_mode_speed_red_bg); + }else{ + // 显示白 + tvSelfSpeed.setTextColor(context.getResources().getColor(R.color.module_ext_vr_mode_left_traffic_light_white)); + tvSelfSpeed.setBackgroundResource(R.drawable.module_ext_vr_mode_speed_white_bg); + } tvSelfSpeed.setText("" + currentSpeed); Logger.d(TAG, "onLocationChange: " + currentSpeed); }); @@ -164,6 +178,7 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca public boolean handleMessage(Message msg) { switch (msg.what) { case MSG_REFRESH_CAR_STRATEGY: + // todo 暂时不采用此种渲染方式 // 自车速度 tvSelfSpeed.setText("" + currentSpeed); // 红绿灯 @@ -190,6 +205,7 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca } return true; case MSG_HIDE_LIMIT_SPEED: + limitSpeed = -1; tvLimitSpeed.setVisibility(View.GONE); return true; case MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD: @@ -218,24 +234,30 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca if (!isVrMode) { return; } - - int type = intent.getIntExtra("type", -1); - if (type == 2) { - // 红绿灯处理 - String data = intent.getStringExtra("data"); - if (data != null && !data.isEmpty()) { - try { - JSONObject jsonObject = new JSONObject(data); - String lightStatus = jsonObject.optString("lightStatus"); - String surplusTime = jsonObject.optString("surplusTime"); - if (!lightStatus.isEmpty() && !surplusTime.isEmpty()) { - handleObuTrafficLightInfo(lightStatus, surplusTime); - } else { - Logger.d(TAG, "红绿灯必要信息都为空,不做展示"); + String action = intent.getAction(); + if("com.mogo.launcher.adas".equals(action)){ + // 收到限速信息 + limitSpeed = intent.getIntExtra("adas_speed_limit", -1); + drawLimitSpeed(); + }else { + int type = intent.getIntExtra("type", -1); + if (type == 2) { + // 红绿灯处理 + String data = intent.getStringExtra("data"); + if (data != null && !data.isEmpty()) { + try { + JSONObject jsonObject = new JSONObject(data); + String lightStatus = jsonObject.optString("lightStatus"); + String surplusTime = jsonObject.optString("surplusTime"); + if (!lightStatus.isEmpty() && !surplusTime.isEmpty()) { + handleObuTrafficLightInfo(lightStatus, surplusTime); + } else { + Logger.d(TAG, "红绿灯必要信息都为空,不做展示"); + } + } catch (Exception e) { + Logger.e(TAG, e, "解析adas数据异常"); + e.printStackTrace(); } - } catch (Exception e) { - Logger.e(TAG, e, "解析adas数据异常"); - e.printStackTrace(); } } } @@ -256,26 +278,35 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca if (tvTrafficLight != null && !handler.hasMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_OBU)) { handler.removeMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD); // todo drawTrafficLight - String lightStatus; + String lightStatus = null; switch (roadData.getLightStatus()) { case 1: // 红灯 lightStatus = "R"; break; + case 2: + // 绿灯 + lightStatus = "G"; + break; case 3: // 黄灯 lightStatus = "Y"; break; default: - // 默认绿灯 - lightStatus = "G"; break; } - int diff = (int) ((System.currentTimeMillis() - roadData.getSystemTime()) / 1000); - int leftTime = roadData.getLightLeftTime() - diff; - drawTrafficLight(lightStatus, "" + leftTime); - handler.sendEmptyMessageDelayed(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD, - HIDE_TRAFFIC_LIGHT_DELAY); + if(lightStatus == null){ + handler.sendEmptyMessage(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD); + }else { + int diff = (int) ((System.currentTimeMillis() - roadData.getSystemTime()) / 1000); + int leftTime = roadData.getLightLeftTime() - diff; + if (leftTime < 0) { + leftTime = 0; + } + drawTrafficLight(lightStatus, "" + leftTime); + handler.sendEmptyMessageDelayed(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD, + HIDE_TRAFFIC_LIGHT_DELAY); + } } } @@ -291,12 +322,21 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca switch (lightStatus) { case "Y": // 黄灯 + tvTrafficLight.setTextColor(context.getResources().getColor(R.color.module_ext_vr_mode_left_traffic_light_yellow)); + tvTrafficLight.setBackgroundResource(R.drawable.module_ext_vr_mode_traffic_light_yellow_bg); + tvTrafficLight.setCompoundDrawablesWithIntrinsicBounds(R.drawable.module_ext_traffic_light_yellow, 0, 0, 0); break; case "R": // 红灯 + tvTrafficLight.setTextColor(context.getResources().getColor(R.color.module_ext_vr_mode_left_traffic_light_red)); + tvTrafficLight.setBackgroundResource(R.drawable.module_ext_vr_mode_traffic_light_red_bg); + tvTrafficLight.setCompoundDrawablesWithIntrinsicBounds(R.drawable.module_ext_traffic_light_red, 0, 0, 0); break; default: // 默认绿灯 + tvTrafficLight.setTextColor(context.getResources().getColor(R.color.module_ext_vr_mode_left_traffic_light_green)); + tvTrafficLight.setBackgroundResource(R.drawable.module_ext_vr_mode_traffic_light_green_bg); + tvTrafficLight.setCompoundDrawablesWithIntrinsicBounds(R.drawable.module_ext_traffic_light_green, 0, 0, 0); break; } tvTrafficLight.setText(surplusTime + "S"); diff --git a/modules/mogo-module-extensions/src/main/res/drawable-xhdpi/module_ext_traffic_light_green.png b/modules/mogo-module-extensions/src/main/res/drawable-xhdpi/module_ext_traffic_light_green.png new file mode 100644 index 0000000000..7d7ddedd8a Binary files /dev/null and b/modules/mogo-module-extensions/src/main/res/drawable-xhdpi/module_ext_traffic_light_green.png differ diff --git a/modules/mogo-module-extensions/src/main/res/drawable-xhdpi/module_ext_traffic_light_red.png b/modules/mogo-module-extensions/src/main/res/drawable-xhdpi/module_ext_traffic_light_red.png new file mode 100644 index 0000000000..694cfd0725 Binary files /dev/null and b/modules/mogo-module-extensions/src/main/res/drawable-xhdpi/module_ext_traffic_light_red.png differ diff --git a/modules/mogo-module-extensions/src/main/res/drawable-xhdpi/module_ext_traffic_light_yellow.png b/modules/mogo-module-extensions/src/main/res/drawable-xhdpi/module_ext_traffic_light_yellow.png new file mode 100644 index 0000000000..8598d800f0 Binary files /dev/null and b/modules/mogo-module-extensions/src/main/res/drawable-xhdpi/module_ext_traffic_light_yellow.png differ diff --git a/modules/mogo-module-extensions/src/main/res/drawable/module_ext_vr_mode_speed_green_bg.xml b/modules/mogo-module-extensions/src/main/res/drawable/module_ext_vr_mode_speed_green_bg.xml new file mode 100644 index 0000000000..d13f3fc8a1 --- /dev/null +++ b/modules/mogo-module-extensions/src/main/res/drawable/module_ext_vr_mode_speed_green_bg.xml @@ -0,0 +1,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/modules/mogo-module-extensions/src/main/res/drawable/module_ext_vr_mode_traffic_light_green_bg.xml b/modules/mogo-module-extensions/src/main/res/drawable/module_ext_vr_mode_traffic_light_green_bg.xml index 478755d48b..0f824c43c0 100644 --- a/modules/mogo-module-extensions/src/main/res/drawable/module_ext_vr_mode_traffic_light_green_bg.xml +++ b/modules/mogo-module-extensions/src/main/res/drawable/module_ext_vr_mode_traffic_light_green_bg.xml @@ -5,7 +5,7 @@ diff --git a/modules/mogo-module-extensions/src/main/res/drawable/module_ext_vr_mode_traffic_light_red_bg.xml b/modules/mogo-module-extensions/src/main/res/drawable/module_ext_vr_mode_traffic_light_red_bg.xml new file mode 100644 index 0000000000..10a256f8cc --- /dev/null +++ b/modules/mogo-module-extensions/src/main/res/drawable/module_ext_vr_mode_traffic_light_red_bg.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/mogo-module-extensions/src/main/res/drawable/module_ext_vr_mode_traffic_light_yellow_bg.xml b/modules/mogo-module-extensions/src/main/res/drawable/module_ext_vr_mode_traffic_light_yellow_bg.xml new file mode 100644 index 0000000000..2edd68c52b --- /dev/null +++ b/modules/mogo-module-extensions/src/main/res/drawable/module_ext_vr_mode_traffic_light_yellow_bg.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_entrance.xml b/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_entrance.xml index e1c8837aa8..fb3ee3ce1c 100644 --- a/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_entrance.xml +++ b/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_entrance.xml @@ -254,6 +254,7 @@ android:background="@drawable/module_ext_vr_mode_traffic_light_green_bg" android:gravity="center" android:text="26S" + android:drawableLeft="@drawable/module_ext_traffic_light_green" android:textColor="@color/module_ext_vr_mode_left_traffic_light_green" android:textSize="@dimen/module_ext_vr_mode_traffic_light_text_size" android:visibility="gone" diff --git a/modules/mogo-module-extensions/src/main/res/values/colors.xml b/modules/mogo-module-extensions/src/main/res/values/colors.xml index 24016f710c..943bde9777 100644 --- a/modules/mogo-module-extensions/src/main/res/values/colors.xml +++ b/modules/mogo-module-extensions/src/main/res/values/colors.xml @@ -7,7 +7,7 @@ #7DE261 #FF2B2B - #FFF + #E3BC59 #FFF diff --git a/modules/mogo-module-extensions/src/main/res/values/dimens.xml b/modules/mogo-module-extensions/src/main/res/values/dimens.xml index e23521fa36..8637aff811 100644 --- a/modules/mogo-module-extensions/src/main/res/values/dimens.xml +++ b/modules/mogo-module-extensions/src/main/res/values/dimens.xml @@ -179,6 +179,8 @@ 32px 15px - 100px + 30px + 689px + 86px \ No newline at end of file diff --git a/modules/mogo-module-obu/src/main/java/com/zhidao/mogo/module/obu/MockUtil.kt b/modules/mogo-module-obu/src/main/java/com/zhidao/mogo/module/obu/MockUtil.kt index ab9f7348b8..68e61eb3c7 100644 --- a/modules/mogo-module-obu/src/main/java/com/zhidao/mogo/module/obu/MockUtil.kt +++ b/modules/mogo-module-obu/src/main/java/com/zhidao/mogo/module/obu/MockUtil.kt @@ -1,28 +1,22 @@ package com.zhidao.mogo.module.obu import android.content.Context +import android.content.Intent import android.os.Handler import android.os.Message import android.view.LayoutInflater import android.view.View import android.widget.Button import com.alibaba.android.arouter.launcher.ARouter -import com.mogo.commons.debug.DebugConfig import com.mogo.service.IMogoServiceApis import com.mogo.service.MogoServicePaths import com.mogo.utils.logger.Logger -import com.zhidao.mogo.module.obu.obu.* +import com.zhidao.mogo.module.obu.obu.BaseObu +import com.zhidao.mogo.module.obu.obu.IObuCallback import com.zhidao.mogo.module.obu.obu.bean.MogoObuEventInfo import com.zhidao.mogo.module.obu.obu.bean.MogoObuTrafficLightInfo -import com.zhidao.mogo.module.obu.socket.IUdpSocketCallback -import com.zhidao.smartv2x.listener.OnMessageReceiveListener -import com.zhidao.smartv2x.model.obu.CarEventInfo -import com.zhidao.smartv2x.model.obu.TrafficLightInfo import io.reactivex.Observable -import io.reactivex.Scheduler -import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable -import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers.io import java.util.concurrent.TimeUnit import kotlin.random.Random @@ -56,22 +50,25 @@ class MockUtil:Handler.Callback { return false } + private var cLightStatus: String = "G" + private var cSurplusTime: String = "10" + fun init(context: Context,obu:BaseObu){ Logger.d(TAG, "使用模拟obu数据===") this.context = context dataCallback = obu.callback view = LayoutInflater.from(context).inflate(R.layout.mock_obu, null) - view.findViewById