diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5f0ed82..b9581b5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -51,8 +51,6 @@ android:supportsRtl="true" android:theme="@style/Theme.WhiteScreen"> @@ -103,8 +101,7 @@ android:name="androidx.core.content.FileProvider" android:authorities="com.navinfo.outdoor.fileprovider" android:grantUriPermissions="true" - android:exported="false" - > + android:exported="false"> diff --git a/app/src/main/java/com/navinfo/outdoor/activity/FragmentManagement.java b/app/src/main/java/com/navinfo/outdoor/activity/FragmentManagement.java index 837fb43..204f96b 100644 --- a/app/src/main/java/com/navinfo/outdoor/activity/FragmentManagement.java +++ b/app/src/main/java/com/navinfo/outdoor/activity/FragmentManagement.java @@ -471,8 +471,6 @@ public class FragmentManagement extends BaseActivity { fragmentTransaction.show(messageFragment); } break; - - } fragmentTransaction.commit(); } diff --git a/app/src/main/java/com/navinfo/outdoor/activity/PictureActivity.java b/app/src/main/java/com/navinfo/outdoor/activity/PictureActivity.java index 81de525..9ddae57 100644 --- a/app/src/main/java/com/navinfo/outdoor/activity/PictureActivity.java +++ b/app/src/main/java/com/navinfo/outdoor/activity/PictureActivity.java @@ -12,8 +12,10 @@ import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.location.Location; import android.media.MediaMetadataRetriever; +import android.os.Bundle; import android.os.Looper; import android.os.Message; +import android.os.SystemClock; import android.util.DisplayMetrics; import android.util.Log; import android.view.View; @@ -21,9 +23,11 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.CheckBox; +import android.widget.Chronometer; import android.widget.CompoundButton; import android.widget.FrameLayout; import android.widget.ImageView; +import android.widget.TextView; import android.widget.Toast; import com.github.lazylibrary.util.DensityUtil; @@ -56,10 +60,13 @@ import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; 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; @@ -96,20 +103,26 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene private TextureMapView ivMap; private CheckBox captureVideo; // 拍摄视频 private Button btnVideo, stopVideo; - private ImageView ivPic; + private String finalVideoPath; // 摄像后最终保存的文件名 - private File tmpFile; // 合并文件的临时文件路径 +// private File tmpFile; // 合并文件的临时文件路径 private Timer timer; private CsvTimerTask timerTask; // 执行定时写入csv文件的task private DateFormat formatter; private final long period = 1; // 记录csv文件的间隔时间,单位为秒 private ViewGroup layerChange; // 切换地图和相机的父控件 private boolean isFinishActivity = false; // 是否需要关闭当前activity + private TextView videoChronometer; + private long recordingTime = 0;// 记录下来的总时间 + private int oratation = -1; // 是否强制横屏拍摄,默认不强制,0-强制横屏 其他-任意 + private List removables; + private String uuId; + private ImageView ivPic; @Override protected int getLayout() { EventBus.getDefault().register(this); - tmpFile = new File(Constant.PICTURE_FOLDER, "temp.mp4"); +// tmpFile = new File(Constant.PICTURE_FOLDER, "temp.mp4"); formatter = new SimpleDateFormat("yyyyMMdd HHmmss"); return R.layout.activity_picture; } @@ -118,26 +131,30 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene protected void initView() { super.initView(); - if (getIntent()!=null) { + if (getIntent() != null) { finalVideoPath = getIntent().getStringExtra(Constant.INTENT_VIDEO_PATH); + uuId = getIntent().getStringExtra("uuId"); + oratation = getIntent().getIntExtra(Constant.INTENT_VIDEO_ORATATION, -1); } - if (finalVideoPath == null) { - finalVideoPath = Constant.PICTURE_FOLDER+"/final.mp4"; - } + videoChronometer = findViewById(R.id.video_chronometer); +// if (finalVideoPath == null) { +// finalVideoPath = Constant.PICTURE_FOLDER+"/final.mp4"; +// } + layerChange = findViewById(R.id.layer_change); + timer = new Timer(); this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); ivMap = (TextureMapView) findViewById(R.id.iv_map); - ivPic = findViewById(R.id.iv_pic); - btnVideo = findViewById(R.id.btn_video); - btnVideo.setOnClickListener(this::onClick); + btnSwitch = (Button) findViewById(R.id.btn_switch); btnSwitch.setOnClickListener(this::onClick); // capturePicture = (ImageButton) findViewById(R.id.capturePicture); // capturePicture.setOnClickListener(this::onClick); + ivPic = findViewById(R.id.iv_pic); //相机记录器 CameraLogger.setLogLevel(CameraLogger.LEVEL_VERBOSE); camera = findViewById(R.id.camera); @@ -147,12 +164,21 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // 开始采集,设置按钮文字内容为“结束采集” + if (oratation == 0) { // oratation为0时,拍摄视频必须为横屏 + // 如果当前手机是竖向,则不允许拍摄 + if (camera.getVideoSize().getWidth() < camera.getVideoSize().getHeight()) { + Toast.makeText(PictureActivity.this, "不允许竖向拍摄...", Toast.LENGTH_SHORT).show(); + return; + } + } + captureVideo.setText("暂停采集"); // stopVideo.setEnabled(false);// 开始采集视频后,禁用停止采集的按钮,必须暂停采集后才可点击停止采集 startTakenVideo(); // 开始采集视频 } else { stopTakenVideo(); captureVideo.setText("开始采集"); +// stopVideoAndFinish(); } } }); @@ -172,10 +198,10 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene 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. @@ -185,7 +211,7 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene SizeSelectors.biggest() // If none is found, take the biggest ); camera.setVideoSize(result); - camera.setVideoBitRate(1920*1440); + camera.setVideoBitRate(1920 * 1440); // camera.setAudioBitRate(); //获取地图 @@ -205,7 +231,23 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene // Log.e("PictureActivity", frame.getTime()+""); // } // }); - + removables = new ArrayList<>();//存储轨迹的marker + if (uuId!=null){ + List videoFileListByUUID = AWMp4ParserHelper.getInstance().getVideoFileListByUUID(uuId); + if (videoFileListByUUID!=null){ + List lineStringByVideoFileList = AWMp4ParserHelper.getInstance().getLineStringByVideoFileList(videoFileListByUUID); + for (int i = 0; i < lineStringByVideoFileList.size(); i++) { + LatLng latLng = lineStringByVideoFileList.get(i); + if (latLng!=null){ + BitmapDescriptor pileDescriptor = BitmapDescriptorFactory.fromResource(ic_baseline); + Marker marker = tencentMap.addMarker(new MarkerOptions(latLng).icon(pileDescriptor).alpha(0.9f) + .flat(true) + .clockwise(false)); + removables.add(marker); + } + } + } + } //相机预览监听 camera.addCameraListener(new CameraListener() { @Override @@ -236,45 +278,49 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene super.onVideoTaken(result); Toast.makeText(PictureActivity.this, "暂停摄像", Toast.LENGTH_SHORT).show(); showLoadingDialog(); - new Thread(new Runnable() { - @Override - public void run() { - if (result!=null) { - File currentFile = result.getFile(); - if (finalVideoPath!=null) { // 有指定的视频文件名称,合并文件 - if (new File(finalVideoPath).exists()) { - List spliteFileList = new ArrayList<>(); - spliteFileList.add(finalVideoPath); - spliteFileList.add(currentFile.getAbsolutePath()); - try { - AWMp4ParserHelper.getInstance().mergeVideos(spliteFileList, tmpFile.getAbsolutePath()); - if (tmpFile.exists()) { - File finalVideoFile = new File(finalVideoPath); - finalVideoFile.delete(); - currentFile.delete(); - tmpFile.renameTo(finalVideoFile); - } else { - Toast.makeText(PictureActivity.this, "视频合并失败!", Toast.LENGTH_SHORT).show(); - } - } catch (Exception e) { - Log.e("PictureActivity", e.getMessage()); - } - } else { - currentFile.renameTo(new File(finalVideoPath)); - } - } - } - runOnUiThread(new Runnable() { - @Override - public void run() { - dismissLoadingDialog(); - if (isFinishActivity) { - PictureActivity.this.finish(); - } - } - }); - } - }).start(); + dismissLoadingDialog(); + if (isFinishActivity) { + PictureActivity.this.finish(); + } +// new Thread(new Runnable() { +// @Override +// public void run() { +// if (result!=null) { +// File currentFile = result.getFile(); +// if (finalVideoPath!=null) { // 有指定的视频文件名称,合并文件 +// if (new File(finalVideoPath).exists()) { +// List spliteFileList = new ArrayList<>(); +// spliteFileList.add(finalVideoPath); +// spliteFileList.add(currentFile.getAbsolutePath()); +// try { +// AWMp4ParserHelper.getInstance().mergeVideos(spliteFileList, tmpFile.getAbsolutePath()); +// if (tmpFile.exists()) { +// File finalVideoFile = new File(finalVideoPath); +// finalVideoFile.delete(); +// currentFile.delete(); +// tmpFile.renameTo(finalVideoFile); +// } else { +// Toast.makeText(PictureActivity.this, "视频合并失败!", Toast.LENGTH_SHORT).show(); +// } +// } catch (Exception e) { +// Log.e("PictureActivity", e.getMessage()); +// } +// } else { +// currentFile.renameTo(new File(finalVideoPath)); +// } +// } +// } +// runOnUiThread(new Runnable() { +// @Override +// public void run() { +// dismissLoadingDialog(); +// if (isFinishActivity) { +// PictureActivity.this.finish(); +// } +// } +// }); +// } +// }).start(); } @Override @@ -289,27 +335,33 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene /** * 获取当前视频的时间,记录csv文件时使用 * */ - long currentTime = AWMp4ParserHelper.getInstance().getVedioTotalTime(new File(finalVideoPath)); - timerTask = new CsvTimerTask(new File(finalVideoPath+".txt")); - - // 开始采集,每隔2秒实时记录位置信息、视频时间以及设备时间 - if (currentTime == 0) { - timer.schedule(timerTask, 0, period*1000); - } else { - timerTask.setCurrentVideoTime(currentTime/1000+1); - timer.schedule(timerTask, 1, period*1000); - } +// long currentTime = AWMp4ParserHelper.getInstance().getVedioTotalTime(new File(finalVideoPath)); + timerTask = new CsvTimerTask(new File(finalVideoPath + ".txt")); + timer.schedule(timerTask, 0, period * 1000); +// // 开始采集,每隔2秒实时记录位置信息、视频时间以及设备时间 +// if (currentTime == 0) { +// timer.schedule(timerTask, 0, period*1000); +// } else { +// timerTask.setCurrentVideoTime(currentTime/1000+1); +// timer.schedule(timerTask, 1, period*1000); +// } } @Override public void onVideoRecordingEnd() { super.onVideoRecordingEnd(); - if (timerTask!=null){ + if (timerTask != null) { timerTask.cancel(); - }else { + } else { // Toast.makeText(PictureActivity.this, "请先拍照", Toast.LENGTH_SHORT).show(); } + // 一段视频拍摄完成自动将当前拍摄路径加1 + File finalVideoFile = new File(finalVideoPath); + if (finalVideoFile.exists()) { + int videoIndex = Integer.parseInt(finalVideoFile.getName().replace(".mp4", "")); + finalVideoPath = finalVideoFile.getParentFile().getAbsolutePath() + "/" + (videoIndex + 1) + ".mp4"; + } } }); @@ -317,12 +369,20 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); FrameLayout.LayoutParams layoutParamsMap = (FrameLayout.LayoutParams) ivMap.getLayoutParams();//相机的宽高 - layoutParamsMap.height = dm.widthPixels/3; - layoutParamsMap.width = dm.heightPixels/3; + layoutParamsMap.height = dm.widthPixels / 3; + layoutParamsMap.width = dm.heightPixels / 3; ivMap.setLayoutParams(layoutParamsMap); } + // 将秒转化成小时分钟秒 + private String formatMiss(long miss) { + String hh = miss / 3600 > 9 ? miss / 3600 + "" : "0" + miss / 3600; + String mm = (miss % 3600) / 60 > 9 ? (miss % 3600) / 60 + "" : "0" + (miss % 3600) / 60; + String ss = (miss % 3600) % 60 > 9 ? (miss % 3600) % 60 + "" : "0" + (miss % 3600) % 60; + return hh + ":" + mm + ":" + ss; + } + private void message(String content, Boolean important) { if (important) { LOG.w(content); @@ -359,51 +419,62 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene // startTakenVideo(); // 开始拍摄视频 // break; case R.id.btn_stop_video: - if (timerTask!=null){ - timerTask.cancel(); - Intent intent = new Intent(); - intent.putExtra(Constant.INTENT_VIDEO_PATH, finalVideoPath); - setResult(0x101, intent); - }else { - Toast.makeText(this, "本段视频没有计时!", Toast.LENGTH_SHORT).show(); - } - if (camera.isTakingVideo()) { - isFinishActivity = true; - camera.stopVideo(); - } else { - finish(); - } + stopVideoAndFinish(); break; } } + public void stopVideoAndFinish() { + if (timerTask != null) { + timerTask.cancel(); + Intent intent = new Intent(); + intent.putExtra(Constant.INTENT_VIDEO_PATH, finalVideoPath); + setResult(0x101, intent); + } else { + Toast.makeText(this, "本段视频没有计时!", Toast.LENGTH_SHORT).show(); + } + if (camera.isTakingVideo()) { + showLoadingDialog(); + isFinishActivity = true; + camera.stopVideo(); + } else { + finish(); + } + } + 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()); +// 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(); +// String path = finalVideoPath.substring(finalVideoPath.length()-20); + if (finalVideoPath != null) { + File file = new File(finalVideoPath); + 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); } } else { - camera.takeVideo(file); + Toast.makeText(this, "请录像", Toast.LENGTH_SHORT).show(); } + } private void stopTakenVideo() { @@ -445,7 +516,6 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene } public void btnSwich() { - DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); System.out.println("width-display :" + dm.widthPixels); @@ -459,7 +529,7 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene layerChange.removeAllViews(); if (widthMap > widthCamera) { - ivPic.setVisibility(View.VISIBLE); + layoutParamsCamera.width = dm.widthPixels; layoutParamsCamera.height = dm.heightPixels; layoutParamsMap.height = heightCamera; @@ -469,7 +539,7 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene layerChange.addView(camera); layerChange.addView(ivMap); } else { - ivPic.setVisibility(View.GONE); + layoutParamsMap.height = dm.heightPixels; layoutParamsMap.width = dm.widthPixels; layoutParamsCamera.height = heightMap; @@ -497,6 +567,10 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene super.onDestroy(); stopTakenVideo(); camera.destroy(); + 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); @@ -549,11 +623,31 @@ public class PictureActivity extends BaseActivity implements View.OnClickListene sb.append(Constant.currentLocation.getLatitude()); sb.append(","); sb.append(Constant.currentLocation.getLongitude()); + sb.append(","); + if (Constant.currentLocation.getBearing()!=0) { + sb.append(Constant.currentLocation.getBearing()); + } else { + sb.append(Constant.currentLocation.getDirection()); + } sb.append("\r\n"); + LatLng latLng = new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()); + BitmapDescriptor pileDescriptor = BitmapDescriptorFactory.fromResource(ic_baseline); + 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; // + currentVideoTime = currentVideoTime + period; // + recordingTime += period; + runOnUiThread(updateTimeRunnable); } } + private Runnable updateTimeRunnable = new Runnable() { + @Override + public void run() { + videoChronometer.setText(formatMiss(recordingTime)); + } + }; } \ No newline at end of file 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 5bc2803..fa8c908 100644 --- a/app/src/main/java/com/navinfo/outdoor/activity/PicturesActivity.java +++ b/app/src/main/java/com/navinfo/outdoor/activity/PicturesActivity.java @@ -5,116 +5,541 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import android.app.Activity; +import android.content.Intent; import android.content.pm.ActivityInfo; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Matrix; import android.os.Bundle; +import android.os.Message; +import android.util.DisplayMetrics; +import android.util.Log; import android.view.View; +import android.view.ViewGroup; import android.widget.Button; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.FrameLayout; import android.widget.Toast; +import com.github.lazylibrary.util.DensityUtil; +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.util.AWMp4ParserHelper; +import com.navinfo.outdoor.util.MyTecentLocationSource; +import com.otaliastudios.cameraview.CameraException; import com.otaliastudios.cameraview.CameraListener; import com.otaliastudios.cameraview.CameraLogger; import com.otaliastudios.cameraview.CameraView; +import com.otaliastudios.cameraview.FileCallback; +import com.otaliastudios.cameraview.PictureResult; import com.otaliastudios.cameraview.VideoResult; import com.otaliastudios.cameraview.controls.Engine; import com.otaliastudios.cameraview.controls.Mode; +import com.otaliastudios.cameraview.size.AspectRatio; +import com.otaliastudios.cameraview.size.SizeSelector; +import com.otaliastudios.cameraview.size.SizeSelectors; +import com.tencent.tencentmap.mapsdk.maps.CameraUpdate; +import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; 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.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.MyLocationStyle; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; import org.jetbrains.annotations.NotNull; import java.io.File; +import java.io.FileDescriptor; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; + +import static com.navinfo.outdoor.R.drawable.location; +import static com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE; public class PicturesActivity extends BaseActivity implements View.OnClickListener { private static final CameraLogger LOG = CameraLogger.create("Picture"); - private com.otaliastudios.cameraview.CameraView cameraView; - private android.widget.Button capuretVideo; - private android.widget.Button btnStopVideo; -// private MapView ivMap; -// private TencentMap tencentMap; + private CameraView camera; + private long captureTime = 0; + private android.widget.Button btnSwitch; + private TencentMap tencentMap; + private MyLocationStyle locationStyle; + private TextureMapView ivMap; + private CheckBox captureVideo; // 拍摄视频 + private Button btnVideo, stopVideo; + private String finalVideoPath; // 摄像后最终保存的文件名 + private File tmpFile; // 合并文件的临时文件路径 + private Timer timer; + private CsvTimerTask timerTask; // 执行定时写入csv文件的task + private DateFormat formatter; + private final long period = 1; // 记录csv文件的间隔时间,单位为秒 + private ViewGroup layerChange; // 切换地图和相机的父控件 + private boolean isFinishActivity = false; // 是否需要关闭当前activity @Override protected int getLayout() { + EventBus.getDefault().register(this); + tmpFile = new File(Constant.PICTURE_FOLDER, "temp.mp4"); + formatter = new SimpleDateFormat("yyyyMMdd HHmmss"); return R.layout.activity_pictures; } -// + @Override protected void initView() { super.initView(); - cameraView = (CameraView) findViewById(R.id.cameraView); - capuretVideo = (Button) findViewById(R.id.capuretVideo); - capuretVideo.setOnClickListener(this::onClick); - btnStopVideo = (Button) findViewById(R.id.btn_stop_video); - btnStopVideo.setOnClickListener(this::onClick); - // ivMap = findViewById(R.id.iv_map); - cameraView.setLifecycleOwner(this); - cameraView.setEngine(Engine.CAMERA1); - cameraView.setMode(Mode.VIDEO); - cameraView.addCameraListener(new CameraListener() { + + if (getIntent()!=null) { + finalVideoPath = getIntent().getStringExtra(Constant.INTENT_VIDEO_PATH); + } + if (finalVideoPath == null) { + finalVideoPath = Constant.PICTURE_FOLDER+"/final.mp4"; + } + + layerChange = findViewById(R.id.layer_change); + + timer = new Timer(); + + // this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + ivMap = (TextureMapView) findViewById(R.id.iv_map); + btnSwitch = (Button) findViewById(R.id.btn_switch); + btnSwitch.setOnClickListener(this::onClick); +// capturePicture = (ImageButton) findViewById(R.id.capturePicture); +// capturePicture.setOnClickListener(this::onClick); + //相机记录器 + CameraLogger.setLogLevel(CameraLogger.LEVEL_VERBOSE); + camera = findViewById(R.id.camera); + camera.setOnClickListener(this::onClick); + captureVideo = findViewById(R.id.capuretVideo); + captureVideo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { // 开始采集,设置按钮文字内容为“结束采集” + captureVideo.setText("暂停采集"); +// stopVideo.setEnabled(false);// 开始采集视频后,禁用停止采集的按钮,必须暂停采集后才可点击停止采集 + startTakenVideo(); // 开始采集视频 + } else { + stopTakenVideo(); + captureVideo.setText("开始采集"); + } + } + }); + + stopVideo = findViewById(R.id.btn_stop_video); + stopVideo.setOnClickListener(this::onClick); + //拍照权限 + camera.setLifecycleOwner(this); + camera.setEngine(Engine.CAMERA1); +// camera.setVideoBitRate(5); + camera.setPreviewFrameRate(5); // 设置预览视频的帧率 + + + // 设置视频可用的宽高size + SizeSelector width = SizeSelectors.maxWidth(1920); + SizeSelector height = SizeSelectors.maxHeight(1440); + 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]); + } + SizeSelector ratio = SizeSelectors.aspectRatio(AspectRatio.of(x, y), 0); // Matches 1:1 sizes. + + SizeSelector result = SizeSelectors.or( + SizeSelectors.and(ratio, dimensions), // Try to match both constraints + ratio, // If none is found, at least try to match the aspect ratio + SizeSelectors.biggest() // If none is found, take the biggest + ); + camera.setVideoSize(result); + camera.setVideoBitRate(1920*1440); +// camera.setAudioBitRate(); + + //获取地图 + tencentMap = ivMap.getMap(); + //获取地图UI 设置对象 + UiSettings uiSettings = tencentMap.getUiSettings(); + //设置logo的大小 + uiSettings.setLogoScale(0.7f); +// uiSettings.setAllGesturesEnabled(false); + setLocMarkerStyle(); // 设置当前位置显示样式 + +// camera.addFrameProcessor(new FrameProcessor() { +// @Override +// public void process(@NonNull Frame frame) { +// Log.e("PictureActivity", frame.getTime()+""); +// } +// }); + + //相机预览监听 + camera.addCameraListener(new CameraListener() { + @Override + public void onPictureTaken(@NonNull @NotNull PictureResult result) { + super.onPictureTaken(result); + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + String format = formatter.format(calendar.getTime()); + //文件 + File file = new File(Constant.PICTURE_FOLDER, format + ".jpg"); + result.toFile(file, new FileCallback() { + @Override + public void onFileReady(@Nullable @org.jetbrains.annotations.Nullable File file) { + Toast.makeText(PicturesActivity.this, "保存成功:" + file.getPath(), Toast.LENGTH_SHORT).show(); + } + }); + if (camera.isTakingVideo()) { + message("Captured while taking video. Size=" + result.getSize(), false); + } + long callbackTime = System.currentTimeMillis(); + captureTime = callbackTime - 300; + Log.d("captureTime", captureTime + ""); + } + + //录像监听 @Override public void onVideoTaken(@NonNull @NotNull VideoResult result) { super.onVideoTaken(result); - Toast.makeText(PicturesActivity.this, "停止摄像", Toast.LENGTH_SHORT).show(); - finish(); + Toast.makeText(PicturesActivity.this, "暂停摄像", Toast.LENGTH_SHORT).show(); + showLoadingDialog(); + new Thread(new Runnable() { + @Override + public void run() { + if (result!=null) { + File currentFile = result.getFile(); + if (finalVideoPath!=null) { // 有指定的视频文件名称,合并文件 + if (new File(finalVideoPath).exists()) { + List spliteFileList = new ArrayList<>(); + spliteFileList.add(finalVideoPath); + spliteFileList.add(currentFile.getAbsolutePath()); + try { + AWMp4ParserHelper.getInstance().mergeVideos(spliteFileList, tmpFile.getAbsolutePath()); + if (tmpFile.exists()) { + File finalVideoFile = new File(finalVideoPath); + finalVideoFile.delete(); + currentFile.delete(); + tmpFile.renameTo(finalVideoFile); + } else { + Toast.makeText(PicturesActivity.this, "视频合并失败!", Toast.LENGTH_SHORT).show(); + } + } catch (Exception e) { + Log.e("PictureActivity", e.getMessage()); + } + } else { + currentFile.renameTo(new File(finalVideoPath)); + } + } + } + runOnUiThread(new Runnable() { + @Override + public void run() { + dismissLoadingDialog(); + if (isFinishActivity) { + PicturesActivity.this.finish(); + } + } + }); + } + }).start(); + } + + @Override + public void onCameraError(@NonNull @NotNull CameraException exception) { + super.onCameraError(exception); + Toast.makeText(PicturesActivity.this, exception.toString(), Toast.LENGTH_SHORT).show(); + } + + @Override + public void onVideoRecordingStart() { + super.onVideoRecordingStart(); + /** + * 获取当前视频的时间,记录csv文件时使用 + * */ + long currentTime = AWMp4ParserHelper.getInstance().getVedioTotalTime(new File(finalVideoPath)); + timerTask = new CsvTimerTask(new File(finalVideoPath+".txt")); + + // 开始采集,每隔2秒实时记录位置信息、视频时间以及设备时间 + if (currentTime == 0) { + timer.schedule(timerTask, 0, period*1000); + } else { + timerTask.setCurrentVideoTime(currentTime/1000+1); + timer.schedule(timerTask, 1, period*1000); + } + + } + + @Override + public void onVideoRecordingEnd() { + super.onVideoRecordingEnd(); + if (timerTask!=null){ + timerTask.cancel(); + }else { + // Toast.makeText(PictureActivity.this, "请先拍照", Toast.LENGTH_SHORT).show(); + } } }); - // tencentMap = ivMap.getMap(); - //获取地图UI 设置对象 -// UiSettings uiSettings = tencentMap.getUiSettings(); -// //设置logo的大小 -// uiSettings.setLogoScale(0.7f); + // 修改相机的宽高为屏幕宽高的1/3 + 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; + ivMap.setLayoutParams(layoutParamsMap); } + private void message(String content, Boolean important) { + if (important) { + LOG.w(content); + Toast.makeText(this, content, Toast.LENGTH_SHORT).show(); + } else { + LOG.i(content); + Toast.makeText(this, content, Toast.LENGTH_SHORT).show(); + } + } + @Override protected void initData() { super.initData(); + camera.setMode(Mode.VIDEO); } - - @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); +// 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_video: + if (timerTask!=null){ + timerTask.cancel(); + Intent intent = new Intent(); + intent.putExtra(Constant.INTENT_VIDEO_PATH, finalVideoPath); + setResult(0x101, intent); + }else { + Toast.makeText(this, "本段视频没有计时!", Toast.LENGTH_SHORT).show(); + } + if (camera.isTakingVideo()) { + isFinishActivity = true; + camera.stopVideo(); + } else { + finish(); + } + + break; + + case R.id.btn_switch: + 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(); + 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; + } + + /** + * 设置定位图标样式 + */ + private void setLocMarkerStyle() { + tencentMap.setLocationSource(new MyTecentLocationSource(this)); + tencentMap.setMyLocationEnabled(true); + + locationStyle = new MyLocationStyle(); + locationStyle = locationStyle.myLocationType(LOCATION_TYPE_LOCATION_ROTATE); + //创建图标 + BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(location)); + locationStyle.icon(bitmapDescriptor); + //设置定位圆形区域的边框宽度; + locationStyle.fillColor(getResources().getColor(android.R.color.transparent)); + locationStyle.strokeWidth(1); + tencentMap.setMyLocationStyle(locationStyle); + } + + + public void btnSwich() { + DisplayMetrics dm = new DisplayMetrics(); + getWindowManager().getDefaultDisplay().getMetrics(dm); + System.out.println("width-display :" + dm.widthPixels); + System.out.println("heigth-display :" + dm.heightPixels); + FrameLayout.LayoutParams layoutParamsMap = (FrameLayout.LayoutParams) ivMap.getLayoutParams();//地图的宽高 + int heightMap = ivMap.getMeasuredHeight(); + int widthMap = ivMap.getMeasuredWidth(); + FrameLayout.LayoutParams layoutParamsCamera = (FrameLayout.LayoutParams) camera.getLayoutParams();//相机的宽高 + int heightCamera = camera.getMeasuredHeight(); + int widthCamera = camera.getMeasuredWidth(); + + layerChange.removeAllViews(); + if (widthMap > widthCamera) { + + layoutParamsCamera.width = dm.widthPixels; + layoutParamsCamera.height = dm.heightPixels; + layoutParamsMap.height = heightCamera; + layoutParamsMap.width = widthCamera; + camera.setLayoutParams(layoutParamsCamera); + ivMap.setLayoutParams(layoutParamsMap); + layerChange.addView(camera); + layerChange.addView(ivMap); + } else { + + layoutParamsMap.height = dm.heightPixels; + layoutParamsMap.width = dm.widthPixels; + layoutParamsCamera.height = heightMap; + layoutParamsCamera.width = widthMap; + camera.setLayoutParams(layoutParamsCamera); + ivMap.setLayoutParams(layoutParamsMap); + layerChange.addView(ivMap); + layerChange.addView(camera); + } + } + + @Override protected void onResume() { super.onResume(); - cameraView.open(); -// ivMap.onResume(); + camera.open(); + } @Override protected void onPause() { super.onPause(); - cameraView.close(); -// ivMap.onPause(); + camera.close(); + } @Override protected void onDestroy() { super.onDestroy(); - cameraView.destroy(); -// ivMap.onDestroy(); + stopTakenVideo(); + camera.destroy(); + timer.cancel(); + if (EventBus.getDefault().isRegistered(this)) { + EventBus.getDefault().unregister(this); + } + + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onEventMessageMainThread(Message msg) { + switch (msg.what) { + case Constant.EVENT_WHAT_LOCATION_CHANGE: // 用户位置更新 + if (tencentMap!=null) { + CameraUpdate cameraSigma = + CameraUpdateFactory.newCameraPosition(new CameraPosition( + new LatLng(Constant.currentLocation.getLatitude(),Constant.currentLocation.getLongitude()), //中心点坐标,地图目标经纬度 + 16, //目标缩放级别 + 0, //目标倾斜角 + 0)); //目标旋转角 0~360° (正北方为0) + tencentMap.animateCamera(cameraSigma); + } + break; + } + } + + /** + * 记录视频拍摄的时间及经纬度 + */ + private class CsvTimerTask extends TimerTask { + private File csvFile; + private long currentVideoTime; // 记录当前的视频时间 + + public CsvTimerTask(File csvFile) { + this.csvFile = csvFile; + if (!csvFile.exists()) { + csvFile.getParentFile().mkdirs(); + } + } + + public void setCurrentVideoTime(long currentVideoTime) { + this.currentVideoTime = currentVideoTime; + } + + @Override + public void run() { + // 记录当前时间、视频时间、以及当前经纬度信息 + StringBuffer sb = new StringBuffer(); + sb.append(formatter.format(new Date())); // 记录当前时间 + sb.append(","); + sb.append(currentVideoTime) ;// 记录视频时间 + sb.append(","); + sb.append(Constant.currentLocation.getLatitude()); + sb.append(","); + sb.append(Constant.currentLocation.getLongitude()); + sb.append("\r\n"); + FileUtils.writeFile(csvFile.getAbsolutePath(), sb.toString(), true); + currentVideoTime = currentVideoTime+period; // + } } } \ No newline at end of file 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 68bf036..977b9c1 100644 --- a/app/src/main/java/com/navinfo/outdoor/activity/UserActivity.java +++ b/app/src/main/java/com/navinfo/outdoor/activity/UserActivity.java @@ -1,6 +1,8 @@ package com.navinfo.outdoor.activity; +import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Color; import android.text.TextUtils; import android.util.Log; @@ -41,6 +43,8 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static com.tencent.mapsdk.internal.aaa.getContext; + /** * 用户资料 */ @@ -59,6 +63,7 @@ public class UserActivity extends BaseActivity implements View.OnClickListener { private String userphone; private String usermailbox; private String region_id; + private SharedPreferences navInfo; @Override @@ -76,6 +81,7 @@ public class UserActivity extends BaseActivity implements View.OnClickListener { protected void initView() { super.initView(); initJsonData(); + navInfo = getSharedPreferences("navInfo", Context.MODE_PRIVATE); ivUser = findViewById(R.id.iv_user); ivUser.setOnClickListener(this::onClick); btnAttestation = findViewById(R.id.btn_attestation); @@ -103,6 +109,11 @@ public class UserActivity extends BaseActivity implements View.OnClickListener { finish(); break; case R.id.btn_gathering: + String attestationName = navInfo.getString("attestationName", null); + if (attestationName == null || attestationName.equals("")) { + Toast.makeText(this, "请先实名认证", Toast.LENGTH_SHORT).show(); + return; + } Intent gatheringIntent = new Intent(this, FragmentManagement.class); gatheringIntent.putExtra("tag", 24); startActivity(gatheringIntent); @@ -153,6 +164,7 @@ public class UserActivity extends BaseActivity implements View.OnClickListener { } } + netWork(); break; } @@ -173,11 +185,12 @@ public class UserActivity extends BaseActivity implements View.OnClickListener { public void onSuccess(Response response) { dismissLoadingDialog(); Log.d("TAG", "onSuccess: " + response.toString() + "sssssssssssss"); + if (response.body().equals("0")) { MessageDialog.show(UserActivity.this, "是否保存", "取消", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(BaseDialog baseDialog, View v) { - // Toast.makeText(getContext(), "点击了确定", Toast.LENGTH_SHORT).show(); + Toast.makeText(getContext(), "点击了确定", Toast.LENGTH_SHORT).show(); return false; } }); @@ -185,7 +198,7 @@ public class UserActivity extends BaseActivity implements View.OnClickListener { MessageDialog.show(UserActivity.this, "是否保存", "确定", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(BaseDialog baseDialog, View v) { - // Toast.makeText(getContext(), "点击了确定", Toast.LENGTH_SHORT).show(); + Toast.makeText(getContext(), "点击了取消", Toast.LENGTH_SHORT).show(); return false; } }); diff --git a/app/src/main/java/com/navinfo/outdoor/adapter/StaySubmitAdapter.java b/app/src/main/java/com/navinfo/outdoor/adapter/StaySubmitAdapter.java index 097dac7..6b0a676 100644 --- a/app/src/main/java/com/navinfo/outdoor/adapter/StaySubmitAdapter.java +++ b/app/src/main/java/com/navinfo/outdoor/adapter/StaySubmitAdapter.java @@ -22,9 +22,10 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Vector; public class StaySubmitAdapter extends RecyclerView.Adapter { - private List allRoad = new ArrayList<>(); + private Vector allRoad = new Vector<>(); private Context context; public StaySubmitAdapter(Context context) { @@ -55,15 +56,17 @@ public class StaySubmitAdapter extends RecyclerView.Adapter { - if (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_BACK) - return true; - return false; - }); - //loading样式 - View view = LayoutInflater.from(this).inflate(R.layout.loading, null); - alertDialog.setView(view); - alertDialog.setCanceledOnTouchOutside(false); - alertDialog.show(); + if (NetWorkUtils.iConnected(this)) { // 当前网络可用 + alertDialog = new AlertDialog.Builder(this).create(); + alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable()); + alertDialog.setCancelable(false); + alertDialog.setOnKeyListener((dialog, keyCode, event) -> { + if (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_BACK) + return true; + return false; + + }); + //loading样式 + View view = LayoutInflater.from(this).inflate(R.layout.loading, null); + alertDialog.setView(view); + alertDialog.setCanceledOnTouchOutside(false); + alertDialog.show(); + initTimer(); + } else { + Toast.makeText(this, "网络不可用", Toast.LENGTH_SHORT).show(); + } + } + public void showFileLoadingDialog() { + if (NetWorkUtils.iConnected(this)) { // 当前网络可用 + alertDialog = new AlertDialog.Builder(this).create(); + alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable()); + alertDialog.setCancelable(false); + alertDialog.setOnKeyListener((dialog, keyCode, event) -> { + if (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_BACK) + return true; + return false; + + }); + //loading样式 + View view = LayoutInflater.from(this).inflate(R.layout.loading, null); + alertDialog.setView(view); + alertDialog.setCanceledOnTouchOutside(false); + alertDialog.show(); + } else { + Toast.makeText(this, "网络不可用", Toast.LENGTH_SHORT).show(); + } + } + + private void initTimer() { + Timer timer = new Timer(true); + TimerTask timerTask = new TimerTask() { + int countTime = 20; + + @Override + public void run() { + if (countTime > 0) { + countTime--; + } + if (countTime == 1) { + dismissLoadingDialog(); + } + + } + }; + timer.schedule(timerTask, 1000, 1000); } public void setLoadingDialogText(String s) { diff --git a/app/src/main/java/com/navinfo/outdoor/base/BaseDrawerFragment.java b/app/src/main/java/com/navinfo/outdoor/base/BaseDrawerFragment.java index f7d5095..0db4230 100644 --- a/app/src/main/java/com/navinfo/outdoor/base/BaseDrawerFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/base/BaseDrawerFragment.java @@ -9,11 +9,14 @@ import android.util.Log; import android.view.View; import android.widget.Toast; +import androidx.annotation.CheckResult; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.navinfo.outdoor.R; import com.navinfo.outdoor.api.Constant; +import com.navinfo.outdoor.room.ChargingPileEntity; +import com.navinfo.outdoor.room.PoiEntity; import com.navinfo.outdoor.util.FragmentBackHandler; import com.navinfo.outdoor.util.GPSUtils; @@ -103,4 +106,28 @@ public abstract class BaseDrawerFragment extends BaseFragment { } + protected abstract PoiEntity initPoiEntityByUI( PoiEntity entity); + protected abstract PoiCheckResult checkPoiEntity(PoiEntity entity); + protected abstract ChargingPileEntity initChargingPileEntityByUI( ChargingPileEntity entity); + protected abstract PoiCheckResult checkChargingPileEntity(ChargingPileEntity entity); + public class PoiCheckResult { + private int code; // 0 检查成功,1:失败 + private String msg; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + } } diff --git a/app/src/main/java/com/navinfo/outdoor/base/BaseFragment.java b/app/src/main/java/com/navinfo/outdoor/base/BaseFragment.java index 95efb2f..34142d6 100644 --- a/app/src/main/java/com/navinfo/outdoor/base/BaseFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/base/BaseFragment.java @@ -4,6 +4,8 @@ import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; +import android.os.Handler; +import android.os.Message; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; @@ -27,6 +29,9 @@ import com.navinfo.outdoor.util.BackHandlerHelper; import com.navinfo.outdoor.util.FragmentBackHandler; import com.navinfo.outdoor.util.NetWorkUtils; +import java.util.Timer; +import java.util.TimerTask; + public abstract class BaseFragment extends Fragment implements FragmentBackHandler { @@ -57,8 +62,7 @@ public abstract class BaseFragment extends Fragment implements FragmentBackHandl return false; } - public void initEvent() { - } + public void initEvent() {} protected T findViewById(@IdRes int id) { return getView().findViewById(id); @@ -81,7 +85,27 @@ public abstract class BaseFragment extends Fragment implements FragmentBackHandl //loading样式 View view = LayoutInflater.from(getContext()).inflate(R.layout.loading, null); alertDialog.setView(view); + alertDialog.setCanceledOnTouchOutside(false); + alertDialog.show(); + initTimer(); + } else { + Toast.makeText(getActivity(), "网络不可用", Toast.LENGTH_SHORT).show(); + } + } + public void showFileLoadingDialog() { + if (NetWorkUtils.iConnected(getContext())) { // 当前网络可用 + alertDialog = new AlertDialog.Builder(getActivity()).create(); + alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable()); + alertDialog.setCancelable(false); + alertDialog.setOnKeyListener((dialog, keyCode, event) -> { + if (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_BACK) + return true; + return false; + }); + //loading样式 + View view = LayoutInflater.from(getContext()).inflate(R.layout.loading, null); + alertDialog.setView(view); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); } else { @@ -89,6 +113,26 @@ public abstract class BaseFragment extends Fragment implements FragmentBackHandl } } + private void initTimer() { + Timer timer = new Timer(true); + TimerTask timerTask = new TimerTask() { + int countTime = 20; + + @Override + public void run() { + if (countTime > 0) { + countTime--; + } + if (countTime == 1) { + dismissLoadingDialog(); + } + + } + }; + timer.schedule(timerTask, 1000, 1000); + } + + public void setLoadingDialogText(String s) { //给loading 添加文字 TextView view = alertDialog.findViewById(R.id.progressBar_tx); @@ -108,18 +152,14 @@ public abstract class BaseFragment extends Fragment implements FragmentBackHandl } } - protected void initMvp() { - } + protected void initMvp() {} - protected void initData() { - } + protected void initData() {} - protected void initView() { - } + protected void initView() {} @Override public void onDestroyView() { super.onDestroyView(); - } } diff --git a/app/src/main/java/com/navinfo/outdoor/bean/GetPriceBean.java b/app/src/main/java/com/navinfo/outdoor/bean/GetPriceBean.java index f8b9b5e..16ed77f 100644 --- a/app/src/main/java/com/navinfo/outdoor/bean/GetPriceBean.java +++ b/app/src/main/java/com/navinfo/outdoor/bean/GetPriceBean.java @@ -2,6 +2,7 @@ package com.navinfo.outdoor.bean; public class GetPriceBean { + private Integer code; private String message; private BodyBean body; @@ -38,6 +39,8 @@ public class GetPriceBean { private Double rewardPrice; private Double poiPushPrice; private Double poiNonepushPrice; + private Double poivideoPushPrice; + private Double poivideoNonepushPrice; private Double roadPushPrice; private Double roadNonepushPrice; private Double csPushPrice; @@ -102,6 +105,22 @@ public class GetPriceBean { this.poiNonepushPrice = poiNonepushPrice; } + public Double getPoivideoPushPrice() { + return poivideoPushPrice; + } + + public void setPoivideoPushPrice(Double poivideoPushPrice) { + this.poivideoPushPrice = poivideoPushPrice; + } + + public Double getPoivideoNonepushPrice() { + return poivideoNonepushPrice; + } + + public void setPoivideoNonepushPrice(Double poivideoNonepushPrice) { + this.poivideoNonepushPrice = poivideoNonepushPrice; + } + public Double getRoadPushPrice() { return roadPushPrice; } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/ChargingPileFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/ChargingPileFragment.java index 5d580d5..28df96f 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/ChargingPileFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/ChargingPileFragment.java @@ -4,8 +4,10 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.Color; +import android.net.Uri; import android.os.Bundle; import android.os.Message; +import android.provider.MediaStore; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -51,6 +53,7 @@ import com.navinfo.outdoor.room.PoiEntity; import com.navinfo.outdoor.util.Geohash; import com.navinfo.outdoor.util.GeometryTools; import com.navinfo.outdoor.util.PhotoPathUtil; +import com.navinfo.outdoor.util.PhotoUtils; import com.navinfo.outdoor.util.PictureUtil; import com.navinfo.outdoor.util.ToastUtil; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; @@ -78,16 +81,17 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC private CheckBox checkBoxLife, checkBoxRight; private Spinner spinnerType, spinnerScutcheon, spinnerStake; String[] type = new String[]{"地上五层", "地上四层", "地上三层", "地上二层", "地上一层", "地下一层", "地下二层", "地下三层", "地下四层", "地下五层"}; - String[] scutcheon = new String[]{"存在","不存在"}; + String[] scutcheon = new String[]{"存在", "不存在"}; String[] stake = new String[]{"可以使用", "不可使用", "维修中", "建设中", "规划中"}; private ArrayAdapter adapterType, adapterScutcheon, adapterStake; private RelativeLayout rlPanorama, rlCoding, rlEquipment, rlFacility, rlUsable, rlAvailable, rlParking, rlNumber, rlScutcheon, rlDevice; private ImageView ivPanorama, ivCoding, ivEquipment, ivFacility, ivUsable, ivAvailable, ivParking, ivNumber, ivScutcheon, ivDevice; + private TextView tvPanorama, tvCoding, tvEquipment, tvFacility, tvUsable, tvAvailable, tvParking, tvNumber, tvScutcheon, tvDevice; private ChargingPileDao chargingPileDao; private int cp_floor = 1; private int sign_exist = 0; private int cp_availableState = 0; - private String buffer1="",buffer2="",buffer3="",buffer4="",buffer5=""; + private String buffer1 = "", buffer2 = "", buffer3 = "", buffer4 = "", buffer5 = ""; private StringBuffer openType = new StringBuffer(); private CheckBox checkButton1, checkButton2, checkButton3, checkButton4, checkButton5; private String pid; @@ -108,6 +112,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC private ArrayList phoneLists; private PoiEntity poiEntity; + private File file; public static ChargingPileFragment newInstance(Bundle bundle) { ChargingPileFragment fragment = new ChargingPileFragment(); @@ -162,14 +167,14 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC checkBoxLife.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked){ + if (isChecked) { checkBoxLife.setText("保存"); checkBoxLife.setTextColor(Color.WHITE); Message obtain = Message.obtain(); obtain.what = Constant.MAIN_CHARGING_PILE; obtain.obj = latLng; EventBus.getDefault().post(obtain); - }else { + } else { checkBoxLife.setText("编辑"); checkBoxLife.setTextColor(Color.BLACK); Message obtain = Message.obtain(); @@ -186,11 +191,11 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { - buffer1="1,"; - buffer2=""; - buffer3=""; - buffer4=""; - buffer5=""; + buffer1 = "1,"; + buffer2 = ""; + buffer3 = ""; + buffer4 = ""; + buffer5 = ""; checkButton2.setChecked(false); checkButton3.setChecked(false); checkButton4.setChecked(false); @@ -203,10 +208,10 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { - buffer2="2,"; + buffer2 = "2,"; checkButton1.setChecked(false); - }else { - buffer2=""; + } else { + buffer2 = ""; } } }); @@ -215,10 +220,10 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { - buffer3="3,"; + buffer3 = "3,"; checkButton1.setChecked(false); - }else { - buffer3=""; + } else { + buffer3 = ""; } } }); @@ -227,10 +232,10 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { - buffer4="4,"; + buffer4 = "4,"; checkButton1.setChecked(false); - }else { - buffer4=""; + } else { + buffer4 = ""; } } }); @@ -239,10 +244,10 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { - buffer5="5,"; + buffer5 = "5,"; checkButton1.setChecked(false); - }else { - buffer5=""; + } else { + buffer5 = ""; } } }); @@ -358,40 +363,50 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC rlPanorama = findViewById(R.id.rl_panorama); rlPanorama.setOnClickListener(this::onClick); ivPanorama = findViewById(R.id.iv_panorama); + tvPanorama = findViewById(R.id.tv_panorama); rlCoding = findViewById(R.id.rl_coding); rlCoding.setOnClickListener(this::onClick); ivCoding = findViewById(R.id.iv_coding); + tvCoding = findViewById(R.id.tv_coding); rlEquipment = findViewById(R.id.rl_equipment); rlEquipment.setOnClickListener(this::onClick); ivEquipment = findViewById(R.id.iv_equipment); + tvEquipment = findViewById(R.id.tv_equipment); rlFacility = findViewById(R.id.rl_facility); rlFacility.setOnClickListener(this::onClick); ivFacility = findViewById(R.id.iv_facility); + tvFacility = findViewById(R.id.tv_facility); rlUsable = findViewById(R.id.rl_usable); rlUsable.setOnClickListener(this::onClick); ivUsable = findViewById(R.id.iv_usable); + tvUsable = findViewById(R.id.tv_usable); rlAvailable = findViewById(R.id.rl_available); rlAvailable.setOnClickListener(this::onClick); ivAvailable = findViewById(R.id.iv_available); + tvAvailable = findViewById(R.id.tv_available); rlParking = findViewById(R.id.rl_parking); rlParking.setOnClickListener(this::onClick); ivParking = findViewById(R.id.iv_parking); + tvParking = findViewById(R.id.tv_parking); rlNumber = findViewById(R.id.rl_number); rlNumber.setOnClickListener(this::onClick); ivNumber = findViewById(R.id.iv_number); + tvNumber = findViewById(R.id.tv_number); rlScutcheon = findViewById(R.id.rl_scutcheon); rlScutcheon.setOnClickListener(this::onClick); ivScutcheon = findViewById(R.id.iv_scutcheon); + tvScutcheon = findViewById(R.id.tv_scutcheon); rlDevice = findViewById(R.id.rl_device); rlDevice.setOnClickListener(this::onClick); ivDevice = findViewById(R.id.iv_device); + tvDevice = findViewById(R.id.tv_device); editDescribe = findViewById(R.id.edit_describe); btnSaveLocal = findViewById(R.id.btn_save_local); btnSaveLocal.setOnClickListener(this::onClick); //展示数据 - initShowPileSharePre(); + initShowPileSharePre(); - onLongDelPic(); + onLongDelPic(); } @@ -540,17 +555,13 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC private void initShowPileSharePre() { station = getArguments().getString("station"); - if (station!=null){ + if (station != null) { poiEntity = new Gson().fromJson(station, PoiEntity.class); pid = poiEntity.getId(); taskId = poiEntity.getTaskId(); - String x = poiEntity.getX(); - String y = poiEntity.getY(); - if (x != null && y != null) { - latLng = new LatLng(); - latLng.setLatitude(Double.parseDouble(y)); - latLng.setLongitude(Double.parseDouble(x)); - } + latLng = new LatLng(); + latLng.setLatitude(Constant.currentLocation.getLatitude()); + latLng.setLongitude(Constant.currentLocation.getLongitude()); } // 添加信息: ChargingPileEntity chargingPileEntity = (ChargingPileEntity) getArguments().getSerializable("chargingPileEntity"); @@ -559,12 +570,16 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC if (name != null) { tvNameContent.setText(name + ""); } + String p = chargingPileEntity.getP(); + if (p != null) { - latLng = GeometryTools.createLatLng(p); + // 解密geo + String decodeGeometry = Geohash.getInstance().decode(p); + latLng = GeometryTools.createLatLng(decodeGeometry); } String memo = chargingPileEntity.getMemo(); - if (memo != null&&!memo.equals("")) { + if (memo != null && !memo.equals("")) { editDescribe.setText(memo); } String fid = chargingPileEntity.getFid(); @@ -596,8 +611,10 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC String[] split = photo.split("/"); if (split[split.length - 1].startsWith("a")) { Glide.with(getActivity()).load(photo).into(ivPanorama); + tvPanorama.setTag(photo); } else if (split[split.length - 1].startsWith("b")) { Glide.with(getActivity()).load(photo).into(ivCoding); + tvCoding.setTag(photo); } else if (split[split.length - 1].startsWith("c")) { cList.add(photo); } else if (split[split.length - 1].startsWith("d")) { @@ -617,21 +634,31 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC switch (list.size()) { case 1: Glide.with(getActivity()).load(list.get(0)).into(ivEquipment); + tvEquipment.setTag(list.get(0)); break; case 2: Glide.with(getActivity()).load(list.get(0)).into(ivEquipment); + tvEquipment.setTag(list.get(0)); Glide.with(getActivity()).load(list.get(1)).into(ivFacility); + tvFacility.setTag(list.get(1)); break; case 3: Glide.with(getActivity()).load(list.get(0)).into(ivEquipment); + tvEquipment.setTag(list.get(0)); Glide.with(getActivity()).load(list.get(1)).into(ivFacility); + tvFacility.setTag(list.get(1)); Glide.with(getActivity()).load(list.get(2)).into(ivScutcheon); + tvScutcheon.setTag(list.get(2)); break; case 4: Glide.with(getActivity()).load(list.get(0)).into(ivEquipment); + tvEquipment.setTag(list.get(0)); Glide.with(getActivity()).load(list.get(1)).into(ivFacility); + tvFacility.setTag(list.get(1)); Glide.with(getActivity()).load(list.get(2)).into(ivScutcheon); + tvScutcheon.setTag(list.get(2)); Glide.with(getActivity()).load(list.get(3)).into(ivDevice); + tvDevice.setTag(list.get(3)); break; } } @@ -640,10 +667,13 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC switch (list.size()) { case 1: Glide.with(getActivity()).load(list.get(0)).into(ivUsable); + tvUsable.setTag(list.get(0)); break; case 2: Glide.with(getActivity()).load(list.get(0)).into(ivUsable); + tvUsable.setTag(list.get(0)); Glide.with(getActivity()).load(list.get(1)).into(ivAvailable); + tvAvailable.setTag(list.get(1)); break; } } @@ -652,10 +682,13 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC switch (list.size()) { case 1: Glide.with(getActivity()).load(list.get(0)).into(ivParking); + tvParking.setTag(list.get(0)); break; case 2: Glide.with(getActivity()).load(list.get(0)).into(ivParking); + tvParking.setTag(list.get(0)); Glide.with(getActivity()).load(list.get(1)).into(ivNumber); + tvNumber.setTag(list.get(1)); break; } } @@ -676,7 +709,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC spinnerScutcheon.setEnabled(false);//设备标牌下拉框 rlEquipment.setEnabled(false);//(蓝色色)设备标牌 rlFacility.setEnabled(false);//(白色)设备标牌 - spinnerStake.setEnabled(false);//桩可用状态 + spinnerStake.setEnabled(false);//桩可用状态 rlUsable.setEnabled(false);//(蓝色)可用状态 rlAvailable.setEnabled(false);//(白色)可用状态 rlParking.setEnabled(false);//(蓝色)停车位编号 @@ -710,138 +743,12 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC public void onGranted(List permissions, boolean all) { if (all) { //保存数据库: - ChargingPileEntity chargingPileEntity = new ChargingPileEntity(); - ArrayList photoBean = new ArrayList<>(); - if (latLng == null || latLng.equals("")) { - Toast.makeText(getActivity(), "请确定点位", Toast.LENGTH_SHORT).show(); - return; - } else { - String encode = Geohash.getInstance().encode(latLng.latitude,latLng.longitude); - chargingPileEntity.setP(encode); -// poiEntity.setX(String.valueOf(latLng.longitude)); -// poiEntity.setY(String.valueOf(latLng.latitude)); - - } - String name = tvNameContent.getText().toString().trim();//名称 - if (name == null || name.equals("")) { - Toast.makeText(getActivity(), "请输入 名称", Toast.LENGTH_SHORT).show(); - return; - } else { - chargingPileEntity.setName(name); - } - String tagPanorama = (String) ivPanorama.getTag(); - if (tagPanorama == null) { - Toast.makeText(getActivity(), "请拍照 全景图", Toast.LENGTH_SHORT).show(); - return; - } else { - photoBean.add(tagPanorama); - } - String tagCoding = (String) ivCoding.getTag(); - if (tagCoding == null) { - Toast.makeText(getActivity(), "请拍照 充电桩编码", Toast.LENGTH_SHORT).show(); - return; - } else { - photoBean.add(tagCoding); - } - String tagEquipment = (String) ivEquipment.getTag(); - if (tagEquipment == null ) { - Toast.makeText(getActivity(), "请拍照 设备标牌", Toast.LENGTH_SHORT).show(); - return; - } else { - photoBean.add(tagEquipment); - } - String tagFacility = (String) ivFacility.getTag(); - if (sign_exist != 0) { - if (tagFacility == null) { - Toast.makeText(getActivity(), "请拍照 设备标牌", Toast.LENGTH_SHORT).show(); - return; - } else { - photoBean.add(tagFacility); - } - } else { - if (tagFacility != null ) { - photoBean.add(tagFacility); - } - } - - String tagScutcheon = (String) ivScutcheon.getTag(); - if (sign_exist == 1) { - if (tagScutcheon == null ) { - Toast.makeText(getActivity(), "请拍照 设备编码", Toast.LENGTH_SHORT).show(); - return; - } else { - photoBean.add(tagScutcheon); - } - } - - String tagDevice = (String) ivDevice.getTag(); - if (sign_exist == 1) { - if (tagDevice == null) { - Toast.makeText(getActivity(), "请拍照 设备标牌", Toast.LENGTH_SHORT).show(); - return; - } else { - photoBean.add(tagDevice); - } - } - - String tagUsable = (String) ivUsable.getTag(); - if (tagUsable == null) { - Toast.makeText(getActivity(), "请拍照 可用状态", Toast.LENGTH_SHORT).show(); - return; - } else { - photoBean.add(tagUsable); - } - String tagAvailable = (String) ivAvailable.getTag(); - if (tagAvailable != null) { - photoBean.add(tagAvailable); - } - String tagParking = (String) ivParking.getTag(); - if (tagParking == null ) { - Toast.makeText(getActivity(), "请拍照 停车位编号", Toast.LENGTH_SHORT).show(); - return; - } else { - photoBean.add(tagPanorama); - } - String tagNumber = (String) ivNumber.getTag(); - if (tagNumber != null ) { - photoBean.add(tagNumber); - } - chargingPileEntity.setPhotos(photoBean); - - if ("".equals(buffer1)&&"".equals(buffer2)&&"".equals(buffer3)&&"".equals(buffer4)&&"".equals(buffer5)) { - Toast.makeText(getActivity(), "开放状态未勾选", Toast.LENGTH_SHORT).show(); + ChargingPileEntity chargingPileEntity = initChargingPileEntityByUI(new ChargingPileEntity()); + PoiCheckResult poiCheckResult = checkChargingPileEntity(chargingPileEntity); + if (poiCheckResult.getCode() == 1) { + Toast.makeText(getActivity(), poiCheckResult.getMsg()+"", Toast.LENGTH_SHORT).show(); return; } - if (buffer1!=null&&!buffer1.equals("")&&buffer1.length()>0){ - openType.delete(0,openType.length()); - openType.append(buffer1); - String charAt = openType.deleteCharAt(openType.length() - 1).toString(); - chargingPileEntity.setCp_openType(charAt); - }else { - openType.delete(0,openType.length()); - openType.append(buffer2); - openType.append(buffer3); - openType.append(buffer4); - openType.append(buffer5); - String charAt = openType.deleteCharAt(openType.length() - 1).toString(); - chargingPileEntity.setCp_openType(charAt); - } - - if (cp_floor != 0) { - chargingPileEntity.setCp_floor(cp_floor); - } - chargingPileEntity.setSign_exist(sign_exist); - chargingPileEntity.setCp_availableState(cp_availableState); - String describe = editDescribe.getText().toString().trim(); - if (describe != null && !describe.equals("")) { - chargingPileEntity.setMemo(describe); - } - if (pid == null) { - Toast.makeText(getActivity(), "没有对应的充电站Id", Toast.LENGTH_SHORT).show(); - } else { - chargingPileEntity.setFid(pid); - } - chargingPileEntity.setTaskStatus(2); // 设置当前充电桩任务状态为本地保存但未上传 new Thread(new Runnable() { @Override public void run() { @@ -849,7 +756,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC getActivity().runOnUiThread(new Runnable() { @Override public void run() { - if (result[0]!=0) { + if (result[0] != 0) { ToastUtil.showShort(getActivity(), "充电桩保存成功"); Message obtain = Message.obtain(); @@ -884,45 +791,65 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC break; case R.id.rl_panorama: Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("a",latLng); + intentPanorama.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentPanorama, 101); initPileSharePre(); break; case R.id.rl_coding: Intent intentCoding = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("b", latLng); + intentCoding.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentCoding, 102); initPileSharePre(); break; case R.id.rl_equipment: Intent intentEquipment = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("c", latLng); + intentEquipment.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentEquipment, 103); initPileSharePre(); break; case R.id.rl_facility: Intent intentFacility = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("c", latLng); + intentFacility.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentFacility, 104); break; case R.id.rl_scutcheon: Intent intentScutcheon = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("c",latLng); + intentScutcheon.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentScutcheon, 105); break; case R.id.rl_device: Intent intentDevice = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("c", latLng); + intentDevice.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentDevice, 106); break; case R.id.rl_usable: Intent intentUsable = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("d", latLng); + intentUsable.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentUsable, 107); break; case R.id.rl_available: Intent intentAvailable = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("d", latLng); + intentAvailable.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentAvailable, 108); break; case R.id.rl_parking: Intent intentParking = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("e", latLng); + intentParking.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentParking, 109); break; case R.id.rl_number: Intent intentNumber = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("e",latLng); + intentNumber.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentNumber, 110); break; @@ -980,49 +907,6 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC // }).build(); // } - private void phoneList() { - phoneLists = new ArrayList<>(); - String ivPanoramaTag = (String) ivPanorama.getTag(); - if (ivPanoramaTag!=null){ - phoneLists.add(new File(ivPanoramaTag)); - } - String ivCodingTag = (String) ivCoding.getTag(); - if (ivCodingTag!=null){ - phoneLists.add(new File(ivCodingTag)); - } - String ivEquipmentTag = (String) ivEquipment.getTag(); - if (ivEquipmentTag!=null){ - phoneLists.add(new File(ivEquipmentTag)); - } - String ivFacilityTag = (String) ivFacility.getTag(); - if (ivFacilityTag!=null){ - phoneLists.add(new File(ivFacilityTag)); - } - String ivUsableTag = (String) ivUsable.getTag(); - if (ivUsableTag!=null){ - phoneLists.add(new File(ivUsableTag)); - } - String ivAvailableTag = (String) ivAvailable.getTag(); - if (ivAvailableTag!=null){ - phoneLists.add(new File(ivAvailableTag)); - } - String ivParkingTag = (String) ivParking.getTag(); - if (ivParkingTag!=null){ - phoneLists.add(new File(ivParkingTag)); - } - String ivNumberTag = (String) ivNumber.getTag(); - if (ivNumberTag!=null){ - phoneLists.add(new File(ivNumberTag)); - } - String ivDeviceTag = (String) ivDevice.getTag(); - if (ivDeviceTag!=null){ - phoneLists.add(new File(ivDeviceTag)); - } - String ivScutcheonTag = (String) ivScutcheon.getTag(); - if (ivScutcheonTag!=null){ - phoneLists.add(new File(ivScutcheonTag)); - } - } @Override @@ -1043,87 +927,11 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC //获取Editor对象 SharedPreferences.Editor edit = poi.edit(); //根据要保存的数据的类型,调用对应的put方法, - ChargingPileEntity chargingPileEntity = new ChargingPileEntity(); - ArrayList photo = new ArrayList<>(); - if (latLng != null) { - chargingPileEntity.setP(latLng.latitude+","+latLng.longitude); - } - String name = tvNameContent.getText().toString().trim();//名称 - if (name != null &&!name.equals("")) { - chargingPileEntity.setName(name); - } - if (cp_floor != 0) { - chargingPileEntity.setCp_floor(cp_floor); - } - String tagPanorama = (String) ivPanorama.getTag(); - if (tagPanorama != null &&!tagPanorama.equals("")) { - photo.add(tagPanorama); - } - String tagCoding = (String) ivCoding.getTag(); - if (tagCoding != null&&!tagCoding.equals("")) { - photo.add(tagCoding); - } - String tagEquipment = (String) ivEquipment.getTag(); - if (tagEquipment != null&&!tagEquipment.equals("")) { - photo.add(tagEquipment); - } - String tagFacility = (String) ivFacility.getTag(); - if (tagFacility != null&&!tagFacility.equals("")) { - photo.add(tagFacility); - } - String tagScutcheon = (String) ivScutcheon.getTag(); - if (tagScutcheon != null&&!tagScutcheon.equals("")) { - photo.add(tagScutcheon); - } - String tagDevice = (String) ivDevice.getTag(); - if (tagDevice != null&&!tagDevice.equals("")) { - photo.add(tagDevice); - } - String tagUsable = (String) ivUsable.getTag(); - if (tagUsable != null &&!tagUsable.equals("")) { - photo.add(tagUsable); - } - String tagAvailable = (String) ivAvailable.getTag(); - if (tagAvailable != null&&!tagAvailable.equals("")) { - photo.add(tagAvailable); - } - String tagParking = (String) ivParking.getTag(); - if (tagParking != null&&!tagParking.equals("")) { - photo.add(tagPanorama); - } - String tagNumber = (String) ivNumber.getTag(); - if (tagNumber != null&&!tagNumber.equals("")) { - photo.add(tagNumber); - } - chargingPileEntity.setPhotos(photo); - chargingPileEntity.setSign_exist(sign_exist); - chargingPileEntity.setCp_availableState(cp_availableState); - String describe = editDescribe.getText().toString().trim(); - if (describe != null && !describe.equals("")) { - chargingPileEntity.setMemo(describe); - } - if (pid != null) { - chargingPileEntity.setFid(pid); - } - if (buffer1!=null&&!buffer1.equals("")){ - chargingPileEntity.setCp_openType(buffer1); - }else { - openType.reverse(); - openType.append(buffer2); - openType.append(buffer3); - openType.append(buffer4); - openType.append(buffer5); - if (openType!=null&&!"".equals(openType)&&openType.length()>0) { - String charAt = openType.deleteCharAt(openType.length() - 1).toString(); - chargingPileEntity.setCp_openType(charAt); - } else { - chargingPileEntity.setCp_openType(""); - } - } + ChargingPileEntity chargingPileEntity = initChargingPileEntityByUI(new ChargingPileEntity()); String newChargingPileEntity = new Gson().toJson(chargingPileEntity); //以键值对的形式添加新值。 edit.putString("chargingPileEntity", newChargingPileEntity); - if (station!=null){ + if (station != null) { edit.putString("poiEntity", station); } //提交新值。必须执行,否则前面的操作都无效。 @@ -1135,11 +943,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 101 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath1 = PhotoPathUtil.getTakePhotoPath(data, "a",Geohash.getInstance().encode(latLng.latitude,latLng.longitude)); - ivPanorama.setTag(takePhotoPath1); - ivPanorama.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivPanorama); + tvPanorama.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1156,11 +968,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 102 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath2 = PhotoPathUtil.getTakePhotoPath(data, "b",Geohash.getInstance().encode(latLng.latitude,latLng.longitude)); - ivCoding.setTag(takePhotoPath2); - ivCoding.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivCoding); + tvCoding.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1177,11 +993,16 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 103 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath3 = PhotoPathUtil.getTakePhotoPath(data, "c",Geohash.getInstance().encode(latLng.latitude,latLng.longitude)); - ivEquipment.setImageBitmap(bitmap);//显示图像 - ivEquipment.setTag(takePhotoPath3); + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivEquipment); + tvEquipment.setTag(s); + } + file=null; + /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1198,11 +1019,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 104 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath4 = PhotoPathUtil.getTakePhotoPath(data, "c",Geohash.getInstance().encode(latLng.latitude,latLng.longitude)); - ivFacility.setTag(takePhotoPath4); - ivFacility.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivFacility); + tvFacility.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1219,11 +1044,16 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 105 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath5 = PhotoPathUtil.getTakePhotoPath(data, "c",Geohash.getInstance().encode(latLng.latitude,latLng.longitude)); - ivScutcheon.setTag(takePhotoPath5); - ivScutcheon.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivScutcheon); + tvScutcheon.setTag(s); + } + file=null; + /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1240,11 +1070,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 106 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath6 = PhotoPathUtil.getTakePhotoPath(data, "c",Geohash.getInstance().encode(latLng.latitude,latLng.longitude)); - ivDevice.setTag(takePhotoPath6); - ivDevice.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivDevice); + tvDevice.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1261,11 +1095,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 107 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath7 = PhotoPathUtil.getTakePhotoPath(data, "d",Geohash.getInstance().encode(latLng.latitude,latLng.longitude)); - ivUsable.setTag(takePhotoPath7); - ivUsable.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivUsable); + tvUsable.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1282,11 +1120,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 108 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath8 = PhotoPathUtil.getTakePhotoPath(data, "d",Geohash.getInstance().encode(latLng.latitude,latLng.longitude)); - ivAvailable.setTag(takePhotoPath8); - ivAvailable.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivAvailable); + tvAvailable.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1303,11 +1145,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 109 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath9 = PhotoPathUtil.getTakePhotoPath(data, "e",Geohash.getInstance().encode(latLng.latitude,latLng.longitude)); - ivParking.setImageBitmap(bitmap);//显示图像 - ivParking.setTag(takePhotoPath9); + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivParking); + tvParking.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1324,11 +1170,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 110 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath10 = PhotoPathUtil.getTakePhotoPath(data, "e",Geohash.getInstance().encode(latLng.latitude,latLng.longitude)); - ivNumber.setImageBitmap(bitmap);//显示图像 - ivNumber.setTag(takePhotoPath10); + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivNumber); + tvNumber.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1356,4 +1206,161 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC } + + @Override + protected ChargingPileEntity initChargingPileEntityByUI(ChargingPileEntity chargingPileEntity) { + ArrayList photo = new ArrayList<>(); + if (latLng != null) { + String encode = Geohash.getInstance().encode(latLng.latitude, latLng.longitude); + chargingPileEntity.setP(encode); + } + String name = tvNameContent.getText().toString().trim();//名称 + if (name != null && !name.equals("")) { + chargingPileEntity.setName(name); + } + if (cp_floor != 0) { + chargingPileEntity.setCp_floor(cp_floor); + } + String tagPanorama = (String) tvPanorama.getTag(); + if (tagPanorama != null && !tagPanorama.equals("")) { + photo.add(tagPanorama); + } + String tagCoding = (String) tvCoding.getTag(); + if (tagCoding != null && !tagCoding.equals("")) { + photo.add(tagCoding); + } + String tagEquipment = (String) tvEquipment.getTag(); + if (tagEquipment != null && !tagEquipment.equals("")) { + photo.add(tagEquipment); + } + String tagFacility = (String) tvFacility.getTag(); + if (tagFacility != null && !tagFacility.equals("")) { + photo.add(tagFacility); + } + String tagScutcheon = (String) tvScutcheon.getTag(); + if (tagScutcheon != null && !tagScutcheon.equals("")) { + photo.add(tagScutcheon); + } + String tagDevice = (String) tvDevice.getTag(); + if (tagDevice != null && !tagDevice.equals("")) { + photo.add(tagDevice); + } + String tagUsable = (String) tvUsable.getTag(); + if (tagUsable != null && !tagUsable.equals("")) { + photo.add(tagUsable); + } + String tagAvailable = (String) tvAvailable.getTag(); + if (tagAvailable != null && !tagAvailable.equals("")) { + photo.add(tagAvailable); + } + String tagParking = (String) tvParking.getTag(); + if (tagParking != null && !tagParking.equals("")) { + photo.add(tagPanorama); + } + String tagNumber = (String) tvNumber.getTag(); + if (tagNumber != null && !tagNumber.equals("")) { + photo.add(tagNumber); + } + chargingPileEntity.setPhotos(photo); + chargingPileEntity.setSign_exist(sign_exist); + chargingPileEntity.setCp_availableState(cp_availableState); + String describe = editDescribe.getText().toString().trim(); + if (describe != null && !describe.equals("")) { + chargingPileEntity.setMemo(describe); + } + if (pid != null) { + chargingPileEntity.setFid(pid); + } + if (buffer1 != null && !buffer1.equals("")) { + chargingPileEntity.setCp_openType(buffer1); + } else { + openType.reverse(); + openType.append(buffer2); + openType.append(buffer3); + openType.append(buffer4); + openType.append(buffer5); + if (openType != null && !"".equals(openType) && openType.length() > 0) { + String charAt = openType.deleteCharAt(openType.length() - 1).toString(); + chargingPileEntity.setCp_openType(charAt); + } else { + chargingPileEntity.setCp_openType(""); + } + } + return chargingPileEntity; + } + + @Override + protected PoiCheckResult checkChargingPileEntity(ChargingPileEntity entity) { + PoiCheckResult poiCheckResult = new PoiCheckResult(); + if (entity.getP()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请确定点位"); + return poiCheckResult; + } + if (entity.getName()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请输入 名称"); + return poiCheckResult; + } + if (entity.getCp_openType()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("开放状态未勾选"); + return poiCheckResult; + } + if (tvPanorama.getTag()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请拍照 全景图"); + return poiCheckResult; + } + if (tvCoding.getTag()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请拍照 充电桩编码"); + return poiCheckResult; + } + if (tvEquipment.getTag()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请拍照 设备标牌"); + return poiCheckResult; + } + if (sign_exist!=0){ + if ( tvFacility.getTag()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请拍照 设备标牌"); + return poiCheckResult; + } + } + if (sign_exist==1){ + if (tvScutcheon.getTag() == null) { + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请拍照 设备标牌"); + return poiCheckResult; + } + if (tvDevice.getTag() == null) { + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请拍照 设备标牌"); + return poiCheckResult; + } + } + if ( tvUsable.getTag() == null) { + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请拍照 可用状态"); + return poiCheckResult; + } + if ( tvParking.getTag() == null) { + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请拍照 停车位编号"); + return poiCheckResult; + } + return poiCheckResult; + } + + @Override + protected PoiEntity initPoiEntityByUI(PoiEntity entity) { + return null; + } + + @Override + protected PoiCheckResult checkPoiEntity(PoiEntity entity) { + return null; + } } \ No newline at end of file diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/ChargingStationFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/ChargingStationFragment.java index de75e27..445ede0 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/ChargingStationFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/ChargingStationFragment.java @@ -4,8 +4,10 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.Color; +import android.net.Uri; import android.os.Bundle; import android.os.Message; +import android.provider.MediaStore; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -62,6 +64,8 @@ import com.navinfo.outdoor.room.PoiEntity; import com.navinfo.outdoor.ui.view.ContactView; import com.navinfo.outdoor.util.Geohash; import com.navinfo.outdoor.util.PhotoPathUtil; +import com.navinfo.outdoor.util.PhotoUtils; +import com.navinfo.outdoor.util.ToastUtil; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import org.greenrobot.eventbus.EventBus; @@ -91,6 +95,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. private RelativeLayout rlPanorama, rlName, rlInternalPhotos, rlElse, rlScutcheon, rlNull; private ImageView ivPanorama, ivName, ivInternal, ivElse, ivScutcheon; private TextView tvExamine; + private TextView tvPanorama, tvName, tvInternal, tvElse, tvScutcheon; private EditText editNameContent, editSiteContent; private ArrayList poiBeans; private Button btnSaveLocal; @@ -118,6 +123,9 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. private ContactView contactView; private ArrayList chargingStationList; +// private ArrayList fileList; + private File photoFile; // 拍照保存的路径 + public static ChargingStationFragment newInstance(Bundle bundle) { ChargingStationFragment fragment = new ChargingStationFragment(); fragment.setArguments(bundle); @@ -216,7 +224,11 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. rlElse.setOnClickListener(this::onClick); rlScutcheon = findViewById(R.id.rl_scutcheon); rlScutcheon.setOnClickListener(this::onClick); - + tvPanorama = findViewById(R.id.tv_panorama); + tvElse = findViewById(R.id.tv_else); + tvInternal = findViewById(R.id.tv_internal); + tvName = findViewById(R.id.tv_name); + tvScutcheon = findViewById(R.id.tv_scutcheon); /* recyclerPhone = findViewById(R.id.recycler_phone); recyclerPhone.setLayoutManager(new LinearLayoutManager(getContext())); recyclerPhone.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL)); @@ -408,9 +420,9 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. private void initShowPoi() { // 添加信息: showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity"); - if (showPoiEntity.getTaskStatus()==1||showPoiEntity.getTaskStatus()==5){ + if (showPoiEntity.getTaskStatus() == 1 || showPoiEntity.getTaskStatus() == 5) { tvExamine.setVisibility(View.GONE); - }else { + } else { tvExamine.setVisibility(View.VISIBLE); } String name = showPoiEntity.getName();//名称 @@ -436,7 +448,16 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. editDescribe.setText(describe); } int station_type = showPoiEntity.getStation_type(); - spinnerType.setSelection(station_type, true); + if (station_type==1){ + spinnerType.setSelection(0, true); + }else if (station_type==2){ + spinnerType.setSelection(1, true); + }else if (station_type==3){ + spinnerType.setSelection(2, true); + }else if (station_type==4){ + spinnerType.setSelection(3, true); + } + String telPhone = showPoiEntity.getTelPhone(); if (telPhone != null && !telPhone.equals("")) { String[] phones = telPhone.split("\\|"); @@ -499,19 +520,19 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. String[] split = photo.split("/"); if (split[split.length - 1].startsWith("a")) { Glide.with(getActivity()).load(photo).into(ivPanorama); - ivPanorama.setTag(photo); + tvPanorama.setTag(photo); } else if (split[split.length - 1].startsWith("b")) { Glide.with(getActivity()).load(photo).into(ivName); - ivName.setTag(photo); + tvName.setTag(photo); } else if (split[split.length - 1].startsWith("c")) { Glide.with(getActivity()).load(photo).into(ivInternal); - ivInternal.setTag(photo); + tvInternal.setTag(photo); } else if (split[split.length - 1].startsWith("d")) { Glide.with(getActivity()).load(photo).into(ivElse); - ivElse.setTag(photo); + tvElse.setTag(photo); } else if (split[split.length - 1].startsWith("e")) { Glide.with(getActivity()).load(photo).into(ivScutcheon); - ivScutcheon.setTag(photo); + tvScutcheon.setTag(photo); } } } @@ -549,7 +570,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. obtain.what = Constant.CHARGING_STATION; obtain.obj = showStation; EventBus.getDefault().post(obtain); - }else { + } else { Message obtains = Message.obtain(); obtains.what = Constant.CHARGING_STATION_PILE; obtains.obj = null; @@ -676,14 +697,14 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. return; } chargingStationList = new ArrayList<>(); - String tagPanorama = (String) ivPanorama.getTag(); + String tagPanorama = (String) tvPanorama.getTag(); if (tagPanorama == null) { Toast.makeText(getContext(), "请拍照", Toast.LENGTH_SHORT).show(); return; } else { chargingStationList.add(new File(tagPanorama)); } - String tagName = (String) ivName.getTag(); + String tagName = (String) tvName.getTag(); if (tagName == null) { Toast.makeText(getContext(), "请拍照", Toast.LENGTH_SHORT).show(); return; @@ -691,21 +712,21 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. chargingStationList.add(new File(tagName)); } if (existence == 0) { - String tagInternal = (String) ivInternal.getTag(); + String tagInternal = (String) tvInternal.getTag(); if (tagInternal == null) { Toast.makeText(getContext(), "请拍照", Toast.LENGTH_SHORT).show(); return; } else { chargingStationList.add(new File(tagInternal)); } - String tagElse = (String) ivElse.getTag(); + String tagElse = (String) tvElse.getTag(); if (tagElse == null) { Toast.makeText(getContext(), "请拍照", Toast.LENGTH_SHORT).show(); return; } else { chargingStationList.add(new File(tagElse)); } - String tagScutcheon = (String) ivScutcheon.getTag(); + String tagScutcheon = (String) tvScutcheon.getTag(); if (tagScutcheon == null) { Toast.makeText(getContext(), "请拍照", Toast.LENGTH_SHORT).show(); return; @@ -737,22 +758,32 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. break; case R.id.rl_panorama: Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE"); + photoFile = PhotoUtils.showPhotoFile("a", latLng); + intentPanorama.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(intentPanorama, 101); break; case R.id.rl_name: Intent intentName = new Intent("android.media.action.IMAGE_CAPTURE"); + photoFile = PhotoUtils.showPhotoFile("b", latLng); + intentName.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(intentName, 102); break; case R.id.rl_internal_photos: Intent intentInternal = new Intent("android.media.action.IMAGE_CAPTURE"); + photoFile = PhotoUtils.showPhotoFile("c", latLng); + intentInternal.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(intentInternal, 103); break; case R.id.rl_else: Intent intentElse = new Intent("android.media.action.IMAGE_CAPTURE"); + photoFile = PhotoUtils.showPhotoFile("d", latLng); + intentElse.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(intentElse, 104); break; case R.id.rl_scutcheon: Intent intentScutcheon = new Intent("android.media.action.IMAGE_CAPTURE"); + photoFile = PhotoUtils.showPhotoFile("e", latLng); + intentScutcheon.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(intentScutcheon, 105); break; case R.id.linear_charging_pile: @@ -853,85 +884,12 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. public void onGranted(List permissions, boolean all) { if (all) { //保存数据库: - PoiEntity poiEntity = showPoiEntity; - List infoPhoto = new ArrayList<>(); - String name = editNameContent.getText().toString().trim();//名称 - if (name == null || name.equals("")) { - Toast.makeText(getActivity(), "请输入充电站 名称", Toast.LENGTH_SHORT).show(); + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); + PoiCheckResult poiCheckResult = checkPoiEntity(poiEntity); + if (poiCheckResult.getCode() == 1) { + Toast.makeText(getActivity(), poiCheckResult.getMsg()+"", Toast.LENGTH_SHORT).show(); return; - } else { - poiEntity.setName(name); } - String site = editSiteContent.getText().toString().trim(); - if (site != null && !site.equals("")) { - poiEntity.setAddress(site); - } - if (latLng == null) { - Toast.makeText(getActivity(), "请确定点位", Toast.LENGTH_SHORT).show(); - return; - } else { - String encode = Geohash.getInstance().encode(latLng.latitude, latLng.longitude); - poiEntity.setGeoWkt(encode); - poiEntity.setX(String.valueOf(latLng.longitude)); - poiEntity.setY(String.valueOf(latLng.latitude)); - } - String describe = editDescribe.getText().toString().trim(); - if (describe != null && !describe.equals("")) { - poiEntity.setMemo(describe); - } - boolean phoneBean = contactView.getPhoneBean(); - if (phoneBean) { - String list = contactView.getList(); - poiEntity.setTelPhone(list); - } - String tagPanorama = (String) ivPanorama.getTag(); - if (tagPanorama == null) { - Toast.makeText(getActivity(), "请拍照 全景图", Toast.LENGTH_SHORT).show(); - return; - } else { - infoPhoto.add(new Info(tagPanorama)); - } - String tagName = (String) ivName.getTag(); - if (tagName == null) { - Toast.makeText(getActivity(), "请拍照 名称照片", Toast.LENGTH_SHORT).show(); - return; - } else { - infoPhoto.add(new Info(tagName)); - } - if (existence == 0) { - String tagInternal = (String) ivInternal.getTag(); - if (tagInternal == null) { - Toast.makeText(getActivity(), "请拍照 服务说明", Toast.LENGTH_SHORT).show(); - return; - } else { - infoPhoto.add(new Info(tagInternal)); - } - String tagElse = (String) ivElse.getTag(); - if (tagElse == null) { - Toast.makeText(getActivity(), "请拍照 充电站指引牌", Toast.LENGTH_SHORT).show(); - return; - } else { - infoPhoto.add(new Info(tagElse)); - } - String tagScutcheon = (String) ivScutcheon.getTag(); - if (tagScutcheon == null) { - Toast.makeText(getActivity(), "请拍照 收费标牌", Toast.LENGTH_SHORT).show(); - return; - } else { - infoPhoto.add(new Info(tagScutcheon)); - } - } - poiEntity.setExistence(existence); - poiEntity.setPhotoInfo(infoPhoto); - poiEntity.setStation_type(station_type); - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - String format = formatter.format(calendar.getTime()); - poiEntity.setCreateTime(format); - poiEntity.setType(2); - poiEntity.setTaskStatus(2); - poiEntity.setIsLocalData(1); new Thread(new Runnable() { @Override public void run() { @@ -962,7 +920,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. } private void stationUploadByNetWork(PoiEntity poiEntity, ArrayList chargingStationList) { - showLoadingDialog(); + showFileLoadingDialog(); if (poiEntity == null || poiEntity.getBodyId() == 0) { Toast.makeText(getActivity(), "没有保存本地", Toast.LENGTH_SHORT).show(); Log.e("TAG", "poiUploadByNetWork: " + poiEntity.getBodyId() + chargingStationList); @@ -1106,30 +1064,38 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. @Override public void onSuccess(ChargingStationBean chargingStationBean, int id) { dismissLoadingDialog(); - bodyId = chargingStationBean.getBody(); - poiEntity.setBodyId(bodyId); - poiEntity.setTaskStatus(3); - new Thread(new Runnable() { - @Override - public void run() { - InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); - // 充电站数据已经保存在服务上,批量保存充电桩数据 - saveChargingPileByChargingStation(poiEntity); - getActivity().runOnUiThread(new Runnable() { + if (chargingStationBean.getCode() == 200) { + bodyId = chargingStationBean.getBody(); + if (bodyId != null && bodyId != 0) { + poiEntity.setBodyId(bodyId); + poiEntity.setTaskStatus(3); + new Thread(new Runnable() { @Override public void run() { - if (isLocal) { - stationUploadByNetWork(poiEntity, chargingStationList); + InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); + // 充电站数据已经保存在服务上,批量保存充电桩数据 + saveChargingPileByChargingStation(poiEntity); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + if (isLocal) { + stationUploadByNetWork(poiEntity, chargingStationList); // chargingPileUploadNetWork(chargingPileBody, fileList); - } else { - Toast.makeText(getActivity(), "保存成功", Toast.LENGTH_SHORT).show(); - onBackPressed(); - } - Log.d("TAG", "onSuccess: " + chargingStationBean.getBody()); + } else { + Toast.makeText(getActivity(), "保存成功", Toast.LENGTH_SHORT).show(); + onBackPressed(); + } + Log.d("TAG", "onSuccess: " + chargingStationBean.getBody()); + } + }); } - }); + }).start(); + } else { + Toast.makeText(getContext(), "" + chargingStationBean.getMessage(), Toast.LENGTH_SHORT).show(); } - }).start(); + } else { + Toast.makeText(getContext(), "" + chargingStationBean.getMessage(), Toast.LENGTH_SHORT).show(); + } } @Override @@ -1143,60 +1109,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. } private String initShowStation() { - PoiEntity poiEntity = showPoiEntity; - List infoPhoto = new ArrayList<>(); - String name = editNameContent.getText().toString().trim();//名称 - if (name != null && !name.equals("")) { - poiEntity.setName(name); - } - String site = editSiteContent.getText().toString().trim(); - if (site != null && !site.equals("")) { - poiEntity.setAddress(site); - } - if (latLng != null) { - poiEntity.setX(String.valueOf(latLng.longitude)); - poiEntity.setY(String.valueOf(latLng.latitude)); - } - String describe = editDescribe.getText().toString().trim(); - if (describe != null && !describe.equals("")) { - poiEntity.setMemo(describe); - } - boolean phoneBean = contactView.getPhoneBean(); - if (phoneBean) { - String list = contactView.getList(); - poiEntity.setTelPhone(list); - } - String tagPanorama = (String) ivPanorama.getTag(); - if (tagPanorama != null && !tagPanorama.equals("")) { - infoPhoto.add(new Info(tagPanorama)); - } - String tagName = (String) ivName.getTag(); - if (tagName != null && !tagName.equals("")) { - infoPhoto.add(new Info(tagName)); - } - String tagInternal = (String) ivInternal.getTag(); - if (tagInternal != null && !tagInternal.equals("")) { - infoPhoto.add(new Info(tagInternal)); - } - String tagElse = (String) ivElse.getTag(); - if (tagElse != null && !tagElse.equals("")) { - infoPhoto.add(new Info(tagElse)); - } - String tagScutcheon = (String) ivScutcheon.getTag(); - if (tagScutcheon != null && !tagScutcheon.equals("")) { - infoPhoto.add(new Info(tagScutcheon)); - } - poiEntity.setPhotoInfo(infoPhoto); - poiEntity.setStation_type(station_type); - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - String format = formatter.format(calendar.getTime()); - poiEntity.setCreateTime(format); - poiEntity.setExistence(existence); - poiEntity.setType(2); - poiEntity.setTaskStatus(2); - poiEntity.setIsLocalData(1); + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); String newPoiEntity = new Gson().toJson(poiEntity); return newPoiEntity; } @@ -1220,61 +1133,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. //获取Editor对象 SharedPreferences.Editor edit = poi.edit(); //根据要保存的数据的类型,调用对应的put方法, - - PoiEntity poiEntity = showPoiEntity; - List infoPhoto = new ArrayList<>(); - String name = editNameContent.getText().toString().trim();//名称 - if (name != null && !name.equals("")) { - poiEntity.setName(name); - } - String site = editSiteContent.getText().toString().trim(); - if (site != null && !site.equals("")) { - poiEntity.setAddress(site); - } - if (latLng != null) { - poiEntity.setX(String.valueOf(latLng.longitude)); - poiEntity.setY(String.valueOf(latLng.latitude)); - } - String describe = editDescribe.getText().toString().trim(); - if (describe != null && !describe.equals("")) { - poiEntity.setMemo(describe); - } - boolean phoneBean = contactView.getPhoneBean(); - if (phoneBean) { - String list = contactView.getList(); - poiEntity.setTelPhone(list); - } - String tagPanorama = (String) ivPanorama.getTag(); - if (tagPanorama != null && !tagPanorama.equals("")) { - infoPhoto.add(new Info(tagPanorama)); - } - String tagName = (String) ivName.getTag(); - if (tagName != null && !tagName.equals("")) { - infoPhoto.add(new Info(tagName)); - } - String tagInternal = (String) ivInternal.getTag(); - if (tagInternal != null && !tagInternal.equals("")) { - infoPhoto.add(new Info(tagInternal)); - } - String tagElse = (String) ivElse.getTag(); - if (tagElse != null && !tagElse.equals("")) { - infoPhoto.add(new Info(tagElse)); - } - String tagScutcheon = (String) ivScutcheon.getTag(); - if (tagScutcheon != null && !tagScutcheon.equals("")) { - infoPhoto.add(new Info(tagScutcheon)); - } - poiEntity.setPhotoInfo(infoPhoto); - poiEntity.setStation_type(station_type); - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - String format = formatter.format(calendar.getTime()); - poiEntity.setCreateTime(format); - poiEntity.setExistence(existence); - poiEntity.setType(2); - poiEntity.setTaskStatus(2); - poiEntity.setIsLocalData(1); + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); String newPoiEntity = new Gson().toJson(poiEntity); //以键值对的形式添加新值。 edit.putString("poiEntity", newPoiEntity); @@ -1287,11 +1146,13 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 101 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "a", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - ivPanorama.setTag(takePhotoPath); - ivPanorama.setImageBitmap(bitmap);//显示图像 + if (photoFile == null || !photoFile.exists()) { + ToastUtil.showShort(getActivity(), "取消拍照"); + return; + } + String photoPath = PhotoUtils.showPhotoAndGetPath(photoFile, ivPanorama); + tvPanorama.setTag(photoPath); + photoFile = null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1308,11 +1169,13 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. }*/ } else if (requestCode == 102 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "b", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - ivName.setTag(takePhotoPath); - ivName.setImageBitmap(bitmap);//显示图像 + if (photoFile == null || !photoFile.exists()) { + ToastUtil.showShort(getActivity(), "取消拍照"); + return; + } + String photoPath = PhotoUtils.showPhotoAndGetPath(photoFile, ivName); + tvName.setTag(photoPath); + photoFile = null; /*int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1329,11 +1192,13 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. }*/ } else if (requestCode == 103 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "c", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - ivInternal.setTag(takePhotoPath); - ivInternal.setImageBitmap(bitmap);//显示图像 + if (photoFile == null || !photoFile.exists()) { + ToastUtil.showShort(getActivity(), "取消拍照"); + return; + } + String photoPath = PhotoUtils.showPhotoAndGetPath(photoFile, ivInternal); + tvInternal.setTag(photoPath); + photoFile = null; /*int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1350,11 +1215,13 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. }*/ } else if (requestCode == 104 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "d", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - ivElse.setTag(takePhotoPath); - ivElse.setImageBitmap(bitmap);//显示图像 + if (photoFile == null || !photoFile.exists()) { + ToastUtil.showShort(getActivity(), "取消拍照"); + return; + } + String photoPath = PhotoUtils.showPhotoAndGetPath(photoFile, ivElse); + tvElse.setTag(photoPath); + photoFile = null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1371,11 +1238,13 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. }*/ } else if (requestCode == 105 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "e", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - ivScutcheon.setTag(takePhotoPath); - ivScutcheon.setImageBitmap(bitmap);//显示图像 + if (photoFile == null || !photoFile.exists()) { + ToastUtil.showShort(getActivity(), "取消拍照"); + return; + } + String photoPath = PhotoUtils.showPhotoAndGetPath(photoFile, ivScutcheon); + tvScutcheon.setTag(photoPath); + photoFile = null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1465,11 +1334,129 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. public void run() { PoiEntity poiDaoPoiEntity = poiDao.getPoiEntity(showPoiEntity.getId()); if (poiDaoPoiEntity != null) { - if (poiDaoPoiEntity.getTaskStatus()==5){ - poiDao.deletePoiEntity(poiDaoPoiEntity); - } + if (poiDaoPoiEntity.getTaskStatus() == 5) { + poiDao.deletePoiEntity(poiDaoPoiEntity); + } } } }).start(); } + + @Override + protected PoiEntity initPoiEntityByUI(PoiEntity poiEntity) { + List infoPhoto = new ArrayList<>(); + String name = editNameContent.getText().toString().trim();//名称 + if (name != null && !name.equals("")) { + poiEntity.setName(name); + } + String site = editSiteContent.getText().toString().trim(); + if (site != null && !site.equals("")) { + poiEntity.setAddress(site); + } + if (latLng != null) { + String encode = Geohash.getInstance().encode(latLng.latitude, latLng.longitude); + poiEntity.setGeoWkt(encode); + poiEntity.setX(String.valueOf(latLng.longitude)); + poiEntity.setY(String.valueOf(latLng.latitude)); + } + String describe = editDescribe.getText().toString().trim(); + if (describe != null && !describe.equals("")) { + poiEntity.setMemo(describe); + } + boolean phoneBean = contactView.getPhoneBean(); + if (phoneBean) { + String list = contactView.getList(); + poiEntity.setTelPhone(list); + } + String tagPanorama = (String) tvPanorama.getTag(); + if (tagPanorama != null && !tagPanorama.equals("")) { + infoPhoto.add(new Info(tagPanorama)); + } + String tagName = (String) tvName.getTag(); + if (tagName != null && !tagName.equals("")) { + infoPhoto.add(new Info(tagName)); + } + String tagInternal = (String) tvInternal.getTag(); + if (tagInternal != null && !tagInternal.equals("")) { + infoPhoto.add(new Info(tagInternal)); + } + String tagElse = (String) tvElse.getTag(); + if (tagElse != null && !tagElse.equals("")) { + infoPhoto.add(new Info(tagElse)); + } + String tagScutcheon = (String) tvScutcheon.getTag(); + if (tagScutcheon != null && !tagScutcheon.equals("")) { + infoPhoto.add(new Info(tagScutcheon)); + } + poiEntity.setPhotoInfo(infoPhoto); + poiEntity.setStation_type(station_type); + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + String format = formatter.format(calendar.getTime()); + poiEntity.setCreateTime(format); + poiEntity.setExistence(existence); + poiEntity.setType(2); + poiEntity.setTaskStatus(2); + poiEntity.setIsLocalData(1); + return poiEntity; + } + + @Override + protected PoiCheckResult checkPoiEntity(PoiEntity entity) { + PoiCheckResult poiCheckResult = new PoiCheckResult(); + if (entity.getName()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请输入 名称"); + return poiCheckResult; + } + if (tvPanorama.getTag()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请拍照 全景图"); + return poiCheckResult; + } + if (tvName.getTag()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请拍照 名称照片"); + return poiCheckResult; + } + if (entity.getExistence()==0){ + if (tvInternal.getTag()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请拍照 服务说明"); + return poiCheckResult; + } + if (tvElse.getTag()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请拍照 充电站指引牌"); + return poiCheckResult; + } + if (tvScutcheon.getTag()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请拍照 收费标牌"); + return poiCheckResult; + } + } + if (entity.getX()==null&&entity.getY()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请确定 点位"); + return poiCheckResult; + } + if (entity.getTelPhone()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请输入 手机号"); + return poiCheckResult; + } + return poiCheckResult; + } + + @Override + protected ChargingPileEntity initChargingPileEntityByUI(ChargingPileEntity entity) { + return null; + } + + @Override + protected PoiCheckResult checkChargingPileEntity(ChargingPileEntity entity) { + return null; + } } \ No newline at end of file diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/FilterFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/FilterFragment.java index 1b35622..b7b6f8b 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/FilterFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/FilterFragment.java @@ -23,6 +23,7 @@ import com.navinfo.outdoor.adapter.FilterAdapter; import com.navinfo.outdoor.api.Constant; import com.navinfo.outdoor.base.BaseDrawerFragment; import com.navinfo.outdoor.bean.JobSearchBean; +import com.navinfo.outdoor.room.ChargingPileEntity; import com.navinfo.outdoor.room.PoiDao; import com.navinfo.outdoor.room.PoiDatabase; import com.navinfo.outdoor.room.PoiEntity; @@ -293,14 +294,17 @@ public class FilterFragment extends BaseDrawerFragment implements View.OnClickLi @Override public void onClick(View v) { switch (v.getId()) { - case R.id.btn_filter: Message obtain = Message.obtain(); - obtain.what = Constant.FILTER_LIST; - obtain.obj = poiEntities; + obtain.what = Constant.TREASURE_FRAGMENT; + obtain.obj = true; EventBus.getDefault().post(obtain); - break; + Message mainButtonVisiableMsg = Message.obtain(); + mainButtonVisiableMsg.what = Constant.MAIN_BUTTON_VISIABLE; + mainButtonVisiableMsg.obj = View.VISIBLE; + EventBus.getDefault().post(mainButtonVisiableMsg); + break; case R.id.cl_number: BottomMenu.show((AppCompatActivity) getContext(), new String[]{"200", "500", "1000"}, new OnMenuItemClickListener() { @Override @@ -435,4 +439,23 @@ public class FilterFragment extends BaseDrawerFragment implements View.OnClickLi super.onDestroy(); } + @Override + protected PoiEntity initPoiEntityByUI(PoiEntity entity) { + return null; + } + @Override + protected PoiCheckResult checkPoiEntity(PoiEntity entity) { + return null; + } + + @Override + protected ChargingPileEntity initChargingPileEntityByUI(ChargingPileEntity entity) { + return null; + } + + @Override + protected PoiCheckResult checkChargingPileEntity(ChargingPileEntity entity) { + return null; + } + } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/ForgetPawFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/ForgetPawFragment.java index 5acb3b6..f1d77ef 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/ForgetPawFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/ForgetPawFragment.java @@ -2,21 +2,30 @@ package com.navinfo.outdoor.fragment; import android.os.Bundle; import android.view.View; +import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; +import com.lzy.okgo.model.HttpParams; import com.navinfo.outdoor.R; +import com.navinfo.outdoor.api.Constant; import com.navinfo.outdoor.base.BaseFragment; +import com.navinfo.outdoor.bean.UserBean; +import com.navinfo.outdoor.http.Callback; +import com.navinfo.outdoor.http.HttpInterface; +import com.navinfo.outdoor.http.OkGoBuilder; /** * 忘记密码页面 */ -public class ForgetPawFragment extends BaseFragment implements View.OnClickListener{ +public class ForgetPawFragment extends BaseFragment implements View.OnClickListener { private ImageView ivFinish; - private TextView title,tvForgetPaw, forgetPawGetNote; + private TextView forgetPawGetNote; private EditText etForgetPawPhone, etForgetPawNote, etForgetPawPaw, etForgetPawConfirmPaw; + private Button btnForgetPaw; + private String sessionId; public static ForgetPawFragment newInstance(Bundle bundle) { ForgetPawFragment fragment = new ForgetPawFragment(); @@ -33,30 +42,129 @@ public class ForgetPawFragment extends BaseFragment implements View.OnClickListe protected void initView() { super.initView(); ivFinish = findViewById(R.id.iv_forgePaw_finish); + ivFinish.setOnClickListener(this); etForgetPawPhone = findViewById(R.id.et_forgetPaw_phone); etForgetPawNote = findViewById(R.id.et_forgetPaw_note); etForgetPawPaw = findViewById(R.id.et_forgetPaw_paw); etForgetPawConfirmPaw = findViewById(R.id.et_forgetPaw_confirm_paw); forgetPawGetNote = findViewById(R.id.forgetPaw_get_note); - tvForgetPaw = findViewById(R.id.tv_forgetPaw); - ivFinish.setOnClickListener(this); forgetPawGetNote.setOnClickListener(this); + btnForgetPaw = findViewById(R.id.btn_forgetPaw); + btnForgetPaw.setOnClickListener(this::onClick); + + } - @Override - protected void initData() { - super.initData(); - } @Override public void onClick(View v) { - switch (v.getId()){ + switch (v.getId()) { case R.id.iv_forgePaw_finish: getActivity().finish(); break; case R.id.forgetPaw_get_note: - Toast.makeText(getActivity(), "忘记密码获取验证码", Toast.LENGTH_SHORT).show(); + initGetNote(); + break; + case R.id.btn_forgetPaw: + initForgetPaw(); break; } } + + private void initForgetPaw() { + HttpParams httpParams = new HttpParams(); + String mobile = etForgetPawPhone.getText().toString().trim(); + if (mobile == null || mobile.equals("")) { + Toast.makeText(getContext(), "请输入手机号", Toast.LENGTH_SHORT).show(); + return; + } else { + httpParams.put("mobile", mobile); + } + String code = etForgetPawNote.getText().toString().trim(); + if (code == null || code.equals("")) { + Toast.makeText(getContext(), "请获取短信验证码", Toast.LENGTH_SHORT).show(); + return; + } else { + httpParams.put("code", code); + } + String password = etForgetPawPaw.getText().toString().trim(); + if (password == null || password.equals("")) { + Toast.makeText(getContext(), "请输入密码", Toast.LENGTH_SHORT).show(); + return; + } else { + httpParams.put("password", password); + } + String conFirmPaw = etForgetPawConfirmPaw.getText().toString().trim(); + if (conFirmPaw == null || conFirmPaw.equals("")) { + Toast.makeText(getContext(), "请输入确认密码", Toast.LENGTH_SHORT).show(); + return; + } + if (!conFirmPaw.equals(password)) { + Toast.makeText(getContext(), "密码和确认密码请保持一致", Toast.LENGTH_SHORT).show(); + } + if (sessionId == null || sessionId.equals("")) { + Toast.makeText(getContext(), "请短信获取验证码", Toast.LENGTH_SHORT).show(); + return; + } else { + httpParams.put("sessionId", sessionId); + } + long time=System.currentTimeMillis(); + httpParams.put("datetime",time); + showLoadingDialog(); + OkGoBuilder.getInstance() + .Builder(getActivity()) + .url(HttpInterface.USER_FORGET_PASSWORD) + .token(null) + .params(httpParams) + .cls(UserBean.class) + .postRequest(new Callback() { + @Override + public void onSuccess(UserBean response, int id) { + dismissLoadingDialog(); + Toast.makeText(getActivity(), response.getMessage() + "", Toast.LENGTH_SHORT).show(); + + } + + @Override + public void onError(Throwable e, int id) { + dismissLoadingDialog(); + Toast.makeText(getActivity(), e.getMessage() + "", Toast.LENGTH_SHORT).show(); + } + }); + } + + private void initGetNote() { + HttpParams httpParams = new HttpParams(); + String mobile = etForgetPawPhone.getText().toString().trim(); + if (mobile == null || mobile.equals("")) { + Toast.makeText(getContext(), "请输入手机号", Toast.LENGTH_SHORT).show(); + return; + } else { + httpParams.put("telephone", mobile); + } + httpParams.put("type", 2); + showLoadingDialog(); + OkGoBuilder.getInstance() + .Builder(getActivity()) + .url(HttpInterface.USER_MESSAGE) + .cls(UserBean.class) + .token(Constant.ACCESS_TOKEN) + .params(httpParams) + .getRequest(new Callback() { + @Override + public void onSuccess(UserBean response, int id) { + dismissLoadingDialog(); + if (response.getCode() == 200) { + sessionId = String.valueOf(response.getBody()); + } + Toast.makeText(getActivity(), response.getMessage() + "", Toast.LENGTH_SHORT).show(); + } + + @Override + public void onError(Throwable e, int id) { + dismissLoadingDialog(); + Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show(); + } + }); + } } \ No newline at end of file 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 5120e82..7118112 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/GatherGetFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/GatherGetFragment.java @@ -27,6 +27,7 @@ import com.navinfo.outdoor.room.InsertAndUpdateUtils; import com.navinfo.outdoor.room.PoiDao; import com.navinfo.outdoor.room.PoiDatabase; import com.navinfo.outdoor.room.PoiEntity; +import com.navinfo.outdoor.util.Geohash; import com.navinfo.outdoor.util.GeometryTools; import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; @@ -131,22 +132,6 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe if (poiEntity.getDist() != null) { tvDistance.setText("距离:" + format5(Double.valueOf(poiEntity.getDist()) / 1000) + "km"); } - - if (poiEntity.getTaskStatus() < 2) { - double latitude = Constant.currentLocation.getLatitude(); - double longitude = Constant.currentLocation.getLongitude(); - LatLng startLatLng = new LatLng(latitude, longitude); //用户当前位置 - LatLng endLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); - double v = GeometryTools.distanceToDouble(startLatLng, endLatLng); - if (v > 5000) { - Message obtain = Message.obtain(); - obtain.what = Constant.EVENT_WORK_UNPOLYGON; - obtain.obj = true; - EventBus.getDefault().post(obtain); - } - } - - } int taskStatus = poiEntity.getTaskStatus(); initViewByTaskStatus(taskStatus); @@ -190,33 +175,26 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe switch (v.getId()) { case R.id.btn_cancel_get://结束领取 if (poiEntity != null) { - int type = poiEntity.getType(); - if (type == 6) { - initUnPolygonTask(HttpInterface.UNRECEIVED_POLYGON_TASK, poiEntity.getTaskId(), poiEntity); - } else { - new Thread(new Runnable() { - @Override - public void run() { - poiDao.deletePoiEntity(poiEntity); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - btnGetTask.setVisibility(View.VISIBLE); - btnCancelGet.setVisibility(View.GONE); - btnGather.setVisibility(View.VISIBLE); - btnFinishGather.setVisibility(View.GONE); - } - }); - } - }).start(); - } + initEndReceiveTask(HttpInterface.UNRECEIVED_POLYGON_TASK, poiEntity.getTaskId(), poiEntity); } break; case R.id.btn_get_task://领取任务 + /* if (poiEntity.getTaskStatus() < 2) { + double latitude = Constant.currentLocation.getLatitude(); + double longitude = Constant.currentLocation.getLongitude(); + LatLng startLatLng = new LatLng(latitude, longitude); //用户当前位置 + LatLng endLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); + double geometry = GeometryTools.distanceToDouble(startLatLng, endLatLng); + if (geometry > 5000) { + Toast.makeText(getActivity(), "作业不在领取范围内,无法领取", Toast.LENGTH_SHORT).show(); + return; + } + }*/ + if (poiEntity != null) { int type = poiEntity.getType(); if (type == 6) {//面状任务的领取类型 - initPolygonTask(HttpInterface.RECEIVED_POLYGON_TASK, poiEntity.getTaskId(), false, poiEntity); + initPolygonTask(HttpInterface.RECEIVED_POLYGON_TASK, poiEntity.getTaskId(), false); } else if (type == 1) {//poi的领取类型 receivedTaskByNet(HttpInterface.RECEIVED_POI_TASK, poiEntity.getTaskId(), false, poiEntity, 1); } else if (type == 2) {//充电站的领取类型 @@ -231,13 +209,24 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe } break; case R.id.btn_gather://立即采集 + if (poiEntity.getTaskStatus() < 2) { + double latitude = Constant.currentLocation.getLatitude(); + double longitude = Constant.currentLocation.getLongitude(); + LatLng startLatLng = new LatLng(latitude, longitude); //用户当前位置 + LatLng endLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); + double geometry = GeometryTools.distanceToDouble(startLatLng, endLatLng); + if (geometry > 5000) { + Toast.makeText(getActivity(), "作业不在领取范围内,无法领取", Toast.LENGTH_SHORT).show(); + return; + } + } if (poiEntity != null) { int type = poiEntity.getType(); if (type == 6) { int taskStatus = poiEntity.getTaskStatus(); if (taskStatus != 1) { - initPolygonTask(HttpInterface.RECEIVED_POLYGON_TASK, poiEntity.getTaskId(), true, poiEntity); + initPolygonTask(HttpInterface.RECEIVED_POLYGON_TASK, poiEntity.getTaskId(), true); } else { new Thread(new Runnable() { @Override @@ -327,7 +316,9 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe chargingStationEntity.setType(Integer.valueOf(stationBean.getType())); chargingStationEntity.setTaskStatus(statusId); chargingStationEntity.setIsLocalData(1); - String geo = stationBean.getGeo(); + + String encodeStr = stationBean.getGeo(); + String geo = Geohash.getInstance().decode(encodeStr); chargingStationEntity.setGeoWkt(geo); Geometry geometry = GeometryTools.createGeometry(geo); if (geometry.getGeometryType().equals("Point")) {//点 @@ -358,9 +349,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() { @@ -405,9 +397,9 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe /** * @param url 面妆任务领取任务 - * @param poiEntity + * @param */ - private void initPolygonTask(String url, int taskId, boolean aBoolean, PoiEntity poiEntity) { + private void initPolygonTask(String url, int taskId, boolean aBoolean) { if (taskId == 0) { Toast.makeText(getContext(), "无此任务", Toast.LENGTH_SHORT).show(); return; @@ -430,7 +422,8 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe polygonEntity.setTaskId(listBean.getId()); polygonEntity.setName(listBean.getName()); polygonEntity.setType(Integer.valueOf(listBean.getType())); - String geo = listBean.getGeo(); + String encodeStr = listBean.getGeo(); + String geo = Geohash.getInstance().decode(encodeStr); polygonEntity.setGeoWkt(geo); Geometry geometry = GeometryTools.createGeometry(geo); if (geometry.getGeometryType().equals("Point")) {//点 @@ -460,10 +453,6 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe if (aBoolean) { initCompleteTask(HttpInterface.COMPLETE, GatherGetFragment.this.poiEntity.getTaskId(), true, polygonEntity); } - Message obtain = Message.obtain(); - obtain.what = Constant.EVENT_WORK_UNPOLYGON; - obtain.obj = false; - EventBus.getDefault().post(obtain); } }); } @@ -482,21 +471,24 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe } /** - * @param url 面妆任务结束领取 + * @param url 所以类型的结束领取 * @param poiEntity */ - private void initUnPolygonTask(String url, int taskId, PoiEntity poiEntity) { + private void initEndReceiveTask(String url, int taskId, PoiEntity poiEntity) { if (taskId == 0) { Toast.makeText(getContext(), "无此任务", Toast.LENGTH_SHORT).show(); return; } showLoadingDialog(); + HttpParams httpParams = new HttpParams(); + httpParams.put("taskIds",taskId); + httpParams.put("auditIds",""); OkGoBuilder.getInstance() .Builder(getActivity()) - .url(url + "/" + taskId) + .url(url) + .params(httpParams) .cls(UnPolygonTaskBean.class) .token(Constant.ACCESS_TOKEN) - .params(new HttpParams()) .getRequest(new Callback() { @Override public void onSuccess(UnPolygonTaskBean response, int id) { @@ -509,11 +501,8 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe getActivity().runOnUiThread(new Runnable() { @Override public void run() { + Log.d("TAG", "run: "+response.getMessage()); initViewByTaskStatus(0); - Message obtain = Message.obtain(); - obtain.what = Constant.EVENT_WORK_UNPOLYGON; - obtain.obj = false; - EventBus.getDefault().post(obtain); } }); } @@ -558,16 +547,6 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe @Override public void run() { InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - initViewByTaskStatus(1); - Message obtain = Message.obtain(); - obtain.what = Constant.EVENT_WORK_UNPOLYGON; - obtain.obj = true; - EventBus.getDefault().post(obtain); - } - }); } }).start(); } @@ -607,16 +586,6 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe @Override public void run() { poiDao.deleteFormTaskID(taskId); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - initViewByTaskStatus(0); - Message obtain = Message.obtain(); - obtain.what = Constant.EVENT_WORK_UNPOLYGON; - obtain.obj = true; - EventBus.getDefault().post(obtain); - } - }); } }).start(); @@ -669,7 +638,8 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe poiListEntity.setIsExclusive(listBean.getIsExclusive()); poiListEntity.setTaskStatus(statusId); poiListEntity.setIsLocalData(1); - String geo = listBean.getGeo(); + String encodeStr = listBean.getGeo(); + String geo = Geohash.getInstance().decode(encodeStr); poiListEntity.setGeoWkt(geo); Geometry geometry = GeometryTools.createGeometry(geo); if (geometry.getGeometryType().equals("Point")) {//点 @@ -685,9 +655,12 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe poiListEntity.setX(latPolygon.get(0).longitude + ""); poiListEntity.setY(latPolygon.get(0).latitude + ""); } - // 通知地图界面显示当前编辑数据的marker - senMessageMarker(poiEntity.getType(), poiEntity.getY(), poiEntity.getX()); - InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiListEntity); + if (poiListEntity.getTaskStatus()!=1){ + // 通知地图界面显示当前编辑数据的marker + senMessageMarker(poiEntity.getType(), poiEntity.getY(), poiEntity.getX()); + InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiListEntity); + } + getActivity().runOnUiThread(new Runnable() { @Override public void run() { @@ -779,7 +752,8 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe poiListEntity.setIsExclusive(listBean.getIsExclusive()); poiListEntity.setTaskStatus(statusId); poiListEntity.setIsLocalData(1); - String geo = listBean.getGeo(); + String encodeStr = listBean.getGeo(); + String geo = Geohash.getInstance().decode(encodeStr); poiListEntity.setGeoWkt(geo); Geometry geometry = GeometryTools.createGeometry(geo); if (geometry.getGeometryType().equals("Point")) {//点 @@ -795,9 +769,12 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe poiListEntity.setX(latPolygon.get(0).longitude + ""); poiListEntity.setY(latPolygon.get(0).latitude + ""); } - // 通知地图界面显示当前编辑数据的marker - senMessageMarker(poiEntity.getType(), poiEntity.getY(), poiEntity.getX()); - InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiListEntity); + if (poiListEntity.getTaskStatus()!=1){ + // 通知地图界面显示当前编辑数据的marker + senMessageMarker(poiEntity.getType(), poiEntity.getY(), poiEntity.getX()); + InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiListEntity); + } + 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..e16d40e 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/GatheringFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/GatheringFragment.java @@ -1,9 +1,13 @@ package com.navinfo.outdoor.fragment; import android.app.Dialog; +import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; +import android.net.Uri; import android.os.Bundle; +import android.provider.MediaStore; import android.util.Log; import android.view.Gravity; import android.view.View; @@ -36,8 +40,10 @@ import com.navinfo.outdoor.bean.BankPathBean; import com.navinfo.outdoor.bean.BankPhoneBean; import com.navinfo.outdoor.http.DialogCallback; import com.navinfo.outdoor.http.HttpInterface; +import com.navinfo.outdoor.util.Geohash; import com.navinfo.outdoor.util.GetJsonDataUtil; import com.navinfo.outdoor.util.PhotoPathUtil; +import com.navinfo.outdoor.util.PhotoUtils; import org.json.JSONArray; @@ -61,6 +67,10 @@ public class GatheringFragment extends BaseFragment implements View.OnClickListe private ArrayList gatheringList; private ArrayList jsonBean; private String value; + private SharedPreferences navInfo; + private SharedPreferences.Editor navInfoEditor; + private File gatherFile; + private String file; public static GatheringFragment newInstance(Bundle bundle) { @@ -78,6 +88,8 @@ public class GatheringFragment extends BaseFragment implements View.OnClickListe @Override protected void initView() { super.initView(); + navInfoEditor = getActivity().getSharedPreferences("navInfo", Context.MODE_PRIVATE).edit(); + navInfo = getActivity().getSharedPreferences("navInfo", Context.MODE_PRIVATE); ivGathering = findViewById(R.id.iv_gathering); ivGathering.setOnClickListener(this::onClick); imageBank = findViewById(R.id.iv_bank); @@ -87,8 +99,9 @@ public class GatheringFragment extends BaseFragment implements View.OnClickListe btnBank = findViewById(R.id.btn_bank); btnBank.setOnClickListener(this::onClick); tvName = (TextView) findViewById(R.id.tv_name); - if (Constant.USER_ATTESTATION_NAME != null) { - tvName.setText(Constant.USER_ATTESTATION_NAME); + String attestationName = navInfo.getString("attestationName", null); + if (attestationName!= null&&!attestationName.equals("")) { + tvName.setText(attestationName); } etBankNum = (EditText) findViewById(R.id.et_bank_num); gatheringCamera = (ImageView) findViewById(R.id.gathering_camera); @@ -153,7 +166,7 @@ public class GatheringFragment extends BaseFragment implements View.OnClickListe } private void gatheringNetWork() { - showLoadingDialog(); + gatheringList = new ArrayList<>(); File gatheringFile = new File(gatheringPath); if (!gatheringFile.exists()) { @@ -166,7 +179,7 @@ public class GatheringFragment extends BaseFragment implements View.OnClickListe Toast.makeText(getContext(), "银行卡号不能为空", Toast.LENGTH_SHORT).show(); return; } - + showLoadingDialog(); OkGo // 请求方式和请求url .post(HttpInterface.USER_BANKCARD_UP_DATA) @@ -181,16 +194,17 @@ public class GatheringFragment extends BaseFragment implements View.OnClickListe public void onSuccess(Response response) { dismissLoadingDialog(); Log.d("TAG", "onSuccess: " + response.toString() + "sssssssssssss"); - if (response.body().equals("0")) { - MessageDialog.show((AppCompatActivity) getActivity(), "是否绑定银行卡", "取消", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { + if (response.code() == 200) { + MessageDialog.show((AppCompatActivity) getActivity(), "绑定成功", "确定", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(BaseDialog baseDialog, View v) { - // Toast.makeText(getContext(), "点击了确定", Toast.LENGTH_SHORT).show(); + navInfoEditor.putString("bankAccount",value); + navInfoEditor.commit(); return false; } }); } else { - MessageDialog.show((AppCompatActivity) getActivity(), "是否绑定银行卡", "确定", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { + MessageDialog.show((AppCompatActivity) getActivity(), "绑定失败", "取消", "取消", "确定").setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(BaseDialog baseDialog, View v) { // Toast.makeText(getContext(), "点击了确定", Toast.LENGTH_SHORT).show(); @@ -225,12 +239,15 @@ public class GatheringFragment extends BaseFragment implements View.OnClickListe @Override public boolean onClick(BaseDialog baseDialog, View v) { Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE"); + gatherFile = new File(Constant.PICTURE_FOLDER+"/aaaaaa.jpg"); + PhotoUtils.showPhotoFile("a", null); + intentPanorama.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(gatherFile)); startActivityForResult(intentPanorama, 400); return false; } }); } else { - gatheringPath = PhotoPathUtil.getTakePhotoPath(data, "", ""); + file = PhotoPathUtil.getTakePhotoPath(data, "", ""); } } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/HasSubmitFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/HasSubmitFragment.java index cbc17ba..91f7d76 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/HasSubmitFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/HasSubmitFragment.java @@ -161,7 +161,7 @@ public class HasSubmitFragment extends BaseFragment implements View.OnClickListe public void onError(Throwable e, int id) { dismissLoadingDialog(); Log.d("TAG", "onError: " + e.getMessage()); - Toast.makeText(getContext(), "请求失败", Toast.LENGTH_SHORT).show(); + Toast.makeText(getContext(), e.getMessage()+"", Toast.LENGTH_SHORT).show(); } }); } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java index 929a947..d3a83d2 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java @@ -4,8 +4,10 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.Color; +import android.net.Uri; import android.os.Bundle; import android.os.Message; +import android.provider.MediaStore; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -18,8 +20,10 @@ import android.widget.EditText; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.Spinner; +import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; @@ -46,12 +50,14 @@ import com.navinfo.outdoor.http.Callback; import com.navinfo.outdoor.http.DialogCallback; import com.navinfo.outdoor.http.HttpInterface; import com.navinfo.outdoor.http.OkGoBuilder; +import com.navinfo.outdoor.room.ChargingPileEntity; import com.navinfo.outdoor.room.InsertAndUpdateUtils; import com.navinfo.outdoor.room.PoiDao; import com.navinfo.outdoor.room.PoiDatabase; import com.navinfo.outdoor.room.PoiEntity; import com.navinfo.outdoor.util.Geohash; import com.navinfo.outdoor.util.PhotoPathUtil; +import com.navinfo.outdoor.util.PhotoUtils; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import org.greenrobot.eventbus.EventBus; @@ -77,8 +83,10 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis private EditText editTaskName, editOtherDescribe; private RelativeLayout rlPicture; private ImageView ivPicture; + private TextView tvPicture; private RelativeLayout rlPictures; private ImageView ivPictures; + private TextView tvPictures; private Button btnOtherLocal; private Button btnOtherUploading; private PoiDatabase poiDatabase; @@ -88,6 +96,7 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis private int station_type = 5; private ArrayList otherUploadList; private CheckBox checkPot; + private File file; public static OtherFragment newInstance(Bundle bundle) { OtherFragment fragment = new OtherFragment(); @@ -187,6 +196,8 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis rlPicture = findViewById(R.id.rl_picture); rlPicture.setOnClickListener(this::onClick); ivPicture = findViewById(R.id.iv_picture); + tvPicture = findViewById(R.id.tv_picture); + tvPictures = findViewById(R.id.tv_pictures); rlPictures = findViewById(R.id.rl_pictures); rlPictures.setOnClickListener(this::onClick); ivPictures = findViewById(R.id.iv_pictures); @@ -285,17 +296,16 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis }else if (station_type==7){ spinnerOther.setSelection(2, true); } - if (showPoiEntity.getPhotoInfo() != null) { for (int i = 0; i < showPoiEntity.getPhotoInfo().size(); i++) { String photo = showPoiEntity.getPhotoInfo().get(i).getPhoto(); String[] split = photo.split("/"); if (split[split.length - 1].startsWith("a")) { Glide.with(getActivity()).load(photo).into(ivPicture); - ivPicture.setTag(photo); + tvPicture.setTag(photo); } else if (split[split.length - 1].startsWith("b")) { Glide.with(getActivity()).load(photo).into(ivPictures); - ivPictures.setTag(photo); + tvPictures.setTag(photo); } } } @@ -311,13 +321,15 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis switch (v.getId()) { case R.id.rl_picture: Intent intentPicture = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("a", latLng); + intentPicture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentPicture, 101); - initOtherSharePre(); break; case R.id.rl_pictures: Intent intentPictures = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("b",latLng); + intentPictures.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentPictures, 102); - initOtherSharePre(); break; case R.id.btn_other_local: initPoiSaveLocal(false); @@ -340,7 +352,7 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis } else { otherUploadList.add(new File(tagPicture)); } - String tagPictures = (String) ivPictures.getTag(); + String tagPictures = (String) tvPictures.getTag(); if (tagPictures == null) { Toast.makeText(getActivity(), "请拍照", Toast.LENGTH_SHORT).show(); return; @@ -376,53 +388,12 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis public void onGranted(List permissions, boolean all) { if (all) { //保存数据库: - PoiEntity poiEntity = showPoiEntity; - List infoList = new ArrayList<>(); - String name = editTaskName.getText().toString().trim();//名称 - if (name == null || name.equals("")) { - Toast.makeText(getActivity(), "请输入poi 名称", Toast.LENGTH_SHORT).show(); + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); + PoiCheckResult poiCheckResult = checkPoiEntity(poiEntity); + if (poiCheckResult.getCode() == 1) { + Toast.makeText(getActivity(), poiCheckResult.getMsg()+"", Toast.LENGTH_SHORT).show(); return; - } else { - poiEntity.setName(name); } - - if (latLng == null) { - Toast.makeText(getActivity(), "请确定点位", Toast.LENGTH_SHORT).show(); - return; - } else { - String encode = Geohash.getInstance().encode(latLng.latitude, latLng.longitude); - poiEntity.setGeoWkt(encode); - poiEntity.setX(String.valueOf(latLng.longitude)); - poiEntity.setY(String.valueOf(latLng.latitude)); - } - String describe = editOtherDescribe.getText().toString().trim(); - if (describe != null&&!describe.equals("")) { - poiEntity.setMemo(describe); - } - String tagPicture = (String) ivPicture.getTag(); - if (tagPicture == null) { - Toast.makeText(getActivity(), "请 拍照", Toast.LENGTH_SHORT).show(); - return; - } else { - infoList.add(new Info(tagPicture)); - } - String tagPictures = (String) ivPictures.getTag(); - if (tagPictures == null) { - Toast.makeText(getActivity(), "请 拍照", Toast.LENGTH_SHORT).show(); - return; - } else { - infoList.add(new Info(tagPictures)); - } - poiEntity.setStation_type(station_type); - poiEntity.setPhotoInfo(infoList); - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - String format = formatter.format(calendar.getTime()); - poiEntity.setCreateTime(format); - poiEntity.setType(5); - poiEntity.setTaskStatus(2); - poiEntity.setIsLocalData(1); new Thread(new Runnable() { @Override public void run() { @@ -452,7 +423,6 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis } }); } - private void otherUploadByNet(int body, List otherUploadList) { if (body == 0) { Toast.makeText(getActivity(), "没有保存本地", Toast.LENGTH_SHORT).show(); @@ -518,26 +488,37 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis @Override public void onSuccess(PoiSaveBean poiSaveBean, int id) { dismissLoadingDialog(); - Integer body = poiSaveBean.getBody(); - poiEntity.setBodyId(body); - poiEntity.setTaskStatus(3); - new Thread(new Runnable() { - @Override - public void run() { - InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); - getActivity().runOnUiThread(new Runnable() { + if (poiSaveBean.getCode()==200){ + Integer body = poiSaveBean.getBody(); + if (body!=null&&body!=0){ + poiEntity.setBodyId(body); + poiEntity.setTaskStatus(3); + new Thread(new Runnable() { @Override public void run() { - if (isLocal){ - otherUploadByNet(body,otherUploadList); - }else { - Toast.makeText(getActivity(), "保存成功", Toast.LENGTH_SHORT).show(); - onBackPressed(); - } + InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + if (isLocal){ + otherUploadByNet(body,otherUploadList); + }else { + Toast.makeText(getActivity(), "保存成功", Toast.LENGTH_SHORT).show(); + onBackPressed(); + } + } + }); } - }); + }).start(); + }else { + Toast.makeText(getActivity(), ""+poiSaveBean.getMessage(), Toast.LENGTH_SHORT).show(); + } - }).start(); + }else { + Toast.makeText(getActivity(), ""+poiSaveBean.getMessage(), Toast.LENGTH_SHORT).show(); + } + + } @Override @@ -550,6 +531,11 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis dismissDialog(); } + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + initOtherSharePre(); + } /** * 防止当页面崩溃后出现数据丢失 */ @@ -562,39 +548,7 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis //获取Editor对象 SharedPreferences.Editor edit = poi.edit(); //根据要保存的数据的类型,调用对应的put方法, - PoiEntity poiEntity = showPoiEntity; - ArrayList arrayList = new ArrayList<>(); - String name = editTaskName.getText().toString().trim();//名称 - if (name != null && !name.equals("")) { - poiEntity.setName(name); - } - - if (latLng != null) { - poiEntity.setX(String.valueOf(latLng.longitude)); - poiEntity.setY(String.valueOf(latLng.latitude)); - } - String describe = editOtherDescribe.getText().toString().trim(); - if (describe != null && !describe.equals("")) { - poiEntity.setMemo(describe); - } - String tagPicture = (String) ivPicture.getTag(); - if (tagPicture != null && !tagPicture.equals("")) { - arrayList.add(new Info(tagPicture)); - } - String tagPictures = (String) ivPictures.getTag(); - if (tagPictures != null && !tagPictures.equals("")) { - arrayList.add(new Info(tagPictures)); - } - poiEntity.setPhotoInfo(arrayList); - poiEntity.setStation_type(station_type); - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - String format = formatter.format(calendar.getTime()); - poiEntity.setCreateTime(format); - poiEntity.setType(5); - poiEntity.setTaskStatus(2); - poiEntity.setIsLocalData(1); + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); String newPoiEntity = new Gson().toJson(poiEntity); //以键值对的形式添加新值。 edit.putString("poiEntity", newPoiEntity); @@ -607,50 +561,25 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 101 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - //照片路径 - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "a", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - ivPicture.setTag(takePhotoPath); - ivPicture.setImageBitmap(bitmap);//显示图像 - /* 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 intent = new Intent("android.media.action.IMAGE_CAPTURE"); - startActivityForResult(intent, 101); - return false; - } - }); - } else { - - - }*/ + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivPicture); + tvPicture.setTag(s); + } + file=null; } else if (requestCode == 102 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 //照片路径 - String takePhotoPath2 = PhotoPathUtil.getTakePhotoPath(data, "b", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - ivPictures.setTag(takePhotoPath2); - ivPictures.setImageBitmap(bitmap);//显示图像 - /*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 intent = new Intent("android.media.action.IMAGE_CAPTURE"); - startActivityForResult(intent, 102); - return false; - } - }); - } else { + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; - }*/ + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivPictures); + tvPictures.setTag(s); + } + file=null; } } @@ -672,4 +601,78 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis }).start(); } + @Override + protected PoiEntity initPoiEntityByUI(PoiEntity poiEntity) { + ArrayList arrayList = new ArrayList<>(); + String name = editTaskName.getText().toString().trim();//名称 + if (name != null && !name.equals("")) { + poiEntity.setName(name); + } + if (latLng != null) { + String encode = Geohash.getInstance().encode(latLng.latitude, latLng.longitude); + poiEntity.setGeoWkt(encode); + poiEntity.setX(String.valueOf(latLng.longitude)); + poiEntity.setY(String.valueOf(latLng.latitude)); + } + String describe = editOtherDescribe.getText().toString().trim(); + if (describe != null && !describe.equals("")) { + poiEntity.setMemo(describe); + } + String tagPicture = (String) tvPicture.getTag(); + if (tagPicture != null && !tagPicture.equals("")) { + arrayList.add(new Info(tagPicture)); + } + String tagPictures = (String) tvPictures.getTag(); + if (tagPictures != null && !tagPictures.equals("")) { + arrayList.add(new Info(tagPictures)); + } + poiEntity.setPhotoInfo(arrayList); + poiEntity.setStation_type(station_type); + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + String format = formatter.format(calendar.getTime()); + poiEntity.setCreateTime(format); + poiEntity.setType(5); + poiEntity.setTaskStatus(2); + poiEntity.setIsLocalData(1); + return poiEntity; + } + + @Override + protected PoiCheckResult checkPoiEntity(PoiEntity entity) { + PoiCheckResult poiCheckResult = new PoiCheckResult(); + if (entity.getName()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请输入 名称"); + return poiCheckResult; + } + if (tvPicture.getTag()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请 拍照"); + return poiCheckResult; + } + if ( tvPictures.getTag()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请 拍照"); + return poiCheckResult; + } + if (entity.getX()==null&&entity.getY()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请确定点位"); + return poiCheckResult; + } + return poiCheckResult; + } + + @Override + protected ChargingPileEntity initChargingPileEntityByUI(ChargingPileEntity entity) { + return null; + } + + @Override + protected PoiCheckResult checkChargingPileEntity(ChargingPileEntity entity) { + return null; + } + } \ No newline at end of file diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java index fe96a86..91343fe 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java @@ -4,8 +4,10 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.Color; +import android.net.Uri; import android.os.Bundle; import android.os.Message; +import android.provider.MediaStore; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -51,6 +53,7 @@ import com.navinfo.outdoor.http.Callback; import com.navinfo.outdoor.http.DialogCallback; import com.navinfo.outdoor.http.HttpInterface; import com.navinfo.outdoor.http.OkGoBuilder; +import com.navinfo.outdoor.room.ChargingPileEntity; import com.navinfo.outdoor.room.InsertAndUpdateUtils; import com.navinfo.outdoor.room.PoiDao; import com.navinfo.outdoor.room.PoiDatabase; @@ -59,6 +62,7 @@ import com.navinfo.outdoor.ui.view.ContactView; import com.navinfo.outdoor.util.Geohash; import com.navinfo.outdoor.util.NetWorkUtils; import com.navinfo.outdoor.util.PhotoPathUtil; +import com.navinfo.outdoor.util.PhotoUtils; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import org.greenrobot.eventbus.EventBus; @@ -82,6 +86,7 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe private EditText editDescribe; private RelativeLayout rlPanorama, rlName, rlInternalPhotos, rlCard, rlElse; private ImageView ivPanorama, ivName, ivInternal, ivCard, ivElse; + private TextView tvPanorama, tvName, tvInternal, tvCard, tvElse; public TextView tvExamine; private EditText editNameContent, editSiteContent; private ArrayList poiBeans; @@ -105,6 +110,7 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe private ContactView contactView; private ArrayList poiPicList; private String tagPanorama; + private File file; public static PoiFragment newInstance(Bundle bundle) { PoiFragment fragment = new PoiFragment(); @@ -190,11 +196,18 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe tvExamine.setOnClickListener(this::onClick); editDescribe = findViewById(R.id.edit_describe); ivPanorama = findViewById(R.id.iv_panorama); + tvPanorama = findViewById(R.id.tv_panorama); ivName = findViewById(R.id.iv_name); + tvName = findViewById(R.id.tv_name); ivInternal = findViewById(R.id.iv_internal); - linearContact = findViewById(R.id.linear_contact); + tvInternal = findViewById(R.id.tv_internal); + ivCard = findViewById(R.id.iv_card); + tvCard = findViewById(R.id.tv_card); + ivElse = findViewById(R.id.iv_else); + tvElse = findViewById(R.id.tv_else); + linearContact = findViewById(R.id.linear_contact); rlPanorama = findViewById(R.id.rl_panorama); rlPanorama.setOnClickListener(this::onClick); rlName = findViewById(R.id.rl_name); @@ -403,19 +416,19 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe String[] split = photo.split("/"); if (split[split.length - 1].startsWith("a")) { Glide.with(getActivity()).load(photo).into(ivPanorama); - ivPanorama.setTag(photo); + tvPanorama.setTag(photo); } else if (split[split.length - 1].startsWith("b")) { Glide.with(getActivity()).load(photo).into(ivName); - ivName.setTag(photo); + tvName.setTag(photo); } else if (split[split.length - 1].startsWith("c")) { Glide.with(getActivity()).load(photo).into(ivInternal); - ivInternal.setTag(photo); + tvInternal.setTag(photo); } else if (split[split.length - 1].startsWith("d")) { Glide.with(getActivity()).load(photo).into(ivCard); - ivCard.setTag(photo); + tvCard.setTag(photo); } else if (split[split.length - 1].startsWith("e")) { Glide.with(getActivity()).load(photo).into(ivElse); - ivElse.setTag(photo); + tvElse.setTag(photo); } } } @@ -509,7 +522,7 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe break; case R.id.btn_uploading: poiPicList = new ArrayList<>(); - String tagPanorama = (String) ivPanorama.getTag(); + String name = editNameContent.getText().toString().trim();//名称 if (name == null || name.equals("")) { Toast.makeText(getActivity(), "请输入poi 名称", Toast.LENGTH_SHORT).show(); @@ -519,13 +532,14 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe Toast.makeText(getActivity(), "请确定点位", Toast.LENGTH_SHORT).show(); return; } + String tagPanorama = (String) tvPanorama.getTag(); if (tagPanorama == null) { Toast.makeText(getActivity(), "请拍照", Toast.LENGTH_SHORT).show(); return; } else { poiPicList.add(new File(tagPanorama)); } - String tagName = (String) ivName.getTag(); + String tagName = (String)tvName.getTag(); if (tagName == null) { Toast.makeText(getActivity(), "请拍照", Toast.LENGTH_SHORT).show(); return; @@ -533,15 +547,15 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe poiPicList.add(new File(tagName)); } - String tagInternal = (String) ivInternal.getTag(); + String tagInternal = (String) tvInternal.getTag(); if (tagInternal != null) { poiPicList.add(new File(tagInternal)); } - String tagElse = (String) ivElse.getTag(); + String tagElse = (String) tvElse.getTag(); if (tagElse != null) { poiPicList.add(new File(tagElse)); } - String tagCard = (String) ivCard.getTag(); + String tagCard = (String) tvCard.getTag(); if (tagCard != null) { poiPicList.add(new File(tagCard)); } @@ -568,22 +582,32 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe break; case R.id.rl_panorama: Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("a", latLng);; + intentPanorama.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentPanorama, 101); break; case R.id.rl_name: Intent intentName = new Intent("android.media.action.IMAGE_CAPTURE"); + file =PhotoUtils.showPhotoFile("b", latLng); + intentName.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentName, 102); break; case R.id.rl_internal_photos: Intent intentInternal = new Intent("android.media.action.IMAGE_CAPTURE"); + file =PhotoUtils.showPhotoFile("c", latLng); + intentInternal.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentInternal, 103); break; case R.id.rl_card: Intent intentCard = new Intent("android.media.action.IMAGE_CAPTURE"); + file =PhotoUtils.showPhotoFile("d", latLng); + intentCard.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentCard, 104); break; case R.id.rl_else: Intent intentElse = new Intent("android.media.action.IMAGE_CAPTURE"); + file =PhotoUtils.showPhotoFile("e",latLng); + intentElse.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentElse, 105); break; } @@ -627,75 +651,12 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe public void onGranted(List permissions, boolean all) { if (all) { //保存数据库: - PoiEntity poiEntity = showPoiEntity; - ArrayList infoPhoto = new ArrayList<>(); - String name = editNameContent.getText().toString().trim();//名称 - if (name == null || name.equals("")) { - Toast.makeText(getActivity(), "请输入poi 名称", Toast.LENGTH_SHORT).show(); + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); + PoiCheckResult poiCheckResult = checkPoiEntity(poiEntity); + if (poiCheckResult.getCode() == 1) { + Toast.makeText(getActivity(), poiCheckResult.getMsg()+"", Toast.LENGTH_SHORT).show(); return; - } else { - poiEntity.setName(name); } - String site = editSiteContent.getText().toString().trim(); - if (site != null && !site.equals("")) { - poiEntity.setAddress(site); - } - if (latLng == null) { - Toast.makeText(getActivity(), "请确定点位", Toast.LENGTH_SHORT).show(); - return; - } else { - String encode = Geohash.getInstance().encode(latLng.latitude, latLng.longitude); - poiEntity.setGeoWkt(encode); - poiEntity.setX(String.valueOf(latLng.longitude)); - poiEntity.setY(String.valueOf(latLng.latitude)); - } - - String describe = editDescribe.getText().toString().trim(); - if (describe != null && !describe.equals("")) { - poiEntity.setMemo(describe); - } - boolean phoneBean = contactView.getPhoneBean(); - if (phoneBean) { - String list = contactView.getList(); - poiEntity.setTelPhone(list); - } - tagPanorama = (String) ivPanorama.getTag(); - if (tagPanorama == null) { - Toast.makeText(getActivity(), "请拍照 全景图", Toast.LENGTH_SHORT).show(); - return; - } else { - infoPhoto.add(new Info(tagPanorama)); - } - String tagName = (String) ivName.getTag(); - if (tagName == null) { - Toast.makeText(getActivity(), "请拍照 名称", Toast.LENGTH_SHORT).show(); - return; - } else { - infoPhoto.add(new Info(tagName)); - } - - String tagInternal = (String) ivInternal.getTag(); - if (tagInternal != null) { - infoPhoto.add(new Info(tagInternal)); - } - String tagElse = (String) ivElse.getTag(); - if (tagElse != null) { - infoPhoto.add(new Info(tagElse)); - } - String tagCard = (String) ivCard.getTag(); - if (tagCard != null) { - infoPhoto.add(new Info(tagCard)); - } - poiEntity.setPhotoInfo(infoPhoto); - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - String format = formatter.format(calendar.getTime()); - poiEntity.setCreateTime(format); - poiEntity.setExistence(existence); - poiEntity.setType(1); - poiEntity.setTaskStatus(2); - poiEntity.setIsLocalData(1); new Thread(new Runnable() { @Override public void run() { @@ -790,29 +751,36 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe @Override public void onSuccess(PoiSaveBean poiSaveBean, int id) { dismissLoadingDialog(); - Integer body = poiSaveBean.getBody(); - if (body!=null){ - poiEntity.setBodyId(body); - poiEntity.setTaskStatus(3); - new Thread(new Runnable() { - @Override - public void run() { - InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - if (isLocal) { - poiUploadByNetWork(body, poiPicList);//上传 - } else { - Toast.makeText(getActivity(), "保存成功", Toast.LENGTH_SHORT).show(); - onBackPressed(); + if (poiSaveBean.getCode()==200){ + Integer body = poiSaveBean.getBody(); + if (body!=null&&body!=0){ + poiEntity.setBodyId(body); + poiEntity.setTaskStatus(3); + new Thread(new Runnable() { + @Override + public void run() { + InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + if (isLocal) { + poiUploadByNetWork(body, poiPicList);//上传 + } else { + Toast.makeText(getActivity(), "保存成功", Toast.LENGTH_SHORT).show(); + onBackPressed(); + } } - } - }); - } - }).start(); + }); + } + }).start(); + }else { + Toast.makeText(getActivity(), ""+poiSaveBean.getMessage(), Toast.LENGTH_SHORT).show(); + } + }else { + Toast.makeText(getActivity(), ""+poiSaveBean.getMessage(), Toast.LENGTH_SHORT).show(); } + } @Override @@ -837,64 +805,7 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe //获取Editor对象 SharedPreferences.Editor edit = poi.edit(); //根据要保存的数据的类型,调用对应的put方法, - PoiEntity poiEntity = showPoiEntity; - ArrayList infoPhoto = new ArrayList<>(); - String name = editNameContent.getText().toString().trim();//名称 - if (name != null && !name.equals("")) { - poiEntity.setName(name); - } - String site = editSiteContent.getText().toString().trim(); - if (site != null && !site.equals("")) { - poiEntity.setAddress(site); - } - if (latLng != null) { - String encode = Geohash.getInstance().encode(latLng.latitude, latLng.longitude); - poiEntity.setGeoWkt(encode); - poiEntity.setX(String.valueOf(latLng.longitude)); - poiEntity.setY(String.valueOf(latLng.latitude)); - } - String describe = editDescribe.getText().toString().trim(); - if (describe != null && !describe.equals("")) { - poiEntity.setMemo(describe); - } - boolean phoneBean = contactView.getPhoneBean(); - if (phoneBean) { - String list = contactView.getList(); - poiEntity.setTelPhone(list); - } else { - Toast.makeText(getActivity(), "请输入手机号", Toast.LENGTH_SHORT).show(); - return; - } - String tagPanorama = (String) ivPanorama.getTag(); - if (tagPanorama != null && !tagPanorama.equals("")) { - infoPhoto.add(new Info(tagPanorama)); - } - String tagName = (String) ivName.getTag(); - if (tagName != null && !tagName.equals("")) { - infoPhoto.add(new Info(tagName)); - } - String tagInternal = (String) ivInternal.getTag(); - if (tagInternal != null && !tagInternal.equals("")) { - infoPhoto.add(new Info(tagInternal)); - } - String tagElse = (String) ivElse.getTag(); - if (tagElse != null && !tagElse.equals("")) { - infoPhoto.add(new Info(tagElse)); - } - String tagCard = (String) ivCard.getTag(); - if (tagCard != null && !tagCard.equals("")) { - infoPhoto.add(new Info(tagCard)); - } - poiEntity.setPhotoInfo(infoPhoto); - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - String format = formatter.format(calendar.getTime()); - poiEntity.setCreateTime(format); - poiEntity.setExistence(existence); - poiEntity.setType(1); - poiEntity.setTaskStatus(2); - poiEntity.setIsLocalData(1); + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); String newPoiEntity = new Gson().toJson(poiEntity); //以键值对的形式添加新值。 edit.putString("poiEntity", newPoiEntity); @@ -908,11 +819,14 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 101 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - String takePhotoPath1 = PhotoPathUtil.getTakePhotoPath(data, "a", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - ivPanorama.setTag(takePhotoPath1); - ivPanorama.setImageBitmap(bitmap);//显示图像 + if (file==null||!file.exists()){ + Toast.makeText(getActivity(), "请先拍照", Toast.LENGTH_SHORT).show(); + return; + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivPanorama); + tvPanorama.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -929,11 +843,16 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe }*/ } else if (requestCode == 102 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - String takePhotoPath2 = PhotoPathUtil.getTakePhotoPath(data, "b", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - ivName.setTag(takePhotoPath2); - ivName.setImageBitmap(bitmap);//显示图像 + + if (file==null||!file.exists()){ + Toast.makeText(getActivity(), "请先拍照", Toast.LENGTH_SHORT).show(); + return; + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivName); + tvName.setTag(s); + } + file=null; + /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -950,11 +869,14 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe }*/ } else if (requestCode == 103 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - String takePhotoPath3 = PhotoPathUtil.getTakePhotoPath(data, "c", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - ivInternal.setTag(takePhotoPath3); - ivInternal.setImageBitmap(bitmap);//显示图像 + if (file==null||!file.exists()){ + Toast.makeText(getActivity(), "请先拍照", Toast.LENGTH_SHORT).show(); + return; + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivInternal); + tvInternal.setTag(s); + } + file=null; /*int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -971,11 +893,14 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe }*/ } else if (requestCode == 104 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - String takePhotoPath4 = PhotoPathUtil.getTakePhotoPath(data, "d", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - ivCard.setTag(takePhotoPath4); - ivCard.setImageBitmap(bitmap);//显示图像 + if (file==null||!file.exists()){ + Toast.makeText(getActivity(), "请先拍照", Toast.LENGTH_SHORT).show(); + return; + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivCard); + tvCard.setTag(s); + } + file = null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -992,11 +917,14 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe }*/ } else if (requestCode == 105 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - String takePhotoPath5 = PhotoPathUtil.getTakePhotoPath(data, "e", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - ivElse.setTag(takePhotoPath5); - ivElse.setImageBitmap(bitmap);//显示图像 + if (file==null||!file.exists()){ + Toast.makeText(getActivity(), "请先拍照", Toast.LENGTH_SHORT).show(); + return; + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivElse); + tvElse.setTag(s); + } + file = null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1040,5 +968,106 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe }).start(); } + @Override + protected PoiEntity initPoiEntityByUI(PoiEntity poiEntity) { + ArrayList infoPhoto = new ArrayList<>(); + String name = editNameContent.getText().toString().trim();//名称 + if (name != null && !name.equals("")) { + poiEntity.setName(name); + } + String site = editSiteContent.getText().toString().trim(); + if (site != null && !site.equals("")) { + poiEntity.setAddress(site); + } + if (latLng != null) { + String encode = Geohash.getInstance().encode(latLng.latitude, latLng.longitude); + poiEntity.setGeoWkt(encode); + poiEntity.setX(String.valueOf(latLng.longitude)); + poiEntity.setY(String.valueOf(latLng.latitude)); + } + String describe = editDescribe.getText().toString().trim(); + if (describe != null && !describe.equals("")) { + poiEntity.setMemo(describe); + } + boolean phoneBean = contactView.getPhoneBean(); + if (phoneBean) { + String list = contactView.getList(); + poiEntity.setTelPhone(list); + + } + String tagPanorama = (String) tvPanorama.getTag(); + if (tagPanorama != null && !tagPanorama.equals("")) { + infoPhoto.add(new Info(tagPanorama)); + } + String tagName = (String) tvName.getTag(); + if (tagName != null && !tagName.equals("")) { + infoPhoto.add(new Info(tagName)); + } + String tagInternal = (String) tvInternal.getTag(); + if (tagInternal != null && !tagInternal.equals("")) { + infoPhoto.add(new Info(tagInternal)); + } + String tagElse = (String) tvElse.getTag(); + if (tagElse != null && !tagElse.equals("")) { + infoPhoto.add(new Info(tagElse)); + } + String tagCard = (String) tvCard.getTag(); + if (tagCard != null && !tagCard.equals("")) { + infoPhoto.add(new Info(tagCard)); + } + poiEntity.setPhotoInfo(infoPhoto); + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + String format = formatter.format(calendar.getTime()); + poiEntity.setCreateTime(format); + poiEntity.setExistence(existence); + poiEntity.setType(1); + poiEntity.setTaskStatus(2); + poiEntity.setIsLocalData(1); + return poiEntity; + } + + @Override + protected PoiCheckResult checkPoiEntity(PoiEntity entity) { + PoiCheckResult poiCheckResult = new PoiCheckResult(); + if (entity.getName()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请输入 名称"); + return poiCheckResult; + } + if (tvPanorama.getTag()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请 拍照"); + return poiCheckResult; + } + if (tvName.getTag()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请 拍照"); + return poiCheckResult; + } + if (entity.getX()==null&&entity.getY()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请确定 点位"); + return poiCheckResult; + } + if (entity.getTelPhone()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请输入 手机号"); + return poiCheckResult; + } + return poiCheckResult; + } + + @Override + protected ChargingPileEntity initChargingPileEntityByUI(ChargingPileEntity entity) { + return null; + } + + @Override + protected PoiCheckResult checkChargingPileEntity(ChargingPileEntity entity) { + return null; + } + } \ No newline at end of file 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 8d43d70..762c837 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java @@ -14,6 +14,7 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; +import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.RadioButton; import android.widget.RadioGroup; @@ -27,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; @@ -52,6 +54,7 @@ import com.navinfo.outdoor.http.Callback; import com.navinfo.outdoor.http.DialogCallback; import com.navinfo.outdoor.http.HttpInterface; import com.navinfo.outdoor.http.OkGoBuilder; +import com.navinfo.outdoor.room.ChargingPileEntity; import com.navinfo.outdoor.room.InsertAndUpdateUtils; import com.navinfo.outdoor.room.PoiDao; import com.navinfo.outdoor.room.PoiDatabase; @@ -61,6 +64,7 @@ import com.navinfo.outdoor.util.GeometryTools; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; import java.io.File; import java.text.DateFormat; @@ -81,7 +85,6 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick private RadioButton rbCar; private RadioButton rbBicycle; private RadioButton rbWalking; - private RadioButton rbManual; private EditText etDesc; private Button btnRoadSave; private RadioGroup rgType; @@ -91,6 +94,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick private Button btnPoiVideoUpload; private String videoPath; private File fileZip; + private FrameLayout fmPoiVideoPic; public static PoiVideoFragment newInstance(Bundle bundle) { PoiVideoFragment fragment = new PoiVideoFragment(); @@ -102,7 +106,14 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick protected int getLayout() { return R.layout.poi_video_fragment; } + @Override + public void onStart() { + super.onStart(); + if (!EventBus.getDefault().isRegistered(this)) {//加上判断 + EventBus.getDefault().register(this); + } + } @Override public void onResume() { super.onResume(); @@ -140,41 +151,45 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick rbCar = (RadioButton) findViewById(R.id.rb_car); rbBicycle = (RadioButton) findViewById(R.id.rb_bicycle); rbWalking = (RadioButton) findViewById(R.id.rb_walking); - rbManual = (RadioButton) findViewById(R.id.rb_manual); etDesc = (EditText) findViewById(R.id.et_desc); + fmPoiVideoPic = findViewById(R.id.fm_poi_video_picture); btnRoadSave = (Button) findViewById(R.id.btn_poi_video_save); btnRoadSave.setOnClickListener(this::onClick); btnPoiVideoUpload = findViewById(R.id.btn_poi_video_upload); btnPoiVideoUpload.setOnClickListener(this::onClick); rgType = (RadioGroup) findViewById(R.id.rg_type); - ivPoiVideoPicture.setOnClickListener(new View.OnClickListener() { + 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(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); Intent intent = new Intent(getContext(), PictureActivity.class); - intent.putExtra(Constant.INTENT_VIDEO_PATH, videoFile.getAbsolutePath()); + intent.putExtra("uuId", showPoiEntity.getId()); + intent.putExtra(Constant.INTENT_VIDEO_PATH, finalFile.getAbsolutePath()); startActivityForResult(intent, 0x101); } }); - ivPoiVideoPicture.setOnLongClickListener(new View.OnLongClickListener() { + fmPoiVideoPic.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) ivPoiVideoPicture.getTag(); - if (videoFile != null) { - videoFile.delete(); - //获取文件名 - String csvFileName = videoFile.getName() + ".txt"; - File cavFile = new File(videoFile.getParent(), csvFileName); - cavFile.delete(); - ivPoiVideoPicture.setImageDrawable(null); + List videoFiles = (List) fmPoiVideoPic.getTag(); + if (videoFiles!=null){ + for (int i = 0; i < videoFiles.size(); i++) { + //获取文件名 + String csvFileName = videoFiles.get(i).getName() + ".txt"; + File cavFile = new File(videoFiles.get(i).getParent(), csvFileName); + videoFiles.clear(); + cavFile.delete(); + ivPoiVideoPicture.setImageDrawable(null); + } } return false; } @@ -198,15 +213,30 @@ 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); - ivPoiVideoPicture.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.getPath().contains("0.mp4")&&!videoFile.getPath().contains("0.mp4.txt")){ + if (videoFile.exists() && !isImageLoad) { + // 使用glide加载视频的第一帧 + AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivPoiVideoPicture, 500); + isImageLoad = true; + } + } + + } + } + fmPoiVideoPic.setTag(videoFileList); } } } @@ -225,33 +255,20 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick btnRoadSave.setEnabled(false); rbCar.setEnabled(false); rbWalking.setEnabled(false); - rbManual.setEnabled(false); rbBicycle.setEnabled(false); } - - /** - * 获取本地视频的第一帧 - * - * @param localPath - * @return - */ - public Bitmap getLocalVideoBitmap(String localPath) { - Bitmap bitmap = null; - MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - try { - //根据文件路径获取缩略图 - retriever.setDataSource(localPath); - //获得第一帧图片 - bitmap = retriever.getFrameAtTime(); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } finally { - retriever.release(); + @Subscribe + public void onEvent(Message data) { + if (data.what == Constant.PICTURE_VIDEO_WORD) { + if ((boolean)data.obj){ + initPoiVideoSharePre(); + } } - return bitmap; } + + @Override public void onClick(View v) { switch (v.getId()) { @@ -260,35 +277,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()); +// 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"); + File finalFile = AWMp4ParserHelper.getInstance().obtainMp4FilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); + intent.putExtra(Constant.INTENT_VIDEO_PATH, finalFile.getAbsolutePath()); + intent.putExtra("uuId", showPoiEntity.getId()); startActivityForResult(intent, 0x101); - break; case R.id.btn_poi_video_upload: - ArrayList videoFileList = new ArrayList<>(); - if (ivPoiVideoPicture.getTag() != null) { - showLoadingDialog(); - File videoFile = (File) ivPoiVideoPicture.getTag(); - videoFileList.add(videoFile); - File file = new File(videoFile.getPath()+".txt"); - videoFileList.add(file); + showFileLoadingDialog(); + setLoadingDialogText("压缩中..."); + if (fmPoiVideoPic.getTag() != null) { + List videoFileList = (List) fmPoiVideoPic.getTag(); fileZip = new File(Constant.PICTURE_FOLDER, "files" + ".zip"); - ZipUtil.zipFiles(videoFileList, fileZip, null); new Thread(new Runnable() { @Override public void run() { + ZipUtil.zipFiles(videoFileList, fileZip, null); PoiEntity poiDaoPoiEntity = poiDao.getPoiEntity(showPoiEntity.getId()); if (poiDaoPoiEntity == null || poiDaoPoiEntity.getTaskStatus() == 1 || poiDaoPoiEntity.getTaskStatus() == 2 || poiDaoPoiEntity.getTaskStatus() == 0) { - dismissLoadingDialog(); - initPoiSaveLocal(true); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + dismissLoadingDialog(); + initPoiSaveLocal(true); + } + }); } else { getActivity().runOnUiThread(new Runnable() { @Override public void run() { + dismissLoadingDialog(); poiVideoUpload(poiDaoPoiEntity.getBodyId(), fileZip); } }); @@ -296,7 +317,8 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick } }).start(); - }else { + } else { + dismissLoadingDialog(); Toast.makeText(getContext(), "请录像", Toast.LENGTH_SHORT).show(); return; } @@ -305,97 +327,21 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick } public void initPoiSaveLocal(boolean isLocal) { - XXPermissions.with(getContext()) .permission(Permission.MANAGE_EXTERNAL_STORAGE) .request(new OnPermissionCallback() { @Override public void onGranted(List permissions, boolean all) { if (all) { - PoiEntity poiEntity = showPoiEntity; - String roadName = etRoadName.getText().toString().trim(); - if (roadName != null && !roadName.equals("")) { - poiEntity.setName(roadName + ""); - } else { - DateFormat formatters = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); - Calendar calendars = Calendar.getInstance(); - calendars.setTimeInMillis(System.currentTimeMillis()); - String formats = formatters.format(calendars.getTime()); - String city = Constant.currentLocation.getCity();//返回当前位置的城市. - String district = Constant.currentLocation.getDistrict();//返回当前位置的区县. - StringBuilder sb = new StringBuilder("poi录像上报"); - if (city != null && !"".equals(city)) { - sb.append("-"); - sb.append(city); - } - if (district != null && !"".equals(district)) { - sb.append(district); - } - sb.append("-").append(formats); - poiEntity.setName(sb.toString()); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - etRoadName.setText(sb); - etRoadName.setEnabled(false); - } - }); - } - int pictureType = getPictureType(); - if (pictureType == -1) { - Toast.makeText(getContext(), "请选择拍照方式", Toast.LENGTH_SHORT).show(); + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); + PoiCheckResult poiCheckResult = checkPoiEntity(poiEntity); + if (poiCheckResult.getCode() == 1) { + Toast.makeText(getActivity(), poiCheckResult.getMsg()+"", Toast.LENGTH_SHORT).show(); return; - } else { - poiEntity.setWork_type(pictureType); } - String desc = etDesc.getText().toString().trim(); - if (desc != null && !desc.equals("")) { - poiEntity.setMemo(desc); - } - if (showPoiEntity != null) { - if (showPoiEntity.getTaskId() != 0) { - poiEntity.setTaskId(showPoiEntity.getTaskId()); - } - } - File videoFile = (File) ivPoiVideoPicture.getTag(); - if (videoFile == null ) { - 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); - Log.d("TAG", "onGranted: " + lineString); - poiEntity.setGeoWkt(lineString); - } - - - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - String format = formatter.format(calendar.getTime()); - poiEntity.setCreateTime(format); - poiEntity.setType(3); - poiEntity.setTaskStatus(2); - poiEntity.setIsLocalData(1); new Thread(new Runnable() { @Override public void run() { -// InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); getActivity().runOnUiThread(new Runnable() { @Override @@ -423,6 +369,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick } + private void poiVideoUpload(int poiVideoBody, File fileZip) { if (poiVideoBody == 0) { Toast.makeText(getActivity(), "请先保存本地在上传", Toast.LENGTH_SHORT).show(); @@ -491,31 +438,34 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick @Override public void onSuccess(PoiVideoBean poiVideoBean, int id) { dismissLoadingDialog(); - Integer poiVideoBody = poiVideoBean.getBody(); - if (poiVideoBody != null && poiVideoBody != 0) { - poiEntity.setBodyId(poiVideoBody); - poiEntity.setTaskStatus(3); - new Thread(new Runnable() { - @Override - public void run() { - InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - if (isLocal) { - poiVideoUpload(poiVideoBody, fileZip); - } else { - Toast.makeText(getActivity(), "保存成功", Toast.LENGTH_SHORT).show(); - onBackPressed(); + if (poiVideoBean.getCode() == 200) { + Integer poiVideoBody = poiVideoBean.getBody(); + if (poiVideoBody != null && poiVideoBody != 0) { + poiEntity.setBodyId(poiVideoBody); + poiEntity.setTaskStatus(3); + new Thread(new Runnable() { + @Override + public void run() { + InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + if (isLocal) { + poiVideoUpload(poiVideoBody, fileZip); + } else { + Toast.makeText(getActivity(), "保存成功", Toast.LENGTH_SHORT).show(); + onBackPressed(); + } } - } - }); - } - }).start(); + }); + } + }).start(); + } else { + Toast.makeText(getActivity(), "" + poiVideoBean.getMessage(), Toast.LENGTH_SHORT).show(); + } } else { - Toast.makeText(getActivity(), ""+poiVideoBean.getMessage(), Toast.LENGTH_SHORT).show(); + Toast.makeText(getActivity(), "" + poiVideoBean.getMessage(), Toast.LENGTH_SHORT).show(); } - } @Override @@ -534,11 +484,12 @@ 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); - ivPoiVideoPicture.setTag(videoFile); + List videoFileListByUUID = AWMp4ParserHelper.getInstance().getVideoFileListByUUID(showPoiEntity.getId()); + fmPoiVideoPic.setTag(videoFileListByUUID); } } } @@ -562,28 +513,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick //获取Editor对象 SharedPreferences.Editor edit = poi.edit(); //根据要保存的数据的类型,调用对应的put方法, - - PoiEntity poiEntity = new PoiEntity(); - String roadName = etRoadName.getText().toString().trim(); - if (roadName != null && !roadName.equals("")) { - poiEntity.setName(roadName); - } - int pictureType = getPictureType(); - if (pictureType != -1) { - poiEntity.setWork_type(pictureType); - } - String desc = etDesc.getText().toString().trim(); - if (desc != null && !desc.equals("")) { - poiEntity.setMemo(desc); - } - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - String format = formatter.format(calendar.getTime()); - poiEntity.setCreateTime(format); - poiEntity.setType(3); - poiEntity.setTaskStatus(2); - poiEntity.setIsLocalData(1); + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); String newPoiEntity = new Gson().toJson(poiEntity); //以键值对的形式添加新值。 edit.putString("poiEntity", newPoiEntity); @@ -601,8 +531,6 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick return 1; } else if (rbWalking != null && rbWalking.isChecked()) { return 2; - } else if (rbManual != null && rbManual.isChecked()) { - return 3; } return -1; } @@ -618,9 +546,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick case 2: rbWalking.setChecked(true); break; - case 3: - rbManual.setChecked(true); - break; + } } @@ -633,12 +559,97 @@ 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); } } } }).start(); } + + @Override + protected PoiEntity initPoiEntityByUI(PoiEntity poiEntity) { + String roadName = etRoadName.getText().toString().trim(); + if (roadName != null && !roadName.equals("")) { + poiEntity.setName(roadName + ""); + } else { + DateFormat formatters = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); + Calendar calendars = Calendar.getInstance(); + calendars.setTimeInMillis(System.currentTimeMillis()); + String formats = formatters.format(calendars.getTime()); + String city = Constant.currentLocation.getCity();//返回当前位置的城市. + String district = Constant.currentLocation.getDistrict();//返回当前位置的区县. + StringBuilder sb = new StringBuilder("poi录像上报"); + if (city != null && !"".equals(city)) { + sb.append("-"); + sb.append(city); + } + if (district != null && !"".equals(district)) { + sb.append(district); + } + sb.append("-").append(formats); + poiEntity.setName(sb.toString()); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + etRoadName.setText(sb); + etRoadName.setEnabled(false); + } + }); + } + int pictureType = getPictureType(); + if (pictureType != -1) { + poiEntity.setWork_type(pictureType); + } + String desc = etDesc.getText().toString().trim(); + if (desc != null && !desc.equals("")) { + poiEntity.setDescribe(desc); + } + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + String format = formatter.format(calendar.getTime()); + poiEntity.setCreateTime(format); + poiEntity.setType(3); + poiEntity.setTaskStatus(2); + poiEntity.setIsLocalData(1); + if (fmPoiVideoPic.getTag() != null &&!((List) fmPoiVideoPic.getTag()).isEmpty()) { + List lineStringByVideoFileList = AWMp4ParserHelper.getInstance().getLineStringByVideoFileList((List) fmPoiVideoPic.getTag()); + String lineString = GeometryTools.getLineString(lineStringByVideoFileList); + Log.d("TAG", "onGranted: " + lineString); + String photoStr = AWMp4ParserHelper.getInstance().getVideoFileListStr((List) fmPoiVideoPic.getTag()); + poiEntity.setPhoto(photoStr); + if (lineString != null) { + poiEntity.setGeoWkt(lineString); + } + } + return poiEntity; + } + + @Override + protected PoiCheckResult checkPoiEntity(PoiEntity entity) { + PoiCheckResult poiCheckResult = new PoiCheckResult(); + if (entity.getPhoto()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请录像"); + return poiCheckResult; + } + if (entity.getWork_type()==-1){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请选择录像方式"); + return poiCheckResult; + } + return poiCheckResult; + } + + @Override + protected ChargingPileEntity initChargingPileEntityByUI(ChargingPileEntity entity) { + return null; + } + + @Override + protected PoiCheckResult checkChargingPileEntity(ChargingPileEntity entity) { + return null; + } } \ No newline at end of file diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/RegisterFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/RegisterFragment.java index a14c042..f11a7dd 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/RegisterFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/RegisterFragment.java @@ -3,23 +3,33 @@ package com.navinfo.outdoor.fragment; import android.content.Intent; import android.os.Bundle; import android.view.View; +import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; +import com.lzy.okgo.model.HttpParams; import com.navinfo.outdoor.R; import com.navinfo.outdoor.activity.LoginActivity; +import com.navinfo.outdoor.api.Constant; import com.navinfo.outdoor.base.BaseFragment; +import com.navinfo.outdoor.bean.UserBean; +import com.navinfo.outdoor.http.Callback; +import com.navinfo.outdoor.http.HttpInterface; +import com.navinfo.outdoor.http.OkGoBuilder; /** * 注册页面 */ -public class RegisterFragment extends BaseFragment implements View.OnClickListener{ +public class RegisterFragment extends BaseFragment implements View.OnClickListener { private EditText etRegisterPhone, etRegisterNote, etRegisterReferrer, etRegisterPaw, etRegisterConfirmPaw; - private ImageView ivRegisterCheck,ivFinish; - private TextView haveGoLogin, tvRegister,registerGetNote; + private ImageView ivRegisterCheck, ivFinish; + private TextView haveGoLogin, registerGetNote; + private Button btnRegister; + private String sessionId; public static RegisterFragment newInstance(Bundle bundle) { RegisterFragment fragment = new RegisterFragment(); @@ -35,18 +45,21 @@ public class RegisterFragment extends BaseFragment implements View.OnClickListen @Override protected void initView() { super.initView(); - ivFinish =findViewById(R.id.iv_register_finish); - etRegisterPhone =findViewById(R.id.et_register_phone); + ivFinish = findViewById(R.id.iv_register_finish); + ivFinish.setOnClickListener(this::onClick); + etRegisterPhone = findViewById(R.id.et_register_phone); etRegisterNote = findViewById(R.id.et_register_note); registerGetNote = findViewById(R.id.register_get_note); + registerGetNote.setOnClickListener(this::onClick); etRegisterReferrer = findViewById(R.id.et_register_referrer); - etRegisterPaw =findViewById(R.id.et_register_paw); + etRegisterPaw = findViewById(R.id.et_register_paw); etRegisterConfirmPaw = findViewById(R.id.et_register_confirm_paw); ivRegisterCheck = findViewById(R.id.iv_register_check); haveGoLogin = findViewById(R.id.have_go_login); - tvRegister =findViewById(R.id.tv_register); - ivFinish.setOnClickListener(this::onClick); haveGoLogin.setOnClickListener(this::onClick); + btnRegister = findViewById(R.id.btn_register); + btnRegister.setOnClickListener(this::onClick); + } @@ -57,7 +70,7 @@ public class RegisterFragment extends BaseFragment implements View.OnClickListen @Override public void onClick(View v) { - switch (v.getId()){ + switch (v.getId()) { case R.id.iv_register_finish: getActivity().finish(); break; @@ -65,6 +78,113 @@ public class RegisterFragment extends BaseFragment implements View.OnClickListen Intent registerLogin = new Intent(getActivity(), LoginActivity.class); startActivity(registerLogin); break; + case R.id.btn_register: + initRegister(); + case R.id.register_get_note: + initGetNote(); + break; } } + + private void initGetNote() { + HttpParams httpParams = new HttpParams(); + String mobile = etRegisterPhone.getText().toString().trim(); + if (mobile == null || mobile.equals("")) { + Toast.makeText(getContext(), "请输入手机号", Toast.LENGTH_SHORT).show(); + return; + } else { + httpParams.put("telephone", mobile); + } + httpParams.put("type", 1); + showLoadingDialog(); + OkGoBuilder.getInstance() + .Builder(getActivity()) + .url(HttpInterface.USER_MESSAGE) + .cls(UserBean.class) + .token(null) + .params(httpParams) + .getRequest(new Callback() { + @Override + public void onSuccess(UserBean response, int id) { + dismissLoadingDialog(); + if (response.getCode() == 200) { + sessionId = String.valueOf(response.getBody()); + } + Toast.makeText(getActivity(), response.getMessage()+ "", Toast.LENGTH_SHORT).show(); + } + + @Override + public void onError(Throwable e, int id) { + dismissLoadingDialog(); + Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show(); + } + }); + } + + private void initRegister() { + HttpParams httpParams = new HttpParams(); + String mobile = etRegisterPhone.getText().toString().trim(); + if (mobile == null || mobile.equals("")) { + Toast.makeText(getContext(), "请输入手机号", Toast.LENGTH_SHORT).show(); + return; + } else { + httpParams.put("mobile", mobile); + } + String code = etRegisterNote.getText().toString().trim(); + if (code == null || code.equals("")) { + Toast.makeText(getContext(), "请获取短信验证码", Toast.LENGTH_SHORT).show(); + return; + } else { + httpParams.put("code", code); + } + String password = etRegisterPaw.getText().toString().trim(); + if (password == null || password.equals("")) { + Toast.makeText(getContext(), "请输入密码", Toast.LENGTH_SHORT).show(); + return; + } else { + httpParams.put("password", password); + } + String conFirmPaw = etRegisterConfirmPaw.getText().toString().trim(); + if (conFirmPaw == null || conFirmPaw.equals("")) { + Toast.makeText(getContext(), "请输入确认密码", Toast.LENGTH_SHORT).show(); + return; + } + if (!conFirmPaw.equals(password)) { + Toast.makeText(getContext(), "密码和确认密码请保持一致", Toast.LENGTH_SHORT).show(); + } + if (sessionId == null||sessionId.equals("")) { + Toast.makeText(getContext(), "请短信获取验证码", Toast.LENGTH_SHORT).show(); + return; + } else { + httpParams.put("sessionId", sessionId); + } + long time=System.currentTimeMillis(); + httpParams.put("datetime",time); + showLoadingDialog(); + OkGoBuilder.getInstance() + .Builder(getActivity()) + .url(HttpInterface.USER_REGISTER) + .token(null) + .params(httpParams) + .cls(UserBean.class) + .postRequest(new Callback() { + @Override + public void onSuccess(UserBean response, int id) { + dismissLoadingDialog(); + if (response.getCode() == 200) { + Toast.makeText(getActivity(), response.getMessage() + "", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(getActivity(), response.getMessage() + "", Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void onError(Throwable e, int id) { + dismissLoadingDialog(); + Toast.makeText(getActivity(), e.getMessage() + "", Toast.LENGTH_SHORT).show(); + } + }); + + + } } \ No newline at end of file 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 0af73de..9ea8d90 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java @@ -14,6 +14,7 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; +import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.RadioButton; import android.widget.RadioGroup; @@ -24,13 +25,19 @@ 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; import com.github.lazylibrary.util.ZipUtil; 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; @@ -46,6 +53,7 @@ import com.navinfo.outdoor.http.Callback; import com.navinfo.outdoor.http.DialogCallback; import com.navinfo.outdoor.http.HttpInterface; import com.navinfo.outdoor.http.OkGoBuilder; +import com.navinfo.outdoor.room.ChargingPileEntity; import com.navinfo.outdoor.room.InsertAndUpdateUtils; import com.navinfo.outdoor.room.PoiDao; import com.navinfo.outdoor.room.PoiDatabase; @@ -55,6 +63,7 @@ import com.navinfo.outdoor.util.GeometryTools; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; import org.json.JSONException; import java.io.File; @@ -65,6 +74,8 @@ import java.util.Calendar; import java.util.Date; import java.util.List; +import okhttp3.OkHttpClient; + /** * 寻宝-点击上传弹窗-道路 */ @@ -76,7 +87,6 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList private RadioButton rbCar; private RadioButton rbBicycle; private RadioButton rbWalking; - private RadioButton rbManual; private EditText etDesc; private Button btnRoadSave; private RadioGroup rgType; @@ -84,8 +94,8 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList private PoiDao poiDao; private PoiEntity showPoiEntity; private Button roadUpload; - private String videoPath; private File fileZip; + private FrameLayout fmRoadPic; public static RoadFragment newInstance(Bundle bundle) { RoadFragment fragment = new RoadFragment(); @@ -98,6 +108,14 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList return R.layout.fragment_road; } + @Override + public void onStart() { + super.onStart(); + if (!EventBus.getDefault().isRegistered(this)) {//加上判断 + EventBus.getDefault().register(this); + } + + } @Override public void onResume() { super.onResume(); @@ -134,26 +152,62 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList rbCar = (RadioButton) findViewById(R.id.rb_car); rbBicycle = (RadioButton) findViewById(R.id.rb_bicycle); rbWalking = (RadioButton) findViewById(R.id.rb_walking); - rbManual = (RadioButton) findViewById(R.id.rb_manual); etDesc = (EditText) findViewById(R.id.et_desc); + fmRoadPic = findViewById(R.id.fm_road_picture); btnRoadSave = (Button) findViewById(R.id.btn_road_save); btnRoadSave.setOnClickListener(this::onClick); rgType = (RadioGroup) findViewById(R.id.rg_type); roadUpload = findViewById(R.id.road_upload); roadUpload.setOnClickListener(this::onClick); - ivRoadPicture.setOnClickListener(new View.OnClickListener() { + showPictureType(1); + fmRoadPic.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(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); Intent intent = new Intent(getContext(), PictureActivity.class); - intent.putExtra(Constant.INTENT_VIDEO_PATH, videoFile.getAbsolutePath()); + intent.putExtra(Constant.INTENT_VIDEO_PATH, finalFile.getAbsolutePath()); + intent.putExtra(Constant.INTENT_VIDEO_ORATATION, 0); + intent.putExtra("uuId", showPoiEntity.getId()); 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) { + List videoFiles = (List) fmRoadPic.getTag(); + if (videoFiles!=null){ + for (int i = 0; i < videoFiles.size(); i++) { + String csvFileName = videoFiles.get(i).getName() + ".txt"; + File cavFile = new File(videoFiles.get(i).getParent(), csvFileName); + videoFiles.clear(); + cavFile.delete(); + ivRoadPicture.setImageDrawable(null); + } + } +// 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(); //禁用可操作性控件 @@ -175,13 +229,28 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList if (describe != null && !describe.equals("")) { 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(), ivRoadPicture, 500); - ivRoadPicture.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.getPath().contains("0.mp4")&&!videoFile.getPath().contains("0.mp4.txt")){ + if (videoFile.exists() && !isImageLoad) { + // 使用glide加载视频的第一帧 + AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivRoadPicture, 500); + isImageLoad = true; + } + } + } + } + + fmRoadPic.setTag(videoFileList); } } } @@ -202,36 +271,16 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList btnRoadSave.setEnabled(false); rbCar.setEnabled(false); rbBicycle.setEnabled(false); - rbManual.setEnabled(false); rbWalking.setEnabled(false); } - @Override - protected void initData() { - super.initData(); - // infos = new ArrayList<>(); - } - - /** - * 获取本地视频的第一帧 - * - * @param localPath - * @return - */ - public Bitmap getLocalVideoBitmap(String localPath) { - Bitmap bitmap = null; - MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - try { - //根据文件路径获取缩略图 - retriever.setDataSource(localPath); - //获得第一帧图片 - bitmap = retriever.getFrameAtTime(); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } finally { - retriever.release(); + @Subscribe + public void onEvent(Message data) { + if (data.what == Constant.PICTURE_VIDEO_WORD) { + if ((boolean)data.obj){ + initRoadSharePre(); + } } - return bitmap; } @Override @@ -243,25 +292,25 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList case R.id.tv_pictures: // 根据用户点击的时间为视频名称赋值 - DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); - String videoFormatName = formatter.format(new Date()); +// 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"); + File finalFile = AWMp4ParserHelper.getInstance().obtainMp4FilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); + intent.putExtra(Constant.INTENT_VIDEO_PATH, finalFile.getAbsolutePath()); + intent.putExtra(Constant.INTENT_VIDEO_ORATATION, 0); + intent.putExtra("uuId", showPoiEntity.getId()); startActivityForResult(intent, 0x101); break; case R.id.road_upload: - ArrayList videoFileList = new ArrayList<>(); - if (ivRoadPicture.getTag() != null) { - showLoadingDialog(); - File videoFile = (File) ivRoadPicture.getTag(); - videoFileList.add(videoFile); - File file = new File(videoFile.getPath() + ".txt"); - videoFileList.add(file); + showFileLoadingDialog(); + setLoadingDialogText("压缩中..."); + if (fmRoadPic.getTag() != null) { + List videoFileList = (List) fmRoadPic.getTag(); fileZip = new File(Constant.PICTURE_FOLDER, "files" + ".zip"); - ZipUtil.zipFiles(videoFileList, fileZip, null); new Thread(new Runnable() { @Override public void run() { + ZipUtil.zipFiles(videoFileList, fileZip, null); PoiEntity poiDaoPoiEntity = poiDao.getPoiEntity(showPoiEntity.getId()); if (poiDaoPoiEntity == null || poiDaoPoiEntity.getTaskStatus() == 1 || poiDaoPoiEntity.getTaskStatus() == 2 || poiDaoPoiEntity.getTaskStatus() == 0) { dismissLoadingDialog(); @@ -270,6 +319,7 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList getActivity().runOnUiThread(new Runnable() { @Override public void run() { + dismissLoadingDialog(); poiVideoUpload(poiDaoPoiEntity.getBodyId(), fileZip); } }); @@ -278,10 +328,10 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList } }).start(); }else { + dismissLoadingDialog(); Toast.makeText(getContext(), "请录像", Toast.LENGTH_SHORT).show(); return; } - break; } @@ -294,83 +344,12 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList @Override public void onGranted(List permissions, boolean all) { if (all) { - PoiEntity poiEntity = showPoiEntity; - String roadName = etRoadName.getText().toString().trim(); - if (roadName != null && !roadName.equals("")) { - poiEntity.setName(roadName); - } else { - DateFormat formatters = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); - Calendar calendars = Calendar.getInstance(); - calendars.setTimeInMillis(System.currentTimeMillis()); - String formats = formatters.format(calendars.getTime()); - String city = Constant.currentLocation.getCity();//返回当前位置的城市. - String district = Constant.currentLocation.getDistrict();//返回当前位置的区县. - StringBuffer sb = new StringBuffer("道路录像上报"); - if (city != null && !"".equals(city)) { - sb.append("-"); - sb.append(city); - } - if (district != null && !"".equals(district)) { - sb.append(district); - } - sb.append("-").append(formats); - poiEntity.setName(sb.toString()); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - etRoadName.setText(sb); - etRoadName.setEnabled(false); - } - }); - } - String desc = etDesc.getText().toString().trim(); - if (desc != null && !desc.equals("")) { - poiEntity.setDescribe(desc); - } - if (showPoiEntity != null) { - if (showPoiEntity.getTaskId() != 0) { - poiEntity.setTaskId(showPoiEntity.getTaskId()); - } - } - if (ivRoadPicture.getTag() == null) { - Toast.makeText(getActivity(), "请录像", Toast.LENGTH_SHORT).show(); + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); + PoiCheckResult poiCheckResult = checkPoiEntity(poiEntity); + if (poiCheckResult.getCode() == 1) { + Toast.makeText(getActivity(), poiCheckResult.getMsg()+"", Toast.LENGTH_SHORT).show(); return; - } else { - File videoFile = (File) ivRoadPicture.getTag(); - 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); - Log.d("TAG", "onGranted: " + lineString); - poiEntity.setGeoWkt(lineString); } - int pictureType = getPictureType(); - if (pictureType == -1) { - Toast.makeText(getContext(), "请选择拍照方式", Toast.LENGTH_SHORT).show(); - return; - }else { - poiEntity.setWork_type(pictureType); - } - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - String format = formatter.format(calendar.getTime()); - poiEntity.setCreateTime(format); - poiEntity.setType(4); - poiEntity.setTaskStatus(2); - poiEntity.setIsLocalData(1); new Thread(new Runnable() { @Override public void run() { @@ -401,6 +380,9 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList }); } + + + private void poiVideoUpload(int body, File fileZip) { if (body == 0) { Toast.makeText(getContext(), "请先保存本地在上传", Toast.LENGTH_SHORT).show(); @@ -469,30 +451,35 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList @Override public void onSuccess(RoadSaveBean roadSaveBean, int id) { dismissLoadingDialog(); - Integer roadBody = roadSaveBean.getBody(); - if (roadBody!=null&&roadBody!=0){ - poiEntity.setBodyId(roadBody); - poiEntity.setTaskStatus(3); - new Thread(new Runnable() { - @Override - public void run() { - InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - if (isLocal) { - poiVideoUpload(roadBody, fileZip); - } else { - Toast.makeText(getActivity(), "保存成功", Toast.LENGTH_SHORT).show(); - onBackPressed(); - } - } - }); - } - }).start(); - }else { - Toast.makeText(getContext(), ""+roadSaveBean.getMessage(), Toast.LENGTH_SHORT).show(); - } + if (roadSaveBean.getCode()==200){ + Integer roadBody = roadSaveBean.getBody(); + if (roadBody!=null&&roadBody!=0){ + poiEntity.setBodyId(roadBody); + poiEntity.setTaskStatus(3); + new Thread(new Runnable() { + @Override + public void run() { + InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + if (isLocal) { + poiVideoUpload(roadBody, fileZip); + } else { + Toast.makeText(getActivity(), "保存成功", Toast.LENGTH_SHORT).show(); + onBackPressed(); + } + } + }); + } + }).start(); + }else { + Toast.makeText(getContext(), ""+roadSaveBean.getMessage(), Toast.LENGTH_SHORT).show(); + } + }else { + Toast.makeText(getContext(), ""+roadSaveBean.getMessage(), Toast.LENGTH_SHORT).show(); + } + } @@ -513,17 +500,43 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList if (requestCode == 0x101) { if (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(), ivRoadPicture, 500); - ivRoadPicture.setTag(videoFile); + 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); + File finalFile = AWMp4ParserHelper.getInstance().obtainMp4FilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); + intentPanorama.putExtra(Constant.INTENT_VIDEO_PATH, finalFile.getAbsolutePath()); + intentPanorama.putExtra(Constant.INTENT_VIDEO_ORATATION, 0); + startActivityForResult(intentPanorama, 0x101); + return false; + } + }); + return; + }else { + if (videoFile.exists()) { + AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivRoadPicture, 500); + List videoFileListByUUID = AWMp4ParserHelper.getInstance().getVideoFileListByUUID(showPoiEntity.getId()); + fmRoadPic.setTag(videoFileListByUUID); + } + } + } } } } } + @Override public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); @@ -542,33 +555,7 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList //获取Editor对象 SharedPreferences.Editor edit = poi.edit(); //根据要保存的数据的类型,调用对应的put方法, - - PoiEntity poiEntity = new PoiEntity(); - String roadName = etRoadName.getText().toString().trim(); - if (roadName != null && !roadName.equals("")) { - poiEntity.setName(roadName); - } - int pictureType = getPictureType(); - if (pictureType != -1) { - poiEntity.setWork_type(pictureType); - } - String desc = etDesc.getText().toString().trim(); - if (desc != null && !desc.equals("")) { - poiEntity.setDescribe(desc); - } - if (showPoiEntity != null) { - if (showPoiEntity.getTaskId() != 0) { - poiEntity.setTaskId(showPoiEntity.getTaskId()); - } - } - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - String format = formatter.format(calendar.getTime()); - poiEntity.setCreateTime(format); - poiEntity.setType(4); - poiEntity.setTaskStatus(2); - poiEntity.setIsLocalData(1); + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); String newPoiEntity = new Gson().toJson(poiEntity); //以键值对的形式添加新值。 edit.putString("poiEntity", newPoiEntity); @@ -585,8 +572,6 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList return 1; } else if (rbWalking != null && rbWalking.isChecked()) { return 2; - } else if (rbManual != null && rbManual.isChecked()) { - return 3; } return -1; } @@ -602,9 +587,7 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList case 2: rbWalking.setChecked(true); break; - case 3: - rbManual.setChecked(true); - break; + } } @@ -625,4 +608,90 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList } }).start(); } + + @Override + protected PoiEntity initPoiEntityByUI(PoiEntity poiEntity) { + String roadName = etRoadName.getText().toString().trim(); + if (roadName != null && !roadName.equals("")) { + poiEntity.setName(roadName); + } else { + DateFormat formatters = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); + Calendar calendars = Calendar.getInstance(); + calendars.setTimeInMillis(System.currentTimeMillis()); + String formats = formatters.format(calendars.getTime()); + String city = Constant.currentLocation.getCity();//返回当前位置的城市. + String district = Constant.currentLocation.getDistrict();//返回当前位置的区县. + StringBuffer sb = new StringBuffer("道路录像上报"); + if (city != null && !"".equals(city)) { + sb.append("-"); + sb.append(city); + } + if (district != null && !"".equals(district)) { + sb.append(district); + } + sb.append("-").append(formats); + poiEntity.setName(sb.toString()); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + etRoadName.setText(sb); + etRoadName.setEnabled(false); + } + }); + } + int pictureType = getPictureType(); + if (pictureType != -1) { + poiEntity.setWork_type(pictureType); + } + String desc = etDesc.getText().toString().trim(); + if (desc != null && !desc.equals("")) { + poiEntity.setDescribe(desc); + } + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + String format = formatter.format(calendar.getTime()); + poiEntity.setCreateTime(format); + poiEntity.setType(4); + poiEntity.setTaskStatus(2); + poiEntity.setIsLocalData(1); + if (fmRoadPic.getTag() != null &&!((List) fmRoadPic.getTag()).isEmpty()) { + List lineStringByVideoFileList = AWMp4ParserHelper.getInstance().getLineStringByVideoFileList((List) fmRoadPic.getTag()); + String lineString = GeometryTools.getLineString(lineStringByVideoFileList); + Log.d("TAG", "onGranted: " + lineString); + String photoStr = AWMp4ParserHelper.getInstance().getVideoFileListStr((List) fmRoadPic.getTag()); + poiEntity.setPhoto(photoStr); + if (lineString != null) { + poiEntity.setGeoWkt(lineString); + } + } + return poiEntity; + } + + @Override + protected PoiCheckResult checkPoiEntity(PoiEntity entity) { + PoiCheckResult poiCheckResult = new PoiCheckResult(); + if (entity.getPhoto()==null){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请录像"); + return poiCheckResult; + } + if (entity.getWork_type()==-1){ + poiCheckResult.setCode(1); + poiCheckResult.setMsg("请选择录像方式"); + return poiCheckResult; + } + + return poiCheckResult; + } + + @Override + protected ChargingPileEntity initChargingPileEntityByUI(ChargingPileEntity entity) { + return null; + } + + @Override + protected PoiCheckResult checkChargingPileEntity(ChargingPileEntity entity) { + return null; + } } \ No newline at end of file diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/StaySubmitFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/StaySubmitFragment.java index a086bbd..7acd63b 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/StaySubmitFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/StaySubmitFragment.java @@ -23,11 +23,16 @@ import com.kongzue.dialog.util.BaseDialog; import com.kongzue.dialog.util.DialogSettings; import com.kongzue.dialog.v3.BottomMenu; import com.kongzue.dialog.v3.MessageDialog; +import com.lzy.okgo.model.HttpParams; import com.navinfo.outdoor.R; import com.navinfo.outdoor.activity.FragmentManagement; import com.navinfo.outdoor.adapter.StaySubmitAdapter; import com.navinfo.outdoor.api.Constant; import com.navinfo.outdoor.base.BaseFragment; +import com.navinfo.outdoor.bean.UnPolygonTaskBean; +import com.navinfo.outdoor.http.Callback; +import com.navinfo.outdoor.http.HttpInterface; +import com.navinfo.outdoor.http.OkGoBuilder; import com.navinfo.outdoor.room.PoiDao; import com.navinfo.outdoor.room.PoiDatabase; import com.navinfo.outdoor.room.PoiEntity; @@ -38,6 +43,7 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; /** @@ -62,6 +68,7 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList fragment.setArguments(bundle); return fragment; } + @Override public void onStart() { super.onStart(); @@ -72,7 +79,6 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList } - @Override protected int getLayout() { return R.layout.fragment_stay_submit; @@ -122,18 +128,13 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList }); refreshData(); } + @Subscribe public void onEvent(Message data) { if (data.what == Constant.EVENT_STAY_REFRESH) { - if ((boolean)data.obj){ - Toast.makeText(getContext(), "提交成功", Toast.LENGTH_SHORT).show(); - }else { - Toast.makeText(getContext(), "提交失败", Toast.LENGTH_SHORT).show(); - } + Toast.makeText(getContext(), (String) data.obj, Toast.LENGTH_SHORT).show(); dismissLoadingDialog(); refreshData(); - - } } @@ -202,27 +203,26 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList MessageDialog.show((AppCompatActivity) getContext(), "提示", "是否删除", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(BaseDialog baseDialog, View v) { - staySubmitAdapter.setAllCheckedDelete(); - refreshData(); + initRequest(staySubmitAdapter.getAllRoad()); return false; } }); break; case R.id.btn_stay_submit://提交 - if (poiEntities==null){ + if (poiEntities == null) { poiEntities = new ArrayList<>(); } poiEntities.clear(); List allRoad = staySubmitAdapter.getAllRoad(); for (int i = 0; i < allRoad.size(); i++) { - if (allRoad.get(i).isChecked()){ + if (allRoad.get(i).isChecked()) { poiEntities.add(allRoad.get(i)); } } - if (poiEntities.size()>0){ - showLoadingDialog(); + if (poiEntities.size() > 0) { + showFileLoadingDialog(); PoiSaveUtils.getInstance(getActivity()).uploadPoiEntityBatch(poiEntities); - }else { + } else { Toast.makeText(getContext(), "请选择要删除的条目数据", Toast.LENGTH_SHORT).show(); } @@ -230,32 +230,99 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList } } + private void initRequest(List allRoad) { + showLoadingDialog(); + new Thread(new Runnable() { + @Override + public void run() { + ArrayList poiEntities = new ArrayList<>(); + synchronized (allRoad) { + Iterator iterator = allRoad.iterator(); + while (iterator.hasNext()) { + PoiEntity poiEntity = (PoiEntity) iterator.next(); + if (poiEntity.isChecked()) { + poiEntities.add(poiEntity); + } + } + ; + } + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + String taskIds = ""; + String auditIds = ""; + for (int i = 0; i < poiEntities.size(); i++) { + if (poiEntities.get(i).getTaskStatus() == 2) { + taskIds += poiEntities.get(i).getTaskId()+","; + } else if (poiEntities.get(i).getTaskStatus() == 3) { + auditIds += poiEntities.get(i).getBodyId()+","; + } + } + if (taskIds!=null&&!taskIds.equals("")){ + taskIds = taskIds.substring(0,taskIds.length() - 1); + } + if (auditIds!=null&&!auditIds.equals("")){ + auditIds = auditIds.substring(0,auditIds.length() - 1); + } + HttpParams httpParams = new HttpParams(); + httpParams.put("taskIds", taskIds); + httpParams.put("auditIds", auditIds); + OkGoBuilder.getInstance() + .Builder(getActivity()) + .url(HttpInterface.UNRECEIVED_POLYGON_TASK) + .params(httpParams) + .token(Constant.ACCESS_TOKEN) + .cls(UnPolygonTaskBean.class) + .getRequest(new Callback() { + @Override + public void onSuccess(UnPolygonTaskBean response, int id) { + dismissLoadingDialog(); + if (response.getCode()==200){ + staySubmitAdapter.setAllCheckedDelete(); + } + Toast.makeText(getContext(), response.getMessage() + "", Toast.LENGTH_SHORT).show(); + } + + @Override + public void onError(Throwable e, int id) { + dismissLoadingDialog(); + Toast.makeText(getContext(), e.getMessage() + "", Toast.LENGTH_SHORT).show(); + + } + }); + } + }); + } + }).start(); + } + public void refreshData() { if (roadEntities == null) { roadEntities = new ArrayList<>(); - }else { + } else { roadEntities.clear(); } if (newEntities == null) { newEntities = new ArrayList<>(); - }else { - newEntities.clear(); + } else { + newEntities.clear(); } new Thread(new Runnable() { @Override public void run() { - List roadAll = roadDao.getAllPoi(); + List roadAll = roadDao.getAllPoiByRecoder(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { roadEntities.clear(); - for (int i = 0; i < roadAll.size(); i++) { - if (roadAll.get(i).getType()!=6){ - roadEntities.add(roadAll.get(i)); - } - } + roadEntities.addAll(roadAll); +// for (int i = 0; i < roadAll.size(); i++) { +// if (roadAll.get(i).getType()!=6){ +// roadEntities.add(roadAll.get(i)); +// } +// } Log.d("TAG", "run: " + roadEntities.toString()); staySubmitAdapter.setAllRoad(roadEntities); staySubmitAdapter.notifyDataSetChanged(); diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java index 12e022d..c489f5a 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java @@ -160,7 +160,6 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen bitmapDescriptor3 = BitmapDescriptorFactory.fromResource(R.mipmap.datouzhen); bitmapDescriptor4 = BitmapDescriptorFactory.fromResource(R.mipmap.datouzhen); bitmapDescriptor5 = BitmapDescriptorFactory.fromResource(R.mipmap.datouzhen); - EventBus.getDefault().register(this); //fragment 管理器 supportFragmentManager = getActivity().getSupportFragmentManager(); @@ -243,7 +242,6 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen dismissLoadingDialog(); refreshFilterData(); } - @Override public void onCancel() { } @@ -334,14 +332,12 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen } else { Toast.makeText(getActivity(), "数据为空", Toast.LENGTH_SHORT).show(); } - } return false; } }); } }); - // 设置地图宽高为屏幕的宽高 int[] widtHeight = DensityUtil.getDeviceInfo(getActivity()); treasureMap.getLayoutParams().width = widtHeight[0]; @@ -384,7 +380,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen e.printStackTrace(); } } - private void initList (TencentLocation tencentLocation){ + private void initList(TencentLocation tencentLocation) { int task_type = Constant.TASK_TYPE; int limit_type = Constant.LIMIT_TTPE; int taskStatus = Constant.TASK_STASTUS; @@ -433,7 +429,10 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen List list = response.getBody().getList(); for (int i = 0; i < list.size(); i++) { JobSearchBean.BodyBean.ListBean listBean = list.get(i); - String geo = list.get(i).getGeo(); + 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; @@ -564,384 +563,393 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen } }); dismissDialog(); - } + } - public void initMarker (PoiEntity poiEntity){ - sliding_layout.setPanelHeight(0); - sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN); - for (int i = 0; i < removablesMarker.size(); i++) { - removablesMarker.get(i).remove(); + public void initMarker(PoiEntity poiEntity) { + sliding_layout.setPanelHeight(0); + sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN); + for (int i = 0; i < removablesMarker.size(); i++) { + removablesMarker.get(i).remove(); + } + removablesMarker.clear(); + String geo = poiEntity.getGeoWkt(); + Log.d("TAG", "onSuccess: " + geo); + Geometry geometry = GeometryTools.createGeometry(geo); + LatLng latLng = null; + if (geometry.getGeometryType().equals("Point")) {//点 + latLng = GeometryTools.createLatLng(geo); + } else if (geometry.getGeometryType().equals("LineString")) {//线 + List latLineString = GeometryTools.getLatLngs(geo); + // 构造 PolylineOpitons + PolylineOptions polylineOptions = new PolylineOptions() + .addAll(latLineString) + // 折线设置圆形线头 + .lineCap(true) + // 折线的颜色为绿色 + .color(0xff00ff00) + // 折线宽度为5像素 + .width(25) + // 还可以添加描边颜色 + .borderColor(0xffff0000) + // 描边颜色的宽度,线宽还是 25 像素,不过填充的部分宽度为 `width` - 2 * `borderWidth` + .borderWidth(1); + // 绘制折线 + Polyline polyline = tencentMap.addPolyline(polylineOptions); + polyline.setZIndex(3); + removablesMarker.add(polyline); + if (latLineString != null && latLineString.size() > 0) { + latLng = latLineString.get(0); + } + } else if (geometry.getGeometryType().equals("Polygon")) {//面 + List latPolygon = GeometryTools.getLatLngs(geo); + Polygon polygon = tencentMap.addPolygon(new PolygonOptions(). + //连接封闭图形的点 + addAll(latPolygon). + //填充颜色为浅蓝色 + fillColor(Color.parseColor("#97E0E7EC")). + //边线颜色为黑色 + strokeColor(0xff000000). + //边线宽度15像素 + strokeWidth(25)); + + polygon.setZIndex(1); + removablesMarker.add(polygon); + com.vividsolutions.jts.geom.Point centroid = geometry.getCentroid(); + double x = centroid.getX(); + double y = centroid.getY(); + if (centroid != null) { + latLng = new LatLng(); + latLng.setLatitude(y); + latLng.setLongitude(x); } - removablesMarker.clear(); - String geo = poiEntity.getGeoWkt(); - Log.d("TAG", "onSuccess: " + geo); - Geometry geometry = GeometryTools.createGeometry(geo); - LatLng latLng = null; - if (geometry.getGeometryType().equals("Point")) {//点 - latLng = GeometryTools.createLatLng(geo); - } else if (geometry.getGeometryType().equals("LineString")) {//线 - List latLineString = GeometryTools.getLatLngs(geo); - // 构造 PolylineOpitons - PolylineOptions polylineOptions = new PolylineOptions() - .addAll(latLineString) - // 折线设置圆形线头 - .lineCap(true) - // 折线的颜色为绿色 - .color(0xff00ff00) - // 折线宽度为5像素 - .width(25) - // 还可以添加描边颜色 - .borderColor(0xffff0000) - // 描边颜色的宽度,线宽还是 25 像素,不过填充的部分宽度为 `width` - 2 * `borderWidth` - .borderWidth(1); - // 绘制折线 - Polyline polyline = tencentMap.addPolyline(polylineOptions); - polyline.setZIndex(3); - removablesMarker.add(polyline); - if (latLineString != null && latLineString.size() > 0) { - latLng = latLineString.get(0); - } - } else if (geometry.getGeometryType().equals("Polygon")) {//面 - List latPolygon = GeometryTools.getLatLngs(geo); - Polygon polygon = tencentMap.addPolygon(new PolygonOptions(). - //连接封闭图形的点 - addAll(latPolygon). - //填充颜色为红色 - fillColor(Color.parseColor("#97E0E7EC")). - //边线颜色为黑色 - strokeColor(0xff000000). - //边线宽度15像素 - strokeWidth(25)); - polygon.setZIndex(1); - removablesMarker.add(polygon); - com.vividsolutions.jts.geom.Point centroid = geometry.getCentroid(); - double x = centroid.getX(); - double y = centroid.getY(); - if (centroid != null) { - latLng = new LatLng(); - latLng.setLatitude(y); - latLng.setLongitude(x); - } /* if (latPolygon != null && latPolygon.size() > 0) { latLng = latPolygon.get(0); }*/ - } - BitmapDescriptor descriptor = null; - if (poiEntity.getType() == 1) { - descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_bags); - } else if (poiEntity.getType() == 2) { - descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_charge_bags); - } else if (poiEntity.getType() == 3) { - descriptor = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_bag); - } else if (poiEntity.getType() == 4) { - descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_road_bag); - } else if (poiEntity.getType() == 5) { - descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_other_bag); - } else if (poiEntity.getType() == 6) { - descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_bag); - } - if (bigMarker == null) { - bigMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(descriptor).alpha(0.9f) - .flat(true) - .clockwise(false)); - } else { - bigMarker.setPosition(latLng); - bigMarker.setIcon(descriptor); - } - bigMarker.setVisible(true); - bigMarker.setClickable(false); - bigMarker.setZIndex(4); - frameLayout.setVisibility(View.VISIBLE); - setMainButtonVisiable(View.GONE); - fragmentTransaction = supportFragmentManager.beginTransaction(); - Bundle bundle = new Bundle(); - bundle.putSerializable("poiEntity", poiEntity); - gatherGetFragment = GatherGetFragment.newInstance(bundle); - fragmentTransaction.replace(R.id.frame_layout, gatherGetFragment); - fragmentTransaction.commit(); } + BitmapDescriptor descriptor = null; + if (poiEntity.getType()==1){ + descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_bags); + }else if (poiEntity.getType()==2){ + descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_charge_bags); + }else if (poiEntity.getType()==3){ + descriptor = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_bag); + }else if (poiEntity.getType()==4){ + descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_road_bag); + }else if (poiEntity.getType()==5){ + descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_other_bag); + }else if (poiEntity.getType()==6){ + descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_bag); + } + if (bigMarker == null) { + bigMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(descriptor).alpha(0.9f) + .flat(true) + .clockwise(false)); + } else { + bigMarker.setPosition(latLng); + bigMarker.setIcon(descriptor); + } + bigMarker.setVisible(true); + bigMarker.setClickable(false); + bigMarker.setZIndex(4); + frameLayout.setVisibility(View.VISIBLE); + setMainButtonVisiable(View.GONE); + fragmentTransaction = supportFragmentManager.beginTransaction(); + Bundle bundle = new Bundle(); + bundle.putSerializable("poiEntity", poiEntity); + gatherGetFragment = GatherGetFragment.newInstance(bundle); + fragmentTransaction.replace(R.id.frame_layout, gatherGetFragment); + fragmentTransaction.commit(); + } - private void initThread () { - int taskStatus = Constant.TASK_STASTUS; - int type = Constant.TASK_TYPE; - int limit = Constant.LIMIT_TTPE; - new Thread(new Runnable() { - @Override - public void run() { - List allTaskStatus = poiDao.getAllTaskStatus(taskStatus, taskStatus, type, type, limit, limit); - //List allTaskStatus = poiDao.getAllPoi(); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - for (int i = 0; i < removablesLocality.size(); i++) { - removablesLocality.get(i).remove(); - } - removablesLocality.clear(); - for (int i = 0; i < allTaskStatus.size(); i++) { - PoiEntity poiEntity = allTaskStatus.get(i); - String geo = allTaskStatus.get(i).getGeoWkt(); - LatLng latLng = null; - Log.d("TAG", "onSuccess: " + geo); - Geometry geometry = GeometryTools.createGeometry(geo); - if (geometry != null) { - if (geometry.getGeometryType().equals("Point")) {//点 - latLng = GeometryTools.createLatLng(geo); - } else if (geometry.getGeometryType().equals("LineString")) {//线 - List latLineString = GeometryTools.getLatLngs(geo); - // 构造 PolylineOpitons - PolylineOptions polylineOptions = new PolylineOptions() - .addAll(latLineString) - // 折线设置圆形线头 - .lineCap(true) - .color(0xffff0000) - // 折线宽度为5像素 - .width(5) - // 还可以添加描边颜色 - .borderColor(0xffff0000) - // 描边颜色的宽度,线宽还是 25 像素,不过填充的部分宽度为 `width` - 2 * `borderWidth` - .borderWidth(1); - // 绘制折线 - Polyline polyline = tencentMap.addPolyline(polylineOptions); - polyline.setZIndex(3); - removablesLocality.add(polyline); - if (latLineString != null && latLineString.size() > 0) { - latLng = latLineString.get(0); - } - } else if (geometry.getGeometryType().equals("Polygon")) {//面 - List latPolygon = GeometryTools.getLatLngs(geo); - Polygon polygon = tencentMap.addPolygon(new PolygonOptions(). - //连接封闭图形的点 - addAll(latPolygon). - //填充颜色为红色 - fillColor(Color.parseColor("#97E0E74C")). - //边线颜色为黑色 - strokeColor(0xff00ff00). - //边线宽度15像素 - strokeWidth(5)); - polygon.setZIndex(1); - removablesLocality.add(polygon); - com.vividsolutions.jts.geom.Point centroid = geometry.getCentroid(); - double x = centroid.getX(); - double y = centroid.getY(); - if (centroid != null) { - latLng = new LatLng(); - latLng.setLatitude(y); - latLng.setLongitude(x); - } + private void initThread() { + int taskStatus = Constant.TASK_STASTUS; + int type = Constant.TASK_TYPE; + int limit = Constant.LIMIT_TTPE; + if (taskStatus == 0) { + Message obtain = Message.obtain(); + obtain.what = Constant.JOB_SEARCH_POI_WORD; + obtain.obj = null; + EventBus.getDefault().post(obtain); + return; + } + new Thread(new Runnable() { + @Override + public void run() { + List allTaskStatus = poiDao.getAllTaskStatus(taskStatus, taskStatus, type, type, limit, limit); + //List allTaskStatus = poiDao.getAllPoi(); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + for (int i = 0; i < removablesLocality.size(); i++) { + removablesLocality.get(i).remove(); + } + removablesLocality.clear(); + for (int i = 0; i < allTaskStatus.size(); i++) { + PoiEntity poiEntity = allTaskStatus.get(i); + String geo = allTaskStatus.get(i).getGeoWkt(); + LatLng latLng = null; + Log.d("TAG", "onSuccess: " + geo); + Geometry geometry = GeometryTools.createGeometry(geo); + if (geometry != null) { + if (geometry.getGeometryType().equals("Point")) {//点 + latLng = GeometryTools.createLatLng(geo); + } else if (geometry.getGeometryType().equals("LineString")) {//线 + List latLineString = GeometryTools.getLatLngs(geo); + // 构造 PolylineOpitons + PolylineOptions polylineOptions = new PolylineOptions() + .alpha(0.5f) + + .addAll(latLineString) + // 折线设置圆形线头 + .lineCap(true) + .color(0xffff0000) + // 折线宽度为5像素 + .width(5) + // 还可以添加描边颜色 + .borderColor(0xffff0000) + // 描边颜色的宽度,线宽还是 25 像素,不过填充的部分宽度为 `width` - 2 * `borderWidth` + .borderWidth(1); + // 绘制折线 + Polyline polyline = tencentMap.addPolyline(polylineOptions); + polyline.setZIndex(3); + removablesLocality.add(polyline); + if (latLineString != null && latLineString.size() > 0) { + latLng = latLineString.get(0); + } + } else if (geometry.getGeometryType().equals("Polygon")) {//面 + List latPolygon = GeometryTools.getLatLngs(geo); + Polygon polygon = tencentMap.addPolygon(new PolygonOptions(). + //连接封闭图形的点 + addAll(latPolygon). + //填充颜色为浅蓝色 + fillColor(Color.parseColor("#97E0E7EC")). + //边线颜色为黑色 + strokeColor(0xff00ff00). + //边线宽度15像素 + strokeWidth(5)); + polygon.setZIndex(1); + removablesLocality.add(polygon); + com.vividsolutions.jts.geom.Point centroid = geometry.getCentroid(); + double x = centroid.getX(); + double y = centroid.getY(); + if (centroid != null) { + latLng = new LatLng(); + latLng.setLatitude(y); + latLng.setLongitude(x); + } /* if (latPolygon != null && latPolygon.size() > 0) { latLng = latPolygon.get(0); }*/ - } - } else { - if (allTaskStatus.get(i).getX() != null && allTaskStatus.get(i).getY() != null) { - latLng = new LatLng(Double.valueOf(allTaskStatus.get(i).getY()), Double.valueOf(allTaskStatus.get(i).getX())); - } } - switch (Integer.valueOf(poiEntity.getType())) { - case 1://poi - BitmapDescriptor poiDescriptor = null; - if (poiEntity.getTaskStatus() == 1) { - poiDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_bg1); - } else { - poiDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.graypoi); - } - Marker poiMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiDescriptor).alpha(0.9f) - .flat(true) - .clockwise(false)); - poiMarker.setClickable(true); - poiMarker.setZIndex(2); - poiMarker.setTitle(poiEntity.getName() + ""); - poiMarker.setTag(poiEntity); - removablesLocality.add(poiMarker); - - - break; - case 2://充电站 - BitmapDescriptor chargeDescriptor = null; - if (poiEntity.getTaskStatus() == 1) { - chargeDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_charge_bg1); - } else { - chargeDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.graycharge); - } - Marker stationMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(chargeDescriptor).alpha(0.9f) - .flat(true) - .clockwise(false)); - stationMarker.setClickable(true); - stationMarker.setZIndex(2); - stationMarker.setTitle(poiEntity.getName() + ""); - stationMarker.setTag(poiEntity); - removablesLocality.add(stationMarker); - break; - case 3://poi录像 - BitmapDescriptor poiVideoDescriptor = null; - if (poiEntity.getTaskStatus() == 1) { - poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_video_bg1); - } else { - poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_have_bg); - } - Marker poiVideoMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiVideoDescriptor).alpha(0.9f) - .flat(true) - .clockwise(false)); - poiVideoMarker.setClickable(true); - poiVideoMarker.setZIndex(2); - poiVideoMarker.setTitle(poiEntity.getName() + ""); - poiVideoMarker.setTag(poiEntity); - removablesLocality.add(poiVideoMarker); - break; - case 4://道路录像 - BitmapDescriptor roadDescriptor = null; - if (poiEntity.getTaskStatus() == 1) { - roadDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_road_bg); - } else { - roadDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.grayroad); - } - Marker roadMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(roadDescriptor).alpha(0.9f) - .flat(true) - .clockwise(false)); - roadMarker.setClickable(true); - roadMarker.setZIndex(2); - roadMarker.setTitle(poiEntity.getName() + ""); - roadMarker.setTag(poiEntity); - removablesLocality.add(roadMarker); - break; - case 5://其他 - BitmapDescriptor otherDescriptor = null; - if (poiEntity.getTaskStatus() == 1) { - otherDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_other_bg1); - } else { - otherDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.grayother); - } - Marker otherMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(otherDescriptor).alpha(0.9f) - .flat(true) - .clockwise(false)); - otherMarker.setClickable(true); - otherMarker.setZIndex(2); - otherMarker.setTitle(poiEntity.getName() + ""); - otherMarker.setTag(poiEntity); - removablesLocality.add(otherMarker); - break; - case 6://面状任务 - BitmapDescriptor Descriptor = null; - if (poiEntity.getTaskStatus() == 1) { - Descriptor = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_bg); - } else { - Descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_other_have_bag); - } - Marker planarMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(Descriptor).alpha(0.9f) - .clockwise(false) - .flat(true)); - planarMarker.setClickable(true); - planarMarker.setZIndex(2); - planarMarker.setTitle(poiEntity.getName() + ""); - planarMarker.setTag(poiEntity); - removablesLocality.add(planarMarker); - break; + } else { + if (allTaskStatus.get(i).getX() != null && allTaskStatus.get(i).getY() != null) { + latLng = new LatLng(Double.valueOf(allTaskStatus.get(i).getY()), Double.valueOf(allTaskStatus.get(i).getX())); } } - Message obtain = Message.obtain(); - obtain.what = Constant.JOB_SEARCH_POI_WORD; - obtain.obj = allTaskStatus; - EventBus.getDefault().post(obtain); + switch (Integer.valueOf(poiEntity.getType())) { + case 1://poi + BitmapDescriptor poiDescriptor=null; + if (poiEntity.getTaskStatus()==1){ + poiDescriptor= BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_bg1); + }else { + poiDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.graypoi); + } + Marker poiMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiDescriptor).alpha(0.9f) + .flat(true) + .clockwise(false)); + poiMarker.setClickable(true); + poiMarker.setZIndex(2); + poiMarker.setTitle(poiEntity.getName() + ""); + poiMarker.setTag(poiEntity); + removablesLocality.add(poiMarker); + break; + case 2://充电站 + BitmapDescriptor chargeDescriptor = null; + if (poiEntity.getTaskStatus()==1){ + chargeDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_charge_bg1); + }else { + chargeDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.graycharge); + } + Marker stationMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(chargeDescriptor).alpha(0.9f) + .flat(true) + .clockwise(false)); + stationMarker.setClickable(true); + stationMarker.setZIndex(2); + stationMarker.setTitle(poiEntity.getName() + ""); + stationMarker.setTag(poiEntity); + removablesLocality.add(stationMarker); + break; + case 3://poi录像 + BitmapDescriptor poiVideoDescriptor = null; + if (poiEntity.getTaskStatus()==1){ + poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_video_bg1); + }else { + poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_have_bg); + } + Marker poiVideoMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiVideoDescriptor).alpha(0.9f) + .flat(true) + .clockwise(false)); + poiVideoMarker.setClickable(true); + poiVideoMarker.setZIndex(2); + poiVideoMarker.setTitle(poiEntity.getName() + ""); + poiVideoMarker.setTag(poiEntity); + removablesLocality.add(poiVideoMarker); + break; + case 4://道路录像 + BitmapDescriptor roadDescriptor =null; + if (poiEntity.getTaskStatus()==1){ + roadDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_road_bg); + }else { + roadDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.grayroad); + } + Marker roadMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(roadDescriptor).alpha(0.9f) + .flat(true) + .clockwise(false)); + roadMarker.setClickable(true); + roadMarker.setZIndex(2); + roadMarker.setTitle(poiEntity.getName() + ""); + roadMarker.setTag(poiEntity); + removablesLocality.add(roadMarker); + break; + case 5://其他 + BitmapDescriptor otherDescriptor = null; + if (poiEntity.getTaskStatus()==1){ + otherDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_other_bg1); + }else { + otherDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.grayother); + } + Marker otherMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(otherDescriptor).alpha(0.9f) + .flat(true) + .clockwise(false)); + otherMarker.setClickable(true); + otherMarker.setZIndex(2); + otherMarker.setTitle(poiEntity.getName() + ""); + otherMarker.setTag(poiEntity); + removablesLocality.add(otherMarker); + break; + case 6://面状任务 + BitmapDescriptor Descriptor =null; + if (poiEntity.getTaskStatus()==1){ + Descriptor = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_bg); + }else { + Descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_other_have_bag); + } + Marker planarMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(Descriptor).alpha(0.9f) + .clockwise(false) + .flat(true)); + planarMarker.setClickable(true); + planarMarker.setZIndex(2); + planarMarker.setTitle(poiEntity.getName() + ""); + planarMarker.setTag(poiEntity); + removablesLocality.add(planarMarker); + break; + } + } + Message obtain = Message.obtain(); + obtain.what = Constant.JOB_SEARCH_POI_WORD; + obtain.obj = allTaskStatus; + EventBus.getDefault().post(obtain); + } + }); + } + }).start(); + } + + + private void initSharePre () { + //根据保存时所用的name属性,获取SharedPreferences对象 + SharedPreferences dataFile = getActivity().getSharedPreferences(Constant.DATA_FILE, 0); + //根据数据类型,调用对应的get方法,通过键取得对应的值。 + String dataFileString = dataFile.getString("poiEntity", null); + if (dataFileString != null) { + PoiEntity poiEntity = new Gson().fromJson(dataFileString, PoiEntity.class); + switch (poiEntity.getType()) { + case 1: + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getContext(), "提示", "你poi页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + Bundle bundle = new Bundle(); + bundle.putSerializable("poiEntity", poiEntity); + PoiFragment poiFragment = PoiFragment.newInstance(bundle); + LatLng newPoiLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); + showPoiMarkerByType(1, newPoiLatLng); + showSlidingFragment(poiFragment); + initRemovePoiSharePre(); + return false; } }); - } - }).start(); - } + break; + case 2: + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getContext(), "提示", "你充电站页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + Bundle bundle = new Bundle(); + bundle.putSerializable("poiEntity", poiEntity); + ChargingStationFragment chargingStationFragment = ChargingStationFragment.newInstance(bundle); + LatLng newPoiLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); + showPoiMarkerByType(4, newPoiLatLng); + showSlidingFragment(chargingStationFragment); + initRemovePoiSharePre(); + return false; + } + }); + break; + case 3: + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getContext(), "提示", "你poi录像页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + Bundle bundle = new Bundle(); + bundle.putSerializable("poiEntity", poiEntity); + PoiVideoFragment poiVideoFragment = PoiVideoFragment.newInstance(bundle); + LatLng newPoiLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); + showPoiMarkerByType(2, newPoiLatLng); + showSlidingFragment(poiVideoFragment); + initRemovePoiSharePre(); + return false; + } + }); + break; + case 4: + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getContext(), "提示", "你道路页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + Bundle bundle = new Bundle(); + bundle.putSerializable("poiEntity", poiEntity); + RoadFragment roadFragment = RoadFragment.newInstance(bundle); + LatLng newPoiLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); + showPoiMarkerByType(3, newPoiLatLng); + showSlidingFragment(roadFragment); + initRemovePoiSharePre(); + return false; + } + }); + break; - private void initSharePre () { - //根据保存时所用的name属性,获取SharedPreferences对象 - SharedPreferences dataFile = getActivity().getSharedPreferences(Constant.DATA_FILE, 0); - //根据数据类型,调用对应的get方法,通过键取得对应的值。 - String dataFileString = dataFile.getString("poiEntity", null); - if (dataFileString != null) { - PoiEntity poiEntity = new Gson().fromJson(dataFileString, PoiEntity.class); - switch (poiEntity.getType()) { - case 1: - DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; - MessageDialog.show((AppCompatActivity) getContext(), "提示", "你poi页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { - @Override - public boolean onClick(BaseDialog baseDialog, View v) { - Bundle bundle = new Bundle(); - bundle.putSerializable("poiEntity", poiEntity); - PoiFragment poiFragment = PoiFragment.newInstance(bundle); - LatLng newPoiLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); - showPoiMarkerByType(1, newPoiLatLng); - showSlidingFragment(poiFragment); - initRemovePoiSharePre(); - return false; - } - }); - break; - case 2: - DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; - MessageDialog.show((AppCompatActivity) getContext(), "提示", "你充电站页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { - @Override - public boolean onClick(BaseDialog baseDialog, View v) { - Bundle bundle = new Bundle(); - bundle.putSerializable("poiEntity", poiEntity); - ChargingStationFragment chargingStationFragment = ChargingStationFragment.newInstance(bundle); - LatLng newPoiLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); - showPoiMarkerByType(4, newPoiLatLng); - showSlidingFragment(chargingStationFragment); - initRemovePoiSharePre(); - return false; - } - }); - break; - case 3: - DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; - MessageDialog.show((AppCompatActivity) getContext(), "提示", "你poi录像页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { - @Override - public boolean onClick(BaseDialog baseDialog, View v) { - Bundle bundle = new Bundle(); - bundle.putSerializable("poiEntity", poiEntity); - PoiVideoFragment poiVideoFragment = PoiVideoFragment.newInstance(bundle); - LatLng newPoiLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); - showPoiMarkerByType(2, newPoiLatLng); - showSlidingFragment(poiVideoFragment); - initRemovePoiSharePre(); - return false; - } - }); - break; - case 4: - DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; - MessageDialog.show((AppCompatActivity) getContext(), "提示", "你道路页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { - @Override - public boolean onClick(BaseDialog baseDialog, View v) { - Bundle bundle = new Bundle(); - bundle.putSerializable("poiEntity", poiEntity); - RoadFragment roadFragment = RoadFragment.newInstance(bundle); - LatLng newPoiLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); - showPoiMarkerByType(3, newPoiLatLng); - showSlidingFragment(roadFragment); - initRemovePoiSharePre(); - return false; - } - }); - break; + case 5: + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getContext(), "提示", "你其他页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + Bundle bundle = new Bundle(); + bundle.putSerializable("poiEntity", poiEntity); + OtherFragment otherFragment = OtherFragment.newInstance(bundle); + LatLng newPoiLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); + showPoiMarkerByType(5, newPoiLatLng); + showSlidingFragment(otherFragment); + initRemovePoiSharePre(); + return false; + } + }); + break; - case 5: - DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; - MessageDialog.show((AppCompatActivity) getContext(), "提示", "你其他页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { - @Override - public boolean onClick(BaseDialog baseDialog, View v) { - Bundle bundle = new Bundle(); - bundle.putSerializable("poiEntity", poiEntity); - OtherFragment otherFragment = OtherFragment.newInstance(bundle); - LatLng newPoiLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX())); - showPoiMarkerByType(5, newPoiLatLng); - showSlidingFragment(otherFragment); - initRemovePoiSharePre(); - return false; - } - }); - break; - - } } } + } public void initRemovePoiSharePre () { //获取SharedPreferences对象,方法中两个参数的意思为:第一个name @@ -1487,36 +1495,26 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen } } - /** - * header 头部布局 - * - * @param view - */ - public void initHeader (View view){ - dragView.removeAllViews(); - dragView.addView(view); - } - /** - * 将fragment显示到抽屉内 - */ - private void showSlidingFragment (BaseDrawerFragment fragment){ - fragmentTransaction = supportFragmentManager.beginTransaction(); - int[] deviceInfo = DensityUtil.getDeviceInfo(getActivity()); - sliding_layout.setPanelHeight(deviceInfo[1] / 2); - sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED); - fragmentTransaction.add(R.id.scroll_view, fragment, fragment.getClass().getName()); - if (!(fragment instanceof FilterFragment)) { - FilterFragment filterFragment = (FilterFragment) supportFragmentManager.findFragmentByTag(FilterFragment.class.getName()); - if (filterFragment != null) { - fragmentTransaction.hide(filterFragment); - } + /** + * 将fragment显示到抽屉内 + */ + private void showSlidingFragment(BaseDrawerFragment fragment) { + fragmentTransaction = supportFragmentManager.beginTransaction(); + int[] deviceInfo = DensityUtil.getDeviceInfo(getActivity()); + sliding_layout.setPanelHeight(deviceInfo[1] / 2); + sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED); + fragmentTransaction.add(R.id.scroll_view, fragment, fragment.getClass().getName()); + if (!(fragment instanceof FilterFragment)) { + FilterFragment filterFragment = (FilterFragment) supportFragmentManager.findFragmentByTag(FilterFragment.class.getName()); + if (filterFragment != null) { + fragmentTransaction.hide(filterFragment); } - if (!(fragment instanceof ChargingStationFragment)) { - ChargingStationFragment chargingStationFragment = (ChargingStationFragment) supportFragmentManager.findFragmentByTag(ChargingStationFragment.class.getName()); - if (chargingStationFragment != null) { - fragmentTransaction.hide(chargingStationFragment); - } + } + if (!(fragment instanceof ChargingStationFragment)) { + ChargingStationFragment chargingStationFragment = (ChargingStationFragment) supportFragmentManager.findFragmentByTag(ChargingStationFragment.class.getName()); + if (chargingStationFragment != null) { + fragmentTransaction.hide(chargingStationFragment); } if (!(fragment instanceof PoiFragment)) { PoiFragment poiFragment = (PoiFragment) supportFragmentManager.findFragmentByTag(PoiFragment.class.getName()); @@ -1540,56 +1538,54 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } + } - /** - * 检查网络状态 - */ - private void checkNetWork () { + /** + * 检查网络状态 + */ + private void checkNetWork() { if (NetWorkUtils.iConnected(getContext())) { // 当前网络可用 checkMyLocation(); } else { // 当前网络不可用 + dismissLoadingDialog(); ToastUtil.showShort(getContext(), Constant.NETWORK_UNAVAILABLE); } } - - /** - * 检查所需权限 - */ - private void checkMyLocation () { - - // 1.判断是否拥有定位的权限 - // 1.1 拥有权限进行相应操作 - // 1.2 没有权限申请权限 - // 1.2.1 Android 6.0 动态申请权限 - // 1.2.1.1 用户给予权限进行相应操作 - // 1.2.1.2 用户没有给予权限 作出相应提示 - // 1.2.2 某些5.0权限的手机执行相应操作 - - XXPermissions.with(this) - .permission(Permission.ACCESS_COARSE_LOCATION) - .request(new OnPermissionCallback() { - - @Override - public void onGranted(List permissions, boolean all) { - if (all) { - //建立定位 - initLocation(); - - } else { - Toast.makeText(getActivity(), "申请权限失败", Toast.LENGTH_SHORT).show(); - } + /** + * 检查所需权限 + */ + private void checkMyLocation() { + // 1.判断是否拥有定位的权限 + // 1.1 拥有权限进行相应操作 + // 1.2 没有权限申请权限 + // 1.2.1 Android 6.0 动态申请权限 + // 1.2.1.1 用户给予权限进行相应操作 + // 1.2.1.2 用户没有给予权限 作出相应提示 + // 1.2.2 某些5.0权限的手机执行相应操作 + XXPermissions.with(this) + .permission(Permission.ACCESS_COARSE_LOCATION) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + if (all) { + //建立定位 + initLocation(); + } else { + dismissLoadingDialog(); + Toast.makeText(getActivity(), "申请权限失败", Toast.LENGTH_SHORT).show(); } - - @Override - public void onDenied(List permissions, boolean never) { - if (never) { - Toast.makeText(getActivity(), "被永久拒绝授权,请手动授予定位权限", Toast.LENGTH_SHORT).show(); - // 如果是被永久拒绝就跳转到应用权限系统设置页面 - XXPermissions.startPermissionActivity(getActivity(), permissions); - } + } + @Override + public void onDenied(List permissions, boolean never) { + if (never) { + dismissLoadingDialog(); + Toast.makeText(getActivity(), "被永久拒绝授权,请手动授予定位权限", Toast.LENGTH_SHORT).show(); + // 如果是被永久拒绝就跳转到应用权限系统设置页面 + XXPermissions.startPermissionActivity(getActivity(), permissions); } - }); - } + } + }); + } @Override 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 cb869a4..4d2c5cc 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/UserAttestationFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/UserAttestationFragment.java @@ -1,8 +1,12 @@ package com.navinfo.outdoor.fragment; +import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; +import android.net.Uri; import android.os.Bundle; +import android.provider.MediaStore; import android.util.Log; import android.view.View; import android.widget.Button; @@ -26,7 +30,9 @@ import com.navinfo.outdoor.base.BaseFragment; import com.navinfo.outdoor.bean.NameAuthenticationBean; import com.navinfo.outdoor.http.DialogCallback; import com.navinfo.outdoor.http.HttpInterface; +import com.navinfo.outdoor.util.Geohash; import com.navinfo.outdoor.util.PhotoPathUtil; +import com.navinfo.outdoor.util.PhotoUtils; import java.io.File; import java.util.ArrayList; @@ -54,6 +60,8 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic private TextView tvCard2; private ImageView ivHera3; private TextView tvCard3; + private SharedPreferences.Editor navInfoEditor; + private File file; public static UserAttestationFragment newInstance(Bundle bundle) { @@ -79,6 +87,7 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic @Override protected void initView() { super.initView(); + navInfoEditor = getActivity().getSharedPreferences("navInfo", Context.MODE_PRIVATE).edit(); ivAttestation = findViewById(R.id.iv_attestation); ivAttestation.setOnClickListener(this); ivAttestation1 = findViewById(R.id.iv_attestation1); @@ -107,22 +116,42 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic break; case R.id.iv_attestation1: Intent ivAttestation1 = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("a", null); + ivAttestation1.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(ivAttestation1, 100); break; case R.id.iv_attestation2: Intent ivAttestation2 = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("a", null); + ivAttestation2.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(ivAttestation2, 200); break; case R.id.iv_attestation3: Intent ivAttestation3 = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("a", null); + ivAttestation3.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(ivAttestation3, 300); break; case R.id.btn_attestation: + if (etAttestationName.getText().toString() == null || etAttestationName.getText().toString().equals("")) { + Toast.makeText(getContext(), "姓名不能为空,请输入姓名", Toast.LENGTH_SHORT).show(); + return; + } + if (!chineseNameTest(etAttestationName.getText().toString())){ + Toast.makeText(getActivity(), "请输入中文名字", Toast.LENGTH_SHORT).show(); + return; + } + if (!checkNum(etNamePhone.getText().toString().trim())) { + Toast.makeText(getContext(), "身份证号错误,请重新输入", Toast.LENGTH_SHORT).show(); + return; + } nameAuthentication(); break; } } - + /*** + * + */ public boolean checkNum(String text) { Pattern patternSfzhm1 = Pattern .compile("^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$"); @@ -135,7 +164,16 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic else return true; } + /** + * 中文效验 + */ + static boolean chineseNameTest(String name) { + if (!name.matches("[\u4e00-\u9fa5]{2,4}")) { + System.out.println("只能输入2到4个汉字"); + return false; + }else return true; + } private void nameAuthentication() { if (etAttestationName.getText().toString() == null || etAttestationName.getText().toString().equals("")) { Toast.makeText(getContext(), "姓名不能为空,请输入姓名", Toast.LENGTH_SHORT).show(); @@ -181,24 +219,23 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic @Override public void onSuccess(Response response) { dismissLoadingDialog(); - - Log.d("TAG", "onSuccess: " + response.toString() + "sssssssssssss"); - if (response.body().equals("0")) { - MessageDialog.show((AppCompatActivity) getActivity(), "提示", "不通过", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { + if (response.code()==200) { + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getActivity(), "提示", "通过", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(BaseDialog baseDialog, View v) { // Toast.makeText(getContext(), "点击了确定", Toast.LENGTH_SHORT).show(); - //传值给持卡人 - Constant.USER_ATTESTATION_NAME = attestationName; return false; } }); } else { - MessageDialog.show((AppCompatActivity) getActivity(), "提示", "通过", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getActivity(), "提示", "不通过", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(BaseDialog baseDialog, View v) { - Constant.USER_ATTESTATION_NAME = attestationName; + navInfoEditor.putString("attestationName",attestationName); + navInfoEditor.commit(); return false; } }); @@ -221,74 +258,84 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic super.onActivityResult(requestCode, resultCode, data); if (requestCode == 100 && resultCode == RESULT_OK) { Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - 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("android.media.action.IMAGE_CAPTURE"); - startActivityForResult(intentPanorama, 100); - return false; - } - }); - } else { + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; - String takePhotoPath1 = PhotoPathUtil.getTakePhotoPath(data, "a", ""); - ivAttestation1.setTag(takePhotoPath1); - ivAttestation1.setImageBitmap(bitmap);//显示图像 - ivHera1.setVisibility(View.GONE); - tvCard1.setVisibility(View.GONE); + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivAttestation1); + ivAttestation1.setTag(s); } + file=null; + ivHera1.setVisibility(View.GONE); + tvCard1.setVisibility(View.GONE); +// 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("android.media.action.IMAGE_CAPTURE"); +// startActivityForResult(intentPanorama, 100); +// return false; +// } +// }); +// } } if (requestCode == 200 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - 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("android.media.action.IMAGE_CAPTURE"); - startActivityForResult(intentPanorama, 200); - return false; - } - }); - } else { - String takePhotoPath2 = PhotoPathUtil.getTakePhotoPath(data, "a", ""); - ivAttestation2.setTag(takePhotoPath2); - ivAttestation2.setImageBitmap(bitmap);//显示图像 - ivHera2.setVisibility(View.GONE); - tvCard2.setVisibility(View.GONE); + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivAttestation2); + ivAttestation2.setTag(s); } + file=null; + ivHera2.setVisibility(View.GONE); + tvCard2.setVisibility(View.GONE); +// 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("android.media.action.IMAGE_CAPTURE"); +// startActivityForResult(intentPanorama, 200); +// return false; +// } +// }); +// } } if (requestCode == 300 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - 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("android.media.action.IMAGE_CAPTURE"); - startActivityForResult(intentPanorama, 300); - return false; - } - }); - } else { - String takePhotoPath3 = PhotoPathUtil.getTakePhotoPath(data, "a", ""); - ivAttestation3.setTag(takePhotoPath3); - ivAttestation3.setImageBitmap(bitmap);//显示图像 - ivHera3.setVisibility(View.GONE); - tvCard3.setVisibility(View.GONE); + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivAttestation3); + ivAttestation3.setTag(s); } + file=null; + ivHera3.setVisibility(View.GONE); + tvCard3.setVisibility(View.GONE); +// 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("android.media.action.IMAGE_CAPTURE"); +// startActivityForResult(intentPanorama, 300); +// return false; +// } +// }); +// } else { +// +// } } } - } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/WithdrawFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/WithdrawFragment.java index 06e6157..fa7ecdf 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/WithdrawFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/WithdrawFragment.java @@ -1,15 +1,25 @@ package com.navinfo.outdoor.fragment; +import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; +import android.widget.CheckBox; +import android.widget.CompoundButton; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; +import androidx.appcompat.app.AppCompatActivity; + +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.model.HttpParams; import com.navinfo.outdoor.R; import com.navinfo.outdoor.activity.FragmentManagement; @@ -34,12 +44,17 @@ public class WithdrawFragment extends BaseFragment implements View.OnClickListen private EditText etAllPrice; private TextView poiPushMoney; private TextView poiReportMoney; + private TextView poiVideoPushMoney; + private TextView poiVideoReportMoney; private TextView roadPushMoney; private TextView roadReportMoney; private TextView chargingPushMoney; private TextView chargingReportMoney; private TextView otherPushMoney; private TextView otherReportMoney; + private SharedPreferences navInfo; + private CheckBox checkBox; + private String bankAccount; public static WithdrawFragment newInstance(Bundle bundle) { WithdrawFragment fragment = new WithdrawFragment(); @@ -61,7 +76,7 @@ public class WithdrawFragment extends BaseFragment implements View.OnClickListen protected void initView() { super.initView(); tvUnit = findViewById(R.id.tv_unit);//可提现 - tvAlready = findViewById(R.id.tv_already);//以提现 + tvAlready = findViewById(R.id.tv_already);//已提现 tvTotal = findViewById(R.id.tv_total);//总资产 tvAll = findViewById(R.id.tv_all); tvAll.setOnClickListener(this::onClick); @@ -70,10 +85,37 @@ public class WithdrawFragment extends BaseFragment implements View.OnClickListen ivWithDraw.setOnClickListener(this); tvText = findViewById(R.id.tv_text); tvText.setOnClickListener(this::onClick); + checkBox = findViewById(R.id.checkBox); + checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked){ + checkBox.setChecked(true); + navInfo = getActivity().getSharedPreferences("navInfo", Context.MODE_PRIVATE); + bankAccount = navInfo.getString("bankAccount", null); + if (bankAccount ==null|| bankAccount.equals("")){ + String attestationName = navInfo.getString("attestationName", null); + if (attestationName == null || attestationName.equals("")) { + Intent attestationIntent = new Intent(getContext(), FragmentManagement.class); + attestationIntent.putExtra("tag", 25); + startActivity(attestationIntent); + Toast.makeText(getContext(), "未实名认证,不能绑定银行卡", Toast.LENGTH_SHORT).show(); + }else { + Intent gatheringIntent = new Intent(getContext(), FragmentManagement.class); + gatheringIntent.putExtra("tag", 24); + startActivity(gatheringIntent); + Toast.makeText(getContext(), "以实名认证,请绑定银行卡", Toast.LENGTH_SHORT).show(); + } + } + } + } + }); btWithdraw = findViewById(R.id.button); btWithdraw.setOnClickListener(this::onClick); poiPushMoney = (TextView) findViewById(R.id.poi_push_money); poiReportMoney = (TextView) findViewById(R.id.poi_report_money); + poiVideoPushMoney = (TextView) findViewById(R.id.poiVideo_push_money); + poiVideoReportMoney = (TextView) findViewById(R.id.poiVideo_report_money); roadPushMoney = (TextView) findViewById(R.id.road_push_money); roadReportMoney = (TextView) findViewById(R.id.road_report_money); chargingPushMoney = (TextView) findViewById(R.id.charging_push_money); @@ -105,6 +147,8 @@ public class WithdrawFragment extends BaseFragment implements View.OnClickListen tvAlready.setText(response.getBody().getHaveExchangePrice() + ""); poiPushMoney.setText(response.getBody().getPoiPushPrice() + "元"); poiReportMoney.setText(response.getBody().getPoiNonepushPrice() + "元"); + poiVideoPushMoney.setText(response.getBody().getPoivideoPushPrice() + "元"); + poiVideoReportMoney.setText(response.getBody().getPoivideoNonepushPrice() + "元"); roadPushMoney.setText(response.getBody().getRoadPushPrice() + "元"); roadReportMoney.setText(response.getBody().getRoadNonepushPrice() + "元"); chargingPushMoney.setText(response.getBody().getCsPushPrice() + "元"); @@ -144,7 +188,30 @@ public class WithdrawFragment extends BaseFragment implements View.OnClickListen if (etAllPrice.getText().toString().equals("")) { Toast.makeText(getContext(), "提现金额不能为空", Toast.LENGTH_SHORT).show(); } - immediatelyPrice(); + String price = etAllPrice.getText().toString().trim(); + Integer integer = Integer.valueOf(price); + if (integer!=null&&integer<10){ + Toast.makeText(getContext(), "提现金额不能低于10元", Toast.LENGTH_SHORT).show(); + return; + } + if (!checkBox.isChecked()){ + Toast.makeText(getContext(), "请勾选银行卡", Toast.LENGTH_SHORT).show(); + return; + } + if (bankAccount!=null){ + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getContext(), "提示", "是否提取到"+bankAccount.substring(bankAccount.length()-4)+"的银行卡", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + immediatelyPrice(); + return false; + } + }); + }else { + Toast.makeText(getContext(), "请先绑定银行卡", Toast.LENGTH_SHORT).show(); + } + + break; case R.id.tv_all: etAllPrice.setText(canExchangePrice + ""); @@ -155,6 +222,7 @@ public class WithdrawFragment extends BaseFragment implements View.OnClickListen private void immediatelyPrice() { showLoadingDialog(); HttpParams httpParams = new HttpParams(); + httpParams.put("exchangeMoney", etAllPrice.getText().toString()); httpParams.put("payType", "1"); OkGoBuilder.getInstance() @@ -167,7 +235,16 @@ public class WithdrawFragment extends BaseFragment implements View.OnClickListen @Override public void onSuccess(UserPriceExchangeBean response, int id) { dismissLoadingDialog(); - Toast.makeText(getContext(), response.getMessage(), Toast.LENGTH_SHORT).show(); + Toast.makeText(getContext(), response.getMessage(), Toast.LENGTH_SHORT).show(); + if (response.getCode()==200){ + String unit = tvUnit.getText().toString(); + String price = etAllPrice.getText().toString(); + double v = Double.valueOf(unit) - Double.valueOf(price); + String s = String.format("%.2f", v).toString(); + tvUnit.setText(s); + } + etAllPrice.getText().clear(); + Log.d("TAG", "onSuccess: " + response.toString() + "tttttttt"); } diff --git a/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java b/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java index 35af2eb..94bcbb7 100644 --- a/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java +++ b/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java @@ -53,6 +53,15 @@ public class HttpInterface { */ //http://172.23.139.4:9999/m4/userlogin/oauth/token public static final String USER_LOGIN_OAUTH_TOKEN = IP +USER_LOGIN_PATH+ "oauth/token"; //登录接口 + ///m4/user/m4/user/register + public static final String USER_REGISTER=IP+USER_PATH+"m4/user/register";//注册接口 + ///m4/user/ phone/message + public static final String USER_MESSAGE=IP+USER_PATH+"phone/message ";//获取验证码 type 1:注册获取 2:更新 + ///m4/user/m4/user/forgetPassword + public static final String USER_FORGET_PASSWORD=IP +USER_PATH+"m4/user/forgetPassword";//忘记密码 + //Flat.: + //dtxbmaps.navinfo.com/dtxb/m4/user/phone/message?mobile=18811794839&type=2 + /** * 提现 金额 * Path=/m4/price/** @@ -106,14 +115,25 @@ public class HttpInterface { //172.23.139.4:8003/m4/task/1/taskName?geo=1rn7exd5uhxy&name=四维 public static final String TASK_NAME = IP+TASK_PATH +"m4/task/"+USERID+"/taskName";//poi-查重 //172.23.139.4:8003/m4/task/1/getCommitList?type=2&pageSize=10&pageNum=1 - public static final String GET_COMMIT_LIST = IP+TASK_PATH +"m4/task/"+USERID+"/getCommitList"; + public static final String GET_COMMIT_LIST = IP+TASK_PATH +"m4/task/"+USERID+"/getCommitList";//紀錄——已提交 public static final String RECEIVED_POLYGON_TASK = IP+TASK_PATH + "polygonTask/"+USERID+"/receivedPolygontask"; //面状任务任务领取 //172.23.139.4:8003/m4/task/1/unReceivedTask?taskIds=&auditIds=214,278 取消领取的接口 - public static final String UNRECEIVED_POLYGON_TASK = IP+TASK_PATH + "m4/task/"+USERID+"/unReceivedTask";//面状任务结束领取 + public static final String UNRECEIVED_POLYGON_TASK = IP+TASK_PATH + "m4/task/"+USERID+"/unReceivedTask";//所有類型结束领取 public static final String COMPLETE = IP+TASK_PATH + "polygonTask/"+USERID+"/complete";//面状任务任务采集 public static final String SUBMIT_POLYGON_TASK = IP+TASK_PATH + "polygonTask/"+USERID+"/submitPolygontask";//面状任务结束采集 + + + + + + /* public static final String IPm8 = "http://172.23.139.4:8003/m4/"; + //http://172.23.139.4:8003/m4/task/1/unReceivedTask?taskIds=&auditIds=214,278 + 、、public static final String UN_RECEIVED_TASK = + "task/1/unReceivedTask";//所以类型的结束领取 +*/ + + /** * //http://172.21.91.160:8000/api/user/list @@ -310,10 +330,11 @@ public class HttpInterface { public static final String COMPLETE = IPm6 + "polygonTask/1/complete";//任务采集 public static final String SUBMIT_POLYGON_TASK = IPm6 + "polygonTask/1/submitPolygontask";//结束采集 public static final String RECEIVED_POLYGON_TASK = IPm6 + "polygonTask/1/receivedPolygontask"; //任务领取 - public static final String UNRECEIVED_POLYGON_TASK = IPm6 + "polygonTask/1/unReceivedPolygontask";//结束领取 public static final String COMPLETE = IPm6 + "polygonTask/1/complete";//任务采集 public static final String SUBMIT_POLYGON_TASK = IPm6 + "polygonTask/1/submitPolygontask";//结束采集 * */ + + } diff --git a/app/src/main/java/com/navinfo/outdoor/http/OkGoBuilder.java b/app/src/main/java/com/navinfo/outdoor/http/OkGoBuilder.java index 1467eba..9094e80 100644 --- a/app/src/main/java/com/navinfo/outdoor/http/OkGoBuilder.java +++ b/app/src/main/java/com/navinfo/outdoor/http/OkGoBuilder.java @@ -2,6 +2,10 @@ package com.navinfo.outdoor.http; import android.app.Activity; +import com.github.lazylibrary.util.DES; +import com.github.lazylibrary.util.MD5; +import com.google.gson.Gson; +import com.google.gson.JsonObject; import com.lzy.okgo.OkGo; import com.lzy.okgo.model.HttpHeaders; import com.lzy.okgo.model.HttpParams; diff --git a/app/src/main/java/com/navinfo/outdoor/room/PoiDao.java b/app/src/main/java/com/navinfo/outdoor/room/PoiDao.java index 974a69e..1201b92 100644 --- a/app/src/main/java/com/navinfo/outdoor/room/PoiDao.java +++ b/app/src/main/java/com/navinfo/outdoor/room/PoiDao.java @@ -22,6 +22,9 @@ public interface PoiDao { @Query("SELECT * FROM poi") List getAllPoi(); + @Query("SELECT * FROM poi where taskStatus > 1 and type!=6") + List getAllPoiByRecoder(); + @Query("SELECT * FROM poi where type=:type") List getAllPoiType(int type); diff --git a/app/src/main/java/com/navinfo/outdoor/room/PoiEntity.java b/app/src/main/java/com/navinfo/outdoor/room/PoiEntity.java index 6b3d385..29e868f 100644 --- a/app/src/main/java/com/navinfo/outdoor/room/PoiEntity.java +++ b/app/src/main/java/com/navinfo/outdoor/room/PoiEntity.java @@ -48,7 +48,7 @@ public class PoiEntity implements Serializable { private int isLocalData;//是否是本地数据 0,服务 1,本地 private int isExclusive;//任务类型 0.普通任务,1.专属任务 private int bodyId;//保存本地的bodyId - private int work_type;//0."车行" 1."自行车" 2."步行" 3."手动" + private int work_type;//0."车行" 1."自行车" 2."步行" public int getWork_type() { return work_type; @@ -266,7 +266,6 @@ public class PoiEntity implements Serializable { this.detail = detail; } - @Override public String toString() { return "PoiEntity{" + diff --git a/app/src/main/java/com/navinfo/outdoor/ui/view/ContactView.java b/app/src/main/java/com/navinfo/outdoor/ui/view/ContactView.java index 6e62a58..7bb7da4 100644 --- a/app/src/main/java/com/navinfo/outdoor/ui/view/ContactView.java +++ b/app/src/main/java/com/navinfo/outdoor/ui/view/ContactView.java @@ -66,7 +66,12 @@ public class ContactView { // rootView.removeViewAt(i); } }); - holder.editPhoneNumber.setText(poiBean.getPhone()+""); + if (poiBean.getPhone()==null){ + holder.editPhoneNumber.setText(""); + }else { + holder.editPhoneNumber.setText(poiBean.getPhone()+""); + } + holder.editPhoneNumber.addTextChangedListener(new TextWatcher() { @Override diff --git a/app/src/main/java/com/navinfo/outdoor/util/AWMp4ParserHelper.java b/app/src/main/java/com/navinfo/outdoor/util/AWMp4ParserHelper.java index 5ec4ce5..5727e71 100644 --- a/app/src/main/java/com/navinfo/outdoor/util/AWMp4ParserHelper.java +++ b/app/src/main/java/com/navinfo/outdoor/util/AWMp4ParserHelper.java @@ -14,17 +14,23 @@ import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; import com.bumptech.glide.load.resource.bitmap.VideoDecoder; import com.bumptech.glide.request.RequestOptions; import com.coremedia.iso.boxes.Container; +import com.github.lazylibrary.util.FileUtils; +import com.github.lazylibrary.util.StringUtils; import com.googlecode.mp4parser.authoring.Movie; import com.googlecode.mp4parser.authoring.Track; import com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder; import com.googlecode.mp4parser.authoring.container.mp4.MovieCreator; import com.googlecode.mp4parser.authoring.tracks.AppendTrack; +import com.navinfo.outdoor.api.Constant; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import java.io.File; +import java.io.FileFilter; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.channels.FileChannel; import java.security.MessageDigest; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; @@ -38,10 +44,12 @@ import java.util.Map; */ public class AWMp4ParserHelper { private static AWMp4ParserHelper instance; + private static SimpleDateFormat simpleDateFormat; public static AWMp4ParserHelper getInstance() { if (instance == null) { instance = new AWMp4ParserHelper(); + simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); } return instance; } @@ -182,4 +190,133 @@ public class AWMp4ParserHelper { } return bitmap; } + + /** + * 生成mp4文件拍摄的生成路径 + * */ + public File obtainMp4FilePath(String uuid, Object tag) { + if (tag == null) { + return new File(Constant.PICTURE_FOLDER+"/"+uuid+"-0.mp4"); + } + List fileList = (List) tag; + if (fileList == null || fileList.isEmpty()) { + return new File(Constant.PICTURE_FOLDER+"/"+uuid+"-0.mp4"); + } + int maxIndex = 0; + for (int i = 0; i < fileList.size(); i++) { + File file = fileList.get(i); + if (file!=null) { + String[] fileSplite = file.getName().replace(".mp4", "").split("-"); + if (fileSplite!=null&&fileSplite.length>0&&fileSplite[fileSplite.length-1]!=null) { + int index = Integer.parseInt(fileSplite[fileSplite.length-1]); + if (index>=maxIndex) { + maxIndex = index; + } + } + } + } + return new File(Constant.PICTURE_FOLDER+"/"+uuid+"-"+(maxIndex+1)+".mp4"); + } + + /** + * 根据文件夹路径生成最新的视频文件路径 + * */ + public File obtainMp4FilePath(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(".mp4")){ + return true; + } + return false; + } + }); + if (fileList == null || fileList.length==0) { + return new File(folderPath+"/0.mp4"); + } + 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(".mp4", "")); + if (index>=maxIndex) { + maxIndex = index; + } + } + } + return new File(folderPath+"/"+(maxIndex+1)+".mp4"); + } + + /** + * 根据提供的uuid,获取指定目录下所有的视频文件 + * */ + public List getVideoFileListByUUID(String uuid) { + List 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 videoFileList) { + StringBuilder resultStrBuilder = new StringBuilder(""); + if (videoFileList == null || videoFileList.size()<=0){ + return resultStrBuilder.toString(); + } + + for (int i = 0; i < videoFileList.size(); i++) { + File f = videoFileList.get(i); + resultStrBuilder.append(f.getAbsolutePath()); + if (i < videoFileList.size() -1) { + resultStrBuilder.append(","); + } + } + return resultStrBuilder.toString(); + } + + /** + * 根据视频文件列表,获取到对应的轨迹数据 + * */ + public List getLineStringByVideoFileList(List videoFileList) { + List latLngs = new ArrayList<>(); + if (videoFileList == null || videoFileList.isEmpty()) { + return latLngs; + } + + 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"); + 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; + } } diff --git a/app/src/main/java/com/navinfo/outdoor/util/Base64.java b/app/src/main/java/com/navinfo/outdoor/util/Base64.java index 00f0699..c6444c3 100644 --- a/app/src/main/java/com/navinfo/outdoor/util/Base64.java +++ b/app/src/main/java/com/navinfo/outdoor/util/Base64.java @@ -261,15 +261,15 @@ public class Base64 { cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv); return encode_(cipher.doFinal(message.getBytes("UTF-8"))); } - public static String desEncrypt1(String message) throws Exception { -// SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); -// SecretKey secretKey = keyFactory.generateSecret(new DESKeySpec(keyValue.getBytes("UTF-8"))); - SecretKeySpec secretKey = new SecretKeySpec(keyValue.getBytes(), "DES"); - IvParameterSpec iv = new IvParameterSpec(keyVector.getBytes("UTF-8")); - Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); - cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv); - return encode_(cipher.doFinal(message.getBytes("UTF-8"))); - } +// public static String desEncrypt1(String message) throws Exception { +//// SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); +//// SecretKey secretKey = keyFactory.generateSecret(new DESKeySpec(keyValue.getBytes("UTF-8"))); +// SecretKeySpec secretKey = new SecretKeySpec(keyValue.getBytes(), "DES"); +// IvParameterSpec iv = new IvParameterSpec(keyVector.getBytes("UTF-8")); +// Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); +// cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv); +// return encode_(cipher.doFinal(message.getBytes("UTF-8"))); +// } /** * 解密 diff --git a/app/src/main/java/com/navinfo/outdoor/util/Geohash.java b/app/src/main/java/com/navinfo/outdoor/util/Geohash.java index 94dd9ca..d49f9c6 100644 --- a/app/src/main/java/com/navinfo/outdoor/util/Geohash.java +++ b/app/src/main/java/com/navinfo/outdoor/util/Geohash.java @@ -1,8 +1,19 @@ package com.navinfo.outdoor.util; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; +import com.vividsolutions.jts.geom.Geometry; + +import java.io.UnsupportedEncodingException; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; import java.util.BitSet; import java.util.HashMap; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; + public class Geohash { private Geohash(){} @@ -33,61 +44,79 @@ public class Geohash { lookup.put(c, i++); } - public static void main(String[] args) { - String s = "1rn7exd5uhxy"; - System.out.println(s); - System.out.println(new Geohash().decode(s)[0]); - System.out.println(new Geohash().decode(s)[1]); - System.out.println(new Geohash().encode(40.073556024581194, 116.24643344432116)); - } +// public static void main(String[] args) { +// String s = "1rn7exd5uhxy"; +// System.out.println(s); +// System.out.println(new Geohash().decode(s)[0]); +// System.out.println(new Geohash().decode(s)[1]); +// System.out.println(new Geohash().encode(40.073556024581194, 116.24643344432116)); +// } //数据解密 /** * @param geohash 需要被解密的字符串 * @return double[] 经纬度double数组,纬度(latitude)在前,经度在后(longitude) * */ - public double[] decode(String geohash) { + public String decode(String geohash) { +// try { +// StringBuilder buffer = new StringBuilder(); +// for (char c : geohash.toCharArray()) { +// +// int i = lookup.get(c) + 32; +// buffer.append(Integer.toString(i, 2).substring(1)); +// } +// +// long a = Long.parseLong(buffer.toString(), 2); +// buffer.setLength(0); +// buffer.append(Long.toBinaryString(a)); +// +// BitSet lonset = new BitSet(); +// BitSet latset = new BitSet(); +// +// // even bits +// int j = 0; +// for (int i = 0; i < numbits * 2; i += 2) { +// boolean isSet = false; +// if (i < buffer.length()) +// isSet = buffer.charAt(i) == '1'; +// lonset.set(j++, isSet); +// } +// +// // odd bits +// j = 0; +// for (int i = 1; i < numbits * 2; i += 2) { +// boolean isSet = false; +// if (i < buffer.length()) +// isSet = buffer.charAt(i) == '1'; +// latset.set(j++, isSet); +// } +// +// double lon = decode(lonset, -180, 180); +// double lat = decode(latset, -90, 90); +// +// return new double[] { lat, lon }; +// } catch (RuntimeException re) { +// re.printStackTrace(); +// return null; +// } try { - StringBuilder buffer = new StringBuilder(); - for (char c : geohash.toCharArray()) { - - int i = lookup.get(c) + 32; - buffer.append(Integer.toString(i, 2).substring(1)); - } - - long a = Long.parseLong(buffer.toString(), 2); - buffer.setLength(0); - buffer.append(Long.toBinaryString(a)); - - BitSet lonset = new BitSet(); - BitSet latset = new BitSet(); - - // even bits - int j = 0; - for (int i = 0; i < numbits * 2; i += 2) { - boolean isSet = false; - if (i < buffer.length()) - isSet = buffer.charAt(i) == '1'; - lonset.set(j++, isSet); - } - - // odd bits - j = 0; - for (int i = 1; i < numbits * 2; i += 2) { - boolean isSet = false; - if (i < buffer.length()) - isSet = buffer.charAt(i) == '1'; - latset.set(j++, isSet); - } - - double lon = decode(lonset, -180, 180); - double lat = decode(latset, -90, 90); - - return new double[] { lat, lon }; - } catch (RuntimeException re) { - re.printStackTrace(); - return null; + return Base64.desDecrypt(geohash); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (NoSuchPaddingException e) { + e.printStackTrace(); + } catch (InvalidKeyException e) { + e.printStackTrace(); + } catch (InvalidAlgorithmParameterException e) { + e.printStackTrace(); + } catch (IllegalBlockSizeException e) { + e.printStackTrace(); + } catch (BadPaddingException e) { + e.printStackTrace(); } + return null; } private double decode(BitSet bs, double floor, double ceiling) { @@ -107,14 +136,20 @@ public class Geohash { * @param lat,lon 需要被加密的double 值 * */ public String encode(double lat, double lon) { - BitSet latbits = getBits(lat, -90, 90); - BitSet lonbits = getBits(lon, -180, 180); - StringBuilder buffer = new StringBuilder(); - for (int i = 0; i < numbits; i++) { - buffer.append((lonbits.get(i)) ? '1' : '0'); - buffer.append((latbits.get(i)) ? '1' : '0'); +// BitSet latbits = getBits(lat, -90, 90); +// BitSet lonbits = getBits(lon, -180, 180); +// StringBuilder buffer = new StringBuilder(); +// for (int i = 0; i < numbits; i++) { +// buffer.append((lonbits.get(i)) ? '1' : '0'); +// buffer.append((latbits.get(i)) ? '1' : '0'); +// } + Geometry geometry = GeometryTools.createGeometry(new LatLng(lat, lon)); + try { + return Base64.desEncrypt(geometry.toString()); + } catch (Exception e) { + e.printStackTrace(); } - return base32(Long.parseLong(buffer.toString(), 2)); + return null; } private BitSet getBits(double lat, double floor, double ceiling) { diff --git a/app/src/main/java/com/navinfo/outdoor/util/PhotoPathUtil.java b/app/src/main/java/com/navinfo/outdoor/util/PhotoPathUtil.java index ffa76c5..ac29674 100644 --- a/app/src/main/java/com/navinfo/outdoor/util/PhotoPathUtil.java +++ b/app/src/main/java/com/navinfo/outdoor/util/PhotoPathUtil.java @@ -54,7 +54,7 @@ public class PhotoPathUtil { if (angle==0){ angle=90; } - File file = new File(Constant.PICTURE_FOLDER, d+time+"_p"+coord+"_a"+angle+".jpg"); + File file = new File(Constant.PICTURE_FOLDER+d+time+"_p"+coord+"_a"+angle+".jpg"); /***打开文件输出流*/ fileOutputStream = new FileOutputStream(file); // 生成图片文件 diff --git a/app/src/main/java/com/navinfo/outdoor/util/PhotoUtils.java b/app/src/main/java/com/navinfo/outdoor/util/PhotoUtils.java new file mode 100644 index 0000000..352bb7a --- /dev/null +++ b/app/src/main/java/com/navinfo/outdoor/util/PhotoUtils.java @@ -0,0 +1,116 @@ +package com.navinfo.outdoor.util; + +import android.content.Intent; +import android.util.Log; +import android.widget.ImageView; + +import androidx.exifinterface.media.ExifInterface; + +import com.bumptech.glide.Glide; +import com.navinfo.outdoor.api.Constant; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; + +import java.io.File; +import java.io.IOException; +import java.util.BitSet; + +import static org.greenrobot.eventbus.EventBus.TAG; + +public class PhotoUtils { + private static int numbits = 6 * 5; + // 为了加密,所以改了base32编码代码表 + final static char[] digits = { 'd', 'f', 'g', 'y', 'n', 't', 'u', 'v', 'q', + 'b', '9', 's', 'z', '7', 'i', '2', 'h', '5', '0', 'p', '4', 'm', + '8', 'x', 'c', 'j', '6', 'e', '1', 'r', '3', 'k' }; + + public static String showPhotoAndGetPath(File file, ImageView imageView) { + Glide.with(imageView.getContext()).load(file).into(imageView); + return file.getAbsolutePath(); + } + + public static File showPhotoFile(String d, LatLng latLng) { + String lat=""; + if (latLng!=null){ + lat= initEncode(latLng); + } + long time = System.currentTimeMillis(); + File file = new File(Constant.PICTURE_FOLDER, d + time + "_p" + lat + "_a" + 0 + ".jpg"); + return file; + } + + public static String initEncode(LatLng latLng) { + BitSet latbits = getBits(latLng.latitude, -90, 90); + BitSet lonbits = getBits(latLng.longitude, -180, 180); + StringBuilder buffer = new StringBuilder(); + for (int i = 0; i < numbits; i++) { + buffer.append((lonbits.get(i)) ? '1' : '0'); + buffer.append((latbits.get(i)) ? '1' : '0'); + } + return base32(Long.parseLong(buffer.toString(), 2)); + } + + private static BitSet getBits(double lat, double floor, double ceiling) { + BitSet buffer = new BitSet(numbits); + for (int i = 0; i < numbits; i++) { + double mid = (floor + ceiling) / 2; + if (lat >= mid) { + buffer.set(i); + floor = mid; + } else { + ceiling = mid; + } + } + return buffer; + } + + public static String base32(long i) { + char[] buf = new char[65]; + int charPos = 64; + boolean negative = (i < 0); + if (!negative) + i = -i; + while (i <= -32) { + buf[charPos--] = digits[(int) (-(i % 32))]; + i /= 32; + } + buf[charPos] = digits[(int) (-i)]; + + if (negative) + buf[--charPos] = '-'; + return new String(buf, charPos, (65 - charPos)); + } + + /** + * 获取图片旋转角度 + * + * @param filepath + * @return + */ + public static int getExifOrientation(String filepath) { + int degree = 0; + ExifInterface exif = null; + try { + exif = new ExifInterface(filepath); + } catch (IOException ex) { + Log.d(TAG, "cannot read exif" + ex); + } + if (exif != null) { + int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1); + if (orientation != -1) { + switch (orientation) { + case ExifInterface.ORIENTATION_ROTATE_90: + degree = 90; + break; + case ExifInterface.ORIENTATION_ROTATE_180: + degree = 180; + break; + case ExifInterface.ORIENTATION_ROTATE_270: + degree = 270; + break; + } + } + } + return degree; + } + +} 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 8e3eb2d..b47f400 100644 --- a/app/src/main/java/com/navinfo/outdoor/util/PoiSaveUtils.java +++ b/app/src/main/java/com/navinfo/outdoor/util/PoiSaveUtils.java @@ -38,7 +38,8 @@ public class PoiSaveUtils { private Activity mContext; private Gson gson; private static PoiSaveUtils instance; - private boolean isBoolean; + private int anInt=0; + private int bInt=0; public static PoiSaveUtils getInstance(Activity mContext) { if (instance == null) { @@ -88,7 +89,7 @@ public class PoiSaveUtils { public void run() { Message obtain = Message.obtain(); obtain.what = Constant.EVENT_STAY_REFRESH; - obtain.obj = isBoolean; + obtain.obj = "提交成功"+anInt+",提交失败"+bInt; EventBus.getDefault().post(obtain); } }); @@ -287,10 +288,10 @@ public class PoiSaveUtils { if (otherUploadPicBean.getCode() == 200) { PoiDatabase.getInstance(mContext).getPoiDao().deletePoiEntity(poiEntity); Log.d("TAGss", "uploadPoiNet: 成功"); - isBoolean = true; + anInt++; } else { Log.d("TAGss", "uploadPoiNet: 失败"); - isBoolean = false; + bInt++; return; } } catch (IOException e) { diff --git a/app/src/main/res/drawable/ic_baseline.xml b/app/src/main/res/drawable/ic_baseline.xml new file mode 100644 index 0000000..b7d587c --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_camera.xml b/app/src/main/res/layout/activity_camera.xml deleted file mode 100644 index 2cc92db..0000000 --- a/app/src/main/res/layout/activity_camera.xml +++ /dev/null @@ -1,195 +0,0 @@ - - - - - - - - -