From afb91152bcd3acacfc1b349821771a037cbaf2c1 Mon Sep 17 00:00:00 2001 From: wangdongsheng Date: Sat, 13 Nov 2021 17:05:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E6=8B=8D=E6=91=84=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8=E5=92=8C=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../outdoor/activity/PicturesActivity.java | 127 ++++++++++-------- .../outdoor/fragment/PoiVideoFragment.java | 8 +- .../outdoor/fragment/RoadFragment.java | 4 +- app/src/main/res/layout/activity_pictures.xml | 2 +- 4 files changed, 74 insertions(+), 67 deletions(-) diff --git a/app/src/main/java/com/navinfo/outdoor/activity/PicturesActivity.java b/app/src/main/java/com/navinfo/outdoor/activity/PicturesActivity.java index 50a0cd4..c566dc4 100644 --- a/app/src/main/java/com/navinfo/outdoor/activity/PicturesActivity.java +++ b/app/src/main/java/com/navinfo/outdoor/activity/PicturesActivity.java @@ -21,6 +21,7 @@ import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.FrameLayout; import android.widget.ImageView; +import android.widget.RadioGroup; import android.widget.TextView; import android.widget.Toast; @@ -94,13 +95,14 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen private TextureMapView ivMap; private List removables; private Polyline polyline; - private String finalVideoPath,geoWkt, detail, type; // 摄像后最终保存的文件名 + private String finalVideoPath, geoWkt, detail; // 摄像后最终保存的文件名 private ViewGroup layerChange; // 切换地图和相机的父控件 private CheckBox capturePicture, cbMapType; //拍照 private boolean isMapSlide = false; private boolean isOration = false; - private boolean isTerminus=false; + private boolean isTerminus = false; private boolean isBack = true; + private int type = 0; private SimpleDateFormat formatter; private File paperFile, logFile; private ImageView ivZoomAdd, ivZoomDel, ivLocation, ivPicImage, ivPicVideoImage, imageView; @@ -108,8 +110,6 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen private Timer timer; private TimerTask timerTask; private int videoIndex = -1; - private int poi_video_type=0; - private int oration = 0; private SystemTTS systemTTS; private StringBuilder picturesBuilder; private Handler handler = new Handler(new Handler.Callback() { @@ -122,7 +122,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen imageView.setEnabled(true); } } else if (msg.what == 0x103) { - if (poi_video_type != 2) { + if (radioPicture != 1) { capturePicture.setText("开始采集"); } capturePicture.setChecked(false); @@ -133,6 +133,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen }); private LatLng startLatLine, endLatLine; private TextView tvTitle; + private int radioPicture; @Override protected int getLayout() { @@ -147,10 +148,8 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen removables = new ArrayList<>();//存储轨迹的marker layerChange = findViewById(R.id.layer_change); 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); - type = getIntent().getStringExtra(Constant.INTENT_TYPE); + type = getIntent().getIntExtra(Constant.INTENT_TYPE, 0); geoWkt = getIntent().getStringExtra(Constant.INTENT_GEO_WKT); detail = getIntent().getStringExtra(Constant.INTENT_DETAIL); if (finalVideoPath != null) { @@ -165,15 +164,37 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen ivMap.setOnClickListener(this); ivPicImage = findViewById(R.id.iv_pic); ivPicVideoImage = findViewById(R.id.iv_pic_video); - if (poi_video_type == 1 || poi_video_type == 2) { + if (type == 3) { ivPicVideoImage.setVisibility(View.VISIBLE); ivPicImage.setVisibility(View.GONE); - } else if (poi_video_type == 3) { + } else if (type == 4) { ivPicImage.setVisibility(View.VISIBLE); ivPicVideoImage.setVisibility(View.GONE); } Button btnSwitch = findViewById(R.id.btn_switch); 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); 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); imageView.setOnClickListener(this); capturePicture = findViewById(R.id.capture_picture); - if (poi_video_type == 2) { - isOration = true; - capturePicture.setText("拍摄"); - } else { - capturePicture.setText("开始采集"); - } capturePicture.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { - if (poi_video_type != 2) { + if (radioPicture != 1) { isOration = true; capturePicture.setText("暂停采集"); picturesBuilder.append("capturePicture 点击了开始采集 ,"); @@ -207,7 +222,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen } startTimer(); } else { - if (poi_video_type != 2) { + if (radioPicture != 1) { isOration = false; capturePicture.setText("开始采集"); 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) { super.onPictureTaken(result); isBack = true; - if (oration == 0) { // oblation为0时,拍摄视频必须为横屏 - // 如果当前手机是竖向,则不 - if (isOration) { - if (Objects.requireNonNull(camera.getPictureSize()).getWidth() < camera.getPictureSize().getHeight()) { - Toast.makeText(PicturesActivity.this, "不允许竖向拍摄...", Toast.LENGTH_SHORT).show(); - picturesBuilder.append("camera 用户竖屏拍照 ,"); - stopTimer(); + // 如果当前手机是竖向,则不 + if (isOration) { + if (Objects.requireNonNull(camera.getPictureSize()).getWidth() < camera.getPictureSize().getHeight()) { + Toast.makeText(PicturesActivity.this, "不允许竖向拍摄...", Toast.LENGTH_SHORT).show(); + picturesBuilder.append("camera 用户竖屏拍照 ,"); + stopTimer(); + capturePicture.setChecked(false); + if (radioPicture != 1) { + capturePicture.setText("开始采集"); 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); @@ -293,7 +306,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen finalVideoPath = Objects.requireNonNull(file.getParentFile()).getAbsolutePath() + "/" + (videoIndex + 1) + ".webp"; tvTitle.setText("保存成功:" + (videoIndex + 1)); } - if (poi_video_type == 2) { + if (radioPicture == 1) { Message message = new Message(); message.what = 0x103; handler.sendMessage(message); @@ -340,11 +353,11 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen Geometry geometry = GeometryTools.createGeometry(geo); if (geometry.getGeometryType().equals("LineString")) {//线 BitmapDescriptor bitmapLine = null; - if (type != null) { - if (type.equals("4")) {//poi录像 - bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_arrows); - } else if (type.equals("3")) {//道路录像 + if (type != 0) { + if (type == 3) {//poi录像 bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.road_arrows); + } else if (type == 4) {//道路录像 + bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_arrows); } } List latLineString = GeometryTools.getLatLags(geo); @@ -372,11 +385,11 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen Geometry geometry = GeometryTools.createGeometry(geo); if (geometry.getGeometryType().equals("LineString")) {//线 BitmapDescriptor bitmapLine = null; - if (type != null) { - if (type.equals("4")) {//poi录像 - bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_arrows); - } else if (type.equals("3")) {//道路录像 + if (type != 0) { + if (type == 3) {//poi录像 bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.road_arrows); + } else if (type == 4) {//道路录像 + bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_arrows); } } List latLineString = GeometryTools.getLatLags(geo); @@ -526,10 +539,10 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen layerChange.addView(camera); layerChange.addView(ivMap); initMapBig(); - if (poi_video_type == 1 || poi_video_type == 2) { + if (type==3) { ivPicVideoImage.setVisibility(View.VISIBLE); ivPicImage.setVisibility(View.GONE); - } else if (poi_video_type == 3) { + } else if (type==4) { ivPicImage.setVisibility(View.VISIBLE); ivPicVideoImage.setVisibility(View.GONE); } @@ -576,7 +589,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen protected void onRestart() { super.onRestart(); this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); - if (poi_video_type != 2) { + if (radioPicture != 1) { capturePicture.setChecked(false); capturePicture.setText("继续采集"); } @@ -684,14 +697,14 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen double startDistance = GeometryTools.distanceToDouble(newLatLine, startLatLine); double endDistance = GeometryTools.distanceToDouble(newLatLine, endLatLine); if (startDistance > endDistance) {//endDistance: 起点 startDistance:终点 - if (startDistance <50&&!isTerminus) { + if (startDistance < 50 && !isTerminus) { systemTTS.playText("即将到达任务终点"); - isTerminus=true; + isTerminus = true; } } else { - if (endDistance <50&&!isTerminus) { + if (endDistance < 50 && !isTerminus) { systemTTS.playText("即将到达任务终点"); - isTerminus=true; + isTerminus = true; } } } @@ -702,11 +715,11 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen float speed = Constant.currentLocation.getSpeed();//米/秒 if (speed != 0) { float a = (speed * 3600 / 1000);//km/h - if (poi_video_type == 1) { + if (radioPicture == 2) { if (a > 25) {//25千米/h systemTTS.playText("您已超速"); } - } else if (poi_video_type == 3) { + } else if (radioPicture == 3) { if (a > 70) {//70千米/h systemTTS.playText("您已超速"); } @@ -716,12 +729,12 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen LatLng startLatLng = new LatLng(oldCurrentLocation.getLatitude(), oldCurrentLocation.getLongitude());//旧的坐标 LatLng endLatLng = new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude());//新的坐标 double geometry = GeometryTools.distanceToDouble(startLatLng, endLatLng);//米 - if (poi_video_type == 1) { + if (radioPicture == 2) { double speeds = ((geometry / 2) * 3600 / 1000); if (speeds > 25) {//25千米/h systemTTS.playText("您已超速"); } - } else if (poi_video_type == 3) { + } else if (radioPicture == 3) { double speeds = ((geometry / 1.5) * 3600 / 1000); if (speeds > 70) {//70千米/h systemTTS.playText("您已超速"); @@ -778,7 +791,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen timerTask = new TimerTask() { @Override public void run() { - if (poi_video_type == 2) { + if (radioPicture == 1) { camera.takePicture(); } else { 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); - } else if (poi_video_type == 1) { + } else if (radioPicture == 2) { + timer.schedule(timerTask, 0, 1000); + } else if (radioPicture == 3) { timer.schedule(timerTask, 0, 2000); - } else if (poi_video_type == 3) { - timer.schedule(timerTask, 0, 1500); } } 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 8b08afa..e66a9eb 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java @@ -447,9 +447,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick Intent intents = new Intent(getActivity(), PicturesActivity.class); 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_VIDEO_OBLATION, 0); - intents.putExtra(Constant.INTENT_POI_VIDEO_TYPE, 2); - intents.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType() + ""); + intents.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType()); intents.putExtra(Constant.INTENT_GEO_WKT, showPoiEntity.getGeoWkt()); intents.putExtra(Constant.INTENT_DETAIL, showPoiEntity.getDetail()); startActivityForResult(intents, 0x102); @@ -473,9 +471,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick Intent intent = new Intent(getActivity(), PicturesActivity.class); 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_VIDEO_OBLATION, 0); - intent.putExtra(Constant.INTENT_POI_VIDEO_TYPE, 1); - intent.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType() + ""); + intent.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType()); intent.putExtra(Constant.INTENT_GEO_WKT, showPoiEntity.getGeoWkt()); intent.putExtra(Constant.INTENT_DETAIL, showPoiEntity.getDetail()); startActivityForResult(intent, 0x101); 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 ac6a63b..c6327da 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java @@ -461,9 +461,7 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList Intent intent = new Intent(getContext(), PicturesActivity.class); 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_VIDEO_OBLATION, 0); - intent.putExtra(Constant.INTENT_POI_VIDEO_TYPE, 3); - intent.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType() + ""); + intent.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType()); intent.putExtra(Constant.INTENT_GEO_WKT, showPoiEntity.getGeoWkt()); intent.putExtra(Constant.INTENT_DETAIL, showPoiEntity.getDetail()); startActivityForResult(intent, 0x101); diff --git a/app/src/main/res/layout/activity_pictures.xml b/app/src/main/res/layout/activity_pictures.xml index e4c1e76..3bcea85 100644 --- a/app/src/main/res/layout/activity_pictures.xml +++ b/app/src/main/res/layout/activity_pictures.xml @@ -131,7 +131,7 @@ android:layout_height="wrap_content" android:layout_marginStart="25dp" android:orientation="vertical" - android:visibility="gone" + android:visibility="visible" app:layout_constraintBottom_toTopOf="@+id/capture_picture" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/image_view">