Merge branch 'sw' into dev_robotaxi-d-app-module_270_220510_2.7.0

This commit is contained in:
liujing
2022-06-01 18:23:37 +08:00
2 changed files with 41 additions and 30 deletions

View File

@@ -2,12 +2,13 @@ package com.mogo.eagle.core.function.hmi.ui.widget
import android.animation.ValueAnimator
import android.content.Context
import android.content.res.Resources
import android.content.res.TypedArray
import android.graphics.*
import android.util.AttributeSet
import android.util.DisplayMetrics
import android.util.Log
import android.view.View
import android.view.animation.LinearInterpolator
import android.view.animation.OvershootInterpolator
import androidx.core.content.ContextCompat
import com.mogo.eagle.core.function.hmi.R
@@ -32,11 +33,13 @@ class CircularProgressView @JvmOverloads constructor(
private var mRectF: RectF? = null
// 圆环渐变色
private var mColorArray: IntArray? = null
private var mConvertColorsArray: IntArray? = null
// 圆环进度(0-100) 初始化进度
private var mProgress: Int = typedArray.getInteger(R.styleable.CircularProgressView_progress, 0)
var dm: DisplayMetrics = resources.displayMetrics
constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
@@ -56,14 +59,13 @@ class CircularProgressView @JvmOverloads constructor(
mProgPaint.isDither = true // 设置抖动
mProgPaint.strokeWidth = typedArray.getDimension(R.styleable.CircularProgressView_progWidth, 10.0f)
mProgPaint.color = typedArray.getColor(R.styleable.CircularProgressView_progColor, Color.BLUE)
// mProgPaint.setPathEffect()
// 初始化进度圆环渐变色
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)
mConvertColorsArray = intArrayOf(startColor, firstColor)
} else {
mColorArray = null
mConvertColorsArray = null
}
typedArray.recycle();
}
@@ -78,24 +80,40 @@ class CircularProgressView @JvmOverloads constructor(
val mRectT = getPaddingTop() + (viewHigh - mRectLength) / 2
mRectF = RectF(mRectL.toFloat(), mRectT.toFloat(), (mRectL + mRectLength).toFloat(),
(mRectT + mRectLength).toFloat())
// 设置进度圆环渐变色
mColorArray?.let {
mProgPaint.shader = LinearGradient(
0f, 0f, 0f,
measuredWidth.toFloat(), mColorArray!![0], mColorArray!![1], Shader.TileMode.MIRROR)
}
Log.d(TAG, mRectL.toString() + "," + mRectT.toString())
Log.d(TAG, mRectF.toString() + "," + "width:" + measuredWidth.toString() + "," + "PaddingLeft:" + getPaddingLeft().toString())
Log.d(TAG, "onMeasure:" + mRectF.toString() + "," + "width:" + measuredWidth.toString() + "," + "PaddingLeft:" + getPaddingLeft().toString())
}
/**
* 渐变色执行方法
* sweepGradient扫描渐变,前两个参数为中心坐标
* mConvertColorsArray:渐变色数组
* position:与渐变数组个数对应的渐变点
* Matrix:改变开始渐变的角度,默认3点方向,改为12点方向
* */
fun sweepGradient() {
if (mConvertColorsArray == null) {
return
}
val position = FloatArray(2)
position[0] = 0.0f;
position[1] = mProgress.toFloat() * 0.01f
val sweepGradient = SweepGradient((measuredWidth / 2).toFloat(), (measuredHeight / 2).toFloat(), mConvertColorsArray!!, position)
val matrix = Matrix()
matrix.setRotate(-90F, (measuredWidth / 2).toFloat(), (measuredHeight / 2).toFloat())
sweepGradient.setLocalMatrix(matrix);
mProgPaint.setShader(sweepGradient)
}
override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)
Log.d(TAG, "onDraw")
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)
sweepGradient()
var degree: Float = 3.6f * (mProgress.toFloat())
it.drawArc(it1, 275.0f, degree, false, mProgPaint)
}
}
@@ -136,11 +154,13 @@ class CircularProgressView @JvmOverloads constructor(
val animator = ValueAnimator.ofInt(mProgress, progress)
animator.addUpdateListener {
mProgress = it.animatedValue as Int
Log.d(TAG, "setProgress" + mProgress.toString())
invalidate()
}
animator.interpolator = OvershootInterpolator()
animator.interpolator = LinearInterpolator()
animator.duration = animTime
animator.start()
}
}
@@ -193,16 +213,7 @@ class CircularProgressView @JvmOverloads constructor(
fun setProgColor(startColor: Int, endColor: Int) {
mColorArray = intArrayOf(ContextCompat.getColor(context, startColor), ContextCompat.getColor(context, endColor))
mColorArray?.let {
if (mRectF != null) {
mProgPaint.shader = LinearGradient(0f, 0f, 0f,
getMeasuredWidth().toFloat(), mColorArray!![0], mColorArray!![1], Shader.TileMode.MIRROR)
}
}
Log.d(TAG, "setProgColor:" + getMeasuredWidth().toString())
mConvertColorsArray = intArrayOf(ContextCompat.getColor(context, startColor), ContextCompat.getColor(context, endColor))
}
fun setProgColor(colorArray: IntArray) {
@@ -210,8 +221,8 @@ class CircularProgressView @JvmOverloads constructor(
if (it.size < 2) {
return
}
mColorArray = it.copyOf()
mColorArray?.let {
mConvertColorsArray = it.copyOf()
mConvertColorsArray?.let {
mProgPaint.shader = LinearGradient(0f, 0f, 0f,
getMeasuredWidth().toFloat(), it, null, Shader.TileMode.MIRROR)
}

View File

@@ -78,16 +78,16 @@ public class SteeringWheelView extends ConstraintLayout {
steeringCircularV = findViewById(R.id.steering_circular);
steeringCircularV.setBackWidth(8);
steeringCircularV.setBackColor(R.color.hmi_light_back_bg);
steeringCircularV.setProgress((int) (270 * 100) / 360, 2000);
steeringCircularV.setProgColor(R.color.hmi_light_blue, R.color.hmi_dark_blue);
steeringCircularV.setProgress((int) (180 * 100) / 360, 1000);
if (AppIdentityModeUtils.isTaxi(FunctionBuildConfig.appIdentityMode)) {
steeringCircularVAlpha = findViewById(R.id.steering_circular_alpha);
steeringCircularVAlpha.setProgress((int) (270 * 100) / 360, 2000);
steeringCircularV.setProgColor(R.color.hmi_dark_blue, R.color.hmi_light_blue);
steeringCircularVAlpha.setBackWidth(8);
steeringCircularVAlpha.setBackColor(R.color.hmi_clear_00);
steeringCircularVAlpha.setProgColor(R.color.hmi_light_blue_alpha_ff, R.color.hmi_light_blue_alpha_00);
steeringCircularVAlpha.setBlurMaskFilter(BlurMaskFilter.Blur.NORMAL, 12);
steeringCircularVAlpha.setProgress((int) (180 * 100) / 360, 1000);
}
}