// 底部弹出的对话框 public void bottomPopUp() { final Dialog dialog = new Dialog(activity, R.style.style_dialog_bottom_pop_up); dialog.setCanceledOnTouchOutside(false); Window window = dialog.getWindow(); window.setGravity(Gravity.BOTTOM); //window.setGravity(Gravity.BOTTOM); window.getDecorView().setPadding(0, 0, 0, 0); //消除边距 WindowManager.LayoutParams lp = window.getAttributes(); lp.gravity = Gravity.BOTTOM; // 设置背景层透明度 lp.dimAmount = 0.3f; lp.width = WindowManager.LayoutParams.MATCH_PARENT; //设置宽度充满屏幕 lp.height = WindowManager.LayoutParams.WRAP_CONTENT; window.setAttributes(lp); dialog.show(); View contentView = LayoutInflater.from(activity).inflate(R.layout.dialog_bottom_pop_up, null); // 拍照 TextView mTakePhoto = (TextView) contentView.findViewById(R.id.takePhoto); mTakePhoto.setOnClickListener(new View.OnClickListener() { // 拍照 @Override public void onClick(View v) { intentCamera(); dialog.dismiss(); } }); // 选择相册 selectorPhoto(dialog, contentView); // 取消 TextView mChoose_photo_cancle = (TextView) contentView.findViewById(R.id.choose_photo_cancle); mChoose_photo_cancle.setOnClickListener(new View.OnClickListener() { // 取消 @Override public void onClick(View v) { dialog.dismiss(); } }); window.setContentView(contentView); } private void selectorPhoto(final Dialog dialog, View contentView) { TextView mChoosePhoto = (TextView) contentView.findViewById(R.id.choosePhoto); mChoosePhoto.setOnClickListener(new View.OnClickListener() { // 从相册 @Override public void onClick(View v) { PhotoPickerIntent intent = new PhotoPickerIntent(activity); intent.setPhotoCount(5); intent.setShowCamera(true); MyApp.stackInstance().getCurrentActivity().startActivityForResult(intent, REQUEST_CODE_UPLOAD_IMAGE); dialog.dismiss(); } }); } private void intentCamera() { Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //设置图片文件路径, mPhotoPath = getSDPath() + "/" + getPhotoFileName(); mPhotoFile = new File(mPhotoPath); if (!mPhotoFile.exists()) { try { mPhotoFile.createNewFile();//创建新文件 } catch (IOException e) { e.printStackTrace(); } } if (Build.VERSION.SDK_INT >= 24) { imageUri = FileProvider.getUriForFile(activity, "com.jkgj.skymonkey.doctor.ui.view.fleprovider", mPhotoFile); } else { imageUri = Uri.fromFile(mPhotoFile); } cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,//Intent有了图片的信息 imageUri); cameraIntent.putExtra(GlobalField.CAMERA_PATH, mPhotoPath); // 通知图库更新 MyApp.stackInstance().getCurrentActivity().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, imageUri)); MyApp.stackInstance().getCurrentActivity().startActivityForResult(cameraIntent, CAMERA_REQUEST); } public String getSDPath() { File sdDir = null; boolean sdCardExist = Environment.getExternalStorageState() .equals(android.os.Environment.MEDIA_MOUNTED); //判断sd卡是否存在 if (sdCardExist) { sdDir = Environment.getExternalStorageDirectory();//获取跟目录 } return sdDir.toString(); } private String getPhotoFileName() { Date date = new Date(System.currentTimeMillis()); SimpleDateFormat dateFormat = new SimpleDateFormat( "'IMG'_yyyyMMdd_HHmmss"); return dateFormat.format(date) + "jk.jpg"; }
底部弹出框拍照,从相册选取,取消 仿 ios
最新推荐文章于 2025-05-10 14:38:05 发布