From 5298fcdbf375eacda1e19a79aca821a30f590e62 Mon Sep 17 00:00:00 2001 From: lizhanwei <Dana_Lee1016@126.com> Date: 星期五, 03 四月 2020 11:40:30 +0800 Subject: [PATCH] 修改科目三显示左右两边距离 --- app/src/main/java/safeluck/drive/evaluation/fragment/RoadDriveMapFragmentaa.java | 153 +++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 124 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/RoadDriveMapFragmentaa.java b/app/src/main/java/safeluck/drive/evaluation/fragment/RoadDriveMapFragmentaa.java index 47f828a..7a45b9b 100644 --- a/app/src/main/java/safeluck/drive/evaluation/fragment/RoadDriveMapFragmentaa.java +++ b/app/src/main/java/safeluck/drive/evaluation/fragment/RoadDriveMapFragmentaa.java @@ -26,6 +26,9 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import org.json.JSONException; +import org.json.JSONObject; + import java.io.IOException; import java.lang.reflect.Type; import java.math.BigDecimal; @@ -45,6 +48,7 @@ import safeluck.drive.evaluation.cEventCenter.ICEventListener; import safeluck.drive.evaluation.util.CThreadPoolExecutor; import safeluck.drive.evaluation.util.FileUtil; +import safeluck.drive.evaluation.util.Utils; public class RoadDriveMapFragmentaa extends SupportFragment implements View.OnClickListener { @@ -52,15 +56,29 @@ private int pixels = 80; private boolean isDrawing = false; private StringBuffer buffer = null;//瀛樻斁鍦板浘鐨刡uffer - + private ICEventListener speedListener = new ICEventListener() { @Override public void onCEvent(String topic, int msgCode, int resultCode, Object obj) { if (msgCode == Constant.RTK_INFO){ gpsSpeed = (double)obj; } + if (msgCode == Constant.LEFT_RIGHT_DISTANCE){ + String str = (String)obj; + + try { + JSONObject jsonObject = new JSONObject(str); + leftDistance = Utils.getdouble(jsonObject.getDouble("left"),3); + rightDistance = Utils.getdouble(jsonObject.getDouble("right"),3); + + } catch (JSONException e) { + e.printStackTrace(); + } + } } }; + private double leftDistance =0.0; + private double rightDistance =0.0; public static SupportFragment newInstance() { return new RoadDriveMapFragmentaa(); @@ -76,7 +94,9 @@ private Toolbar toolbar; private Bitmap bmp = null; + private Bitmap bmp2 = null; private Canvas canvas2 = null; + private Canvas canvas3 = null; private Paint paint = null; private int screen_width = 0, screen_height = 0; private String osdHeading = null; @@ -134,6 +154,11 @@ canvas2 = new Canvas(bmp); canvas2.drawColor(Color.WHITE); + + bmp2 = Bitmap.createBitmap(screen_width/3, screen_height, Bitmap.Config.ARGB_8888); + canvas3 = new Canvas(bmp2); + canvas3.drawColor(Color.WHITE); + paint = new Paint(); paint.setTextSize(30); @@ -144,6 +169,7 @@ holder.lockCanvas(); canvas.drawBitmap(bmp, 0, 0, paint); + canvas.drawBitmap(bmp2, screen_width/3, 0, paint); holder.unlockCanvasAndPost(canvas); } } @@ -200,7 +226,7 @@ if (canvas2 == null || bmp == null) { return; } - double base_x = 300, base_y = 20; + float base_x = 300, base_y = 20; double max_x = 0, min_x = 0, max_y = 0, min_y = 0; long scale_x, scale_y; @@ -437,50 +463,119 @@ paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setPathEffect(null); paint.setColor(Color.BLACK); - if (osdHeading != null) { - Path pathText = new Path(); - pathText.moveTo(10, 170); - pathText.lineTo(700, 170); - canvas2.drawTextOnPath(osdHeading, pathText, 0, 0, paint);//閫嗘椂閽堢敓鎴� - } - if (osdMoveDirect != null) { + paint.setStyle(Paint.Style.FILL_AND_STROKE); + + canvas3.drawColor(Color.YELLOW); + if (osdHeading != null) { Path pathText = new Path(); pathText.moveTo(10, 30); pathText.lineTo(700, 30); - canvas2.drawTextOnPath(osdMoveDirect, pathText, 0, 0, paint);//閫嗘椂閽堢敓鎴� + canvas3.drawTextOnPath(osdHeading, pathText, 0, 0, paint);//閫嗘椂閽堢敓鎴� } + +// if (osdMoveDirect != null) { +// Path pathText = new Path(); +// pathText.moveTo(10, 30); +// pathText.lineTo(700, 30); +// canvas3.drawTextOnPath(osdMoveDirect, pathText, 0, 0, paint);//閫嗘椂閽堢敓鎴� +// } if (osdRtkSpeed != null) { Path pathText = new Path(); - pathText.moveTo(10, 240); - pathText.lineTo(700, 240); - canvas2.drawTextOnPath(osdRtkSpeed, pathText, 0, 0, paint);//閫嗘椂閽堢敓鎴� - } - - if (osdQf != null) { - Path pathText = new Path(); - pathText.moveTo(10, 120); - pathText.lineTo(700, 120); - canvas2.drawTextOnPath(osdQf, pathText, 0, 0, paint);//閫嗘椂閽堢敓鎴� - } - - { - BigDecimal bd = new BigDecimal(gpsSpeed); - bd = bd.setScale(3, BigDecimal.ROUND_HALF_UP); - - Path pathText = new Path(); pathText.moveTo(10, 70); pathText.lineTo(700, 70); - - canvas2.drawTextOnPath("GPS閫熷害:" + bd, pathText, 0, 0, paint);//閫嗘椂閽堢敓鎴� + canvas3.drawTextOnPath(osdRtkSpeed, pathText, 0, 0, paint);//閫嗘椂閽堢敓鎴� } +// +// if (osdQf != null) { +// Path pathText = new Path(); +// pathText.moveTo(10, 120); +// pathText.lineTo(700, 120); +// canvas3.drawTextOnPath(osdQf, pathText, 0, 0, paint);//閫嗘椂閽堢敓鎴� +// } +// +// { +// BigDecimal bd = new BigDecimal(gpsSpeed); +// bd = bd.setScale(3, BigDecimal.ROUND_HALF_UP); +// +// Path pathText = new Path(); +// pathText.moveTo(10, 70); +// pathText.lineTo(700, 70); +// +// canvas3.drawTextOnPath("GPS閫熷害:" + bd, pathText, 0, 0, paint);//閫嗘椂閽堢敓鎴� +// } + + + + + + + + base_x = 170; + base_y = 350; + + scale_x=scale_y = 27; + + paint.setStyle(Paint.Style.FILL_AND_STROKE); + paint.setColor(Color.BLUE); +// canvas2.drawCircle((float) (base_x + (mainAnt.get(0) - min_x) * scale_x), (float) (base_y + (mainAnt.get(1) - min_y) * scale_y), 2, paint); + canvas3.drawCircle((float) base_x, (float) base_y, 2, paint); + + paint.setColor(Color.RED); + + canvas3.drawCircle((float) (base_x + (car[tire.get(0)][0]) * scale_x), (float) (base_y + (car[tire.get(0)][1]) * scale_y), 2.5f, paint); + canvas3.drawCircle((float) (base_x + (car[tire.get(1)][0]) * scale_x), (float) (base_y + (car[tire.get(1)][1]) * scale_y), 2.5f, paint); + canvas3.drawCircle((float) (base_x + (car[tire.get(2)][0]) * scale_x), (float) (base_y + (car[tire.get(2)][1]) * scale_y), 2.5f, paint); + canvas3.drawCircle((float) (base_x + (car[tire.get(3)][0]) * scale_x), (float) (base_y + (car[tire.get(3)][1]) * scale_y), 2.5f, paint); + + + + Path pathCanvs3 = new Path(); + pathCanvs3.moveTo((float) (base_x + (car[body.get(0)][0] - min_x) * scale_x), (float) (base_y + (car[body.get(0)][1] - min_y) * scale_y)); + for (int i = 1; i < body.size(); i++){ +// Log.d(TAG, "for 寰幆 DrawMap to X = " + (float) (base_x + (car[body.get(i)][0] - min_x) * scale_x)+ " Y = " + (float) (base_y + (car[body.get(i)][1] - min_y) * scale_y)); + Log.i(TAG,String.format("car[%d][0]=%f,to X =%f,car[%d][1]=%f,to Y=%f",i,car[body.get(i)][0], + (float) (base_x + (car[body.get(i)][0] - min_x) * scale_x),i,car[body.get(i)][1],(float) (base_y + (car[body.get(i)][1] - min_y) * scale_y))); + pathCanvs3.lineTo((float) (base_x + (car[body.get(i)][0] - min_x) * scale_x), (float) (base_y + (car[body.get(i)][1] - min_y) * scale_y)); + } + paint.setStyle(Paint.Style.STROKE); + paint.setColor(Color.BLACK); + pathCanvs3.close(); + canvas3.drawPath(pathCanvs3,paint); + + Paint mPaint = new Paint(); + mPaint.setTextSize(20); + mPaint.setStyle(Paint.Style.FILL_AND_STROKE); + osdMoveDirect="9.4345"; + if (osdMoveDirect != null) { + Path pathText = new Path(); + pathText.moveTo(base_x-110, base_y-35); + pathText.lineTo(base_x-20, base_y-35); + canvas3.drawTextOnPath(String.valueOf(leftDistance), pathText, 0, 0, mPaint);//閫嗘椂閽堢敓鎴� + } + if (osdMoveDirect != null) { + Path pathText = new Path(); + pathText.moveTo(base_x+30, base_y-35); + pathText.lineTo(base_x+110, base_y-35); + canvas3.drawTextOnPath(String.valueOf(rightDistance), pathText, 0, 0, mPaint);//閫嗘椂閽堢敓鎴� + } + paint.setColor(Color.RED); + canvas3.drawLine(base_x-120,base_y-200,base_x-120,base_y+200,paint); + canvas3.drawLine(base_x+120,base_y-200,base_x+120,base_y+200,paint); + + DrawArrows(canvas3,Color.GREEN,15f,base_x-20,base_y-30,base_x-120,base_y-30);//宸﹁竟绠ご锛堝乏杈硅窛 + DrawArrows(canvas3,Color.GREEN,15f,base_x+20,base_y-30,base_x+120,base_y-30);//鍙宠竟绠ご锛堣竟璺� + + + // 鎻愪氦鐢诲竷 Canvas canvas = holder.lockCanvas(); if (canvas != null){ canvas.drawBitmap(bmp, 0, 0, paint); + canvas.drawBitmap(bmp2, screen_width*2/3, 0, paint); holder.unlockCanvasAndPost(canvas); } } -- Gitblit v1.8.0