在拍摄界面添加自动和手动的逻辑

This commit is contained in:
wangdongsheng
2021-11-13 17:05:02 +08:00
parent dd814f4ebe
commit afb91152bc
4 changed files with 74 additions and 67 deletions

View File

@@ -21,6 +21,7 @@ import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@@ -94,13 +95,14 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
private TextureMapView ivMap; private TextureMapView ivMap;
private List<Removable> removables; private List<Removable> removables;
private Polyline polyline; private Polyline polyline;
private String finalVideoPath,geoWkt, detail, type; // 摄像后最终保存的文件名 private String finalVideoPath, geoWkt, detail; // 摄像后最终保存的文件名
private ViewGroup layerChange; // 切换地图和相机的父控件 private ViewGroup layerChange; // 切换地图和相机的父控件
private CheckBox capturePicture, cbMapType; //拍照 private CheckBox capturePicture, cbMapType; //拍照
private boolean isMapSlide = false; private boolean isMapSlide = false;
private boolean isOration = false; private boolean isOration = false;
private boolean isTerminus=false; private boolean isTerminus = false;
private boolean isBack = true; private boolean isBack = true;
private int type = 0;
private SimpleDateFormat formatter; private SimpleDateFormat formatter;
private File paperFile, logFile; private File paperFile, logFile;
private ImageView ivZoomAdd, ivZoomDel, ivLocation, ivPicImage, ivPicVideoImage, imageView; private ImageView ivZoomAdd, ivZoomDel, ivLocation, ivPicImage, ivPicVideoImage, imageView;
@@ -108,8 +110,6 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
private Timer timer; private Timer timer;
private TimerTask timerTask; private TimerTask timerTask;
private int videoIndex = -1; private int videoIndex = -1;
private int poi_video_type=0;
private int oration = 0;
private SystemTTS systemTTS; private SystemTTS systemTTS;
private StringBuilder picturesBuilder; private StringBuilder picturesBuilder;
private Handler handler = new Handler(new Handler.Callback() { private Handler handler = new Handler(new Handler.Callback() {
@@ -122,7 +122,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
imageView.setEnabled(true); imageView.setEnabled(true);
} }
} else if (msg.what == 0x103) { } else if (msg.what == 0x103) {
if (poi_video_type != 2) { if (radioPicture != 1) {
capturePicture.setText("开始采集"); capturePicture.setText("开始采集");
} }
capturePicture.setChecked(false); capturePicture.setChecked(false);
@@ -133,6 +133,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
}); });
private LatLng startLatLine, endLatLine; private LatLng startLatLine, endLatLine;
private TextView tvTitle; private TextView tvTitle;
private int radioPicture;
@Override @Override
protected int getLayout() { protected int getLayout() {
@@ -147,10 +148,8 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
removables = new ArrayList<>();//存储轨迹的marker removables = new ArrayList<>();//存储轨迹的marker
layerChange = findViewById(R.id.layer_change); layerChange = findViewById(R.id.layer_change);
if (getIntent() != null) { if (getIntent() != null) {
poi_video_type = getIntent().getIntExtra(Constant.INTENT_POI_VIDEO_TYPE, -1);
oration = getIntent().getIntExtra(Constant.INTENT_VIDEO_OBLATION, 0);
finalVideoPath = getIntent().getStringExtra(Constant.INTENT_JPG_PATH); finalVideoPath = getIntent().getStringExtra(Constant.INTENT_JPG_PATH);
type = getIntent().getStringExtra(Constant.INTENT_TYPE); type = getIntent().getIntExtra(Constant.INTENT_TYPE, 0);
geoWkt = getIntent().getStringExtra(Constant.INTENT_GEO_WKT); geoWkt = getIntent().getStringExtra(Constant.INTENT_GEO_WKT);
detail = getIntent().getStringExtra(Constant.INTENT_DETAIL); detail = getIntent().getStringExtra(Constant.INTENT_DETAIL);
if (finalVideoPath != null) { if (finalVideoPath != null) {
@@ -165,15 +164,37 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
ivMap.setOnClickListener(this); ivMap.setOnClickListener(this);
ivPicImage = findViewById(R.id.iv_pic); ivPicImage = findViewById(R.id.iv_pic);
ivPicVideoImage = findViewById(R.id.iv_pic_video); ivPicVideoImage = findViewById(R.id.iv_pic_video);
if (poi_video_type == 1 || poi_video_type == 2) { if (type == 3) {
ivPicVideoImage.setVisibility(View.VISIBLE); ivPicVideoImage.setVisibility(View.VISIBLE);
ivPicImage.setVisibility(View.GONE); ivPicImage.setVisibility(View.GONE);
} else if (poi_video_type == 3) { } else if (type == 4) {
ivPicImage.setVisibility(View.VISIBLE); ivPicImage.setVisibility(View.VISIBLE);
ivPicVideoImage.setVisibility(View.GONE); ivPicVideoImage.setVisibility(View.GONE);
} }
Button btnSwitch = findViewById(R.id.btn_switch); Button btnSwitch = findViewById(R.id.btn_switch);
btnSwitch.setOnClickListener(this); btnSwitch.setOnClickListener(this);
RadioGroup radioGroupPicture = findViewById(R.id.radio_group_picture);
radioGroupPicture.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radio_btn_hand://手动
radioPicture = 1;
isOration = true;
capturePicture.setText("拍摄");
break;
case R.id.radio_btn_auto://自动1秒:
radioPicture = 2;
capturePicture.setText("开始采集");
break;
case R.id.radio_btn_auto_sec://自动2 秒
radioPicture = 3;
capturePicture.setText("开始采集");
break;
}
}
});
//相机记录器 //相机记录器
CameraLogger.setLogLevel(CameraLogger.LEVEL_VERBOSE); CameraLogger.setLogLevel(CameraLogger.LEVEL_VERBOSE);
ivZoomAdd = findViewById(R.id.iv_zoom_add); ivZoomAdd = findViewById(R.id.iv_zoom_add);
@@ -188,17 +209,11 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
tvTitle = findViewById(R.id.tv_title); tvTitle = findViewById(R.id.tv_title);
imageView.setOnClickListener(this); imageView.setOnClickListener(this);
capturePicture = findViewById(R.id.capture_picture); capturePicture = findViewById(R.id.capture_picture);
if (poi_video_type == 2) {
isOration = true;
capturePicture.setText("拍摄");
} else {
capturePicture.setText("开始采集");
}
capturePicture.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { capturePicture.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) { if (isChecked) {
if (poi_video_type != 2) { if (radioPicture != 1) {
isOration = true; isOration = true;
capturePicture.setText("暂停采集"); capturePicture.setText("暂停采集");
picturesBuilder.append("capturePicture 点击了开始采集 ,"); picturesBuilder.append("capturePicture 点击了开始采集 ,");
@@ -207,7 +222,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
} }
startTimer(); startTimer();
} else { } else {
if (poi_video_type != 2) { if (radioPicture != 1) {
isOration = false; isOration = false;
capturePicture.setText("开始采集"); capturePicture.setText("开始采集");
picturesBuilder.append("capturePicture 点击了暂停采集 ,"); picturesBuilder.append("capturePicture 点击了暂停采集 ,");
@@ -234,23 +249,21 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
if (result != null && result.getData() != null && result.getData().length > 0) { if (result != null && result.getData() != null && result.getData().length > 0) {
super.onPictureTaken(result); super.onPictureTaken(result);
isBack = true; isBack = true;
if (oration == 0) { // oblation为0时拍摄视频必须为横屏 // 如果当前手机是竖向,则不
// 如果当前手机是竖向,则不 if (isOration) {
if (isOration) { if (Objects.requireNonNull(camera.getPictureSize()).getWidth() < camera.getPictureSize().getHeight()) {
if (Objects.requireNonNull(camera.getPictureSize()).getWidth() < camera.getPictureSize().getHeight()) { Toast.makeText(PicturesActivity.this, "不允许竖向拍摄...", Toast.LENGTH_SHORT).show();
Toast.makeText(PicturesActivity.this, "不允许竖向拍摄...", Toast.LENGTH_SHORT).show(); picturesBuilder.append("camera 用户竖屏拍照 ,");
picturesBuilder.append("camera 用户竖屏拍照 ,"); stopTimer();
stopTimer(); capturePicture.setChecked(false);
if (radioPicture != 1) {
capturePicture.setText("开始采集");
capturePicture.setChecked(false); capturePicture.setChecked(false);
if (poi_video_type != 2) {
capturePicture.setText("开始采集");
capturePicture.setChecked(false);
}
return;
} else {
isOration = false;
} }
return;
} else {
isOration = false;
} }
} }
File file = new File(finalVideoPath); File file = new File(finalVideoPath);
@@ -293,7 +306,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
finalVideoPath = Objects.requireNonNull(file.getParentFile()).getAbsolutePath() + "/" + (videoIndex + 1) + ".webp"; finalVideoPath = Objects.requireNonNull(file.getParentFile()).getAbsolutePath() + "/" + (videoIndex + 1) + ".webp";
tvTitle.setText("保存成功:" + (videoIndex + 1)); tvTitle.setText("保存成功:" + (videoIndex + 1));
} }
if (poi_video_type == 2) { if (radioPicture == 1) {
Message message = new Message(); Message message = new Message();
message.what = 0x103; message.what = 0x103;
handler.sendMessage(message); handler.sendMessage(message);
@@ -340,11 +353,11 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
Geometry geometry = GeometryTools.createGeometry(geo); Geometry geometry = GeometryTools.createGeometry(geo);
if (geometry.getGeometryType().equals("LineString")) {//线 if (geometry.getGeometryType().equals("LineString")) {//线
BitmapDescriptor bitmapLine = null; BitmapDescriptor bitmapLine = null;
if (type != null) { if (type != 0) {
if (type.equals("4")) {//poi录像 if (type == 3) {//poi录像
bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_arrows);
} else if (type.equals("3")) {//道路录像
bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.road_arrows); bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.road_arrows);
} else if (type == 4) {//道路录像
bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_arrows);
} }
} }
List<LatLng> latLineString = GeometryTools.getLatLags(geo); List<LatLng> latLineString = GeometryTools.getLatLags(geo);
@@ -372,11 +385,11 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
Geometry geometry = GeometryTools.createGeometry(geo); Geometry geometry = GeometryTools.createGeometry(geo);
if (geometry.getGeometryType().equals("LineString")) {//线 if (geometry.getGeometryType().equals("LineString")) {//线
BitmapDescriptor bitmapLine = null; BitmapDescriptor bitmapLine = null;
if (type != null) { if (type != 0) {
if (type.equals("4")) {//poi录像 if (type == 3) {//poi录像
bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_arrows);
} else if (type.equals("3")) {//道路录像
bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.road_arrows); bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.road_arrows);
} else if (type == 4) {//道路录像
bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_arrows);
} }
} }
List<LatLng> latLineString = GeometryTools.getLatLags(geo); List<LatLng> latLineString = GeometryTools.getLatLags(geo);
@@ -526,10 +539,10 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
layerChange.addView(camera); layerChange.addView(camera);
layerChange.addView(ivMap); layerChange.addView(ivMap);
initMapBig(); initMapBig();
if (poi_video_type == 1 || poi_video_type == 2) { if (type==3) {
ivPicVideoImage.setVisibility(View.VISIBLE); ivPicVideoImage.setVisibility(View.VISIBLE);
ivPicImage.setVisibility(View.GONE); ivPicImage.setVisibility(View.GONE);
} else if (poi_video_type == 3) { } else if (type==4) {
ivPicImage.setVisibility(View.VISIBLE); ivPicImage.setVisibility(View.VISIBLE);
ivPicVideoImage.setVisibility(View.GONE); ivPicVideoImage.setVisibility(View.GONE);
} }
@@ -576,7 +589,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
protected void onRestart() { protected void onRestart() {
super.onRestart(); super.onRestart();
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
if (poi_video_type != 2) { if (radioPicture != 1) {
capturePicture.setChecked(false); capturePicture.setChecked(false);
capturePicture.setText("继续采集"); capturePicture.setText("继续采集");
} }
@@ -684,14 +697,14 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
double startDistance = GeometryTools.distanceToDouble(newLatLine, startLatLine); double startDistance = GeometryTools.distanceToDouble(newLatLine, startLatLine);
double endDistance = GeometryTools.distanceToDouble(newLatLine, endLatLine); double endDistance = GeometryTools.distanceToDouble(newLatLine, endLatLine);
if (startDistance > endDistance) {//endDistance: 起点 startDistance:终点 if (startDistance > endDistance) {//endDistance: 起点 startDistance:终点
if (startDistance <50&&!isTerminus) { if (startDistance < 50 && !isTerminus) {
systemTTS.playText("即将到达任务终点"); systemTTS.playText("即将到达任务终点");
isTerminus=true; isTerminus = true;
} }
} else { } else {
if (endDistance <50&&!isTerminus) { if (endDistance < 50 && !isTerminus) {
systemTTS.playText("即将到达任务终点"); systemTTS.playText("即将到达任务终点");
isTerminus=true; isTerminus = true;
} }
} }
} }
@@ -702,11 +715,11 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
float speed = Constant.currentLocation.getSpeed();//米/秒 float speed = Constant.currentLocation.getSpeed();//米/秒
if (speed != 0) { if (speed != 0) {
float a = (speed * 3600 / 1000);//km/h float a = (speed * 3600 / 1000);//km/h
if (poi_video_type == 1) { if (radioPicture == 2) {
if (a > 25) {//25千米/h if (a > 25) {//25千米/h
systemTTS.playText("您已超速"); systemTTS.playText("您已超速");
} }
} else if (poi_video_type == 3) { } else if (radioPicture == 3) {
if (a > 70) {//70千米/h if (a > 70) {//70千米/h
systemTTS.playText("您已超速"); systemTTS.playText("您已超速");
} }
@@ -716,12 +729,12 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
LatLng startLatLng = new LatLng(oldCurrentLocation.getLatitude(), oldCurrentLocation.getLongitude());//旧的坐标 LatLng startLatLng = new LatLng(oldCurrentLocation.getLatitude(), oldCurrentLocation.getLongitude());//旧的坐标
LatLng endLatLng = new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude());//新的坐标 LatLng endLatLng = new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude());//新的坐标
double geometry = GeometryTools.distanceToDouble(startLatLng, endLatLng);//米 double geometry = GeometryTools.distanceToDouble(startLatLng, endLatLng);//米
if (poi_video_type == 1) { if (radioPicture == 2) {
double speeds = ((geometry / 2) * 3600 / 1000); double speeds = ((geometry / 2) * 3600 / 1000);
if (speeds > 25) {//25千米/h if (speeds > 25) {//25千米/h
systemTTS.playText("您已超速"); systemTTS.playText("您已超速");
} }
} else if (poi_video_type == 3) { } else if (radioPicture == 3) {
double speeds = ((geometry / 1.5) * 3600 / 1000); double speeds = ((geometry / 1.5) * 3600 / 1000);
if (speeds > 70) {//70千米/h if (speeds > 70) {//70千米/h
systemTTS.playText("您已超速"); systemTTS.playText("您已超速");
@@ -778,7 +791,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
timerTask = new TimerTask() { timerTask = new TimerTask() {
@Override @Override
public void run() { public void run() {
if (poi_video_type == 2) { if (radioPicture == 1) {
camera.takePicture(); camera.takePicture();
} else { } else {
Message message = new Message(); Message message = new Message();
@@ -787,12 +800,12 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
} }
} }
}; };
if (poi_video_type == 2) { if (radioPicture == 1) {
timer.schedule(timerTask, 0); timer.schedule(timerTask, 0);
} else if (poi_video_type == 1) { } else if (radioPicture == 2) {
timer.schedule(timerTask, 0, 1000);
} else if (radioPicture == 3) {
timer.schedule(timerTask, 0, 2000); timer.schedule(timerTask, 0, 2000);
} else if (poi_video_type == 3) {
timer.schedule(timerTask, 0, 1500);
} }
} }

View File

@@ -447,9 +447,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick
Intent intents = new Intent(getActivity(), PicturesActivity.class); Intent intents = new Intent(getActivity(), PicturesActivity.class);
File filePath = AWMp4ParserHelper.getInstance().obtainWebpFilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); File filePath = AWMp4ParserHelper.getInstance().obtainWebpFilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath());
intents.putExtra(Constant.INTENT_JPG_PATH, filePath.getAbsolutePath()); intents.putExtra(Constant.INTENT_JPG_PATH, filePath.getAbsolutePath());
intents.putExtra(Constant.INTENT_VIDEO_OBLATION, 0); intents.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType());
intents.putExtra(Constant.INTENT_POI_VIDEO_TYPE, 2);
intents.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType() + "");
intents.putExtra(Constant.INTENT_GEO_WKT, showPoiEntity.getGeoWkt()); intents.putExtra(Constant.INTENT_GEO_WKT, showPoiEntity.getGeoWkt());
intents.putExtra(Constant.INTENT_DETAIL, showPoiEntity.getDetail()); intents.putExtra(Constant.INTENT_DETAIL, showPoiEntity.getDetail());
startActivityForResult(intents, 0x102); startActivityForResult(intents, 0x102);
@@ -473,9 +471,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick
Intent intent = new Intent(getActivity(), PicturesActivity.class); Intent intent = new Intent(getActivity(), PicturesActivity.class);
File fileJpgPath = AWMp4ParserHelper.getInstance().obtainWebpFilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); File fileJpgPath = AWMp4ParserHelper.getInstance().obtainWebpFilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath());
intent.putExtra(Constant.INTENT_JPG_PATH, fileJpgPath.getAbsolutePath()); intent.putExtra(Constant.INTENT_JPG_PATH, fileJpgPath.getAbsolutePath());
intent.putExtra(Constant.INTENT_VIDEO_OBLATION, 0); intent.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType());
intent.putExtra(Constant.INTENT_POI_VIDEO_TYPE, 1);
intent.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType() + "");
intent.putExtra(Constant.INTENT_GEO_WKT, showPoiEntity.getGeoWkt()); intent.putExtra(Constant.INTENT_GEO_WKT, showPoiEntity.getGeoWkt());
intent.putExtra(Constant.INTENT_DETAIL, showPoiEntity.getDetail()); intent.putExtra(Constant.INTENT_DETAIL, showPoiEntity.getDetail());
startActivityForResult(intent, 0x101); startActivityForResult(intent, 0x101);

