diff --git a/OCH/mogo-och-bus-passenger/build.gradle b/OCH/mogo-och-bus-passenger/build.gradle index b38804a63d..fc55956e11 100644 --- a/OCH/mogo-och-bus-passenger/build.gradle +++ b/OCH/mogo-och-bus-passenger/build.gradle @@ -60,6 +60,7 @@ dependencies { implementation rootProject.ext.dependencies.mogo_core_data implementation rootProject.ext.dependencies.mogo_core_function_call implementation rootProject.ext.dependencies.mogo_core_function_v2x + implementation rootProject.ext.dependencies.mogo_core_function_hmi }else { implementation project(":core:mogo-core-utils") implementation project(":foudations:mogo-commons") @@ -67,6 +68,7 @@ dependencies { implementation project(':core:mogo-core-data') implementation project(':core:mogo-core-function-call') implementation project(':core:function-impl:mogo-core-function-v2x') + implementation project(':core:function-impl:mogo-core-function-hmi') } } diff --git a/OCH/mogo-och-bus-passenger/src/main/res/layout/bus_p_base_fragment.xml b/OCH/mogo-och-bus-passenger/src/main/res/layout/bus_p_base_fragment.xml index 77d9ef65f8..92d0795565 100644 --- a/OCH/mogo-och-bus-passenger/src/main/res/layout/bus_p_base_fragment.xml +++ b/OCH/mogo-och-bus-passenger/src/main/res/layout/bus_p_base_fragment.xml @@ -1,6 +1,15 @@ + \ No newline at end of file diff --git a/OCH/mogo-och-bus/src/main/res/layout/fragment_och_bus.xml b/OCH/mogo-och-bus/src/main/res/layout/fragment_och_bus.xml index 558429d9ec..1b3710568c 100644 --- a/OCH/mogo-och-bus/src/main/res/layout/fragment_och_bus.xml +++ b/OCH/mogo-och-bus/src/main/res/layout/fragment_och_bus.xml @@ -170,7 +170,7 @@ 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()) + Log.d(TAG, "渐变色:" + mColorArray?.size.toString()) // 设置进度圆环渐变色 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 +91,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 +104,7 @@ class CircularProgressView @JvmOverloads constructor( * 获取当前进度 * @return 当前进度(0-100) */ - fun getProgress() : Int{ + fun getProgress(): Int { return mProgress } @@ -103,7 +112,7 @@ class CircularProgressView @JvmOverloads constructor( * 设置当前进度 * @param progress 当前进度(0-100) */ - fun setProgress(progress : Int){ + fun setProgress(progress: Int) { mProgress = progress invalidate() } @@ -113,12 +122,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 +141,7 @@ class CircularProgressView @JvmOverloads constructor( * 设置背景圆环宽度 * @param width 背景圆环宽度 */ - fun setBackWidth(width : Int){ + fun setBackWidth(width: Int) { mBackPaint.strokeWidth = width.toFloat() invalidate() } @@ -141,8 +150,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 +159,50 @@ 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 new file mode 100644 index 0000000000..97ab6a6dcd --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/SteeringWheelView.java @@ -0,0 +1,190 @@ +package com.mogo.eagle.core.function.hmi.ui.widget; + +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; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.constraintlayout.widget.ConstraintLayout; + +import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo; +import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener; +import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotVehicleStateListener; +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.utilcode.mogo.logger.CallerLogger; + +import org.jetbrains.annotations.NotNull; + +import chassis.Chassis; +import mogo.telematics.pad.MessagePad; +import mogo_msg.MogoReportMsg; + +import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS_P; + +/** + * @author Jing + * @description 方向盘 + * 方向盘跟随CAN数据做旋转 + * 档位随CAN数据做切换和高亮显示 + * @since: 4/7/22 + */ +public class SteeringWheelView extends ConstraintLayout { + private static final String TAG = "SteeringWheelView"; + private ImageView autopilotIV; + 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); + } + + 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, 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() { + @Override + public void onAutopilotArriveAtStation(@org.jetbrains.annotations.Nullable MessagePad.ArrivalNotification arrivalNotification) { + + } + + @Override + public void onAutopilotGuardian(@Nullable MogoReportMsg.MogoReportMessage guardianInfo) { + + } + + @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) { + + 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_DISABLE) { + autopilotIV.setImageResource(R.drawable.bg_auto_nor); + } + } else { + Log.d(TAG, "autopilotIV=null"); + } + } + + @Override + public void onAutopilotSNRequest() { + + } + }; + + 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) { + if (steeringTV != null && String.valueOf(steering) != null) { + steeringTV.setText(String.valueOf(steering) + "°"); + steeringCircularV.setProgress((int) steering, 1000); + animationWithSteeringData(steering); + } else { + Log.d(TAG, "steering未呈现"); + } + } + + /** + * 档位 + * @param gear + */ + @Override + public void onAutopilotGearData(@NotNull Chassis.GearPosition gear) { + Log.d(TAG, "档位" + gear.toString()); + if (tapPositionView != null) { + tapPositionView.updateWithGear(gear); + } + } + }; + + /** + * 方向盘随CAN数据做方向和角度旋转 + * 参数1从哪一个旋转角度开始 + * 参数2:转到什么角度 + * 后4个参数用于设置围绕着旋转的圆的圆心在哪里 + * 参数3:肯定x轴坐标的类型,有ABSOLUT绝对坐标、RELATIVE_TO_SELF相对于自身坐标、RELATIVE_TO_PARENT相对于父控件的坐标 + * 参数4:x轴的值,0.5f代表是以自身这个控件的一半长度为x轴 + * 参数5:肯定y轴坐标的类型 + * 参数6:y轴的值,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; + } + +} diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/TapPositionView.java b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/TapPositionView.java new file mode 100644 index 0000000000..1a655e3660 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/TapPositionView.java @@ -0,0 +1,80 @@ +package com.mogo.eagle.core.function.hmi.ui.widget; + +import android.content.Context; +import android.graphics.Color; +import android.util.AttributeSet; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.Nullable; +import androidx.constraintlayout.widget.ConstraintLayout; + +import com.mogo.eagle.core.function.hmi.R; + +import org.jetbrains.annotations.NotNull; + +import chassis.Chassis; + +/** + * @author Jing + * @description 方向盘下方的档位 + * @since: 4/7/22 + */ +public class TapPositionView extends ConstraintLayout { + private static final String TAG = "TapPositionView"; + private TextView tabP; + private TextView tabR; + private TextView tabN; + private TextView tabD; + + public TapPositionView(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + Log.d(TAG, "2"); + LayoutInflater.from(context).inflate(R.layout.hmi_tap_position, this); + tabP = findViewById(R.id.tap_p); + tabR = findViewById(R.id.tap_r); + tabN = findViewById(R.id.tap_n); + tabD = findViewById(R.id.tap_d); + } + + public void updateWithGear(@NotNull Chassis.GearPosition gear) { + 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; + } + } + } +} diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/bg_auto.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/bg_auto.png new file mode 100644 index 0000000000..748625a43c Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/bg_auto.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/bg_auto_nor.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/bg_auto_nor.png new file mode 100644 index 0000000000..a9965aaf1f Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/bg_auto_nor.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/bg_steering_outer.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/bg_steering_outer.xml new file mode 100644 index 0000000000..f5e1da1a55 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/bg_steering_outer.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/bg_steering_wheel.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/bg_steering_wheel.xml new file mode 100644 index 0000000000..156cc4f0e0 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/bg_steering_wheel.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/icon_in_steering.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/icon_in_steering.png new file mode 100644 index 0000000000..4545e67555 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/icon_in_steering.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/streeing_wheel_rotate.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/streeing_wheel_rotate.xml new file mode 100644 index 0000000000..a883260939 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/streeing_wheel_rotate.xml @@ -0,0 +1,18 @@ + + + + + + + + \ 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 new file mode 100644 index 0000000000..aa5a02d635 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_steering_wheel.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_tap_position.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_tap_position.xml new file mode 100644 index 0000000000..5020791857 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/hmi_tap_position.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + \ No newline at end of file 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 diff --git a/modules/mogo-module-common/src/main/res/values-xhdpi-2560x1600/dimens.xml b/modules/mogo-module-common/src/main/res/values-xhdpi-2560x1600/dimens.xml index 3fec33a8e2..e8a50c2de8 100644 --- a/modules/mogo-module-common/src/main/res/values-xhdpi-2560x1600/dimens.xml +++ b/modules/mogo-module-common/src/main/res/values-xhdpi-2560x1600/dimens.xml @@ -11,5 +11,6 @@ 120px 37px 27px - + 144px + 300px