| | |
| | | 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; |
| | |
| | | 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 { |
| | | |
| | |
| | | private int pixels = 80; |
| | | private boolean isDrawing = false; |
| | | private StringBuffer buffer = null;//存放地图的buffer |
| | | |
| | | |
| | | 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(); |
| | |
| | | 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; |
| | |
| | | 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); |
| | |
| | | |
| | | holder.lockCanvas(); |
| | | canvas.drawBitmap(bmp, 0, 0, paint); |
| | | canvas.drawBitmap(bmp2, screen_width/3, 0, paint); |
| | | holder.unlockCanvasAndPost(canvas); |
| | | } |
| | | } |
| | |
| | | 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; |
| | | |
| | |
| | | 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); |
| | | } |
| | | } |