[fix] 监听数据回调,执行UI刷新->主线程;方向盘部分UI

This commit is contained in:
liujing
2022-04-11 15:16:59 +08:00
parent 524a5a7415
commit e78795ec7e
4 changed files with 114 additions and 56 deletions

View File

@@ -12,6 +12,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo;
@@ -20,7 +21,9 @@ import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotVehicleStateList
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager;
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotVehicleStateListenerManager;
import com.mogo.eagle.core.function.hmi.R;
import com.mogo.eagle.core.network.utils.Util;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.util.ThreadUtils;
import org.jetbrains.annotations.NotNull;
@@ -40,7 +43,8 @@ import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS
public class SteeringWheelView extends ConstraintLayout {
private static final String TAG = "SteeringWheelView";
private ImageView autopilotIV;
private TextView steeringTV;
private TextView steeringTVL;
private TextView steeringTVR;
private TapPositionView tapPositionView;
private CircularProgressView steeringCircularV;
private RotateAnimation rotateAnimation;
@@ -62,13 +66,13 @@ public class SteeringWheelView extends ConstraintLayout {
private void initView() {
autopilotIV = (ImageView) findViewById(R.id.autopilot_iv);
steeringTV = findViewById(R.id.steering_tv);
steeringTVL = findViewById(R.id.steering_tv_left);
steeringTVR = findViewById(R.id.steering_tv_right);
tapPositionView = findViewById(R.id.tap_position);
steeringCircularV = findViewById(R.id.steering_circular);
steeringCircularV.setBackWidth(8);
steeringCircularV.setBackColor(R.color.hmi_light_blue_00);
steeringCircularV.setProgColor(R.color.hmi_light_blue, R.color.hmi_dark_blue);
steeringCircularV.setProgress(10, 1000);
}
public SteeringWheelView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
@@ -94,24 +98,30 @@ public class SteeringWheelView extends ConstraintLayout {
@Override
public void onAutopilotStatusResponse(@NotNull AutopilotStatusInfo autopilotStatusInfo) {
if (autopilotStatusInfo == null) return;
int state = autopilotStatusInfo.getState();
CallerLogger.INSTANCE.d(M_BUS_P + TAG, "state = %s", state);
if (autopilotIV != null) {
Log.d(TAG, "autopilotIV != null");
if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
if (autopilotStatusInfo == null) return;
int state = autopilotStatusInfo.getState();
CallerLogger.INSTANCE.d(M_BUS_P + TAG, "state = %s", state);
if (autopilotIV != null) {
Log.d(TAG, "autopilotIV != null");
if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
autopilotIV.setImageResource(R.drawable.bg_auto);
autopilotIV.setImageResource(R.drawable.bg_auto);
} else if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE) {
autopilotIV.setImageResource(R.drawable.bg_auto_nor);
} else if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE) {
autopilotIV.setImageResource(R.drawable.bg_auto_nor);
} else if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE) {
autopilotIV.setImageResource(R.drawable.bg_auto_nor);
} else if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE) {
autopilotIV.setImageResource(R.drawable.bg_auto_nor);
}
} else {
Log.d(TAG, "autopilotIV=null");
}
}
} else {
Log.d(TAG, "autopilotIV=null");
}
});
}
@Override
@@ -139,15 +149,34 @@ public class SteeringWheelView extends ConstraintLayout {
Log.d(TAG, "刹车灯:" + String.valueOf(brakeLight));
}
/**
* 方向盘转向角
* @param steering
*/
@Override
public void onAutopilotSteeringData(float steering) {
if (steeringTV != null && String.valueOf(steering) != null) {
steeringTV.setText(String.valueOf(steering) + "°");
steeringCircularV.setProgress((int) steering, 1000);
animationWithSteeringData(steering);
} else {
Log.d(TAG, "steering未呈现");
}
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
Log.d(TAG, "steering" + String.valueOf(steering));
if (steeringTVL != null && steering < 0) {
steeringTVR.setVisibility(View.INVISIBLE);
steeringTVL.setVisibility(View.VISIBLE);
steeringTVL.setText(String.valueOf((int) steering) + "°");
steeringCircularV.setProgress((int) steering, 1000);
animationWithSteeringData(steering);
} else if (steeringTVR != null && steering > 0) {
steeringTVL.setVisibility(View.INVISIBLE);
steeringTVR.setVisibility(View.VISIBLE);
steeringTVR.setText(String.valueOf((int) steering) + "°");
steeringCircularV.setProgress((int) steering, 1000);
animationWithSteeringData(steering);
} else {
Log.d(TAG, "onAutopilotSteeringData error");
}
}
});
}
/**
@@ -156,10 +185,16 @@ public class SteeringWheelView extends ConstraintLayout {
*/
@Override
public void onAutopilotGearData(@NotNull Chassis.GearPosition gear) {
Log.d(TAG, "档位" + gear.toString());
if (tapPositionView != null) {
tapPositionView.updateWithGear(gear);
}
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
Log.d(TAG, "档位" + gear.toString());
if (tapPositionView != null) {
tapPositionView.updateWithGear(gear);
}
}
});
}
};

