feat: 修改自动采集时路径规划,修改文件分割的bug

This commit is contained in:
xiaoyan 2022-11-09 14:22:20 +08:00
parent 6cf1c3511f
commit 98829d9e9e
5 changed files with 408 additions and 274 deletions

View File

@ -88,11 +88,17 @@ import com.otaliastudios.cameraview.size.AspectRatio;
import com.otaliastudios.cameraview.size.SizeSelector; import com.otaliastudios.cameraview.size.SizeSelector;
import com.otaliastudios.cameraview.size.SizeSelectors; import com.otaliastudios.cameraview.size.SizeSelectors;
import com.tencent.map.geolocation.TencentLocation; import com.tencent.map.geolocation.TencentLocation;
import com.tencent.map.geolocation.TencentMotion;
import com.tencent.map.geolocation.TencentPoi;
import com.tencent.map.navi.TencentNaviCallback;
import com.tencent.map.navi.TencentNaviManager; import com.tencent.map.navi.TencentNaviManager;
import com.tencent.map.navi.TencentRouteSearchCallback; import com.tencent.map.navi.TencentRouteSearchCallback;
import com.tencent.map.navi.car.TencentCarNaviManager; import com.tencent.map.navi.car.TencentCarNaviManager;
import com.tencent.map.navi.data.AttachedLocation;
import com.tencent.map.navi.data.CalcRouteResult; import com.tencent.map.navi.data.CalcRouteResult;
import com.tencent.map.navi.data.NaviPoi; import com.tencent.map.navi.data.NaviPoi;
import com.tencent.map.navi.data.NaviTts;
import com.tencent.map.navi.data.ParallelRoadStatus;
import com.tencent.map.navi.data.RouteData; import com.tencent.map.navi.data.RouteData;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
@ -213,6 +219,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
private TencentLocation oldCurrentLocation = null; private TencentLocation oldCurrentLocation = null;
private MediaPlayer mediaPlayer; private MediaPlayer mediaPlayer;
private ImageView imgNaviDistance; // 自动规划到距离最近的数据开关 private ImageView imgNaviDistance; // 自动规划到距离最近的数据开关
private Polyline currentNaviLine; // 当前界面上正显示的导航路径线重绘路径时需要清除此前已绘制的路径
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -426,6 +433,16 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
@Override @Override
public void onClick(View view) { public void onClick(View view) {
imgNaviDistance.setSelected(!imgNaviDistance.isSelected()); imgNaviDistance.setSelected(!imgNaviDistance.isSelected());
if (view.isSelected()) {
// 开始自动匹配
if (roadMatchEntityList.isEmpty()) {
navi2NearestPoiEntity();
}
} else {
if (currentNaviLine!=null) {
currentNaviLine.remove();
}
}
} }
}); });
} }
@ -455,14 +472,14 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
} }
}); });
// tencentMap.setOnMapClickListener(new TencentMap.OnMapClickListener() { tencentMap.setOnMapClickListener(new TencentMap.OnMapClickListener() {
// @Override @Override
// public void onMapClick(LatLng latLng) { public void onMapClick(LatLng latLng) {
// Message msg = handler.obtainMessage(0x105); Message msg = handler.obtainMessage(0x105);
// msg.obj = obtainTecentLocation(latLng); msg.obj = obtainTecentLocation(latLng);
// handler.sendMessage(msg); handler.sendMessage(msg);
// } }
// }); });
tencentMap.addTencentMapGestureListener(new TencentMapGestureListener() { tencentMap.addTencentMapGestureListener(new TencentMapGestureListener() {
@Override @Override
@ -627,6 +644,10 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
roadLinkEntityList.add(roadMatchEntity); roadLinkEntityList.add(roadMatchEntity);
} }
); );
// 如果当前自动规划打开且没有正在匹配的任务自动规划下一条最近的任务
if (imgNaviDistance.isSelected()&&roadMatchEntityList.isEmpty()) {
navi2NearestPoiEntity();
}
} }
} }
}); });
@ -792,8 +813,6 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
// 语音提示用户 // 语音提示用户
mediaPlayer.start(); mediaPlayer.start();
systemTTS.playText("拍摄完成"); systemTTS.playText("拍摄完成");
// 此时自动规划距离最近的任务路径
} }
} }
@ -829,66 +848,81 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
} }
/** /**
* 导航到最近的POIEntity * 导航到最近的道路任务
* */ * */
@RequiresApi(api = Build.VERSION_CODES.N) @RequiresApi(api = Build.VERSION_CODES.N)
private void navi2NearestPoiEntity() { private void navi2NearestPoiEntity() {
if (removables == null || removables.isEmpty()) { if (roadLinkEntityList == null || roadLinkEntityList.isEmpty()) {
SystemTTS.getInstance(this).playText("附近当前没有可匹配的任务"); SystemTTS.getInstance(this).playText("附近当前没有可匹配的任务");
return; return;
} }
// RxJava处理子线程中做后台计算路径规划
Geometry currentGeometry = GeometryTools.createGeometry(new double[]{Constant.currentLocation.getLongitude(), Constant.currentLocation.getLatitude()}); Geometry currentGeometry = GeometryTools.createGeometry(new double[]{Constant.currentLocation.getLongitude(), Constant.currentLocation.getLatitude()});
Removable minRemoveable = removables.stream().filter(new Predicate<Removable>() { Observable.create(
@Override new ObservableOnSubscribe<RoadMatchEntity>() {
public boolean test(Removable removable) { @Override
if (removable instanceof Marker) { public void subscribe(ObservableEmitter<RoadMatchEntity> emitter) throws Exception {
return true; RoadMatchEntity minRoadLink = roadLinkEntityList.stream()
} // 过滤已经匹配到的数据
return false; .filter(roadMatchEntity -> {
} if (roadMatchEntityList.contains(roadMatchEntity)) {
}).min((removable, t1) -> { return false;
Marker marker1 = (Marker) removable; }
Marker marker2 = (Marker) t1; return true;
// 判断距离用户当前位置的距离 })
JobSearchBean.BodyBean.ListBean bean1 = (JobSearchBean.BodyBean.ListBean) marker1.getTag(); .min((t1, t2) -> {
JobSearchBean.BodyBean.ListBean bean2 = (JobSearchBean.BodyBean.ListBean) marker2.getTag(); // 判断距离用户当前位置的距离
// 转换geo JobSearchBean.BodyBean.ListBean bean1 = t1.getDataDetail();
Geometry geometry1 = GeometryTools.createGeometry(Geohash.getInstance().decode(bean1.getGeo())); JobSearchBean.BodyBean.ListBean bean2 = t2.getDataDetail();
Geometry geometry2 = GeometryTools.createGeometry(Geohash.getInstance().decode(bean2.getGeo())); // 转换geo
if (currentGeometry.distance(geometry1)<currentGeometry.distance(geometry2)) { Geometry geometry1 = GeometryTools.createGeometry(Geohash.getInstance().decode(bean1.getGeo()));
return 1; Geometry geometry2 = GeometryTools.createGeometry(Geohash.getInstance().decode(bean2.getGeo()));
} else if (currentGeometry.distance(geometry1)<currentGeometry.distance(geometry2)) { if (currentGeometry.distance(geometry1)<currentGeometry.distance(geometry2)) {
return -1; return 1;
} } else if (currentGeometry.distance(geometry1)<currentGeometry.distance(geometry2)) {
return 0; return -1;
}).get(); }
JobSearchBean.BodyBean.ListBean bean = (JobSearchBean.BodyBean.ListBean)((Marker)minRemoveable).getTag(); return 0;
Coordinate endPoint = GeometryTools.createGeometry(Geohash.getInstance().decode(bean.getGeo())).getCoordinates()[0]; }).get();
ToastUtils.Message(this, "自动导航到"+bean.getName()); emitter.onNext(minRoadLink);
// 跳转到对应的导航界面 emitter.onComplete();
try { }
if (Constant.currentNaviType == null) { }
NaviUtils.getInstance().selectNaviType(this, new NaviUtils.SelectNaviTypeListener() { )
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<RoadMatchEntity>() {
@Override @Override
public void selectNaviType(Constant.NAV_TYPE nav_type) { public void accept(RoadMatchEntity minRoadLink) throws Exception {
// 显示导航类型选择的对话框 JobSearchBean.BodyBean.ListBean bean = minRoadLink.getDataDetail();
Constant.currentNaviType = nav_type; Coordinate endPoint = GeometryTools.createGeometry(Geohash.getInstance().decode(bean.getGeo())).getCoordinates()[0];
ToastUtils.Message(AutoTakePictureActivity.this, "已为您规划距离最近的任务路径:"+bean.getName());
// 跳转到对应的导航界面
try { try {
tencentNaviManager = NaviUtils.getInstance().searchRouteOnly(AutoTakePictureActivity.this, Constant.currentNaviType, new NaviPoi(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()), new NaviPoi(endPoint.getY(), endPoint.getX()), routeSearchCallback); if (Constant.currentNaviType == null) {
NaviUtils.getInstance().selectNaviType(AutoTakePictureActivity.this, new NaviUtils.SelectNaviTypeListener() {
@Override
public void selectNaviType(Constant.NAV_TYPE nav_type) {
// 显示导航类型选择的对话框
Constant.currentNaviType = nav_type;
try {
tencentNaviManager = NaviUtils.getInstance().searchRouteOnly(AutoTakePictureActivity.this, Constant.currentNaviType, new NaviPoi(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()), new NaviPoi(endPoint.getY(), endPoint.getX()), routeSearchCallback);
} catch (Exception e) {
e.printStackTrace();
com.github.lazylibrary.util.ToastUtils.showToast(AutoTakePictureActivity.this, e.getMessage());
}
}
});
} else {
// 已选择导航方式
tencentNaviManager = NaviUtils.getInstance().searchRouteOnly(AutoTakePictureActivity.this, Constant.currentNaviType, new NaviPoi(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()), new NaviPoi(endPoint.getY(), endPoint.getX()), routeSearchCallback);
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
com.github.lazylibrary.util.ToastUtils.showToast(AutoTakePictureActivity.this, e.getMessage()); com.github.lazylibrary.util.ToastUtils.showToast(AutoTakePictureActivity.this, e.getMessage());
} }
} }
}); });
} else {
// 已选择导航方式
tencentNaviManager = NaviUtils.getInstance().searchRouteOnly(AutoTakePictureActivity.this, Constant.currentNaviType, new NaviPoi(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()), new NaviPoi(endPoint.getY(), endPoint.getX()), routeSearchCallback);
}
} catch (Exception e) {
e.printStackTrace();
com.github.lazylibrary.util.ToastUtils.showToast(AutoTakePictureActivity.this, e.getMessage());
}
} }
private TencentNaviManager tencentNaviManager; private TencentNaviManager tencentNaviManager;
@ -900,22 +934,11 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
@Override @Override
public void onRouteSearchSuccess(ArrayList<RouteData> arrayList) { public void onRouteSearchSuccess(ArrayList<RouteData> arrayList) {
NaviUtils.getInstance().addRoutes(arrayList, tencentMap); currentNaviLine = drawNaviLine(arrayList.get(0));
NaviUtils.getInstance().zoomToRoute(arrayList.get(0), tencentMap);
if (tencentNaviManager!=null) {
if (Constant.currentNaviType == Constant.NAV_TYPE.CAR) {
((TencentCarNaviManager)tencentNaviManager).startNavi(0);
} else if (Constant.currentNaviType == Constant.NAV_TYPE.RIDE) {
} else {
}
}
} }
@Override @Override
public void onCalcRouteSuccess(CalcRouteResult calcRouteResult) { public void onCalcRouteSuccess(CalcRouteResult calcRouteResult) {
} }
@Override @Override
@ -924,6 +947,118 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
} }
}; };
/**
* 绘制导航线路
* */
private Polyline drawNaviLine(RouteData routeData) {
if (currentNaviLine!=null) {
currentNaviLine.remove();
}
Polyline polyline = NaviUtils.getInstance().addRoutes(routeData, tencentMap);
NaviUtils.getInstance().zoomToRoute(AutoTakePictureActivity.this, routeData, tencentMap);
if (tencentNaviManager!=null) {
// if (Constant.currentNaviType == Constant.NAV_TYPE.CAR) {
// } else if (Constant.currentNaviType == Constant.NAV_TYPE.RIDE) {
//
// } else {
//
// }
tencentNaviManager.setNaviCallback(new TencentNaviCallback() {
@Override
public void onStartNavi() {
}
@Override
public void onStopNavi() {
polyline.remove();
}
@Override
public void onOffRoute() {
}
@Override
public void onRecalculateRouteSuccess(int i, ArrayList<RouteData> arrayList) {
}
@Override
public void onRecalculateRouteSuccessInFence(int i) {
}
@Override
public void onRecalculateRouteFailure(int i, int i1, String s) {
}
@Override
public void onRecalculateSuccess(CalcRouteResult calcRouteResult) {
}
@Override
public void onRecalculateFailure(CalcRouteResult calcRouteResult) {
}
@Override
public void onRecalculateRouteStarted(int i) {
}
@Override
public void onRecalculateRouteCanceled() {
}
@Override
public void onArrivedDestination() {
polyline.remove();
}
@Override
public void onPassedWayPoint(int i) {
}
@Override
public void onUpdateRoadType(int i) {
}
@Override
public void onUpdateParallelRoadStatus(ParallelRoadStatus parallelRoadStatus) {
}
@Override
public void onUpdateAttachedLocation(AttachedLocation attachedLocation) {
}
@Override
public void onFollowRouteClick(String s, ArrayList<LatLng> arrayList) {
}
@Override
public int onVoiceBroadcast(NaviTts naviTts) {
return 0;
}
});
}
return polyline;
}
/**
* 清除导航的路线
* */
private void clearNaviLine(Polyline polyline) {
polyline.remove();
}
/** /**
* 初始化领取任务的管理栈 * 初始化领取任务的管理栈
* */ * */
@ -1568,204 +1703,204 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
// window.setAttributes(lp); // window.setAttributes(lp);
} }
// private TencentLocation obtainTecentLocation(LatLng latLng) { private TencentLocation obtainTecentLocation(LatLng latLng) {
// return new TencentLocation() { return new TencentLocation() {
// @Override @Override
// public String getProvider() { public String getProvider() {
// return "NetWork"; return "NetWork";
// } }
//
// @Override @Override
// public String getFusionProvider() { public String getFusionProvider() {
// return null; return null;
// } }
//
// @Override @Override
// public String getSourceProvider() { public String getSourceProvider() {
// return null; return null;
// } }
//
// @Override @Override
// public double getLatitude() { public double getLatitude() {
// return latLng.getLatitude(); return latLng.getLatitude();
// } }
//
// @Override @Override
// public double getLongitude() { public double getLongitude() {
// return latLng.getLongitude(); return latLng.getLongitude();
// } }
//
// @Override @Override
// public double getAltitude() { public double getAltitude() {
// return latLng.getAltitude(); return latLng.getAltitude();
// } }
//
// @Override @Override
// public float getAccuracy() { public float getAccuracy() {
// return 100; return 100;
// } }
//
// @Override @Override
// public String getName() { public String getName() {
// return "null"; return "null";
// } }
//
// @Override @Override
// public String getAddress() { public String getAddress() {
// return "null"; return "null";
// } }
//
// @Override @Override
// public String getNation() { public String getNation() {
// return "null"; return "null";
// } }
//
// @Override @Override
// public String getProvince() { public String getProvince() {
// return "null"; return "null";
// } }
//
// @Override @Override
// public String getCity() { public String getCity() {
// return "null"; return "null";
// } }
//
// @Override @Override
// public String getDistrict() { public String getDistrict() {
// return "null"; return "null";
// } }
//
// @Override @Override
// public String getTown() { public String getTown() {
// return null; return null;
// } }
//
// @Override @Override
// public String getVillage() { public String getVillage() {
// return null; return null;
// } }
//
// @Override @Override
// public String getStreet() { public String getStreet() {
// return null; return null;
// } }
//
// @Override @Override
// public String getStreetNo() { public String getStreetNo() {
// return null; return null;
// } }
//
// @Override @Override
// public Integer getAreaStat() { public Integer getAreaStat() {
// return null; return null;
// } }
//
// @Override @Override
// public List<TencentPoi> getPoiList() { public List<TencentPoi> getPoiList() {
// return null; return null;
// } }
//
// @Override @Override
// public float getBearing() { public float getBearing() {
// return 0; return 0;
// } }
//
// @Override @Override
// public float getSpeed() { public float getSpeed() {
// return 0; return 0;
// } }
//
// @Override @Override
// public long getTime() { public long getTime() {
// return 0; return 0;
// } }
//
// @Override @Override
// public long getElapsedRealtime() { public long getElapsedRealtime() {
// return 0; return 0;
// } }
//
// @Override @Override
// public int getGPSRssi() { public int getGPSRssi() {
// return 0; return 0;
// } }
//
// @Override @Override
// public int getInOutStatus() { public int getInOutStatus() {
// return 0; return 0;
// } }
//
// @Override @Override
// public String getIndoorBuildingId() { public String getIndoorBuildingId() {
// return null; return null;
// } }
//
// @Override @Override
// public String getIndoorBuildingFloor() { public String getIndoorBuildingFloor() {
// return null; return null;
// } }
//
// @Override @Override
// public int getIndoorLocationType() { public int getIndoorLocationType() {
// return 0; return 0;
// } }
//
// @Override @Override
// public double getDirection() { public double getDirection() {
// return 0; return 0;
// } }
//
// @Override @Override
// public String getCityCode() { public String getCityCode() {
// return null; return null;
// } }
//
// @Override @Override
// public String getCityPhoneCode() { public String getCityPhoneCode() {
// return null; return null;
// } }
//
// @Override @Override
// public TencentMotion getMotion() { public TencentMotion getMotion() {
// return null; return null;
// } }
//
// @Override @Override
// public int getGpsQuality() { public int getGpsQuality() {
// return 0; return 0;
// } }
//
// @Override @Override
// public float getDeltaAngle() { public float getDeltaAngle() {
// return 0; return 0;
// } }
//
// @Override @Override
// public float getDeltaSpeed() { public float getDeltaSpeed() {
// return 0; return 0;
// } }
//
// @Override @Override
// public int getCoordinateType() { public int getCoordinateType() {
// return 0; return 0;
// } }
//
// @Override @Override
// public int getFakeReason() { public int getFakeReason() {
// return 0; return 0;
// } }
//
// @Override @Override
// public int isMockGps() { public int isMockGps() {
// return 0; return 0;
// } }
//
// @Override @Override
// public Bundle getExtra() { public Bundle getExtra() {
// return null; return null;
// } }
// }; };
// } }
private Handler handler = new Handler(new Handler.Callback() { private Handler handler = new Handler(new Handler.Callback() {
@Override @Override

View File

@ -44,7 +44,7 @@ object FileSpliteMergeUtils {
val begin = offSet val begin = offSet
// 如果当前index对应的数据没有超过文件大小则使用cutSize否则使用文件实际剩余大小 // 如果当前index对应的数据没有超过文件大小则使用cutSize否则使用文件实际剩余大小
var end = begin + cutSize var end = begin + cutSize
if (totalLength<end) { if (totalLength<=end) {
end = totalLength; end = totalLength;
} }
val file = createSingleFile(sourceFile,i) val file = createSingleFile(sourceFile,i)
@ -88,9 +88,9 @@ object FileSpliteMergeUtils {
private fun writeFile(inFile: RandomAccessFile,single: File,begin: Long,end: Long): Long{ private fun writeFile(inFile: RandomAccessFile,single: File,begin: Long,end: Long): Long{
var endPointer = 0L var endPointer = 0L
val out = RandomAccessFile(single,"rw") val out = RandomAccessFile(single,"rw")
var index = 0
try { try {
val byte = ByteArray(1024) val byte = ByteArray(1024)
var index = 0
inFile.seek(begin) inFile.seek(begin)
while (inFile.read(byte).also { index = it } != -1 && inFile.filePointer <= end){ while (inFile.read(byte).also { index = it } != -1 && inFile.filePointer <= end){
out.write(byte,0,index) out.write(byte,0,index)
@ -101,7 +101,7 @@ object FileSpliteMergeUtils {
}finally { }finally {
out.close() out.close()
} }
return endPointer - 1024//减1024是为了避免分割文件时丢包 return endPointer - index // 减去最后一次读取的字节数因为while循环中会先读取文件导致filePointer字段向后移动index但是后面的判断条件导致循环跳出所以要将下次读取的offset向前移动
} }
/** /**

View File

@ -474,8 +474,8 @@ public class NaviUtils {
@Override @Override
public void onRouteSearchSuccess(ArrayList<RouteData> arrayList) { public void onRouteSearchSuccess(ArrayList<RouteData> arrayList) {
// 添加道路Route到地图默认选取第一条 // 添加道路Route到地图默认选取第一条
addRoutes(arrayList, tencentMap); addRoutes(arrayList.get(0), tencentMap);
zoomToRoute(arrayList.get(0), tencentMap); zoomToRoute(mContext, arrayList.get(0), tencentMap);
try { try {
// 自动开始导航 // 自动开始导航
if (Constant.currentNaviType == Constant.NAV_TYPE.CAR) { if (Constant.currentNaviType == Constant.NAV_TYPE.CAR) {
@ -536,8 +536,7 @@ public class NaviUtils {
} }
} }
public void addRoutes(ArrayList<RouteData> mRouteDatas, TencentMap map) { public Polyline addRoutes(RouteData routeData, TencentMap map) {
RouteData routeData = mRouteDatas.get(0);
ArrayList<TrafficItem> traffics = getTrafficItemsFromList(routeData.getTrafficIndexList()); ArrayList<TrafficItem> traffics = getTrafficItemsFromList(routeData.getTrafficIndexList());
List<LatLng> mRoutePoints = routeData.getRoutePoints(); List<LatLng> mRoutePoints = routeData.getRoutePoints();
// 点的个数 // 点的个数
@ -578,9 +577,9 @@ public class NaviUtils {
map = tencentMap; map = tencentMap;
} }
Polyline polyline = map.addPolyline(options); Polyline polyline = map.addPolyline(options);
return polyline;
} }
public void zoomToRoute(RouteData routeData, TencentMap map) { public void zoomToRoute(Context mContext, RouteData routeData, TencentMap map) {
int marginLeft = mContext.getResources().getDimensionPixelSize(R.dimen.navigation_line_margin_left); int marginLeft = mContext.getResources().getDimensionPixelSize(R.dimen.navigation_line_margin_left);
int marginTop = mContext.getResources().getDimensionPixelSize(R.dimen.navigation_line_margin_top); int marginTop = mContext.getResources().getDimensionPixelSize(R.dimen.navigation_line_margin_top);
int marginRight = mContext.getResources().getDimensionPixelSize(R.dimen.navigation_line_margin_right); int marginRight = mContext.getResources().getDimensionPixelSize(R.dimen.navigation_line_margin_right);

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB