opt traffic light

This commit is contained in:
tongchenfei
2020-10-29 16:41:42 +08:00
parent fc7018862a
commit a421f6c6ae
13 changed files with 265 additions and 86 deletions

View File

@@ -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");

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="65px"
android:height="65px" />
<solid android:color="#7f000000" />
<stroke
android:width="2px"
android:color="#997DE261" />
</shape>

View File

@@ -5,7 +5,7 @@
<size android:height="65px" />
<padding
android:left="30px"
android:left="20px"
android:right="30px"/>
<corners android:radius="32.5px" />

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:height="65px" />
<padding
android:left="20px"
android:right="30px"/>
<corners android:radius="32.5px" />
<solid android:color="#7f000000" />
<stroke
android:width="2px"
android:color="#99FF3B2B" />
</shape>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:height="65px" />
<padding
android:left="20px"
android:right="30px"/>
<corners android:radius="32.5px" />
<solid android:color="#7f000000" />
<stroke
android:width="2px"
android:color="#99E3BC59" />
</shape>

View File

@@ -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"

View File

@@ -7,7 +7,7 @@
<color name="module_ext_vr_mode_left_traffic_light_green">#7DE261</color>
<color name="module_ext_vr_mode_left_traffic_light_red">#FF2B2B</color>
<color name="module_ext_vr_mode_left_traffic_light_yellow">#FFF</color>
<color name="module_ext_vr_mode_left_traffic_light_yellow">#E3BC59</color>
<color name="module_ext_vr_mode_left_traffic_light_white">#FFF</color>

View File

@@ -179,6 +179,8 @@
<dimen name="module_ext_vr_mode_traffic_light_text_size">32px</dimen>
<dimen name="module_ext_vr_mode_self_speed_margin_end">15px</dimen>
<dimen name="module_ext_vr_mode_self_speed_margin_bottom">100px</dimen>
<dimen name="module_ext_vr_mode_self_speed_margin_start">30px</dimen>
<dimen name="module_ext_vr_mode_self_speed_gonemargin_start">689px</dimen>
<dimen name="module_ext_vr_mode_self_speed_margin_bottom">86px</dimen>
</resources>

View File

