| | |
| | | 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; |
| | | |
| | | |
| | | /** |
| | |
| | | public static SupportFragment newInstance(){ |
| | | return new MapFragment(); |
| | | } |
| | | |
| | | private SurfaceView mSurfaceView; |
| | | private static final String TAG = "MapFragment"; |
| | | private SurfaceHolder holder; |
| | |
| | | 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, |
| | | |
| | | |
| | |
| | | @Override |
| | | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
| | | 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); |
| | | } |
| | |
| | | }); |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | } |