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>