From 57119a84e4ad007f32d0e1747c9e3c530d9e1894 Mon Sep 17 00:00:00 2001 From: md Date: Thu, 5 Aug 2021 10:45:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9poiVideo=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../outdoor/fragment/GatherGetFragment.java | 5 +- .../outdoor/fragment/GatheringFragment.java | 11 +- .../outdoor/fragment/PoiVideoFragment.java | 171 +++++++++++------- .../outdoor/fragment/RoadFragment.java | 55 +++++- .../fragment/UserAttestationFragment.java | 10 +- app/src/main/res/layout/fragment_road.xml | 2 +- 6 files changed, 167 insertions(+), 87 deletions(-) diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/GatherGetFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/GatherGetFragment.java index 1bab237..1ed5f4a 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/GatherGetFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/GatherGetFragment.java @@ -357,9 +357,10 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe } InsertAndUpdateUtils.getInstance().insertOrUpdateChargingPile(getActivity(), chargingPileEntityList); } + //获取当前位置的marker - senMessageMarker(chargingStationEntity.getType(), chargingStationEntity.getY(), chargingStationEntity.getX()); - InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(),chargingStationEntity); +// senMessageMarker(chargingStationEntity.getType(), chargingStationEntity.getY(), chargingStationEntity.getX()); +// InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(),chargingStationEntity); getActivity().runOnUiThread(new Runnable() { @Override public void run() { diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/GatheringFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/GatheringFragment.java index 18eb7e0..847a0d6 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/GatheringFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/GatheringFragment.java @@ -154,13 +154,14 @@ public class GatheringFragment extends BaseFragment implements View.OnClickListe private void gatheringNetWork() { showLoadingDialog(); - gatheringList = new ArrayList<>(); - File gatheringFile = new File(gatheringPath); - if (!gatheringFile.exists()) { - Toast.makeText(getContext(), "身份证照片不能为空", Toast.LENGTH_SHORT).show(); + if (ivGathering.getTag()==null){ + Toast.makeText(getContext(), "银行卡照片不能为空", Toast.LENGTH_SHORT).show(); return; } - gatheringList.add(gatheringFile); + gatheringList = new ArrayList<>(); + String ivGatheringTag = (String) ivGathering.getTag(); + gatheringList.add(new File(ivGatheringTag)); + String etBankAccount = etBankNum.getText().toString().trim(); if (etBankAccount == null || etBankAccount.equals("")) { Toast.makeText(getContext(), "银行卡号不能为空", Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java index 029ebb7..653ae37 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java @@ -28,6 +28,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import com.github.lazylibrary.util.FileUtils; +import com.github.lazylibrary.util.StringUtils; import com.github.lazylibrary.util.ZipUtil; import com.google.gson.Gson; import com.hjq.permissions.OnPermissionCallback; @@ -162,13 +163,14 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick fmPoiVideoPic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (v.getTag() == null) { + if (v.getTag() == null || ((List) v.getTag()).size() == 0) { Toast.makeText(getActivity(), "还没有拍摄视频!", Toast.LENGTH_SHORT).show(); return; } - File videoFile = (File) v.getTag(); + + File finalFile = AWMp4ParserHelper.getInstance().obtainMp4FilePath(showPoiEntity.getId(), fmPoiVideoPic.getTag()); Intent intent = new Intent(getContext(), PictureActivity.class); - intent.putExtra(Constant.INTENT_VIDEO_PATH, videoFile.getAbsolutePath()); + intent.putExtra(Constant.INTENT_VIDEO_PATH, finalFile.getAbsolutePath()); startActivityForResult(intent, 0x101); } }); @@ -210,15 +212,27 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick showPictureType(work_type); String describe = showPoiEntity.getMemo();//任务描述 if (describe != null && !describe.equals("")) { - etDesc.setText(describe+""); + etDesc.setText(describe + ""); } - String photo = showPoiEntity.getPhoto(); - if (photo != null) { - File videoFile = new File(photo); - if (videoFile.exists()) { - // 使用glide加载视频的第一帧 - AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivPoiVideoPicture, 500); - fmPoiVideoPic.setTag(videoFile); + String photoList = showPoiEntity.getPhoto(); + if (!StringUtils.isEmpty(photoList)) { + String[] photos = photoList.split(","); + List videoFileList = new ArrayList<>(); + boolean isImageLoad = false; + if (photos != null && photos.length > 0) { + for (int i = 0; i < photos.length; i++) { + String photo = photos[i]; + if (!StringUtils.isEmpty(photo)) { + File videoFile = new File(photo); + videoFileList.add(new File(photo)); + if (videoFile.exists() && !isImageLoad) { + // 使用glide加载视频的第一帧 + AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivPoiVideoPicture, 500); + isImageLoad = true; + } + } + } + fmPoiVideoPic.setTag(videoFileList); } } } @@ -272,36 +286,39 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick break; case R.id.tv_pictures: // 根据用户点击的时间为视频名称赋值 - DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); - String videoFormatName = formatter.format(new Date()); - Intent intent = new Intent(getContext(), PictureActivity.class); - intent.putExtra(Constant.INTENT_VIDEO_PATH, Constant.PICTURE_FOLDER + "/" + videoFormatName + ".mp4"); - startActivityForResult(intent, 0x101); +// DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); +// String videoFormatName = formatter.format(new Date()); + Intent intent = new Intent(getContext(), PictureActivity.class); + File finalFile = AWMp4ParserHelper.getInstance().obtainMp4FilePath(showPoiEntity.getId(), fmPoiVideoPic.getTag()); + intent.putExtra(Constant.INTENT_VIDEO_PATH, finalFile.getAbsolutePath()); + startActivityForResult(intent, 0x101); break; case R.id.btn_poi_video_upload: showLoadingDialog(); - ArrayList videoFileList = new ArrayList<>(); + ArrayList fileList = new ArrayList<>(); if (fmPoiVideoPic.getTag() != null) { - File videoFile = (File) fmPoiVideoPic.getTag(); - videoFileList.add(videoFile); - File file = new File(videoFile.getPath()+".txt"); - videoFileList.add(file); + List videoFileList = (List) fmPoiVideoPic.getTag(); + for (File videoFile : videoFileList) { + fileList.add(videoFile); + File file = new File(videoFile.getPath() + ".txt"); + fileList.add(file); + } fileZip = new File(Constant.PICTURE_FOLDER, "files" + ".zip"); new Thread(new Runnable() { @Override public void run() { - ZipUtil.zipFiles(videoFileList, fileZip, null); + ZipUtil.zipFiles(fileList, fileZip, null); PoiEntity poiDaoPoiEntity = poiDao.getPoiEntity(showPoiEntity.getId()); if (poiDaoPoiEntity == null || poiDaoPoiEntity.getTaskStatus() == 1 || poiDaoPoiEntity.getTaskStatus() == 2 || poiDaoPoiEntity.getTaskStatus() == 0) { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - dismissLoadingDialog(); - initPoiSaveLocal(true); - } - }); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + dismissLoadingDialog(); + initPoiSaveLocal(true); + } + }); } else { getActivity().runOnUiThread(new Runnable() { @Override @@ -314,7 +331,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick } }).start(); - }else { + } else { dismissLoadingDialog(); Toast.makeText(getContext(), "请录像", Toast.LENGTH_SHORT).show(); return; @@ -359,13 +376,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick } }); } - int pictureType = getPictureType(); - if (pictureType == -1) { - Toast.makeText(getContext(), "请选择拍照方式", Toast.LENGTH_SHORT).show(); - return; - } else { - poiEntity.setWork_type(pictureType); - } + String desc = etDesc.getText().toString().trim(); if (desc != null && !desc.equals("")) { poiEntity.setMemo(desc); @@ -375,30 +386,17 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick poiEntity.setTaskId(showPoiEntity.getTaskId()); } } - File videoFile = (File) fmPoiVideoPic.getTag(); - if (videoFile == null ) { + if (fmPoiVideoPic.getTag() == null || ((List) fmPoiVideoPic.getTag()).isEmpty()) { Toast.makeText(getActivity(), "请录像", Toast.LENGTH_SHORT).show(); return; } else { - - String path = videoFile.getPath() + ".txt"; - poiEntity.setPhoto(videoFile.getAbsolutePath()); - List strings = FileUtils.readFileToList(path, "utf-8"); - ArrayList latLngs = new ArrayList<>(); - for (int i = 0; i < strings.size(); i++) { - String[] split = strings.get(i).split(","); - LatLng latLng = new LatLng(); - latLng.setLatitude(Double.valueOf(split[2])); - latLng.setLongitude(Double.valueOf(split[3])); - latLngs.add(latLng); - } - if (strings.size() == 1) { - LatLng latLng = latLngs.get(0); - latLngs.add(latLng); - } - String lineString = GeometryTools.getLineString(latLngs); + String lineString = GeometryTools.getLineString(getLineString()); + String filePathString = getPhotoStrFromTag(); Log.d("TAG", "onGranted: " + lineString); - poiEntity.setGeoWkt(lineString); + poiEntity.setPhoto(filePathString); + if (lineString != null) { + poiEntity.setGeoWkt(lineString); + } } @@ -440,6 +438,44 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick }); } + private String getPhotoStrFromTag() { + List videoFileList = (List) fmPoiVideoPic.getTag(); + + StringBuilder filePathStringBuilder = new StringBuilder(""); + for (int m = 0; m < videoFileList.size(); m++) { + File videoFile = videoFileList.get(m); + filePathStringBuilder.append(videoFile.getAbsolutePath()); + if (m != videoFileList.size() - 1) { + filePathStringBuilder.append(","); + } + } + return filePathStringBuilder.toString(); + } + + private List getLineString() { + List videoFileList = (List) fmPoiVideoPic.getTag(); + + List latLngs = new ArrayList<>(); + StringBuilder filePathStringBuilder = new StringBuilder(""); + for (int m = 0; m < videoFileList.size(); m++) { + File videoFile = videoFileList.get(m); + + String path = videoFile.getPath() + ".txt"; + List strings = FileUtils.readFileToList(path, "utf-8"); + for (int i = 0; i < strings.size(); i++) { + String[] split = strings.get(i).split(","); + LatLng latLng = new LatLng(); + latLng.setLatitude(Double.valueOf(split[2])); + latLng.setLongitude(Double.valueOf(split[3])); + latLngs.add(latLng); + } + if (strings.size() == 1) { + LatLng latLng = latLngs.get(0); + latLngs.add(latLng); + } + } + return latLngs; + } private void poiVideoUpload(int poiVideoBody, File fileZip) { if (poiVideoBody == 0) { @@ -508,7 +544,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick @Override public void onSuccess(PoiVideoBean poiVideoBean, int id) { dismissLoadingDialog(); - if (poiVideoBean.getCode()==200){ + if (poiVideoBean.getCode() == 200) { Integer poiVideoBody = poiVideoBean.getBody(); if (poiVideoBody != null && poiVideoBody != 0) { poiEntity.setBodyId(poiVideoBody); @@ -531,10 +567,10 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick } }).start(); } else { - Toast.makeText(getActivity(), ""+poiVideoBean.getMessage(), Toast.LENGTH_SHORT).show(); + Toast.makeText(getActivity(), "" + poiVideoBean.getMessage(), Toast.LENGTH_SHORT).show(); } - }else { - Toast.makeText(getActivity(), ""+poiVideoBean.getMessage(), Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(getActivity(), "" + poiVideoBean.getMessage(), Toast.LENGTH_SHORT).show(); } @@ -556,11 +592,15 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick if (requestCode == 0x101 && resultCode == 0x101) { if (data != null && data.hasExtra(Constant.INTENT_VIDEO_PATH)) { - videoPath = data.getStringExtra(Constant.INTENT_VIDEO_PATH); + String videoPath = data.getStringExtra(Constant.INTENT_VIDEO_PATH); File videoFile = new File(videoPath); if (videoFile.exists()) { AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivPoiVideoPicture, 500); - fmPoiVideoPic.setTag(videoFile); + if (fmPoiVideoPic.getTag() == null) { + fmPoiVideoPic.setTag(new ArrayList<>()); + } + List fileList = (List) fmPoiVideoPic.getTag(); + fileList.add(videoFile); } } } @@ -606,6 +646,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick poiEntity.setType(3); poiEntity.setTaskStatus(2); poiEntity.setIsLocalData(1); + poiEntity.setPhoto(getPhotoStrFromTag()); String newPoiEntity = new Gson().toJson(poiEntity); //以键值对的形式添加新值。 edit.putString("poiEntity", newPoiEntity); @@ -655,8 +696,8 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick @Override public void run() { PoiEntity poiDaoPoiEntity = poiDao.getPoiEntity(showPoiEntity.getId()); - if (poiDaoPoiEntity!=null) { - if (poiDaoPoiEntity.getTaskStatus()==5){ + if (poiDaoPoiEntity != null) { + if (poiDaoPoiEntity.getTaskStatus() == 5) { poiDao.deletePoiEntity(poiDaoPoiEntity); } } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java index 2018613..484fa60 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java @@ -25,6 +25,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import com.github.lazylibrary.util.FileUtils; import com.github.lazylibrary.util.StringUtils; @@ -33,6 +34,10 @@ import com.google.gson.Gson; import com.hjq.permissions.OnPermissionCallback; import com.hjq.permissions.Permission; import com.hjq.permissions.XXPermissions; +import com.kongzue.dialog.interfaces.OnDialogButtonClickListener; +import com.kongzue.dialog.util.BaseDialog; +import com.kongzue.dialog.util.DialogSettings; +import com.kongzue.dialog.v3.MessageDialog; import com.lzy.okgo.OkGo; import com.lzy.okgo.model.HttpParams; import com.lzy.okgo.model.Response; @@ -169,6 +174,28 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList startActivityForResult(intent, 0x101); } }); + fmRoadPic.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getContext(), "提示", "对否删除", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + File videoFile = (File) fmRoadPic.getTag(); + if (videoFile != null) { + videoFile.delete(); + //获取文件名 + String csvFileName = videoFile.getName() + ".txt"; + File cavFile = new File(videoFile.getParent(), csvFileName); + cavFile.delete(); + ivRoadPicture.setImageDrawable(null); + } + return false; + } + }); + return false; + } + }); //数据展示 initShowPoi(); //禁用可操作性控件 @@ -581,12 +608,29 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList String videoPath = data.getStringExtra(Constant.INTENT_VIDEO_PATH); File videoFile = new File(videoPath); if (videoFile.exists()) { - AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivRoadPicture, 500); - if (fmRoadPic.getTag() == null) { - fmRoadPic.setTag(new ArrayList<>()); + Bitmap bitmap = AWMp4ParserHelper.getInstance().getLocalVideoBitmap(videoPath); + int height = bitmap.getHeight(); + int width = bitmap.getWidth(); + if (height>width){ + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新录像,要求横屏录像", "确定").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + Intent intentPanorama = new Intent(getActivity(),PictureActivity.class); + startActivityForResult(intentPanorama, 0x101); + return false; + } + }); + return; + }else { + AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivRoadPicture, 500); + if (fmRoadPic.getTag() == null) { + fmRoadPic.setTag(new ArrayList<>()); + } + List fileList = (List) fmRoadPic.getTag(); + fileList.add(videoFile); } - List fileList = (List) fmRoadPic.getTag(); - fileList.add(videoFile); + } } } @@ -638,7 +682,6 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList poiEntity.setType(4); poiEntity.setTaskStatus(2); poiEntity.setIsLocalData(1); - poiEntity.setPhoto(getPhotoStrFromTag()); String newPoiEntity = new Gson().toJson(poiEntity); //以键值对的形式添加新值。 edit.putString("poiEntity", newPoiEntity); diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/UserAttestationFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/UserAttestationFragment.java index 8b39156..19aab9d 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/UserAttestationFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/UserAttestationFragment.java @@ -118,14 +118,6 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic startActivityForResult(ivAttestation3, 300); break; case R.id.btn_attestation: - /** - * static boolean ChineseNameTest(String name) { - * if (!name.matches("[\u4e00-\u9fa5]{2,4}")) { - * System.out.println("只能输入2到4个汉字"); - * return false; - * }else return true; - * } - */ if (etAttestationName.getText().toString() == null || etAttestationName.getText().toString().equals("")) { Toast.makeText(getContext(), "姓名不能为空,请输入姓名", Toast.LENGTH_SHORT).show(); return; @@ -216,6 +208,7 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic Log.d("TAG", "onSuccess: " + response.toString() + "sssssssssssss"); if (response.body().equals("0")) { + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; MessageDialog.show((AppCompatActivity) getActivity(), "提示", "不通过", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(BaseDialog baseDialog, View v) { @@ -226,6 +219,7 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic } }); } else { + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; MessageDialog.show((AppCompatActivity) getActivity(), "提示", "通过", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(BaseDialog baseDialog, View v) { diff --git a/app/src/main/res/layout/fragment_road.xml b/app/src/main/res/layout/fragment_road.xml index ca30a87..9909329 100644 --- a/app/src/main/res/layout/fragment_road.xml +++ b/app/src/main/res/layout/fragment_road.xml @@ -150,7 +150,7 @@ android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:gravity="center" - android:text="拍照" + android:text="录像" android:textColor="@color/white" android:textSize="15sp" />