From db61166b033e61d543f2489b725118ee5b09d521 Mon Sep 17 00:00:00 2001 From: lizhanwei <Dana_Lee1016@126.com> Date: 星期四, 09 一月 2020 17:32:07 +0800 Subject: [PATCH] 增加推送车辆模型,场地地图接口;增加查看地图Fragment --- app/src/main/java/safeluck/drive/evaluation/Constant.java | 2 app/src/main/java/safeluck/drive/evaluation/app.java | 10 + app/src/main/assets/vehiclemodel.json | 9 + app/src/main/java/safeluck/drive/evaluation/util/FileUtil.java | 52 +++++ app/src/main/res/layout/layout_mapfragment.xml | 26 ++ app/src/main/assets/map.json | 23 ++ app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java | 9 + app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java | 365 ++++++++++++++++++++++++++++++++------- 8 files changed, 425 insertions(+), 71 deletions(-) diff --git a/app/src/main/assets/map.json b/app/src/main/assets/map.json new file mode 100644 index 0000000..36abf91 --- /dev/null +++ b/app/src/main/assets/map.json @@ -0,0 +1,23 @@ +[{ + "id": 863, + "item": 1, + "point": [{ + "x-y": [-11.9669, 28.013, -11.5114, 27.137, -10.8069, 27.5039, -10.2969, 26.4212, -9.2102, 26.8894, -9.6513, 28.0027, -8.9758, 28.3797, -9.5057, 29.3232] + }, + { + "x-y": [-11.9669, 28.013, -11.5114, 27.137, -10.8069, 27.5039, -10.2969, 26.4212, -9.2102, 26.8894, -9.6513, 28.0027, -8.9758, 28.3797, -9.5057, 29.3232] + } + ] +}, + { + "id": 3000, + "item": 2, + "point": [{ + "x-y": [-11.9669, 28.013, -11.5114, 27.137, -10.8069, 27.5039, -10.2969, 26.4212, -9.2102, 26.8894, -9.6513, 28.0027, -8.9758, 28.3797, -9.5057, 29.3232] + }, + { + "x-y": [-11.9669, 28.013, -11.5114, 27.137, -10.8069, 27.5039, -10.2969, 26.4212, -9.2102, 26.8894, -9.6513, 28.0027, -8.9758, 28.3797, -9.5057, 29.3232] + } + ] + } +] \ No newline at end of file diff --git a/app/src/main/assets/vehiclemodel.json b/app/src/main/assets/vehiclemodel.json new file mode 100644 index 0000000..64ba654 --- /dev/null +++ b/app/src/main/assets/vehiclemodel.json @@ -0,0 +1,9 @@ +{ + "main_ant": [123.3, 85.5], + "axial": [0, 18], + "left_front_tire": [4, 5], + "right_front_tire": [6, 7], + "left_rear_tire": [8, 9], + "right_rear_tire": [10, 11], + "point": [-11.9669, 28.013, -11.5114, 27.137, -10.8069, 27.5039, -10.2969, 26.4212, -9.2102, 26.8894, -9.6513, 28.0027, -8.9758, 28.3797, -9.5057, 29.3232] +} \ No newline at end of file diff --git a/app/src/main/java/safeluck/drive/evaluation/Constant.java b/app/src/main/java/safeluck/drive/evaluation/Constant.java index dbd4d74..2993eb3 100644 --- a/app/src/main/java/safeluck/drive/evaluation/Constant.java +++ b/app/src/main/java/safeluck/drive/evaluation/Constant.java @@ -50,4 +50,6 @@ //I绫昏瘎鍒よ〃 public static final int SUBJECT_I = 1; + public static final String MAP = "map.json"; + public static final String VEHICLE = "vehiclemodel.json"; } diff --git a/app/src/main/java/safeluck/drive/evaluation/app.java b/app/src/main/java/safeluck/drive/evaluation/app.java index 8b384a0..6465d57 100644 --- a/app/src/main/java/safeluck/drive/evaluation/app.java +++ b/app/src/main/java/safeluck/drive/evaluation/app.java @@ -27,6 +27,7 @@ import safeluck.drive.evaluation.DB.failitems.FailedProjRepository; import safeluck.drive.evaluation.DB.rtktb.RTKConfig; import safeluck.drive.evaluation.DB.rtktb.RTKWorkRepository; +import safeluck.drive.evaluation.util.FileUtil; import safeluck.drive.evaluation.util.SystemUtil; /** @@ -189,6 +190,15 @@ } rtkWorkRepository.insertRTKConfig(rtkConfig); break; + case Constant.FETCH_MAP_INFO: + + StringBuffer buffer =FileUtil.readAssetTxtFile(this,Constant.MAP); + AYSdk.getInstance().sendCmd(Constant.PUSH_MAP_INFO,buffer.toString()); + break; + case Constant.REQ_VECHILE_PROFILE: + StringBuffer vebuffer =FileUtil.readAssetTxtFile(this,Constant.VEHICLE); + AYSdk.getInstance().sendCmd(Constant.PUSH_VECHILE_PROFILE,vebuffer.toString()); + break; } } 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 f27254c..986f967 100644 --- a/app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java +++ b/app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java @@ -1,72 +1,295 @@ -//package safeluck.drive.evaluation.fragment; +package safeluck.drive.evaluation.fragment; + +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Path; +import android.opengl.GLSurfaceView; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; + + +import me.yokeyword.fragmentation.SupportFragment; +import safeluck.drive.evaluation.R; + + +/** + * MyApplication2 + * Created by lzw on 2019/9/26. 15:20:58 + * 閭锛�632393724@qq.com + * All Rights Saved! Chongqing AnYun Tech co. LTD + */ +public class MapFragment extends SupportFragment{ + private boolean isDrawing = false; + + public static SupportFragment newInstance(){ + return new MapFragment(); + } + private SurfaceView mSurfaceView; + private static final String TAG = "MapFragment"; + private SurfaceHolder holder; + Path path = new Path(); + private Canvas canvas; + private int x=-1; + private int y = -1; + private Toolbar toolbar; + + private Bitmap bmp = null; + private Canvas canvas2 = null; + private Paint paint = null; + private int screen_width = 0, screen_height = 0; + private String osd = null; + private String osd2 = null; + private String osd3 = null; + + + private LinearLayout linearLayout;//surfaceview鐨勭埗瀹瑰櫒锛屼负浜嗙Щ鍔╯urfaceview鑰屼娇鐢紝鍥犱负scrollto涓嶈兘绉诲姩view锛� + + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.layout_mapfragment,container,false); + initView(view); + return view; + } + + private void initView(View view) { + toolbar = view.findViewById(R.id.toolbar); + toolbar.setTitle("绠�鍗曞湴鍥�"); + toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp); + toolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + _mActivity.onBackPressed(); + } + }); + + mSurfaceView = view.findViewById(R.id.surfaceview); + + holder = mSurfaceView.getHolder(); + + holder.addCallback(new SurfaceHolder.Callback() { + @Override + public void surfaceCreated(SurfaceHolder surfaceHolder) { + Canvas canvas = surfaceHolder.lockCanvas(); + + if (canvas != null) { + Log.d(TAG, "W = " + canvas.getWidth() + " H = " + canvas.getHeight()); + screen_width = canvas.getWidth(); + screen_height = canvas.getHeight(); + surfaceHolder.unlockCanvasAndPost(canvas); + + bmp = Bitmap.createBitmap(screen_width, screen_height, Bitmap.Config.ARGB_8888); + canvas2 = new Canvas(bmp); + canvas2.drawColor(Color.WHITE); + + paint = new Paint(); + + paint.setTextSize(30); + paint.setColor(Color.BLACK); + paint.setStrokeWidth(1.5f); + paint.setAntiAlias(true); + paint.setStyle(Paint.Style.STROKE); + + holder.lockCanvas(); + canvas.drawBitmap(bmp, 0, 0, paint); + holder.unlockCanvasAndPost(canvas); + } + + new Thread(new NeedForSpeed()).start(); + } + + @Override + public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) { + + } + + @Override + public void surfaceDestroyed(SurfaceHolder surfaceHolder) { + + } + }); + } + + + class NeedForSpeed implements Runnable { + @Override + public void run() { + double map[][] = {{1,1}, {10,1}, {10,10}, {1,10}}; + double car[][] = {{3,3}, {8,3}, {8,8}, {3,8}}; + + DrawMap(map, car); + } + } + + public void DrawMap(final double [][]map, final double [][]car) { + if (canvas2 == null || bmp == null) { + return; + } + _mActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + double base_x = 100, base_y = 100; + 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); + + for (int i = 0; i < map.length; i++) { + if (i == 0) { + max_x = map[0][0]; + min_x = map[0][0]; + max_y = map[0][1]; + min_y = map[0][1]; + } else { + if (max_x < map[i][0]) { + max_x = map[i][0]; + } + if (min_x > map[i][0]) { + min_x = map[i][0]; + } + if (max_y < map[i][1]) { + max_y = map[i][1]; + } + if (min_y > map[i][1]) { + min_y = map[i][1]; + } + } + } + + Log.d(TAG, "DrawMap max_x " + max_x + " max_y " + max_y + " min_x " + min_x + " min_y " + min_y); + + for (int i = 0; i < car.length; i++) { + if (max_x < car[i][0]) { + max_x = car[i][0]; + } + if (min_x > car[i][0]) { + min_x = car[i][0]; + } + if (max_y < car[i][1]) { + max_y = car[i][1]; + } + if (min_y > car[i][1]) { + min_y = car[i][1]; + } + } + + Log.d(TAG, "DrawMap max_x " + max_x + " max_y " + max_y + " min_x " + min_x + " min_y " + min_y); + + long scale_x = Math.round(500 / (max_x - min_x)); + long scale_y = Math.round(300 / (max_y - min_y)); + + if (scale_x >= scale_y) { + scale_x = scale_y; + } else { + scale_y = scale_x; + } + + Log.d(TAG, "DrawMap scale_x " + scale_x + " scale_y " + scale_y); + + canvas2.drawColor(Color.WHITE); + + paint.setStyle(Paint.Style.STROKE); + + Path path = new Path(); + + if (map.length != 9) { + Log.d(TAG, "DrawMap X = " + String.format("%f", (float) (base_x + (map[0][0] - min_x) * scale_x)) + " Y = " + String.format("%f", (float) (base_y + (map[0][1] - min_y) * scale_y))); + path.moveTo((float) (base_x + (map[0][0] - min_x) * scale_x), (float) (base_y + (map[0][1] - min_y) * scale_y)); + for (int i = 1; i < map.length; i++) { + Log.d(TAG, "DrawMap to X = " + (float) (base_x + (map[i][0] - min_x) * scale_x) + " Y = "+ (float) (base_y + (map[i][1] - min_y) * scale_y)); + path.lineTo((float) (base_x + (map[i][0] - min_x) * scale_x), (float) (base_y + (map[i][1] - min_y) * scale_y)); + } + path.close(); + } else { + path.moveTo((float) (base_x + (map[0][0] - min_x) * scale_x), (float) (base_y + (map[0][1] - min_y) * scale_y)); + path.lineTo((float) (base_x + (map[8][0] - min_x) * scale_x), (float) (base_y + (map[8][1] - min_y) * scale_y)); + + path.moveTo((float) (base_x + (map[2][0] - min_x) * scale_x), (float) (base_y + (map[2][1] - min_y) * scale_y)); + path.lineTo((float) (base_x + (map[1][0] - min_x) * scale_x), (float) (base_y + (map[1][1] - min_y) * scale_y)); + + path.moveTo((float) (base_x + (map[3][0] - min_x) * scale_x), (float) (base_y + (map[3][1] - min_y) * scale_y)); + path.lineTo((float) (base_x + (map[4][0] - min_x) * scale_x), (float) (base_y + (map[4][1] - min_y) * scale_y)); + + path.moveTo((float) (base_x + (map[6][0] - min_x) * scale_x), (float) (base_y + (map[6][1] - min_y) * scale_y)); + path.lineTo((float) (base_x + (map[5][0] - min_x) * scale_x), (float) (base_y + (map[5][1] - min_y) * scale_y)); + + path.moveTo((float) (base_x + (map[7][0] - min_x) * scale_x), (float) (base_y + (map[7][1] - min_y) * scale_y)); + path.lineTo((float) (base_x + (map[8][0] - min_x) * scale_x), (float) (base_y + (map[8][1] - min_y) * scale_y)); + } + canvas2.drawPath(path, paint); + + path.moveTo((float) (base_x + (car[0][0] - min_x) * scale_x), (float) (base_y + (car[0][1] - min_y)*scale_y)); + for (int i = 1; i < car.length; i++) + path.lineTo((float) (base_x + (car[i][0] - min_x) * scale_x), (float) (base_y + (car[i][1] - min_y)*scale_y)); + path.close(); + canvas2.drawPath(path, paint); + + paint.setStyle(Paint.Style.FILL_AND_STROKE); + + if (osd != null) { + Path pathText = new Path(); + pathText.moveTo(100, 470); + pathText.lineTo(700, 470); + canvas2.drawTextOnPath(osd, pathText, 0, 0, paint);//閫嗘椂閽堢敓鎴� + } + + if (osd2 != null) { + Path pathText = new Path(); + pathText.moveTo(10, 30); + pathText.lineTo(700, 30); + canvas2.drawTextOnPath(osd2, pathText, 0, 0, paint);//閫嗘椂閽堢敓鎴� + } + + // 鎻愪氦鐢诲竷 + Canvas canvas = holder.lockCanvas(); + canvas.drawBitmap(bmp, 0, 0, paint); + holder.unlockCanvasAndPost(canvas); + } + }); + } + + public void CCL(final int c, final int who) { + _mActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + /*if (canvas2 != null && bmp != null) { + if (c == 0) + canvas2.drawColor(Color.GREEN); + else + canvas2.drawColor(Color.GRAY); + // 鎻愪氦鐢诲竷 + Canvas canvas = holder.lockCanvas(); + canvas.drawBitmap(bmp, 0, 0, paint); + holder.unlockCanvasAndPost(canvas); + }*/ +// Button button; +// if (who == 0) { +// button = findViewById(R.id.sample_button); +// } else { +// button = findViewById(R.id.net_button); +// } // -//import android.graphics.Canvas; -//import android.graphics.Color; -//import android.graphics.Paint; -//import android.graphics.Path; -//import android.graphics.PathDashPathEffect; -//import android.graphics.Rect; -//import android.graphics.RectF; -//import android.opengl.GLSurfaceView; -//import android.os.Bundle; -//import android.support.annotation.NonNull; -//import android.support.annotation.Nullable; -//import android.support.v7.widget.Toolbar; -//import android.util.Log; -//import android.view.LayoutInflater; -//import android.view.SurfaceHolder; -//import android.view.SurfaceView; -//import android.view.View; -//import android.view.ViewGroup; -//import android.widget.LinearLayout; -// -//import javax.security.auth.login.LoginException; -// -//import me.yokeyword.fragmentation.SupportFragment; -//import safeluck.drive.evaluation.R; -////import safeluck.drive.evaluation.render.GLRender; -// -// -///** -// * MyApplication2 -// * Created by lzw on 2019/9/26. 15:20:58 -// * 閭锛�632393724@qq.com -// * All Rights Saved! Chongqing AnYun Tech co. LTD -// */ -//public class MapFragment extends SupportFragment{ -// private boolean isDrawing = false; -// -// public static SupportFragment newInstance(){ -// return new MapFragment(); -// } -// private GLSurfaceView mGLSurfaceView; -// private static final String TAG = "MapFragment"; -// private SurfaceHolder holder; -// Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); -// Path path = new Path(); -// private Canvas canvas; -// private int x=-1; -// private int y = -1; -// private Toolbar toolbar; -// -// private LinearLayout linearLayout;//surfaceview鐨勭埗瀹瑰櫒锛屼负浜嗙Щ鍔╯urfaceview鑰屼娇鐢紝鍥犱负scrollto涓嶈兘绉诲姩view锛� -// -// @Nullable -// @Override -// public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { -// View view = inflater.inflate(R.layout.layout_mapfragment,container,false); -// initView(view); -// return view; -// } -// -// private void initView(View view) { -// toolbar = view.findViewById(R.id.toolbar); -// toolbar.setTitle("绠�鍗曞湴鍥�"); -// -// mGLSurfaceView = view.findViewById(R.id.glsurface); -// mGLSurfaceView.setRenderer(new GLRender()); -// } -// -// -// -//} +// if (c == 0) +// button.setBackgroundColor(Color.GREEN); +// else +// button.setBackgroundColor(Color.RED); + } + }); + } + + + + +} diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java b/app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java index 31c1dcb..9c1603d 100644 --- a/app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java +++ b/app/src/main/java/safeluck/drive/evaluation/fragment/NetWorkTrainFragment.java @@ -86,6 +86,8 @@ private void initView(View view) { mListView = view.findViewById(R.id.lv); + mListView.setFocusable(false); + view.findViewById(R.id.view_map).setOnClickListener(this); mScoreAdapter = new ScoreAdapter(_mActivity); mListView.setAdapter(mScoreAdapter); btn_start_exam = view.findViewById(R.id.btn_start); @@ -121,6 +123,13 @@ e.printStackTrace(); } break; + case R.id.view_map: + MapFragment mapFragment = findFragment(MapFragment.class); + if (mapFragment==null){ + mapFragment = (MapFragment)MapFragment.newInstance(); + } + start(mapFragment); + break; } } diff --git a/app/src/main/java/safeluck/drive/evaluation/util/FileUtil.java b/app/src/main/java/safeluck/drive/evaluation/util/FileUtil.java index 0549d03..ea5345b 100644 --- a/app/src/main/java/safeluck/drive/evaluation/util/FileUtil.java +++ b/app/src/main/java/safeluck/drive/evaluation/util/FileUtil.java @@ -5,9 +5,13 @@ import android.content.res.Resources; import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStream; public class FileUtil { /** @@ -43,4 +47,52 @@ return stringBuffer; } + /** + * + * @param fromFile 婧愭枃浠惰矾寰勫寘鎷枃浠跺悕锛堢粷瀵硅矾寰勶級 + * @param toFile + */ + public static void copyFile(String fromFile,String toFile){ + + try { + InputStream inputStream =new FileInputStream(fromFile); + OutputStream outputStream = new FileOutputStream(toFile); + byte[] bytes = new byte[1024]; + while ((inputStream.read(bytes))>0){ + outputStream.write(bytes); + } + inputStream.close(); + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + /** + * 鎷疯礉assert鐩綍涓嬬殑鏂囦欢鍒� 瀹夎鍖呯洰褰曚笅 + * @param context + * @param assertfileName + */ + public static void copyAssertFileToSD(Context context,String assertfileName){ + try { + InputStream inputStream = null; + try { + inputStream = context.getAssets() + .open(assertfileName); + } catch (IOException e) { + e.printStackTrace(); + } + OutputStream outputStream = new FileOutputStream( new File(context.getExternalFilesDir(null), assertfileName)); + byte[] bytes = new byte[1024]; + while ((inputStream.read(bytes))>0){ + outputStream.write(bytes); + } + inputStream.close(); + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } diff --git a/app/src/main/res/layout/layout_mapfragment.xml b/app/src/main/res/layout/layout_mapfragment.xml new file mode 100644 index 0000000..94b9469 --- /dev/null +++ b/app/src/main/res/layout/layout_mapfragment.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" android:layout_width="match_parent" + android:layout_height="match_parent"> + <com.google.android.material.appbar.AppBarLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:theme="@style/AppTheme.AppBarOverlay"> + + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + android:background="?attr/colorPrimary" + android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" + app:popupTheme="@style/AppTheme.NoActionBar.PopupOverlay" + app:titleTextAppearance="@style/Toolbar_TextAppearance_White"/> + + </com.google.android.material.appbar.AppBarLayout> + <SurfaceView + android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/surfaceview"/> +</LinearLayout> \ No newline at end of file -- Gitblit v1.8.0