@@ -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<Button>(R.id.btnVip).setOnClickListener {
val carEventInfo = MogoObuEventInfo()
carEventInfo.type = "vip变灯提醒"
carEventInfo.typeCode = "vip变灯提醒"
val r = Random.nextInt(0, 2)
carEventInfo.describe = when (r) {
0 -> "已更改前方红绿灯状态,可优先通行"
else -> "已增加前方绿灯时间,可优先通行"
}
dataCallback?.onEventInfoCallback(carEventInfo)
}
// view.findViewById<Button>(R.id.btnVip).setOnClickListener {
// val carEventInfo = MogoObuEventInfo()
// carEventInfo.type = "vip变灯提醒"
// carEventInfo.typeCode = "vip变灯提醒"
// val r = Random.nextInt(0, 2)
// carEventInfo.describe = when (r) {
// 0 -> "已更改前方红绿灯状态,可优先通行"
// else -> "已增加前方绿灯时间,可优先通行"
// }
// dataCallback?.onEventInfoCallback(carEventInfo)
// }
// view.findViewById<Button>(R.id.btnPersonCrash).setOnClickListener {
// obu.onMessageReceived("{\"pedestrain_information\": {\"pedestrian_crash_alarm\": 1}}".toByteArray())
@@ -89,14 +86,44 @@ class MockUtil:Handler.Callback {
// obu.onMessageReceived("{\"rush_redlight\": {\"glosa_info\": [{\"rush_redlight_alarm\": 0}]}}".toByteArray())
// }
view.findViewById<Button>(R.id.btnStartTrafficLight).setOnClickListener {
intervalMockData()
// view.findViewById<Button>(R.id.btnStartTrafficLight).setOnClickListener {
// intervalMockData()
// }
//
// view.findViewById<Button>(R.id.btnStopTrafficLight).setOnClickListener {
// if (intervalObs != null&&!intervalObs.isDisposed) {
// intervalObs.dispose()
// }
// }
view.findViewById<Button>(R.id.btnGreen).setOnClickListener {
Logger.d(TAG,"准备发送绿灯信号")
cLightStatus = "G"
sendTrafficEvent()
}
view.findViewById<Button>(R.id.btnRed).setOnClickListener {
Logger.d(TAG,"准备发送红灯信号")
cLightStatus = "R"
sendTrafficEvent()
}
view.findViewById<Button>(R.id.btnYello).setOnClickListener {
Logger.d(TAG,"准备发送黄灯信号")
cLightStatus = "Y"
sendTrafficEvent()
}
view.findViewById<Button>(R.id.btnChangeTime).setOnClickListener {
val random = Random.nextInt(100)
Logger.d(TAG,"准备修改时间信息: $random")
cSurplusTime = random.toString()
sendTrafficEvent()
}
view.findViewById<Button>(R.id.btnStopTrafficLight).setOnClickListener {
if (intervalObs != null&&!intervalObs.isDisposed) {
intervalObs.dispose()
}
view.findViewById<Button>(R.id.btnShowLimitSpeed).setOnClickListener{
val random = Random.nextInt(200)
// 发送当前限速到 adas
val intent = Intent("com.mogo.launcher.adas")
intent.putExtra("adas_speed_limit", random)
context.sendBroadcast(intent)
}
handler.sendEmptyMessageDelayed(1001, 10000)
@@ -148,6 +175,16 @@ class MockUtil:Handler.Callback {
intervalObs2.dispose()
}
private fun sendTrafficEvent() {
val trafficLightInfo = MogoObuTrafficLightInfo()
trafficLightInfo.id = "12"
trafficLightInfo.lightStatus = cLightStatus
trafficLightInfo.surplusTime = cSurplusTime
dataCallback?.onTrafficLightInfoCallback(trafficLightInfo)
Logger.d(TAG, "发送红绿灯数据: $trafficLightInfo")
}
private fun debugCarEvent() {
val random = Random.nextInt(0, 4)
Logger.d(TAG, "random====$random")

View File

@@ -5,45 +5,92 @@
android:columnCount="4">
<Button
android:id="@+id/btnVip"
android:id="@+id/btnGreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="vip同行" />
android:text="绿灯"
android:textSize="30sp"
android:padding="10dp"
android:background="#0f0" />
<Button
android:id="@+id/btnRushRedLight"
android:id="@+id/btnRed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="红灯" />
android:text="红灯"
android:textSize="30sp"
android:padding="10dp"
android:background="#f00" />
<Button
android:id="@+id/btnOptimizeSpeed"
android:id="@+id/btnYello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="绿波车速" />
android:text="黄灯"
android:textSize="30sp"
android:padding="10dp"
android:background="#F7F709" />
<Button
android:id="@+id/btnCrossCrash"
android:id="@+id/btnChangeTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="交叉口碰撞" />
android:text="改变时间"
android:textSize="30sp"
android:padding="10dp"
android:background="#FF00FF" />
<Button
android:id="@+id/btnPersonCrash"
android:id="@+id/btnShowLimitSpeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="行人碰撞" />
android:text="修改限速"
android:textSize="30sp"
android:padding="10dp"
android:background="#FF00FF" />
<Button
android:id="@+id/btnStartTrafficLight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始红绿灯倒计时" />
<Button
android:id="@+id/btnStopTrafficLight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="停止红绿灯倒计时" />
<!-- <Button-->
<!-- android:id="@+id/btnVip"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="vip同行" />-->
<!-- <Button-->
<!-- android:id="@+id/btnRushRedLight"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="闯红灯" />-->
<!-- <Button-->
<!-- android:id="@+id/btnOptimizeSpeed"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="绿波车速" />-->
<!-- <Button-->
<!-- android:id="@+id/btnCrossCrash"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="交叉口碰撞" />-->
<!-- <Button-->
<!-- android:id="@+id/btnPersonCrash"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="行人碰撞" />-->
<!-- <Button-->
<!-- android:id="@+id/btnStartTrafficLight"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="开始红绿灯倒计时" />-->
<!-- <Button-->
<!-- android:id="@+id/btnStopTrafficLight"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="停止红绿灯倒计时" />-->
</GridLayout>