diff --git a/app/build.gradle b/app/build.gradle index b199dff..30699f0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,7 +10,7 @@ android { defaultConfig { applicationId "com.navinfo.outdoor" - minSdkVersion 23 + minSdkVersion 24 targetSdkVersion 30 versionCode 36 versionName "8.221207" diff --git a/app/src/main/java/com/navinfo/outdoor/activity/HomeActivity.java b/app/src/main/java/com/navinfo/outdoor/activity/HomeActivity.java index 4611880..20b648b 100644 --- a/app/src/main/java/com/navinfo/outdoor/activity/HomeActivity.java +++ b/app/src/main/java/com/navinfo/outdoor/activity/HomeActivity.java @@ -111,6 +111,8 @@ public class HomeActivity extends BaseActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + DialogSettings.style = DialogSettings.STYLE.STYLE_IOS; + DialogSettings.init(); if (Constant.USHERED != null) { Constant.initRootFolder(Constant.USHERED); // 检测用户是否为虚拟定位 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 37f3efd..a7103ab 100644 --- a/app/src/main/java/com/navinfo/outdoor/base/BaseDrawerFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/base/BaseDrawerFragment.java @@ -138,6 +138,7 @@ public abstract class BaseDrawerFragment extends BaseFragment { //以键值对的形式添加新值。 edit.putString("poiEntity", null); edit.putString("chargingPileEntity", null); + edit.putInt("roadVideoType", -1); //提交新值。必须执行,否则前面的操作都无效。 edit.commit(); } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/AreaHubFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/AreaHubFragment.java new file mode 100644 index 0000000..9a8e44f --- /dev/null +++ b/app/src/main/java/com/navinfo/outdoor/fragment/AreaHubFragment.java @@ -0,0 +1,1044 @@ +package com.navinfo.outdoor.fragment; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.os.Message; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.Button; +import android.widget.EditText; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.NumberPicker; +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.annotation.RequiresApi; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.widget.NestedScrollView; + +import com.bumptech.glide.Glide; +import com.github.lazylibrary.util.FileUtils; +import com.github.lazylibrary.util.StringUtils; +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.CustomDialog; +import com.kongzue.dialog.v3.MessageDialog; +import com.kongzue.dialog.v3.WaitDialog; +import com.lzy.okgo.model.HttpParams; +import com.navinfo.outdoor.R; +import com.navinfo.outdoor.activity.FragmentManagement; +import com.navinfo.outdoor.activity.PicturesActivity; +import com.navinfo.outdoor.api.Constant; +import com.navinfo.outdoor.base.BaseDrawerFragment; +import com.navinfo.outdoor.bean.PoiVideoBean; +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.ChargingPileEntity; +import com.navinfo.outdoor.room.InsertAndUpdateUtils; +import com.navinfo.outdoor.room.PoiDatabase; +import com.navinfo.outdoor.room.PoiEntity; +import com.navinfo.outdoor.ui.view.SpinnerUtils; +import com.navinfo.outdoor.util.AWMp4ParserHelper; +import com.navinfo.outdoor.util.DataSaveUtils; +import com.navinfo.outdoor.util.FlushTokenUtil; +import com.navinfo.outdoor.util.Geohash; +import com.navinfo.outdoor.util.GeometryTools; +import com.navinfo.outdoor.util.PoiSaveUtils; +import com.navinfo.outdoor.util.PreserveUtils; +import com.navinfo.outdoor.util.TimestampUtil; +import com.navinfo.outdoor.util.ToastUtils; +import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; +import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; +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 org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.locationtech.jts.geom.Geometry; + +import java.io.File; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Objects; + +/** + * 寻宝-上报弹窗-交通枢纽 + */ +@RequiresApi(api = Build.VERSION_CODES.N) +public class AreaHubFragment extends BaseDrawerFragment implements View.OnClickListener { + private EditText etDesc; + private Spinner spnRoadName; + private ImageView ivPoiVideoPicture; + private Button btnRoadSave; + private File fileZip, logFile; + private FrameLayout fmPoiVideoPic; + private LatLng latLng; + private Marker markerPoiVideo; + private TextView tvCombo, tvShort; + private StringBuilder poiVideoBuilder; + private LatLng rearLatLng; + private boolean booleanExtra = true; + private TextView btnSelectFloor; + private String[] items; + + public static AreaHubFragment newInstance(Bundle bundle) { + AreaHubFragment fragment = new AreaHubFragment(); + fragment.setArguments(bundle); + return fragment; + } + + @Override + protected int getLayout() { + return R.layout.traffic_hub_fragment; + } + + @Override + public void onStart() { + super.onStart(); + if (!EventBus.getDefault().isRegistered(this)) {//加上判断 + EventBus.getDefault().register(this); + } + } + + @Override + public void onResume() { + super.onResume(); + View header = mView.findViewById(R.id.traffic_hub_header); + header.findViewById(R.id.iv_final).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + initBack(); + } + }); + header.findViewById(R.id.tv_explain).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(getActivity(), FragmentManagement.class); + intent.putExtra("tag", 8); + startActivity(intent); + } + }); + moveLatlng(latLng, null); + } + + @Override + public boolean onBackPressed() { + initBack(); + return true; + } + + private void initBack() { + if (showPoiEntity != null) { + if (showPoiEntity.getTaskStatus() == 5) { + DialogSettings.style = DialogSettings.STYLE.STYLE_IOS; + MessageDialog.show((AppCompatActivity) Objects.requireNonNull(getActivity()), "提示", "当前在任务作业中,是否退出", "确定", "取消").setOnOkButtonClickListener(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了返回当前页面的 确定 按钮,"); + initEndReceiveTask(HttpInterface.UNRECEIVED_POLYGON_TASK, showPoiEntity); + Objects.requireNonNull(getActivity()).getSupportFragmentManager().popBackStack(); + return false; + } + }); + } else if (showPoiEntity.getTaskStatus() == 0 || showPoiEntity.getTaskStatus() == 1) { + DialogSettings.style = DialogSettings.STYLE.STYLE_IOS; + MessageDialog.show((AppCompatActivity) Objects.requireNonNull(getActivity()), "提示", "当前在任务作业中,是否退出", "确定", "取消").setOnOkButtonClickListener(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了返回当前页面的 确定 按钮,"); + if (showPoiEntity != null) { + if (showPoiEntity.getId() != null) { + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + for (int i = 0; i < fileListByUUID.size(); i++) { + fileListByUUID.get(i).delete(); + } + File filePath = AWMp4ParserHelper.getInstance().getFilePath(showPoiEntity.getId()); + filePath.delete(); + } + } + Message obtain = Message.obtain(); + obtain.what = Constant.JOB_WORD_MONITOR; + obtain.obj = true; + EventBus.getDefault().post(obtain); + Bundle arguments = getArguments(); + if (arguments != null) { + isSliding = arguments.getBoolean("isSliding", true); + } + if (isSliding) { + Message obtain1 = Message.obtain(); + obtain1.what = Constant.TREASURE_FRAGMENT; + obtain1.obj = isSliding; + EventBus.getDefault().post(obtain1); + } + Objects.requireNonNull(getActivity()).getSupportFragmentManager().popBackStack(); + return false; + } + }); + } else { + Message obtain = Message.obtain(); + obtain.what = Constant.JOB_WORD_MONITOR; + obtain.obj = true; + EventBus.getDefault().post(obtain); + Bundle arguments = getArguments(); + if (arguments != null) { + isSliding = arguments.getBoolean("isSliding", true); + } + if (isSliding) { + Message obtain1 = Message.obtain(); + obtain1.what = Constant.TREASURE_FRAGMENT; + obtain1.obj = isSliding; + EventBus.getDefault().post(obtain1); + } + Objects.requireNonNull(getActivity()).getSupportFragmentManager().popBackStack(); + } + } + } + + @Override + protected void initView() { + super.initView(); + setSlidingUpPanelLayout(Constant.SLIDING_LAYOUT); + NestedScrollView nestedScrollView = findViewById(R.id.nested_scroll_view); + if (slidingPaneLayout != null) { + slidingPaneLayout.setScrollableView(nestedScrollView); + } + spnRoadName = findViewById(R.id.spn_poi_video_name); + ivPoiVideoPicture = findViewById(R.id.iv_poi_video_picture); + etDesc = findViewById(R.id.et_desc); + //点击拍照 + tvShort = findViewById(R.id.tv_short); + tvShort.setOnClickListener(this); + //自动连拍 + tvCombo = findViewById(R.id.tv_combo); + tvCombo.setOnClickListener(this); + fmPoiVideoPic = findViewById(R.id.fm_poi_video_picture); + fmPoiVideoPic.setOnClickListener(this); + fmPoiVideoPic.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + DialogSettings.style = DialogSettings.STYLE.STYLE_IOS; + MessageDialog.show((AppCompatActivity) Objects.requireNonNull(getContext()), "提示", "是否删除", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了长按删除图片的 按钮,"); + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + for (int i = 0; i < fileListByUUID.size(); i++) { + fileListByUUID.get(i).delete(); + } + ivPoiVideoPicture.setImageDrawable(null); + fmPoiVideoPic.setTag(null); + return false; + } + }); + return false; + } + }); + btnRoadSave = findViewById(R.id.btn_poi_video_save); + btnRoadSave.setOnClickListener(this); + Button btnPoiVideoUpload = findViewById(R.id.btn_poi_video_upload); + btnPoiVideoUpload.setOnClickListener(this); + //添加数据 + initShowPoi(); + ((TextView)findViewById(R.id.tv1)).setText("区域设施"); + } + + @Override + protected void initData() { + super.initData(); + SharedPreferences sharedPreferences = Objects.requireNonNull(getActivity()).getSharedPreferences(Constant.MESSAGE_TYPE, Context.MODE_PRIVATE); + SharedPreferences.Editor sharedEdit = sharedPreferences.edit(); + @SuppressLint("SimpleDateFormat") + DateFormat formatter = new SimpleDateFormat("yyyyMMdd"); + String newFormat = formatter.format(new Date(System.currentTimeMillis())); + String pictures_time = sharedPreferences.getString("pictures_time", null); + if (pictures_time == null) { + sharedEdit.putString("pictures_time", newFormat); + sharedEdit.apply(); + logFile = new File(Constant.LOG_FOLDER + "/" + newFormat + ".txt"); + } else { + if (pictures_time.equals(newFormat)) { + logFile = new File(Constant.LOG_FOLDER + "/" + pictures_time + ".txt"); + } else { + logFile = new File(Constant.LOG_FOLDER + "/" + newFormat + ".txt"); + } + } + poiVideoBuilder = new StringBuilder(); + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("PoiVideoActivity-onCreate-initData ,"); + if (Constant.USHERED != null) { + poiVideoBuilder.append("userId:").append(Constant.USHERED).append(","); + } + } + + private void initShowPoi() { + // 添加信息: + assert getArguments() != null; + btnSelectFloor = findViewById(R.id.btn_select_floor); + showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity"); + if (showPoiEntity != null) { + btnSelectFloor.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // 显示对话框选择对应的楼层 + CustomDialog + .show((AppCompatActivity) getActivity(), R.layout.dialog_select_floor, new CustomDialog.OnBindView() { + @Override + public void onBind(CustomDialog dialog, View v) { + List numValues = new ArrayList(); + for (int i = -10; i <= 100; i++) { + if (i == 0) { + continue; + } + numValues.add(i+""); + } + NumberPicker numberPicker = v.findViewById(R.id.number_picker); + numberPicker.setDisplayedValues(numValues.toArray(new String[numValues.size()])); + numberPicker.setMinValue(0); + numberPicker.setMaxValue(numValues.size()-1); + numberPicker.setValue(10); // 设置默认选择1楼 + TextView confirmTv = v.findViewById(R.id.btn_select_floor_confirm); + confirmTv.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + int index = numberPicker.getValue(); + int floor = Integer.parseInt(numValues.get(index)); + btnSelectFloor.setTag(floor); + btnSelectFloor.setText(floor+"层"); + spnRoadName.setTag(floor+"层"); + dialog.doDismiss(); + } + }); + } + }) + .setCustomLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)) + .setCustomDialogStyleId(R.style.iOSDialogAnimStyle); + } + }); + String name = showPoiEntity.getName();//名称 + SpinnerUtils spinnerUtils = new SpinnerUtils(); + items = new String[]{"建筑物全景", "建筑物底商", "楼层引导图", "楼层选择"}; + if (StringUtils.isEmpty(name)) { // 如果从数据获取的名称为空,则设置name显示为默认的第一个选项 + name = items[0]; + } + spinnerUtils.initSpinner(getActivity(), spnRoadName, new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + if (items[position].equals("楼层选择")) { + btnSelectFloor.setVisibility(View.VISIBLE); + btnSelectFloor.setTag(null); + btnSelectFloor.setText("楼层"); + spnRoadName.setTag(null); + } else { + btnSelectFloor.setVisibility(View.GONE); + spnRoadName.setTag(items[position]); + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + }, name, items); + if (name.endsWith("层")) { + btnSelectFloor.setVisibility(View.VISIBLE); + btnSelectFloor.setText(name); + btnSelectFloor.setTag(name.replace("层", "")); + } + String geoWkt = showPoiEntity.getGeoWkt(); + if (geoWkt != null) { + String geo = Geohash.getInstance().decode(geoWkt); + Geometry geometry = GeometryTools.createGeometry(geo); + switch (geometry.getGeometryType()) { + case "Point": //点 + latLng = GeometryTools.createLatLng(geo); + break; + case "LineString": //线 + case "Polygon": //面 + List latLineString = GeometryTools.getLatLags(geo); + assert latLineString != null; + latLng = latLineString.get(0);//起點 + rearLatLng = latLineString.get(latLineString.size() - 1);//終點 + break; + } + BitmapDescriptor poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_video_show); + markerPoiVideo = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiVideoDescriptor).anchor(0.5f, 1.0f)); + markerPoiVideo.setZIndex(4); + moveLatlng(latLng, null); + } else { + String detail = showPoiEntity.getDetail(); + if (detail != null) { + String geo = Geohash.getInstance().decode(detail); + Geometry geometry = GeometryTools.createGeometry(geo); + switch (geometry.getGeometryType()) { + case "Point": //点 + latLng = GeometryTools.createLatLng(geo); + break; + case "LineString": //线 + case "Polygon": //面 + List latLineString = GeometryTools.getLatLags(geo); + assert latLineString != null; + latLng = latLineString.get(0); + break; + } + BitmapDescriptor poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_video_show); + markerPoiVideo = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiVideoDescriptor).anchor(0.5f, 1.0f)); + markerPoiVideo.setZIndex(4); + moveLatlng(latLng, null); + } else { + String x = showPoiEntity.getX(); + String y = showPoiEntity.getY(); + if (x != null && y != null) { + latLng = new LatLng(); + latLng.setLongitude(Double.parseDouble(x)); + latLng.setLatitude(Double.parseDouble(y)); + BitmapDescriptor poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_video_show); + markerPoiVideo = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiVideoDescriptor).anchor(0.5f, 1.0f)); + markerPoiVideo.setZIndex(4); + moveLatlng(latLng, null); + } + } + } + String memo = showPoiEntity.getMemo();//任务描述 + if (memo != null && !memo.equals("")) { + etDesc.setText(memo); + } + showPoiEntity.setType(3); + String photoList = showPoiEntity.getPhoto(); + if (!StringUtils.isEmpty(photoList)) { + boolean isImageLoad = false; + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + for (int i = 0; i < fileListByUUID.size(); i++) { + if (fileListByUUID.get(i).getPath().contains(".webp") && !fileListByUUID.get(i).getPath().contains("paper.txt")) { + if (fileListByUUID.get(i).exists() && !isImageLoad) { + // 使用glide加载视频的第一帧 + Glide.with(Objects.requireNonNull(getActivity())).load(fileListByUUID.get(i)).into(ivPoiVideoPicture); + isImageLoad = true; + } + } + } + fmPoiVideoPic.setTag(fileListByUUID); + } + if (showPoiEntity.getTaskStatus() == 3) { + disables();//禁用所有可操作的控件 + } + // 如果是推送的POI录像,不允许修改名称 + if (showPoiEntity.getTaskId()>0) { + spnRoadName.setEnabled(false); + } + } + } + + private void disables() { + spnRoadName.setEnabled(false); + ivPoiVideoPicture.setEnabled(false); + tvShort.setEnabled(false); + tvCombo.setEnabled(false); + etDesc.setEnabled(false); + btnRoadSave.setEnabled(false); + } + + @Subscribe + public void onEvent(Message data) { + if (data.what == Constant.PICTURE_VIDEO_WORD) { + if ((boolean) data.obj) { + initPoiVideoSharePre(); + } + } else if (data.what == Constant.PHOTO_FINISH_VIDEO) { + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + if (fileListByUUID.size() == 1) { + for (int i = 0; i < fileListByUUID.size(); i++) { + fileListByUUID.get(i).delete(); + } + ivPoiVideoPicture.setImageDrawable(null); + fmPoiVideoPic.setTag(null); + } else { + boolean isImageLoad = false; + for (int i = 0; i < fileListByUUID.size(); i++) { + File videoFile = fileListByUUID.get(i); + if (videoFile.getPath().contains(".webp") && !videoFile.getPath().contains("paper.txt")) { + if (videoFile.exists() && !isImageLoad) { + // 使用glide加载视频的第一帧 + AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivPoiVideoPicture, 500); + isImageLoad = true; + } + } + } + fmPoiVideoPic.setTag(fileListByUUID); + } + initPoiVideoSharePre(); + } + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.fm_poi_video_picture: + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了图片查看列表 ,"); + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + if (fileListByUUID.size() > 1) { + Intent photoAlbumIntent = new Intent(getActivity(), FragmentManagement.class); + photoAlbumIntent.putExtra("tag", 36); + photoAlbumIntent.putExtra("showPoiEntity", showPoiEntity); + startActivity(photoAlbumIntent); + } else { + ToastUtils.Message(getActivity(), "请拍摄"); + } + break; + case R.id.btn_poi_video_save: + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了保存本地的按钮 ,"); + initPoiSaveLocal(false); + break; + case R.id.tv_short://点击拍摄 + // 检查是否选择了楼层选择选项 + checkAreaType(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (spnRoadName.getTag()!=null) { // 用户已经设置楼层信息 + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了拍摄的按钮 ,"); + double latitude = Constant.currentLocation.getLatitude(); + double longitude = Constant.currentLocation.getLongitude(); + LatLng startLatLng = new LatLng(latitude, longitude);// 用户当前位置 + double geometry = GeometryTools.distanceToDouble(startLatLng, latLng);// 起點 于用戶的距離 + double rearGeometry = GeometryTools.distanceToDouble(startLatLng, rearLatLng);// 終點于用戶的距離 + if (geometry > rearGeometry) {//用戶在终点开始作业 + if (rearGeometry > 5000) { + ToastUtils.Message(getActivity(), "用户距离作业终点五公里以内才能拍摄"); + return; + } + } else {//用户在起点开始作业 + if (geometry > 5000) { + ToastUtils.Message(getActivity(), "用户距离作业终点五公里以内才能拍摄"); + return; + } + } + Intent intents = new Intent(getActivity(), PicturesActivity.class); + File filePath = AWMp4ParserHelper.getInstance().obtainWebpFilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); + intents.putExtra(Constant.INTENT_JPG_PATH, filePath.getAbsolutePath()); + intents.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType()); + intents.putExtra(Constant.INTENT_GEO_WKT, showPoiEntity.getGeoWkt()); + intents.putExtra(Constant.INTENT_DETAIL, showPoiEntity.getDetail()); + int gpsRssi = Constant.currentLocation.getGPSRssi(); + if (gpsRssi == 0) { + intents.putExtra(Constant.INTENT_BOOLEAN, false); + } else { + intents.putExtra(Constant.INTENT_BOOLEAN, true); + } + startActivityForResult(intents, 0x101); + } + } + }); + break; + case R.id.tv_combo://自动连拍: + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了自动连拍的按钮 ,"); + LatLng startLng = new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()); //用户当前位置 + double geom = GeometryTools.distanceToDouble(startLng, latLng); + double rearGeom = GeometryTools.distanceToDouble(startLng, rearLatLng); + if (geom > rearGeom) {//用戶在终点开始作业 + if (rearGeom > 5000) { + ToastUtils.Message(getActivity(), "用户距离作业终点五公里以内才能拍摄"); + return; + } + } else {//用户在起点开始作业 + if (geom > 5000) { + ToastUtils.Message(getActivity(), "用户距离作业终点五公里以内才能拍摄"); + return; + } + } + Intent intent = new Intent(getActivity(), PicturesActivity.class); + File fileJpgPath = AWMp4ParserHelper.getInstance().obtainWebpFilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); + intent.putExtra(Constant.INTENT_JPG_PATH, fileJpgPath.getAbsolutePath()); + intent.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType()); + intent.putExtra(Constant.INTENT_GEO_WKT, showPoiEntity.getGeoWkt()); + intent.putExtra(Constant.INTENT_DETAIL, showPoiEntity.getDetail()); + int gpsRss = Constant.currentLocation.getGPSRssi(); + if (gpsRss == 0) { + intent.putExtra(Constant.INTENT_BOOLEAN, false); + } else { + intent.putExtra(Constant.INTENT_BOOLEAN, true); + } + startActivityForResult(intent, 0x102); + break; + case R.id.btn_poi_video_upload: + if (spnRoadName.getTag() == null) { + com.github.lazylibrary.util.ToastUtils.showToast(getActivity(), "没有POI名称,无法保存!"); + return; + } + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了上传的按钮 ,"); + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); + if (poiEntity.getTaskStatus() == 1 || poiEntity.getTaskStatus() == 2 || poiEntity.getTaskStatus() == 0 || poiEntity.getTaskStatus() == 5) { + initPoiSaveLocal(true); + } else { + poiVideoUpload(poiEntity); + Constant.isPresent = false; + } + break; + } + } + + private void checkAreaType(View.OnClickListener listener) { + String message; + if (spnRoadName.getTag() == null || spnRoadName.getTag().toString().endsWith("层")) { // 名称下拉框为空,说明选择了 楼层选择,但是没选择楼层层数 + message = "请先选择楼层!"; + if (spnRoadName.getTag()!=null&&spnRoadName.getTag().toString().endsWith("层")) { // 如果当前spn的tag是X层这样的tag,说明已经选择了楼层层数 + message = "请首先拍摄楼层证明"; + } + MessageDialog.show((AppCompatActivity) getActivity(), "提示", message) + .setCustomDialogStyleId(R.style.iOSDialogAnimStyle) + .setAlign(BaseDialog.ALIGN.DEFAULT) + .setOnOkButtonClickListener(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + if (spnRoadName.getTag()!=null) { // 只有tag为非空时,才可以继续走拍照流程 + listener.onClick(v); + } + if (baseDialog.isShow) { + baseDialog.doDismiss(); + } + return true; + } + }); + } else { // 名称下拉框选项不为空,说明选择的不是 楼层选择 选项 + listener.onClick(spnRoadName); + return; + } + } + + public void initPoiSaveLocal(boolean isLocal) { + if (spnRoadName.getTag() == null) { + com.github.lazylibrary.util.ToastUtils.showToast(getActivity(), "没有POI名称,无法保存!"); + return; + } + XXPermissions.with(getContext()) + .permission(Permission.MANAGE_EXTERNAL_STORAGE) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + if (all) { + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); + if (poiEntity.getPhoto() == null||poiEntity.getPhoto().isEmpty()) { + Toast.makeText(getActivity(), "POI录像任务必须拍照!", Toast.LENGTH_LONG).show(); + return; + } + PoiCheckResult poiCheckResult = checkPoiEntity(poiEntity); + if (poiCheckResult.getCode() == 1) { + ToastUtils.Message(getActivity(), poiCheckResult.getMsg()); + return; + } + poiEntity.setTaskStatus(2); + new Thread(new Runnable() { + @Override + public void run() { + InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); + if (getActivity() != null) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + if (isLocal) { + poiVideoSave(poiEntity); + } else { + poiVideoSaveNet(poiEntity); + } + + } + }); + } + } + }).start(); + } else { + ToastUtils.Message(getActivity(), "没有申请权限,请手动申请"); + } + } + + @Override + public void onDenied(List permissions, boolean never) { + if (never) { + ToastUtils.Message(getActivity(), "被永久拒绝授权,请手动授予权限"); + // 如果是被永久拒绝就跳转到应用权限系统设置页面 + XXPermissions.startPermissionActivity(Objects.requireNonNull(getActivity()), permissions); + } + } + }); + } + + private void poiVideoSaveNet(PoiEntity poiEntity) { + HttpParams httpParams = new HttpParams(); + httpParams.put("taskId", poiEntity.getTaskId()); + httpParams.put("name", poiEntity.getName()); + httpParams.put("address", poiEntity.getAddress()); + httpParams.put("workType", 1); + httpParams.put("memo", poiEntity.getMemo()); + OkGoBuilder okGoBuilder = OkGoBuilder.getInstance() + .time(30) + .Builder(getActivity()) + .url(HttpInterface.INSIDE_API_LIST) + .cls(PoiVideoBean.class) + .params(httpParams) + .token(Constant.ACCESS_TOKEN); + if (getActivity() != null) { + okGoBuilder.getRequest(PreserveUtils.getInstance().getPoiVideoPreserveCallback(getActivity(), poiEntity)); + getActivity().getSupportFragmentManager().popBackStack();//回退 + WaitDialog.show((AppCompatActivity) getActivity(), "任务已保存本地,请稍后"); + WaitDialog.dismiss(1000); + } + + } + + private void poiVideoUpload(PoiEntity poiEntity) { + if (poiEntity.getBodyId() == 0) { + ToastUtils.Message(getActivity(), "请先保存本地在上传"); + return; + } + if (Constant.isPresent) { + if (fmPoiVideoPic.getTag() != null) { + List videoFileList = (List) fmPoiVideoPic.getTag(); + boolean existsPic = PoiSaveUtils.getInstance(getActivity()).checkPicExists(videoFileList); + if (!existsPic) { + ToastUtils.Message(getActivity(), "本地不存在照片文件,无法上传数据,请确认!"); + return; + } + DataSaveUtils.getInstance().uploadFiles(getActivity(), showPoiEntity, videoFileList, new DataSaveUtils.UploadCallback() { + @Override + public void onStart() { + dismissLoadingDialog(); + Constant.isPresent = false; + getActivity().getSupportFragmentManager().popBackStack();//回退 + WaitDialog.show((AppCompatActivity) getActivity(), "任务正在后台上传中,请稍候..."); + WaitDialog.dismiss(3000); + } + + @Override + public void onFinish() { + Constant.isPresent = true; + } + + @Override + public void onError() { + + } + }); + } else { + dismissLoadingDialog(); + ToastUtils.Message(getActivity(), "请录像拍照"); + return; + } + } else { + ToastUtils.Message(getActivity(), "该任务正在提交中"); + } + } + + private void poiVideoSave(PoiEntity poiEntity) { + HttpParams httpParams = new HttpParams(); + httpParams.put("taskId", poiEntity.getTaskId()); + httpParams.put("name", poiEntity.getName()); + httpParams.put("address", poiEntity.getAddress()); + httpParams.put("workType", 1); + httpParams.put("memo", poiEntity.getMemo()); + showLoadingDialog(); + OkGoBuilder okGoBuilder = OkGoBuilder.getInstance() + .time(30) + .Builder(getActivity()) + .url(HttpInterface.INSIDE_API_LIST) + .cls(PoiVideoBean.class) + .params(httpParams) + .token(Constant.ACCESS_TOKEN); + okGoBuilder.getRequest(new Callback() { + @Override + public void onSuccess(PoiVideoBean poiVideoBean, int id) { + dismissLoadingDialog(); + 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); + if (getActivity() != null) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + poiVideoUpload(poiEntity); + Constant.isPresent = false; + } + }); + } + } + }).start(); + } else { + ToastUtils.Message(getActivity(), poiVideoBean.getMessage()); + } + } else if (poiVideoBean.getCode() == 230) { + FlushTokenUtil.flushToken(getActivity()); + } else { + ToastUtils.Message(getActivity(), poiVideoBean.getMessage()); + } + } + + @Override + public void onError(Throwable e, int id) { + dismissLoadingDialog(); + String message = e.getMessage(); + assert message != null; + if (message.equals("timeout") || message.equals("Read time out")) { + ToastUtils.Message(getActivity(), "请求超时"); + } else { + ToastUtils.Message(getActivity(), message); + } + } + }); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == 0x101 && resultCode == 0x111) { + if (data != null && data.hasExtra(Constant.INTENT_PICTURES_PATH)) { + String videoPath = data.getStringExtra(Constant.INTENT_PICTURES_PATH); + booleanExtra = data.getBooleanExtra(Constant.INTENT_BOOLEAN, true); + assert videoPath != null; + File videoFile = new File(videoPath); + if (videoFile.exists()) { + AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivPoiVideoPicture, 500); + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + fmPoiVideoPic.setTag(fileListByUUID); + } + } + } + } + + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + initPoiVideoSharePre(); + } + + /* 防止程序崩溃后数据丢失*/ + public void initPoiVideoSharePre() { + //获取SharedPreferences对象,方法中两个参数的意思为:第一个name + //表示文件名,系统将会在/dada/dada/包名/shared_prefs目录下生成 + //一个以该参数命名的.xml文件。第二个mode表示创建的模式,通过查看 + //方法注释得知,建议以0或者MODE_PRIVATE为默认值。 + SharedPreferences poi = Objects.requireNonNull(getActivity()).getSharedPreferences(Constant.DATA_FILE, 0); + //获取Editor对象 + SharedPreferences.Editor edit = poi.edit(); + //根据要保存的数据的类型,调用对应的put方法, + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); + String newPoiEntity = new Gson().toJson(poiEntity); + //以键值对的形式添加新值。 + edit.putString("poiEntity", newPoiEntity); + edit.putInt("roadVideoType", 2); + //提交新值。必须执行,否则前面的操作都无效。 + edit.apply(); + Log.d("TAG", "initRoadSharePre: " + newPoiEntity); + } + + @Override + public void onPause() { + super.onPause(); + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("onPause ,"); + } + + @Override + public void onStop() { + super.onStop(); + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("onStop ,"); + } + + @Override + public void onDestroy() { + if (EventBus.getDefault().isRegistered(this))//加上判断 + EventBus.getDefault().unregister(this); + super.onDestroy(); + if (markerPoiVideo != null) { + markerPoiVideo.remove(); + } + if (poiVideoBuilder != null) { + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("onDestroy "); + poiVideoBuilder.append("\r\n"); + FileUtils.writeFile(logFile.getAbsolutePath(), poiVideoBuilder.toString(), true); + } + } + + private void initEndReceiveTask(String url, PoiEntity poiEntity) { + if (poiEntity == null) { + ToastUtils.Message(getActivity(), "无此任务"); + return; + } + if (poiEntity.getTaskId() == 0) { + ToastUtils.Message(getActivity(), "无此任务"); + return; + } + HttpParams httpParams = new HttpParams(); + httpParams.put("taskIds", poiEntity.getTaskId()); + httpParams.put("auditIds", ""); + OkGoBuilder okGoBuilder = OkGoBuilder.getInstance() + .time(30) + .Builder(getActivity()) + .url(url) + .params(httpParams) + .cls(UnPolygonTaskBean.class) + .token(Constant.ACCESS_TOKEN); + okGoBuilder.getRequest(new Callback() { + @Override + public void onSuccess(UnPolygonTaskBean response, int id) { + dismissLoadingDialog(); + if (response.getCode() == 200) { + new Thread(new Runnable() { + @Override + public void run() { + PoiDatabase.getInstance(getActivity()).getPoiDao().deletePoiEntity(poiEntity); + } + }).start(); + if (poiEntity.getId() != null) { + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(poiEntity.getId()); + for (int i = 0; i < fileListByUUID.size(); i++) { + fileListByUUID.get(i).delete(); + } + File filePath = AWMp4ParserHelper.getInstance().getFilePath(poiEntity.getId()); + filePath.delete(); + } + Message obtain = Message.obtain(); + obtain.what = Constant.JOB_WORD_MONITOR; + obtain.obj = true; + EventBus.getDefault().post(obtain); + } else if (response.getCode() == 230) { + FlushTokenUtil.flushToken(getActivity()); + } else { + ToastUtils.Message(getActivity(), response.getMessage()); + } + } + + @Override + public void onError(Throwable e, int id) { + dismissLoadingDialog(); + String message = e.getMessage(); + assert message != null; + if (message.equals("timeout") || message.equals("Read time out")) { + ToastUtils.Message(getActivity(), "请求超时"); + } else { + ToastUtils.Message(getActivity(), message); + } + } + }); + } + + @Override + protected PoiEntity initPoiEntityByUI(PoiEntity poiEntity) { + if (spnRoadName.getTag()!=null) { + String roadName = spnRoadName.getTag().toString(); + poiEntity.setName(roadName); + } +// if (!roadName.equals("")) { +// poiEntity.setName(roadName); +// } else { +// @SuppressLint("SimpleDateFormat") +// DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); +// Calendar calendars = Calendar.getInstance(); +// calendars.setTimeInMillis(System.currentTimeMillis()); +// String formats = formatter.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()); +// Objects.requireNonNull(getActivity()).runOnUiThread(new Runnable() { +// @Override +// public void run() { +// etRoadName.setText(sb); +// } +// }); +// } + String desc = etDesc.getText().toString().trim(); + if (!desc.equals("")) { + poiEntity.setMemo(desc); + } + @SuppressLint("SimpleDateFormat") + 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.setChecked(false); + poiEntity.setType(3); + if (showPoiEntity.getId() != null) { + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + if (fileListByUUID != null) { + fmPoiVideoPic.setTag(fileListByUUID); + if (booleanExtra) { + List lineStringByFileList = AWMp4ParserHelper.getInstance().getLinePhotoByList(fileListByUUID); + if (lineStringByFileList != null) { + String lineString = Geohash.getInstance().encodeList(lineStringByFileList); + if (lineString != null) { + poiEntity.setDetail(lineString); + } + } + } else { + List lineStringByFileList = AWMp4ParserHelper.getInstance().getGpsLineByList(fileListByUUID); + if (lineStringByFileList != null) { + String lineString = Geohash.getInstance().encodeList(lineStringByFileList); + if (lineString != null) { + poiEntity.setDetail(lineString); + } + } + } + String photoStr = AWMp4ParserHelper.getInstance().getVideoFileListStr(fileListByUUID); + poiEntity.setPhoto(photoStr); + + } + } + return poiEntity; + } + + @Override + protected PoiCheckResult checkPoiEntity(PoiEntity entity) { + PoiCheckResult poiCheckResult = new PoiCheckResult(); + if (entity.getPhoto() == 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/BuildingInsideFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/BuildingInsideFragment.java new file mode 100644 index 0000000..d0e3f12 --- /dev/null +++ b/app/src/main/java/com/navinfo/outdoor/fragment/BuildingInsideFragment.java @@ -0,0 +1,940 @@ +package com.navinfo.outdoor.fragment; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.net.Uri; +import android.os.Bundle; +import android.os.Message; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.Button; +import android.widget.EditText; +import android.widget.FrameLayout; +import android.widget.ImageView; +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; +import androidx.core.widget.NestedScrollView; + +import com.bumptech.glide.Glide; +import com.github.lazylibrary.util.FileUtils; +import com.github.lazylibrary.util.StringUtils; +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.kongzue.dialog.v3.WaitDialog; +import com.lzy.okgo.model.HttpParams; +import com.navinfo.outdoor.R; +import com.navinfo.outdoor.activity.FragmentManagement; +import com.navinfo.outdoor.activity.PicturesActivity; +import com.navinfo.outdoor.api.Constant; +import com.navinfo.outdoor.base.BaseDrawerFragment; +import com.navinfo.outdoor.bean.PoiVideoBean; +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.ChargingPileEntity; +import com.navinfo.outdoor.room.InsertAndUpdateUtils; +import com.navinfo.outdoor.room.PoiDatabase; +import com.navinfo.outdoor.room.PoiEntity; +import com.navinfo.outdoor.ui.view.SpinnerUtils; +import com.navinfo.outdoor.util.AWMp4ParserHelper; +import com.navinfo.outdoor.util.DataSaveUtils; +import com.navinfo.outdoor.util.FlushTokenUtil; +import com.navinfo.outdoor.util.Geohash; +import com.navinfo.outdoor.util.GeometryTools; +import com.navinfo.outdoor.util.PoiSaveUtils; +import com.navinfo.outdoor.util.PreserveUtils; +import com.navinfo.outdoor.util.TimestampUtil; +import com.navinfo.outdoor.util.ToastUtils; +import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; +import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; +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 org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.locationtech.jts.geom.Geometry; + +import java.io.File; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Objects; + +/** + * 寻宝-上报弹窗-建筑物内部 + */ +public class BuildingInsideFragment extends BaseDrawerFragment implements View.OnClickListener { + private EditText etDesc; + private Spinner spnRoadName; + private ImageView ivPoiVideoPicture; + private Button btnRoadSave; + private File fileZip, logFile; + private FrameLayout fmPoiVideoPic; + private LatLng latLng; + private Marker markerPoiVideo; + private TextView tvCombo, tvShort; + private StringBuilder poiVideoBuilder; + private LatLng rearLatLng; + private boolean booleanExtra = true; + + public static BuildingInsideFragment newInstance(Bundle bundle) { + BuildingInsideFragment fragment = new BuildingInsideFragment(); + fragment.setArguments(bundle); + return fragment; + } + + @Override + protected int getLayout() { + return R.layout.traffic_hub_fragment; + } + + @Override + public void onStart() { + super.onStart(); + if (!EventBus.getDefault().isRegistered(this)) {//加上判断 + EventBus.getDefault().register(this); + } + } + + @Override + public void onResume() { + super.onResume(); + View header = mView.findViewById(R.id.traffic_hub_header); + header.findViewById(R.id.iv_final).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + initBack(); + } + }); + header.findViewById(R.id.tv_explain).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(getActivity(), FragmentManagement.class); + intent.putExtra("tag", 8); + startActivity(intent); + } + }); + moveLatlng(latLng, null); + } + + @Override + public boolean onBackPressed() { + initBack(); + return true; + } + + private void initBack() { + if (showPoiEntity != null) { + if (showPoiEntity.getTaskStatus() == 5) { + DialogSettings.style = DialogSettings.STYLE.STYLE_IOS; + MessageDialog.show((AppCompatActivity) Objects.requireNonNull(getActivity()), "提示", "当前在任务作业中,是否退出", "确定", "取消").setOnOkButtonClickListener(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了返回当前页面的 确定 按钮,"); + initEndReceiveTask(HttpInterface.UNRECEIVED_POLYGON_TASK, showPoiEntity); + Objects.requireNonNull(getActivity()).getSupportFragmentManager().popBackStack(); + return false; + } + }); + } else if (showPoiEntity.getTaskStatus() == 0 || showPoiEntity.getTaskStatus() == 1) { + DialogSettings.style = DialogSettings.STYLE.STYLE_IOS; + MessageDialog.show((AppCompatActivity) Objects.requireNonNull(getActivity()), "提示", "当前在任务作业中,是否退出", "确定", "取消").setOnOkButtonClickListener(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了返回当前页面的 确定 按钮,"); + if (showPoiEntity != null) { + if (showPoiEntity.getId() != null) { + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + for (int i = 0; i < fileListByUUID.size(); i++) { + fileListByUUID.get(i).delete(); + } + File filePath = AWMp4ParserHelper.getInstance().getFilePath(showPoiEntity.getId()); + filePath.delete(); + } + } + Message obtain = Message.obtain(); + obtain.what = Constant.JOB_WORD_MONITOR; + obtain.obj = true; + EventBus.getDefault().post(obtain); + Bundle arguments = getArguments(); + if (arguments != null) { + isSliding = arguments.getBoolean("isSliding", true); + } + if (isSliding) { + Message obtain1 = Message.obtain(); + obtain1.what = Constant.TREASURE_FRAGMENT; + obtain1.obj = isSliding; + EventBus.getDefault().post(obtain1); + } + Objects.requireNonNull(getActivity()).getSupportFragmentManager().popBackStack(); + return false; + } + }); + } else { + Message obtain = Message.obtain(); + obtain.what = Constant.JOB_WORD_MONITOR; + obtain.obj = true; + EventBus.getDefault().post(obtain); + Bundle arguments = getArguments(); + if (arguments != null) { + isSliding = arguments.getBoolean("isSliding", true); + } + if (isSliding) { + Message obtain1 = Message.obtain(); + obtain1.what = Constant.TREASURE_FRAGMENT; + obtain1.obj = isSliding; + EventBus.getDefault().post(obtain1); + } + Objects.requireNonNull(getActivity()).getSupportFragmentManager().popBackStack(); + } + } + } + + @Override + protected void initView() { + super.initView(); + setSlidingUpPanelLayout(Constant.SLIDING_LAYOUT); + NestedScrollView nestedScrollView = findViewById(R.id.nested_scroll_view); + if (slidingPaneLayout != null) { + slidingPaneLayout.setScrollableView(nestedScrollView); + } + spnRoadName = findViewById(R.id.spn_poi_video_name); + ivPoiVideoPicture = findViewById(R.id.iv_poi_video_picture); + etDesc = findViewById(R.id.et_desc); + //点击拍照 + tvShort = findViewById(R.id.tv_short); + tvShort.setOnClickListener(this); + //自动连拍 + tvCombo = findViewById(R.id.tv_combo); + tvCombo.setOnClickListener(this); + fmPoiVideoPic = findViewById(R.id.fm_poi_video_picture); + fmPoiVideoPic.setOnClickListener(this); + fmPoiVideoPic.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + DialogSettings.style = DialogSettings.STYLE.STYLE_IOS; + MessageDialog.show((AppCompatActivity) Objects.requireNonNull(getContext()), "提示", "是否删除", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了长按删除图片的 按钮,"); + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + for (int i = 0; i < fileListByUUID.size(); i++) { + fileListByUUID.get(i).delete(); + } + ivPoiVideoPicture.setImageDrawable(null); + fmPoiVideoPic.setTag(null); + return false; + } + }); + return false; + } + }); + btnRoadSave = findViewById(R.id.btn_poi_video_save); + btnRoadSave.setOnClickListener(this); + Button btnPoiVideoUpload = findViewById(R.id.btn_poi_video_upload); + btnPoiVideoUpload.setOnClickListener(this); + //添加数据 + initShowPoi(); + ((TextView)findViewById(R.id.tv1)).setText("建筑物内部"); + } + + @Override + protected void initData() { + super.initData(); + SharedPreferences sharedPreferences = Objects.requireNonNull(getActivity()).getSharedPreferences(Constant.MESSAGE_TYPE, Context.MODE_PRIVATE); + SharedPreferences.Editor sharedEdit = sharedPreferences.edit(); + @SuppressLint("SimpleDateFormat") + DateFormat formatter = new SimpleDateFormat("yyyyMMdd"); + String newFormat = formatter.format(new Date(System.currentTimeMillis())); + String pictures_time = sharedPreferences.getString("pictures_time", null); + if (pictures_time == null) { + sharedEdit.putString("pictures_time", newFormat); + sharedEdit.apply(); + logFile = new File(Constant.LOG_FOLDER + "/" + newFormat + ".txt"); + } else { + if (pictures_time.equals(newFormat)) { + logFile = new File(Constant.LOG_FOLDER + "/" + pictures_time + ".txt"); + } else { + logFile = new File(Constant.LOG_FOLDER + "/" + newFormat + ".txt"); + } + } + poiVideoBuilder = new StringBuilder(); + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("PoiVideoActivity-onCreate-initData ,"); + if (Constant.USHERED != null) { + poiVideoBuilder.append("userId:").append(Constant.USHERED).append(","); + } + } + + private void initShowPoi() { + // 添加信息: + assert getArguments() != null; + showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity"); + if (showPoiEntity != null) { + String name = showPoiEntity.getName();//名称 + SpinnerUtils spinnerUtils = new SpinnerUtils(); + String[] items = {"园区外围(含门)", "园区引导图", "园区底商"}; + if (StringUtils.isEmpty(name)) {// 如果从数据获取的名称为空,则设置name显示为默认的第一个选项 + name = items[0]; + } + spinnerUtils.initSpinner(getActivity(), spnRoadName, new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + spnRoadName.setTag(items[position]); + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + }, name, items); + String geoWkt = showPoiEntity.getGeoWkt(); + if (geoWkt != null) { + String geo = Geohash.getInstance().decode(geoWkt); + Geometry geometry = GeometryTools.createGeometry(geo); + switch (geometry.getGeometryType()) { + case "Point": //点 + latLng = GeometryTools.createLatLng(geo); + break; + case "LineString": //线 + case "Polygon": //面 + List latLineString = GeometryTools.getLatLags(geo); + assert latLineString != null; + latLng = latLineString.get(0);//起點 + rearLatLng = latLineString.get(latLineString.size() - 1);//終點 + break; + } + BitmapDescriptor poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_video_show); + markerPoiVideo = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiVideoDescriptor).anchor(0.5f, 1.0f)); + markerPoiVideo.setZIndex(4); + moveLatlng(latLng, null); + } else { + String detail = showPoiEntity.getDetail(); + if (detail != null) { + String geo = Geohash.getInstance().decode(detail); + Geometry geometry = GeometryTools.createGeometry(geo); + switch (geometry.getGeometryType()) { + case "Point": //点 + latLng = GeometryTools.createLatLng(geo); + break; + case "LineString": //线 + case "Polygon": //面 + List latLineString = GeometryTools.getLatLags(geo); + assert latLineString != null; + latLng = latLineString.get(0); + break; + } + BitmapDescriptor poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_video_show); + markerPoiVideo = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiVideoDescriptor).anchor(0.5f, 1.0f)); + markerPoiVideo.setZIndex(4); + moveLatlng(latLng, null); + } else { + String x = showPoiEntity.getX(); + String y = showPoiEntity.getY(); + if (x != null && y != null) { + latLng = new LatLng(); + latLng.setLongitude(Double.parseDouble(x)); + latLng.setLatitude(Double.parseDouble(y)); + BitmapDescriptor poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_video_show); + markerPoiVideo = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiVideoDescriptor).anchor(0.5f, 1.0f)); + markerPoiVideo.setZIndex(4); + moveLatlng(latLng, null); + } + } + } + String memo = showPoiEntity.getMemo();//任务描述 + if (memo != null && !memo.equals("")) { + etDesc.setText(memo); + } + showPoiEntity.setType(3); + String photoList = showPoiEntity.getPhoto(); + if (!StringUtils.isEmpty(photoList)) { + boolean isImageLoad = false; + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + for (int i = 0; i < fileListByUUID.size(); i++) { + if (fileListByUUID.get(i).getPath().contains(".webp") && !fileListByUUID.get(i).getPath().contains("paper.txt")) { + if (fileListByUUID.get(i).exists() && !isImageLoad) { + // 使用glide加载视频的第一帧 + Glide.with(Objects.requireNonNull(getActivity())).load(fileListByUUID.get(i)).into(ivPoiVideoPicture); + isImageLoad = true; + } + } + } + fmPoiVideoPic.setTag(fileListByUUID); + } + if (showPoiEntity.getTaskStatus() == 3) { + disables();//禁用所有可操作的控件 + } + // 如果是推送的POI录像,不允许修改名称 + if (showPoiEntity.getTaskId()>0) { + spnRoadName.setEnabled(false); + } + } + } + + private void disables() { + spnRoadName.setEnabled(false); + ivPoiVideoPicture.setEnabled(false); + tvShort.setEnabled(false); + tvCombo.setEnabled(false); + etDesc.setEnabled(false); + btnRoadSave.setEnabled(false); + } + + @Subscribe + public void onEvent(Message data) { + if (data.what == Constant.PICTURE_VIDEO_WORD) { + if ((boolean) data.obj) { + initPoiVideoSharePre(); + } + } else if (data.what == Constant.PHOTO_FINISH_VIDEO) { + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + if (fileListByUUID.size() == 1) { + for (int i = 0; i < fileListByUUID.size(); i++) { + fileListByUUID.get(i).delete(); + } + ivPoiVideoPicture.setImageDrawable(null); + fmPoiVideoPic.setTag(null); + } else { + boolean isImageLoad = false; + for (int i = 0; i < fileListByUUID.size(); i++) { + File videoFile = fileListByUUID.get(i); + if (videoFile.getPath().contains(".webp") && !videoFile.getPath().contains("paper.txt")) { + if (videoFile.exists() && !isImageLoad) { + // 使用glide加载视频的第一帧 + AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivPoiVideoPicture, 500); + isImageLoad = true; + } + } + } + fmPoiVideoPic.setTag(fileListByUUID); + } + initPoiVideoSharePre(); + } + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.fm_poi_video_picture: + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了图片查看列表 ,"); + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + if (fileListByUUID.size() > 1) { + Intent photoAlbumIntent = new Intent(getActivity(), FragmentManagement.class); + photoAlbumIntent.putExtra("tag", 36); + photoAlbumIntent.putExtra("showPoiEntity", showPoiEntity); + startActivity(photoAlbumIntent); + } else { + ToastUtils.Message(getActivity(), "请拍摄"); + } + break; + case R.id.btn_poi_video_save: + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了保存本地的按钮 ,"); + initPoiSaveLocal(false); + break; + case R.id.tv_short://点击拍摄 + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了拍摄的按钮 ,"); + double latitude = Constant.currentLocation.getLatitude(); + double longitude = Constant.currentLocation.getLongitude(); + LatLng startLatLng = new LatLng(latitude, longitude);// 用户当前位置 + double geometry = GeometryTools.distanceToDouble(startLatLng, latLng);// 起點 于用戶的距離 + double rearGeometry = GeometryTools.distanceToDouble(startLatLng, rearLatLng);// 終點于用戶的距離 + if (geometry > rearGeometry) {//用戶在终点开始作业 + if (rearGeometry > 5000) { + ToastUtils.Message(getActivity(), "用户距离作业终点五公里以内才能拍摄"); + return; + } + } else {//用户在起点开始作业 + if (geometry > 5000) { + ToastUtils.Message(getActivity(), "用户距离作业终点五公里以内才能拍摄"); + return; + } + } + Intent intents = new Intent(getActivity(), PicturesActivity.class); + File filePath = AWMp4ParserHelper.getInstance().obtainWebpFilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); + intents.putExtra(Constant.INTENT_JPG_PATH, filePath.getAbsolutePath()); + intents.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType()); + intents.putExtra(Constant.INTENT_GEO_WKT, showPoiEntity.getGeoWkt()); + intents.putExtra(Constant.INTENT_DETAIL, showPoiEntity.getDetail()); + int gpsRssi = Constant.currentLocation.getGPSRssi(); + if (gpsRssi == 0) { + intents.putExtra(Constant.INTENT_BOOLEAN, false); + } else { + intents.putExtra(Constant.INTENT_BOOLEAN, true); + } + startActivityForResult(intents, 0x101); + break; + case R.id.tv_combo://自动连拍: + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了自动连拍的按钮 ,"); + LatLng startLng = new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()); //用户当前位置 + double geom = GeometryTools.distanceToDouble(startLng, latLng); + double rearGeom = GeometryTools.distanceToDouble(startLng, rearLatLng); + if (geom > rearGeom) {//用戶在终点开始作业 + if (rearGeom > 5000) { + ToastUtils.Message(getActivity(), "用户距离作业终点五公里以内才能拍摄"); + return; + } + } else {//用户在起点开始作业 + if (geom > 5000) { + ToastUtils.Message(getActivity(), "用户距离作业终点五公里以内才能拍摄"); + return; + } + } + Intent intent = new Intent(getActivity(), PicturesActivity.class); + File fileJpgPath = AWMp4ParserHelper.getInstance().obtainWebpFilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); + intent.putExtra(Constant.INTENT_JPG_PATH, fileJpgPath.getAbsolutePath()); + intent.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType()); + intent.putExtra(Constant.INTENT_GEO_WKT, showPoiEntity.getGeoWkt()); + intent.putExtra(Constant.INTENT_DETAIL, showPoiEntity.getDetail()); + int gpsRss = Constant.currentLocation.getGPSRssi(); + if (gpsRss == 0) { + intent.putExtra(Constant.INTENT_BOOLEAN, false); + } else { + intent.putExtra(Constant.INTENT_BOOLEAN, true); + } + startActivityForResult(intent, 0x102); + break; + case R.id.btn_poi_video_upload: + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了上传的按钮 ,"); + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); + if (poiEntity.getTaskStatus() == 1 || poiEntity.getTaskStatus() == 2 || poiEntity.getTaskStatus() == 0 || poiEntity.getTaskStatus() == 5) { + initPoiSaveLocal(true); + } else { + poiVideoUpload(poiEntity); + Constant.isPresent = false; + } + break; + } + } + + public void initPoiSaveLocal(boolean isLocal) { + if (spnRoadName.getTag() == null) { + com.github.lazylibrary.util.ToastUtils.showToast(getActivity(), "没有POI名称,无法保存!"); + return; + } + XXPermissions.with(getContext()) + .permission(Permission.MANAGE_EXTERNAL_STORAGE) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + if (all) { + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); + if (poiEntity.getPhoto() == null||poiEntity.getPhoto().isEmpty()) { + Toast.makeText(getActivity(), "POI录像任务必须拍照!", Toast.LENGTH_LONG).show(); + return; + } + PoiCheckResult poiCheckResult = checkPoiEntity(poiEntity); + if (poiCheckResult.getCode() == 1) { + ToastUtils.Message(getActivity(), poiCheckResult.getMsg()); + return; + } + poiEntity.setTaskStatus(2); + new Thread(new Runnable() { + @Override + public void run() { + InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); + if (getActivity() != null) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + if (isLocal) { + poiVideoSave(poiEntity); + } else { + poiVideoSaveNet(poiEntity); + } + + } + }); + } + } + }).start(); + } else { + ToastUtils.Message(getActivity(), "没有申请权限,请手动申请"); + } + } + + @Override + public void onDenied(List permissions, boolean never) { + if (never) { + ToastUtils.Message(getActivity(), "被永久拒绝授权,请手动授予权限"); + // 如果是被永久拒绝就跳转到应用权限系统设置页面 + XXPermissions.startPermissionActivity(Objects.requireNonNull(getActivity()), permissions); + } + } + }); + } + + private void poiVideoSaveNet(PoiEntity poiEntity) { + HttpParams httpParams = new HttpParams(); + httpParams.put("taskId", poiEntity.getTaskId()); + httpParams.put("name", poiEntity.getName()); + httpParams.put("address", poiEntity.getAddress()); + httpParams.put("workType", 1); + httpParams.put("memo", poiEntity.getMemo()); + OkGoBuilder okGoBuilder = OkGoBuilder.getInstance() + .time(30) + .Builder(getActivity()) + .url(HttpInterface.INSIDE_API_LIST) + .cls(PoiVideoBean.class) + .params(httpParams) + .token(Constant.ACCESS_TOKEN); + if (getActivity() != null) { + okGoBuilder.getRequest(PreserveUtils.getInstance().getPoiVideoPreserveCallback(getActivity(), poiEntity)); + getActivity().getSupportFragmentManager().popBackStack();//回退 + WaitDialog.show((AppCompatActivity) getActivity(), "任务已保存本地,请稍后"); + WaitDialog.dismiss(1000); + } + + } + + private void poiVideoUpload(PoiEntity poiEntity) { + if (poiEntity.getBodyId() == 0) { + ToastUtils.Message(getActivity(), "请先保存本地在上传"); + return; + } + if (Constant.isPresent) { + if (fmPoiVideoPic.getTag() != null) { + List videoFileList = (List) fmPoiVideoPic.getTag(); + boolean existsPic = PoiSaveUtils.getInstance(getActivity()).checkPicExists(videoFileList); + if (!existsPic) { + ToastUtils.Message(getActivity(), "本地不存在照片文件,无法上传数据,请确认!"); + return; + } + DataSaveUtils.getInstance().uploadFiles(getActivity(), showPoiEntity, videoFileList, new DataSaveUtils.UploadCallback() { + @Override + public void onStart() { + dismissLoadingDialog(); + Constant.isPresent = false; + getActivity().getSupportFragmentManager().popBackStack();//回退 + WaitDialog.show((AppCompatActivity) getActivity(), "任务正在后台上传中,请稍候..."); + WaitDialog.dismiss(3000); + } + + @Override + public void onFinish() { + Constant.isPresent = true; + } + + @Override + public void onError() { + + } + }); + } else { + dismissLoadingDialog(); + ToastUtils.Message(getActivity(), "请录像拍照"); + return; + } + } else { + ToastUtils.Message(getActivity(), "该任务正在提交中"); + } + } + + private void poiVideoSave(PoiEntity poiEntity) { + HttpParams httpParams = new HttpParams(); + httpParams.put("taskId", poiEntity.getTaskId()); + httpParams.put("name", poiEntity.getName()); + httpParams.put("address", poiEntity.getAddress()); + httpParams.put("workType", 1); + httpParams.put("memo", poiEntity.getMemo()); + showLoadingDialog(); + OkGoBuilder okGoBuilder = OkGoBuilder.getInstance() + .time(30) + .Builder(getActivity()) + .url(HttpInterface.INSIDE_API_LIST) + .cls(PoiVideoBean.class) + .params(httpParams) + .token(Constant.ACCESS_TOKEN); + okGoBuilder.getRequest(new Callback() { + @Override + public void onSuccess(PoiVideoBean poiVideoBean, int id) { + dismissLoadingDialog(); + 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); + if (getActivity() != null) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + poiVideoUpload(poiEntity); + Constant.isPresent = false; + } + }); + } + } + }).start(); + } else { + ToastUtils.Message(getActivity(), poiVideoBean.getMessage()); + } + } else if (poiVideoBean.getCode() == 230) { + FlushTokenUtil.flushToken(getActivity()); + } else { + ToastUtils.Message(getActivity(), poiVideoBean.getMessage()); + } + } + + @Override + public void onError(Throwable e, int id) { + dismissLoadingDialog(); + String message = e.getMessage(); + assert message != null; + if (message.equals("timeout") || message.equals("Read time out")) { + ToastUtils.Message(getActivity(), "请求超时"); + } else { + ToastUtils.Message(getActivity(), message); + } + } + }); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == 0x101 && resultCode == 0x111) { + if (data != null && data.hasExtra(Constant.INTENT_PICTURES_PATH)) { + String videoPath = data.getStringExtra(Constant.INTENT_PICTURES_PATH); + booleanExtra = data.getBooleanExtra(Constant.INTENT_BOOLEAN, true); + assert videoPath != null; + File videoFile = new File(videoPath); + if (videoFile.exists()) { + AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivPoiVideoPicture, 500); + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + fmPoiVideoPic.setTag(fileListByUUID); + } + } + } + } + + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + initPoiVideoSharePre(); + } + + /* 防止程序崩溃后数据丢失*/ + public void initPoiVideoSharePre() { + //获取SharedPreferences对象,方法中两个参数的意思为:第一个name + //表示文件名,系统将会在/dada/dada/包名/shared_prefs目录下生成 + //一个以该参数命名的.xml文件。第二个mode表示创建的模式,通过查看 + //方法注释得知,建议以0或者MODE_PRIVATE为默认值。 + SharedPreferences poi = Objects.requireNonNull(getActivity()).getSharedPreferences(Constant.DATA_FILE, 0); + //获取Editor对象 + SharedPreferences.Editor edit = poi.edit(); + //根据要保存的数据的类型,调用对应的put方法, + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); + String newPoiEntity = new Gson().toJson(poiEntity); + //以键值对的形式添加新值。 + edit.putString("poiEntity", newPoiEntity); + edit.putInt("roadVideoType", 3); + //提交新值。必须执行,否则前面的操作都无效。 + edit.apply(); + Log.d("TAG", "initRoadSharePre: " + newPoiEntity); + } + + @Override + public void onPause() { + super.onPause(); + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("onPause ,"); + } + + @Override + public void onStop() { + super.onStop(); + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("onStop ,"); + } + + @Override + public void onDestroy() { + if (EventBus.getDefault().isRegistered(this))//加上判断 + EventBus.getDefault().unregister(this); + super.onDestroy(); + if (markerPoiVideo != null) { + markerPoiVideo.remove(); + } + if (poiVideoBuilder != null) { + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("onDestroy "); + poiVideoBuilder.append("\r\n"); + FileUtils.writeFile(logFile.getAbsolutePath(), poiVideoBuilder.toString(), true); + } + } + + private void initEndReceiveTask(String url, PoiEntity poiEntity) { + if (poiEntity == null) { + ToastUtils.Message(getActivity(), "无此任务"); + return; + } + if (poiEntity.getTaskId() == 0) { + ToastUtils.Message(getActivity(), "无此任务"); + return; + } + HttpParams httpParams = new HttpParams(); + httpParams.put("taskIds", poiEntity.getTaskId()); + httpParams.put("auditIds", ""); + OkGoBuilder okGoBuilder = OkGoBuilder.getInstance() + .time(30) + .Builder(getActivity()) + .url(url) + .params(httpParams) + .cls(UnPolygonTaskBean.class) + .token(Constant.ACCESS_TOKEN); + okGoBuilder.getRequest(new Callback() { + @Override + public void onSuccess(UnPolygonTaskBean response, int id) { + dismissLoadingDialog(); + if (response.getCode() == 200) { + new Thread(new Runnable() { + @Override + public void run() { + PoiDatabase.getInstance(getActivity()).getPoiDao().deletePoiEntity(poiEntity); + } + }).start(); + if (poiEntity.getId() != null) { + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(poiEntity.getId()); + for (int i = 0; i < fileListByUUID.size(); i++) { + fileListByUUID.get(i).delete(); + } + File filePath = AWMp4ParserHelper.getInstance().getFilePath(poiEntity.getId()); + filePath.delete(); + } + Message obtain = Message.obtain(); + obtain.what = Constant.JOB_WORD_MONITOR; + obtain.obj = true; + EventBus.getDefault().post(obtain); + } else if (response.getCode() == 230) { + FlushTokenUtil.flushToken(getActivity()); + } else { + ToastUtils.Message(getActivity(), response.getMessage()); + } + } + + @Override + public void onError(Throwable e, int id) { + dismissLoadingDialog(); + String message = e.getMessage(); + assert message != null; + if (message.equals("timeout") || message.equals("Read time out")) { + ToastUtils.Message(getActivity(), "请求超时"); + } else { + ToastUtils.Message(getActivity(), message); + } + } + }); + } + + @Override + protected PoiEntity initPoiEntityByUI(PoiEntity poiEntity) { + String roadName = spnRoadName.getTag().toString(); + poiEntity.setName(roadName); +// if (!roadName.equals("")) { +// poiEntity.setName(roadName); +// } else { +// @SuppressLint("SimpleDateFormat") +// DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); +// Calendar calendars = Calendar.getInstance(); +// calendars.setTimeInMillis(System.currentTimeMillis()); +// String formats = formatter.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()); +// Objects.requireNonNull(getActivity()).runOnUiThread(new Runnable() { +// @Override +// public void run() { +// etRoadName.setText(sb); +// } +// }); +// } + String desc = etDesc.getText().toString().trim(); + if (!desc.equals("")) { + poiEntity.setMemo(desc); + } + @SuppressLint("SimpleDateFormat") + 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.setChecked(false); + poiEntity.setType(3); + if (showPoiEntity.getId() != null) { + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + if (fileListByUUID != null) { + fmPoiVideoPic.setTag(fileListByUUID); + if (booleanExtra) { + List lineStringByFileList = AWMp4ParserHelper.getInstance().getLinePhotoByList(fileListByUUID); + if (lineStringByFileList != null) { + String lineString = Geohash.getInstance().encodeList(lineStringByFileList); + if (lineString != null) { + poiEntity.setDetail(lineString); + } + } + } else { + List lineStringByFileList = AWMp4ParserHelper.getInstance().getGpsLineByList(fileListByUUID); + if (lineStringByFileList != null) { + String lineString = Geohash.getInstance().encodeList(lineStringByFileList); + if (lineString != null) { + poiEntity.setDetail(lineString); + } + } + } + String photoStr = AWMp4ParserHelper.getInstance().getVideoFileListStr(fileListByUUID); + poiEntity.setPhoto(photoStr); + + } + } + return poiEntity; + } + + @Override + protected PoiCheckResult checkPoiEntity(PoiEntity entity) { + PoiCheckResult poiCheckResult = new PoiCheckResult(); + if (entity.getPhoto() == 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/TrafficHubFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/TrafficHubFragment.java new file mode 100644 index 0000000..b6f6a13 --- /dev/null +++ b/app/src/main/java/com/navinfo/outdoor/fragment/TrafficHubFragment.java @@ -0,0 +1,940 @@ +package com.navinfo.outdoor.fragment; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.net.Uri; +import android.os.Bundle; +import android.os.Message; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.Button; +import android.widget.EditText; +import android.widget.FrameLayout; +import android.widget.ImageView; +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; +import androidx.core.widget.NestedScrollView; + +import com.bumptech.glide.Glide; +import com.github.lazylibrary.util.FileUtils; +import com.github.lazylibrary.util.StringUtils; +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.kongzue.dialog.v3.WaitDialog; +import com.lzy.okgo.model.HttpParams; +import com.navinfo.outdoor.R; +import com.navinfo.outdoor.activity.FragmentManagement; +import com.navinfo.outdoor.activity.PicturesActivity; +import com.navinfo.outdoor.api.Constant; +import com.navinfo.outdoor.base.BaseDrawerFragment; +import com.navinfo.outdoor.bean.PoiVideoBean; +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.ChargingPileEntity; +import com.navinfo.outdoor.room.InsertAndUpdateUtils; +import com.navinfo.outdoor.room.PoiDatabase; +import com.navinfo.outdoor.room.PoiEntity; +import com.navinfo.outdoor.ui.view.SpinnerUtils; +import com.navinfo.outdoor.util.AWMp4ParserHelper; +import com.navinfo.outdoor.util.DataSaveUtils; +import com.navinfo.outdoor.util.FlushTokenUtil; +import com.navinfo.outdoor.util.Geohash; +import com.navinfo.outdoor.util.GeometryTools; +import com.navinfo.outdoor.util.PoiSaveUtils; +import com.navinfo.outdoor.util.PreserveUtils; +import com.navinfo.outdoor.util.TimestampUtil; +import com.navinfo.outdoor.util.ToastUtils; +import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; +import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; +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 org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.locationtech.jts.geom.Geometry; + +import java.io.File; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Objects; + +/** + * 寻宝-上报弹窗-交通枢纽 + */ +public class TrafficHubFragment extends BaseDrawerFragment implements View.OnClickListener { + private EditText etDesc; + private Spinner spnRoadName; + private ImageView ivPoiVideoPicture; + private Button btnRoadSave; + private File fileZip, logFile; + private FrameLayout fmPoiVideoPic; + private LatLng latLng; + private Marker markerPoiVideo; + private TextView tvCombo, tvShort; + private StringBuilder poiVideoBuilder; + private LatLng rearLatLng; + private boolean booleanExtra = true; + + public static TrafficHubFragment newInstance(Bundle bundle) { + TrafficHubFragment fragment = new TrafficHubFragment(); + fragment.setArguments(bundle); + return fragment; + } + + @Override + protected int getLayout() { + return R.layout.traffic_hub_fragment; + } + + @Override + public void onStart() { + super.onStart(); + if (!EventBus.getDefault().isRegistered(this)) {//加上判断 + EventBus.getDefault().register(this); + } + } + + @Override + public void onResume() { + super.onResume(); + View header = mView.findViewById(R.id.traffic_hub_header); + header.findViewById(R.id.iv_final).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + initBack(); + } + }); + header.findViewById(R.id.tv_explain).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(getActivity(), FragmentManagement.class); + intent.putExtra("tag", 8); + startActivity(intent); + } + }); + moveLatlng(latLng, null); + } + + @Override + public boolean onBackPressed() { + initBack(); + return true; + } + + private void initBack() { + if (showPoiEntity != null) { + if (showPoiEntity.getTaskStatus() == 5) { + DialogSettings.style = DialogSettings.STYLE.STYLE_IOS; + MessageDialog.show((AppCompatActivity) Objects.requireNonNull(getActivity()), "提示", "当前在任务作业中,是否退出", "确定", "取消").setOnOkButtonClickListener(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了返回当前页面的 确定 按钮,"); + initEndReceiveTask(HttpInterface.UNRECEIVED_POLYGON_TASK, showPoiEntity); + Objects.requireNonNull(getActivity()).getSupportFragmentManager().popBackStack(); + return false; + } + }); + } else if (showPoiEntity.getTaskStatus() == 0 || showPoiEntity.getTaskStatus() == 1) { + DialogSettings.style = DialogSettings.STYLE.STYLE_IOS; + MessageDialog.show((AppCompatActivity) Objects.requireNonNull(getActivity()), "提示", "当前在任务作业中,是否退出", "确定", "取消").setOnOkButtonClickListener(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了返回当前页面的 确定 按钮,"); + if (showPoiEntity != null) { + if (showPoiEntity.getId() != null) { + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + for (int i = 0; i < fileListByUUID.size(); i++) { + fileListByUUID.get(i).delete(); + } + File filePath = AWMp4ParserHelper.getInstance().getFilePath(showPoiEntity.getId()); + filePath.delete(); + } + } + Message obtain = Message.obtain(); + obtain.what = Constant.JOB_WORD_MONITOR; + obtain.obj = true; + EventBus.getDefault().post(obtain); + Bundle arguments = getArguments(); + if (arguments != null) { + isSliding = arguments.getBoolean("isSliding", true); + } + if (isSliding) { + Message obtain1 = Message.obtain(); + obtain1.what = Constant.TREASURE_FRAGMENT; + obtain1.obj = isSliding; + EventBus.getDefault().post(obtain1); + } + Objects.requireNonNull(getActivity()).getSupportFragmentManager().popBackStack(); + return false; + } + }); + } else { + Message obtain = Message.obtain(); + obtain.what = Constant.JOB_WORD_MONITOR; + obtain.obj = true; + EventBus.getDefault().post(obtain); + Bundle arguments = getArguments(); + if (arguments != null) { + isSliding = arguments.getBoolean("isSliding", true); + } + if (isSliding) { + Message obtain1 = Message.obtain(); + obtain1.what = Constant.TREASURE_FRAGMENT; + obtain1.obj = isSliding; + EventBus.getDefault().post(obtain1); + } + Objects.requireNonNull(getActivity()).getSupportFragmentManager().popBackStack(); + } + } + } + + @Override + protected void initView() { + super.initView(); + setSlidingUpPanelLayout(Constant.SLIDING_LAYOUT); + NestedScrollView nestedScrollView = findViewById(R.id.nested_scroll_view); + if (slidingPaneLayout != null) { + slidingPaneLayout.setScrollableView(nestedScrollView); + } + spnRoadName = findViewById(R.id.spn_poi_video_name); + ivPoiVideoPicture = findViewById(R.id.iv_poi_video_picture); + etDesc = findViewById(R.id.et_desc); + //点击拍照 + tvShort = findViewById(R.id.tv_short); + tvShort.setOnClickListener(this); + //自动连拍 + tvCombo = findViewById(R.id.tv_combo); + tvCombo.setOnClickListener(this); + fmPoiVideoPic = findViewById(R.id.fm_poi_video_picture); + fmPoiVideoPic.setOnClickListener(this); + fmPoiVideoPic.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + DialogSettings.style = DialogSettings.STYLE.STYLE_IOS; + MessageDialog.show((AppCompatActivity) Objects.requireNonNull(getContext()), "提示", "是否删除", "确定", "取消").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了长按删除图片的 按钮,"); + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + for (int i = 0; i < fileListByUUID.size(); i++) { + fileListByUUID.get(i).delete(); + } + ivPoiVideoPicture.setImageDrawable(null); + fmPoiVideoPic.setTag(null); + return false; + } + }); + return false; + } + }); + btnRoadSave = findViewById(R.id.btn_poi_video_save); + btnRoadSave.setOnClickListener(this); + Button btnPoiVideoUpload = findViewById(R.id.btn_poi_video_upload); + btnPoiVideoUpload.setOnClickListener(this); + //添加数据 + initShowPoi(); + ((TextView)findViewById(R.id.tv1)).setText("交通枢纽"); + } + + @Override + protected void initData() { + super.initData(); + SharedPreferences sharedPreferences = Objects.requireNonNull(getActivity()).getSharedPreferences(Constant.MESSAGE_TYPE, Context.MODE_PRIVATE); + SharedPreferences.Editor sharedEdit = sharedPreferences.edit(); + @SuppressLint("SimpleDateFormat") + DateFormat formatter = new SimpleDateFormat("yyyyMMdd"); + String newFormat = formatter.format(new Date(System.currentTimeMillis())); + String pictures_time = sharedPreferences.getString("pictures_time", null); + if (pictures_time == null) { + sharedEdit.putString("pictures_time", newFormat); + sharedEdit.apply(); + logFile = new File(Constant.LOG_FOLDER + "/" + newFormat + ".txt"); + } else { + if (pictures_time.equals(newFormat)) { + logFile = new File(Constant.LOG_FOLDER + "/" + pictures_time + ".txt"); + } else { + logFile = new File(Constant.LOG_FOLDER + "/" + newFormat + ".txt"); + } + } + poiVideoBuilder = new StringBuilder(); + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("PoiVideoActivity-onCreate-initData ,"); + if (Constant.USHERED != null) { + poiVideoBuilder.append("userId:").append(Constant.USHERED).append(","); + } + } + + private void initShowPoi() { + // 添加信息: + assert getArguments() != null; + showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity"); + if (showPoiEntity != null) { + String name = showPoiEntity.getName();//名称 + SpinnerUtils spinnerUtils = new SpinnerUtils(); + String[] items = {"交通枢纽全景", "引导图", "出发、到达层", "停车场", "其他"}; + if (StringUtils.isEmpty(name)) { // 如果从数据获取的名称为空,则设置name显示为默认的第一个选项 + name = items[0]; + } + spinnerUtils.initSpinner(getActivity(), spnRoadName, new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + spnRoadName.setTag(items[position]); + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + }, name, items); + String geoWkt = showPoiEntity.getGeoWkt(); + if (geoWkt != null) { + String geo = Geohash.getInstance().decode(geoWkt); + Geometry geometry = GeometryTools.createGeometry(geo); + switch (geometry.getGeometryType()) { + case "Point": //点 + latLng = GeometryTools.createLatLng(geo); + break; + case "LineString": //线 + case "Polygon": //面 + List latLineString = GeometryTools.getLatLags(geo); + assert latLineString != null; + latLng = latLineString.get(0);//起點 + rearLatLng = latLineString.get(latLineString.size() - 1);//終點 + break; + } + BitmapDescriptor poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_video_show); + markerPoiVideo = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiVideoDescriptor).anchor(0.5f, 1.0f)); + markerPoiVideo.setZIndex(4); + moveLatlng(latLng, null); + } else { + String detail = showPoiEntity.getDetail(); + if (detail != null) { + String geo = Geohash.getInstance().decode(detail); + Geometry geometry = GeometryTools.createGeometry(geo); + switch (geometry.getGeometryType()) { + case "Point": //点 + latLng = GeometryTools.createLatLng(geo); + break; + case "LineString": //线 + case "Polygon": //面 + List latLineString = GeometryTools.getLatLags(geo); + assert latLineString != null; + latLng = latLineString.get(0); + break; + } + BitmapDescriptor poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_video_show); + markerPoiVideo = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiVideoDescriptor).anchor(0.5f, 1.0f)); + markerPoiVideo.setZIndex(4); + moveLatlng(latLng, null); + } else { + String x = showPoiEntity.getX(); + String y = showPoiEntity.getY(); + if (x != null && y != null) { + latLng = new LatLng(); + latLng.setLongitude(Double.parseDouble(x)); + latLng.setLatitude(Double.parseDouble(y)); + BitmapDescriptor poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_video_show); + markerPoiVideo = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiVideoDescriptor).anchor(0.5f, 1.0f)); + markerPoiVideo.setZIndex(4); + moveLatlng(latLng, null); + } + } + } + String memo = showPoiEntity.getMemo();//任务描述 + if (memo != null && !memo.equals("")) { + etDesc.setText(memo); + } + showPoiEntity.setType(3); + String photoList = showPoiEntity.getPhoto(); + if (!StringUtils.isEmpty(photoList)) { + boolean isImageLoad = false; + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + for (int i = 0; i < fileListByUUID.size(); i++) { + if (fileListByUUID.get(i).getPath().contains(".webp") && !fileListByUUID.get(i).getPath().contains("paper.txt")) { + if (fileListByUUID.get(i).exists() && !isImageLoad) { + // 使用glide加载视频的第一帧 + Glide.with(Objects.requireNonNull(getActivity())).load(fileListByUUID.get(i)).into(ivPoiVideoPicture); + isImageLoad = true; + } + } + } + fmPoiVideoPic.setTag(fileListByUUID); + } + if (showPoiEntity.getTaskStatus() == 3) { + disables();//禁用所有可操作的控件 + } + // 如果是推送的POI录像,不允许修改名称 + if (showPoiEntity.getTaskId()>0) { + spnRoadName.setEnabled(false); + } + } + } + + private void disables() { + spnRoadName.setEnabled(false); + ivPoiVideoPicture.setEnabled(false); + tvShort.setEnabled(false); + tvCombo.setEnabled(false); + etDesc.setEnabled(false); + btnRoadSave.setEnabled(false); + } + + @Subscribe + public void onEvent(Message data) { + if (data.what == Constant.PICTURE_VIDEO_WORD) { + if ((boolean) data.obj) { + initPoiVideoSharePre(); + } + } else if (data.what == Constant.PHOTO_FINISH_VIDEO) { + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + if (fileListByUUID.size() == 1) { + for (int i = 0; i < fileListByUUID.size(); i++) { + fileListByUUID.get(i).delete(); + } + ivPoiVideoPicture.setImageDrawable(null); + fmPoiVideoPic.setTag(null); + } else { + boolean isImageLoad = false; + for (int i = 0; i < fileListByUUID.size(); i++) { + File videoFile = fileListByUUID.get(i); + if (videoFile.getPath().contains(".webp") && !videoFile.getPath().contains("paper.txt")) { + if (videoFile.exists() && !isImageLoad) { + // 使用glide加载视频的第一帧 + AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivPoiVideoPicture, 500); + isImageLoad = true; + } + } + } + fmPoiVideoPic.setTag(fileListByUUID); + } + initPoiVideoSharePre(); + } + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.fm_poi_video_picture: + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了图片查看列表 ,"); + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + if (fileListByUUID.size() > 1) { + Intent photoAlbumIntent = new Intent(getActivity(), FragmentManagement.class); + photoAlbumIntent.putExtra("tag", 36); + photoAlbumIntent.putExtra("showPoiEntity", showPoiEntity); + startActivity(photoAlbumIntent); + } else { + ToastUtils.Message(getActivity(), "请拍摄"); + } + break; + case R.id.btn_poi_video_save: + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了保存本地的按钮 ,"); + initPoiSaveLocal(false); + break; + case R.id.tv_short://点击拍摄 + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了拍摄的按钮 ,"); + double latitude = Constant.currentLocation.getLatitude(); + double longitude = Constant.currentLocation.getLongitude(); + LatLng startLatLng = new LatLng(latitude, longitude);// 用户当前位置 + double geometry = GeometryTools.distanceToDouble(startLatLng, latLng);// 起點 于用戶的距離 + double rearGeometry = GeometryTools.distanceToDouble(startLatLng, rearLatLng);// 終點于用戶的距離 + if (geometry > rearGeometry) {//用戶在终点开始作业 + if (rearGeometry > 5000) { + ToastUtils.Message(getActivity(), "用户距离作业终点五公里以内才能拍摄"); + return; + } + } else {//用户在起点开始作业 + if (geometry > 5000) { + ToastUtils.Message(getActivity(), "用户距离作业终点五公里以内才能拍摄"); + return; + } + } + Intent intents = new Intent(getActivity(), PicturesActivity.class); + File filePath = AWMp4ParserHelper.getInstance().obtainWebpFilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); + intents.putExtra(Constant.INTENT_JPG_PATH, filePath.getAbsolutePath()); + intents.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType()); + intents.putExtra(Constant.INTENT_GEO_WKT, showPoiEntity.getGeoWkt()); + intents.putExtra(Constant.INTENT_DETAIL, showPoiEntity.getDetail()); + int gpsRssi = Constant.currentLocation.getGPSRssi(); + if (gpsRssi == 0) { + intents.putExtra(Constant.INTENT_BOOLEAN, false); + } else { + intents.putExtra(Constant.INTENT_BOOLEAN, true); + } + startActivityForResult(intents, 0x101); + break; + case R.id.tv_combo://自动连拍: + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了自动连拍的按钮 ,"); + LatLng startLng = new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()); //用户当前位置 + double geom = GeometryTools.distanceToDouble(startLng, latLng); + double rearGeom = GeometryTools.distanceToDouble(startLng, rearLatLng); + if (geom > rearGeom) {//用戶在终点开始作业 + if (rearGeom > 5000) { + ToastUtils.Message(getActivity(), "用户距离作业终点五公里以内才能拍摄"); + return; + } + } else {//用户在起点开始作业 + if (geom > 5000) { + ToastUtils.Message(getActivity(), "用户距离作业终点五公里以内才能拍摄"); + return; + } + } + Intent intent = new Intent(getActivity(), PicturesActivity.class); + File fileJpgPath = AWMp4ParserHelper.getInstance().obtainWebpFilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); + intent.putExtra(Constant.INTENT_JPG_PATH, fileJpgPath.getAbsolutePath()); + intent.putExtra(Constant.INTENT_TYPE, showPoiEntity.getType()); + intent.putExtra(Constant.INTENT_GEO_WKT, showPoiEntity.getGeoWkt()); + intent.putExtra(Constant.INTENT_DETAIL, showPoiEntity.getDetail()); + int gpsRss = Constant.currentLocation.getGPSRssi(); + if (gpsRss == 0) { + intent.putExtra(Constant.INTENT_BOOLEAN, false); + } else { + intent.putExtra(Constant.INTENT_BOOLEAN, true); + } + startActivityForResult(intent, 0x102); + break; + case R.id.btn_poi_video_upload: + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("点击了上传的按钮 ,"); + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); + if (poiEntity.getTaskStatus() == 1 || poiEntity.getTaskStatus() == 2 || poiEntity.getTaskStatus() == 0 || poiEntity.getTaskStatus() == 5) { + initPoiSaveLocal(true); + } else { + poiVideoUpload(poiEntity); + Constant.isPresent = false; + } + break; + } + } + + public void initPoiSaveLocal(boolean isLocal) { + if (spnRoadName.getTag() == null) { + com.github.lazylibrary.util.ToastUtils.showToast(getActivity(), "没有POI名称,无法保存!"); + return; + } + XXPermissions.with(getContext()) + .permission(Permission.MANAGE_EXTERNAL_STORAGE) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + if (all) { + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); + if (poiEntity.getPhoto() == null||poiEntity.getPhoto().isEmpty()) { + Toast.makeText(getActivity(), "POI录像任务必须拍照!", Toast.LENGTH_LONG).show(); + return; + } + PoiCheckResult poiCheckResult = checkPoiEntity(poiEntity); + if (poiCheckResult.getCode() == 1) { + ToastUtils.Message(getActivity(), poiCheckResult.getMsg()); + return; + } + poiEntity.setTaskStatus(2); + new Thread(new Runnable() { + @Override + public void run() { + InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); + if (getActivity() != null) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + if (isLocal) { + poiVideoSave(poiEntity); + } else { + poiVideoSaveNet(poiEntity); + } + + } + }); + } + } + }).start(); + } else { + ToastUtils.Message(getActivity(), "没有申请权限,请手动申请"); + } + } + + @Override + public void onDenied(List permissions, boolean never) { + if (never) { + ToastUtils.Message(getActivity(), "被永久拒绝授权,请手动授予权限"); + // 如果是被永久拒绝就跳转到应用权限系统设置页面 + XXPermissions.startPermissionActivity(Objects.requireNonNull(getActivity()), permissions); + } + } + }); + } + + private void poiVideoSaveNet(PoiEntity poiEntity) { + HttpParams httpParams = new HttpParams(); + httpParams.put("taskId", poiEntity.getTaskId()); + httpParams.put("name", poiEntity.getName()); + httpParams.put("address", poiEntity.getAddress()); + httpParams.put("workType", 1); + httpParams.put("memo", poiEntity.getMemo()); + OkGoBuilder okGoBuilder = OkGoBuilder.getInstance() + .time(30) + .Builder(getActivity()) + .url(HttpInterface.INSIDE_API_LIST) + .cls(PoiVideoBean.class) + .params(httpParams) + .token(Constant.ACCESS_TOKEN); + if (getActivity() != null) { + okGoBuilder.getRequest(PreserveUtils.getInstance().getPoiVideoPreserveCallback(getActivity(), poiEntity)); + getActivity().getSupportFragmentManager().popBackStack();//回退 + WaitDialog.show((AppCompatActivity) getActivity(), "任务已保存本地,请稍后"); + WaitDialog.dismiss(1000); + } + + } + + private void poiVideoUpload(PoiEntity poiEntity) { + if (poiEntity.getBodyId() == 0) { + ToastUtils.Message(getActivity(), "请先保存本地在上传"); + return; + } + if (Constant.isPresent) { + if (fmPoiVideoPic.getTag() != null) { + List videoFileList = (List) fmPoiVideoPic.getTag(); + boolean existsPic = PoiSaveUtils.getInstance(getActivity()).checkPicExists(videoFileList); + if (!existsPic) { + ToastUtils.Message(getActivity(), "本地不存在照片文件,无法上传数据,请确认!"); + return; + } + DataSaveUtils.getInstance().uploadFiles(getActivity(), showPoiEntity, videoFileList, new DataSaveUtils.UploadCallback() { + @Override + public void onStart() { + dismissLoadingDialog(); + Constant.isPresent = false; + getActivity().getSupportFragmentManager().popBackStack();//回退 + WaitDialog.show((AppCompatActivity) getActivity(), "任务正在后台上传中,请稍候..."); + WaitDialog.dismiss(3000); + } + + @Override + public void onFinish() { + Constant.isPresent = true; + } + + @Override + public void onError() { + + } + }); + } else { + dismissLoadingDialog(); + ToastUtils.Message(getActivity(), "请录像拍照"); + return; + } + } else { + ToastUtils.Message(getActivity(), "该任务正在提交中"); + } + } + + private void poiVideoSave(PoiEntity poiEntity) { + HttpParams httpParams = new HttpParams(); + httpParams.put("taskId", poiEntity.getTaskId()); + httpParams.put("name", poiEntity.getName()); + httpParams.put("address", poiEntity.getAddress()); + httpParams.put("workType", 1); + httpParams.put("memo", poiEntity.getMemo()); + showLoadingDialog(); + OkGoBuilder okGoBuilder = OkGoBuilder.getInstance() + .time(30) + .Builder(getActivity()) + .url(HttpInterface.INSIDE_API_LIST) + .cls(PoiVideoBean.class) + .params(httpParams) + .token(Constant.ACCESS_TOKEN); + okGoBuilder.getRequest(new Callback() { + @Override + public void onSuccess(PoiVideoBean poiVideoBean, int id) { + dismissLoadingDialog(); + 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); + if (getActivity() != null) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + poiVideoUpload(poiEntity); + Constant.isPresent = false; + } + }); + } + } + }).start(); + } else { + ToastUtils.Message(getActivity(), poiVideoBean.getMessage()); + } + } else if (poiVideoBean.getCode() == 230) { + FlushTokenUtil.flushToken(getActivity()); + } else { + ToastUtils.Message(getActivity(), poiVideoBean.getMessage()); + } + } + + @Override + public void onError(Throwable e, int id) { + dismissLoadingDialog(); + String message = e.getMessage(); + assert message != null; + if (message.equals("timeout") || message.equals("Read time out")) { + ToastUtils.Message(getActivity(), "请求超时"); + } else { + ToastUtils.Message(getActivity(), message); + } + } + }); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == 0x101 && resultCode == 0x111) { + if (data != null && data.hasExtra(Constant.INTENT_PICTURES_PATH)) { + String videoPath = data.getStringExtra(Constant.INTENT_PICTURES_PATH); + booleanExtra = data.getBooleanExtra(Constant.INTENT_BOOLEAN, true); + assert videoPath != null; + File videoFile = new File(videoPath); + if (videoFile.exists()) { + AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivPoiVideoPicture, 500); + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + fmPoiVideoPic.setTag(fileListByUUID); + } + } + } + } + + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + initPoiVideoSharePre(); + } + + /* 防止程序崩溃后数据丢失*/ + public void initPoiVideoSharePre() { + //获取SharedPreferences对象,方法中两个参数的意思为:第一个name + //表示文件名,系统将会在/dada/dada/包名/shared_prefs目录下生成 + //一个以该参数命名的.xml文件。第二个mode表示创建的模式,通过查看 + //方法注释得知,建议以0或者MODE_PRIVATE为默认值。 + SharedPreferences poi = Objects.requireNonNull(getActivity()).getSharedPreferences(Constant.DATA_FILE, 0); + //获取Editor对象 + SharedPreferences.Editor edit = poi.edit(); + //根据要保存的数据的类型,调用对应的put方法, + PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity); + String newPoiEntity = new Gson().toJson(poiEntity); + //以键值对的形式添加新值。 + edit.putString("poiEntity", newPoiEntity); + edit.putInt("roadVideoType", 1); + //提交新值。必须执行,否则前面的操作都无效。 + edit.apply(); + Log.d("TAG", "initRoadSharePre: " + newPoiEntity); + } + + @Override + public void onPause() { + super.onPause(); + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("onPause ,"); + } + + @Override + public void onStop() { + super.onStop(); + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("onStop ,"); + } + + @Override + public void onDestroy() { + if (EventBus.getDefault().isRegistered(this))//加上判断 + EventBus.getDefault().unregister(this); + super.onDestroy(); + if (markerPoiVideo != null) { + markerPoiVideo.remove(); + } + if (poiVideoBuilder != null) { + poiVideoBuilder.append(TimestampUtil.time()).append(",").append("onDestroy "); + poiVideoBuilder.append("\r\n"); + FileUtils.writeFile(logFile.getAbsolutePath(), poiVideoBuilder.toString(), true); + } + } + + private void initEndReceiveTask(String url, PoiEntity poiEntity) { + if (poiEntity == null) { + ToastUtils.Message(getActivity(), "无此任务"); + return; + } + if (poiEntity.getTaskId() == 0) { + ToastUtils.Message(getActivity(), "无此任务"); + return; + } + HttpParams httpParams = new HttpParams(); + httpParams.put("taskIds", poiEntity.getTaskId()); + httpParams.put("auditIds", ""); + OkGoBuilder okGoBuilder = OkGoBuilder.getInstance() + .time(30) + .Builder(getActivity()) + .url(url) + .params(httpParams) + .cls(UnPolygonTaskBean.class) + .token(Constant.ACCESS_TOKEN); + okGoBuilder.getRequest(new Callback() { + @Override + public void onSuccess(UnPolygonTaskBean response, int id) { + dismissLoadingDialog(); + if (response.getCode() == 200) { + new Thread(new Runnable() { + @Override + public void run() { + PoiDatabase.getInstance(getActivity()).getPoiDao().deletePoiEntity(poiEntity); + } + }).start(); + if (poiEntity.getId() != null) { + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(poiEntity.getId()); + for (int i = 0; i < fileListByUUID.size(); i++) { + fileListByUUID.get(i).delete(); + } + File filePath = AWMp4ParserHelper.getInstance().getFilePath(poiEntity.getId()); + filePath.delete(); + } + Message obtain = Message.obtain(); + obtain.what = Constant.JOB_WORD_MONITOR; + obtain.obj = true; + EventBus.getDefault().post(obtain); + } else if (response.getCode() == 230) { + FlushTokenUtil.flushToken(getActivity()); + } else { + ToastUtils.Message(getActivity(), response.getMessage()); + } + } + + @Override + public void onError(Throwable e, int id) { + dismissLoadingDialog(); + String message = e.getMessage(); + assert message != null; + if (message.equals("timeout") || message.equals("Read time out")) { + ToastUtils.Message(getActivity(), "请求超时"); + } else { + ToastUtils.Message(getActivity(), message); + } + } + }); + } + + @Override + protected PoiEntity initPoiEntityByUI(PoiEntity poiEntity) { + String roadName = spnRoadName.getTag().toString(); + poiEntity.setName(roadName); +// if (!roadName.equals("")) { +// poiEntity.setName(roadName); +// } else { +// @SuppressLint("SimpleDateFormat") +// DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); +// Calendar calendars = Calendar.getInstance(); +// calendars.setTimeInMillis(System.currentTimeMillis()); +// String formats = formatter.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()); +// Objects.requireNonNull(getActivity()).runOnUiThread(new Runnable() { +// @Override +// public void run() { +// etRoadName.setText(sb); +// } +// }); +// } + String desc = etDesc.getText().toString().trim(); + if (!desc.equals("")) { + poiEntity.setMemo(desc); + } + @SuppressLint("SimpleDateFormat") + 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.setChecked(false); + poiEntity.setType(3); + if (showPoiEntity.getId() != null) { + List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); + if (fileListByUUID != null) { + fmPoiVideoPic.setTag(fileListByUUID); + if (booleanExtra) { + List lineStringByFileList = AWMp4ParserHelper.getInstance().getLinePhotoByList(fileListByUUID); + if (lineStringByFileList != null) { + String lineString = Geohash.getInstance().encodeList(lineStringByFileList); + if (lineString != null) { + poiEntity.setDetail(lineString); + } + } + } else { + List lineStringByFileList = AWMp4ParserHelper.getInstance().getGpsLineByList(fileListByUUID); + if (lineStringByFileList != null) { + String lineString = Geohash.getInstance().encodeList(lineStringByFileList); + if (lineString != null) { + poiEntity.setDetail(lineString); + } + } + } + String photoStr = AWMp4ParserHelper.getInstance().getVideoFileListStr(fileListByUUID); + poiEntity.setPhoto(photoStr); + + } + } + return poiEntity; + } + + @Override + protected PoiCheckResult checkPoiEntity(PoiEntity entity) { + PoiCheckResult poiCheckResult = new PoiCheckResult(); + if (entity.getPhoto() == 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/TreasureFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java index 67be0da..81258ef 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java @@ -39,6 +39,7 @@ import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.elvishew.xlog.XLog; import com.github.lazylibrary.util.DensityUtil; import com.github.lazylibrary.util.FileUtils; import com.google.gson.Gson; @@ -1127,13 +1128,26 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen DialogSettings.style = DialogSettings.STYLE.STYLE_IOS; DialogSettings.cancelable = false; MessageDialog.show((AppCompatActivity) Objects.requireNonNull(getContext()), "提示", "你poi录像页面还有未提交完的数据,之前的成果已保存,点击确定可继续作业", "确定").setOkButton(new OnDialogButtonClickListener() { + @RequiresApi(api = Build.VERSION_CODES.N) @Override public boolean onClick(BaseDialog baseDialog, View v) { treasureBuilder.append(TimestampUtil.time()).append(",").append("未提交完的数据-点击了poi录像,"); Bundle bundle = new Bundle(); bundle.putSerializable("poiEntity", poiEntity); - PoiVideoFragment poiVideoFragment = PoiVideoFragment.newInstance(bundle); - showSlidingFragment(poiVideoFragment); + int roadVideoType = dataFile.getInt("roadVideoType", -1); + if (roadVideoType == -1) { + PoiVideoFragment poiVideoFragment = PoiVideoFragment.newInstance(bundle); + showSlidingFragment(poiVideoFragment); + } else if (roadVideoType == 1) { + TrafficHubFragment trafficHubFragment = TrafficHubFragment.newInstance(bundle); + showSlidingFragment(trafficHubFragment); + } else if (roadVideoType == 2) { + AreaHubFragment areaHubFragment = AreaHubFragment.newInstance(bundle); + showSlidingFragment(areaHubFragment); + } else if (roadVideoType == 3) { + BuildingInsideFragment buildingInsideFragment = BuildingInsideFragment.newInstance(bundle); + showSlidingFragment(buildingInsideFragment); + } initRemovePoiSharePre(); return false; } @@ -1187,6 +1201,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen //根据要保存的数据的类型,调用对应的put方法, //以键值对的形式添加新值。 edit.putString("poiEntity", null); + edit.putInt("roadVideoType", -1); //提交新值。必须执行,否则前面的操作都无效。 edit.apply(); } @@ -1335,6 +1350,11 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen if (upload.contains(5)) { itemList.add(new ShareDialog.Item(Objects.requireNonNull(getContext()), R.drawable.marker_other, "其他")); } + if (upload.contains(3)) { + itemList.add(new ShareDialog.Item(Objects.requireNonNull(getContext()), R.drawable.icon_traffic_hub, "交通枢纽")); + itemList.add(new ShareDialog.Item(Objects.requireNonNull(getContext()), R.drawable.icon_parking_hub, "区域设施")); + itemList.add(new ShareDialog.Item(Objects.requireNonNull(getContext()), R.drawable.icon_building_inside, "建筑物内部")); + } Bundle bundle = new Bundle(); PoiEntity poiEntity = new PoiEntity(); // 上报时以当前用户位置为准 @@ -1369,6 +1389,18 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen OtherFragment otherFragment = OtherFragment.newInstance(bundle); showSlidingFragment(otherFragment); treasureBuilder.append(TimestampUtil.time()).append("点击弹窗上的其他,"); + } else if (item.getText().equals("交通枢纽")) { + TrafficHubFragment trafficHubFragment = TrafficHubFragment.newInstance(bundle); + showSlidingFragment(trafficHubFragment); + XLog.d("点击弹窗上的交通枢纽"); + } else if (item.getText().equals("区域设施")) { + AreaHubFragment areaHubFragment = AreaHubFragment.newInstance(bundle); + showSlidingFragment(areaHubFragment); + XLog.d("点击弹窗上的区域设施"); + } else if (item.getText().equals("建筑物内部")) { + BuildingInsideFragment buildingInsideFragment = BuildingInsideFragment.newInstance(bundle); + showSlidingFragment(buildingInsideFragment); + XLog.d("点击弹窗上的建筑物内部"); } return false; } @@ -1413,6 +1445,24 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen fragmentTransaction.hide(poiVideoFragment); } } + if (!(fragment instanceof TrafficHubFragment)) { + TrafficHubFragment trafficHubFragment = (TrafficHubFragment) supportFragmentManager.findFragmentByTag(TrafficHubFragment.class.getName()); + if (trafficHubFragment != null) { + fragmentTransaction.hide(trafficHubFragment); + } + } + if (!(fragment instanceof AreaHubFragment)) { + AreaHubFragment areaHubFragment = (AreaHubFragment) supportFragmentManager.findFragmentByTag(AreaHubFragment.class.getName()); + if (areaHubFragment != null) { + fragmentTransaction.hide(areaHubFragment); + } + } + if (!(fragment instanceof BuildingInsideFragment)) { + BuildingInsideFragment buildingInsideFragment = (BuildingInsideFragment) supportFragmentManager.findFragmentByTag(BuildingInsideFragment.class.getName()); + if (buildingInsideFragment != null) { + fragmentTransaction.hide(buildingInsideFragment); + } + } if (!(fragment instanceof OtherFragment)) { OtherFragment otherFragment = (OtherFragment) supportFragmentManager.findFragmentByTag(OtherFragment.class.getName()); if (otherFragment != null) { diff --git a/app/src/main/java/com/navinfo/outdoor/ui/view/SpinnerUtils.java b/app/src/main/java/com/navinfo/outdoor/ui/view/SpinnerUtils.java new file mode 100644 index 0000000..9dcc236 --- /dev/null +++ b/app/src/main/java/com/navinfo/outdoor/ui/view/SpinnerUtils.java @@ -0,0 +1,36 @@ +package com.navinfo.outdoor.ui.view; + +import android.content.Context; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Spinner; + +public class SpinnerUtils { + public void initSpinner(Context mContext, Spinner spinner, AdapterView.OnItemSelectedListener selectedListener, String selectItem, String... items) { + if (spinner == null) { + return; + } + ArrayAdapter adapter = new ArrayAdapter(mContext, android.R.layout.simple_dropdown_item_1line, + android.R.id.text1, items); + spinner.setAdapter(adapter); + for (int i = 0; i < items.length; i++) { + if (items[i]!=null) { + if (items[i].equals(selectItem)) { + spinner.setSelection(i); + spinner.setTag(items[i]); + break; + } + } + if (selectItem!=null) { + // 如果是楼层选项,则被选中要素为“楼层选择” + if (items[i].startsWith("楼层选择")&&selectItem.endsWith("层")) { + spinner.setSelection(i); + spinner.setTag(selectItem); + break; + } + } + } + // 增加监听 + spinner.setOnItemSelectedListener(selectedListener); + } +} diff --git a/app/src/main/res/drawable-hdpi/icon_building_inside.png b/app/src/main/res/drawable-hdpi/icon_building_inside.png new file mode 100644 index 0000000..d002303 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/icon_building_inside.png differ diff --git a/app/src/main/res/drawable-hdpi/icon_parking_hub.png b/app/src/main/res/drawable-hdpi/icon_parking_hub.png new file mode 100644 index 0000000..c1e7ef0 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/icon_parking_hub.png differ diff --git a/app/src/main/res/drawable-hdpi/icon_traffic_hub.png b/app/src/main/res/drawable-hdpi/icon_traffic_hub.png new file mode 100644 index 0000000..fe7d515 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/icon_traffic_hub.png differ diff --git a/app/src/main/res/layout/dialog_select_floor.xml b/app/src/main/res/layout/dialog_select_floor.xml new file mode 100644 index 0000000..76f3f87 --- /dev/null +++ b/app/src/main/res/layout/dialog_select_floor.xml @@ -0,0 +1,29 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/traffic_hub_fragment.xml b/app/src/main/res/layout/traffic_hub_fragment.xml new file mode 100644 index 0000000..327b114 --- /dev/null +++ b/app/src/main/res/layout/traffic_hub_fragment.xml @@ -0,0 +1,235 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +