diff --git a/app/build.gradle b/app/build.gradle index e1e1655..ddad9ff 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 29 buildToolsVersion '29.0.2' - ndkVersion '23.0.7123448' + // ndkVersion '23.0.7123448' defaultConfig { applicationId "com.navinfo.outdoor" diff --git a/app/src/main/java/com/navinfo/outdoor/api/Constant.java b/app/src/main/java/com/navinfo/outdoor/api/Constant.java index 197c939..017d11a 100644 --- a/app/src/main/java/com/navinfo/outdoor/api/Constant.java +++ b/app/src/main/java/com/navinfo/outdoor/api/Constant.java @@ -55,6 +55,7 @@ public class Constant { public static final int CHARGING_PILE_STATION = 22;//将充电桩的数据回传给充电站 public static final int MAIN_OTHER = 23;//其他的Fragment 对地图页面marker 的一个展示 public static final int OTHER_WORD = 25;//地图页面marker 的经纬都回传 + public static final int CHARGING_STATION_PILE = 26;//跳转到充电桩 传给数据 /** * 用户当前位置 */ 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 a885235..bae090a 100644 --- a/app/src/main/java/com/navinfo/outdoor/base/BaseDrawerFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/base/BaseDrawerFragment.java @@ -1,5 +1,6 @@ package com.navinfo.outdoor.base; +import android.content.SharedPreferences; import android.os.Bundle; import android.os.Message; import android.util.Log; @@ -68,7 +69,24 @@ public abstract class BaseDrawerFragment extends BaseFragment { mainButtonVisiableMsg.obj= View.VISIBLE; EventBus.getDefault().post(mainButtonVisiableMsg); } + initRemovePoiSharePre(); } + public void initRemovePoiSharePre() { + //获取SharedPreferences对象,方法中两个参数的意思为:第一个name + //表示文件名,系统将会在/dada/dada/包名/shared_prefs目录下生成 + //一个以该参数命名的.xml文件。第二个mode表示创建的模式,通过查看 + //方法注释得知,建议以0或者MODE_PRIVATE为默认值。 + SharedPreferences poi = getActivity().getSharedPreferences("dataFile", 0); + //获取Editor对象 + SharedPreferences.Editor edit = poi.edit(); + //根据要保存的数据的类型,调用对应的put方法, + //以键值对的形式添加新值。 + edit.putString("poiEntity", null); + edit.putString("chargingPileEntity", null); + //提交新值。必须执行,否则前面的操作都无效。 + edit.commit(); + } + public View getScrollerView() { return findViewById(R.id.scroller_view); diff --git a/app/src/main/java/com/navinfo/outdoor/bean/Info.java b/app/src/main/java/com/navinfo/outdoor/bean/Info.java index 2d7a011..bf25fab 100644 --- a/app/src/main/java/com/navinfo/outdoor/bean/Info.java +++ b/app/src/main/java/com/navinfo/outdoor/bean/Info.java @@ -13,6 +13,10 @@ public class Info { private String y; private String t; + public Info(String photo) { + this.photo = photo; + } + public String getPhoto() { return photo; } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/ChargingPileFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/ChargingPileFragment.java index 795cc68..68c750f 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/ChargingPileFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/ChargingPileFragment.java @@ -1,6 +1,7 @@ package com.navinfo.outdoor.fragment; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.Color; import android.os.Bundle; @@ -23,12 +24,15 @@ 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.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.bumptech.glide.Glide; +import com.google.gson.Gson; import com.hjq.permissions.OnPermissionCallback; import com.hjq.permissions.Permission; import com.hjq.permissions.XXPermissions; @@ -159,7 +163,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC checkButton1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked){ + if (isChecked) { Toast.makeText(getContext(), "1", Toast.LENGTH_SHORT).show(); checkButton2.setChecked(false); checkButton3.setChecked(false); @@ -173,7 +177,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC checkButton2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked){ + if (isChecked) { Toast.makeText(getContext(), "2", Toast.LENGTH_SHORT).show(); } } @@ -182,7 +186,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC checkButton3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked){ + if (isChecked) { Toast.makeText(getContext(), "3", Toast.LENGTH_SHORT).show(); } } @@ -191,7 +195,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC checkButton4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked){ + if (isChecked) { Toast.makeText(getContext(), "4", Toast.LENGTH_SHORT).show(); } } @@ -200,7 +204,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC checkButton5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked){ + if (isChecked) { Toast.makeText(getContext(), "5", Toast.LENGTH_SHORT).show(); } } @@ -209,7 +213,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC checkButton6.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked){ + if (isChecked) { Toast.makeText(getContext(), "6", Toast.LENGTH_SHORT).show(); } } @@ -357,11 +361,91 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC editDescribe = findViewById(R.id.edit_describe); btnSaveLocal = findViewById(R.id.btn_save_local); btnSaveLocal.setOnClickListener(this::onClick); - pid = getArguments().getInt("pid",0); + //展示数据 + initShowPileSharePre(); } + private void initShowPileSharePre() { + // 添加信息: + pid = getArguments().getInt("pid", 0); + ChargingPileEntity chargingPileEntity = (ChargingPileEntity) getArguments().getSerializable("chargingPileEntity"); + if (chargingPileEntity != null) { + String name = chargingPileEntity.getName();//名称 + if (name != null || !name.equals("")) { + editNameContent.setText(name + ""); + } + String p = chargingPileEntity.getP(); + if (p != null || !p.equals("")) { + inode = p; + } + String memo = chargingPileEntity.getMemo(); + if (memo != null || !memo.equals("")) { + editDescribe.setText(memo); + } + int fid = chargingPileEntity.getFid(); + if (fid != 0) { + pid = fid; + } + int sign_exist = chargingPileEntity.getSign_exist(); + spinnerScutcheon.setSelection(sign_exist, true); + int cp_availableState = chargingPileEntity.getCp_availableState(); + spinnerStake.setSelection(cp_availableState, true); + int cp_floor = chargingPileEntity.getCp_floor(); + spinnerType.setSelection(cp_floor, true); + if (chargingPileEntity.getPhotos() != null) { + photoBean.clear(); + for (int i = 0; i < chargingPileEntity.getPhotos().size(); i++) { + String photo = chargingPileEntity.getPhotos().get(i); + String[] split = photo.split("/"); + char charAt = split[6].charAt(0); + if (charAt == 'a') { + Glide.with(getActivity()).load(photo).into(ivPanorama); + photoBean.add(photo); + } else if (charAt == 'b') { + Glide.with(getActivity()).load(photo).into(ivCoding); + photoBean.add(photo); + } else if (charAt == 'c') { + char charAtc = split[6].charAt(1); + if (charAtc == '1') { + Glide.with(getActivity()).load(photo).into(ivEquipment); + photoBean.add(photo); + } else if (charAtc == '2') { + Glide.with(getActivity()).load(photo).into(ivFacility); + photoBean.add(photo); + } else if (charAtc == '3') { + Glide.with(getActivity()).load(photo).into(ivScutcheon); + photoBean.add(photo); + } else if (charAtc == '4') { + Glide.with(getActivity()).load(photo).into(ivDevice); + photoBean.add(photo); + } + } else if (charAt == 'd') { + char charAtd = split[6].charAt(1); + if (charAtd == '1') { + Glide.with(getActivity()).load(photo).into(ivUsable); + photoBean.add(photo); + } else if (charAtd == '2') { + Glide.with(getActivity()).load(photo).into(ivAvailable); + photoBean.add(photo); + } + } else if (charAt == 'e') { + char charAte =split[6].charAt(1); + if (charAte == '1') { + Glide.with(getActivity()).load(photo).into(ivParking); + photoBean.add(photo); + } else if (charAte == '2') { + Glide.with(getActivity()).load(photo).into(ivNumber); + photoBean.add(photo); + } + } + } + } + } + } + + //禁用所有可操作性控件 private void disables() { checkBoxLife.setEnabled(false); @@ -433,7 +517,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC } if (pid == 0) { Toast.makeText(getActivity(), "没有关联充电站", Toast.LENGTH_SHORT).show(); - }else { + } else { chargingPileEntity.setFid(pid); } new Thread(new Runnable() { @@ -446,11 +530,6 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC obtain.what = Constant.CHARGING_PILE_STATION; obtain.obj = chargingPileEntity; EventBus.getDefault().post(obtain); - - Message obtains = Message.obtain(); - obtains.what = Constant.TREASURE_FRAGMENT; - obtains.obj = false; - EventBus.getDefault().post(obtains); onBackPressed(); } else { Toast.makeText(getActivity(), "没有申请权限,请手动申请", Toast.LENGTH_SHORT).show(); @@ -470,14 +549,17 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC case R.id.rl_panorama: Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intentPanorama, 101); + initPileSharePre(); break; case R.id.rl_coding: Intent intentCoding = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intentCoding, 102); + initPileSharePre(); break; case R.id.rl_equipment: Intent intentEquipment = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intentEquipment, 103); + initPileSharePre(); break; case R.id.rl_facility: Intent intentFacility = new Intent("android.media.action.IMAGE_CAPTURE"); @@ -511,6 +593,54 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC } } + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + initPileSharePre(); + } + + /** + * 防止当页面崩溃后出现数据丢失 + */ + public void initPileSharePre() { + //获取SharedPreferences对象,方法中两个参数的意思为:第一个name + //表示文件名,系统将会在/dada/dada/包名/shared_prefs目录下生成 + //一个以该参数命名的.xml文件。第二个mode表示创建的模式,通过查看 + //方法注释得知,建议以0或者MODE_PRIVATE为默认值。 + SharedPreferences poi = getActivity().getSharedPreferences("dataFile", 0); + //获取Editor对象 + SharedPreferences.Editor edit = poi.edit(); + //根据要保存的数据的类型,调用对应的put方法, + ChargingPileEntity chargingPileEntity = new ChargingPileEntity(); + if (inode != null) { + chargingPileEntity.setP(inode); + } + String name = editNameContent.getText().toString().trim();//名称 + if (name != null || !name.equals("")) { + chargingPileEntity.setName(name); + } + if (cp_floor != 0) { + chargingPileEntity.setCp_floor(cp_floor); + } + if (photoBean.size() > 0) { + chargingPileEntity.setPhotos(photoBean); + } + chargingPileEntity.setSign_exist(sign_exist); + chargingPileEntity.setCp_availableState(cp_availableState); + String describe = editDescribe.getText().toString().trim(); + if (describe != null || !describe.equals("")) { + chargingPileEntity.setMemo(describe); + } + if (pid != 0) { + chargingPileEntity.setFid(pid); + } + String newChargingPileEntity = new Gson().toJson(chargingPileEntity); + //以键值对的形式添加新值。 + edit.putString("chargingPileEntity", newChargingPileEntity); + //提交新值。必须执行,否则前面的操作都无效。 + edit.commit(); + Log.d("TAG", "initPileSharePre: " + newChargingPileEntity); + } @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { @@ -531,7 +661,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "a"); photoBean.add(takePhotoPath); ivPanorama.setImageBitmap(bitmap);//显示图像 } @@ -551,7 +681,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "b"); photoBean.add(takePhotoPath); ivCoding.setImageBitmap(bitmap);//显示图像 } @@ -571,7 +701,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "c1"); photoBean.add(takePhotoPath); ivEquipment.setImageBitmap(bitmap);//显示图像 } @@ -591,7 +721,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "c2"); photoBean.add(takePhotoPath); ivFacility.setImageBitmap(bitmap);//显示图像 } @@ -611,7 +741,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "c3"); photoBean.add(takePhotoPath); ivScutcheon.setImageBitmap(bitmap);//显示图像 } @@ -631,7 +761,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "c4"); photoBean.add(takePhotoPath); ivDevice.setImageBitmap(bitmap);//显示图像 } @@ -651,7 +781,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "d1"); photoBean.add(takePhotoPath); ivUsable.setImageBitmap(bitmap);//显示图像 } @@ -671,7 +801,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "d2"); photoBean.add(takePhotoPath); ivAvailable.setImageBitmap(bitmap);//显示图像 } @@ -691,7 +821,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "e1"); photoBean.add(takePhotoPath); ivParking.setImageBitmap(bitmap);//显示图像 } @@ -711,8 +841,9 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "e2"); photoBean.add(takePhotoPath); + ivNumber.setImageBitmap(bitmap);//显示图像 } } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/ChargingStationFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/ChargingStationFragment.java index be9d17a..29d6cdb 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/ChargingStationFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/ChargingStationFragment.java @@ -1,6 +1,7 @@ package com.navinfo.outdoor.fragment; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Message; @@ -20,6 +21,7 @@ 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.recyclerview.widget.DividerItemDecoration; @@ -28,6 +30,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; +import com.google.gson.Gson; import com.hjq.permissions.OnPermissionCallback; import com.hjq.permissions.Permission; import com.hjq.permissions.XXPermissions; @@ -53,6 +56,7 @@ import com.sothree.slidinguppanel.SlidingUpPanelLayout; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; +import java.io.Serializable; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -68,8 +72,8 @@ import static android.app.Activity.RESULT_OK; public class ChargingStationFragment extends BaseDrawerFragment implements View.OnClickListener { private EditText editDescribe; - private RelativeLayout rlPanorama, rlName, rlInternalPhotos, rlCard, rlElse, rlScutcheon; - private ImageView ivPanorama, ivName, ivInternal, ivCard, ivElse, ivScutcheon; + private RelativeLayout rlPanorama, rlName, rlInternalPhotos, rlElse, rlScutcheon; + private ImageView ivPanorama, ivName, ivInternal, ivElse, ivScutcheon; private TextView tvExamine; private EditText editNameContent, editSiteContent; private RecyclerView recyclerPhone; @@ -246,7 +250,6 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. ivPanorama = findViewById(R.id.iv_panorama); ivName = findViewById(R.id.iv_name); ivInternal = findViewById(R.id.iv_internal); - ivCard = findViewById(R.id.iv_card); ivElse = findViewById(R.id.iv_else); ivScutcheon = findViewById(R.id.iv_scutcheon); rlPanorama = findViewById(R.id.rl_panorama); @@ -255,8 +258,6 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. rlName.setOnClickListener(this::onClick); rlInternalPhotos = findViewById(R.id.rl_internal_photos); rlInternalPhotos.setOnClickListener(this::onClick); - rlCard = findViewById(R.id.rl_card); - rlCard.setOnClickListener(this::onClick); rlElse = findViewById(R.id.rl_else); rlElse.setOnClickListener(this::onClick); rlScutcheon = findViewById(R.id.rl_scutcheon); @@ -298,16 +299,64 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. recyclerStation.setLayoutManager(new GridLayoutManager(getContext(), 3)); chargingPileAdapter = new ChargingPileAdapter(getContext()); recyclerStation.setAdapter(chargingPileAdapter); + //数据展示 + initShowPoi(); + //禁用所有可操作控件 + //disables(); - - showPoiEntity = (PoiEntity) getArguments().getSerializable("PoiEntity"); + } + private void initShowPoi() { + // 添加信息: + showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity"); if (showPoiEntity != null) { - editNameContent.setText(showPoiEntity.getName()); - editDescribe.setText(showPoiEntity.getDescribe()); - editSiteContent.setText(showPoiEntity.getAddress()); + String name = showPoiEntity.getName();//名称 + if (name != null || !name.equals("")) { + editNameContent.setText(name + ""); + } + String address = showPoiEntity.getAddress();//地址 + if (address != null || !address.equals("")) { + editSiteContent.setText(address); + } String x = showPoiEntity.getX(); String y = showPoiEntity.getY(); - int id = showPoiEntity.getId(); + if (x != null && y != null) { + inode = x + "," + y; + } + String describe = showPoiEntity.getDescribe();//任务描述 + if (describe != null || !describe.equals("")) { + editDescribe.setText(describe); + } + String telPhone = showPoiEntity.getTelPhone(); + if (telPhone != null) { + phoneData.add(showPoiEntity.getTelPhone()); + poiBeans.add(new PoiBean("电话*", telPhone, R.drawable.icon_add_bg)); + } + + if (showPoiEntity.getPhotoInfo() != null) { + photoBean.clear(); + for (int i = 0; i < showPoiEntity.getPhotoInfo().size(); i++) { + String photo =showPoiEntity.getPhotoInfo().get(i).getPhoto(); + String[] split = photo.split("/"); + char charAt = split[6].charAt(0); + if (charAt=='a'){ + Glide.with(getActivity()).load(photo).into(ivPanorama); + photoBean.add(new Info(photo)); + }else if (charAt=='b'){ + Glide.with(getActivity()).load(photo).into(ivName); + photoBean.add(new Info(photo)); + }else if (charAt=='c'){ + Glide.with(getActivity()).load(photo).into(ivInternal); + photoBean.add(new Info(photo)); + }else if (charAt=='d'){ + Glide.with(getActivity()).load(photo).into(ivElse); + photoBean.add(new Info(photo)); + + }else if (charAt=='e'){ + Glide.with(getActivity()).load(photo).into(ivScutcheon); + photoBean.add(new Info(photo)); + } + } + } ArrayList chargingPileEntities = new ArrayList<>(); new Thread(new Runnable() { @Override @@ -329,12 +378,16 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. } }).start(); } - - //禁用所有可操作控件 - //disables(); - + ChargingPileEntity chargingPileEntity = (ChargingPileEntity) getArguments().getSerializable("chargingPileEntity"); + if (chargingPileEntity!=null){ + Message obtains = Message.obtain(); + obtains.what = Constant.CHARGING_STATION_PILE; + obtains.obj = chargingPileEntity; + EventBus.getDefault().post(obtains); + } } + //禁用所有可操作性控件 private void disables() { checkBoxLife.setEnabled(false); @@ -345,7 +398,6 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. ivPanorama.setEnabled(false); ivName.setEnabled(false); ivInternal.setEnabled(false); - ivCard.setEnabled(false); ivElse.setEnabled(false); editDescribe.setEnabled(false); btnSaveLocal.setEnabled(false); @@ -453,10 +505,6 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. poiDao.insertPoiEntity(poiEntity); } }).start(); - Message obtains = Message.obtain(); - obtains.what = Constant.TREASURE_FRAGMENT; - obtains.obj = false; - EventBus.getDefault().post(obtains); onBackPressed(); } else { Toast.makeText(getActivity(), "没有申请权限,请手动申请", Toast.LENGTH_SHORT).show(); @@ -495,17 +543,13 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. Intent intentInternal = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intentInternal, 103); break; - case R.id.rl_card: - Intent intentCard = new Intent("android.media.action.IMAGE_CAPTURE"); - startActivityForResult(intentCard, 104); - break; case R.id.rl_else: Intent intentElse = new Intent("android.media.action.IMAGE_CAPTURE"); - startActivityForResult(intentElse, 105); + startActivityForResult(intentElse, 104); break; case R.id.rl_scutcheon: Intent intentScutcheon = new Intent("android.media.action.IMAGE_CAPTURE"); - startActivityForResult(intentScutcheon, 106); + startActivityForResult(intentScutcheon, 105); break; case R.id.linear_charging_pile: Message obtains = Message.obtain(); @@ -516,6 +560,65 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. } } + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + initStationSharePre(); + } + + /** + * 防止当页面崩溃后出现数据丢失 + */ + public void initStationSharePre(){ + //获取SharedPreferences对象,方法中两个参数的意思为:第一个name + //表示文件名,系统将会在/dada/dada/包名/shared_prefs目录下生成 + //一个以该参数命名的.xml文件。第二个mode表示创建的模式,通过查看 + //方法注释得知,建议以0或者MODE_PRIVATE为默认值。 + SharedPreferences poi = getActivity().getSharedPreferences("dataFile", 0); + //获取Editor对象 + SharedPreferences.Editor edit = poi.edit(); + //根据要保存的数据的类型,调用对应的put方法, + + poiEntity = new PoiEntity(); + String name = editNameContent.getText().toString().trim();//名称 + if (name != null || !name.equals("")) { + poiEntity.setName(name); + } + String site = editSiteContent.getText().toString().trim(); + if (site != null || !site.equals("")) { + poiEntity.setAddress(site); + } + if (inode != null ) { + String[] split = inode.split(","); + poiEntity.setX(split[0]); + poiEntity.setY(split[1]); + } + String describe = editDescribe.getText().toString().trim(); + if (describe != null || !describe.equals("")) { + poiEntity.setDescribe(describe); + } + if (phoneData.size() > 0) { + poiEntity.setTelPhone(phoneData.get(0)); + } + if (photoBean.size() > 0) { + poiEntity.setPhotoInfo(photoBean); + } + poiEntity.setStation_type(station_type); + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + String format = formatter.format(calendar.getTime()); + poiEntity.setCreateTime(format); + poiEntity.setType(2); + poiEntity.setTaskStatus(0); + poiEntity.setTaskId(101); + String newPoiEntity = new Gson().toJson(poiEntity); + //以键值对的形式添加新值。 + edit.putString("poiEntity", newPoiEntity); + //提交新值。必须执行,否则前面的操作都无效。 + edit.commit(); + Log.d("TAG", "initPoiSharePre: "+newPoiEntity); + } @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { @@ -536,10 +639,8 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); - Info info = new Info(); - info.setPhoto(takePhotoPath); - photoBean.add(info); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data,"a"); + photoBean.add(new Info(takePhotoPath)); ivPanorama.setImageBitmap(bitmap);//显示图像 } @@ -559,10 +660,8 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); - Info info = new Info(); - info.setPhoto(takePhotoPath); - photoBean.add(info); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data,"b"); + photoBean.add(new Info(takePhotoPath)); ivName.setImageBitmap(bitmap);//显示图像 } @@ -582,10 +681,8 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); - Info info = new Info(); - info.setPhoto(takePhotoPath); - photoBean.add(info); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data,"c"); + photoBean.add(new Info(takePhotoPath)); ivInternal.setImageBitmap(bitmap);//显示图像 } } else if (requestCode == 104 && resultCode == RESULT_OK) { @@ -604,11 +701,9 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); - Info info = new Info(); - info.setPhoto(takePhotoPath); - photoBean.add(info); - ivCard.setImageBitmap(bitmap);//显示图像 + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data,"d"); + photoBean.add(new Info(takePhotoPath)); + ivElse.setImageBitmap(bitmap);//显示图像 } } else if (requestCode == 105 && resultCode == RESULT_OK) { Bundle extras = data.getExtras();//从Intent中获取附加值 @@ -626,35 +721,11 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View. } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); - Info info = new Info(); - info.setPhoto(takePhotoPath); - photoBean.add(info); - ivElse.setImageBitmap(bitmap);//显示图像 - } - - } else if (requestCode == 106 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - int height = bitmap.getHeight(); - int width = bitmap.getWidth(); - if (height > width) { - DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; - MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照,要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() { - @Override - public boolean onClick(BaseDialog baseDialog, View v) { - Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE"); - startActivityForResult(intentPanorama, 106); - return false; - } - }); - } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); - Info info = new Info(); - info.setPhoto(takePhotoPath); - photoBean.add(info); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data,"e"); + photoBean.add(new Info(takePhotoPath)); ivScutcheon.setImageBitmap(bitmap);//显示图像 } + } } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/GatherGetFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/GatherGetFragment.java index 5e4a210..3ffdb24 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/GatherGetFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/GatherGetFragment.java @@ -95,7 +95,7 @@ public class GatherGetFragment extends BaseFragment implements View.OnClickListe Bundle arguments = getArguments(); if (arguments!=null) { - poiEntity = (PoiEntity) arguments.getSerializable("PoiEntity"); + poiEntity = (PoiEntity) arguments.getSerializable("poiEntity"); tvTitle.setText(poiEntity.getName()); tvMoney.setText("3.5元"); tvTime.setText("到期时间:" + poiEntity.getCreateTime()); 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 ed7b3df..c8c3901 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java @@ -1,6 +1,7 @@ package com.navinfo.outdoor.fragment; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Message; @@ -25,6 +26,7 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.slidingpanelayout.widget.SlidingPaneLayout; import com.bumptech.glide.Glide; +import com.google.gson.Gson; import com.hjq.permissions.OnPermissionCallback; import com.hjq.permissions.Permission; import com.hjq.permissions.XXPermissions; @@ -36,6 +38,7 @@ import com.navinfo.outdoor.R; import com.navinfo.outdoor.api.Constant; import com.navinfo.outdoor.base.BaseDrawerFragment; import com.navinfo.outdoor.bean.Info; +import com.navinfo.outdoor.bean.PoiBean; import com.navinfo.outdoor.room.PoiDao; import com.navinfo.outdoor.room.PoiDatabase; import com.navinfo.outdoor.room.PoiEntity; @@ -128,20 +131,6 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis @Override protected void initView() { super.initView(); - //存储图片地址 - photoBean = new ArrayList<>(); - - } - @Subscribe - public void onEvent(Message data) { - if (data.what == Constant.OTHER_WORD) { - inode = data.obj.toString(); - Toast.makeText(getContext(), inode, Toast.LENGTH_SHORT).show(); - } - } - @Override - protected void initData() { - super.initData(); poiDatabase = PoiDatabase.getInstance(getContext()); poiDao = poiDatabase.getPoiDao(); spinnerOther = findViewById(R.id.spinner_other); @@ -189,7 +178,6 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis rlPicture = findViewById(R.id.rl_picture); rlPicture.setOnClickListener(this::onClick); ivPicture = findViewById(R.id.iv_picture); - rlPictures = findViewById(R.id.rl_pictures); rlPictures.setOnClickListener(this::onClick); ivPictures = findViewById(R.id.iv_pictures); @@ -198,20 +186,58 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis btnOtherLocal.setOnClickListener(this::onClick); btnOtherUploading = findViewById(R.id.btn_other_uploading); btnOtherUploading.setOnClickListener(this::onClick); + //数据展示 + initShowPoi(); - showPoiEntity = (PoiEntity) getArguments().getSerializable("PoiEntity"); + } + @Subscribe + public void onEvent(Message data) { + if (data.what == Constant.OTHER_WORD) { + inode = data.obj.toString(); + Toast.makeText(getContext(), inode, Toast.LENGTH_SHORT).show(); + } + } + @Override + protected void initData() { + super.initData(); + //存储图片地址 + photoBean = new ArrayList<>(); + + } + + private void initShowPoi() { + // 添加信息: + showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity"); if (showPoiEntity != null) { - editTaskName.setText(showPoiEntity.getName()); - inode = showPoiEntity.getX() + "," + showPoiEntity.getY(); - editOtherDescribe.setText(showPoiEntity.getDescribe()); + String name = showPoiEntity.getName();//名称 + if (name != null || !name.equals("")) { + editTaskName.setText(name + ""); + } + String x = showPoiEntity.getX(); + String y = showPoiEntity.getY(); + if (x != null && y != null) { + inode = x + "," + y; + } + String describe = showPoiEntity.getDescribe();//任务描述 + if (describe != null || !describe.equals("")) { + editOtherDescribe.setText(describe); + } if (showPoiEntity.getPhotoInfo() != null) { - if (showPoiEntity.getPhotoInfo().get(0).getPhoto() != null) { - Glide.with(getActivity()).load(showPoiEntity.getPhotoInfo().get(0).getPhoto()).into(ivPicture); + photoBean.clear(); + for (int i = 0; i < showPoiEntity.getPhotoInfo().size(); i++) { + String photo =showPoiEntity.getPhotoInfo().get(i).getPhoto(); + String[] split = photo.split("/"); + char charAt = split[6].charAt(0); + if (charAt=='a'){ + Glide.with(getActivity()).load(photo).into(ivPicture); + photoBean.add(new Info(photo)); + aBoolean=true; + }else if (charAt=='b'){ + Glide.with(getActivity()).load(photo).into(ivPictures); + photoBean.add(new Info(photo)); + bBoolean =true; + } } - if (showPoiEntity.getPhotoInfo().get(1).getPhoto() != null) { - Glide.with(getActivity()).load(showPoiEntity.getPhotoInfo().get(1).getPhoto()).into(ivPictures); - } - } } } @@ -222,10 +248,12 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis case R.id.rl_picture: Intent intentPicture = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intentPicture, 101); + initOtherSharePre(); break; case R.id.rl_pictures: Intent intentPictures = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intentPictures, 102); + initOtherSharePre(); break; case R.id.btn_other_local: XXPermissions.with(this) @@ -288,10 +316,6 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis } }).start(); - Message obtains = Message.obtain(); - obtains.what = Constant.TREASURE_FRAGMENT; - obtains.obj = false; - EventBus.getDefault().post(obtains); onBackPressed(); } else { Toast.makeText(getActivity(), "没有申请权限,请手动申请", Toast.LENGTH_SHORT).show(); @@ -313,6 +337,50 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis break; } } + /** + * 防止当页面崩溃后出现数据丢失 + */ + public void initOtherSharePre(){ + //获取SharedPreferences对象,方法中两个参数的意思为:第一个name + //表示文件名,系统将会在/dada/dada/包名/shared_prefs目录下生成 + //一个以该参数命名的.xml文件。第二个mode表示创建的模式,通过查看 + //方法注释得知,建议以0或者MODE_PRIVATE为默认值。 + SharedPreferences poi = getActivity().getSharedPreferences("dataFile", 0); + //获取Editor对象 + SharedPreferences.Editor edit = poi.edit(); + //根据要保存的数据的类型,调用对应的put方法, + PoiEntity poiEntity = new PoiEntity(); + String name = editTaskName.getText().toString().trim();//名称 + if (name != null || !name.equals("")) { + poiEntity.setName(name); + } + + if (inode != null) { + String[] split = inode.split(","); + poiEntity.setX(split[0]); + poiEntity.setY(split[1]); + } + String describe = editOtherDescribe.getText().toString().trim(); + if (describe != null || !describe.equals("")) { + poiEntity.setDescribe(describe); + } + if (photoBean.size() >0) { + poiEntity.setPhotoInfo(photoBean); + } + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + String format = formatter.format(calendar.getTime()); + poiEntity.setCreateTime(format); + poiEntity.setType(3); + poiEntity.setTaskStatus(0); + String newPoiEntity = new Gson().toJson(poiEntity); + //以键值对的形式添加新值。 + edit.putString("poiEntity", newPoiEntity); + //提交新值。必须执行,否则前面的操作都无效。 + edit.commit(); + Log.d("TAG", "initPoiSharePre: "+newPoiEntity); + } @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { @@ -333,11 +401,11 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data);//照片路径 - Info info = new Info(); - info.setPhoto(takePhotoPath); - photoBean.add(info); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data,"a");//照片路径 + photoBean.add(new Info(takePhotoPath)); ivPicture.setImageBitmap(bitmap);//显示图像 + String[] split = takePhotoPath.split("/"); + Log.d("TAG", "onActivityResult: "+takePhotoPath+" "+split[0]+" "+split[1]+" "+split[2]+" "+split[3]+" "+split[4]+" "+split[6]); aBoolean=true; } } else if (requestCode == 102 && resultCode == RESULT_OK) { @@ -356,16 +424,15 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data);//照片路径 - Info info = new Info(); - info.setPhoto(takePhotoPath); - photoBean.add(info); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data,"b");//照片路径 + photoBean.add(new Info(takePhotoPath)); ivPictures.setImageBitmap(bitmap);//显示图像 bBoolean=true; } } } + @Override public void onDestroy() { if (EventBus.getDefault().isRegistered(this))//加上判断 diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java index b434497..436382b 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java @@ -1,6 +1,7 @@ package com.navinfo.outdoor.fragment; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Message; @@ -16,6 +17,7 @@ import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.DividerItemDecoration; @@ -23,6 +25,8 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; +import com.google.gson.Gson; +import com.google.gson.JsonObject; import com.hjq.permissions.OnPermissionCallback; import com.hjq.permissions.Permission; import com.hjq.permissions.XXPermissions; @@ -45,6 +49,7 @@ import com.navinfo.outdoor.util.PhotoPathUtil; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; +import org.json.JSONObject; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -69,7 +74,6 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe private PoiRecycleAdapter poiRecycleAdapter; private ArrayList phoneData; private ArrayList poiBeans; - private int aInts; private Button btnSaveLocal; private Button btnUploading; private PoiDatabase poiDatabase; @@ -80,7 +84,6 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe private boolean bBoolean = false; private CheckBox checkBoxLife; private CheckBox checkBoxRight; - private String phone; private PoiEntity showPoiEntity; public static PoiFragment newInstance(Bundle bundle) { @@ -115,20 +118,20 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe @Override public void onClick(View v) { Bundle arguments = getArguments(); - if (arguments!=null) { - isSliding= arguments.getBoolean("isSliding",true); - Log.d("TAG", "onCreatessss: "+isSliding); + if (arguments != null) { + isSliding = arguments.getBoolean("isSliding", true); + Log.d("TAG", "onCreatessss: " + isSliding); } if (isSliding) { // 监听到返回按钮点击事件 Message obtain = Message.obtain(); - obtain.what= Constant.TREASURE_FRAGMENT; - obtain.obj=isSliding; + obtain.what = Constant.TREASURE_FRAGMENT; + obtain.obj = isSliding; EventBus.getDefault().post(obtain); Message mainButtonVisiableMsg = Message.obtain(); - mainButtonVisiableMsg.what= Constant.MAIN_BUTTON_VISIABLE; - mainButtonVisiableMsg.obj= View.VISIBLE; + mainButtonVisiableMsg.what = Constant.MAIN_BUTTON_VISIABLE; + mainButtonVisiableMsg.obj = View.VISIBLE; EventBus.getDefault().post(mainButtonVisiableMsg); } onBackPressed(); @@ -175,33 +178,12 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe rlInternalPhotos.setOnClickListener(this::onClick); rlCard = findViewById(R.id.rl_card); rlCard.setOnClickListener(this::onClick); - rlElse = findViewById(R.id.rl_else); rlElse.setOnClickListener(this::onClick); recyclerPhone = findViewById(R.id.recycler_phone); - - // 添加信息: - showPoiEntity = (PoiEntity) getArguments().getSerializable("PoiEntity"); - if (showPoiEntity != null) { - editNameContent.setText(showPoiEntity.getName()); - inode = showPoiEntity.getX() + "," + showPoiEntity.getY(); - editSiteContent.setText(showPoiEntity.getAddress()); - editDescribe.setText(showPoiEntity.getDescribe()); - phoneData.add(showPoiEntity.getTelPhone()); - phone = showPoiEntity.getTelPhone(); - if (showPoiEntity.getPhotoInfo() != null) { - if (showPoiEntity.getPhotoInfo().get(0).getPhoto() != null) { - Glide.with(getActivity()).load(showPoiEntity.getPhotoInfo().get(0).getPhoto()).into(ivPanorama); - } - if (showPoiEntity.getPhotoInfo().get(1).getPhoto() != null) { - Glide.with(getActivity()).load(showPoiEntity.getPhotoInfo().get(1).getPhoto()).into(ivName); - } - - } - } recyclerPhone.setLayoutManager(new LinearLayoutManager(getContext())); recyclerPhone.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL)); - poiBeans.add(new PoiBean("电话*", phone, R.drawable.icon_add_bg)); + poiRecycleAdapter = new PoiRecycleAdapter(getContext(), poiBeans); recyclerPhone.setAdapter(poiRecycleAdapter); poiRecycleAdapter.setInitPoiClick(new PoiRecycleAdapter.initPoiClick() { @@ -231,12 +213,69 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe } } }); + //数据展示 + initShowPoi(); //禁用所有可操作控件 //disables(); } + private void initShowPoi() { + // 添加信息: + showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity"); + if (showPoiEntity != null) { + String name = showPoiEntity.getName();//名称 + if (name != null || !name.equals("")) { + editNameContent.setText(name + ""); + } + String address = showPoiEntity.getAddress();//地址 + if (address != null || !address.equals("")) { + editSiteContent.setText(address); + } + String x = showPoiEntity.getX(); + String y = showPoiEntity.getY(); + if (x != null && y != null) { + inode = x + "," + y; + } + String describe = showPoiEntity.getDescribe();//任务描述 + if (describe != null || !describe.equals("")) { + editDescribe.setText(describe); + } + String telPhone = showPoiEntity.getTelPhone(); + if (telPhone != null) { + phoneData.add(showPoiEntity.getTelPhone()); + poiBeans.add(new PoiBean("电话*", telPhone, R.drawable.icon_add_bg)); + } + if (showPoiEntity.getPhotoInfo() != null) { + photoBean.clear(); + for (int i = 0; i < showPoiEntity.getPhotoInfo().size(); i++) { + String photo =showPoiEntity.getPhotoInfo().get(i).getPhoto(); + String[] split = photo.split("/"); + char charAt = split[6].charAt(0); + if (charAt=='a'){ + Glide.with(getActivity()).load(photo).into(ivPanorama); + photoBean.add(new Info(photo)); + }else if (charAt=='b'){ + Glide.with(getActivity()).load(photo).into(ivName); + photoBean.add(new Info(photo)); + }else if (charAt=='c'){ + Glide.with(getActivity()).load(photo).into(ivInternal); + photoBean.add(new Info(photo)); + }else if (charAt=='d'){ + Glide.with(getActivity()).load(photo).into(ivCard); + photoBean.add(new Info(photo)); + + }else if (charAt=='e'){ + Glide.with(getActivity()).load(photo).into(ivElse); + photoBean.add(new Info(photo)); + } + } + } + } + } + + //禁用所有可操作性控件 private void disables() { checkBoxLife.setEnabled(false); @@ -353,10 +392,6 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe } }).start(); - Message obtains = Message.obtain(); - obtains.what = Constant.TREASURE_FRAGMENT; - obtains.obj = false; - EventBus.getDefault().post(obtains); onBackPressed(); } else { Toast.makeText(getActivity(), "没有申请权限,请手动申请", Toast.LENGTH_SHORT).show(); @@ -383,7 +418,6 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe case R.id.tv_examine: Toast.makeText(getContext(), editNameContent.getText().toString(), Toast.LENGTH_SHORT).show(); break; - case R.id.rl_panorama: Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intentPanorama, 101); @@ -403,11 +437,65 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe case R.id.rl_else: Intent intentElse = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intentElse, 105); + break; } } + /** + * 防止当页面崩溃后出现数据丢失 + */ + public void initPoiSharePre() { + //获取SharedPreferences对象,方法中两个参数的意思为:第一个name + //表示文件名,系统将会在/dada/dada/包名/shared_prefs目录下生成 + //一个以该参数命名的.xml文件。第二个mode表示创建的模式,通过查看 + //方法注释得知,建议以0或者MODE_PRIVATE为默认值。 + SharedPreferences poi = getActivity().getSharedPreferences("dataFile", 0); + //获取Editor对象 + SharedPreferences.Editor edit = poi.edit(); + //根据要保存的数据的类型,调用对应的put方法, + + PoiEntity poiEntity = new PoiEntity(); + String name = editNameContent.getText().toString().trim();//名称 + if (name != null || !name.equals("")) { + poiEntity.setName(name); + } + String site = editSiteContent.getText().toString().trim(); + if (site != null || !site.equals("")) { + poiEntity.setAddress(site); + } + if (inode!=null) { + String[] split = inode.split(","); + poiEntity.setX(split[0]); + poiEntity.setY(split[1]); + } + String describe = editDescribe.getText().toString().trim(); + if (describe!= null || !describe.equals("")) { + poiEntity.setDescribe(describe); + } + if (phoneData.size() > 0) { + poiEntity.setTelPhone(phoneData.get(0)); + } + if (photoBean.size() > 0) { + poiEntity.setPhotoInfo(photoBean); + } + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + String format = formatter.format(calendar.getTime()); + poiEntity.setCreateTime(format); + poiEntity.setType(0); + poiEntity.setTaskStatus(0); + String newPoiEntity = new Gson().toJson(poiEntity); + //以键值对的形式添加新值。 + edit.putString("poiEntity", newPoiEntity); + //提交新值。必须执行,否则前面的操作都无效。 + edit.commit(); + Log.d("TAG", "initPoiSharePre: " + newPoiEntity); + } + + @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { @@ -428,10 +516,8 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); - Info info = new Info(); - info.setPhoto(takePhotoPath); - photoBean.add(info); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data,"a"); + photoBean.add(new Info(takePhotoPath)); ivPanorama.setImageBitmap(bitmap);//显示图像 aBoolean = true; } @@ -452,10 +538,8 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); - Info info = new Info(); - info.setPhoto(takePhotoPath); - photoBean.add(info); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data,"b"); + photoBean.add(new Info(takePhotoPath)); ivName.setImageBitmap(bitmap);//显示图像 bBoolean = true; } @@ -476,10 +560,8 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); - Info info = new Info(); - info.setPhoto(takePhotoPath); - photoBean.add(info); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data,"c"); + photoBean.add(new Info(takePhotoPath)); ivInternal.setImageBitmap(bitmap);//显示图像 } } else if (requestCode == 104 && resultCode == RESULT_OK) { @@ -498,10 +580,8 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); - Info info = new Info(); - info.setPhoto(takePhotoPath); - photoBean.add(info); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data,"d"); + photoBean.add(new Info(takePhotoPath)); ivCard.setImageBitmap(bitmap);//显示图像 } } else if (requestCode == 105 && resultCode == RESULT_OK) { @@ -520,16 +600,20 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe } }); } else { - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data); - Info info = new Info(); - info.setPhoto(takePhotoPath); - photoBean.add(info); + String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data,"e"); + photoBean.add(new Info(takePhotoPath)); ivElse.setImageBitmap(bitmap);//显示图像 } } } + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + initPoiSharePre(); + Log.d("TAG", "onSaveInstanceState: "); + } @Override public void onDestroy() { 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 28d35bf..5c5dbad 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/PoiVideoFragment.java @@ -1,6 +1,7 @@ package com.navinfo.outdoor.fragment; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.media.MediaMetadataRetriever; import android.os.Bundle; @@ -16,6 +17,8 @@ import android.widget.RadioGroup; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; + import com.google.gson.Gson; import com.hjq.permissions.OnPermissionCallback; import com.hjq.permissions.Permission; @@ -53,6 +56,7 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick private RadioGroup rgType; private PoiDatabase poiDatabase; private PoiDao poiDao; + private PoiEntity showPoiEntity; public static PoiVideoFragment newInstance(Bundle bundle) { PoiVideoFragment fragment = new PoiVideoFragment(); @@ -119,12 +123,32 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick btnRoadSave = (Button) findViewById(R.id.btn_road_save); btnRoadSave.setOnClickListener(this::onClick); rgType = (RadioGroup) findViewById(R.id.rg_type); - + //添加数据 + initShowPoi(); //禁用可操作性控件 // disables(); //获取 } - + private void initShowPoi() { + // 添加信息: + showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity"); + if (showPoiEntity != null) { + String name = showPoiEntity.getName();//名称 + if (name != null || !name.equals("")) { + etRoadName.setText(name + ""); + } + String extend = showPoiEntity.getExtend(); + if (extend!=null||!extend.equals("")){ + RoadExtend roadExtend = new Gson().fromJson(extend, RoadExtend.class); + int type= roadExtend.getType(); + showPictureType(type); + } + String describe = showPoiEntity.getDescribe();//任务描述 + if (describe != null || !describe.equals("")) { + etDesc.setText(describe); + } + } + } private void disables() { etRoadName.setEnabled(false); rgType.setEnabled(false); @@ -204,9 +228,13 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick new Thread(new Runnable() { @Override public void run() { + if (showPoiEntity != null) { + poiDao.updatePoiEntity(poiEntity); + } poiDao.insertPoiEntity(poiEntity); } }).start(); + onBackPressed(); } } @@ -229,6 +257,57 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick } } + @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 = getActivity().getSharedPreferences("dataFile", 0); + //获取Editor对象 + SharedPreferences.Editor edit = poi.edit(); + //根据要保存的数据的类型,调用对应的put方法, + + PoiEntity poiEntity = new PoiEntity(); + String roadName = etRoadName.getText().toString().trim(); + if (roadName != null || !roadName.equals("")) { + poiEntity.setName(roadName); + } + RoadExtend roadExtend = new RoadExtend(); + int type = getPictureType(); + if (type != -1) { + roadExtend.setType(type); + Gson gson = new Gson(); + String roadExtendJson = gson.toJson(roadExtend); + poiEntity.setExtend(roadExtendJson); + } + String desc = etDesc.getText().toString().trim(); + if (desc != null || !desc.equals("")) { + poiEntity.setDescribe(desc); + } + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + String format = formatter.format(calendar.getTime()); + poiEntity.setCreateTime(format); + poiEntity.setType(4); + String newPoiEntity = new Gson().toJson(poiEntity); + //以键值对的形式添加新值。 + edit.putString("poiEntity", newPoiEntity); + //提交新值。必须执行,否则前面的操作都无效。 + edit.commit(); + Log.d("TAG", "initRoadSharePre: "+newPoiEntity); + } + + //获取拍照类型 private int getPictureType() { if (rbCar != null && rbCar.isChecked()) { @@ -242,4 +321,20 @@ public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClick } return -1; } + private void showPictureType(int type){ + switch (type){ + case 0: + rbCar.setChecked(true); + break; + case 1: + rbBicycle.setChecked(true); + break; + case 2: + rbWalking.setChecked(true); + break; + case 3: + rbManual.setChecked(true); + break; + } + } } \ 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 1537210..22fbbc2 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/RoadFragment.java @@ -1,6 +1,7 @@ package com.navinfo.outdoor.fragment; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.media.MediaMetadataRetriever; import android.os.Bundle; @@ -16,6 +17,9 @@ import android.widget.RadioGroup; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; + +import com.bumptech.glide.Glide; import com.google.gson.Gson; import com.hjq.permissions.OnPermissionCallback; import com.hjq.permissions.Permission; @@ -24,6 +28,7 @@ import com.navinfo.outdoor.R; import com.navinfo.outdoor.activity.PictureActivity; import com.navinfo.outdoor.api.Constant; import com.navinfo.outdoor.base.BaseDrawerFragment; +import com.navinfo.outdoor.bean.PoiBean; import com.navinfo.outdoor.bean.RoadExtend; import com.navinfo.outdoor.room.PoiDao; import com.navinfo.outdoor.room.PoiDatabase; @@ -120,12 +125,32 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList btnRoadSave = (Button) findViewById(R.id.btn_road_save); btnRoadSave.setOnClickListener(this::onClick); rgType = (RadioGroup) findViewById(R.id.rg_type); - + //数据展示 + initShowPoi(); //禁用可操作性控件 // disables(); - //获取 } + private void initShowPoi() { + // 添加信息: + showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity"); + if (showPoiEntity != null) { + String name = showPoiEntity.getName();//名称 + if (name != null || !name.equals("")) { + etRoadName.setText(name + ""); + } + String extend = showPoiEntity.getExtend(); + if (extend!=null||!extend.equals("")){ + RoadExtend roadExtend = new Gson().fromJson(extend, RoadExtend.class); + int type= roadExtend.getType(); + showPictureType(type); + } + String describe = showPoiEntity.getDescribe();//任务描述 + if (describe != null || !describe.equals("")) { + etDesc.setText(describe); + } + } + } private void disables() { etRoadName.setEnabled(false); @@ -237,6 +262,56 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList } } + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + initRoadSharePre(); + } + + /** + *防止程序崩溃后数据丢失 + */ + public void initRoadSharePre(){ + //获取SharedPreferences对象,方法中两个参数的意思为:第一个name + //表示文件名,系统将会在/dada/dada/包名/shared_prefs目录下生成 + //一个以该参数命名的.xml文件。第二个mode表示创建的模式,通过查看 + //方法注释得知,建议以0或者MODE_PRIVATE为默认值。 + SharedPreferences poi = getActivity().getSharedPreferences("dataFile", 0); + //获取Editor对象 + SharedPreferences.Editor edit = poi.edit(); + //根据要保存的数据的类型,调用对应的put方法, + + PoiEntity poiEntity = new PoiEntity(); + String roadName = etRoadName.getText().toString().trim(); + if (roadName != null || !roadName.equals("")) { + poiEntity.setName(roadName); + } + RoadExtend roadExtend = new RoadExtend(); + int type = getPictureType(); + if (type != -1) { + roadExtend.setType(type); + Gson gson = new Gson(); + String roadExtendJson = gson.toJson(roadExtend); + poiEntity.setExtend(roadExtendJson); + } + String desc = etDesc.getText().toString().trim(); + if (desc != null || !desc.equals("")) { + poiEntity.setDescribe(desc); + } + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + String format = formatter.format(calendar.getTime()); + poiEntity.setCreateTime(format); + poiEntity.setType(1); + String newPoiEntity = new Gson().toJson(poiEntity); + //以键值对的形式添加新值。 + edit.putString("poiEntity", newPoiEntity); + //提交新值。必须执行,否则前面的操作都无效。 + edit.commit(); + Log.d("TAG", "initRoadSharePre: "+newPoiEntity); + } + //获取拍照类型 private int getPictureType() { if (rbCar != null && rbCar.isChecked()) { @@ -250,4 +325,20 @@ public class RoadFragment extends BaseDrawerFragment implements View.OnClickList } return -1; } + private void showPictureType(int type){ + switch (type){ + case 0: + rbCar.setChecked(true); + break; + case 1: + rbBicycle.setChecked(true); + break; + case 2: + rbWalking.setChecked(true); + break; + case 3: + rbManual.setChecked(true); + break; + } + } } \ 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 562eac7..dbf7c97 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/TreasureFragment.java @@ -1,6 +1,7 @@ package com.navinfo.outdoor.fragment; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; @@ -38,6 +39,7 @@ import com.navinfo.outdoor.activity.FragmentManagement; import com.navinfo.outdoor.api.Constant; import com.navinfo.outdoor.base.BaseDrawerFragment; import com.navinfo.outdoor.base.BaseFragment; +import com.navinfo.outdoor.room.ChargingPileEntity; import com.navinfo.outdoor.room.PoiEntity; import com.navinfo.outdoor.util.NetWorkUtils; import com.navinfo.outdoor.util.ToastUtil; @@ -159,9 +161,125 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen uiSettings.setLogoScale(0.7f); //开启定位权限 checkNetWork(); + //检查是否有没有填完的页面 + initSharePre(); } + + private void initSharePre() { + //根据保存时所用的name属性,获取SharedPreferences对象 + SharedPreferences dataFile = getActivity().getSharedPreferences("dataFile", 0); + //根据数据类型,调用对应的get方法,通过键取得对应的值。 + String dataFileString = dataFile.getString("poiEntity", null); + String pileFileString = dataFile.getString("chargingPileEntity", null); + if (dataFileString!=null){ + PoiEntity poiEntity = new Gson().fromJson(dataFileString, PoiEntity.class); + switch (poiEntity.getType()){ + case 0: + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getContext(), "提示", "你poi页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + Bundle bundle = new Bundle(); + bundle.putSerializable("poiEntity", poiEntity); + PoiFragment poiFragment = PoiFragment.newInstance(bundle); + showSlidingFragment(poiFragment); + initRemovePoiSharePre(); + return false; + } + }); + break; + case 1: + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getContext(), "提示", "你道路页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + Bundle bundle = new Bundle(); + bundle.putSerializable("poiEntity",poiEntity); + RoadFragment roadFragment = RoadFragment.newInstance(bundle); + showSlidingFragment(roadFragment); + initRemovePoiSharePre(); + return false; + } + }); + break; + case 2: + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getContext(), "提示", "你充电站页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + Bundle bundle = new Bundle(); + bundle.putSerializable("poiEntity",poiEntity); + ChargingStationFragment chargingStationFragment = ChargingStationFragment.newInstance(bundle); + showSlidingFragment(chargingStationFragment); + initRemovePoiSharePre(); + return false; + } + }); + break; + case 3: + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getContext(), "提示", "你其他页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + Bundle bundle = new Bundle(); + bundle.putSerializable("poiEntity",poiEntity); + OtherFragment otherFragment = OtherFragment.newInstance(bundle); + showSlidingFragment(otherFragment); + initRemovePoiSharePre(); + return false; + } + }); + break; + case 4: + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getContext(), "提示", "你poi录像页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + Bundle bundle = new Bundle(); + bundle.putSerializable("poiEntity",poiEntity); + PoiVideoFragment poiVideoFragment = PoiVideoFragment.newInstance(bundle); + showSlidingFragment(poiVideoFragment); + initRemovePoiSharePre(); + return false; + } + }); + break; + } + } + if (pileFileString!=null){ + ChargingPileEntity chargingPileEntity = new Gson().fromJson(pileFileString, ChargingPileEntity.class); + DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE; + MessageDialog.show((AppCompatActivity) getContext(), "提示", "你充电桩页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() { + @Override + public boolean onClick(BaseDialog baseDialog, View v) { + Bundle bundle = new Bundle(); + bundle.putSerializable("chargingPileEntity",chargingPileEntity); + ChargingStationFragment chargingStationFragment = ChargingStationFragment.newInstance(bundle); + showSlidingFragment(chargingStationFragment); + initRemovePoiSharePre(); + return false; + } + }); + } + } + public void initRemovePoiSharePre() { + //获取SharedPreferences对象,方法中两个参数的意思为:第一个name + //表示文件名,系统将会在/dada/dada/包名/shared_prefs目录下生成 + //一个以该参数命名的.xml文件。第二个mode表示创建的模式,通过查看 + //方法注释得知,建议以0或者MODE_PRIVATE为默认值。 + SharedPreferences poi = getActivity().getSharedPreferences("dataFile", 0); + //获取Editor对象 + SharedPreferences.Editor edit = poi.edit(); + //根据要保存的数据的类型,调用对应的put方法, + //以键值对的形式添加新值。 + edit.putString("poiEntity", null); + edit.putString("chargingPileEntity", null); + //提交新值。必须执行,否则前面的操作都无效。 + edit.commit(); + } + @Subscribe public void onEvent(Message data) { if (data.what == Constant.FILTER_LIST_ITEM) { // 点击筛选的item @@ -173,7 +291,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen frameLayout.setVisibility(View.VISIBLE); fragmentTransaction = supportFragmentManager.beginTransaction(); Bundle bundle = new Bundle(); - bundle.putSerializable("PoiEntity", poiEntity); + bundle.putSerializable("poiEntity", poiEntity); gatherGetFragment = GatherGetFragment.newInstance(bundle); fragmentTransaction.replace(R.id.frame_layout, gatherGetFragment); fragmentTransaction.commit(); @@ -181,7 +299,7 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen PoiEntity poiEntity = (PoiEntity) data.obj; Bundle bundle = new Bundle(); bundle.putBoolean("isSliding", false); // 通知抽屉不收回 - bundle.putSerializable("PoiEntity", poiEntity); + bundle.putSerializable("poiEntity", poiEntity); frameLayout.setVisibility(View.GONE); fragmentTransaction.remove(gatherGetFragment); switch (poiEntity.getType()) { @@ -244,6 +362,12 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen bundle.putInt("pid", (Integer) data.obj); ChargingPileFragment chargingPileFragment = ChargingPileFragment.newInstance(bundle); showSlidingFragment(chargingPileFragment); + } else if (data.what == Constant.CHARGING_STATION_PILE) {//充电站的充电桩 + Bundle bundle = new Bundle(); + bundle.putBoolean("isSliding", false); // 通知抽屉不收回 + bundle.putSerializable("chargingPileEntity",(ChargingPileEntity) data.obj); + ChargingPileFragment chargingPileFragment = ChargingPileFragment.newInstance(bundle); + showSlidingFragment(chargingPileFragment); } diff --git a/app/src/main/java/com/navinfo/outdoor/fragment/UserAttestationFragment.java b/app/src/main/java/com/navinfo/outdoor/fragment/UserAttestationFragment.java index f5f8dbc..8af2cca 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/UserAttestationFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/UserAttestationFragment.java @@ -168,13 +168,13 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 100 && resultCode == RESULT_OK) { - takePhotoPath1 = PhotoPathUtil.getTakePhotoPath(data); + takePhotoPath1 = PhotoPathUtil.getTakePhotoPath(data,"a"); Bundle extras = data.getExtras();//从Intent中获取附加值 //从附加值中获取返回的图像 Bitmap bitmap = (Bitmap) extras.get("data"); ivAttestation1.setImageBitmap(bitmap);//显示图像 } else if (requestCode == 200 && resultCode == RESULT_OK) { - takePhotoPath2 = PhotoPathUtil.getTakePhotoPath(data); + takePhotoPath2 = PhotoPathUtil.getTakePhotoPath(data,"b"); Bundle extras = data.getExtras();//从Intent中获取附加值 //从附加值中获取返回的图像 Bitmap bitmap = (Bitmap) extras.get("data"); diff --git a/app/src/main/java/com/navinfo/outdoor/room/ChargingPileEntity.java b/app/src/main/java/com/navinfo/outdoor/room/ChargingPileEntity.java index 8cfdf01..3c54f54 100644 --- a/app/src/main/java/com/navinfo/outdoor/room/ChargingPileEntity.java +++ b/app/src/main/java/com/navinfo/outdoor/room/ChargingPileEntity.java @@ -9,6 +9,7 @@ import com.navinfo.outdoor.bean.Info; import com.navinfo.outdoor.util.PhotoInfoConverter; import com.navinfo.outdoor.util.StringTypeConverter; +import java.io.Serializable; import java.util.List; import static androidx.room.ForeignKey.CASCADE; @@ -19,7 +20,7 @@ import static androidx.room.ForeignKey.CASCADE; * 注解中包含Delete = CASCADE, 你可以告诉SQLite,如果相应的PoiEntity实例被删除,那么删除这个PoiEntity下的所有ChargingPileEntity。 */ @Entity(tableName = "pile") -public class ChargingPileEntity { +public class ChargingPileEntity implements Serializable { @PrimaryKey(autoGenerate = true) // 设置主键,并且自动生长 private int pileId; private String name;//名称 diff --git a/app/src/main/java/com/navinfo/outdoor/room/PoiEntity.java b/app/src/main/java/com/navinfo/outdoor/room/PoiEntity.java index 29ed6e1..585b369 100644 --- a/app/src/main/java/com/navinfo/outdoor/room/PoiEntity.java +++ b/app/src/main/java/com/navinfo/outdoor/room/PoiEntity.java @@ -55,7 +55,7 @@ public class PoiEntity implements Serializable { private String y;//纬度 private String detail;//深度信息 private int taskStatus;//任务状态 0.待提交,1.已提交,2 已领取 - private int type;//0.poi,1.道路,2.充电站,3.其他 + private int type;//0.poi,1.道路,2.充电站,3.其他 ,4,poi录像 private int station_type;//0.全部,1.poi,2.道路,3.充电站,4.其他 public int getStation_type() { diff --git a/app/src/main/java/com/navinfo/outdoor/util/PhotoPathUtil.java b/app/src/main/java/com/navinfo/outdoor/util/PhotoPathUtil.java index 472cbda..983b6a7 100644 --- a/app/src/main/java/com/navinfo/outdoor/util/PhotoPathUtil.java +++ b/app/src/main/java/com/navinfo/outdoor/util/PhotoPathUtil.java @@ -21,7 +21,7 @@ import java.util.Date; */ public class PhotoPathUtil { - public static String getTakePhotoPath(Intent data) { + public static String getTakePhotoPath(Intent data,String d) { Bitmap photo = null; Uri uri = data.getData(); if (uri != null) { @@ -43,7 +43,7 @@ public class PhotoPathUtil { calendar.setTimeInMillis(System.currentTimeMillis()); String format = formatter.format(calendar.getTime()); //文件 - File file = new File(Constant.PICTURE_FOLDER, format + ".jpg"); + File file = new File(Constant.PICTURE_FOLDER, d+format + ".jpg"); /***打开文件输出流*/ fileOutputStream = new FileOutputStream(file); // 生成图片文件 diff --git a/app/src/main/res/layout/charging_station_fragment.xml b/app/src/main/res/layout/charging_station_fragment.xml index 145e580..1c6c8fc 100644 --- a/app/src/main/res/layout/charging_station_fragment.xml +++ b/app/src/main/res/layout/charging_station_fragment.xml @@ -352,40 +352,6 @@ android:layout_height="0dp" android:layout_weight="1" > - - - - - + + + diff --git a/app/src/main/res/layout/treasure_fragment.xml b/app/src/main/res/layout/treasure_fragment.xml index ec2a5ee..f7cd612 100644 --- a/app/src/main/res/layout/treasure_fragment.xml +++ b/app/src/main/res/layout/treasure_fragment.xml @@ -18,8 +18,6 @@ android:layout_height="match_parent" android:gravity="center"> - -