From e6f8db51b2371e430c5f8198a37d5fe65c69e747 Mon Sep 17 00:00:00 2001 From: liujing Date: Fri, 8 Apr 2022 11:32:06 +0800 Subject: [PATCH] =?UTF-8?q?[rm]=20=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E8=B5=84=E6=BA=90,=E6=A1=A3=E4=BD=8D+=E6=96=B9=E5=90=91?= =?UTF-8?q?=E7=9B=98=E8=A7=92=E5=BA=A6=E4=B8=9A=E5=8A=A1=E5=AE=B9=E9=94=99?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E6=B7=BB=E5=8A=A0,=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E6=9D=A1UI=E9=85=8D=E7=BD=AE=E8=AE=BE=E7=BD=AE=20=E7=BC=BA?= =?UTF-8?q?=E5=B0=91=E8=BF=9B=E5=BA=A6=E6=9D=A1=E6=A0=B9=E6=8D=AE=E6=96=B9?= =?UTF-8?q?=E5=90=91=E7=9B=98=E8=A7=92=E5=BA=A6=E8=BD=AC=E5=8A=A8+?= =?UTF-8?q?=E6=96=B9=E5=90=91=E7=9B=98=E8=BD=AC=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmi/ui/widget/CircularProgressView.kt | 96 +++++++++++-------- .../hmi/ui/widget/SteeringWheelView.java | 48 +++++++--- .../taxi_steering_wheel_color_selector.xml | 12 --- .../main/res/layout/hmi_steering_wheel.xml | 4 +- .../src/main/res/values/color.xml | 3 + 5 files changed, 98 insertions(+), 65 deletions(-) delete mode 100644 core/function-impl/mogo-core-function-hmi/src/main/res/color/taxi_steering_wheel_color_selector.xml diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/CircularProgressView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/CircularProgressView.kt index 66be06132d..eaa0cc7885 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/CircularProgressView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/CircularProgressView.kt @@ -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) } } diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/SteeringWheelView.java b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/SteeringWheelView.java index f6f59bfa29..6adfdd1cca 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/SteeringWheelView.java +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/SteeringWheelView.java @@ -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); + } } }; + } diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/color/taxi_steering_wheel_color_selector.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/color/taxi_steering_wheel_color_selector.xml deleted file mode 100644 index 0d2bcb88d7..0000000000 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/color/taxi_steering_wheel_color_selector.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_steering_wheel.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_steering_wheel.xml index 016545b117..5108cbb5d9 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_steering_wheel.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_steering_wheel.xml @@ -31,15 +31,15 @@ app:layout_constraintTop_toTopOf="parent" /> diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/values/color.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/values/color.xml index bd4ed43a04..5bc14b5b52 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/values/color.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/values/color.xml @@ -53,4 +53,7 @@ #FF006D43 #FFFFE198 #FFFF9B00 + #45D3FF + #1B5BFF + #0045D3FF \ No newline at end of file