opt traffic light panel
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.mogo.module.extensions.utils;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -9,6 +11,8 @@ import com.mogo.module.extensions.R;
|
||||
import com.mogo.module.extensions.view.VerticalTrafficLightView;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 红绿灯面板管理类,控制各部分显示隐藏,同时控制限速、车速、红绿灯信息展示
|
||||
* <p>
|
||||
@@ -17,7 +21,7 @@ import com.mogo.utils.logger.Logger;
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public class TrafficLightPanelManager {
|
||||
public class TrafficLightPanelManager implements Handler.Callback, View.OnClickListener {
|
||||
private static final String TAG = "TrafficLightPanelManager";
|
||||
|
||||
private TrafficLightPanelManager() {
|
||||
@@ -33,6 +37,8 @@ public class TrafficLightPanelManager {
|
||||
private TextView tvLimitSpeed;
|
||||
private VerticalTrafficLightView turnAroundLight, turnLeftLight, straightLight, turnRightLight;
|
||||
|
||||
private Handler handler = new Handler(this);
|
||||
|
||||
private boolean isInit = false;
|
||||
|
||||
public void initPanel(View root) {
|
||||
@@ -45,6 +51,10 @@ public class TrafficLightPanelManager {
|
||||
straightLight = root.findViewById(R.id.module_ext_id_traffic_light_straight);
|
||||
turnRightLight = root.findViewById(R.id.module_ext_id_traffic_light_turn_right);
|
||||
isInit = true;
|
||||
|
||||
// debug
|
||||
root.findViewById(R.id.module_ext_id_navi_in_vr_speed_bg).setOnClickListener(this);
|
||||
root.findViewById(R.id.module_ext_id_navi_in_vr_traffic_bg).setOnClickListener(this);
|
||||
}
|
||||
|
||||
public void showNavPanel() {
|
||||
@@ -53,8 +63,13 @@ public class TrafficLightPanelManager {
|
||||
return;
|
||||
}
|
||||
extraGroup.setVisibility(View.VISIBLE);
|
||||
speedGroup.setVisibility(View.VISIBLE);
|
||||
// navGroup.setVisibility(View.VISIBLE);
|
||||
if (isNav) {
|
||||
navGroup.setVisibility(View.VISIBLE);
|
||||
speedGroup.setVisibility(View.GONE);
|
||||
} else {
|
||||
speedGroup.setVisibility(View.VISIBLE);
|
||||
navGroup.setVisibility(View.GONE);
|
||||
}
|
||||
tvLimitSpeed.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@@ -65,8 +80,42 @@ public class TrafficLightPanelManager {
|
||||
}
|
||||
extraGroup.setVisibility(View.GONE);
|
||||
speedGroup.setVisibility(View.GONE);
|
||||
// navGroup.setVisibility(View.GONE);
|
||||
tvLimitSpeed.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
|
||||
private boolean isNav = false;
|
||||
|
||||
public void startNav() {
|
||||
isNav = true;
|
||||
navGroup.setVisibility(View.VISIBLE);
|
||||
speedGroup.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void stopNav() {
|
||||
isNav = false;
|
||||
speedGroup.setVisibility(View.VISIBLE);
|
||||
navGroup.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void refreshLimitSpeed(int limitSpeed) {
|
||||
handler.removeMessages(MSG_HIDE_LIMIT_SPEED);
|
||||
tvLimitSpeed.setVisibility(View.VISIBLE);
|
||||
tvLimitSpeed.setText(String.valueOf(limitSpeed));
|
||||
handler.sendEmptyMessageDelayed(MSG_HIDE_LIMIT_SPEED, HIDE_LIMIT_SPEED_DELAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新红绿灯显示状态
|
||||
*
|
||||
* @param laneLight 固定数组长度为4的车道类型灯,从0-3依次代表 掉头,左转,执行,右转
|
||||
* @param surplusTime 固定数组长度为4的剩余时长数组,从0-3依次代表 掉头,左转,执行,右转
|
||||
*/
|
||||
public void refreshTrafficLightStatus(int[] laneLight, String[] surplusTime) {
|
||||
turnAroundLight.setTrafficLightStatus(laneLight[0], surplusTime[0]);
|
||||
turnLeftLight.setTrafficLightStatus(laneLight[1], surplusTime[1]);
|
||||
straightLight.setTrafficLightStatus(laneLight[2], surplusTime[2]);
|
||||
turnRightLight.setTrafficLightStatus(laneLight[3], surplusTime[3]);
|
||||
}
|
||||
|
||||
public void release() {
|
||||
@@ -80,4 +129,47 @@ public class TrafficLightPanelManager {
|
||||
straightLight = null;
|
||||
turnRightLight = null;
|
||||
}
|
||||
|
||||
private static final int MSG_HIDE_LIMIT_SPEED = 1001;
|
||||
private static final long HIDE_LIMIT_SPEED_DELAY = 5000;
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message msg) {
|
||||
if (!isInit) {
|
||||
return false;
|
||||
}
|
||||
if (msg.what == MSG_HIDE_LIMIT_SPEED) {
|
||||
tvLimitSpeed.setVisibility(View.GONE);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getId() == R.id.module_ext_id_navi_in_vr_speed_bg) {
|
||||
boolean s = new Random().nextBoolean();
|
||||
boolean b = new Random().nextBoolean();
|
||||
if (s) {
|
||||
if (b) {
|
||||
startNav();
|
||||
} else {
|
||||
stopNav();
|
||||
}
|
||||
} else {
|
||||
refreshLimitSpeed(90);
|
||||
}
|
||||
} else {
|
||||
int[] color = new int[4];
|
||||
String[] time = new String[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int s = new Random().nextInt(4);
|
||||
boolean b = new Random().nextBoolean();
|
||||
color[i] = s;
|
||||
time[i] = b ? "12" : "";
|
||||
}
|
||||
refreshTrafficLightStatus(color, time);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class VerticalTrafficLightView extends ConstraintLayout {
|
||||
private static final int[] TURN_RIGHT_ICON_RES = new int[]{R.drawable.module_ext_dw_traffic_turn_right_gray, R.drawable.module_ext_dw_traffic_turn_right_red, R.drawable.module_ext_dw_traffic_turn_right_yellow, R.drawable.module_ext_dw_traffic_turn_right_green};
|
||||
|
||||
private final int[] iconRes;
|
||||
private final int[] colorRes = new int[]{-1, Color.parseColor("#F63A35"), Color.parseColor("#F63A35"), Color.parseColor("#11FF89")};
|
||||
private final int[] colorRes = new int[]{-1, Color.parseColor("#F63A35"), Color.parseColor("#FFA71F"), Color.parseColor("#11FF89")};
|
||||
|
||||
public VerticalTrafficLightView(Context context) {
|
||||
this(context, null);
|
||||
|
||||
Reference in New Issue
Block a user