View File

@@ -461,9 +461,7 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList
Intent intent = new Intent(getContext(), PicturesActivity.class); Intent intent = new Intent(getContext(), PicturesActivity.class);
File finalFile = AWMp4ParserHelper.getInstance().obtainWebpFilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); File finalFile = AWMp4ParserHelper.getInstance().obtainWebpFilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath());
intent.putExtra(Constant.INTENT_JPG_PATH, finalFile.getAbsolutePath()); intent.putExtra(Constant.INTENT_JPG_PATH, finalFile.getAbsolutePath());
intent.putExtra(Constant.INTENT_VIDEO_OBLATION, 0); intent.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType());
intent.putExtra(Constant.INTENT_POI_VIDEO_TYPE, 3);
intent.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType() + "");
intent.putExtra(Constant.INTENT_GEO_WKT, showPoiEntity.getGeoWkt()); intent.putExtra(Constant.INTENT_GEO_WKT, showPoiEntity.getGeoWkt());
intent.putExtra(Constant.INTENT_DETAIL, showPoiEntity.getDetail()); intent.putExtra(Constant.INTENT_DETAIL, showPoiEntity.getDetail());
startActivityForResult(intent, 0x101); startActivityForResult(intent, 0x101);

View File

@@ -131,7 +131,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="25dp" android:layout_marginStart="25dp"
android:orientation="vertical" android:orientation="vertical"
android:visibility="gone" android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/capture_picture" app:layout_constraintBottom_toTopOf="@+id/capture_picture"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/image_view"> app:layout_constraintTop_toBottomOf="@+id/image_view">