抽离优化速度卡片
This commit is contained in:
@@ -67,7 +67,6 @@ import com.mogo.module.extensions.utils.EntranceViewHolder;
|
||||
import com.mogo.module.extensions.utils.NoMapTopViewShaderHelper;
|
||||
import com.mogo.module.extensions.utils.TopViewAnimHelper;
|
||||
import com.mogo.module.extensions.utils.TopViewNoLinkageAnimHelper;
|
||||
import com.mogo.module.extensions.view.SpeedChartView;
|
||||
import com.mogo.module.service.receiver.MogoReceiver;
|
||||
import com.mogo.module.share.manager.ServiceApisManager;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
@@ -126,7 +125,6 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
|
||||
IMogoAimlessModeListener,
|
||||
IMogoStatusChangedListener,
|
||||
IMogoIntentListener,
|
||||
// IMogoLocationListener,
|
||||
IMogoCarLocationChangedListener2 {
|
||||
|
||||
private static final String TAG = "EntranceFragment";
|
||||
@@ -205,8 +203,6 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
|
||||
private TextView tvExitVrMode;
|
||||
|
||||
|
||||
private FrameLayout flSpeed;
|
||||
private SpeedChartView mouduleArc;
|
||||
private ConstraintLayout clTrafficLight;
|
||||
private TextView tvYellow;
|
||||
private TextView tvRed;
|
||||
@@ -366,18 +362,6 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
|
||||
// 根据本地配置设置自车图标
|
||||
MyLocationUtil.setMyLocationIconUrl(getContext());
|
||||
|
||||
flSpeed = (FrameLayout) findViewById(R.id.fl_speed);
|
||||
mouduleArc = (SpeedChartView) findViewById(R.id.moudule_arc);
|
||||
if (DebugConfig.isDebug()) {
|
||||
mouduleArc.setLongClickable(true);
|
||||
mouduleArc.setOnLongClickListener(v -> {
|
||||
Log.d(TAG,"长按显示状态工具栏");
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("oper", 52);
|
||||
MogoApisHandler.getInstance().getApis().getIntentManagerApi().invoke(MogoReceiver.ACTION_MOCK, intent);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
clTrafficLight = (ConstraintLayout) findViewById(R.id.cl_traffic_light);
|
||||
tvYellow = (TextView) findViewById(R.id.tv_yellow);
|
||||
tvRed = (TextView) findViewById(R.id.tv_red);
|
||||
@@ -420,7 +404,6 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
|
||||
.registerCarLocationChangedListener(TAG, this);
|
||||
|
||||
localIsVrMode = true;
|
||||
flSpeed.setVisibility(View.VISIBLE);
|
||||
mSwitchMapModeLayout.setVisibility(View.VISIBLE);
|
||||
mApis.getV2XListenerManager().changeTipWindowStatusForListener(ACTION_V2X_REMOVE_TIP_WINDOW);
|
||||
}
|
||||
@@ -434,10 +417,6 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
|
||||
if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isSeekHelping()) {
|
||||
seekHelpGroup.setVisibility(View.VISIBLE);
|
||||
}
|
||||
// mWeatherContainer.setVisibility(View.VISIBLE);
|
||||
// mMsgContainer.setVisibility(View.VISIBLE);
|
||||
|
||||
// tvExitVrMode.setVisibility(View.GONE);
|
||||
TopViewAnimHelper.getInstance().exitVrMode();
|
||||
TopViewNoLinkageAnimHelper.getInstance().exitVrMode();
|
||||
mNaviInfo = animNavInfoView;
|
||||
@@ -446,7 +425,6 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
|
||||
|
||||
MogoApisHandler.getInstance().getApis().getRegisterCenterApi().unregisterMogoLocationListener(TAG);
|
||||
localIsVrMode = false;
|
||||
flSpeed.setVisibility(View.GONE);
|
||||
mSwitchMapModeLayout.setVisibility(View.GONE);
|
||||
clTrafficLight.setVisibility(View.GONE);
|
||||
}
|
||||
@@ -1387,10 +1365,6 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
|
||||
@Override
|
||||
public void onCarLocationChanged2(Location location) {
|
||||
vrModeNavInfoView.refreshCurrentSpeed((int) (location.getSpeed() * 3.6F));
|
||||
int speed = (int) (location.getSpeed() * 3.6F);
|
||||
mouduleArc.setArcColor(Color.parseColor(speed > 60 ? "#DB3137" : "#3E77F6"));
|
||||
mouduleArc.setValues(speed);
|
||||
flSpeed.setBackgroundResource(speed > 60 ? R.drawable.yi_biao_pan_bg_speeding : R.drawable.yi_biao_pan_bg_nor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,190 +0,0 @@
|
||||
package com.mogo.module.extensions.view;
|
||||
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mogo.module.extensions.R;
|
||||
|
||||
/**
|
||||
* created by wujifei on 2021/3/24 16:20
|
||||
* describe:
|
||||
*/
|
||||
public class SpeedChartView extends View {
|
||||
|
||||
//中心的文字描述
|
||||
private String mDes = "KM/H";
|
||||
//根据数据显示的圆弧Paint
|
||||
private Paint mArcPaint;
|
||||
//圆弧颜色
|
||||
private int mArcColor;
|
||||
//圆弧的画笔的宽度
|
||||
private float mStrokeWith = getResources().getDimension(R.dimen.module_ext_arcView_stroke_with);
|
||||
//文字描述的paint
|
||||
private Paint mTextPaint;
|
||||
|
||||
//当前进度夹角大小
|
||||
private float mIncludedAngle = 0;
|
||||
//当前数据
|
||||
private int currentValue;
|
||||
//最大数据
|
||||
private int maxValue = 240;
|
||||
//圆弧背景的开始和结束间的夹角大小
|
||||
private float mAngle = 270;
|
||||
//上次绘制圆弧夹角
|
||||
private float lastAngle = 0;
|
||||
|
||||
public SpeedChartView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public SpeedChartView(Context context, @Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public SpeedChartView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
//初始化paint
|
||||
initPaint();
|
||||
//绘制弧度
|
||||
drawArc(canvas);
|
||||
//绘制文本
|
||||
drawText(canvas);
|
||||
}
|
||||
|
||||
private void drawText(Canvas canvas) {
|
||||
Rect mRect = new Rect();
|
||||
String mValue = String.valueOf(currentValue);
|
||||
mTextPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
|
||||
//绘制中心的数值
|
||||
mTextPaint.getTextBounds(mValue, 0, mValue.length(), mRect);
|
||||
canvas.drawText(mValue, getWidth() / 2, getHeight() / 2 + mRect.height() / 2 - 10, mTextPaint);
|
||||
|
||||
mTextPaint.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
|
||||
//绘制中心文字描述
|
||||
mTextPaint.setTextSize(getResources().getDimension(R.dimen.module_ext_arcView_des_text_size));
|
||||
mTextPaint.getTextBounds(mDes, 0, mDes.length(), mRect);
|
||||
canvas.drawText(mDes, getWidth() / 2, getHeight() * 17 / 20 + mRect.height() / 2, mTextPaint);
|
||||
}
|
||||
|
||||
private void drawArc(Canvas canvas) {
|
||||
//绘制圆弧背景
|
||||
RectF mRectF = new RectF(mStrokeWith, mStrokeWith, getWidth() - mStrokeWith, getHeight() - mStrokeWith);
|
||||
canvas.drawArc(mRectF, 135, mAngle, false, mArcPaint);
|
||||
|
||||
//绘制当前数值对应的圆弧
|
||||
mArcPaint.setColor(mArcColor);
|
||||
//根据当前数据绘制对应的圆弧
|
||||
canvas.drawArc(mRectF, 135, mIncludedAngle, false, mArcPaint);
|
||||
}
|
||||
|
||||
private void initPaint() {
|
||||
//圆弧的paint
|
||||
mArcPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
//抗锯齿
|
||||
mArcPaint.setAntiAlias(true);
|
||||
mArcPaint.setColor(Color.parseColor("#151D4C"));
|
||||
//设置透明度(数值为0-255)
|
||||
mArcPaint.setAlpha(100);
|
||||
//设置画笔的画出的形状
|
||||
mArcPaint.setStrokeJoin(Paint.Join.ROUND);
|
||||
mArcPaint.setStrokeCap(Paint.Cap.ROUND);
|
||||
//设置画笔类型
|
||||
mArcPaint.setStyle(Paint.Style.STROKE);
|
||||
//画笔宽度
|
||||
mArcPaint.setStrokeWidth(mStrokeWith);
|
||||
|
||||
//中心文字的paint
|
||||
mTextPaint = new Paint();
|
||||
mTextPaint.setAntiAlias(true);
|
||||
mTextPaint.setColor(Color.parseColor("#FFFFFF"));
|
||||
//设置文本的对齐方式
|
||||
mTextPaint.setTextAlign(Paint.Align.CENTER);
|
||||
//mTextPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.dp_12));
|
||||
mTextPaint.setTextSize(getResources().getDimension(R.dimen.module_ext_arcView_center_text_size));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 为绘制弧度及数据设置动画
|
||||
*
|
||||
* @param startAngle 开始的弧度
|
||||
* @param currentAngle 需要绘制的弧度
|
||||
* @param time 动画执行的时长
|
||||
*/
|
||||
private void setAnimation(float startAngle, float currentAngle, int time) {
|
||||
//绘制当前数据对应的圆弧的动画效果
|
||||
ValueAnimator progressAnimator = ValueAnimator.ofFloat(startAngle, currentAngle);
|
||||
progressAnimator.setDuration(time);
|
||||
progressAnimator.setTarget(mIncludedAngle);
|
||||
progressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
mIncludedAngle = (float) animation.getAnimatedValue();
|
||||
//重新绘制,不然不会出现效果
|
||||
postInvalidate();
|
||||
}
|
||||
});
|
||||
//开始执行动画
|
||||
progressAnimator.start();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置弧形颜色
|
||||
*
|
||||
* @param value 颜色值
|
||||
*/
|
||||
public void setArcColor(int value) {
|
||||
mArcColor = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置数据
|
||||
*
|
||||
* @param value 当前绘制的值
|
||||
*/
|
||||
public void setValues(int value) {
|
||||
//完全覆盖
|
||||
if (value > maxValue) {
|
||||
value = maxValue;
|
||||
}
|
||||
if (value < 0) {
|
||||
value = 0;
|
||||
}
|
||||
currentValue = value;
|
||||
//计算弧度比重
|
||||
float scale = (float) currentValue / maxValue;
|
||||
//计算弧度
|
||||
float currentAngle = scale * mAngle;
|
||||
//开始执行动画
|
||||
setAnimation(lastAngle, currentAngle, 1000);
|
||||
lastAngle = currentAngle;
|
||||
//重新绘制
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
|
||||
private float dp2px(float dp) {
|
||||
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
|
||||
return dp * metrics.density;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user