增加poi录像的连拍

This commit is contained in:
wds 2021-08-20 16:59:14 +08:00
parent 409f2a3879
commit 7d4355a648
11 changed files with 292 additions and 189 deletions

View File

@ -28,7 +28,9 @@ import com.github.lazylibrary.util.FileUtils;
import com.navinfo.outdoor.R;
import com.navinfo.outdoor.api.Constant;
import com.navinfo.outdoor.base.BaseActivity;
import com.navinfo.outdoor.room.PoiEntity;
import com.navinfo.outdoor.util.AWMp4ParserHelper;
import com.navinfo.outdoor.util.GeometryTools;
import com.navinfo.outdoor.util.MyTecentLocationSource;
import com.otaliastudios.cameraview.CameraException;
import com.otaliastudios.cameraview.CameraListener;
@ -48,11 +50,17 @@ import com.tencent.tencentmap.mapsdk.maps.MapView;
import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.TextureMapView;
import com.tencent.tencentmap.mapsdk.maps.UiSettings;
import com.tencent.tencentmap.mapsdk.maps.interfaces.Removable;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.Marker;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
import com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle;
import com.tencent.tencentmap.mapsdk.maps.model.Polyline;
import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions;
import com.vividsolutions.jts.geom.Geometry;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@ -85,34 +93,45 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
private MyLocationStyle locationStyle;
private TextureMapView ivMap;
private Button stopPicture;
private CsvTimerTask timerTask;
private List<Removable> removables;
private PoiEntity poiEntity;
private Polyline polyline;
// private String finalVideoPath; // 摄像后最终保存的文件名
private String finalVideoPath; // 摄像后最终保存的文件名
// private File tmpFile; // 合并文件的临时文件路径
//private Timer timer;
private Timer timer;
// private CsvTimerTask timerTask; // 执行定时写入csv文件的task
// private DateFormat formatter;
// private final long period = 1; // 记录csv文件的间隔时间单位为秒
private final long period = 2; // 记录csv文件的间隔时间单位为秒
private ViewGroup layerChange; // 切换地图和相机的父控件
// private boolean isFinishActivity = false; // 是否需要关闭当前activity
private CheckBox capturePicture;//拍照
private ArrayList<File> pictureList;
private Handler handler=new Handler(new Handler.Callback() {
private Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
if (msg.what==0&&listenerPicture){
File file= (File) msg.obj;
if (msg.what == 0 && listenerPicture) {
File file = (File) msg.obj;
pictureList.add(file);
if (camera.isTakingPicture()){
if (camera.isTakingPicture()) {
camera.destroy();
}else {
} else {
if (timerTask != null) {
timerTask.cancel();
}
camera.takePicture();
}
} else if (msg.what == 1) {
if (btnSwitch != null) {
btnSwitch.setEnabled(true);
}
}
return false;
}
});
private boolean listenerPicture=true;
private boolean listenerPicture = true;
@Override
@ -128,12 +147,17 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
super.initView();
/* if (getIntent()!=null) {
finalVideoPath = getIntent().getStringExtra(Constant.INTENT_VIDEO_PATH);
}*/
pictureList = new ArrayList<>();
removables = new ArrayList<>();//存储轨迹的marker
layerChange = findViewById(R.id.layer_change);
if (getIntent() != null) {
poiEntity = (PoiEntity) getIntent().getSerializableExtra("poiEntity");
finalVideoPath = getIntent().getStringExtra(Constant.INTENT_VIDEO_PATH);
}
//timer = new Timer();
timer = new Timer();
// this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
ivMap = (TextureMapView) findViewById(R.id.iv_map);
@ -151,7 +175,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) { // 开始采集设置按钮文字内容为结束采集
capturePicture.setText("暂停采集");
listenerPicture= true;
listenerPicture = true;
camera.takePicture();
} else {
listenerPicture = false;
@ -175,10 +199,10 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
SizeSelector dimensions = SizeSelectors.and(width, height); // Matches sizes bigger than 1000x2000.
// 获取屏幕信息
int[] density = DensityUtil.getDeviceInfo(this);
int x=1920, y=1440;
if (density!=null&&density.length>1) {
x = (density[0]>=density[1]?density[0]:density[1]);
y = (density[0]>=density[1]?density[1]:density[0]);
int x = 1920, y = 1440;
if (density != null && density.length > 1) {
x = (density[0] >= density[1] ? density[0] : density[1]);
y = (density[0] >= density[1] ? density[1] : density[0]);
}
SizeSelector ratio = SizeSelectors.aspectRatio(AspectRatio.of(x, y), 0); // Matches 1:1 sizes.
@ -188,7 +212,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
SizeSelectors.biggest() // If none is found, take the biggest
);
camera.setVideoSize(result);
camera.setVideoBitRate(1920*1440);
camera.setVideoBitRate(1920 * 1440);
// camera.setAudioBitRate();
//获取地图
@ -199,7 +223,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
uiSettings.setLogoScale(0.7f);
// uiSettings.setAllGesturesEnabled(false);
setLocMarkerStyle(); // 设置当前位置显示样式
initLine();
// camera.addFrameProcessor(new FrameProcessor() {
// @Override
// public void process(@NonNull Frame frame) {
@ -212,19 +236,23 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
@Override
public void onPictureTaken(@NonNull @NotNull PictureResult result) {
super.onPictureTaken(result);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HHmmss");
String format = formatter.format(calendar.getTime());
//文件
File file = new File(Constant.PICTURE_FOLDER, format + ".jpg");
File file = new File(finalVideoPath);
result.toFile(file, new FileCallback() {
@Override
public void onFileReady(@Nullable @org.jetbrains.annotations.Nullable File file) {
Message message = new Message();
message.what=0;
message.obj=file;
handler.sendMessageDelayed(message,2000);
message.what = 0;
message.obj = file;
handler.sendMessageDelayed(message, 2000);
File finalVideoFile = new File(finalVideoPath);
if (finalVideoFile.exists()&&listenerPicture) {
timerTask = new CsvTimerTask(new File(finalVideoPath + ".txt"));
timer.schedule(timerTask, 0, period * 1000);
int videoIndex = Integer.parseInt(finalVideoFile.getName().replace(".jpg", ""));
finalVideoPath = finalVideoFile.getParentFile().getAbsolutePath() + "/" + (videoIndex + 1) + ".jpg";
}
Toast.makeText(PicturesActivity.this, "保存成功:" + file.getPath(), Toast.LENGTH_SHORT).show();
}
});
@ -296,16 +324,15 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
* 获取当前视频的时间记录csv文件时使用
* *//*
long currentTime = AWMp4ParserHelper.getInstance().getVedioTotalTime(new File(finalVideoPath));
timerTask = new CsvTimerTask(new File(finalVideoPath+".txt"));
timerTask = new CsvTimerTask(new File(finalVideoPath + ".txt"));
// 开始采集每隔2秒实时记录位置信息视频时间以及设备时间
if (currentTime == 0) {
timer.schedule(timerTask, 0, period*1000);
timer.schedule(timerTask, 0, period * 1000);
} else {
timerTask.setCurrentVideoTime(currentTime/1000+1);
timer.schedule(timerTask, 1, period*1000);
timerTask.setCurrentVideoTime(currentTime / 1000 + 1);
timer.schedule(timerTask, 1, period * 1000);
}
*/
}
@Override
@ -323,8 +350,8 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
FrameLayout.LayoutParams layoutParamsMap = (FrameLayout.LayoutParams) ivMap.getLayoutParams();//相机的宽高
layoutParamsMap.height = dm.heightPixels/3;
layoutParamsMap.width = dm.widthPixels/3;
layoutParamsMap.height = dm.heightPixels / 3;
layoutParamsMap.width = dm.widthPixels / 3;
ivMap.setLayoutParams(layoutParamsMap);
}
@ -339,76 +366,64 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
}
}
private void initLine() {
String geo = poiEntity.getGeoWkt();
if (geo != null) {
Geometry geometry = GeometryTools.createGeometry(geo);
if (geometry.getGeometryType().equals("LineString")) {//线
BitmapDescriptor bitmapLine = null;
if (poiEntity.getType() == 3) {//poi录像
bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_arrows);
} else if (poiEntity.getType() == 4) {//道路录像
bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.road_arrows);
}
List<LatLng> latLineString = GeometryTools.getLatLngs(geo);
// 构造 PolylineOpitons
PolylineOptions polylineOptions = new PolylineOptions()
.addAll(latLineString)
// 折线设置圆形线头
.lineCap(true)
// 折线的颜色为绿色
.color(0xff00ff00)
// 折线宽度为5像素
.width(20)
.arrow(true)
.arrowSpacing(150)
.arrowTexture(bitmapLine);
// 绘制折线
polyline = tencentMap.addPolyline(polylineOptions);
polyline.setZIndex(2);
}
}
}
@Override
protected void initData() {
super.initData();
camera.setMode(Mode.PICTURE);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
// case R.id.capuretVideo:
// DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// Calendar calendar = Calendar.getInstance();
// calendar.setTimeInMillis(System.currentTimeMillis());
// String format = formatter.format(calendar.getTime());
// //文件
// File file = new File(Constant.PICTURE_FOLDER, format + ".mp4");
// cameraView.takeVideo(file, 15000);
// break;
case R.id.btn_stop_picture:
/* if (camera.isTakingPicture()) {
} else {
}*/
camera.destroy();
if (timerTask != null) {
timerTask.cancel();
}
Intent intent = new Intent();
intent.putExtra(Constant.INTENT_VIDEO_PATH,pictureList );
intent.putExtra(Constant.INTENT_PICTURES_PATH, pictureList);
setResult(0x102, intent);
finish();
break;
case R.id.btn_switch:
v.setEnabled(false);
handler.sendEmptyMessageDelayed(1, 2000); // 利用handler延迟发送更改状态信息
btnSwich();
break;
}
}
/**
* 开始采集
*/
private void startTakenVideo() {
if (camera.isTakingVideo()) {
Toast.makeText(this, "已经在拍摄中...", Toast.LENGTH_SHORT).show();
return;
}
DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
String formatVideoName = formatter.format(calendar.getTime());
//文件
File file = new File(Constant.PICTURE_FOLDER, formatVideoName + ".mp4");
if (file.exists()) {
try {
FileOutputStream fo = new FileOutputStream(file);
FileDescriptor fileDescriptor = fo.getFD();
camera.takeVideo(fileDescriptor);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else {
camera.takeVideo(file);
}
}
private void stopTakenVideo() {
if (camera.isTakingVideo()) {
camera.stopVideo();
}
}
private Bitmap getBitMap(int resourceId) {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);
int width = bitmap.getWidth();
@ -479,7 +494,6 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
}
@Override
protected void onResume() {
super.onResume();
@ -498,8 +512,18 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
@Override
protected void onDestroy() {
super.onDestroy();
stopTakenVideo();
// stopTakenVideo();
camera.destroy();
if (polyline != null) {
polyline.remove();
}
if (timerTask != null) {
timerTask.cancel();
}
for (int i = 0; i < removables.size(); i++) {
removables.get(i).remove();
}
removables.clear();
// timer.cancel();
if (EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().unregister(this);
@ -511,10 +535,10 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
public void onEventMessageMainThread(Message msg) {
switch (msg.what) {
case Constant.EVENT_WHAT_LOCATION_CHANGE: // 用户位置更新
if (tencentMap!=null) {
if (tencentMap != null) {
CameraUpdate cameraSigma =
CameraUpdateFactory.newCameraPosition(new CameraPosition(
new LatLng(Constant.currentLocation.getLatitude(),Constant.currentLocation.getLongitude()), //中心点坐标地图目标经纬度
new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()), //中心点坐标地图目标经纬度
16, //目标缩放级别
0, //目标倾斜角
0)); //目标旋转角 0~360° (正北方为0)
@ -548,14 +572,19 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
StringBuffer sb = new StringBuffer();
// sb.append(formatter.format(new Date())); // 记录当前时间
sb.append(",");
sb.append(currentVideoTime) ;// 记录视频时间
sb.append(currentVideoTime);// 记录视频时间
sb.append(",");
sb.append(Constant.currentLocation.getLatitude());
sb.append(",");
sb.append(Constant.currentLocation.getLongitude());
sb.append("\r\n");
LatLng latLng = new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude());
BitmapDescriptor pileDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.circle);
Marker marker = tencentMap.addMarker(new MarkerOptions(latLng).icon(pileDescriptor).alpha(0.9f)
.flat(true)
.clockwise(false));
removables.add(marker);
FileUtils.writeFile(csvFile.getAbsolutePath(), sb.toString(), true);
// currentVideoTime = currentVideoTime+period; //
}
}
}

View File

@ -94,25 +94,14 @@ public class StaySubmitAdapter extends RecyclerView.Adapter<StaySubmitAdapter.Vi
poiEntity.setChecked(!poiEntity.isChecked());
}
});
if (poiEntity.getIsLocalData() == 1){
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onClickItem!=null){
onClickItem.item(position,poiEntity);
if (onClickItem != null) {
onClickItem.item(position, poiEntity);
}
}
});
}else {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onClickItem!=null){
onClickItem.item(position,poiEntity);
}
}
});
}
}
@ -147,7 +136,7 @@ public class StaySubmitAdapter extends RecyclerView.Adapter<StaySubmitAdapter.Vi
}
};
public onClickItem onClickItem ;
public onClickItem onClickItem;
public void setOnClickItem(StaySubmitAdapter.onClickItem onClickItem) {
this.onClickItem = onClickItem;

View File

@ -165,6 +165,7 @@ public class Constant {
public static MapView treasureMap;
public static final String INTENT_VIDEO_PATH = "INTENT_VIDEO_PATH"; // 拍照界面指定的视频文件保存位置
public static final String INTENT_PICTURES_PATH = "INTENT_VIDEO_PATH"; // 拍照界面指定的视频文件保存位置
public static final String INTENT_VIDEO_ORATATION = "INTENT_VIDEO_ORATATION"; // 视频拍摄时屏幕方向 0-强制横屏 其他-任意
public static SlidingUpPanelLayout SLIDING_LAYOUT = null;//設置

View File

@ -1622,7 +1622,6 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
poiEntity.setExistence(existence);
poiEntity.setType(2);
poiEntity.setTaskStatus(2);
poiEntity.setIsLocalData(1);
return poiEntity;
}

View File

@ -325,7 +325,6 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe
}
chargingStationEntity.setType(Integer.valueOf(stationBean.getType()));
chargingStationEntity.setTaskStatus(statusId);
chargingStationEntity.setIsLocalData(1);
String encodeStr = stationBean.getGeo();
String geo = Geohash.getInstance().decode(encodeStr);
@ -688,7 +687,6 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe
poiListEntity.setType(Integer.valueOf(listBean.getType()));
poiListEntity.setIsExclusive(listBean.getIsExclusive());
poiListEntity.setTaskStatus(statusId);
poiListEntity.setIsLocalData(1);
String encodeStr = listBean.getGeo();
String geo = Geohash.getInstance().decode(encodeStr);
poiListEntity.setGeoWkt(geo);
@ -812,7 +810,6 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe
poiListEntity.setPrecision(String.valueOf(listBean.getPrice()));
poiListEntity.setIsExclusive(listBean.getIsExclusive());
poiListEntity.setTaskStatus(statusId);
poiListEntity.setIsLocalData(1);
String encodeStr = listBean.getGeo();
String geo = Geohash.getInstance().decode(encodeStr);
poiListEntity.setGeoWkt(geo);

