[6.5.0]融合红绿灯UI调整
This commit is contained in:
@@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.mogo.eagle.core.data.enums.DataSourceType
|
||||
@@ -13,14 +14,6 @@ import com.mogo.eagle.core.function.call.v2x.CallerTrafficLightListenerManager
|
||||
import com.mogo.eagle.core.function.hmi.R
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import kotlinx.android.synthetic.main.hmi_view_fusion_traffic_light.view.fusionTrafficLightBg
|
||||
import kotlinx.android.synthetic.main.hmi_view_fusion_traffic_light.view.fusionTrafficLightNum
|
||||
import kotlinx.android.synthetic.main.hmi_view_fusion_traffic_light.view.fusionTrafficLightPointer
|
||||
import kotlinx.android.synthetic.main.hmi_view_fusion_traffic_light.view.fusionTrafficLightProportion
|
||||
import kotlinx.android.synthetic.main.hmi_view_fusion_traffic_light.view.fusionTrafficLightScale
|
||||
import kotlinx.android.synthetic.main.hmi_view_fusion_traffic_light.view.fusionTrafficLightState
|
||||
import java.util.LinkedList
|
||||
|
||||
/**
|
||||
* 融合红绿灯View
|
||||
* 鹰眼6.5.0版本需求
|
||||
@@ -42,6 +35,12 @@ class FusionTrafficLightView @JvmOverloads constructor(
|
||||
private var maxYellowDuration = 0 //黄灯最长时间
|
||||
private var maxRedDuration = 0 //红灯最长时间
|
||||
|
||||
private var fusionTrafficLightNum: TypefaceTextView ?=null //融合红绿灯倒计时
|
||||
private var fusionTrafficLightState: ImageView ?= null //融合红绿灯灯态
|
||||
private var fusionTrafficLightScale: ImageView ?= null //融合红绿灯刻度
|
||||
private var fusionTrafficLightPointer: ImageView ?= null //融合红绿灯指针
|
||||
private var fusionTrafficLightProportion: ProportionChartView ?= null //占比进度条
|
||||
|
||||
|
||||
init {
|
||||
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.FusionTrafficLightView)
|
||||
@@ -51,13 +50,17 @@ class FusionTrafficLightView @JvmOverloads constructor(
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
LayoutInflater.from(context).inflate(R.layout.hmi_view_fusion_traffic_light, this, true)
|
||||
CallerTrafficLightListenerManager.addListener(TAG, this)
|
||||
if(user == 0){
|
||||
fusionTrafficLightBg.setBackgroundResource(R.drawable.bg_fusion_traffic_light)
|
||||
LayoutInflater.from(context).inflate(R.layout.hmi_view_fusion_traffic_light, this, true)
|
||||
}else{
|
||||
fusionTrafficLightBg.setBackgroundResource(R.drawable.bg_fusion_traffic_light_p)
|
||||
LayoutInflater.from(context).inflate(R.layout.hmi_view_fusion_traffic_light_p, this, true)
|
||||
}
|
||||
CallerTrafficLightListenerManager.addListener(TAG, this)
|
||||
fusionTrafficLightNum = findViewById(R.id.fusionTrafficLightNum)
|
||||
fusionTrafficLightState = findViewById(R.id.fusionTrafficLightState)
|
||||
fusionTrafficLightScale = findViewById(R.id.fusionTrafficLightScale)
|
||||
fusionTrafficLightPointer = findViewById(R.id.fusionTrafficLightPointer)
|
||||
fusionTrafficLightProportion = findViewById(R.id.fusionTrafficLightProportion)
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
@@ -111,10 +114,10 @@ class FusionTrafficLightView @JvmOverloads constructor(
|
||||
}
|
||||
TrafficLightEnum.YELLOW -> {
|
||||
proportionList.add(1,currentDuration)
|
||||
if(currentDuration < 3){
|
||||
maxYellowDuration = 3
|
||||
maxYellowDuration = if(currentDuration < 3){
|
||||
3
|
||||
}else{
|
||||
maxYellowDuration = currentDuration
|
||||
currentDuration
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
@@ -129,10 +132,10 @@ class FusionTrafficLightView @JvmOverloads constructor(
|
||||
}
|
||||
TrafficLightEnum.YELLOW -> {
|
||||
proportionList.add(1,nextDuration)
|
||||
if(nextDuration<3){
|
||||
maxYellowDuration = 3
|
||||
maxYellowDuration = if(nextDuration<3){
|
||||
3
|
||||
}else{
|
||||
maxYellowDuration = nextDuration
|
||||
nextDuration
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
@@ -147,10 +150,10 @@ class FusionTrafficLightView @JvmOverloads constructor(
|
||||
}
|
||||
TrafficLightEnum.YELLOW -> {
|
||||
proportionList.add(1,nextTwoDuration)
|
||||
if(nextTwoDuration<3){
|
||||
maxYellowDuration = 3
|
||||
maxYellowDuration = if(nextTwoDuration<3){
|
||||
3
|
||||
}else{
|
||||
maxYellowDuration = nextTwoDuration
|
||||
nextTwoDuration
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
@@ -158,48 +161,47 @@ class FusionTrafficLightView @JvmOverloads constructor(
|
||||
maxRedDuration = nextTwoDuration
|
||||
}
|
||||
}
|
||||
fusionTrafficLightProportion.updateProportion(proportionList)
|
||||
fusionTrafficLightProportion?.updateProportion(proportionList)
|
||||
totalDuration = maxGreenDuration + maxYellowDuration + maxRedDuration
|
||||
}
|
||||
//根据当前灯态设置转盘、刻度、指针背景
|
||||
when(currentState){
|
||||
TrafficLightEnum.GREEN -> {
|
||||
fusionTrafficLightState.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_green))
|
||||
fusionTrafficLightScale.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_green_scale))
|
||||
fusionTrafficLightPointer.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_green_pointer))
|
||||
fusionTrafficLightState?.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_green))
|
||||
fusionTrafficLightScale?.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_green_scale))
|
||||
fusionTrafficLightPointer?.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_green_pointer))
|
||||
}
|
||||
TrafficLightEnum.YELLOW -> {
|
||||
fusionTrafficLightState.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_yellow))
|
||||
fusionTrafficLightScale.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_yellow_scale))
|
||||
fusionTrafficLightPointer.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_yellow_pointer))
|
||||
fusionTrafficLightState?.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_yellow))
|
||||
fusionTrafficLightScale?.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_yellow_scale))
|
||||
fusionTrafficLightPointer?.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_yellow_pointer))
|
||||
}
|
||||
else -> {
|
||||
fusionTrafficLightState.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_red))
|
||||
fusionTrafficLightScale.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_red_scale))
|
||||
fusionTrafficLightPointer.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_red_pointer))
|
||||
fusionTrafficLightState?.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_red))
|
||||
fusionTrafficLightScale?.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_red_scale))
|
||||
fusionTrafficLightPointer?.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.icon_light_red_pointer))
|
||||
}
|
||||
}
|
||||
//更新当前灯态倒计时时间
|
||||
if(currentDuration>0){
|
||||
fusionTrafficLightNum.text = currentDuration.toString()
|
||||
fusionTrafficLightNum?.text = currentDuration.toString()
|
||||
}else{
|
||||
fusionTrafficLightNum.text = "0"
|
||||
fusionTrafficLightNum?.text = "0"
|
||||
}
|
||||
//当时间为1开头时时间视觉上看不是左右居中对齐,需要做便宜操作
|
||||
if(currentDuration.toString().startsWith("1")){
|
||||
val numLayoutParams = fusionTrafficLightNum.layoutParams as LayoutParams
|
||||
numLayoutParams.rightMargin = 10
|
||||
fusionTrafficLightNum.layoutParams = numLayoutParams
|
||||
val numLayoutParams = fusionTrafficLightNum?.layoutParams as LayoutParams
|
||||
numLayoutParams.rightMargin = 6
|
||||
fusionTrafficLightNum?.layoutParams = numLayoutParams
|
||||
}else{
|
||||
val numLayoutParams = fusionTrafficLightNum.layoutParams as LayoutParams
|
||||
val numLayoutParams = fusionTrafficLightNum?.layoutParams as LayoutParams
|
||||
numLayoutParams.rightMargin = 0
|
||||
fusionTrafficLightNum.layoutParams = numLayoutParams
|
||||
fusionTrafficLightNum?.layoutParams = numLayoutParams
|
||||
}
|
||||
|
||||
//更新指针指向
|
||||
val pointerLayoutParams = fusionTrafficLightPointer.layoutParams as LayoutParams
|
||||
var currentAngle = 0f
|
||||
currentAngle = when (currentState) {
|
||||
val pointerLayoutParams = fusionTrafficLightPointer?.layoutParams as LayoutParams
|
||||
val currentAngle = when (currentState) {
|
||||
TrafficLightEnum.GREEN -> {
|
||||
360f*(maxGreenDuration-currentDuration)/totalDuration
|
||||
}
|
||||
@@ -213,8 +215,8 @@ class FusionTrafficLightView @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
pointerLayoutParams.circleAngle = currentAngle
|
||||
fusionTrafficLightPointer.rotation = currentAngle
|
||||
fusionTrafficLightPointer.layoutParams = pointerLayoutParams
|
||||
fusionTrafficLightPointer?.rotation = currentAngle
|
||||
fusionTrafficLightPointer?.layoutParams = pointerLayoutParams
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.SweepGradient;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.mogo.eagle.core.function.hmi.R;
|
||||
@@ -132,7 +131,6 @@ public class ProportionChartView extends View {
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
Log.i("xuxinchao","onDraw canvas");
|
||||
drawRingView(canvas);
|
||||
}
|
||||
|
||||
@@ -140,7 +138,6 @@ public class ProportionChartView extends View {
|
||||
* 画Ring
|
||||
*/
|
||||
private void drawRingView(Canvas canvas){
|
||||
Log.i("xuxinchao","drawRingView 画Ring");
|
||||
float sweepAngle = 0f;
|
||||
float startAngle = -90f;
|
||||
//矩形坐标
|
||||
@@ -176,7 +173,7 @@ public class ProportionChartView extends View {
|
||||
}
|
||||
mRingPaint.setShader(sweepGradient);
|
||||
//画圆环
|
||||
canvas.drawArc(mRectF, startAngle, sweepAngle - 2, false, mRingPaint);
|
||||
canvas.drawArc(mRectF, startAngle, sweepAngle, false, mRingPaint);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/fusionTrafficLightBg"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_fusion_traffic_light_p"
|
||||
android:layout_width="@dimen/dp_200"
|
||||
android:layout_height="@dimen/dp_200"
|
||||
android:background="@drawable/bg_fusion_traffic_light"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
@@ -51,15 +51,15 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="@dimen/sp_55"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/sp_69"
|
||||
app:textType="DS_DIGIB_2"
|
||||
/>
|
||||
|
||||
<com.mogo.eagle.core.function.hmi.ui.widget.ProportionChartView
|
||||
android:id="@+id/fusionTrafficLightProportion"
|
||||
android:layout_width="@dimen/dp_170"
|
||||
android:layout_height="@dimen/dp_170"
|
||||
android:layout_width="@dimen/dp_180"
|
||||
android:layout_height="@dimen/dp_180"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/fusionTrafficLightBg"
|
||||
android:layout_width="@dimen/dp_250"
|
||||
android:layout_height="@dimen/dp_250"
|
||||
android:background="@drawable/bg_fusion_traffic_light_p"
|
||||
>
|
||||
|
||||
<com.mogo.eagle.core.function.hmi.ui.widget.ProportionChartView
|
||||
android:id="@+id/fusionTrafficLightProportion"
|
||||
android:layout_width="@dimen/dp_180"
|
||||
android:layout_height="@dimen/dp_180"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:layout_marginBottom="@dimen/dp_12"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/fusionTrafficLightState"
|
||||
android:layout_width="@dimen/dp_147"
|
||||
android:layout_height="@dimen/dp_147"
|
||||
app:layout_constraintTop_toTopOf="@id/fusionTrafficLightProportion"
|
||||
app:layout_constraintBottom_toBottomOf="@id/fusionTrafficLightProportion"
|
||||
app:layout_constraintLeft_toLeftOf="@id/fusionTrafficLightProportion"
|
||||
app:layout_constraintRight_toRightOf="@id/fusionTrafficLightProportion"
|
||||
android:src="@drawable/icon_light_green"
|
||||
android:contentDescription="@string/fusion_traffic_light_state"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/fusionTrafficLightScale"
|
||||
android:layout_width="@dimen/dp_148"
|
||||
android:layout_height="@dimen/dp_148"
|
||||
app:layout_constraintTop_toTopOf="@id/fusionTrafficLightProportion"
|
||||
app:layout_constraintBottom_toBottomOf="@id/fusionTrafficLightProportion"
|
||||
app:layout_constraintLeft_toLeftOf="@id/fusionTrafficLightProportion"
|
||||
app:layout_constraintRight_toRightOf="@id/fusionTrafficLightProportion"
|
||||
android:src="@drawable/icon_light_green_scale"
|
||||
android:contentDescription="@string/fusion_traffic_light_scale"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/fusionTrafficLightPointer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintCircle="@id/fusionTrafficLightState"
|
||||
app:layout_constraintCircleRadius="@dimen/dp_60"
|
||||
android:src="@drawable/icon_light_green_pointer"
|
||||
android:contentDescription="@string/fusion_traffic_light_pointer"
|
||||
tools:ignore="MissingConstraints"
|
||||
/>
|
||||
|
||||
<com.mogo.eagle.core.function.hmi.ui.widget.TypefaceTextView
|
||||
android:id="@+id/fusionTrafficLightNum"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="@id/fusionTrafficLightProportion"
|
||||
app:layout_constraintBottom_toBottomOf="@id/fusionTrafficLightProportion"
|
||||
app:layout_constraintLeft_toLeftOf="@id/fusionTrafficLightProportion"
|
||||
app:layout_constraintRight_toRightOf="@id/fusionTrafficLightProportion"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="@dimen/sp_69"
|
||||
app:textType="DS_DIGIB_2"
|
||||
/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -35,7 +35,7 @@
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="@id/tvPromptContent"
|
||||
android:layout_marginRight="@dimen/dp_15"
|
||||
android:textSize="@dimen/sp_40"
|
||||
android:textSize="@dimen/sp_48"
|
||||
android:textColor="@color/light_prompt_red"
|
||||
app:textType="DS_DIGIB_2"
|
||||
/>
|
||||
@@ -44,8 +44,10 @@
|
||||
android:id="@+id/tvTrafficNum"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="@id/tvTrafficNumDecimal"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintRight_toLeftOf="@id/tvTrafficNumDecimal"
|
||||
android:layout_marginTop="@dimen/dp_26"
|
||||
android:layout_marginRight="@dimen/dp_2"
|
||||
android:textSize="@dimen/sp_90"
|
||||
android:textColor="@color/light_prompt_red"
|
||||
app:textType="DS_DIGIB_2"
|
||||
|
||||
@@ -13,30 +13,31 @@
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
android:textSize="@dimen/sp_32"
|
||||
android:textColor="@color/light_prompt_content"
|
||||
android:layout_marginTop="@dimen/dp_50"
|
||||
android:layout_marginStart="@dimen/dp_50"
|
||||
android:layout_marginTop="@dimen/dp_55"
|
||||
android:layout_marginStart="@dimen/dp_70"
|
||||
/>
|
||||
|
||||
<com.mogo.eagle.core.function.hmi.ui.widget.TypefaceTextView
|
||||
android:id="@+id/tvTrafficNum"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="@id/tvPromptContent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintLeft_toRightOf="@id/tvPromptContent"
|
||||
android:textSize="@dimen/sp_76"
|
||||
android:layout_marginLeft="@dimen/dp_25"
|
||||
android:textSize="@dimen/sp_90"
|
||||
android:layout_marginLeft="@dimen/dp_30"
|
||||
app:textType="DS_DIGIB_2"
|
||||
android:layout_marginTop="@dimen/dp_20"
|
||||
/>
|
||||
|
||||
<com.mogo.eagle.core.function.hmi.ui.widget.TypefaceTextView
|
||||
android:id="@+id/tvTrafficNumDecimal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="@id/tvTrafficNum"
|
||||
app:layout_constraintBottom_toBottomOf="@id/tvPromptContent"
|
||||
app:layout_constraintLeft_toRightOf="@id/tvTrafficNum"
|
||||
android:textSize="@dimen/sp_30"
|
||||
android:layout_marginLeft="@dimen/dp_2"
|
||||
android:textSize="@dimen/sp_48"
|
||||
app:textType="DS_DIGIB_2"
|
||||
android:gravity="bottom"
|
||||
/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user