| | |
| | | package safeluck.drive.evaluation.fragment; |
| | | |
| | | import android.content.Context; |
| | | import android.graphics.Bitmap; |
| | | import android.graphics.Canvas; |
| | | import android.graphics.Color; |
| | |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.Toast; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.annotation.Nullable; |
| | | import androidx.appcompat.widget.Toolbar; |
| | | |
| | | |
| | | import com.anyun.exam.lib.MyLog; |
| | | import com.google.gson.Gson; |
| | | |
| | | import org.json.JSONArray; |
| | | import org.json.JSONObject; |
| | | |
| | | import java.util.List; |
| | | |
| | | import me.yokeyword.fragmentation.SupportFragment; |
| | | import safeluck.drive.evaluation.Constant; |
| | | import safeluck.drive.evaluation.R; |
| | | import safeluck.drive.evaluation.bean.RealTimeCarPos; |
| | | import safeluck.drive.evaluation.cEventCenter.CEventCenter; |
| | | import safeluck.drive.evaluation.cEventCenter.ICEventListener; |
| | | import safeluck.drive.evaluation.util.CThreadPoolExecutor; |
| | | |
| | | |
| | | /** |
| | |
| | | * 邮箱:632393724@qq.com |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | | */ |
| | | public class MapFragment extends SupportFragment{ |
| | | public class MapFragment extends SupportFragment { |
| | | private boolean isDrawing = false; |
| | | |
| | | public static SupportFragment newInstance(){ |
| | | 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 x = -1; |
| | | private int y = -1; |
| | | private Toolbar toolbar; |
| | | |
| | |
| | | private String osd = null; |
| | | private String osd2 = null; |
| | | private String osd3 = null; |
| | | |
| | | |
| | | double map[][] = {{1, 1}, {10, 1}, {10, 10}, {1, 10}}; |
| | | double car[][] = {{8.278, 1.467}, {7.2780000000000009, 1.467}, {7.2780000000000009, -1.533}, {8.278, -1.533} |
| | | , {9.278, -1.5330000000000004}, {9.277999999999999, 1.467000000000001}}; |
| | | Gson gson; |
| | | private LinearLayout linearLayout;//surfaceview的父容器,为了移动surfaceview而使用,因为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); |
| | | View view = inflater.inflate(R.layout.layout_mapfragment, container, false); |
| | | gson = new Gson(); |
| | | initView(view); |
| | | return view; |
| | | } |
| | |
| | | holder.unlockCanvasAndPost(canvas); |
| | | } |
| | | |
| | | new Thread(new NeedForSpeed()).start(); |
| | | // new Thread(new NeedForSpeed(car, map)).start(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | |
| | | class NeedForSpeed implements Runnable { |
| | | public NeedForSpeed(double[][] car, double[][] map) { |
| | | DrawMap(map, car); |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | double map[][] = {{1,1}, {10,1}, {10,10}, {1,10}}; |
| | | double car[][] = {{3,3}, {8,3}, {8,8}, {3,8}}; |
| | | |
| | | // double car[][] = {{3,3}, {8,3}, {8,8}, {3,8}}; |
| | | |
| | | |
| | | DrawMap(map, car); |
| | | } |
| | | } |
| | | |
| | | public void DrawMap(final double [][]map, final double [][]car) { |
| | | public void DrawMap(final double[][] map, final double[][] car) { |
| | | if (canvas2 == null || bmp == null) { |
| | | return; |
| | | } |
| | |
| | | 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))); |
| | | 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)); |
| | | 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(); |
| | |
| | | } |
| | | 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)); |
| | | 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.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); |
| | | |
| | |
| | | }); |
| | | } |
| | | |
| | | int line = 0; |
| | | private ICEventListener icEventListener = new ICEventListener() { |
| | | @Override |
| | | public void onCEvent(String topic, int msgCode, int resultCode, Object obj) { |
| | | MyLog.i(TAG, (String) obj); |
| | | RealTimeCarPos timeCarPos = gson.fromJson((String) obj, RealTimeCarPos.class); |
| | | List<Double> points = timeCarPos.getPoint(); |
| | | line = 0; |
| | | |
| | | for (int i = 0; i < points.size(); i++) { |
| | | if ((i % 2) == 0) { |
| | | car[line][0] = points.get(i); |
| | | } else { |
| | | double value = 0 - points.get(i); |
| | | Log.i(TAG, "onCEvent: 新值=" + value + " 位置:" + i); |
| | | car[line][1] = value; |
| | | line++; |
| | | } |
| | | |
| | | } |
| | | CThreadPoolExecutor.runInBackground(new NeedForSpeed(car,map)); |
| | | } |
| | | }; |
| | | |
| | | @Override |
| | | public void onAttach(Context context) { |
| | | super.onAttach(context); |
| | | CEventCenter.onBindEvent(true, icEventListener, Constant.REAL_TIME_POS_CAR_TOPIC); |
| | | } |
| | | |
| | | @Override |
| | | public void onDetach() { |
| | | super.onDetach(); |
| | | CEventCenter.onBindEvent(false, icEventListener, Constant.REAL_TIME_POS_CAR_TOPIC); |
| | | } |
| | | } |