public class MerchantCertifBusinessLicenseActivity extends BaseActivity {
private static final int REQUEST_PHOTO_GALLERY = 1;
private static final int REQUEST_PHOTO_TAKE = 2;
private Bitmap mBusinessLicenseBtp;
private ImageView mBusinessLicenseImageView;
private static String mBtpFileStr;
private File mBtpFile;
private Toast mToast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_merchant_certif_business_license);
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
mBusinessLicenseImageView = (ImageView) findViewById(R.id.merchant_certif_business_license_activity_take);
findViewById(R.id.merchant_certif_business_license_activity_back)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
findViewById(R.id.merchant_certif_business_license_activity_take)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
initPhotoSelectorPopwindow(v);
}
});
}
private void initPhotoSelectorPopwindow(View parent) {
View view = LayoutInflater.from(this).inflate(
R.layout.activity_merchant_cerfit_ic_card_take_photo, null);
((TextView) (view.findViewById(R.id.merchant_certif_id_card_activity_take_title)))
.setText("拍摄营业执照照片");
Display display = getWindowManager().getDefaultDisplay();
int desWidth = (int) ((display.getWidth()) * 0.9);
final PopupWindow popupWindow = new PopupWindow(view, desWidth
, ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setAnimationStyle(R.style.popwin_anim_style);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.showAtLocation(
parent, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = 1.0f;
getWindow().setAttributes(lp);
}
});
view.findViewById(R.id.merchant_certif_id_card_activity_take_cancel)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
view.findViewById(R.id.merchant_certif_id_card_activity_take_gallery)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, REQUEST_PHOTO_GALLERY);
popupWindow.dismiss();
}
});
view.findViewById(R.id.merchant_certif_id_card_activity_take_photo)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
Calendar currentDate = Calendar.getInstance();
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(currentDate.getTime());
String pathStr = Environment.getExternalStorageDirectory() + "/com.genzzhang.shupian";
File pathFile = new File(pathStr);
if(!pathFile.exists()) pathFile.mkdirs();
mBtpFile = new File(pathFile, "/IMG_" + timeStamp + ".jpg");
mBtpFileStr = mBtpFile.getAbsolutePath();
if(!mBtpFile.exists())
try {
mBtpFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mBtpFile));
startActivityForResult(intent, REQUEST_PHOTO_TAKE);
popupWindow.dismiss();
} else {
mToast.setText("未找到存储卡");
mToast.show();
return;
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK) return;
switch (requestCode) {
case REQUEST_PHOTO_GALLERY:
// mFoodServiceBtp = (Bitmap)data.getExtras().get("data");
if(data != null) {
try {
mBusinessLicenseBtp = BitmapFactory.decodeStream(
getContentResolver().openInputStream(data.getData())
);
mBusinessLicenseImageView.setImageBitmap(mBusinessLicenseBtp);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
break;
case REQUEST_PHOTO_TAKE:
File tempFile = new File(mBtpFileStr);
try {
mBusinessLicenseBtp = BitmapFactory.decodeStream(
getContentResolver().openInputStream(Uri.fromFile(tempFile))
);
mBusinessLicenseImageView.setImageBitmap(mBusinessLicenseBtp);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
break;
default:
break;
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if(mBusinessLicenseBtp != null && !mBusinessLicenseBtp.isRecycled())
mBusinessLicenseBtp.recycle();
}
}