fix: 充电站拍照过程优化

This commit is contained in:
XiaoYan 2021-08-06 23:10:49 +08:00
parent ec501bc6d2
commit e2cbf5fb4e

View File

@ -4,8 +4,10 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.provider.MediaStore;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -63,6 +65,8 @@ import com.navinfo.outdoor.room.PoiEntity;
import com.navinfo.outdoor.ui.view.ContactView; import com.navinfo.outdoor.ui.view.ContactView;
import com.navinfo.outdoor.util.Geohash; import com.navinfo.outdoor.util.Geohash;
import com.navinfo.outdoor.util.PhotoPathUtil; import com.navinfo.outdoor.util.PhotoPathUtil;
import com.navinfo.outdoor.util.PhotoUtils;
import com.navinfo.outdoor.util.ToastUtil;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng; import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
@ -120,6 +124,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
// private Integer chargingPileBody; // private Integer chargingPileBody;
private ArrayList<File> chargingStationList; private ArrayList<File> chargingStationList;
// private ArrayList<File> fileList; // private ArrayList<File> fileList;
private File photoFile; // 拍照保存的路径
public static ChargingStationFragment newInstance(Bundle bundle) { public static ChargingStationFragment newInstance(Bundle bundle) {
ChargingStationFragment fragment = new ChargingStationFragment(); ChargingStationFragment fragment = new ChargingStationFragment();
@ -780,22 +785,32 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
break; break;
case R.id.rl_panorama: case R.id.rl_panorama:
Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE"); Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE");
photoFile = PhotoUtils.showPhotoFile("a", Geohash.getInstance().encode(latLng.latitude, latLng.longitude));
intentPanorama.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(intentPanorama, 101); startActivityForResult(intentPanorama, 101);
break; break;
case R.id.rl_name: case R.id.rl_name:
Intent intentName = new Intent("android.media.action.IMAGE_CAPTURE"); Intent intentName = new Intent("android.media.action.IMAGE_CAPTURE");
photoFile = PhotoUtils.showPhotoFile("b", Geohash.getInstance().encode(latLng.latitude, latLng.longitude));
intentName.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(intentName, 102); startActivityForResult(intentName, 102);
break; break;
case R.id.rl_internal_photos: case R.id.rl_internal_photos:
Intent intentInternal = new Intent("android.media.action.IMAGE_CAPTURE"); Intent intentInternal = new Intent("android.media.action.IMAGE_CAPTURE");
photoFile = PhotoUtils.showPhotoFile("c", Geohash.getInstance().encode(latLng.latitude, latLng.longitude));
intentInternal.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(intentInternal, 103); startActivityForResult(intentInternal, 103);
break; break;
case R.id.rl_else: case R.id.rl_else:
Intent intentElse = new Intent("android.media.action.IMAGE_CAPTURE"); Intent intentElse = new Intent("android.media.action.IMAGE_CAPTURE");
photoFile = PhotoUtils.showPhotoFile("d", Geohash.getInstance().encode(latLng.latitude, latLng.longitude));
intentElse.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(intentElse, 104); startActivityForResult(intentElse, 104);
break; break;
case R.id.rl_scutcheon: case R.id.rl_scutcheon:
Intent intentScutcheon = new Intent("android.media.action.IMAGE_CAPTURE"); Intent intentScutcheon = new Intent("android.media.action.IMAGE_CAPTURE");
photoFile = PhotoUtils.showPhotoFile("e", Geohash.getInstance().encode(latLng.latitude, latLng.longitude));
intentScutcheon.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(intentScutcheon, 105); startActivityForResult(intentScutcheon, 105);
break; break;
case R.id.linear_charging_pile: case R.id.linear_charging_pile:
@ -1116,11 +1131,13 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 101 && resultCode == RESULT_OK) { if (requestCode == 101 && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();//从Intent中获取附加值 if (photoFile == null || !photoFile.exists()) {
Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 ToastUtil.showShort(getActivity(), "取消拍照");
String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "a", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); return;
tvPanorama.setTag(takePhotoPath); }
ivPanorama.setImageBitmap(bitmap);//显示图像 String photoPath = PhotoUtils.showPhotoAndGetPath(photoFile, ivPanorama);
tvPanorama.setTag(photoPath);
photoFile = null;
/* int height = bitmap.getHeight(); /* int height = bitmap.getHeight();
int width = bitmap.getWidth(); int width = bitmap.getWidth();
if (height > width) { if (height > width) {
@ -1137,11 +1154,13 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
}*/ }*/
} else if (requestCode == 102 && resultCode == RESULT_OK) { } else if (requestCode == 102 && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();//从Intent中获取附加值 if (photoFile == null || !photoFile.exists()) {
Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 ToastUtil.showShort(getActivity(), "取消拍照");
String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "b", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); return;
tvName.setTag(takePhotoPath); }
ivName.setImageBitmap(bitmap);//显示图像 String photoPath = PhotoUtils.showPhotoAndGetPath(photoFile, ivName);
tvName.setTag(photoPath);
photoFile = null;
/*int height = bitmap.getHeight(); /*int height = bitmap.getHeight();
int width = bitmap.getWidth(); int width = bitmap.getWidth();
if (height > width) { if (height > width) {
@ -1158,11 +1177,13 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
}*/ }*/
} else if (requestCode == 103 && resultCode == RESULT_OK) { } else if (requestCode == 103 && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();//从Intent中获取附加值 if (photoFile == null || !photoFile.exists()) {
Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 ToastUtil.showShort(getActivity(), "取消拍照");
String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "c", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); return;
tvInternal.setTag(takePhotoPath); }
ivInternal.setImageBitmap(bitmap);//显示图像 String photoPath = PhotoUtils.showPhotoAndGetPath(photoFile, ivInternal);
tvInternal.setTag(photoPath);
photoFile = null;
/*int height = bitmap.getHeight(); /*int height = bitmap.getHeight();
int width = bitmap.getWidth(); int width = bitmap.getWidth();
if (height > width) { if (height > width) {
@ -1179,11 +1200,13 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
}*/ }*/
} else if (requestCode == 104 && resultCode == RESULT_OK) { } else if (requestCode == 104 && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();//从Intent中获取附加值 if (photoFile == null || !photoFile.exists()) {
Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 ToastUtil.showShort(getActivity(), "取消拍照");
String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "d", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); return;
tvElse.setTag(takePhotoPath); }
ivElse.setImageBitmap(bitmap);//显示图像 String photoPath = PhotoUtils.showPhotoAndGetPath(photoFile, ivElse);
tvElse.setTag(photoPath);
photoFile = null;
/* int height = bitmap.getHeight(); /* int height = bitmap.getHeight();
int width = bitmap.getWidth(); int width = bitmap.getWidth();
if (height > width) { if (height > width) {
@ -1200,11 +1223,13 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
}*/ }*/
} else if (requestCode == 105 && resultCode == RESULT_OK) { } else if (requestCode == 105 && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();//从Intent中获取附加值 if (photoFile == null || !photoFile.exists()) {
Bitmap bitmap = (Bitmap) extras.get("data");//从附加值中获取返回的图像 ToastUtil.showShort(getActivity(), "取消拍照");
String takePhotoPath = PhotoPathUtil.getTakePhotoPath(data, "e", Geohash.getInstance().encode(latLng.latitude, latLng.longitude)); return;
tvScutcheon.setTag(takePhotoPath); }
ivScutcheon.setImageBitmap(bitmap);//显示图像 String photoPath = PhotoUtils.showPhotoAndGetPath(photoFile, ivScutcheon);
tvScutcheon.setTag(photoPath);
photoFile = null;
/* int height = bitmap.getHeight(); /* int height = bitmap.getHeight();
int width = bitmap.getWidth(); int width = bitmap.getWidth();
if (height > width) { if (height > width) {