View File

@@ -14,7 +14,7 @@ import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
/**
* @author liujing
* @description 车辆监控
* @description 车辆监控,暂时隐藏该功能
* @since: 8/16/21
*/
public class VehicleMonitoring implements Handler.Callback {
@@ -34,31 +34,36 @@ public class VehicleMonitoring implements Handler.Callback {
}
public void vehicleCheck() {
if (AutopilotStatus == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
CallerLogger.INSTANCE.d(M_HMI + TAG, "自动驾驶中...");
mHandler.sendEmptyMessageDelayed(AutopilotStatus, AUTO_CHECK_STATUS_DELAY);
} else {
CallerLogger.INSTANCE.d(M_HMI + TAG, "非自动驾驶状态");
//非自动驾驶状态只展示一次
mHandler.sendEmptyMessageDelayed(AutopilotStatus, MANUAL_CHECK_STATUS_DELAY);
}
//暂时隐藏自检功能
/**
*
if (AutopilotStatus == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
CallerLogger.INSTANCE.d(M_HMI + TAG, "自动驾驶中...");
mHandler.sendEmptyMessageDelayed(AutopilotStatus, AUTO_CHECK_STATUS_DELAY);
} else {
CallerLogger.INSTANCE.d(M_HMI + TAG, "非自动驾驶状态");
//非自动驾驶状态只展示一次
mHandler.sendEmptyMessageDelayed(AutopilotStatus, MANUAL_CHECK_STATUS_DELAY);
}
*/
}
@Override
public boolean handleMessage(Message msg) {
AutopilotStatus = CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getState();
switch (msg.what) {
case IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING:
vehicleMonitor();
mHandler.sendEmptyMessageDelayed(AutopilotStatus, AUTO_CHECK_STATUS_DELAY);
return true;
case IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE:
case IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE:
vehicleMonitor();
mHandler.sendEmptyMessageDelayed(AutopilotStatus, MANUAL_CHECK_STATUS_DELAY);
return true;
default:
}
// AutopilotStatus = CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getState();
// switch (msg.what) {
// case IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING:
// vehicleMonitor();
// mHandler.sendEmptyMessageDelayed(AutopilotStatus, AUTO_CHECK_STATUS_DELAY);
// return true;
// case IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE:
// case IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE:
// vehicleMonitor();
// mHandler.sendEmptyMessageDelayed(AutopilotStatus, MANUAL_CHECK_STATUS_DELAY);
// return true;
// default:
// }
return false;
}

View File

@@ -19,15 +19,31 @@
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/steering_tv"
android:id="@+id/steering_tv_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_50"
android:layout_marginRight="-10px"
android:gravity="right"
android:text="-18°"
android:textColor="#415479"
android:textSize="@dimen/dp_26"
android:visibility="invisible"
app:layout_constraintRight_toLeftOf="@+id/blue_circle"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/steering_tv_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-10px"
android:layout_marginTop="@dimen/dp_50"
android:gravity="left"
android:text="18°"
android:textColor="#415479"
android:textSize="@dimen/dp_26"
app:layout_constraintRight_toLeftOf="@+id/blue_circle"
android:visibility="invisible"
app:layout_constraintLeft_toRightOf="@+id/autopilot_iv"
app:layout_constraintTop_toTopOf="parent" />
<com.mogo.eagle.core.function.hmi.ui.widget.CircularProgressView
@@ -45,11 +61,11 @@
<ImageView
android:id="@+id/autopilot_iv"
android:layout_width="@dimen/dp_144"
android:layout_height="@dimen/dp_144"
android:layout_width="@dimen/dp_186"
android:layout_height="@dimen/dp_186"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/dp_54"
android:layout_marginTop="@dimen/dp_34"
android:src="@drawable/bg_auto"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
@@ -69,7 +85,7 @@
android:id="@+id/tap_position"
android:layout_width="@dimen/dp_240"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dp_30"
android:layout_marginBottom="@dimen/dp_20"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"

View File

@@ -11,6 +11,8 @@
<dimen name="module_v2x_brake_image_width">120px</dimen>
<dimen name="module_v2x_brake_image_margin_left">37px</dimen>
<dimen name="module_v2x_brake_image_margin_right">27px</dimen>
<dimen name="dp_90">90px</dimen>
<dimen name="dp_144">144px</dimen>
<dimen name="dp_186">186px</dimen>
<dimen name="dp_300">300px</dimen>
</resources>