diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/TrafficDataView.java b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/TrafficDataView.java index 0f2d237421..f669c9487e 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/TrafficDataView.java +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/TrafficDataView.java @@ -42,6 +42,8 @@ public class TrafficDataView extends ConstraintLayout { private static final int MSG_SEND_UPDATE = 1; private volatile double acceleration; + private volatile float mBrake; + private volatile float mThrottle; @SuppressLint("HandlerLeak") private final Handler handler = new Handler() { @@ -49,10 +51,24 @@ public class TrafficDataView extends ConstraintLayout { public void handleMessage(@NonNull Message msg) { super.handleMessage(msg); if (msg.what == MSG_SEND_UPDATE) { - java.text.DecimalFormat mFormat = new java.text.DecimalFormat("0.00"); + java.text.DecimalFormat mFormat = new java.text.DecimalFormat("0.0"); String accStr = mFormat.format(acceleration); - accTextView.setText("a: " + accStr); + if (acceleration > 0f) { + accTextView.setText(accStr); + } else { + accTextView.setText("—" + accStr); + } + + if (mBrake > 0) { + brakeStatus.setImageResource(R.drawable.traffic_data_brake); + } else if (mThrottle >= 0 && mBrake == 0) { + brakeStatus.setImageResource(R.drawable.traffic_data_accelerator); + } else { + brakeStatus.setImageResource(R.drawable.traffic_data_empty); + } + } + handler.sendEmptyMessageDelayed(MSG_SEND_UPDATE, 1000L); } }; @@ -76,12 +92,12 @@ public class TrafficDataView extends ConstraintLayout { @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); + handler.sendEmptyMessageDelayed(MSG_SEND_UPDATE, 1000L); CallerAutopilotVehicleStateListenerManager.INSTANCE.addListener(TAG, mIMoGoAutopilotVehicleStateListener); CallerAutopilotCarStatusListenerManager.INSTANCE.addListener(TAG, gnssInfo -> { if (gnssInfo != null) { acceleration = gnssInfo.getAcceleration(); } - handler.sendEmptyMessageDelayed(MSG_SEND_UPDATE, 1000L); }); } @@ -162,25 +178,13 @@ public class TrafficDataView extends ConstraintLayout { @Override public void onAutopilotBrake(float brake) { CallerLogger.INSTANCE.d(TAG, "刹车:" + brake); - ThreadUtils.runOnUiThread(() -> { - if (brake > 0) { - brakeStatus.setImageResource(R.drawable.traffic_data_brake); - } else { - brakeStatus.setImageResource(R.drawable.traffic_data_empty); - } - }); + mBrake = brake; } @Override public void onAutopilotThrottle(float throttle) { CallerLogger.INSTANCE.d(TAG, "油门:" + throttle); - ThreadUtils.runOnUiThread(() -> { - if (throttle > 0) { - brakeStatus.setImageResource(R.drawable.traffic_data_accelerator); - } else { - brakeStatus.setImageResource(R.drawable.traffic_data_empty); - } - }); + mThrottle = throttle; } }; diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_traffic_data.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_traffic_data.xml index e96bc08d6a..754b67fde0 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_traffic_data.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_traffic_data.xml @@ -73,8 +73,19 @@ android:id="@+id/speedAccTextView" android:layout_width="wrap_content" android:layout_height="@dimen/dp_56" - android:layout_marginLeft="@dimen/dp_42" - android:text="a: " + android:layout_marginEnd="@dimen/dp_80" + android:gravity="end" + android:textColor="#fff" + android:textSize="@dimen/dp_40" + app:layout_constraintBottom_toBottomOf="@+id/brakeStatus" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toTopOf="@+id/brakeStatus"/> + + 12px + 14px 20px 22px 43px + 50px 57px + 60px 72px + 80px 88px 26px 30px