业务逻辑添加:方向盘根据CAN数据做转动+外侧渐变色呈现

This commit is contained in:
liujing
2022-04-08 16:36:20 +08:00
parent e6f8db51b2
commit 8c36b453ac
6 changed files with 104 additions and 46 deletions

View File

@@ -170,7 +170,7 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/switch_line_btn"
android:id="@+id/switch_line_btn"fragment_och_bus.xml
android:layout_width="@dimen/module_mogo_och_autopilot_order_bg_width"
android:layout_height="@dimen/bus_switch_line_btn"
android:text="@string/bus_switch_line_btn"

View File

@@ -5,6 +5,7 @@ import android.content.Context
import android.content.res.TypedArray
import android.graphics.*
import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.view.animation.OvershootInterpolator
import androidx.core.content.ContextCompat
@@ -20,6 +21,7 @@ class CircularProgressView @JvmOverloads constructor(
: View(context, attrs, defStyleAttr) {
val typedArray: TypedArray = context.obtainStyledAttributes(attrs, R.styleable.CircularProgressView)
val TAG: String = "CircularProgressView"
// 绘制画笔
private val mBackPaint: Paint = Paint()
@@ -76,6 +78,7 @@ class CircularProgressView @JvmOverloads constructor(
val mRectT = getPaddingTop() + (viewHigh - mRectLength) / 2
mRectF = RectF(mRectL.toFloat(), mRectT.toFloat(), (mRectL + mRectLength).toFloat(),
(mRectT + mRectLength).toFloat())
Log.d(TAG, "渐变色:" + mColorArray?.size.toString())
// 设置进度圆环渐变色
mColorArray?.let {
mProgPaint.shader = LinearGradient(
@@ -181,6 +184,7 @@ class CircularProgressView @JvmOverloads constructor(
invalidate()
}
fun setProgColor(startColor: Int, endColor: Int) {
mColorArray = intArrayOf(ContextCompat.getColor(context, startColor), ContextCompat.getColor(context, endColor))
mColorArray?.let {

View File

@@ -4,6 +4,9 @@ import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.TextView;
@@ -30,6 +33,8 @@ import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS
/**
* @author Jing
* @description 方向盘
* 方向盘跟随CAN数据做旋转
* 档位随CAN数据做切换和高亮显示
* @since: 4/7/22
*/
public class SteeringWheelView extends ConstraintLayout {
@@ -38,22 +43,42 @@ public class SteeringWheelView extends ConstraintLayout {
private TextView steeringTV;
private TapPositionView tapPositionView;
private CircularProgressView steeringCircularV;
private RotateAnimation rotateAnimation;
private float fromDegrees = 0;//方向盘旋转起始位置
public SteeringWheelView(@NonNull Context context) {
super(context);
Log.d(TAG, "1");
}
public SteeringWheelView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
Log.d(TAG, "2");
LayoutInflater.from(context).inflate(R.layout.hmi_steering_wheel, this);
initView();
CallerAutoPilotStatusListenerManager.INSTANCE.addListener(TAG, mGoAutopilotStatusListener);
CallerAutopilotVehicleStateListenerManager.INSTANCE.addListener(TAG, mIMoGoAutopilotVehicleStateListener);
autopilotIV = findViewById(R.id.autopilot_iv);
}
private void initView() {
autopilotIV = (ImageView) findViewById(R.id.autopilot_iv);
steeringTV = findViewById(R.id.steering_tv);
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);
steeringCircularV.setProgFirstColor(R.color.hmi_dark_blue);
steeringCircularV.setProgress(20, 20);
tapPositionView.updateWithGear(Chassis.GearPosition.GEAR_R);
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) {
super(context, attrs, defStyleAttr);
Log.d(TAG, "3");
}
public SteeringWheelView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
Log.d(TAG, "4");
}
private final IMoGoAutopilotStatusListener mGoAutopilotStatusListener = new IMoGoAutopilotStatusListener() {
@@ -84,6 +109,8 @@ public class SteeringWheelView extends ConstraintLayout {
} else if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE) {
autopilotIV.setImageResource(R.drawable.bg_auto_nor);
}
} else {
Log.d(TAG, "autopilotIV=null");
}
}
@@ -116,6 +143,8 @@ public class SteeringWheelView extends ConstraintLayout {
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未呈现");
}
@@ -134,4 +163,28 @@ public class SteeringWheelView extends ConstraintLayout {
}
};
/**
* 方向盘随CAN数据做方向和角度旋转
* 参数1从哪一个旋转角度开始
* 参数2转到什么角度
* 后4个参数用于设置围绕着旋转的圆的圆心在哪里
* 参数3肯定x轴坐标的类型有ABSOLUT绝对坐标、RELATIVE_TO_SELF相对于自身坐标、RELATIVE_TO_PARENT相对于父控件的坐标
* 参数4x轴的值0.5f代表是以自身这个控件的一半长度为x轴
* 参数5肯定y轴坐标的类型
* 参数6y轴的值0.5f代表是以自身这个控件的一半长度为x轴
*
* @param steering
*/
private void animationWithSteeringData(float steering) {
Log.d(TAG, "方向盘转动" + String.valueOf(steering));
rotateAnimation = new RotateAnimation(fromDegrees, steering,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(1000);//旋转时长
rotateAnimation.setFillAfter(true);//旋转后保持原状
autopilotIV.clearAnimation();
autopilotIV.startAnimation(rotateAnimation);
fromDegrees = steering;
}
}

View File

@@ -40,40 +40,41 @@ public class TapPositionView extends ConstraintLayout {
}
public void updateWithGear(@NotNull Chassis.GearPosition gear) {
switch (gear) {
case GEAR_NONE:
tabP.setTextColor(Color.parseColor("#6E8EC9"));
tabR.setTextColor(Color.parseColor("#6E8EC9"));
tabN.setTextColor(Color.parseColor("#6E8EC9"));
tabD.setTextColor(Color.parseColor("#6E8EC9"));
break;
case GEAR_P:
tabP.setTextColor(Color.parseColor("#0043FF"));
tabR.setTextColor(Color.parseColor("#6E8EC9"));
tabN.setTextColor(Color.parseColor("#6E8EC9"));
tabD.setTextColor(Color.parseColor("#6E8EC9"));
break;
case GEAR_R:
tabR.setTextColor(Color.parseColor("#0043FF"));
tabP.setTextColor(Color.parseColor("#6E8EC9"));
tabN.setTextColor(Color.parseColor("#6E8EC9"));
tabD.setTextColor(Color.parseColor("#6E8EC9"));
break;
case GEAR_N:
tabN.setTextColor(Color.parseColor("#0043FF"));
tabR.setTextColor(Color.parseColor("#6E8EC9"));
tabP.setTextColor(Color.parseColor("#6E8EC9"));
tabD.setTextColor(Color.parseColor("#6E8EC9"));
break;
case GEAR_D:
tabD.setTextColor(Color.parseColor("#0043FF"));
tabN.setTextColor(Color.parseColor("#6E8EC9"));
tabR.setTextColor(Color.parseColor("#6E8EC9"));
tabP.setTextColor(Color.parseColor("#6E8EC9"));
break;
default:
break;
if (tabP != null && tabR != null && tabN != null && tabD != null) {
switch (gear) {
case GEAR_NONE:
tabP.setTextColor(Color.parseColor("#6E8EC9"));
tabR.setTextColor(Color.parseColor("#6E8EC9"));
tabN.setTextColor(Color.parseColor("#6E8EC9"));
tabD.setTextColor(Color.parseColor("#6E8EC9"));
break;
case GEAR_P:
tabP.setTextColor(Color.parseColor("#0043FF"));
tabR.setTextColor(Color.parseColor("#6E8EC9"));
tabN.setTextColor(Color.parseColor("#6E8EC9"));
tabD.setTextColor(Color.parseColor("#6E8EC9"));
break;
case GEAR_R:
tabR.setTextColor(Color.parseColor("#0043FF"));
tabP.setTextColor(Color.parseColor("#6E8EC9"));
tabN.setTextColor(Color.parseColor("#6E8EC9"));
tabD.setTextColor(Color.parseColor("#6E8EC9"));
break;
case GEAR_N:
tabN.setTextColor(Color.parseColor("#0043FF"));
tabR.setTextColor(Color.parseColor("#6E8EC9"));
tabP.setTextColor(Color.parseColor("#6E8EC9"));
tabD.setTextColor(Color.parseColor("#6E8EC9"));
break;
case GEAR_D:
tabD.setTextColor(Color.parseColor("#0043FF"));
tabN.setTextColor(Color.parseColor("#6E8EC9"));
tabR.setTextColor(Color.parseColor("#6E8EC9"));
tabP.setTextColor(Color.parseColor("#6E8EC9"));
break;
default:
break;
}
}
}
}

View File

@@ -32,11 +32,11 @@
<com.mogo.eagle.core.function.hmi.ui.widget.CircularProgressView
android:id="@+id/steering_circular"
android:layout_width="@dimen/dp_190"
android:layout_height="@dimen/dp_190"
android:layout_width="@dimen/dp_180"
android:layout_height="@dimen/dp_180"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/dp_38"
android:layout_marginTop="@dimen/dp_36"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
@@ -50,8 +50,7 @@
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/dp_54"
android:scaleType="fitXY"
android:src="@drawable/bg_auto_nor"
android:src="@drawable/bg_auto"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

View File

@@ -11,5 +11,6 @@
<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_144">144px</dimen>
<dimen name="dp_300">300px</dimen>
</resources>