From dc81a6513d0e48f1e4e5afc796cd0a30e86131de Mon Sep 17 00:00:00 2001 From: wangdongsheng Date: Fri, 29 Oct 2021 18:51:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9map=E7=9A=84=E9=BB=91?= =?UTF-8?q?=E5=B1=8F=E9=97=AE=E9=A2=98=E3=80=82=E4=BB=A5=E5=8F=8A=E5=8F=8B?= =?UTF-8?q?=E7=9B=9F=E4=B8=8A=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../outdoor/activity/HomeActivity.java | 37 +-- .../outdoor/activity/PicturesActivity.java | 1 - .../outdoor/adapter/TaskExplainAdapter2.java | 16 +- .../com/navinfo/outdoor/api/Constant.java | 48 +-- .../fragment/ChargingStationFragment.java | 16 +- .../outdoor/fragment/GatheringFragment.java | 14 +- .../outdoor/fragment/HasSubmitFragment.java | 48 ++- .../outdoor/fragment/OtherFragment.java | 7 +- .../outdoor/fragment/PoiVideoFragment.java | 123 ++++--- .../outdoor/fragment/PrivilegeFragment.java | 2 + .../outdoor/fragment/RecordFragment.java | 57 ++-- .../outdoor/fragment/RoadFragment.java | 66 +++- .../outdoor/fragment/StaySubmitFragment.java | 149 +++++---- .../fragment/TaskExplainFragment2.java | 122 +++++-- .../outdoor/fragment/TreasureFragment.java | 60 ++-- .../outdoor/fragment/WithdrawFragment.java | 20 +- .../navinfo/outdoor/util/PoiSaveUtils.java | 170 ++++++---- .../com/navinfo/outdoor/util/ZipUtils.java | 308 ++++++++++++++++++ app/src/main/res/layout/treasure_fragment.xml | 18 +- 19 files changed, 893 insertions(+), 389 deletions(-) create mode 100644 app/src/main/java/com/navinfo/outdoor/util/ZipUtils.java 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 ccb5380..c8785e1 100644 --- a/app/src/main/java/com/navinfo/outdoor/activity/HomeActivity.java +++ b/app/src/main/java/com/navinfo/outdoor/activity/HomeActivity.java @@ -92,21 +92,6 @@ public class HomeActivity extends BaseActivity{ return fragments.size(); } }); - mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } - - @Override - public void onPageSelected(int position) { - if (position == 1) { - recordFragment.refreshData(); - } - } - - @Override - public void onPageScrollStateChanged(int state) { - } - }); mViewPager.setCanScroll(true); mViewPager.setNoScrollAnim(false); mTab.setupWithViewPager(mViewPager); @@ -124,7 +109,16 @@ public class HomeActivity extends BaseActivity{ obtain.what = Constant.JOB_WORD_MONITOR; obtain.obj = true; EventBus.getDefault().post(obtain); - }else if (tab.getPosition()==3){ + }else if (tab.getPosition()==1){ + Message obtain = Message.obtain(); + obtain.what = Constant.STAY_SUBMIT_ITEM; + obtain.obj = true; + EventBus.getDefault().post(obtain); + Message obtain1 = Message.obtain(); + obtain1.what = Constant.HAS_SUBMIT_ITEM; + obtain1.obj = true; + EventBus.getDefault().post(obtain1); + } else if (tab.getPosition()==3){ Message obtain = Message.obtain(); obtain.what = Constant.HOME_MINE; obtain.obj = true; @@ -133,11 +127,14 @@ public class HomeActivity extends BaseActivity{ } //点击table layout效果 @Override - public void onTabUnselected(TabLayout.Tab tab) {} - @Override - public void onTabReselected(TabLayout.Tab tab) {} - }); + public void onTabUnselected(TabLayout.Tab tab) { + } + @Override + public void onTabReselected(TabLayout.Tab tab) { + + } + }); } @Subscribe public void onEvent(Message data) { diff --git a/app/src/main/java/com/navinfo/outdoor/activity/PicturesActivity.java b/app/src/main/java/com/navinfo/outdoor/activity/PicturesActivity.java index df99a5f..ef6d7c8 100644 --- a/app/src/main/java/com/navinfo/outdoor/activity/PicturesActivity.java +++ b/app/src/main/java/com/navinfo/outdoor/activity/PicturesActivity.java @@ -399,7 +399,6 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen Intent intent = new Intent(); finalVideoPath = Objects.requireNonNull(paperFile.getParentFile()).getAbsolutePath() + "/" + videoIndex + ".webp"; intent.putExtra(Constant.INTENT_PICTURES_PATH, finalVideoPath); - intent.putExtra("type", poi_video_type); setResult(0x111, intent); this.finish(); break; diff --git a/app/src/main/java/com/navinfo/outdoor/adapter/TaskExplainAdapter2.java b/app/src/main/java/com/navinfo/outdoor/adapter/TaskExplainAdapter2.java index fcd6ba5..b9b43d4 100644 --- a/app/src/main/java/com/navinfo/outdoor/adapter/TaskExplainAdapter2.java +++ b/app/src/main/java/com/navinfo/outdoor/adapter/TaskExplainAdapter2.java @@ -17,20 +17,14 @@ import java.util.ArrayList; import java.util.List; public class TaskExplainAdapter2 extends RecyclerView.Adapter { - private List explainList2 = new ArrayList<>(); + private List explainList2 ; private Context context; - public TaskExplainAdapter2(Context context) { + public TaskExplainAdapter2(List explainList2, Context context) { + this.explainList2 = explainList2; this.context = context; } - public void setExplainList2(List explainList2) { - if (explainList2 != null) { - this.explainList2.addAll(explainList2); - notifyDataSetChanged(); - } - } - public void taskExplainClearData() { if (explainList2 != null) { explainList2.clear(); @@ -76,9 +70,9 @@ public class TaskExplainAdapter2 extends RecyclerView.Adapter() { @Override public void onSuccess(HasSubmitBean hasSubmitBean, int id) { dismissLoadingDialog(); if (hasSubmitBean.getCode() == 200) { - HasSubmitBean.BodyBean hasSubmitBeanBody = hasSubmitBean.getBody(); + hasSubmitBeanBody = hasSubmitBean.getBody(); if (hasSubmitBeanBody != null) { auditProcess.setText(hasSubmitBeanBody.getAuditingCount() + ""); auditThrough.setText(hasSubmitBeanBody.getPassCount() + ""); auditNotThrough.setText(hasSubmitBeanBody.getNotPassCount() + ""); - Log.d("TAG", "onSuccess: " + hasSubmitBean.getBody() + ""); } } else { Toast.makeText(getActivity(), hasSubmitBean.getMessage() + "", Toast.LENGTH_SHORT).show(); @@ -282,7 +293,6 @@ public class HasSubmitFragment extends BaseFragment implements View.OnClickListe @Override public void onError(Throwable e, int id) { dismissLoadingDialog(); - Log.d("TAG", "onError: " + e.getMessage()); Toast.makeText(getActivity(), "请求失败", Toast.LENGTH_SHORT).show(); } }); @@ -333,6 +343,7 @@ public class HasSubmitFragment extends BaseFragment implements View.OnClickListe roadIntent.putExtra("type", 4); startActivity(roadIntent); break; + case R.id.cl_charging: hasSubmitBuilder.append("点击了charging item跳转到charging列表 ,"); Intent chargingIntent = new Intent(getContext(), FragmentManagement.class); @@ -371,10 +382,11 @@ public class HasSubmitFragment extends BaseFragment implements View.OnClickListe @Override public void onDestroy() { + if (EventBus.getDefault().isRegistered(this))//加上判断 + EventBus.getDefault().unregister(this); super.onDestroy(); hasSubmitBuilder.append("onDestroy "); hasSubmitBuilder.append("\r\n"); FileUtils.writeFile(logFile.getAbsolutePath(), hasSubmitBuilder.toString(), true); } - } \ No newline at end of file diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java index 025d6ae..837e8a8 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java @@ -81,7 +81,6 @@ import java.util.Date; import java.util.List; import java.util.Objects; - /** * 寻宝-上报-其他的fragment */ @@ -277,11 +276,8 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis }); //数据展示 initShowPoi(); - //禁用所有操作控件 - //disables(); //长按刪除 onLongDelPic(); - } private void onLongDelPic() { @@ -385,9 +381,9 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis if (name != null && !name.equals("")) { editTaskName.setText(name); } - String geoWkt = showPoiEntity.getGeoWkt(); if (geoWkt != null) { + linearExist.setVisibility(View.VISIBLE); String geo = Geohash.getInstance().decode(geoWkt); Geometry geometry = GeometryTools.createGeometry(geo); switch (geometry.getGeometryType()) { @@ -419,7 +415,6 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis } } if (showPoiEntity.getName() != null) { - linearExist.setVisibility(View.VISIBLE); spinnerExist.setSelection(showPoiEntity.getExistence(), true); } String describe = showPoiEntity.getMemo();//任务描述 diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java index 2e29beb..3325f47 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java @@ -55,6 +55,7 @@ import com.navinfo.outdoor.util.AWMp4ParserHelper; import com.navinfo.outdoor.util.Geohash; import com.navinfo.outdoor.util.GeometryTools; import com.navinfo.outdoor.util.UploadUtils; +import com.navinfo.outdoor.util.ZipUtils; import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; @@ -91,6 +92,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick private TextView tvShort; private File logFile; private StringBuilder poiVideoBuilder; + private LatLng rearLatLng; public static PoiVideoFragment newInstance(Bundle bundle) { PoiVideoFragment fragment = new PoiVideoFragment(); @@ -201,20 +203,20 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick 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); + 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)){ + } else { + if (pictures_time.equals(newFormat)) { logFile = new File(Constant.LOG_FOLDER + "/" + pictures_time + ".txt"); - }else { + } else { logFile = new File(Constant.LOG_FOLDER + "/" + newFormat + ".txt"); } } poiVideoBuilder = new StringBuilder(); poiVideoBuilder.append("PoiVideoActivity-onCreate-initData ,"); - if (Constant.USHERED!=null){ + if (Constant.USHERED != null) { poiVideoBuilder.append("userId:").append(Constant.USHERED).append(","); } } @@ -241,6 +243,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick 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); @@ -307,6 +310,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick 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); @@ -348,23 +352,41 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick break; case R.id.tv_short://手动拍摄 poiVideoBuilder.append("点击了手动拍摄的按钮 ,"); - 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("poiEntity", showPoiEntity); - intents.putExtra(Constant.INTENT_VIDEO_OBLATION, 0); - intents.putExtra(Constant.INTENT_POI_VIDEO_TYPE, 2); - startActivityForResult(intents, 0x102); + 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 > 5000 || rearGeometry > 5000) { + Toast.makeText(getActivity(), "用户距离作业起点或者终点五公里以内才能拍摄", Toast.LENGTH_SHORT).show(); + return; + } else { + 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("poiEntity", showPoiEntity); + intents.putExtra(Constant.INTENT_VIDEO_OBLATION, 0); + intents.putExtra(Constant.INTENT_POI_VIDEO_TYPE, 2); + startActivityForResult(intents, 0x102); + } break; case R.id.tv_combo://自动连拍: poiVideoBuilder.append("点击了自动连拍的按钮 ,"); - 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("poiEntity", showPoiEntity); - intent.putExtra(Constant.INTENT_VIDEO_OBLATION, 0); - intent.putExtra(Constant.INTENT_POI_VIDEO_TYPE, 1); - startActivityForResult(intent, 0x101); + LatLng startLng = new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()); //用户当前位置 + double geom = GeometryTools.distanceToDouble(startLng, latLng); + double rearGeom = GeometryTools.distanceToDouble(startLng, rearLatLng); + if (geom > 5000 || rearGeom > 5000) { + Toast.makeText(getActivity(), "用户距离作业起点或者终点五公里以内才能拍摄", Toast.LENGTH_SHORT).show(); + return; + } else { + 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("poiEntity", showPoiEntity); + intent.putExtra(Constant.INTENT_VIDEO_OBLATION, 0); + intent.putExtra(Constant.INTENT_POI_VIDEO_TYPE, 1); + startActivityForResult(intent, 0x101); + } break; case R.id.btn_poi_video_upload: poiVideoBuilder.append("点击了上传的按钮 ,"); @@ -376,17 +398,37 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick @Override public void run() { ZipUtil.zipFiles(videoFileList, fileZip, null); + long zipTrueSize = ZipUtils.getZipTrueSize(fileZip.getAbsolutePath()); + if (zipTrueSize > 0) { + if (getActivity() != null) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + if (showPoiEntity == null) { + showPoiEntity = new PoiEntity(); + } + if (showPoiEntity.getTaskStatus() == 1 || showPoiEntity.getTaskStatus() == 2 || showPoiEntity.getTaskStatus() == 0 || showPoiEntity.getTaskStatus() == 5) { + initPoiSaveLocal(true); + } else { + poiVideoUpload(showPoiEntity.getBodyId(), fileZip); + Constant.isPresent = false; + } + } + }); + } + } else { + if (getActivity() != null) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + fileZip.delete(); + Toast.makeText(getActivity(), "压缩文件失败,请重新提交", Toast.LENGTH_SHORT).show(); + } + }); + } + } } }).start(); - if (showPoiEntity == null) { - showPoiEntity = new PoiEntity(); - } - if (showPoiEntity.getTaskStatus() == 1 || showPoiEntity.getTaskStatus() == 2 || showPoiEntity.getTaskStatus() == 0 || showPoiEntity.getTaskStatus() == 5) { - initPoiSaveLocal(true); - } else { - poiVideoUpload(showPoiEntity.getBodyId(), fileZip); - Constant.isPresent = false; - } } else { dismissLoadingDialog(); Toast.makeText(getActivity(), "请录像", Toast.LENGTH_SHORT).show(); @@ -395,7 +437,6 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick } else { Toast.makeText(getContext(), "有正在提交的数据,等提交成功后,方可操作", Toast.LENGTH_SHORT).show(); } - break; } } @@ -418,12 +459,14 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick @Override public void run() { InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); - Objects.requireNonNull(getActivity()).runOnUiThread(new Runnable() { - @Override - public void run() { - poiVideoSave(poiEntity, isLocal); - } - }); + if (getActivity() != null) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + poiVideoSave(poiEntity, isLocal); + } + }); + } } }).start(); //onBackPressed(); @@ -443,7 +486,6 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick }); } - private void poiVideoUpload(int poiVideoBody, File fileZip) { if (poiVideoBody == 0) { Toast.makeText(getActivity(), "请先保存本地在上传", Toast.LENGTH_SHORT).show(); @@ -468,7 +510,6 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick Objects.requireNonNull(getActivity()).onBackPressed();//回退 WaitDialog.show((AppCompatActivity) getActivity(), "任务正在后台上传中,请稍候..."); WaitDialog.dismiss(3000); - } private void poiVideoSave(PoiEntity poiEntity, boolean isLocal) { @@ -498,7 +539,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick @Override public void run() { InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity); - if (getActivity()!=null){ + if (getActivity() != null) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { @@ -589,7 +630,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick if (showPoiEntity.getTaskStatus() == 5) { initEndReceiveTask(HttpInterface.UNRECEIVED_POLYGON_TASK, showPoiEntity);//结束领取 } else if (showPoiEntity.getTaskStatus() == 0 || showPoiEntity.getTaskStatus() == 1) { - if (showPoiEntity.getId()!=null){ + if (showPoiEntity.getId() != null) { List fileListByUUID = AWMp4ParserHelper.getInstance().getFileListByUUID(showPoiEntity.getId()); for (int i = 0; i < fileListByUUID.size(); i++) { fileListByUUID.get(i).delete(); @@ -622,7 +663,6 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick poiVideoBuilder.append("onStop ,"); } - @Override public void onDestroy() { if (EventBus.getDefault().isRegistered(this))//加上判断 @@ -682,7 +722,6 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick public void onError(Throwable e, int id) { dismissLoadingDialog(); Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show(); - Log.d("TAG", "onError: " + e.getMessage()); } }); } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/PrivilegeFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/PrivilegeFragment.java index 8edb5c0..8bc1db8 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/PrivilegeFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/PrivilegeFragment.java @@ -19,6 +19,7 @@ public class PrivilegeFragment extends BaseFragment implements View.OnClickListe fragment.setArguments(bundle); return fragment; } + @Override protected int getLayout() { return R.layout.privilege_fragment; @@ -42,4 +43,5 @@ public class PrivilegeFragment extends BaseFragment implements View.OnClickListe Objects.requireNonNull(getActivity()).finish(); } } + } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/RecordFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/RecordFragment.java index 8661647..282180e 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/RecordFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/RecordFragment.java @@ -3,6 +3,7 @@ package com.navinfo.outdoor.fragment; import android.content.Context; import android.graphics.Color; import android.os.Bundle; +import android.os.Message; import android.view.View; import androidx.annotation.NonNull; @@ -12,9 +13,11 @@ import androidx.viewpager.widget.ViewPager; import com.google.android.material.tabs.TabLayout; import com.navinfo.outdoor.R; +import com.navinfo.outdoor.api.Constant; import com.navinfo.outdoor.base.BaseFragment; import com.navinfo.outdoor.util.NoSlideViewPager; +import org.greenrobot.eventbus.EventBus; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -24,11 +27,9 @@ import java.util.Objects; * 记录的Fragment * 2021-5-25 */ -public class RecordFragment extends BaseFragment implements View.OnClickListener { +public class RecordFragment extends BaseFragment { private final String[] names = {"待提交", "已提交"}; - private StaySubmitFragment staySubmitFragment; // 待提交 - private HasSubmitFragment hasSubmitFragment;// 已提交 public static RecordFragment newInstance(Bundle bundle) { RecordFragment fragment = new RecordFragment(); @@ -47,10 +48,10 @@ public class RecordFragment extends BaseFragment implements View.OnClickListener TabLayout tabRecord = (TabLayout) findViewById(R.id.tab_record); NoSlideViewPager vpRecord = (NoSlideViewPager) findViewById(R.id.vp_record); ArrayList fragments = new ArrayList<>(); - staySubmitFragment = new StaySubmitFragment(); - fragments.add(staySubmitFragment); - hasSubmitFragment = new HasSubmitFragment(); - fragments.add(hasSubmitFragment); + // 待提交 + fragments.add(new StaySubmitFragment()); + // 已提交 + fragments.add(new HasSubmitFragment()); assert getFragmentManager() != null; vpRecord.setAdapter(new FragmentPagerAdapter(getFragmentManager()) { @NotNull @@ -64,48 +65,32 @@ public class RecordFragment extends BaseFragment implements View.OnClickListener return fragments.size(); } }); - tabRecord.setupWithViewPager(vpRecord); Objects.requireNonNull(tabRecord.getTabAt(0)).setText(names[0]); Objects.requireNonNull(tabRecord.getTabAt(1)).setText(names[1]); tabRecord.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { - refreshData(); + if (tab.getPosition()==0){ + Message obtain = Message.obtain(); + obtain.what = Constant.STAY_SUBMIT_ITEM; + obtain.obj = true; + EventBus.getDefault().post(obtain); + }else if (tab.getPosition()==1){ + Message obtain = Message.obtain(); + obtain.what = Constant.HAS_SUBMIT_ITEM; + obtain.obj = true; + EventBus.getDefault().post(obtain); + } } @Override - public void onTabUnselected(TabLayout.Tab tab) { - - } + public void onTabUnselected(TabLayout.Tab tab) { } @Override - public void onTabReselected(TabLayout.Tab tab) { - - } + public void onTabReselected(TabLayout.Tab tab) { } }); } - @Override - protected void initData() { - super.initData(); - } - - @Override - public void onClick(View v) { - - } - - /** - * 刷新fragment内的所有数据 - * */ - public void refreshData() { - if (staySubmitFragment!=null) { - staySubmitFragment.refreshData(); - } - if (hasSubmitFragment!=null) { - hasSubmitFragment.initRequest(); - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java index 2d0f0b9..d352e4d 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java @@ -55,6 +55,7 @@ import com.navinfo.outdoor.room.PoiEntity; import com.navinfo.outdoor.util.AWMp4ParserHelper; import com.navinfo.outdoor.util.Geohash; import com.navinfo.outdoor.util.GeometryTools; +import com.navinfo.outdoor.util.ZipUtils; import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; @@ -90,6 +91,7 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList private LatLng latLng; private File logFile; private StringBuilder roadBuilder; + private LatLng rearLatLng; public static RoadFragment newInstance(Bundle bundle) { RoadFragment fragment = new RoadFragment(); @@ -237,6 +239,7 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList List latLineString = GeometryTools.getLatLags(geo); assert latLineString != null; latLng = latLineString.get(0); + rearLatLng = latLineString.get(latLineString.size() - 1); break; } BitmapDescriptor roadDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_road_show); @@ -360,13 +363,23 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList break; case R.id.tv_pictures: roadBuilder.append("点击了自动拍照的按钮 ,"); - Intent intent = new Intent(getContext(), PicturesActivity.class); - File finalFile = AWMp4ParserHelper.getInstance().obtainWebpFilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); - intent.putExtra(Constant.INTENT_JPG_PATH, finalFile.getAbsolutePath()); - intent.putExtra(Constant.INTENT_VIDEO_OBLATION, 0); - intent.putExtra(Constant.INTENT_POI_VIDEO_TYPE, 3); - intent.putExtra("poiEntity", showPoiEntity); - startActivityForResult(intent, 0x101); + 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>5000||rearGeometry>5000){ + Toast.makeText(getActivity(), "用户距离作业起点或者终点五公里以内才能拍摄", Toast.LENGTH_SHORT).show(); + return; + }else { + Intent intent = new Intent(getContext(), PicturesActivity.class); + File finalFile = AWMp4ParserHelper.getInstance().obtainWebpFilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath()); + intent.putExtra(Constant.INTENT_JPG_PATH, finalFile.getAbsolutePath()); + intent.putExtra(Constant.INTENT_VIDEO_OBLATION, 0); + intent.putExtra(Constant.INTENT_POI_VIDEO_TYPE, 3); + intent.putExtra("poiEntity", showPoiEntity); + startActivityForResult(intent, 0x101); + } break; case R.id.road_upload: roadBuilder.append("点击了上传的按钮 ,"); @@ -378,17 +391,38 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList @Override public void run() { ZipUtil.zipFiles(videoFileList, fileZip, null);//压缩 + long zipTrueSize = ZipUtils.getZipTrueSize(fileZip.getAbsolutePath()); + if (zipTrueSize>0){ + if (getActivity()!=null){ + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + if (showPoiEntity == null) { + showPoiEntity = new PoiEntity(); + } + if (showPoiEntity.getTaskStatus() == 1 || showPoiEntity.getTaskStatus() == 2 || showPoiEntity.getTaskStatus() == 0 || showPoiEntity.getTaskStatus() == 5) { + initPoiSaveLocal(true); + } else { + poiVideoUpload(showPoiEntity.getBodyId(), fileZip); + Constant.isPresent = false; + } + } + }); + } + }else { + if (getActivity()!=null){ + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + fileZip.delete(); + Toast.makeText(getActivity(), "压缩文件失败,请重新提交", Toast.LENGTH_SHORT).show(); + } + }); + } + + } } }).start(); - if (showPoiEntity == null) { - showPoiEntity = new PoiEntity(); - } - if (showPoiEntity.getTaskStatus() == 1 || showPoiEntity.getTaskStatus() == 2 || showPoiEntity.getTaskStatus() == 0 || showPoiEntity.getTaskStatus() == 5) { - initPoiSaveLocal(true); - } else { - poiVideoUpload(showPoiEntity.getBodyId(), fileZip); - Constant.isPresent = false; - } } else { dismissLoadingDialog(); Toast.makeText(getActivity(), "请录像", Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/StaySubmitFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/StaySubmitFragment.java index 7acab0a..0e2c632 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/StaySubmitFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/StaySubmitFragment.java @@ -128,8 +128,8 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList staySubmitAdapter.notifyDataSetChanged(); } }); - if (Constant.currentLocation!=null){ - if (Constant.USHERED!=null){ + if (Constant.currentLocation != null) { + if (Constant.USHERED != null) { cbSelect.setChecked(false); refreshData(); } @@ -166,18 +166,25 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList @Subscribe public void onEvent(Message data) { if (data.what == Constant.EVENT_STAY_REFRESH) { - cbSelect.setChecked(false); - if (Constant.currentLocation!=null){ - if (Constant.USHERED!=null){ - cbSelect.setChecked(false); + if (Constant.currentLocation != null) { + if (Constant.USHERED != null) { + if (cbSelect != null) { + cbSelect.setChecked(false); + } refreshData(); } - } - }else if (data.what==Constant.NEST_WORD_SUBMIT){ - if (messageDialog!=null){ + } else if (data.what == Constant.NEST_WORD_SUBMIT) { + if (messageDialog != null) { messageDialog.doDismiss(); } + }else if (data.what==Constant.STAY_SUBMIT_ITEM){ + if ((boolean)data.obj){ + if (cbSelect != null) { + cbSelect.setChecked(false); + } + refreshData(); + } } } @@ -305,52 +312,54 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList } } } - Objects.requireNonNull(getActivity()).runOnUiThread(new Runnable() { - @Override - public void run() { - StringBuilder taskIds = new StringBuilder(); - StringBuilder auditIds = new StringBuilder(); - for (int i = 0; i < poiEntities.size(); i++) { - if (poiEntities.get(i).getTaskStatus() == 2) { - taskIds.append(poiEntities.get(i).getTaskId()).append(","); - } else if (poiEntities.get(i).getTaskStatus() == 3) { - auditIds.append(poiEntities.get(i).getBodyId()).append(","); + if (getActivity() != null) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + StringBuilder taskIds = new StringBuilder(); + StringBuilder auditIds = new StringBuilder(); + for (int i = 0; i < poiEntities.size(); i++) { + if (poiEntities.get(i).getTaskStatus() == 2) { + taskIds.append(poiEntities.get(i).getTaskId()).append(","); + } else if (poiEntities.get(i).getTaskStatus() == 3) { + auditIds.append(poiEntities.get(i).getBodyId()).append(","); + } } - } - if (!taskIds.toString().equals("")) { - taskIds = new StringBuilder(taskIds.substring(0, taskIds.length() - 1)); - } - if (!auditIds.toString().equals("")) { - auditIds = new StringBuilder(auditIds.substring(0, auditIds.length() - 1)); - } - HttpParams httpParams = new HttpParams(); - httpParams.put("taskIds", taskIds.toString()); - httpParams.put("auditIds", auditIds.toString()); - OkGoBuilder.getInstance() - .Builder(getActivity()) - .url(HttpInterface.UNRECEIVED_POLYGON_TASK) - .params(httpParams) - .token(Constant.ACCESS_TOKEN) - .cls(UnPolygonTaskBean.class) - .getRequest(new Callback() { - @Override - public void onSuccess(UnPolygonTaskBean response, int id) { - dismissLoadingDialog(); - if (response.getCode() == 200) { - staySubmitAdapter.setAllCheckedDelete(); - } else { - Toast.makeText(getActivity(), response.getMessage() + "", Toast.LENGTH_SHORT).show(); + if (!taskIds.toString().equals("")) { + taskIds = new StringBuilder(taskIds.substring(0, taskIds.length() - 1)); + } + if (!auditIds.toString().equals("")) { + auditIds = new StringBuilder(auditIds.substring(0, auditIds.length() - 1)); + } + HttpParams httpParams = new HttpParams(); + httpParams.put("taskIds", taskIds.toString()); + httpParams.put("auditIds", auditIds.toString()); + OkGoBuilder.getInstance() + .Builder(getActivity()) + .url(HttpInterface.UNRECEIVED_POLYGON_TASK) + .params(httpParams) + .token(Constant.ACCESS_TOKEN) + .cls(UnPolygonTaskBean.class) + .getRequest(new Callback() { + @Override + public void onSuccess(UnPolygonTaskBean response, int id) { + dismissLoadingDialog(); + if (response.getCode() == 200) { + staySubmitAdapter.setAllCheckedDelete(); + } else { + Toast.makeText(getActivity(), response.getMessage() + "", Toast.LENGTH_SHORT).show(); + } } - } - @Override - public void onError(Throwable e, int id) { - dismissLoadingDialog(); - Toast.makeText(getActivity(), e.getMessage() + "", Toast.LENGTH_SHORT).show(); - } - }); - } - }); + @Override + public void onError(Throwable e, int id) { + dismissLoadingDialog(); + Toast.makeText(getActivity(), e.getMessage() + "", Toast.LENGTH_SHORT).show(); + } + }); + } + }); + } } }).start(); } @@ -368,29 +377,30 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList } PoiDatabase roadDatabase = PoiDatabase.getInstance(getContext()); PoiDao roadDao = roadDatabase.getPoiDao(); - if (roadDao!=null){ + if (roadDao != null) { new Thread(new Runnable() { @Override public void run() { List roadAll = roadDao.getAllPoiByRecoded(); - Objects.requireNonNull(getActivity()).runOnUiThread(new Runnable() { - @Override - public void run() { - roadEntities.clear(); - roadEntities.addAll(roadAll); -// for (int i = 0; i < roadAll.size(); i++) { -// if (roadAll.get(i).getType()!=6){ -// roadEntities.add(roadAll.get(i)); -// } -// } - Log.d("TAG", "run: " + roadEntities.toString()); - staySubmitAdapter.setAllRoad(roadEntities); - staySubmitAdapter.notifyDataSetChanged(); - } - }); + if (getActivity() != null) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + roadEntities.clear(); + roadEntities.addAll(roadAll); + Log.d("TAG", "run: " + roadEntities.toString()); + staySubmitAdapter.setAllRoad(roadEntities); + staySubmitAdapter.notifyDataSetChanged(); + /*for (int i = 0; i < roadAll.size(); i++) { + if (roadAll.get(i).getType()!=6){ + roadEntities.add(roadAll.get(i)); + } + }*/ + } + }); + } } }).start(); - } } @@ -401,7 +411,6 @@ public class StaySubmitFragment extends BaseFragment implements View.OnClickList } - @Override public void onDestroy() { if (EventBus.getDefault().isRegistered(this))//加上判断 diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/TaskExplainFragment2.java b/app/src/main/java/com/navinfo/outdoor/fragment/TaskExplainFragment2.java index 778f3a6..267d4ec 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/TaskExplainFragment2.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/TaskExplainFragment2.java @@ -1,6 +1,9 @@ package com.navinfo.outdoor.fragment; +import android.annotation.SuppressLint; +import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; import android.view.View; @@ -10,6 +13,7 @@ import android.widget.Toast; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; +import com.github.lazylibrary.util.FileUtils; import com.lzy.okgo.model.HttpParams; import com.navinfo.outdoor.R; @@ -27,8 +31,13 @@ import com.jcodecraeer.xrecyclerview.XRecyclerView; import org.json.JSONObject; +import java.io.File; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Objects; /** @@ -38,7 +47,10 @@ public class TaskExplainFragment2 extends BaseFragment implements View.OnClickLi private XRecyclerView taskExplain2Recycler; private TaskExplainAdapter2 taskExplainAdapter2; + private List explainList; private int taskExplainPage = 1; + private File logFile; + private StringBuilder taskExplain2Builder; public static TaskExplainFragment2 newInstance(Bundle bundle) { TaskExplainFragment2 fragment = new TaskExplainFragment2(); @@ -60,32 +72,31 @@ public class TaskExplainFragment2 extends BaseFragment implements View.OnClickLi ivTaskExplain2.setOnClickListener(this); taskExplain2Recycler.setLayoutManager(new LinearLayoutManager(getActivity())); //下划线 - // taskExplain2Recycler.addItemDecoration(new DividerItemDecoration(getActivity(),DividerItemDecoration.VERTICAL)); +// taskExplain2Recycler.addItemDecoration(new DividerItemDecoration(getActivity(),DividerItemDecoration.VERTICAL)); taskExplain2Recycler.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader); taskExplain2Recycler.setLoadingMoreProgressStyle(ProgressStyle.BallRotate); //取消上拉加载,刷新功能。 -// taskExplain2Recycler.setPullRefreshEnabled(false); -// taskExplain2Recycler.setLoadingMoreEnabled(false); - - taskExplainAdapter2 = new TaskExplainAdapter2(getActivity()); +// taskExplain2Recycler.setPullRefreshEnabled(false); +// taskExplain2Recycler.setLoadingMoreEnabled(false); + taskExplainAdapter2 = new TaskExplainAdapter2(explainList,getActivity()); taskExplain2Recycler.setAdapter(taskExplainAdapter2); taskExplain2Recycler.getDefaultFootView().setNoMoreHint("加载完毕"); taskExplain2Recycler.setLoadingListener(new XRecyclerView.LoadingListener() { @Override public void onRefresh() { - taskExplainAdapter2.taskExplainClearData(); taskExplainPage=1; - initNetWork2(); + initNetWork2(true); } @Override public void onLoadMore() { - initNetWork2(); + initNetWork2(false); } }); taskExplainAdapter2.setOnItemClick(new TaskExplainAdapter2.OnItemClick2() { @Override public void onClick2(int pos) { + taskExplain2Builder.append("点击了item ,"); HashMap paramMap = new HashMap<>(); paramMap.put("id",pos+""); intint2WebActivity(HttpInterface.MSG_CONTENT, paramMap); @@ -96,17 +107,39 @@ public class TaskExplainFragment2 extends BaseFragment implements View.OnClickLi @Override protected void initData() { super.initData(); - ArrayList dataBeans2 = new ArrayList<>(); - initNetWork2(); + explainList = new ArrayList<>(); + initNetWork2(true); + 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"); + } + } + taskExplain2Builder = new StringBuilder(); + taskExplain2Builder.append("TaskExplainFragment-onCreate-initData ,"); + if (Constant.USHERED != null) { + taskExplain2Builder.append("userId:").append(Constant.USHERED).append(","); + } } - private void initNetWork2() { - showLoadingDialog(); + private void initNetWork2(boolean aBoolean) { String id = Objects.requireNonNull(getActivity()).getIntent().getStringExtra("id"); HttpParams httpParams = new HttpParams(); httpParams.put("fid", id); httpParams.put("pageNum", taskExplainPage); - httpParams.put("pageSize", "20"); + httpParams.put("pageSize", 20); + showLoadingDialog(); OkGoBuilder.getInstance() .Builder(getActivity()) .url(HttpInterface.LIST_TASK) @@ -118,18 +151,15 @@ public class TaskExplainFragment2 extends BaseFragment implements View.OnClickLi public void onSuccess(TaskPrefectureBean response, int id) { dismissLoadingDialog(); if (response.getCode() == 200){ - taskExplainAdapter2.setExplainList2(response.getBody().getList()); - taskExplainPage++; + initTaskPrefectureBean(response,aBoolean); + }else { + Toast.makeText(getActivity(), response.getMessage()+"", Toast.LENGTH_SHORT).show(); } - taskExplain2Recycler.refreshComplete(); - taskExplain2Recycler.loadMoreComplete(); - Log.d("TAG", "onSuccess: " + response.getMessage() + "sassafras's"); + Log.d("TAG", "onSuccess: " + response.getMessage() + ""); } @Override public void onError(Throwable e, int id) { - taskExplain2Recycler.refreshComplete(); - taskExplain2Recycler.loadMoreComplete(); dismissLoadingDialog(); Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show(); Log.d("TAG", "onError: " + e.getMessage()); @@ -137,10 +167,62 @@ public class TaskExplainFragment2 extends BaseFragment implements View.OnClickLi }); } + private void initTaskPrefectureBean(TaskPrefectureBean taskPrefectureBean, boolean aBoolean) { + if (taskPrefectureBean.getCode() == 200) { + if (aBoolean) { + if (explainList.size() > 0) { + explainList.clear(); + } + if (taskPrefectureBean.getBody().getList()== null) { + Toast.makeText(getActivity(), "没有相关数据", Toast.LENGTH_SHORT).show(); + } else { + explainList.addAll(taskPrefectureBean.getBody().getList()); + taskExplainPage++; + } + taskExplainAdapter2.notifyDataSetChanged(); + taskExplain2Recycler.refreshComplete(); + } else { + if (taskPrefectureBean.getBody().getList() == null) { + taskExplain2Recycler.setNoMore(true); + + } else { + explainList.addAll(taskPrefectureBean.getBody().getList()); + taskExplainAdapter2.notifyDataSetChanged(); + taskExplain2Recycler.loadMoreComplete(); + taskExplainPage++; + } + } + } else { + Toast.makeText(getActivity(), taskPrefectureBean.getMessage(), Toast.LENGTH_SHORT).show(); + Log.d("TAG", "" + taskPrefectureBean.getMessage()); + } + } + @Override public void onClick(View v) { if (v.getId() == R.id.iv_task_explain2_finish) { Objects.requireNonNull(getActivity()).finish(); + taskExplain2Builder.append("点击了返回的按钮 ,"); } } + + @Override + public void onPause() { + super.onPause(); + taskExplain2Builder.append("onPause ,"); + } + + @Override + public void onStop() { + super.onStop(); + taskExplain2Builder.append("onStop ,"); + } + + @Override + public void onDestroy() { + super.onDestroy(); + taskExplain2Builder.append("onDestroy"); + taskExplain2Builder.append("\r\n"); + FileUtils.writeFile(logFile.getAbsolutePath(), taskExplain2Builder.toString(), true); + } } \ 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 6edfadd..49c7a23 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java @@ -79,6 +79,7 @@ import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory; import com.tencent.tencentmap.mapsdk.maps.MapView; import com.tencent.tencentmap.mapsdk.maps.Projection; import com.tencent.tencentmap.mapsdk.maps.TencentMap; +import com.tencent.tencentmap.mapsdk.maps.TextureMapView; import com.tencent.tencentmap.mapsdk.maps.UiSettings; import com.tencent.tencentmap.mapsdk.maps.interfaces.Removable; import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor; @@ -116,7 +117,7 @@ import java.util.Objects; * 2021-5-25 */ public class TreasureFragment extends BaseFragment implements View.OnClickListener { - private MapView treasureMap; + private TextureMapView mapView; private TencentMap tencentMap; private CheckBox cbMapType; private ImageView ivZoomAdd; @@ -298,8 +299,12 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen ivSubmit.setOnClickListener(this); ivMessage = findViewById(R.id.iv_message); ivMessage.setOnClickListener(this); - treasureMap = (MapView) findViewById(R.id.treasure_map); - tencentMap = treasureMap.getMap(); + mapView = findViewById(R.id.treasure_map); + tencentMap = mapView.getMap(); + // 设置地图宽高为屏幕的宽高 + int[] widthHeight = DensityUtil.getDeviceInfo(getActivity()); + mapView.getLayoutParams().width = widthHeight[0]; + mapView.getLayoutParams().height = widthHeight[1]; ivMassNotification = findViewById(R.id.iv_mas_notification);//定时消息小红点 MapManager.getInstance().init(getActivity(), tencentMap); cbMapType = (CheckBox) findViewById(R.id.cb_map_type); @@ -387,10 +392,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen tencentMap.setOnMarkerClickListener(Constant.markerClickListener); } }); - // 设置地图宽高为屏幕的宽高 - int[] widthHeight = DensityUtil.getDeviceInfo(getActivity()); - treasureMap.getLayoutParams().width = widthHeight[0]; - treasureMap.getLayoutParams().height = widthHeight[1]; + } /* //监听回传 @@ -411,15 +413,18 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen Toast.makeText(getActivity(), "没有确定经纬度", Toast.LENGTH_SHORT).show(); return; } + HttpParams httpParams = new HttpParams(); + httpParams.put("geo", encode); OkGoBuilder.getInstance() .Builder(getActivity()) .url(HttpInterface.GET_PHONES) - .params(new HttpParams("geo", encode)) + .params(httpParams) .cls(GetPhoneBean.class) .token(Constant.ACCESS_TOKEN) .getRequest(new Callback() { @Override public void onSuccess(GetPhoneBean getPhoneBean, int id) { + dismissLoadingDialog(); if (getPhoneBean.getCode() == 200) { String code = getPhoneBean.getBody().getCode(); Integer telLength = getPhoneBean.getBody().getTelLength(); @@ -430,6 +435,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen @Override public void onError(Throwable e, int id) { + dismissLoadingDialog(); Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show(); } }); @@ -1044,7 +1050,6 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen otherDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.grayother); } assert latLng != null; - Marker otherMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(otherDescriptor) .anchor(0.5f, 1f) .flat(true) @@ -1105,7 +1110,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen MessageDialog.show((AppCompatActivity) Objects.requireNonNull(getContext()), "提示", "你poi页面还有未提交完的数据,之前的成果已保存,点击确定可继续作业", "确定").setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(BaseDialog baseDialog, View v) { - treasureBuilder.append("initSharePre-点击了poi,"); + treasureBuilder.append("initSharePre-点击了poi,"); Bundle bundle = new Bundle(); bundle.putSerializable("poiEntity", poiEntity); PoiFragment poiFragment = PoiFragment.newInstance(bundle); @@ -1121,7 +1126,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen MessageDialog.show((AppCompatActivity) Objects.requireNonNull(getContext()), "提示", "你充电站页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(BaseDialog baseDialog, View v) { - treasureBuilder.append("initSharePre-点击了充电站,"); + treasureBuilder.append("initSharePre-点击了充电站,"); Bundle bundle = new Bundle(); bundle.putSerializable("poiEntity", poiEntity); ChargingStationFragment chargingStationFragment = ChargingStationFragment.newInstance(bundle); @@ -1137,7 +1142,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen MessageDialog.show((AppCompatActivity) Objects.requireNonNull(getContext()), "提示", "你poi录像页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(BaseDialog baseDialog, View v) { - treasureBuilder.append("initSharePre-点击了poi录像,"); + treasureBuilder.append("initSharePre-点击了poi录像,"); Bundle bundle = new Bundle(); bundle.putSerializable("poiEntity", poiEntity); PoiVideoFragment poiVideoFragment = PoiVideoFragment.newInstance(bundle); @@ -1153,7 +1158,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen MessageDialog.show((AppCompatActivity) Objects.requireNonNull(getContext()), "提示", "你道路页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(BaseDialog baseDialog, View v) { - treasureBuilder.append("initSharePre-点击了道路,"); + treasureBuilder.append("initSharePre-点击了道路,"); Bundle bundle = new Bundle(); bundle.putSerializable("poiEntity", poiEntity); RoadFragment roadFragment = RoadFragment.newInstance(bundle); @@ -1169,7 +1174,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen MessageDialog.show((AppCompatActivity) Objects.requireNonNull(getContext()), "提示", "你其他页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(BaseDialog baseDialog, View v) { - treasureBuilder.append("initSharePre-点击了其他,"); + treasureBuilder.append("initSharePre-点击了其他,"); Bundle bundle = new Bundle(); bundle.putSerializable("poiEntity", poiEntity); OtherFragment otherFragment = OtherFragment.newInstance(bundle); @@ -1178,7 +1183,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen return false; } }); - break; + break; } } } @@ -1453,40 +1458,41 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen if (!EventBus.getDefault().isRegistered(this)) {//加上判断 EventBus.getDefault().register(this); } - treasureMap.onStart(); + mapView.onStart(); } @Override public void onResume() { super.onResume(); - treasureMap.onResume(); + mapView.onResume(); } @Override public void onPause() { super.onPause(); - treasureMap.onPause(); + mapView.onPause(); treasureBuilder.append("onPause,"); } @Override public void onStop() { super.onStop(); - treasureMap.onStop(); + mapView.onStop(); treasureBuilder.append("onStop,"); } @Override public void onDestroy() { - treasureBuilder.append("onDestroy"); - treasureBuilder.append("\r\n"); - FileUtils.writeFile(logFile.getAbsolutePath(), treasureBuilder.toString(), true); if (EventBus.getDefault().isRegistered(this)) { EventBus.getDefault().unregister(this); } super.onDestroy(); - treasureMap.onDestroy(); + mapView.onDestroy(); + treasureBuilder.append("onDestroy"); + treasureBuilder.append("\r\n"); + FileUtils.writeFile(logFile.getAbsolutePath(), treasureBuilder.toString(), true); + if (bigMarker != null) { bigMarker.remove(); } @@ -2035,12 +2041,12 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen @Override public void onConfigurationChanged(@NonNull Configuration newConfig) { super.onConfigurationChanged(newConfig); - int measuredWidth = treasureMap.getWidth(); - int measuredHeight = treasureMap.getHeight(); + int measuredWidth = mapView.getWidth(); + int measuredHeight = mapView.getHeight(); if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { - treasureMap.onSizeChanged(measuredHeight, measuredWidth, measuredWidth, measuredHeight); + mapView.onSizeChanged(measuredHeight, measuredWidth, measuredWidth, measuredHeight); } else if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { - treasureMap.onSizeChanged(measuredHeight, measuredWidth, measuredWidth, measuredHeight); + mapView.onSizeChanged(measuredHeight, measuredWidth, measuredWidth, measuredHeight); } } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/WithdrawFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/WithdrawFragment.java index 5ade69a..3b2e716 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/WithdrawFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/WithdrawFragment.java @@ -61,6 +61,10 @@ public class WithdrawFragment extends BaseFragment implements View.OnClickListen private CheckBox checkBox; private File logFile; private StringBuilder withdrawBuilder; + private TextView tvAll; + private ImageView ivWithDraw; + private TextView tvText; + private Button btWithdraw; public static WithdrawFragment newInstance(Bundle bundle) { WithdrawFragment fragment = new WithdrawFragment(); @@ -106,12 +110,12 @@ public class WithdrawFragment extends BaseFragment implements View.OnClickListen tvUnit = findViewById(R.id.tv_unit);//可提现 tvAlready = findViewById(R.id.tv_already);//已提现 tvTotal = findViewById(R.id.tv_total);//总资产 - TextView tvAll = findViewById(R.id.tv_all); + tvAll = findViewById(R.id.tv_all); tvAll.setOnClickListener(this); etAllPrice = findViewById(R.id.et_allPrice); - ImageView ivWithDraw = findViewById(R.id.iv_withdraw); + ivWithDraw = findViewById(R.id.iv_withdraw); ivWithDraw.setOnClickListener(this); - TextView tvText = findViewById(R.id.tv_text); + tvText = findViewById(R.id.tv_text); tvText.setOnClickListener(this); checkBox = findViewById(R.id.checkBox); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @@ -129,7 +133,7 @@ public class WithdrawFragment extends BaseFragment implements View.OnClickListen } } }); - Button btWithdraw = findViewById(R.id.button); + btWithdraw = findViewById(R.id.button); btWithdraw.setOnClickListener(this); poiPushMoney = findViewById(R.id.poi_push_money); poiReportMoney = findViewById(R.id.poi_report_money); @@ -150,18 +154,16 @@ public class WithdrawFragment extends BaseFragment implements View.OnClickListen .Builder(getActivity()) .url(HttpInterface.GET_PRICE) .cls(GetPriceBean.class) - .token(Constant.ACCESS_TOKEN) .params(new HttpParams()) + .token(Constant.ACCESS_TOKEN) .getRequest(new Callback() { @Override public void onSuccess(GetPriceBean response, int id) { dismissLoadingDialog(); if (response.getCode() == 200) { GetPriceBean.BodyBean body = response.getBody(); - Double userPrice = body.getUserPrice(); - tvTotal.setText(userPrice + ""); - canExchangePrice = body.getCanExchangePrice(); - tvUnit.setText(canExchangePrice + ""); + tvTotal.setText(body.getUserPrice() + ""); + tvUnit.setText( body.getCanExchangePrice() + ""); tvAlready.setText(body.getHaveExchangePrice()+""); poiPushMoney.setText(body.getPoiPushPrice()+"元"); poiReportMoney.setText(body.getPoiNonepushPrice()+"元"); diff --git a/app/src/main/java/com/navinfo/outdoor/util/PoiSaveUtils.java b/app/src/main/java/com/navinfo/outdoor/util/PoiSaveUtils.java index 27ae598..abfef2d 100644 --- a/app/src/main/java/com/navinfo/outdoor/util/PoiSaveUtils.java +++ b/app/src/main/java/com/navinfo/outdoor/util/PoiSaveUtils.java @@ -266,74 +266,52 @@ public class PoiSaveUtils { } } } - if (poiEntity.getType()==3||poiEntity.getType()==4){ + //1 "POI"2 "充电站"3 "POI录像"4 "道路录像"5 "其他"6 "面状任务" + if (poiEntity.getType() == 1) { + initList(HttpInterface.POI_TASK_UPLOAD_PIC,photoFile,poiEntity); + } else if (poiEntity.getType() == 2) { + initList(HttpInterface.C_TASK_UP_LOAD_PIC,photoFile,poiEntity); + } else if (poiEntity.getType() == 3) { List videoFileList = AWMp4ParserHelper.getInstance().getFileListByUUID(poiEntity.getId()); if (videoFileList != null && !videoFileList.isEmpty()) { File fileZip = new File(Constant.PICTURE_FOLDER, "files" + ".zip"); ZipUtil.zipFiles(videoFileList, fileZip, null); photoFile.add(fileZip); } - } - String url = null; - //1 "POI"2 "充电站"3 "POI录像"4 "道路录像"5 "其他"6 "面状任务" - if (poiEntity.getType() == 1) { - url = HttpInterface.POI_TASK_UPLOAD_PIC; - } else if (poiEntity.getType() == 2) { - url = HttpInterface.C_TASK_UP_LOAD_PIC; - } else if (poiEntity.getType() == 3) { - url = HttpInterface.POI_VIDEO_UPLOAD_PIC; - } else if (poiEntity.getType() == 4) { - url = HttpInterface.ROAD_TASK_UPLOAD_PIC; - } else if (poiEntity.getType() == 5) { - url = HttpInterface.OTHER_TASK_UPLOAD_PIC; - } - try { - HttpParams httpParams = new HttpParams(); - httpParams.put("auditId", bodyId); - Response execute = OkGoBuilder.getInstance() - .Builder(mContext) - .url(url) - .params(httpParams) - .token(Constant.ACCESS_TOKEN) - .fileList(photoFile).postFileSynchronization(); - if (execute == null) { - return; - } - if (execute.code() != 200) { - return; - } - assert execute.body() != null; - String bodyStr = execute.body().string(); - if (bodyStr == null) { - return; - } - Gson gson = new Gson(); - OtherUploadPicBean otherUploadPicBean = gson.fromJson(bodyStr, OtherUploadPicBean.class); - if (otherUploadPicBean.getCode() == 200) { - PoiDatabase.getInstance(mContext).getPoiDao().deletePoiEntity(poiEntity); - for (int i = 0; i < photoFile.size(); i++) { - photoFile.get(i).delete(); - } - if (poiEntity.getType()==3||poiEntity.getType()==4) { - 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(); + if (photoFile.size()>0){ + long zipTrueSize = ZipUtils.getZipTrueSize(photoFile.get(0).getAbsolutePath()); + if (zipTrueSize>0){ + initList(HttpInterface.POI_VIDEO_UPLOAD_PIC,photoFile,poiEntity); + }else { + for (int i = 0; i < photoFile.size(); i++) { + photoFile.get(i).delete(); } + bInt++; + return; } - Log.d("TAGss", "uploadPoiNet: 成功" + anInt); - anInt++; - return; - } else { - Log.d("TAGss", "uploadPoiNet: 失败" + bInt); - bInt++; - return; + } - } catch (IOException e) { - e.printStackTrace(); + } else if (poiEntity.getType() == 4) { + List videoFileList = AWMp4ParserHelper.getInstance().getFileListByUUID(poiEntity.getId()); + if (videoFileList != null && !videoFileList.isEmpty()) { + File fileZip = new File(Constant.PICTURE_FOLDER, "files" + ".zip"); + ZipUtil.zipFiles(videoFileList, fileZip, null); + photoFile.add(fileZip); + } + if (photoFile.size()>0){ + long zipTrueSize = ZipUtils.getZipTrueSize(photoFile.get(0).getAbsolutePath()); + if (zipTrueSize>0){ + initList(HttpInterface.ROAD_TASK_UPLOAD_PIC,photoFile,poiEntity); + }else { + for (int i = 0; i < photoFile.size(); i++) { + photoFile.get(i).delete(); + } + bInt++; + return; + } + } + } else if (poiEntity.getType() == 5) { + initList(HttpInterface.OTHER_TASK_UPLOAD_PIC,photoFile,poiEntity); } /* OkGo // 请求方式和请求url @@ -358,6 +336,58 @@ public class PoiSaveUtils { });*/ } + private void initList(String url,List list,PoiEntity poiEntity) { + try { + HttpParams httpParams = new HttpParams(); + httpParams.put("auditId", poiEntity.getBodyId()); + Response execute = OkGoBuilder.getInstance() + .Builder(mContext) + .url(url) + .params(httpParams) + .token(Constant.ACCESS_TOKEN) + .fileList(list) + .postFileSynchronization(); + if (execute == null) { + return; + } + if (execute.code() != 200) { + return; + } + assert execute.body() != null; + String bodyStr = execute.body().string(); + if (bodyStr == null) { + return; + } + Gson gson = new Gson(); + OtherUploadPicBean otherUploadPicBean = gson.fromJson(bodyStr, OtherUploadPicBean.class); + if (otherUploadPicBean.getCode() == 200) { + PoiDatabase.getInstance(mContext).getPoiDao().deletePoiEntity(poiEntity); + for (int i = 0; i < list.size(); i++) { + list.get(i).delete(); + } + if (poiEntity.getType()==3||poiEntity.getType()==4) { + 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(); + } + } + Log.d("TAGss", "uploadPoiNet: 成功" + anInt); + anInt++; + return; + } else { + Log.d("TAGss", "uploadPoiNet: 失败" + bInt); + bInt++; + return; + } + } catch (IOException e) { + e.printStackTrace(); + } + } + /** * 根据充电站数据检查充电桩数据,如果没有网络保存,则批量网络保存 */ @@ -366,21 +396,19 @@ public class PoiSaveUtils { if (chargingStationPoiEntity != null) { List chargingPileEntityList = PoiDatabase.getInstance(mContext).getChargingPileDao().getChargingPileByStationId(chargingStationPoiEntity.getId()); PoiEntity poiEntity = PoiDatabase.getInstance(mContext).getPoiDao().getPoiEntity(chargingStationPoiEntity.getId()); - if (poiEntity!=null){ - if (chargingPileEntityList != null && !chargingPileEntityList.isEmpty()) { - // 依次上传充电桩数据,如果有一条数据未上传成功,则返回false - for (ChargingPileEntity pileEntity : chargingPileEntityList) { - if (pileEntity.getBodyId() == 0) { - int saveResult = saveChargingPile2NetWork(pileEntity, poiEntity.getBodyId()); - if (saveResult == 200) { - result = result & true; - } else { - result = result & false; - } + + if (chargingPileEntityList != null && !chargingPileEntityList.isEmpty()) { + // 依次上传充电桩数据,如果有一条数据未上传成功,则返回false + for (ChargingPileEntity pileEntity : chargingPileEntityList) { + if (pileEntity.getBodyId() == 0) { + int saveResult = saveChargingPile2NetWork(pileEntity, poiEntity.getBodyId()); + if (saveResult == 200) { + result = result & true; + } else { + result = result & false; } } } - } } Log.d("TAGss", "saveChargingPileByChargingStation" + result); diff --git a/app/src/main/java/com/navinfo/outdoor/util/ZipUtils.java b/app/src/main/java/com/navinfo/outdoor/util/ZipUtils.java new file mode 100644 index 0000000..cf881b5 --- /dev/null +++ b/app/src/main/java/com/navinfo/outdoor/util/ZipUtils.java @@ -0,0 +1,308 @@ +package com.navinfo.outdoor.util; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import java.util.zip.ZipOutputStream; + +/** + * Java utils 实现的Zip工具 + * + * @author once + */ +public class ZipUtils{ + private static final int BUFF_SIZE = 1024 * 1024; // 1M Byte + private static boolean stopZipFlag; + + /** + * 批量压缩文件(夹) + * + * @param resFileList 要压缩的文件(夹)列表 + * @param zipFile 生成的压缩文件 + */ + public static void zipFiles(Collection resFileList, File zipFile) { + + ZipOutputStream zipout = null; + try { + zipout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream( + zipFile), BUFF_SIZE)); + for (File resFile : resFileList) { + if(stopZipFlag){ + break; + } + zipFile(resFile, zipout, ""); + } + zipout.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 批量压缩文件(夹) + * + * @param resFileList 要压缩的文件(夹)列表 + * @param zipFile 生成的压缩文件 + * @param comment 压缩文件的注释 + * @param zipListener zipListener + */ + public static void zipFiles(Collection resFileList, File zipFile, String comment, com.github.lazylibrary.util.ZipUtil.ZipListener zipListener) + { + ZipOutputStream zipout = null; + try { + zipout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile), BUFF_SIZE)); + for (File resFile : resFileList) { + zipFile(resFile, zipout, ""); + } + zipout.setComment(comment); + zipout.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 解压缩一个文件 + * + * @param zipFile 压缩文件 + * @param folderPath 解压缩的目标目录 + */ + public static void upZipFile(File zipFile, String folderPath) { + File desDir = new File(folderPath); + if (!desDir.exists()) { + desDir.mkdirs(); + } + ZipFile zf = null; + try { + zf = new ZipFile(zipFile); + for (Enumeration entries = zf.entries(); entries.hasMoreElements();) { + ZipEntry entry = ((ZipEntry)entries.nextElement()); + InputStream in = zf.getInputStream(entry); + String str = folderPath + File.separator + entry.getName(); + str = new String(str.getBytes("8859_1"), "GB2312"); + File desFile = new File(str); + if (!desFile.exists()) { + File fileParentDir = desFile.getParentFile(); + if (!fileParentDir.exists()) { + fileParentDir.mkdirs(); + } + desFile.createNewFile(); + } + OutputStream out = new FileOutputStream(desFile); + byte buffer[] = new byte[BUFF_SIZE]; + int realLength; + while ((realLength = in.read(buffer)) > 0) { + out.write(buffer, 0, realLength); + } + in.close(); + out.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + + /** + * 解压文件名包含传入文字的文件 + * + * @param zipFile 压缩文件 + * @param folderPath 目标文件夹 + * @param nameContains 传入的文件匹配名 + * @return 返回的集合 + */ + public static ArrayList upZipSelectedFile(File zipFile, String folderPath, + String nameContains) { + + ArrayList fileList = new ArrayList(); + + File desDir = new File(folderPath); + if (!desDir.exists()) { + desDir.mkdir(); + } + + ZipFile zf = null; + try { + zf = new ZipFile(zipFile); + for (Enumeration entries = zf.entries(); entries.hasMoreElements();) { + ZipEntry entry = ((ZipEntry)entries.nextElement()); + if (entry.getName().contains(nameContains)) { + InputStream in = zf.getInputStream(entry); + String str = folderPath + File.separator + entry.getName(); + str = new String(str.getBytes("8859_1"), "GB2312"); + // str.getBytes("GB2312"),"8859_1" 输出 + // str.getBytes("8859_1"),"GB2312" 输入 + File desFile = new File(str); + if (!desFile.exists()) { + File fileParentDir = desFile.getParentFile(); + if (!fileParentDir.exists()) { + fileParentDir.mkdirs(); + } + desFile.createNewFile(); + } + OutputStream out = new FileOutputStream(desFile); + byte buffer[] = new byte[BUFF_SIZE]; + int realLength; + while ((realLength = in.read(buffer)) > 0) { + out.write(buffer, 0, realLength); + } + in.close(); + out.close(); + fileList.add(desFile); + } + } + return fileList; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * 获得压缩文件内文件列表 + * + * @param zipFile 压缩文件 + * @return 压缩文件内文件名称 + */ + public static ArrayList getEntriesNames(File zipFile) { + + ArrayList entryNames = new ArrayList(); + Enumeration entries = null; + try { + entries = getEntriesEnumeration(zipFile); + while (entries.hasMoreElements()) { + ZipEntry entry = ((ZipEntry)entries.nextElement()); + entryNames.add(new String(getEntryName(entry).getBytes("GB2312"), "8859_1")); + } + return entryNames; + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 获得压缩文件内压缩文件对象以取得其属性 + * + * @param zipFile 压缩文件 + * @return 返回一个压缩文件列表 + */ + public static Enumeration getEntriesEnumeration(File zipFile) { + ZipFile zf = null; + try { + zf = new ZipFile(zipFile); + } catch (IOException e) { + e.printStackTrace(); + } + return zf.entries(); + + } + + /** + * 取得压缩文件对象的注释 + * + * @param entry 压缩文件对象 + * @return 压缩文件对象的注释 + */ + public static String getEntryComment(ZipEntry entry) { + try { + return new String(entry.getComment().getBytes("GB2312"), "8859_1"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 取得压缩文件对象的名称 + * + * @param entry 压缩文件对象 + * @return 压缩文件对象的名称 + */ + public static String getEntryName(ZipEntry entry) { + try { + return new String(entry.getName().getBytes("GB2312"), "8859_1"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 压缩文件 + * + * @param resFile 需要压缩的文件(夹) + * @param zipout 压缩的目的文件 + * @param rootpath 压缩的文件路径 + */ + private static void zipFile(File resFile, ZipOutputStream zipout, String rootpath) { + try { + rootpath = rootpath + (rootpath.trim().length() == 0 ? "" : File.separator) + + resFile.getName(); + rootpath = new String(rootpath.getBytes("8859_1"), "GB2312"); + if (resFile.isDirectory()) { + File[] fileList = resFile.listFiles(); + int length=fileList.length; + // Log.e("zipprogress", (int)((1 / (float) (length+1))*100)+"%"); + //zipListener.zipProgress((int)((1 / (float) (length+1))*100)); + for (int i=0;i en = f.entries(); + while (en.hasMoreElements()) { + size += en.nextElement().getSize(); + } + } catch (IOException e) { + e.printStackTrace(); + } + return size; + } + + public interface ZipListener{ + void zipProgress(int zipProgress); + } +} diff --git a/app/src/main/res/layout/treasure_fragment.xml b/app/src/main/res/layout/treasure_fragment.xml index bdc37bd..86cbc10 100644 --- a/app/src/main/res/layout/treasure_fragment.xml +++ b/app/src/main/res/layout/treasure_fragment.xml @@ -14,23 +14,23 @@ - + android:gravity="center"> + - - + app:layout_constraintTop_toTopOf="parent"> + + android:layout_height="wrap_content"> +