View File

@ -754,7 +754,6 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis
poiEntity.setCreateTime(format);
poiEntity.setType(5);
poiEntity.setTaskStatus(2);
poiEntity.setIsLocalData(1);
return poiEntity;
}

View File

@ -1186,7 +1186,6 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe
poiEntity.setExistence(existence);
poiEntity.setType(1);
poiEntity.setTaskStatus(2);
poiEntity.setIsLocalData(1);
return poiEntity;
}

View File

@ -107,6 +107,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick
private LatLng latLng;
private Marker markerPoiVideo;
private TextView tvPicture;
private int isRequest;
public static PoiVideoFragment newInstance(Bundle bundle) {
PoiVideoFragment fragment = new PoiVideoFragment();
@ -251,47 +252,41 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick
etDesc.setText(describe + "");
}
String photoList = showPoiEntity.getPhoto();
if (showPoiEntity.getPhotoInfo()!=null&&photoList==null){
tvPicture.setEnabled(false);
ArrayList<File> files = new ArrayList<>();
List<Info> list = showPoiEntity.getPhotoInfo();
for (int i = 0; i < list.size(); i++) {
files.add(new File(list.get(i).getPhoto()));
}
if (files!=null){
Uri uri = Uri.fromFile(files.get(0));
Glide.with(getContext()).load(uri).into(ivPoiVideoPicture);
fmPoiVideoPic.setTag(files);
}
}else if (showPoiEntity.getPhotoInfo()==null&&photoList!=null){
tvPictures.setEnabled(false);
int record_way = showPoiEntity.getRecord_way();
if (record_way == 1) {//录像
isRequest = 0x101;
if (!StringUtils.isEmpty(photoList)) {
String[] photos = photoList.split(",");
List<File> 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.getPath().contains("0.mp4") && !videoFile.getPath().contains("0.mp4.txt")) {
if (videoFile.exists() && !isImageLoad) {
List<File> videoFileListByUUID = AWMp4ParserHelper.getInstance().getVideoFileListByUUID(showPoiEntity.getId());
for (int i = 0; i < videoFileListByUUID.size(); i++) {
if (videoFileListByUUID.get(i).getPath().contains("0.mp4") && !videoFileListByUUID.get(i).getPath().contains("0.mp4.txt")) {
if (videoFileListByUUID.get(i).exists() && !isImageLoad) {
// 使用glide加载视频的第一帧
AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivPoiVideoPicture, 500);
AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFileListByUUID.get(i)).toString(), ivPoiVideoPicture, 500);
isImageLoad = true;
}
}
fmPoiVideoPic.setTag(videoFileListByUUID);
}
}
} else if (record_way == 2) {//连拍
isRequest = 0x102;
if (!StringUtils.isEmpty(photoList)) {
boolean isImageLoad = false;
List<File> pictureFileListByUUID = AWMp4ParserHelper.getInstance().getJPGFileListByUUID(showPoiEntity.getId());
for (int i = 0; i < pictureFileListByUUID.size(); i++) {
if (pictureFileListByUUID.get(i).getPath().contains("0.jpg") && !pictureFileListByUUID.get(i).getPath().contains("0.jpg.txt")) {
if (pictureFileListByUUID.get(i).exists() && !isImageLoad) {
// 使用glide加载视频的第一帧
Glide.with(getActivity()).load(pictureFileListByUUID.get(i)).into(ivPoiVideoPicture);
isImageLoad = true;
}
}
}
fmPoiVideoPic.setTag(pictureFileListByUUID);
}
}
fmPoiVideoPic.setTag(videoFileList);
}
}
}
}
//判断是否是已做完任务并保存成功
if (showPoiEntity.getTaskStatus() == 3) {
@ -332,6 +327,9 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick
case R.id.tv_pictures://拍照
tvPicture.setEnabled(false);
Intent intents = new Intent(getContext(), PicturesActivity.class);
File filePath = AWMp4ParserHelper.getInstance().obtainJPGFilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath());
intents.putExtra(Constant.INTENT_VIDEO_PATH, filePath.getAbsolutePath());
intents.putExtra("poiEntity", showPoiEntity);
startActivityForResult(intents, 0x102);
break;
case R.id.tv_picture://录像
@ -553,8 +551,8 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0x101 && resultCode == 0x101) {
isRequest = 0x101;
if (data != null && data.hasExtra(Constant.INTENT_VIDEO_PATH)) {
String videoPath = data.getStringExtra(Constant.INTENT_VIDEO_PATH);
File videoFile = new File(videoPath);
@ -565,14 +563,14 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick
}
}
} else if (requestCode == 0x102 && resultCode == 0x102) {
if (data != null) {
List<File> serializableExtra = (List<File>) data.getSerializableExtra(Constant.INTENT_VIDEO_PATH);
if (serializableExtra!=null){
Uri uri = Uri.fromFile(serializableExtra.get(0));
Glide.with(getContext()).load(uri).into(ivPoiVideoPicture);
fmPoiVideoPic.setTag(serializableExtra);
isRequest =0x102;
if (data != null && data.hasExtra(Constant.INTENT_PICTURES_PATH)) {
ArrayList<File> serializableExtra = (ArrayList<File>) data.getSerializableExtra(Constant.INTENT_PICTURES_PATH);
if (serializableExtra != null) {
Glide.with(getActivity()).load(serializableExtra.get(0)).into(ivPoiVideoPicture);
List<File> pictureFileListByUUID = AWMp4ParserHelper.getInstance().getJPGFileListByUUID(showPoiEntity.getId());
fmPoiVideoPic.setTag(pictureFileListByUUID);
}
}
}
}
@ -750,9 +748,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick
poiEntity.setCreateTime(format);
poiEntity.setType(3);
poiEntity.setTaskStatus(2);
poiEntity.setIsLocalData(1);
if (tvPicture.isEnabled()){
if (isRequest==0x101){
if (fmPoiVideoPic.getTag() == null) {
List<File> videoFileListByUUID = AWMp4ParserHelper.getInstance().getVideoFileListByUUID(showPoiEntity.getId());
if (videoFileListByUUID != null) {
@ -768,16 +764,25 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick
if (lineString != null) {
poiEntity.setGeoWkt(lineString);
}
poiEntity.setRecord_way(1);//录像
}
}else if (isRequest==0x102){
if (fmPoiVideoPic.getTag() == null) {
List<File> pictureFileListByUUID = AWMp4ParserHelper.getInstance().getJPGFileListByUUID(showPoiEntity.getId());
if (pictureFileListByUUID != null) {
fmPoiVideoPic.setTag(pictureFileListByUUID);
}
}
if (tvPictures.isEnabled()){
if (fmPoiVideoPic.getTag() != null && !((List<File>) fmPoiVideoPic.getTag()).isEmpty()) {
ArrayList<Info> infos = new ArrayList<>();
List<File> poiVideoPic = (List<File>) fmPoiVideoPic.getTag();
for (int i = 0; i < poiVideoPic.size(); i++) {
infos.add(new Info(poiVideoPic.get(i).getPath()));
List<LatLng> lineStringByVideoFileList = AWMp4ParserHelper.getInstance().getLineStringByVideoFileList((List<File>) fmPoiVideoPic.getTag());
String lineString = GeometryTools.getLineString(lineStringByVideoFileList);
Log.d("TAG", "onGranted: " + lineString);
String photoStr = AWMp4ParserHelper.getInstance().getVideoFileListStr((List<File>) fmPoiVideoPic.getTag());
poiEntity.setPhoto(photoStr);
if (lineString != null) {
poiEntity.setGeoWkt(lineString);
}
poiEntity.setPhotoInfo(infos);
poiEntity.setRecord_way(2);//录像
}
}
return poiEntity;
@ -787,7 +792,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick
protected PoiCheckResult checkPoiEntity(PoiEntity entity) {
PoiCheckResult poiCheckResult = new PoiCheckResult();
if (tvPicture.isEnabled()) {
if (tvPictures.isEnabled()){
if (tvPictures.isEnabled()) {
poiCheckResult.setCode(1);
poiCheckResult.setMsg("请录像");
return poiCheckResult;
@ -795,7 +800,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick
}
if (tvPictures.isEnabled()) {
if (tvPicture.isEnabled()){
if (tvPicture.isEnabled()) {
poiCheckResult.setCode(1);
poiCheckResult.setMsg("请拍照");
return poiCheckResult;

View File

@ -742,7 +742,6 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList
poiEntity.setCreateTime(format);
poiEntity.setType(4);
poiEntity.setTaskStatus(2);
poiEntity.setIsLocalData(1);
if (fmRoadPic.getTag() == null) {
List<File> videoFileListByUUID = AWMp4ParserHelper.getInstance().getVideoFileListByUUID(showPoiEntity.getId());
if (videoFileListByUUID != null) {

View File

@ -44,11 +44,19 @@ public class PoiEntity implements Serializable {
private String dist;//距离用户位置
private int taskStatus;//任务状态 0.未领取 1.已领取5 立即采集2.未保存(保存到本地但未提交成功),3.已保存(保存到本地提交成功)4已上传结束采集
private int type;//1 "POI"2 "充电站"3 "POI录像"4 "道路录像"5 "其他"6 "面状任务"
private int station_type;//1."充电站"2 "充换电站"3 "充电桩组"4 "换电站"5 "门牌", "公交:6 情报:7
private int isLocalData;//是否是本地数据 0,服务 1,本地
private int station_type;//1."充电站"2 "充换电站"3 "充电桩组"4 "换电站"7 "门牌", "公交:8 情报:9
private int isExclusive;//任务类型 0.普通任务1.专属任务
private int bodyId;//保存本地的bodyId
private int work_type;//0."车行" 1."自行车" 2."步行"
private int record_way; //1,录像2连拍
public int getRecord_way() {
return record_way;
}
public void setRecord_way(int record_way) {
this.record_way = record_way;
}
public int getWork_type() {
return work_type;
@ -90,13 +98,6 @@ public class PoiEntity implements Serializable {
this.isExclusive = isExclusive;
}
public int getIsLocalData() {
return isLocalData;
}
public void setIsLocalData(int isLocalData) {
this.isLocalData = isLocalData;
}
public String getDist() {
return dist;

View File

@ -254,6 +254,44 @@ public class AWMp4ParserHelper {
return new File(folderPath+"/"+(maxIndex+1)+".mp4");
}
/**
* 根据文件夹路径生成最新的视频文件路径
* */
public File obtainJPGFilePath(String folderPath) {
if (folderPath == null) {
return null;
}
File folderFile = new File(folderPath);
if (!folderFile.exists()) {
folderFile.mkdirs();
}
File[] fileList = folderFile.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
if (pathname.getName().endsWith(".jpg")){
return true;
}
return false;
}
});
if (fileList == null || fileList.length==0) {
return new File(folderPath+"/0.jpg");
}
int maxIndex = 0;
for (int i = 0; i < fileList.length; i++) {
File file = fileList[i];
if (file!=null) {
int index = Integer.parseInt(file.getName().replace(".jpg", ""));
if (index>=maxIndex) {
maxIndex = index;
}
}
}
return new File(folderPath+"/"+(maxIndex+1)+".jpg");
}
/**
* 根据提供的uuid获取指定目录下所有的视频文件
* */
@ -272,7 +310,24 @@ public class AWMp4ParserHelper {
}
return videoFileList;
}
/**
* 根据提供的uuid获取指定目录下所有的视频文件
* */
public List<File> getJPGFileListByUUID(String uuid) {
List<File> videoFileList = new ArrayList<>();
if (StringUtils.isEmpty(uuid)) {
return videoFileList;
}
File folderFile = new File(Constant.PICTURE_FOLDER+"/"+uuid+"/");
if (!folderFile.exists()) {
folderFile.mkdirs();
return videoFileList;
}
for (File videoFile: folderFile.listFiles()) {
videoFileList.add(videoFile);
}
return videoFileList;
}
public String getVideoFileListStr(List<File> videoFileList) {
StringBuilder resultStrBuilder = new StringBuilder("");
if (videoFileList == null || videoFileList.size()<=0){
@ -298,6 +353,36 @@ public class AWMp4ParserHelper {
return latLngs;
}
for (int m = 0; m < videoFileList.size(); m++) {
File videoFile = videoFileList.get(m);
String path = videoFile.getPath() + ".txt";
List<String> strings = FileUtils.readFileToList(path, "utf-8");
if (strings!=null) {
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;
}
/**
* 根据视频文件列表获取到对应的轨迹数据
* */
public List<LatLng> getLineStringByPictureFileList(List<File> videoFileList) {
List<LatLng> latLngs = new ArrayList<>();
if (videoFileList == null || videoFileList.isEmpty()) {
return latLngs;
}
for (int m = 0; m < videoFileList.size(); m++) {
File videoFile = videoFileList.get(m);