diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 98f8bd1..4eab927 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -102,7 +102,8 @@ - + removables; + private List markerLatlng; + private final int MARKER_DOT = 3; + private final int MARKER_LINE = 2; + private final int MARKER_FACE = 1; + private ClusterManager clusterItemClusterManager; + private Circle circle; + private List items; + + + @Override + protected int getLayout() { + return R.layout.activity_test; + } + + @Override + protected void initData() { + super.initData(); + removables = new ArrayList<>();//存储网络数据的marker数据(线,面,点) + markerLatlng = new ArrayList<>();//存储网络数据的marker数据(线,面,点) + initList(Constant.currentLocation); + } + + private void initList(TencentLocation tencentLocation) { + int task_type = Constant.TASK_TYPE; + int limit_type = Constant.LIMIT_TYPE; + int taskStatus = Constant.TASK_STARTUP; + if (taskStatus == 1 || taskStatus == 2 || taskStatus == 3) { + Message obtain = Message.obtain(); + obtain.what = Constant.JOB_SEARCH_WORD; + obtain.obj = null; + EventBus.getDefault().post(obtain); + return; + } + //获取中心点位置 + LatLng mapCenterPoint = tencentMap.getCameraPosition().target; + String centerEncode = null; + if (mapCenterPoint != null) { + centerEncode = Geohash.getInstance().encode(mapCenterPoint.latitude, mapCenterPoint.longitude); + } + String userEncode = Geohash.getInstance().encode(tencentLocation.getLatitude(), tencentLocation.getLongitude()); + OkGo.getInstance().cancelTag(this); + showLoadingDialog(); + // 请求方式和请求url + HttpParams httpParams = new HttpParams(); + httpParams.put("userGeo", userEncode); + httpParams.put("centerGeo", centerEncode); + httpParams.put("pageSize", Constant.NUMBER); + int treasurePage = 1; + httpParams.put("pageNum", treasurePage); + httpParams.put("type", task_type); + httpParams.put("isExclusive", limit_type); + OkGoBuilder.getInstance() + .Builder(this) + .url(HttpInterface.TASK_LIST) + .cls(JobSearchBean.class) + .params(httpParams) + .token(Constant.ACCESS_TOKEN) + .getRequest(new Callback() { + @Override + public void onSuccess(JobSearchBean response, int id) { + dismissLoadingDialog(); + if (response.getCode() == 200) { + JobSearchBean.BodyBean body = response.getBody(); + if (body != null) { + Log.d("TAG", "onSuccess: " + response.getBody().toString() + "sassafras's"); + for (int i = 0; i < removables.size(); i++) { + removables.get(i).remove(); + } + removables.clear(); + List list = response.getBody().getList(); + for (int i = 0; i < list.size(); i++) { + JobSearchBean.BodyBean.ListBean listBean = list.get(i); + String encodeStr = list.get(i).getGeo(); + // 解密geo + String geo = Geohash.getInstance().decode(encodeStr); + listBean.setGeo(geo); + Log.d("TAG", "onSuccess: " + geo); + Geometry geometry = GeometryTools.createGeometry(geo); + LatLng latLng = null; + switch (geometry.getGeometryType()) { + case "Point": //点 + latLng = GeometryTools.createLatLng(geo); + break; + case "LineString": //线 + BitmapDescriptor bitmapLine = null; + if (listBean.getType() == 3) {//poi录像 + bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_arrows); + } else if (listBean.getType() == 4) {//道路录像 + bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.road_arrows); + } + List latLineString = GeometryTools.getLatLngs(geo); + // 构造 PolylineOptions + PolylineOptions polylineOptions = new PolylineOptions() + .addAll(latLineString) + // 折线设置圆形线头 + .lineCap(true) + // 折线的颜色为绿色 + .color(Color.parseColor("#0096FF")) + // 折线宽度为5像素 + .width(10) + .arrow(true) + .arrowSpacing(100) + .arrowTexture(bitmapLine); + // 还可以添加描边颜色 + //.borderColor(0xffff0000) + // 描边颜色的宽度,线宽还是 25 像素,不过填充的部分宽度为 `width` - 2 * `borderWidth` + //.borderWidth(1); + // 绘制折线 + Polyline polyline = tencentMap.addPolyline(polylineOptions); + polyline.setZIndex(MARKER_LINE); + removables.add(polyline); + if (latLineString != null && latLineString.size() > 0) { + latLng = latLineString.get(0); + } + break; + case "Polygon": //面 + List latPolygon = GeometryTools.getLatLngs(geo); + Polygon polygon = tencentMap.addPolygon(new PolygonOptions(). + //连接封闭图形的点 + addAll(latPolygon). + //填充颜色为红色 + fillColor(Color.parseColor("#97E0E7EC")). + //边线颜色为黑色 + strokeColor(0xff000000). + //边线宽度15像素 + strokeWidth(5)); + polygon.setZIndex(MARKER_FACE); + removables.add(polygon); + com.vividsolutions.jts.geom.Point centroid = geometry.getCentroid(); + double x = centroid.getX(); + double y = centroid.getY(); + latLng = new LatLng(); + latLng.setLatitude(y); + latLng.setLongitude(x); + /* if (latPolygon != null && latPolygon.size() > 0) { + latLng = latPolygon.get(0); + }*/ + break; + } + markerLatlng.add(latLng); + switch (list.get(i).getType()) { + + case 1://poi + BitmapDescriptor poiDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_bg1); + //poiDescriptor.getForager().setScale(50); + assert latLng != null; + Marker poiMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiDescriptor).alpha(0.9f) + .anchor(0.5f, 1.0f) + .flat(true) + .clockwise(false)); + poiMarker.setZIndex(MARKER_DOT); + poiMarker.setTag(listBean); + removables.add(poiMarker); + poiMarker.setClickable(true); + break; + case 2://充电站 + BitmapDescriptor chargeDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_charge_bg1); + assert latLng != null; + Marker stationMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(chargeDescriptor).alpha(0.9f) + .anchor(0.5f, 1.0f) + .flat(true) + .clockwise(false)); + stationMarker.setZIndex(MARKER_DOT); + stationMarker.setTag(listBean); + removables.add(stationMarker); + stationMarker.setClickable(true); + + break; + case 3://poi录像 + BitmapDescriptor poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_video_bg1); + assert latLng != null; + Marker poiVideoMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiVideoDescriptor).alpha(0.9f) + .anchor(0.5f, 1.0f) + .flat(true) + .clockwise(false)); + poiVideoMarker.setTag(listBean); + poiVideoMarker.setZIndex(MARKER_DOT); + removables.add(poiVideoMarker); + poiVideoMarker.setClickable(true); + break; + case 4://道路录像 + BitmapDescriptor roadDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_road_bg); + assert latLng != null; + Marker roadMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(roadDescriptor).alpha(0.9f) + .anchor(0.5f, 1.0f) + .flat(true) + .clockwise(false)); + roadMarker.setZIndex(MARKER_DOT); + roadMarker.setTag(listBean); + removables.add(roadMarker); + roadMarker.setClickable(true); + + break; + case 5://其他 + BitmapDescriptor otherDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_other_bg1); + assert latLng != null; + Marker otherMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(otherDescriptor).alpha(0.9f) + .anchor(0.5f, 1.0f) + .flat(true) + .clockwise(false)); + otherMarker.setZIndex(MARKER_DOT); + otherMarker.setTag(listBean); + removables.add(otherMarker); + otherMarker.setClickable(true); + break; + case 6://面状任务 + BitmapDescriptor Descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_facet_bg1); + assert latLng != null; + Marker planarMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(Descriptor).alpha(0.9f) + .anchor(0.5f, 1.0f) + .flat(true) + .clockwise(false)); + planarMarker.setZIndex(MARKER_DOT); + planarMarker.setTag(listBean); + removables.add(planarMarker); + planarMarker.setClickable(true); + break; + } + } + } + Message obtain = Message.obtain(); + obtain.what = Constant.JOB_SEARCH_WORD; + obtain.obj = response; + EventBus.getDefault().post(obtain); + } else { + Toast.makeText(TestActivity.this, response.getMessage(), Toast.LENGTH_SHORT).show(); + } + + } + + @Override + public void onError(Throwable e, int id) { + dismissLoadingDialog(); + Log.d("TAG", "onError: " + e.getMessage() + ""); + } + }); + } + + @Override + protected void initView() { + super.initView(); + TextureMapView tvMap = findViewById(R.id.iv_map); + + tencentMap = tvMap.getMap(); + + //获取地图UI 设置对象 + UiSettings uiSettings = tencentMap.getUiSettings(); + //设置logo的大小 + uiSettings.setLogoScale(0.7f); + uiSettings.setRotateGesturesEnabled(false);//禁止地图旋转手势. + uiSettings.setTiltGesturesEnabled(false);//禁止倾斜手势. + //uiSettings.setAllGesturesEnabled(false); + setLocMarkerStyle(LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER); + // initCluster(); + initNewMarker(); + + + } + + private void initNewMarker() { + //添加圆 + LatLng mapCenterPoint = tencentMap.getCameraPosition().target; + circle = tencentMap.addCircle(new CircleOptions(). + // 圆心 + center(mapCenterPoint). + // 半径 + radius(1000d). + // 圆的填充色为蓝色 + fillColor(0xff0000ff). + // 描边的颜色为黑色 + strokeColor(0xff000000). + // 描边宽度 + strokeWidth(1). + // 可点击性 + clickable(true). + // 可见性 + visible(true). + // 层级 + zIndex(2)); + // 设置圆的填充色为红色 + circle.setFillColor(0xFF00ff00); + + // 移除圆 + // circle.remove(); + //中心点的圆 + Geometry geometry = GeometryTools.createGeometry(mapCenterPoint); + ArrayList latLngs = new ArrayList<>(); + for (int i = 0; i < items.size(); i++) { + LatLng position = items.get(i).getPosition(); + latLngs.add(position); + } + // 多 点 + MultiPoint multiPoint = GeometryTools.createMultiPoint(latLngs); + // 点与多点直接形成的交叉点 + Geometry intersection = geometry.intersection(multiPoint); + + + String geometryType = intersection.getGeometryType(); + Log.d("ddddd", "initNewMarker: " + geometryType); + + + } + + private void initCluster() { + // 实例化点聚合管理者 + clusterItemClusterManager = new ClusterManager<>(this, tencentMap); + + //默认聚合策略,调用是不必添加,如果需要其他聚合策略可以按以下代码修改 + NonHierarchicalDistanceBasedAlgorithm hierarchicalDistanceBasedAlgorithm = new NonHierarchicalDistanceBasedAlgorithm<>(this); + //设置点聚合生效距离,以dp为代码 + hierarchicalDistanceBasedAlgorithm.setMaxDistanceAtZoom(35); + //设置策略 + clusterItemClusterManager.setAlgorithm(hierarchicalDistanceBasedAlgorithm); + //设置聚合渲染器,默认使用的是DefaultClusterRenderer,可以不调用下列代码 + DefaultClusterRenderer markerClusterItemDefaultClusterRenderer = new DefaultClusterRenderer<>(this, tencentMap, clusterItemClusterManager); + //设置最小聚合数量,默认为4.这里设置为2,即有两个以上不包括2个marker 才会聚合 + markerClusterItemDefaultClusterRenderer.setMinClusterSize(2); + + //定义聚合的分段,当超过五个不足10个的时候,显示5+ ,其他分段同理 + markerClusterItemDefaultClusterRenderer.setBuckets(new int[]{5, 10, 15, 20, 25, 50, 100, 200}); + clusterItemClusterManager.setRenderer(markerClusterItemDefaultClusterRenderer); + //添加聚合 + + items = new ArrayList<>(); + items.add(new MarkerClusterItem(39.984059, 116.307621)); + items.add(new MarkerClusterItem(39.981954, 116.304703)); + items.add(new MarkerClusterItem(39.984355, 116.312256)); + items.add(new MarkerClusterItem(39.980442, 116.315346)); + items.add(new MarkerClusterItem(39.981527, 116.308994)); + items.add(new MarkerClusterItem(39.979751, 116.310539)); + items.add(new MarkerClusterItem(39.977252, 116.305776)); + items.add(new MarkerClusterItem(39.984026, 116.316419)); + items.add(new MarkerClusterItem(39.976956, 116.314874)); + items.add(new MarkerClusterItem(39.978501, 116.311827)); + items.add(new MarkerClusterItem(39.980277, 116.312814)); + items.add(new MarkerClusterItem(39.980236, 116.369022)); + items.add(new MarkerClusterItem(39.978838, 116.368486)); + items.add(new MarkerClusterItem(39.977161, 116.367488)); + items.add(new MarkerClusterItem(39.915398, 116.396713)); + items.add(new MarkerClusterItem(39.937645, 116.455421)); + items.add(new MarkerClusterItem(39.896304, 116.321182)); + items.add(new MarkerClusterItem(31.254487, 121.452827)); + items.add(new MarkerClusterItem(31.225133, 121.485443)); + items.add(new MarkerClusterItem(31.216912, 121.442528)); + items.add(new MarkerClusterItem(31.251552, 121.500893)); + items.add(new MarkerClusterItem(31.249204, 121.455917)); + items.add(new MarkerClusterItem(22.546885, 114.042892)); + items.add(new MarkerClusterItem(22.538086, 113.999805)); + items.add(new MarkerClusterItem(22.534756, 114.082031)); + clusterItemClusterManager.addItems(items); + + tencentMap.setOnCameraChangeListener(clusterItemClusterManager); + tencentMap.setOnCameraChangeListener(new TencentMap.OnCameraChangeListener() { + @Override + public void onCameraChange(CameraPosition cameraPosition) { + clusterItemClusterManager.cluster(); + + } + + @Override + public void onCameraChangeFinished(CameraPosition cameraPosition) { + } + }); + + } + + + /** + * 设置定位图标样式 + */ + private void setLocMarkerStyle(int style) { + tencentMap.setLocationSource(new MyTecentLocationSource(this)); + tencentMap.setMyLocationEnabled(true); + + MyLocationStyle locationStyle = new MyLocationStyle(); + locationStyle = locationStyle.myLocationType(style); + //创建图标 + BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap()); + locationStyle.icon(bitmapDescriptor); + //设置定位圆形区域的边框宽度; + locationStyle.fillColor(getResources().getColor(android.R.color.transparent)); + locationStyle.strokeWidth(1); + tencentMap.setMyLocationStyle(locationStyle); + } + + private Bitmap getBitMap() { + Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.location); + int width = bitmap.getWidth(); + int height = bitmap.getHeight(); + int newWidth = 55; + int newHeight = 55; + float widthScale = ((float) newWidth) / width; + float heightScale = ((float) newHeight) / height; + Matrix matrix = new Matrix(); + matrix.postScale(widthScale, heightScale); + bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); + return bitmap; + } + + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onEventMessageMainThread(Message msg) { + if (msg.what == Constant.EVENT_WHAT_LOCATION_CHANGE) { // 用户位置更新 + if (tencentMap != null) { + TencentLocation tencentLocation = (TencentLocation) msg.obj; + CameraUpdate cameraSigma = + CameraUpdateFactory.newCameraPosition(new CameraPosition( + new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()), //中心点坐标,地图目标经纬度 + tencentMap.getCameraPosition().zoom, //目标缩放级别 + 0, //目标倾斜角 + tencentLocation.getBearing())); //目标旋转角 0~360° (正北方为0) + tencentMap.animateCamera(cameraSigma); + + + } + } + } } diff --git a/app/src/main/java/com/navinfo/outdoor/activity/UserActivity.java b/app/src/main/java/com/navinfo/outdoor/activity/UserActivity.java index 5d44bcf..1eaec3d 100644 --- a/app/src/main/java/com/navinfo/outdoor/activity/UserActivity.java +++ b/app/src/main/java/com/navinfo/outdoor/activity/UserActivity.java @@ -48,19 +48,10 @@ public class UserActivity extends BaseActivity implements View.OnClickListener { private ArrayList> options2Items = new ArrayList<>(); private ArrayList>> options3Items = new ArrayList<>(); private ArrayList>> cityItems = new ArrayList<>(); - private Button btnGathering, btnAttestation; - private ImageView ivUser; private TextView region; private EditText etPhone, etQq, etMailbox; - private Button userSave; - private LinearLayout llRegion; - private String userqq; - private String userphone; - private String usermailbox; private String region_id; - private SharedPreferences navInfo; private SharedPreferences.Editor navInfoEditor; - private Button btnWeChat; @Override @@ -79,17 +70,17 @@ public class UserActivity extends BaseActivity implements View.OnClickListener { protected void initView() { super.initView(); initJsonData(); - navInfo = getSharedPreferences(Constant.SHARED_PREFERENCES, Context.MODE_PRIVATE); + SharedPreferences navInfo = getSharedPreferences(Constant.SHARED_PREFERENCES, Context.MODE_PRIVATE); navInfoEditor = navInfo.edit(); - ivUser = findViewById(R.id.iv_user); + ImageView ivUser = findViewById(R.id.iv_user); ivUser.setOnClickListener(this); - btnAttestation = findViewById(R.id.btn_attestations); + Button btnAttestation = findViewById(R.id.btn_attestations); btnAttestation.setOnClickListener(this); - btnGathering = findViewById(R.id.btn_gathering); + Button btnGathering = findViewById(R.id.btn_gathering); btnGathering.setOnClickListener(this); region = findViewById(R.id.region); region.setOnClickListener(this); - llRegion = findViewById(R.id.ll_region); + LinearLayout llRegion = findViewById(R.id.ll_region); llRegion.setOnClickListener(this); etPhone = findViewById(R.id.et_phone); etPhone.setOnClickListener(this); @@ -97,9 +88,9 @@ public class UserActivity extends BaseActivity implements View.OnClickListener { etQq.setOnClickListener(this); etMailbox = findViewById(R.id.edit_mailbox); etMailbox.setOnClickListener(this); - userSave = findViewById(R.id.btn_save); + Button userSave = findViewById(R.id.btn_save); userSave.setOnClickListener(this); - btnWeChat = findViewById(R.id.btn_weChat_binding); + Button btnWeChat = findViewById(R.id.btn_weChat_binding); btnWeChat.setOnClickListener(this); if (Constant.MOBILE!=null){ etPhone.setText(Constant.MOBILE); @@ -162,9 +153,9 @@ public class UserActivity extends BaseActivity implements View.OnClickListener { Toast.makeText(this, "请先绑定银行卡", Toast.LENGTH_SHORT).show(); } - userphone = etPhone.getText().toString().trim(); - userqq = etQq.getText().toString().trim(); - usermailbox = etMailbox.getText().toString().trim(); + String userphone = etPhone.getText().toString().trim(); + String userqq = etQq.getText().toString().trim(); + String usermailbox = etMailbox.getText().toString().trim(); HttpParams httpParams = new HttpParams(); httpParams.put("pid",Constant.USHERED); long time = System.currentTimeMillis(); @@ -185,21 +176,21 @@ public class UserActivity extends BaseActivity implements View.OnClickListener { Toast.makeText(this, "手机号输入错误", Toast.LENGTH_SHORT).show(); return; }else { - httpParams.put("mobile",userphone); + httpParams.put("mobile", userphone); } if (!userqq.equals("")) { if (!isQQNum_matcher) { Toast.makeText(this, "QQ号输入错误", Toast.LENGTH_SHORT).show(); return; }else { - httpParams.put("qq",userqq); + httpParams.put("qq", userqq); } } if (!usermailbox.equals("")){ if (!isEmail_matcher) { Toast.makeText(this, "邮箱格式错误", Toast.LENGTH_SHORT).show(); }else { - httpParams.put("mail",usermailbox); //邮箱 + httpParams.put("mail", usermailbox); //邮箱 } return; } diff --git a/app/src/main/java/com/navinfo/outdoor/util/MarkerClusterItem.java b/app/src/main/java/com/navinfo/outdoor/util/MarkerClusterItem.java new file mode 100644 index 0000000..50d1d1d --- /dev/null +++ b/app/src/main/java/com/navinfo/outdoor/util/MarkerClusterItem.java @@ -0,0 +1,16 @@ +package com.navinfo.outdoor.util; + +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +import com.tencent.tencentmap.mapsdk.vector.utils.clustering.ClusterItem; + +public class MarkerClusterItem implements ClusterItem { + private final LatLng mLatLng; + @Override + public LatLng getPosition() { + return mLatLng; + } + + public MarkerClusterItem(double al,double lon) { + this.mLatLng = new LatLng(al,lon); + } +} diff --git a/app/src/main/java/com/navinfo/outdoor/util/PoiSaveUtils.java b/app/src/main/java/com/navinfo/outdoor/util/PoiSaveUtils.java index eea8cf8..8e10250 100644 --- a/app/src/main/java/com/navinfo/outdoor/util/PoiSaveUtils.java +++ b/app/src/main/java/com/navinfo/outdoor/util/PoiSaveUtils.java @@ -38,8 +38,8 @@ public class PoiSaveUtils { private Activity mContext; private Gson gson; private static PoiSaveUtils instance; - private int anInt = 0; - private int bInt = 0; + private int anInt=0; + private int bInt=0; public static PoiSaveUtils getInstance(Activity mContext) { if (instance == null) { @@ -70,12 +70,15 @@ public class PoiSaveUtils { if (saveChargingPileByChargingStation(poiEntity)) { if (savePoiNet(poiEntity) == 200) { // 网络保存成功 // 开始上传流程 - if (saveChargingPileUploadChargingStation(poiEntity)) { + if (saveChargingPileUploadChargingStation(poiEntity)){ uploadPoiNet(poiEntity); } } } - }else {//其他类型 + } else if (poiEntity.getType() == 6) {//面状任务 + + + } else {//其他类型 if (savePoiNet(poiEntity) == 200) { // 网络保存成功 //走上传流程: uploadPoiNet(poiEntity); @@ -87,7 +90,7 @@ public class PoiSaveUtils { public void run() { Message obtain = Message.obtain(); obtain.what = Constant.EVENT_STAY_REFRESH; - obtain.obj = "提交成功" + anInt + ",提交失败" + bInt; + obtain.obj = "提交成功"+anInt+",提交失败"+bInt; EventBus.getDefault().post(obtain); } }); @@ -182,8 +185,10 @@ public class PoiSaveUtils { if (execute.code() != 200) { return execute.code(); } - assert execute.body() != null; String bodyStr = execute.body().string(); + if (bodyStr == null) { + return -1; + } PoiSaveBean poiSaveBean = gson.fromJson(bodyStr, PoiSaveBean.class); if (poiSaveBean.getCode() == 200) { poiEntity.setTaskStatus(3); @@ -255,12 +260,8 @@ public class PoiSaveUtils { } } } - List videoFileList=null; - if (poiEntity.getRecord_way()==1){//,录像,2,连拍 - videoFileList = AWMp4ParserHelper.getInstance().getVideoFileListByUUID(poiEntity.getId()); - }else if (poiEntity.getRecord_way()==2){ - videoFileList = AWMp4ParserHelper.getInstance().getJPGFileListByUUID(poiEntity.getId()); - } + + List videoFileList = AWMp4ParserHelper.getInstance().getVideoFileListByUUID(poiEntity.getId()); if (videoFileList != null && !videoFileList.isEmpty()) { List txtFileList = new ArrayList<>(); for (File videoFile : videoFileList) { @@ -270,7 +271,9 @@ public class PoiSaveUtils { videoFileList.addAll(txtFileList); File fileZip = new File(Constant.PICTURE_FOLDER, "files" + ".zip"); ZipUtil.zipFiles(videoFileList, fileZip, null); - photoFile.add(fileZip); + if (fileZip!=null){ + photoFile.add(fileZip); + } } String url = null; //1 "POI"2 "充电站"3 "POI录像"4 "道路录像"5 "其他"6 "面状任务" @@ -300,8 +303,10 @@ public class PoiSaveUtils { if (execute.code() != 200) { return; } - assert execute.body() != null; String bodyStr = execute.body().string(); + if (bodyStr == null) { + return; + } Gson gson = new Gson(); OtherUploadPicBean otherUploadPicBean = gson.fromJson(bodyStr, OtherUploadPicBean.class); if (otherUploadPicBean.getCode() == 200) { @@ -311,6 +316,7 @@ public class PoiSaveUtils { } else { Log.d("TAGss", "uploadPoiNet: 失败"); bInt++; + return; } } catch (IOException e) { e.printStackTrace(); @@ -392,16 +398,20 @@ public class PoiSaveUtils { if (execute.code() != 200) { return execute.code(); } - assert execute.body() != null; String responseBodyStr = execute.body().string(); - Gson gson = new Gson(); - ChargingPileSaveBean chargingPileSaveBean = gson.fromJson(responseBodyStr, ChargingPileSaveBean.class); - if (chargingPileSaveBean.getCode() != 200) { - return chargingPileSaveBean.getCode(); + if (responseBodyStr == null) { + return -1; + } + if (responseBodyStr != null) { + Gson gson = new Gson(); + ChargingPileSaveBean chargingPileSaveBean = gson.fromJson(responseBodyStr, ChargingPileSaveBean.class); + if (chargingPileSaveBean.getCode() != 200) { + return chargingPileSaveBean.getCode(); + } + Log.d("TAGss", "saveChargingPile2NetWork" + 200); + chargingPileEntity.setBodyId(chargingPileSaveBean.getBody()); + InsertAndUpdateUtils.getInstance().insertOrUpdateChargingPile(mContext, chargingPileEntity); // 更新当前充电桩的bodyId } - Log.d("TAGss", "saveChargingPile2NetWork" + 200); - chargingPileEntity.setBodyId(chargingPileSaveBean.getBody()); - InsertAndUpdateUtils.getInstance().insertOrUpdateChargingPile(mContext, chargingPileEntity); // 更新当前充电桩的bodyId } catch (IOException e) { e.printStackTrace(); } @@ -470,13 +480,17 @@ public class PoiSaveUtils { if (execute.code() != 200) { return execute.code(); } - assert execute.body() != null; String pileUpLoadResultStr = execute.body().string(); - Gson gson = new Gson(); - PoiUploadBean uploadBeanResult = gson.fromJson(pileUpLoadResultStr, PoiUploadBean.class); - if (uploadBeanResult.getCode() == 200) { - Log.d("TAGss", "chargingPileUploadNetWork" + 200); - PoiDatabase.getInstance(mContext).getChargingPileDao().deleteChargingPileEntity(chargingPileEntity); + if (pileUpLoadResultStr == null) { + return -1; + } + if (pileUpLoadResultStr != null) { + Gson gson = new Gson(); + PoiUploadBean uploadBeanResult = gson.fromJson(pileUpLoadResultStr, PoiUploadBean.class); + if (uploadBeanResult.getCode() == 200) { + Log.d("TAGss", "chargingPileUploadNetWork" + 200); + PoiDatabase.getInstance(mContext).getChargingPileDao().deleteChargingPileEntity(chargingPileEntity); + } } } catch (IOException e) { e.printStackTrace(); diff --git a/app/src/main/res/layout/activity_test.xml b/app/src/main/res/layout/activity_test.xml new file mode 100644 index 0000000..213c17c --- /dev/null +++ b/app/src/main/res/layout/activity_test.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file