ui problem

This commit is contained in:
zhongchao
2022-08-03 18:50:13 +08:00
parent e7f57c1cfc
commit 05f4a8b371
3 changed files with 38 additions and 19 deletions

View File

@@ -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;
}
};

View File

@@ -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"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="@dimen/dp_56"
android:layout_marginLeft="@dimen/dp_14"
android:text="a:"
android:textAlignment="viewStart"
android:textColor="#fff"
android:textSize="@dimen/dp_40"