diff --git a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/entrance/EntranceFragment.java b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/entrance/EntranceFragment.java index 19015182c1..e76a035b56 100644 --- a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/entrance/EntranceFragment.java +++ b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/entrance/EntranceFragment.java @@ -1,6 +1,7 @@ package com.mogo.module.extensions.entrance; import android.content.Intent; +import android.graphics.Color; import android.graphics.Rect; import android.location.Location; import android.os.Bundle; @@ -15,6 +16,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; +import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.RadioButton; @@ -65,6 +67,7 @@ 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.ArcView; import com.mogo.module.share.manager.ServiceApisManager; import com.mogo.service.IMogoServiceApis; import com.mogo.service.analytics.IMogoAnalytics; @@ -194,6 +197,18 @@ public class EntranceFragment extends MvpFragment 40 ? "#DB3137" : "#3E77F6")); + mouduleArc.setValues(speed); + flSpeed.setBackgroundResource(speed > 40 ? R.drawable.yi_biao_pan_bg_speeding : R.drawable.yi_biao_pan_bg_nor); } @Override - public void onCarLocationChanged( MogoLatLng latLng ) { + public void onCarLocationChanged(MogoLatLng latLng) { } } diff --git a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/TopViewAnimHelper.java b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/TopViewAnimHelper.java index 9082dab01f..9fc3aeb8a8 100644 --- a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/TopViewAnimHelper.java +++ b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/TopViewAnimHelper.java @@ -507,7 +507,7 @@ public class TopViewAnimHelper { public void enterVrMode() { removeAllView(); topContainer.getLayoutParams().width = (int) getDimen(R.dimen.module_ext_top_view_width_in_vr_mode); - vrModeNavInfoView.setVisibility(View.VISIBLE); + // vrModeNavInfoView.setVisibility(View.VISIBLE); // topContainer.requestLayout(); // topMotionLayout.requestLayout(); } diff --git a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/view/ArcView.java b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/view/ArcView.java new file mode 100644 index 0000000000..7c22a7c303 --- /dev/null +++ b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/view/ArcView.java @@ -0,0 +1,182 @@ +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.util.AttributeSet; +import android.util.DisplayMetrics; +import android.view.View; + +import androidx.annotation.Nullable; + +/** + * created by wujifei on 2021/3/24 16:20 + * describe: + */ +public class ArcView extends View { + + //中心的文字描述 + private String mDes = "km/h"; + //根据数据显示的圆弧Paint + private Paint mArcPaint; + //圆弧颜色 + private int mArcColor; + //圆弧的画笔的宽度 + private float mStrokeWith = 10; + //文字描述的paint + private Paint mTextPaint; + + //当前进度夹角大小 + private float mIncludedAngle = 0; + //当前数据 + private int currentValue; + //最大数据 + private int maxValue = 240; + //圆弧背景的开始和结束间的夹角大小 + private float mAngle = 270; + //上次绘制圆弧夹角 + private float lastAngle = 0; + + public ArcView(Context context) { + this(context, null); + } + + public ArcView(Context context, @Nullable AttributeSet attrs) { + this(context, attrs, 0); + } + + public ArcView(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.getTextBounds(mValue, 0, mValue.length(), mRect); + canvas.drawText(mValue, getWidth() / 2, getHeight() / 2 + mRect.height() / 2, mTextPaint); + + //绘制中心文字描述 + mTextPaint.setTextSize(28); + 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("#222A66")); + //设置透明度(数值为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(80); + + } + + + /** + * 为绘制弧度及数据设置动画 + * + * @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; + } + 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; + } +} diff --git a/modules/mogo-module-extensions/src/main/res/drawable/green_light_vr_bg.xml b/modules/mogo-module-extensions/src/main/res/drawable/green_light_vr_bg.xml new file mode 100644 index 0000000000..053ca17b45 --- /dev/null +++ b/modules/mogo-module-extensions/src/main/res/drawable/green_light_vr_bg.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/modules/mogo-module-extensions/src/main/res/drawable/red_light_vr_bg.xml b/modules/mogo-module-extensions/src/main/res/drawable/red_light_vr_bg.xml new file mode 100644 index 0000000000..c8b510cfd4 --- /dev/null +++ b/modules/mogo-module-extensions/src/main/res/drawable/red_light_vr_bg.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/modules/mogo-module-extensions/src/main/res/drawable/traffic_light_vr_bg.xml b/modules/mogo-module-extensions/src/main/res/drawable/traffic_light_vr_bg.xml new file mode 100644 index 0000000000..90c7bde175 --- /dev/null +++ b/modules/mogo-module-extensions/src/main/res/drawable/traffic_light_vr_bg.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/modules/mogo-module-extensions/src/main/res/drawable/view_traffic_light_vr_bg.xml b/modules/mogo-module-extensions/src/main/res/drawable/view_traffic_light_vr_bg.xml new file mode 100644 index 0000000000..a63c02e5a6 --- /dev/null +++ b/modules/mogo-module-extensions/src/main/res/drawable/view_traffic_light_vr_bg.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/modules/mogo-module-extensions/src/main/res/drawable/yellow_light_vr_bg.xml b/modules/mogo-module-extensions/src/main/res/drawable/yellow_light_vr_bg.xml new file mode 100644 index 0000000000..9248409de9 --- /dev/null +++ b/modules/mogo-module-extensions/src/main/res/drawable/yellow_light_vr_bg.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/modules/mogo-module-extensions/src/main/res/drawable/yi_biao_pan_bg_nor.xml b/modules/mogo-module-extensions/src/main/res/drawable/yi_biao_pan_bg_nor.xml new file mode 100644 index 0000000000..077f8a578a --- /dev/null +++ b/modules/mogo-module-extensions/src/main/res/drawable/yi_biao_pan_bg_nor.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/modules/mogo-module-extensions/src/main/res/drawable/yi_biao_pan_bg_speeding.xml b/modules/mogo-module-extensions/src/main/res/drawable/yi_biao_pan_bg_speeding.xml new file mode 100644 index 0000000000..9a939a7647 --- /dev/null +++ b/modules/mogo-module-extensions/src/main/res/drawable/yi_biao_pan_bg_speeding.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_entrance.xml b/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_entrance.xml index e7c4bc0569..cddd191134 100644 --- a/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_entrance.xml +++ b/modules/mogo-module-extensions/src/main/res/layout/module_ext_layout_entrance.xml @@ -5,7 +5,10 @@ android:id="@+id/module_entrance_id_top_motion_layout" android:layout_width="match_parent" android:layout_height="match_parent"> - + + app:layout_constraintTop_toTopOf="parent" /> + + + + + + + + + + + + + + + + tools:visibility="visible" /> @@ -237,8 +307,8 @@ android:textSize="@dimen/module_ext_exit_vr_mode_text_size" android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintTop_toTopOf="parent" - app:layout_constraintRight_toRightOf="parent" /> + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" />