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 ba58d54..ba13f02 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/ChargingPileFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/ChargingPileFragment.java @@ -4,8 +4,10 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.Color; +import android.net.Uri; import android.os.Bundle; import android.os.Message; +import android.provider.MediaStore; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -51,6 +53,7 @@ import com.navinfo.outdoor.room.PoiEntity; import com.navinfo.outdoor.util.Geohash; import com.navinfo.outdoor.util.GeometryTools; import com.navinfo.outdoor.util.PhotoPathUtil; +import com.navinfo.outdoor.util.PhotoUtils; import com.navinfo.outdoor.util.PictureUtil; import com.navinfo.outdoor.util.ToastUtil; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; @@ -109,6 +112,7 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC private ArrayList phoneLists; private PoiEntity poiEntity; + private File file; public static ChargingPileFragment newInstance(Bundle bundle) { ChargingPileFragment fragment = new ChargingPileFragment(); @@ -796,45 +800,65 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC break; case R.id.rl_panorama: Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("a",latLng); + intentPanorama.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentPanorama, 101); initPileSharePre(); break; case R.id.rl_coding: Intent intentCoding = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("b", latLng); + intentCoding.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentCoding, 102); initPileSharePre(); break; case R.id.rl_equipment: Intent intentEquipment = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("c", latLng); + intentEquipment.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentEquipment, 103); initPileSharePre(); break; case R.id.rl_facility: Intent intentFacility = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("c", latLng); + intentFacility.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentFacility, 104); break; case R.id.rl_scutcheon: Intent intentScutcheon = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("c",latLng); + intentScutcheon.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentScutcheon, 105); break; case R.id.rl_device: Intent intentDevice = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("c", latLng); + intentDevice.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentDevice, 106); break; case R.id.rl_usable: Intent intentUsable = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("d", latLng); + intentUsable.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentUsable, 107); break; case R.id.rl_available: Intent intentAvailable = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("d", latLng); + intentAvailable.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentAvailable, 108); break; case R.id.rl_parking: Intent intentParking = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("e", latLng); + intentParking.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentParking, 109); break; case R.id.rl_number: Intent intentNumber = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("e",latLng); + intentNumber.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentNumber, 110); break; @@ -928,11 +952,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 101 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath1 = PhotoPathUtil.getTakePhotoPath(data, "a", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - tvPanorama.setTag(takePhotoPath1); - ivPanorama.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivPanorama); + tvPanorama.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -949,11 +977,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 102 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath2 = PhotoPathUtil.getTakePhotoPath(data, "b", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - tvCoding.setTag(takePhotoPath2); - ivCoding.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivCoding); + tvCoding.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -970,11 +1002,16 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 103 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath3 = PhotoPathUtil.getTakePhotoPath(data, "c", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - ivEquipment.setImageBitmap(bitmap);//显示图像 - tvEquipment.setTag(takePhotoPath3); + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivEquipment); + tvEquipment.setTag(s); + } + file=null; + /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -991,11 +1028,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 104 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath4 = PhotoPathUtil.getTakePhotoPath(data, "c", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - tvFacility.setTag(takePhotoPath4); - ivFacility.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivFacility); + tvFacility.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1012,11 +1053,16 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 105 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath5 = PhotoPathUtil.getTakePhotoPath(data, "c", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - tvScutcheon.setTag(takePhotoPath5); - ivScutcheon.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivScutcheon); + tvScutcheon.setTag(s); + } + file=null; + /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1033,11 +1079,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 106 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath6 = PhotoPathUtil.getTakePhotoPath(data, "c", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - tvDevice.setTag(takePhotoPath6); - ivDevice.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivDevice); + tvDevice.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1054,11 +1104,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 107 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath7 = PhotoPathUtil.getTakePhotoPath(data, "d", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - tvUsable.setTag(takePhotoPath7); - ivUsable.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivUsable); + tvUsable.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1075,11 +1129,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 108 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath8 = PhotoPathUtil.getTakePhotoPath(data, "d", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - tvAvailable.setTag(takePhotoPath8); - ivAvailable.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivAvailable); + tvAvailable.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1096,11 +1154,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 109 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath9 = PhotoPathUtil.getTakePhotoPath(data, "e", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - ivParking.setImageBitmap(bitmap);//显示图像 - tvParking.setTag(takePhotoPath9); + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivParking); + tvParking.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { @@ -1117,11 +1179,15 @@ public class ChargingPileFragment extends BaseDrawerFragment implements View.OnC }*/ } else if (requestCode == 110 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - takePhotoPath10 = PhotoPathUtil.getTakePhotoPath(data, "e", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - ivNumber.setImageBitmap(bitmap);//显示图像 - tvNumber.setTag(takePhotoPath10); + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivNumber); + tvNumber.setTag(s); + } + file=null; /* int height = bitmap.getHeight(); int width = bitmap.getWidth(); if (height > width) { 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 c9448dc..c8849ae 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/OtherFragment.java @@ -4,8 +4,10 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.Color; +import android.net.Uri; import android.os.Bundle; import android.os.Message; +import android.provider.MediaStore; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -21,6 +23,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; @@ -54,6 +57,7 @@ import com.navinfo.outdoor.room.PoiDatabase; import com.navinfo.outdoor.room.PoiEntity; import com.navinfo.outdoor.util.Geohash; import com.navinfo.outdoor.util.PhotoPathUtil; +import com.navinfo.outdoor.util.PhotoUtils; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import org.greenrobot.eventbus.EventBus; @@ -92,6 +96,7 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis private int station_type = 5; private ArrayList otherUploadList; private CheckBox checkPot; + private File file; public static OtherFragment newInstance(Bundle bundle) { OtherFragment fragment = new OtherFragment(); @@ -325,13 +330,15 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis switch (v.getId()) { case R.id.rl_picture: Intent intentPicture = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("a", latLng); + intentPicture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentPicture, 101); - initOtherSharePre(); break; case R.id.rl_pictures: Intent intentPictures = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("b",latLng); + intentPictures.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentPictures, 102); - initOtherSharePre(); break; case R.id.btn_other_local: initPoiSaveLocal(false); @@ -425,7 +432,6 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis } }); } - private void otherUploadByNet(int body, List otherUploadList) { if (body == 0) { Toast.makeText(getActivity(), "没有保存本地", Toast.LENGTH_SHORT).show(); @@ -534,6 +540,11 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis dismissDialog(); } + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + initOtherSharePre(); + } /** * 防止当页面崩溃后出现数据丢失 */ @@ -559,19 +570,25 @@ public class OtherFragment extends BaseDrawerFragment implements View.OnClickLis public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 101 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - //照片路径 - String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "a", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - tvPicture.setTag(takePhotoPath); - ivPicture.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivPicture); + tvPicture.setTag(s); + } + file=null; } else if (requestCode == 102 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 //照片路径 - String takePhotoPath2 = PhotoPathUtil.getTakePhotoPath(data, "b", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); - tvPictures.setTag(takePhotoPath2); - ivPictures.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivPictures); + tvPictures.setTag(s); + } + file=null; } } 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 6a84c65..8cbd9c5 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/PoiFragment.java @@ -62,6 +62,7 @@ import com.navinfo.outdoor.ui.view.ContactView; import com.navinfo.outdoor.util.Geohash; import com.navinfo.outdoor.util.NetWorkUtils; import com.navinfo.outdoor.util.PhotoPathUtil; +import com.navinfo.outdoor.util.PhotoUtils; import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import org.greenrobot.eventbus.EventBus; @@ -109,6 +110,7 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe private ContactView contactView; private ArrayList poiPicList; private String tagPanorama; + private File file; public static PoiFragment newInstance(Bundle bundle) { PoiFragment fragment = new PoiFragment(); @@ -588,7 +590,7 @@ public class PoiFragment extends BaseDrawerFragment implements View.OnClickListe break; case R.id.rl_panorama: Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE"); - File file = new File(Constant.PICTURE_FOLDER+"/aaaaaa.jpg"); + file = PhotoUtils.showPhotoFile("a",latLng); intentPanorama.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intentPanorama, 101); break; 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 8db9c6a..4d2c5cc 100644 --- a/app/src/main/java/com/navinfo/outdoor/fragment/UserAttestationFragment.java +++ b/app/src/main/java/com/navinfo/outdoor/fragment/UserAttestationFragment.java @@ -4,7 +4,9 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; +import android.net.Uri; import android.os.Bundle; +import android.provider.MediaStore; import android.util.Log; import android.view.View; import android.widget.Button; @@ -28,7 +30,9 @@ import com.navinfo.outdoor.base.BaseFragment; import com.navinfo.outdoor.bean.NameAuthenticationBean; import com.navinfo.outdoor.http.DialogCallback; import com.navinfo.outdoor.http.HttpInterface; +import com.navinfo.outdoor.util.Geohash; import com.navinfo.outdoor.util.PhotoPathUtil; +import com.navinfo.outdoor.util.PhotoUtils; import java.io.File; import java.util.ArrayList; @@ -57,6 +61,7 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic private ImageView ivHera3; private TextView tvCard3; private SharedPreferences.Editor navInfoEditor; + private File file; public static UserAttestationFragment newInstance(Bundle bundle) { @@ -111,14 +116,20 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic break; case R.id.iv_attestation1: Intent ivAttestation1 = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("a", null); + ivAttestation1.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(ivAttestation1, 100); break; case R.id.iv_attestation2: Intent ivAttestation2 = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("a", null); + ivAttestation2.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(ivAttestation2, 200); break; case R.id.iv_attestation3: Intent ivAttestation3 = new Intent("android.media.action.IMAGE_CAPTURE"); + file = PhotoUtils.showPhotoFile("a", null); + ivAttestation3.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(ivAttestation3, 300); break; case R.id.btn_attestation: @@ -247,10 +258,15 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic super.onActivityResult(requestCode, resultCode, data); if (requestCode == 100 && resultCode == RESULT_OK) { Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - String takePhotoPath1 = PhotoPathUtil.getTakePhotoPath(data, "a", ""); - ivAttestation1.setTag(takePhotoPath1); - ivAttestation1.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivAttestation1); + ivAttestation1.setTag(s); + } + file=null; ivHera1.setVisibility(View.GONE); tvCard1.setVisibility(View.GONE); // int height = bitmap.getHeight(); @@ -268,11 +284,15 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic // } } if (requestCode == 200 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - String takePhotoPath2 = PhotoPathUtil.getTakePhotoPath(data, "a", ""); - ivAttestation2.setTag(takePhotoPath2); - ivAttestation2.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivAttestation2); + ivAttestation2.setTag(s); + } + file=null; ivHera2.setVisibility(View.GONE); tvCard2.setVisibility(View.GONE); // int height = bitmap.getHeight(); @@ -290,11 +310,15 @@ public class UserAttestationFragment extends BaseFragment implements View.OnClic // } } if (requestCode == 300 && resultCode == RESULT_OK) { - Bundle extras = data.getExtras();//从Intent中获取附加值 - Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 - String takePhotoPath3 = PhotoPathUtil.getTakePhotoPath(data, "a", ""); - ivAttestation3.setTag(takePhotoPath3); - ivAttestation3.setImageBitmap(bitmap);//显示图像 + if (file == null || !file.exists()) { + Toast.makeText(getContext(), "没有拍摄照片", Toast.LENGTH_SHORT).show(); + return; + + }else { + String s = PhotoUtils.showPhotoAndGetPath(file, ivAttestation3); + ivAttestation3.setTag(s); + } + file=null; ivHera3.setVisibility(View.GONE); tvCard3.setVisibility(View.GONE); // int height = bitmap.getHeight(); diff --git a/app/src/main/java/com/navinfo/outdoor/util/PhotoUtils.java b/app/src/main/java/com/navinfo/outdoor/util/PhotoUtils.java index ed7ae9b..352bb7a 100644 --- a/app/src/main/java/com/navinfo/outdoor/util/PhotoUtils.java +++ b/app/src/main/java/com/navinfo/outdoor/util/PhotoUtils.java @@ -6,25 +6,83 @@ import android.widget.ImageView; import androidx.exifinterface.media.ExifInterface; +import com.bumptech.glide.Glide; import com.navinfo.outdoor.api.Constant; +import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import java.io.File; import java.io.IOException; +import java.util.BitSet; import static org.greenrobot.eventbus.EventBus.TAG; public class PhotoUtils { + private static int numbits = 6 * 5; + // 为了加密,所以改了base32编码代码表 + final static char[] digits = { 'd', 'f', 'g', 'y', 'n', 't', 'u', 'v', 'q', + 'b', '9', 's', 'z', '7', 'i', '2', 'h', '5', '0', 'p', '4', 'm', + '8', 'x', 'c', 'j', '6', 'e', '1', 'r', '3', 'k' }; + public static String showPhotoAndGetPath(File file, ImageView imageView) { - return null; + Glide.with(imageView.getContext()).load(file).into(imageView); + return file.getAbsolutePath(); } - public static File showPhotoFile(String d,String lat) { - long time=System.currentTimeMillis(); - File file = new File(Constant.PICTURE_FOLDER, d+time+"_p"+lat+"_a"+0+".jpg"); + + public static File showPhotoFile(String d, LatLng latLng) { + String lat=""; + if (latLng!=null){ + lat= initEncode(latLng); + } + long time = System.currentTimeMillis(); + File file = new File(Constant.PICTURE_FOLDER, d + time + "_p" + lat + "_a" + 0 + ".jpg"); return file; } + public static String initEncode(LatLng latLng) { + BitSet latbits = getBits(latLng.latitude, -90, 90); + BitSet lonbits = getBits(latLng.longitude, -180, 180); + StringBuilder buffer = new StringBuilder(); + for (int i = 0; i < numbits; i++) { + buffer.append((lonbits.get(i)) ? '1' : '0'); + buffer.append((latbits.get(i)) ? '1' : '0'); + } + return base32(Long.parseLong(buffer.toString(), 2)); + } + + private static BitSet getBits(double lat, double floor, double ceiling) { + BitSet buffer = new BitSet(numbits); + for (int i = 0; i < numbits; i++) { + double mid = (floor + ceiling) / 2; + if (lat >= mid) { + buffer.set(i); + floor = mid; + } else { + ceiling = mid; + } + } + return buffer; + } + + public static String base32(long i) { + char[] buf = new char[65]; + int charPos = 64; + boolean negative = (i < 0); + if (!negative) + i = -i; + while (i <= -32) { + buf[charPos--] = digits[(int) (-(i % 32))]; + i /= 32; + } + buf[charPos] = digits[(int) (-i)]; + + if (negative) + buf[--charPos] = '-'; + return new String(buf, charPos, (65 - charPos)); + } + /** * 获取图片旋转角度 + * * @param filepath * @return */ @@ -39,7 +97,7 @@ public class PhotoUtils { if (exif != null) { int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1); if (orientation != -1) { - switch(orientation) { + switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: degree = 90; break;