From dae6a3f73b39597ebbf55401aa4449c6ae5f7cd3 Mon Sep 17 00:00:00 2001 From: lizhanwei <Dana_Lee1016@126.com> Date: 星期五, 03 四月 2020 11:27:14 +0800 Subject: [PATCH] 修改科目二显示,左右边距 --- app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java | 254 ++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 182 insertions(+), 72 deletions(-) diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java b/app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java index 87d38b3..1733684 100644 --- a/app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java +++ b/app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java @@ -7,8 +7,6 @@ import android.graphics.Paint; import android.graphics.Path; import android.os.Bundle; -import android.os.Handler; -import android.text.LoginFilter; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; @@ -24,16 +22,16 @@ import androidx.appcompat.widget.Toolbar; -import com.anyun.exam.lib.AYSdk; import com.anyun.exam.lib.MyLog; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import org.json.JSONException; +import org.json.JSONObject; import java.lang.reflect.Type; import java.math.BigDecimal; -import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; @@ -45,12 +43,12 @@ import safeluck.drive.evaluation.R; import safeluck.drive.evaluation.bean.ExamMap; import safeluck.drive.evaluation.bean.ExamPlatformData; -import safeluck.drive.evaluation.bean.Point; import safeluck.drive.evaluation.bean.RealTimeCarPos; import safeluck.drive.evaluation.cEventCenter.CEventCenter; import safeluck.drive.evaluation.cEventCenter.ICEventListener; import safeluck.drive.evaluation.util.CThreadPoolExecutor; import safeluck.drive.evaluation.util.FileUtil; +import safeluck.drive.evaluation.util.Utils; /** @@ -77,26 +75,24 @@ } } }; - private ICEventListener debugTxticEventListener = new ICEventListener() { - @Override - public void onCEvent(String topic, int msgCode, int resultCode, final Object obj) { - if (msgCode == Constant.DEBUG_TXT){ - CThreadPoolExecutor.runOnMainThread(new Runnable() { - @Override - public void run() { - Log.i(TAG, "subtitle="+(String)obj); - toolbar.setSubtitle((String)obj); - } - }); - } - } - }; 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(); + } } } }; @@ -128,6 +124,8 @@ private int map_id; private double gpsSpeed = 0; + private double leftDistance = 0; + private double rightDistance = 0; double allMap[][][]; double map[][] = {{-2.4065, 30.7090}, {-3.0759, 30.3599}, { -2.6023, 29.2578}, {-3.3316,28.9383},{-3.8247,30.0293}, @@ -380,26 +378,26 @@ canvas2.drawTextOnPath(osdHeading, pathText, 0, 0, paint);//閫嗘椂閽堢敓鎴� } - if (osdMoveDirect != null) { - Path pathText = new Path(); - pathText.moveTo(10, 30); - pathText.lineTo(700, 30); - canvas2.drawTextOnPath(osdMoveDirect, pathText, 0, 0, paint);//閫嗘椂閽堢敓鎴� - } +// if (osdMoveDirect != null) { +// Path pathText = new Path(); +// pathText.moveTo(10, 30); +// pathText.lineTo(700, 30); +// canvas2.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 (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);//閫嗘椂閽堢敓鎴� - } +// 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); @@ -489,7 +487,8 @@ // _mActivity.runOnUiThread(new Runnable() { // @Override // public void run() { - double base_x = 300, base_y = 20; + float base_x = 300; + float base_y = 20; double max_x = 0, min_x = 0, max_y = 0, min_y = 0; // Log.d(TAG, "DrawMap map size " + map.length + " car size " + car.length); @@ -712,46 +711,103 @@ paint.setStyle(Paint.Style.FILL_AND_STROKE); - canvas3.drawColor(Color.RED); + canvas3.drawColor(Color.YELLOW); if (osdHeading != null) { Path pathText = new Path(); - pathText.moveTo(10, 170); - pathText.lineTo(700, 170); + pathText.moveTo(10, 30); + pathText.lineTo(700, 30); 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 (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); - 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);//閫嗘椂閽堢敓鎴� + 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);//鍙宠竟绠ご锛堣竟璺� // 鎻愪氦鐢诲竷 @@ -1068,7 +1124,7 @@ BigDecimal bd = new BigDecimal(timeCarPos.getSpeed()); bd = bd.setScale(3, BigDecimal.ROUND_HALF_UP); - osdRtkSpeed = "璁$畻閫熷害:" + bd; + osdRtkSpeed = "閫熷害:" + bd; osdQf = "QF锛�" + String.valueOf(timeCarPos.getQf()); @@ -1243,8 +1299,6 @@ public void onAttach(Context context) { super.onAttach(context); CEventCenter.onBindEvent(true, icEventListener, Constant.REAL_TIME_POS_CAR_TOPIC); - CEventCenter.onBindEvent(true, rtcmicEventListener, Constant.BIND_RTCM_TOPIC); - CEventCenter.onBindEvent(true, debugTxticEventListener, Constant.BIND_DEBUG_TXT); CEventCenter.onBindEvent(true, speedListener, Constant.BIND_RTK_SPEED_TOPIC); } @@ -1255,8 +1309,64 @@ producer.shutdown(); consumer.shutdown(); CEventCenter.onBindEvent(false, icEventListener, Constant.REAL_TIME_POS_CAR_TOPIC); - CEventCenter.onBindEvent(false, icEventListener, Constant.BIND_RTCM_TOPIC); - CEventCenter.onBindEvent(false, icEventListener, Constant.BIND_DEBUG_TXT); CEventCenter.onBindEvent(false, speedListener, Constant.BIND_RTK_SPEED_TOPIC); } + + + + void DrawArrows(Canvas canvas, int color, float arrowSize, float x1, + float y1, float x2, float y2) { + paint.setAntiAlias(true); + paint.setStyle(Paint.Style.STROKE); + paint.setColor(color); + + // 鐢荤洿绾� + canvas.drawLine(x1, y1, x2, y2, paint); + + // 绠ご涓殑绗竴鏉$嚎鐨勮捣鐐� + int x3 = 0; + int y3 = 0; + + // 绠ご涓殑绗簩鏉$嚎鐨勮捣鐐� + int x4 = 0; + int y4 = 0; + + double awrad = Math.atan(3.5 / 8); + double[] arrXY_1 = rotateVec(x2 - x1, y2 - y1, awrad, arrowSize); + double[] arrXY_2 = rotateVec(x2 - x1, y2 - y1, -awrad, arrowSize); + + // 绗竴绔偣 + Double X3 = Double.valueOf(x2 - arrXY_1[0]); + x3 = X3.intValue(); + Double Y3 = Double.valueOf(y2 - arrXY_1[1]); + y3 = Y3.intValue(); + + // 绗簩绔偣 + Double X4 = Double.valueOf(x2 - arrXY_2[0]); + x4 = X4.intValue(); + Double Y4 = Double.valueOf(y2 - arrXY_2[1]); + y4 = Y4.intValue(); + + Path arrowsPath = new Path(); + arrowsPath.moveTo(x2, y2); + arrowsPath.lineTo(x3, y3); + arrowsPath.lineTo(x4, y4); + arrowsPath.close(); + canvas.drawLine(x3, y3, x2, y2, paint); + canvas.drawLine(x4, y4, x2, y2, paint); + } + + private double[] rotateVec(float px, float py, double ang, double arrowSize) { + double mathstr[] = new double[2]; + double vx = px * Math.cos(ang) - py * Math.sin(ang); + double vy = px * Math.sin(ang) + py * Math.cos(ang); + double d = Math.sqrt(vx * vx + vy * vy); + vx = vx / d * arrowSize; + vy = vy / d * arrowSize; + mathstr[0] = vx; + mathstr[1] = vy; + return mathstr; + } + + } -- Gitblit v1.8.0