[rm] 删除无用资源,档位+方向盘角度业务容错逻辑添加,进度条UI配置设置

缺少进度条根据方向盘角度转动+方向盘转动
This commit is contained in:
liujing
2022-04-08 11:32:06 +08:00
parent 8b13a991f8
commit e6f8db51b2
5 changed files with 98 additions and 65 deletions

View File

@@ -16,23 +16,27 @@ import com.mogo.eagle.core.function.hmi.R
* @since: 2022/1/14
*/
class CircularProgressView @JvmOverloads constructor(
context: Context, attrs: AttributeSet?, defStyleAttr : Int)
: View(context, attrs, defStyleAttr){
context: Context, attrs: AttributeSet?, defStyleAttr: Int)
: View(context, attrs, defStyleAttr) {
val typedArray: TypedArray = context.obtainStyledAttributes(attrs, R.styleable.CircularProgressView)
val typedArray : TypedArray = context.obtainStyledAttributes(attrs, R.styleable.CircularProgressView)
// 绘制画笔
private val mBackPaint : Paint = Paint()
private val mProgPaint : Paint = Paint()
private val mBackPaint: Paint = Paint()
private val mProgPaint: Paint = Paint()
// 绘制区域
private var mRectF : RectF? = null
private var mRectF: RectF? = null
// 圆环渐变色
private var mColorArray : IntArray?=null
private var mColorArray: IntArray? = null
// 圆环进度(0-100) 初始化进度
private var mProgress : Int = typedArray.getInteger(R.styleable.CircularProgressView_progress, 0)
private var mProgress: Int = typedArray.getInteger(R.styleable.CircularProgressView_progress, 0)
constructor(context : Context) : this(context,null)
constructor(context: Context) : this(context, null)
constructor(context : Context,attrs : AttributeSet?) :this(context, attrs, 0)
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
init {
// 初始化背景圆环画笔
@@ -52,9 +56,9 @@ class CircularProgressView @JvmOverloads constructor(
// 初始化进度圆环渐变色
val startColor = typedArray.getColor(R.styleable.CircularProgressView_progStartColor, -1)
val firstColor = typedArray.getColor(R.styleable.CircularProgressView_progFirstColor, -1)
if(startColor != -1 && firstColor != -1){
mColorArray = intArrayOf(startColor,firstColor)
}else{
if (startColor != -1 && firstColor != -1) {
mColorArray = intArrayOf(startColor, firstColor)
} else {
mColorArray = null
}
@@ -67,16 +71,16 @@ class CircularProgressView @JvmOverloads constructor(
val viewWide = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
val viewHigh = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();
val mRectLength =
((if (viewWide > viewHigh) viewHigh else viewWide) - if (mBackPaint.strokeWidth > mProgPaint.strokeWidth) mBackPaint.strokeWidth else mProgPaint.strokeWidth).toInt()
((if (viewWide > viewHigh) viewHigh else viewWide) - if (mBackPaint.strokeWidth > mProgPaint.strokeWidth) mBackPaint.strokeWidth else mProgPaint.strokeWidth).toInt()
val mRectL = getPaddingLeft() + (viewWide - mRectLength) / 2
val mRectT = getPaddingTop() + (viewHigh - mRectLength) / 2
mRectF = RectF(mRectL.toFloat(), mRectT.toFloat(), (mRectL + mRectLength).toFloat(),
(mRectT + mRectLength).toFloat())
(mRectT + mRectLength).toFloat())
// 设置进度圆环渐变色
mColorArray?.let {
mProgPaint.shader = LinearGradient(
0.0f, 0.0f, 0.0f,
measuredWidth.toFloat(), it, null, Shader.TileMode.MIRROR)
0.0f, 0.0f, 0.0f,
measuredWidth.toFloat(), it, null, Shader.TileMode.MIRROR)
}
}
@@ -84,9 +88,11 @@ class CircularProgressView @JvmOverloads constructor(
override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)
canvas?.let {
mRectF?.let { it1 -> it.drawArc(it1, 0.0f, 360.0f, false, mBackPaint) }
mRectF?.let { it1 -> it.drawArc(it1, 275.0f,
(360 * mProgress / 100).toFloat(), false, mProgPaint) }
mRectF?.let { it1 -> it.drawArc(it1, 0.0f, 360.0f, false, mBackPaint) }
mRectF?.let { it1 ->
it.drawArc(it1, 275.0f,
(360 * mProgress / 100).toFloat(), false, mProgPaint)
}
}
}
@@ -95,7 +101,7 @@ class CircularProgressView @JvmOverloads constructor(
* 获取当前进度
* @return 当前进度0-100
*/
fun getProgress() : Int{
fun getProgress(): Int {
return mProgress
}
@@ -103,7 +109,7 @@ class CircularProgressView @JvmOverloads constructor(
* 设置当前进度
* @param progress 当前进度0-100
*/
fun setProgress(progress : Int){
fun setProgress(progress: Int) {
mProgress = progress
invalidate()
}
@@ -113,12 +119,12 @@ class CircularProgressView @JvmOverloads constructor(
* @param progress 当前进度0-100
* @param animTime 动画时间(毫秒)
*/
fun setProgress(progress : Int, animTime : Long){
if (animTime<=0){
fun setProgress(progress: Int, animTime: Long) {
if (animTime <= 0) {
setProgress(progress)
} else{
} else {
val animator = ValueAnimator.ofInt(mProgress, progress)
animator.addUpdateListener{
animator.addUpdateListener {
mProgress = it.animatedValue as Int
invalidate()
}
@@ -132,7 +138,7 @@ class CircularProgressView @JvmOverloads constructor(
* 设置背景圆环宽度
* @param width 背景圆环宽度
*/
fun setBackWidth(width : Int){
fun setBackWidth(width: Int) {
mBackPaint.strokeWidth = width.toFloat()
invalidate()
}
@@ -141,8 +147,8 @@ class CircularProgressView @JvmOverloads constructor(
* 设置背景圆环颜色
* @param color 背景圆环颜色
*/
fun setBackColor(color : Int){
mBackPaint.color = ContextCompat.getColor(context,color)
fun setBackColor(color: Int) {
mBackPaint.color = ContextCompat.getColor(context, color)
invalidate()
}
@@ -150,39 +156,49 @@ class CircularProgressView @JvmOverloads constructor(
* 设置进度圆环宽度
* @param width 进度圆环宽度
*/
fun setProgWidth(width : Int){
fun setProgWidth(width: Int) {
mProgPaint.strokeWidth = width.toFloat()
invalidate()
}
/**
* 设置进度圆环
* 设置进度圆环渐变色起始
* @param color 景圆环颜色
*/
fun setProgColor(color : Int){
mProgPaint.color = ContextCompat.getColor(context,color)
fun setProgColor(color: Int) {
mProgPaint.color = ContextCompat.getColor(context, color)
mProgPaint.shader = null
invalidate()
}
fun setProgColor(startColor : Int,endColor: Int){
mColorArray = intArrayOf(ContextCompat.getColor(context,startColor),ContextCompat.getColor(context,endColor))
/**
* 渐变色结束色
*/
fun setProgFirstColor(color: Int) {
mProgPaint.color = ContextCompat.getColor(context, color)
mProgPaint.shader = null
invalidate()
}
fun setProgColor(startColor: Int, endColor: Int) {
mColorArray = intArrayOf(ContextCompat.getColor(context, startColor), ContextCompat.getColor(context, endColor))
mColorArray?.let {
mProgPaint.shader = LinearGradient(0f, 0f, 0f,
getMeasuredWidth().toFloat(), it, null, Shader.TileMode.MIRROR)
getMeasuredWidth().toFloat(), it, null, Shader.TileMode.MIRROR)
}
}
fun setProgColor(colorArray : IntArray){
fun setProgColor(colorArray: IntArray) {
colorArray.let {
if(it.size<2){
if (it.size < 2) {
return
}
mColorArray = it.copyOf()
mColorArray?.let{
mColorArray?.let {
mProgPaint.shader = LinearGradient(0f, 0f, 0f,
getMeasuredWidth().toFloat(), it, null, Shader.TileMode.MIRROR)
getMeasuredWidth().toFloat(), it, null, Shader.TileMode.MIRROR)
}
}

View File

@@ -37,16 +37,23 @@ public class SteeringWheelView extends ConstraintLayout {
private ImageView autopilotIV;
private TextView steeringTV;
private TapPositionView tapPositionView;
private CircularProgressView steeringCircularV;
public SteeringWheelView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.hmi_steering_wheel, this);
Log.d(TAG, "2");
CallerAutoPilotStatusListenerManager.INSTANCE.addListener(TAG, mGoAutopilotStatusListener);
CallerAutopilotVehicleStateListenerManager.INSTANCE.addListener(TAG, mIMoGoAutopilotVehicleStateListener);
autopilotIV = 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);
}
private final IMoGoAutopilotStatusListener mGoAutopilotStatusListener = new IMoGoAutopilotStatusListener() {
@@ -65,14 +72,18 @@ public class SteeringWheelView extends ConstraintLayout {
if (autopilotStatusInfo == null) return;
int state = autopilotStatusInfo.getState();
CallerLogger.INSTANCE.d(M_BUS_P + TAG, "state = %s", state);
if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
autopilotIV.setImageResource(R.drawable.bg_auto);
if (autopilotIV != null) {
Log.d(TAG, "autopilotIV != null");
if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
} else if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE) {
autopilotIV.setImageResource(R.drawable.bg_auto_nor);
autopilotIV.setImageResource(R.drawable.bg_auto);
} else if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE) {
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);
}
}
}
@@ -83,19 +94,31 @@ public class SteeringWheelView extends ConstraintLayout {
};
private final IMoGoAutopilotVehicleStateListener mIMoGoAutopilotVehicleStateListener = new IMoGoAutopilotVehicleStateListener() {
/**
* 车辆转向灯
* @param lightSwitch
*/
@Override
public void onAutopilotLightSwitchData(@org.jetbrains.annotations.Nullable Chassis.LightSwitch lightSwitch) {
Log.d(TAG, "车辆转向灯:" + lightSwitch.toString());
}
/**
* 刹车灯
* @param brakeLight
*/
@Override
public void onAutopilotBrakeLightData(boolean brakeLight) {
Log.d(TAG, "刹车灯:" + String.valueOf(brakeLight));
}
@Override
public void onAutopilotSteeringData(float steering) {
steeringTV.setText(String.valueOf(steering) + "°");
if (steeringTV != null && String.valueOf(steering) != null) {
steeringTV.setText(String.valueOf(steering) + "°");
} else {
Log.d(TAG, "steering未呈现");
}
}
/**
@@ -105,7 +128,10 @@ public class SteeringWheelView extends ConstraintLayout {
@Override
public void onAutopilotGearData(@NotNull Chassis.GearPosition gear) {
Log.d(TAG, "档位" + gear.toString());
if (tapPositionView != null) {
tapPositionView.updateWithGear(gear);
}
}
};
}

View File

@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:bottomLeftRadius="20px"
android:bottomRightRadius="50px"
android:topLeftRadius="50px"
android:topRightRadius="20px" />
<gradient android:angle="315" android:endColor="#1B5BFF" android:startColor="#45D3FF" />
</shape>
</item>
</selector>

View File

@@ -31,15 +31,15 @@
app:layout_constraintTop_toTopOf="parent" />
<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_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/dp_30"
android:layout_marginTop="@dimen/dp_38"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:progColor="@color/taxi_steering_wheel_color_selector"
app:progWidth="8px"
app:progress="0" />

View File

@@ -53,4 +53,7 @@
<color name="hmi_traffic_light_green_color_down">#FF006D43</color>
<color name="hmi_traffic_light_yellow_color_up">#FFFFE198</color>
<color name="hmi_traffic_light_yellow_color_down">#FFFF9B00</color>
<color name="hmi_light_blue">#45D3FF</color>
<color name="hmi_dark_blue">#1B5BFF</color>
<color name="hmi_light_blue_00">#0045D3FF</color>
</resources>