From 6060b1e0c4a3cd4396eabc25634aaff45959e360 Mon Sep 17 00:00:00 2001
From: lizhanwei <Dana_Lee1016@126.com>
Date: 星期六, 25 七月 2020 20:18:19 +0800
Subject: [PATCH] 加入对远程服务的监听
---
app/src/main/java/safeluck/drive/evaluation/Constant.java | 2
app/src/main/java/safeluck/drive/evaluation/app.java | 24 +++
lib/src/main/java/com/anyun/exam/lib/SvrManager.java | 9 +
app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java | 94 ++++++++++++++-
app/src/main/java/safeluck/drive/evaluation/DB/exam_status/ExamStatusOutWorker.kt | 3
lib/src/main/java/com/anyun/exam/lib/IAYExamListener.java | 1
app/src/main/java/safeluck/drive/evaluation/bean/RTKInfoBean.java | 171 ++++++++++++++++++++++++++++
app/src/main/java/safeluck/drive/evaluation/arcgis/MapSingleTapListener.kt | 36 ++++++
8 files changed, 326 insertions(+), 14 deletions(-)
diff --git a/app/src/main/java/safeluck/drive/evaluation/Constant.java b/app/src/main/java/safeluck/drive/evaluation/Constant.java
index e997c5d..4cc6f00 100644
--- a/app/src/main/java/safeluck/drive/evaluation/Constant.java
+++ b/app/src/main/java/safeluck/drive/evaluation/Constant.java
@@ -91,6 +91,8 @@
public static final int SUBJECT_III = 3;//璺��
public static final int LEFT_RIGHT_DISTANCE = 0x0020;
public static final String NEED_MAPS_CAR = "need_maps_car";
+ //鐢ㄤ簬鍦板浘杞﹁締绉诲姩 鍧愭爣
+ public static final String BIND_RTK_INFO_MAP = "bind_rtk_info_map";
public static String exam_enter_exitdata="exam_enter_exitdata";
public static int Chang_di = 2;
public static int DaoLu_night = 3;
diff --git a/app/src/main/java/safeluck/drive/evaluation/DB/exam_status/ExamStatusOutWorker.kt b/app/src/main/java/safeluck/drive/evaluation/DB/exam_status/ExamStatusOutWorker.kt
index e2f6007..d9a8c31 100644
--- a/app/src/main/java/safeluck/drive/evaluation/DB/exam_status/ExamStatusOutWorker.kt
+++ b/app/src/main/java/safeluck/drive/evaluation/DB/exam_status/ExamStatusOutWorker.kt
@@ -39,7 +39,7 @@
private val tempQs: MutableList<QuestionBean> = java.util.ArrayList()
override fun doWork(): Result {
val examType =WorkRoomDataBase.getWorkRoomDataBase(applicationContext).examStatusDao.startExamInt;
-
+ MyLog.i(TAG+"do work")
simulateNightBean.setExam(0)
val list = ExamPlatformData.getInstance().simulate_light_tips
@@ -54,6 +54,7 @@
simulateNightBean.setQuestion(tempQs)
if (inputData.getInt(safeluck.drive.evaluation.Constant.NEED_MAPS_CAR,0)==1){
+ MyLog.i("Constant.NEED_MAPS_CAR,")
sendMapInfo()
sendVehicleInfo()
}
diff --git a/app/src/main/java/safeluck/drive/evaluation/app.java b/app/src/main/java/safeluck/drive/evaluation/app.java
index 3c2f9aa..f21a3d9 100644
--- a/app/src/main/java/safeluck/drive/evaluation/app.java
+++ b/app/src/main/java/safeluck/drive/evaluation/app.java
@@ -96,7 +96,7 @@
FileUtil.createdirs(getApplicationContext());
//鑰冭瘯鐘舵�� 锛屼竴浜涘垵濮嬬姸鎬侊紝app涓�浜涚姸鎬佸簲璇ュ厛鍒濆鍖栦竴涓�
- initData();
+
}
@@ -109,6 +109,8 @@
int type = WorkRoomDataBase.getWorkRoomDataBase(getApplicationContext()).getExamStatusDao().getStartExamInt();
ExamPlatformData.getInstance().setExamType(type);
OneTimeWorkRequest examStatausOutWorker = OneTimeWorkRequest.from(ExamStatusOutWorker.class);
+ sendMapInfo();
+ sendVechileInfo();
OneTimeWorkRequest mcuUpgradeWorker = OneTimeWorkRequest.from(MCUUpgradeWorker.class);
WorkManager.getInstance(getApplicationContext()).beginWith(examStatausOutWorker).then(mcuUpgradeWorker).enqueue();
});
@@ -417,6 +419,8 @@
e.printStackTrace();
}
+ CEventCenter.dispatchEvent(Constant.BIND_RTK_INFO_MAP,cmd,0,json);
+
if (ExamPlatformData.getInstance().getExamplatformStatus()==ExamPlatformData.DEV_LOGIN){
try {
@@ -492,7 +496,21 @@
}
}
-private String last0206Str="";
+
+ @Override
+ public void bindStatus(int code) {
+ MyLog.i(String.format("bindStatus = %d",code));
+ if (code == 0){
+ ExamPlatformData.getInstance().getTTS().speak("鏈嶅姟缁戝畾鎴愬姛");
+ initData();
+ }else{
+ ExamPlatformData.getInstance().getTTS().speak("鏈嶅姟寮傚父姝讳骸");
+ }
+
+
+ }
+
+ private String last0206Str="";
private int lastSatNum= 0;
private int lastQf = 0;
@@ -553,7 +571,7 @@
byte[] fileContent = FileUtil.readFile(roadmapPath);
if (fileContent != null){
String str = new String(fileContent);
- Log.i(TAG, "鏂囦欢鍐呭锛�"+str);
+ MyLog.i("鏂囦欢鍐呭锛�"+str);
AYSdk.getInstance().sendCmd(Constant.PUSH_ROAD_MAP_INFO,str);
}else{
MyLog.i(String.format("鏂囦欢:%s涓嶅瓨鍦�",roadmapPath));
diff --git a/app/src/main/java/safeluck/drive/evaluation/arcgis/MapSingleTapListener.kt b/app/src/main/java/safeluck/drive/evaluation/arcgis/MapSingleTapListener.kt
new file mode 100644
index 0000000..e84bed6
--- /dev/null
+++ b/app/src/main/java/safeluck/drive/evaluation/arcgis/MapSingleTapListener.kt
@@ -0,0 +1,36 @@
+package safeluck.drive.evaluation.arcgis
+
+import android.content.Context
+import android.graphics.Point
+import android.view.MotionEvent
+import android.widget.Toast
+import com.esri.arcgisruntime.mapping.view.DefaultMapViewOnTouchListener
+import com.esri.arcgisruntime.mapping.view.MapView
+
+/**
+ *
+ * @ProjectName: DriveJudge
+ * @Package: safeluck.drive.evaluation.arcgis
+ * @ClassName: MapSingleTapListener
+ * @Description: java绫讳綔鐢ㄦ弿杩�
+ * @Author: 鏉庡崰浼�
+ * @CreateDate: 20/7/16 涓嬪崍5:12
+ * @UpdateUser: 鏇存柊鑰�
+ * @UpdateDate: 20/7/16 涓嬪崍5:12
+ * @UpdateRemark: 鏇存柊璇存槑
+ * @Version: 1.0
+ */
+
+class MapSingleTapListener(context: Context, mapView: MapView) : DefaultMapViewOnTouchListener(context, mapView) {
+ private var mContext: Context = context
+ val TAG = MapSingleTapListener::class.java.canonicalName
+ override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
+ var mapPoint = mMapView.screenToLocation(e?.x?.toInt()?.let { Point(it, e.y.toInt()) })
+ showMessage(String.format("User tapped on the map at (%.3f,%.3f)", mapPoint.getX(), mapPoint.getY()))
+ return true
+ }
+
+ private fun showMessage(message: String) {
+ Toast.makeText(mContext,message,Toast.LENGTH_SHORT).show()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/safeluck/drive/evaluation/bean/RTKInfoBean.java b/app/src/main/java/safeluck/drive/evaluation/bean/RTKInfoBean.java
new file mode 100644
index 0000000..7910004
--- /dev/null
+++ b/app/src/main/java/safeluck/drive/evaluation/bean/RTKInfoBean.java
@@ -0,0 +1,171 @@
+package safeluck.drive.evaluation.bean;
+
+/**
+ * @ProjectName: DriveJudge
+ * @Package: safeluck.drive.evaluation.bean
+ * @ClassName: RTKInfoBean
+ * @Description: java绫讳綔鐢ㄦ弿杩�
+ * @Author: 鏉庡崰浼�
+ * @CreateDate: 20/7/20 涓婂崍11:27
+ * @UpdateUser: 鏇存柊鑰�
+ * @UpdateDate: 20/7/20 涓婂崍11:27
+ * @UpdateRemark: 鏇存柊璇存槑
+ * @Version: 1.0
+ */
+
+public class RTKInfoBean {
+
+ /**
+ * utc : 20200720032340.60
+ * qf : 3
+ * coord_x : -7600.317
+ * coord_x_dir : N
+ * coord_y : 16574.11
+ * coord_y_dir : E
+ * heading : 0.0
+ * pitch : 0.0
+ * roll : 0.0
+ * sat_num : 14
+ * latitude : 33.270174833333336
+ * longitude : 120.78765005
+ * altitude : 58.9666
+ * speed : 1.72591488
+ * track_ture : 0.0
+ */
+
+ private String utc;
+ private int qf;
+ private double coord_x;
+ private String coord_x_dir;
+ private double coord_y;
+ private String coord_y_dir;
+ private double heading;
+ private double pitch;
+ private double roll;
+ private int sat_num;
+ private double latitude;
+ private double longitude;
+ private double altitude;
+ private double speed;
+ private double track_ture;
+
+ public String getUtc() {
+ return utc;
+ }
+
+ public void setUtc(String utc) {
+ this.utc = utc;
+ }
+
+ public int getQf() {
+ return qf;
+ }
+
+ public void setQf(int qf) {
+ this.qf = qf;
+ }
+
+ public double getCoord_x() {
+ return coord_x;
+ }
+
+ public void setCoord_x(double coord_x) {
+ this.coord_x = coord_x;
+ }
+
+ public String getCoord_x_dir() {
+ return coord_x_dir;
+ }
+
+ public void setCoord_x_dir(String coord_x_dir) {
+ this.coord_x_dir = coord_x_dir;
+ }
+
+ public double getCoord_y() {
+ return coord_y;
+ }
+
+ public void setCoord_y(double coord_y) {
+ this.coord_y = coord_y;
+ }
+
+ public String getCoord_y_dir() {
+ return coord_y_dir;
+ }
+
+ public void setCoord_y_dir(String coord_y_dir) {
+ this.coord_y_dir = coord_y_dir;
+ }
+
+ public double getHeading() {
+ return heading;
+ }
+
+ public void setHeading(double heading) {
+ this.heading = heading;
+ }
+
+ public double getPitch() {
+ return pitch;
+ }
+
+ public void setPitch(double pitch) {
+ this.pitch = pitch;
+ }
+
+ public double getRoll() {
+ return roll;
+ }
+
+ public void setRoll(double roll) {
+ this.roll = roll;
+ }
+
+ public int getSat_num() {
+ return sat_num;
+ }
+
+ public void setSat_num(int sat_num) {
+ this.sat_num = sat_num;
+ }
+
+ public double getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(double latitude) {
+ this.latitude = latitude;
+ }
+
+ public double getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(double longitude) {
+ this.longitude = longitude;
+ }
+
+ public double getAltitude() {
+ return altitude;
+ }
+
+ public void setAltitude(double altitude) {
+ this.altitude = altitude;
+ }
+
+ public double getSpeed() {
+ return speed;
+ }
+
+ public void setSpeed(double speed) {
+ this.speed = speed;
+ }
+
+ public double getTrack_ture() {
+ return track_ture;
+ }
+
+ public void setTrack_ture(double track_ture) {
+ this.track_ture = track_ture;
+ }
+}
diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java b/app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java
index 454809f..942bbb6 100644
--- a/app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java
+++ b/app/src/main/java/safeluck/drive/evaluation/fragment/JiaXiaoFragment.java
@@ -1,21 +1,25 @@
package safeluck.drive.evaluation.fragment;
+import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
+import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
import com.esri.arcgisruntime.arcgisservices.ArcGISMapServiceInfo;
+import com.esri.arcgisruntime.concurrent.ListenableFuture;
import com.esri.arcgisruntime.data.ServiceFeatureTable;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.PointCollection;
@@ -55,14 +59,23 @@
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import me.yokeyword.fragmentation.SupportFragment;
+import safeluck.drive.evaluation.Constant;
import safeluck.drive.evaluation.R;
import safeluck.drive.evaluation.app;
+import safeluck.drive.evaluation.arcgis.MapSingleTapListener;
+import safeluck.drive.evaluation.bean.ExamPlatformData;
import safeluck.drive.evaluation.bean.GisCarModel;
+import safeluck.drive.evaluation.bean.RTKInfoBean;
+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;
@@ -74,10 +87,37 @@
* All Rights Saved! Chongqing AnYun Tech co. LTD
*/
public class JiaXiaoFragment extends SupportFragment {
+
+ private static final String TAG = JiaXiaoFragment.class.getSimpleName();
+
+
+
+ private Gson gson = new Gson();
+ private ICEventListener icEventListener = new ICEventListener() {
+ @Override
+ public void onCEvent(String topic, int msgCode, int resultCode, Object obj) {
+
+ synchronized (JiaXiaoFragment.class){
+ String json = (String)obj;
+ Log.i(TAG,String.format("褰撳墠绾跨▼鍙�%d,json=%s",Thread.currentThread().getId(),json));
+ RTKInfoBean rtkInfoBean = gson.fromJson(json,RTKInfoBean.class);
+ Log.i(TAG,String.format("CThreadPoolExecutor,褰撳墠绾跨▼鍙�%d,Coord_x=%f,Coord_y=%f",
+ Thread.currentThread().getId(),rtkInfoBean.getCoord_x(),rtkInfoBean
+ .getCoord_y()));
+ yaw = rtkInfoBean.getHeading();
+ startX = rtkInfoBean.getCoord_y();
+ startY = rtkInfoBean.getCoord_x();
+ addGraphicLayer(yaw,startX,startY);
+ }
+
+
+ }
+ };
+
public static SupportFragment newInstance(){
return new JiaXiaoFragment();
}
- private static final String TAG = JiaXiaoFragment.class.getSimpleName();
+
private MapView mMapView ;
private static final int MSG_CAR = 100;
@@ -108,13 +148,14 @@
View view = inflater.inflate(R.layout.layout_arc_gis,container,false);
mMapView = view.findViewById(R.id.mapView);
+ Log.i(TAG,String.format("褰撳墠绾跨▼鍙�%d,json=%s",Thread.currentThread().getId(),"onCreateView"));
setupMap();
addTrailheadsLayer();
-// addImageLayer();
+ addGraphicLayer(0,startX,startY);
- mHandler.sendEmptyMessageDelayed(MSG_CAR,1000);
+// mHandler.sendEmptyMessageDelayed(MSG_CAR,1000);
-// drawPolygon();
+
return view;
}
private SublayerList mSublayersList;
@@ -130,9 +171,11 @@
}
private void addTrailheadsLayer() {
-
+//涓�瀹氫笉鑳藉皯浜嗘渶鍚庣殑 /
String url = "http://192.168.0.47:6080/arcgis/rest/services/%E5%9C%9F%E4%B8%BB%E8%80%83%E5%9C%BA/MapServer/";
+// String url = "http://192.168.0.47:6080/arcgis/rest/services/test/MapServer/";
+// String url = "http://192.168.0.47:6080/arcgis/rest/services/Testmap_3/MapServer/";
ArcGISMapImageLayer arcGISMapImageLayer = new ArcGISMapImageLayer(url);
arcGISMapImageLayer.loadAsync();
arcGISMapImageLayer.addLoadStatusChangedListener(loadStatusChangedEvent -> {
@@ -141,6 +184,7 @@
Log.i(TAG,"ServiceFeatureTables size = "+tables.size());
for (int i = tables.size()-1; i >= 0; i--) {
+// for (int i =0; i < tables.size(); i++) {
ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable(url+String.valueOf(i));
FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable);
@@ -150,8 +194,23 @@
}
});
-
+ final ListenableFuture<Boolean> viewPointSetFuture = mMapView.setViewpointRotationAsync(90);
+ viewPointSetFuture.addDoneListener(() -> {
+ try{
+ boolean completed = viewPointSetFuture.get();
+ if (completed){
+ Log.i(TAG,"Rotation completed successfully");
+ }
+ }catch (InterruptedException e){
+ Log.i(TAG,"Rotation Interrupted");
+ }catch (ExecutionException e){
+
+ }
+ });
+
+
+ mMapView.setOnTouchListener(new MapSingleTapListener(getContext(),mMapView));
}
@@ -161,13 +220,18 @@
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.rgb(232,0,0), 0.5f);
SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.argb(255,232,0,0), lineSymbol);
PointCollection points = new PointCollection(SpatialReference.create(4544));
+ String carFilePath = ExamPlatformData.getInstance().getCarModelPath();
+ if (TextUtils.isEmpty(carFilePath)){
+ Toast.makeText(_mActivity, "杞﹁締妯″瀷鏂囦欢涓嶅瓨鍦�", Toast.LENGTH_SHORT).show();
+ return;
+ }
CThreadPoolExecutor.runInBackground(new Runnable() {
@Override
public void run() {
- StringBuffer buffer= FileUtil.readAssetTxtFile(app.getAppContext(),"giscar.json");
- Log.i(TAG,"giscar="+buffer.toString());
- GisCarModel gisCarModel= new Gson().fromJson(buffer.toString(),GisCarModel.class);
-// List<safeluck.drive.evaluation.bean.Point> carNew=Utils.getCarPoint(0,45,new safeluck.drive.evaluation.bean.Point(-8633.77199999988,14471.793700000271));
+ byte[] fileContentBytes=FileUtil.readFile(carFilePath);
+ String buffer= new String(fileContentBytes);
+// Log.i(TAG,"giscar="+buffer);
+ GisCarModel gisCarModel= new Gson().fromJson(buffer,GisCarModel.class);
List<safeluck.drive.evaluation.bean.Point> carNew=Utils.getCarPoint(0,yaw,new safeluck.drive.evaluation.bean.Point(x,y));
List<Integer> bodys =gisCarModel.getBody();
for (int i = 0; i <bodys.size(); i++) {
@@ -189,6 +253,9 @@
drawPoint(new Point(x,y));
+ if (mMapView != null){
+ mMapView.setViewpointCenterAsync(new Point(x,y));
+ }
}
});
@@ -415,6 +482,13 @@
if (mMapView != null) {
mMapView.dispose();
}
+ CEventCenter.onBindEvent(false,icEventListener, Constant.BIND_RTK_INFO_MAP);
super.onDetach();
}
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ CEventCenter.onBindEvent(true,icEventListener,Constant.BIND_RTK_INFO_MAP);
+ }
}
diff --git a/lib/src/main/java/com/anyun/exam/lib/IAYExamListener.java b/lib/src/main/java/com/anyun/exam/lib/IAYExamListener.java
index bee2b40..8966762 100644
--- a/lib/src/main/java/com/anyun/exam/lib/IAYExamListener.java
+++ b/lib/src/main/java/com/anyun/exam/lib/IAYExamListener.java
@@ -10,4 +10,5 @@
*/
public interface IAYExamListener {
void callBackMsg(int code,String json);
+ void bindStatus(int code);//0-缁戝畾鎴愬姛 -1 binderDied 1
}
diff --git a/lib/src/main/java/com/anyun/exam/lib/SvrManager.java b/lib/src/main/java/com/anyun/exam/lib/SvrManager.java
index 042fe64..b9d9f6d 100644
--- a/lib/src/main/java/com/anyun/exam/lib/SvrManager.java
+++ b/lib/src/main/java/com/anyun/exam/lib/SvrManager.java
@@ -28,6 +28,9 @@
private IAYExamListener mCallback;
//杩滅▼鏈嶅姟鎺ュ彛
private IRemoteInterface remoteInterface;
+ private int BIND_SUCC = 0;
+ private int BIND_binderDied = -1;
+
static SvrManager getInstance() {
return ourInstance;
}
@@ -49,6 +52,9 @@
@Override
public void binderDied() {
MyLog.e(TAG,"IBinder.DeathRecipient binderDied");
+ if (mCallback != null){
+ mCallback.bindStatus(BIND_binderDied);
+ }
if (remoteInterface == null){
MyLog.e(TAG,"IBinder.DeathRecipient binderDied remoteInterface == null ,return");
return;
@@ -98,6 +104,9 @@
//璁剧疆姝讳骸浠g悊
service.linkToDeath(mDeathRecipient,0);
MyLog.i("缁戝畾鏈嶅姟onServiceConnected");
+ if(mCallback!=null){
+ mCallback.bindStatus(BIND_SUCC);
+ }
remoteInterface.registListener(RemoteCallback);
} catch (RemoteException e) {
e.printStackTrace();
--
Gitblit v1.8.0