Java源码示例:com.luck.picture.lib.config.PictureMimeType
示例1
@OnClick({R.id.vid_aqi_select_btn, R.id.vid_aqi_tv})
@Override
public void onClick(View v) {
super.onClick(v);
switch (v.getId()) {
case R.id.vid_aqi_select_btn:
// 初始化图片配置
PictureSelectorUtils.PicConfig picConfig = new PictureSelectorUtils.PicConfig()
.setCompress(false).setMaxSelectNum(1).setCrop(false).setMimeType(PictureMimeType.ofImage())
.setCamera(true).setGif(false);
// 打开图片选择器
PictureSelectorUtils.openGallery(PictureSelector.create(this), picConfig);
break;
case R.id.vid_aqi_tv:
String text = TextViewUtils.getText(vid_aqi_tv);
if (TextUtils.isEmpty(text)) return;
// 复制到剪切板
ClipboardUtils.copyText(text);
// 进行提示
ToastTintUtils.success(ResourceUtils.getString(R.string.copy_suc) + " -> " + text);
break;
}
}
示例2
/**
* 拍摄视频
*/
private void openVideo() {
int quality = this.cameraOptions.getInt("quality");
int MaxSecond = this.cameraOptions.getInt("MaxSecond");
int MinSecond = this.cameraOptions.getInt("MinSecond");
int recordVideoSecond = this.cameraOptions.getInt("recordVideoSecond");
int imageCount = this.cameraOptions.getInt("imageCount");
Activity currentActivity = getCurrentActivity();
PictureSelector.create(currentActivity)
.openCamera(PictureMimeType.ofVideo())//全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
.loadImageEngine(GlideEngine.createGlideEngine())
.selectionMedia(selectList) // 当前已选中的图片 List
.openClickSound(false)// 是否开启点击声音 true or false
.maxSelectNum(imageCount)// 最大图片选择数量 int
.minSelectNum(0)// 最小选择数量 int
.imageSpanCount(4)// 每行显示个数 int
.selectionMode(PictureConfig.MULTIPLE)// 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE
.previewVideo(true)// 是否可预览视频 true or false
.videoQuality(quality)// 视频录制质量 0 or 1 int
.videoMaxSecond(MaxSecond)// 显示多少秒以内的视频or音频也可适用 int
.videoMinSecond(MinSecond)// 显示多少秒以内的视频or音频也可适用 int
.recordVideoSecond(recordVideoSecond)//视频秒数录制 默认60s int
.forResult(PictureConfig.REQUEST_CAMERA);//结果回调onActivityResult code
}
示例3
/**
* 加载图片
*
* @param context
* @param url
* @param imageView
*/
@Override
public void loadImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
VideoRequestHandler videoRequestHandler = new VideoRequestHandler();
if (PictureMimeType.isContent(url)) {
Picasso.get()
.load(Uri.parse(url))
.into(imageView);
} else {
if (PictureMimeType.isUrlHasVideo(url)) {
Picasso picasso = new Picasso.Builder(context.getApplicationContext())
.addRequestHandler(videoRequestHandler)
.build();
picasso.load(videoRequestHandler.SCHEME_VIDEO + ":" + url)
.into(imageView);
} else {
Picasso.get()
.load(new File(url))
.into(imageView);
}
}
}
示例4
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case PictureConfig.APPLY_STORAGE_PERMISSIONS_CODE:
// 存储权限
for (int i = 0; i < grantResults.length; i++) {
if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
PictureFileUtils.deleteCacheDirFile(getContext(), PictureMimeType.ofImage());
} else {
Toast.makeText(getContext(),
getString(R.string.picture_jurisdiction), Toast.LENGTH_SHORT).show();
}
}
break;
}
}
示例5
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case PictureConfig.APPLY_STORAGE_PERMISSIONS_CODE:
// 存储权限
for (int i = 0; i < grantResults.length; i++) {
if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
PictureFileUtils.deleteCacheDirFile(getContext(), PictureMimeType.ofImage());
} else {
Toast.makeText(MainActivity.this,
getString(R.string.picture_jurisdiction), Toast.LENGTH_SHORT).show();
}
}
break;
}
}
示例6
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case PictureConfig.APPLY_STORAGE_PERMISSIONS_CODE:
// 存储权限
for (int i = 0; i < grantResults.length; i++) {
if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
PictureFileUtils.deleteCacheDirFile(PhotoFragmentActivity.this, PictureMimeType.ofImage());
} else {
Toast.makeText(PhotoFragmentActivity.this,
getString(R.string.picture_jurisdiction), Toast.LENGTH_SHORT).show();
}
}
break;
}
}
示例7
/**
* 保存相片至本地相册
*
* @throws Exception
*/
private void savePictureAlbum() throws Exception {
String suffix = PictureMimeType.getLastImgSuffix(mMimeType);
String state = Environment.getExternalStorageState();
File rootDir = state.equals(Environment.MEDIA_MOUNTED)
? Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
: getContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
if (rootDir != null && !rootDir.exists() && rootDir.mkdirs()) {
}
File folderDir = new File(SdkVersionUtils.checkedAndroid_Q() || !state.equals(Environment.MEDIA_MOUNTED)
? rootDir.getAbsolutePath() : rootDir.getAbsolutePath() + File.separator + PictureMimeType.CAMERA + File.separator);
if (folderDir != null && !folderDir.exists() && folderDir.mkdirs()) {
}
String fileName = DateUtils.getCreateFileName("IMG_") + suffix;
File file = new File(folderDir, fileName);
PictureFileUtils.copyFile(downloadPath, file.getAbsolutePath());
onSuccessful(file.getAbsolutePath());
}
示例8
/**
* single crop
*
* @param originalPath
* @param cachePath
* @param mimeType
* @param options
*/
private void startSingleCropActivity(String originalPath, String cachePath, String mimeType, UCrop.Options options) {
boolean isHttp = PictureMimeType.isHasHttp(originalPath);
String suffix = mimeType.replace("image/", ".");
File file = new File(PictureFileUtils.getDiskCacheDir(getContext()),
TextUtils.isEmpty(config.renameCropFileName) ? DateUtils.getCreateFileName("IMG_CROP_") + suffix : config.renameCropFileName);
Uri uri;
if (!TextUtils.isEmpty(cachePath)) {
uri = Uri.fromFile(new File(cachePath));
} else {
uri = isHttp || SdkVersionUtils.checkedAndroid_Q() ? Uri.parse(originalPath) : Uri.fromFile(new File(originalPath));
}
UCrop.of(uri, Uri.fromFile(file))
.withOptions(options)
.startAnimationActivity(this, config.windowAnimationStyle != null
? config.windowAnimationStyle.activityCropEnterAnimation : R.anim.picture_anim_enter);
}
示例9
/**
* startMultipleCropActivity
*
* @param cutInfo
* @param options
*/
private void startMultipleCropActivity(CutInfo cutInfo, int count, UCrop.Options options) {
String path = cutInfo.getPath();
String mimeType = cutInfo.getMimeType();
boolean isHttp = PictureMimeType.isHasHttp(path);
Uri uri;
if (!TextUtils.isEmpty(cutInfo.getAndroidQToPath())) {
uri = Uri.fromFile(new File(cutInfo.getAndroidQToPath()));
} else {
uri = isHttp || SdkVersionUtils.checkedAndroid_Q() ? Uri.parse(path) : Uri.fromFile(new File(path));
}
String suffix = mimeType.replace("image/", ".");
File file = new File(PictureFileUtils.getDiskCacheDir(this),
TextUtils.isEmpty(config.renameCropFileName) ? DateUtils.getCreateFileName("IMG_CROP_")
+ suffix : config.camera || count == 1 ? config.renameCropFileName : StringUtils.rename(config.renameCropFileName));
UCrop.of(uri, Uri.fromFile(file))
.withOptions(options)
.startAnimationMultipleCropActivity(this, config.windowAnimationStyle != null
? config.windowAnimationStyle.activityCropEnterAnimation : R.anim.picture_anim_enter);
}
示例10
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
LocalMedia item = getItem(position);
if (item != null) {
holder.viewBorder.setVisibility(item.isChecked() ? View.VISIBLE : View.GONE);
if (config != null && PictureSelectionConfig.imageEngine != null) {
PictureSelectionConfig.imageEngine.loadImage(holder.itemView.getContext(), item.getPath(), holder.ivImage);
}
holder.ivPlay.setVisibility(PictureMimeType.isHasVideo(item.getMimeType()) ? View.VISIBLE : View.GONE);
holder.itemView.setOnClickListener(v -> {
if (listener != null && holder.getAdapterPosition() >= 0) {
listener.onItemClick(holder.getAdapterPosition(), getItem(position), v);
}
});
}
}
示例11
/**
* isSame
*
* @param newMedia
* @return
*/
private boolean isLocalMediaSame(LocalMedia newMedia) {
LocalMedia oldMedia = mAdapter.getItem(0);
if (oldMedia == null || newMedia == null) {
return false;
}
if (oldMedia.getPath().equals(newMedia.getPath())) {
return true;
}
// if Content:// type,determines whether the suffix id is consistent, mainly to solve the following two types of problems
// content://media/external/images/media/5844
// content://media/external/file/5844
if (PictureMimeType.isContent(newMedia.getPath())
&& PictureMimeType.isContent(oldMedia.getPath())) {
if (!TextUtils.isEmpty(newMedia.getPath()) && !TextUtils.isEmpty(oldMedia.getPath())) {
String newId = newMedia.getPath().substring(newMedia.getPath().lastIndexOf("/") + 1);
String oldId = oldMedia.getPath().substring(oldMedia.getPath().lastIndexOf("/") + 1);
if (newId.equals(oldId)) {
return true;
}
}
}
return false;
}
示例12
@Override
public void onPictureClick(LocalMedia media, int position) {
if (config.selectionMode == PictureConfig.SINGLE && config.isSingleDirectReturn) {
List<LocalMedia> list = new ArrayList<>();
list.add(media);
if (config.enableCrop && PictureMimeType.isHasImage(media.getMimeType()) && !config.isCheckOriginalImage) {
mAdapter.bindSelectData(list);
startCrop(media.getPath(), media.getMimeType());
} else {
handlerResult(list);
}
} else {
List<LocalMedia> data = mAdapter.getData();
startPreview(data, position);
}
}
示例13
/**
* Verify the validity of the video
*
* @param media
* @return
*/
private boolean checkVideoLegitimacy(LocalMedia media) {
boolean isEnterNext = true;
if (PictureMimeType.isHasVideo(media.getMimeType())) {
if (config.videoMinSecond > 0 && config.videoMaxSecond > 0) {
// The user sets the minimum and maximum video length to determine whether the video is within the interval
if (media.getDuration() < config.videoMinSecond || media.getDuration() > config.videoMaxSecond) {
isEnterNext = false;
showPromptDialog(getString(R.string.picture_choose_limit_seconds, config.videoMinSecond / 1000, config.videoMaxSecond / 1000));
}
} else if (config.videoMinSecond > 0) {
// The user has only set a minimum video length limit
if (media.getDuration() < config.videoMinSecond) {
isEnterNext = false;
showPromptDialog(getString(R.string.picture_choose_min_seconds, config.videoMinSecond / 1000));
}
} else if (config.videoMaxSecond > 0) {
// Only the maximum length of video is set
if (media.getDuration() > config.videoMaxSecond) {
isEnterNext = false;
showPromptDialog(getString(R.string.picture_choose_max_seconds, config.videoMaxSecond / 1000));
}
}
}
return isEnterNext;
}
示例14
@Override
public void onItemClick(View view, int position) {
switch (position) {
case PhotoItemSelectedDialog.IMAGE_CAMERA:
if (PictureSelectionConfig.onCustomCameraInterfaceListener != null) {
PictureSelectionConfig.onCustomCameraInterfaceListener.onCameraClick(getContext(), config, PictureConfig.TYPE_IMAGE);
config.cameraMimeType = PictureMimeType.ofImage();
} else {
startOpenCamera();
}
break;
case PhotoItemSelectedDialog.VIDEO_CAMERA:
if (PictureSelectionConfig.onCustomCameraInterfaceListener != null) {
PictureSelectionConfig.onCustomCameraInterfaceListener.onCameraClick(getContext(), config, PictureConfig.TYPE_IMAGE);
config.cameraMimeType = PictureMimeType.ofVideo();
} else {
startOpenCameraVideo();
}
break;
default:
break;
}
}
示例15
/**
* 创建一条图片地址uri,用于保存拍照后的照片
*
* @param context
* @param suffixType
* @return 图片的uri
*/
@Nullable
public static Uri createImageUri(final Context context, String suffixType) {
final Uri[] imageFilePath = {null};
String status = Environment.getExternalStorageState();
String time = ValueOf.toString(System.currentTimeMillis());
// ContentValues是我们希望这条记录被创建时包含的数据信息
ContentValues values = new ContentValues(3);
values.put(MediaStore.Images.Media.DISPLAY_NAME, DateUtils.getCreateFileName("IMG_"));
values.put(MediaStore.Images.Media.DATE_TAKEN, time);
values.put(MediaStore.Images.Media.MIME_TYPE, TextUtils.isEmpty(suffixType) ? PictureMimeType.MIME_TYPE_IMAGE : suffixType);
// 判断是否有SD卡,优先使用SD卡存储,当没有SD卡时使用手机存储
if (status.equals(Environment.MEDIA_MOUNTED)) {
values.put(MediaStore.Images.Media.RELATIVE_PATH, PictureMimeType.DCIM);
imageFilePath[0] = context.getContentResolver()
.insert(MediaStore.Images.Media.getContentUri("external"), values);
} else {
imageFilePath[0] = context.getContentResolver()
.insert(MediaStore.Images.Media.getContentUri("internal"), values);
}
return imageFilePath[0];
}
示例16
/**
* 创建一条视频地址uri,用于保存录制的视频
*
* @param context
* @param suffixType
* @return 视频的uri
*/
@Nullable
public static Uri createVideoUri(final Context context, String suffixType) {
final Uri[] imageFilePath = {null};
String status = Environment.getExternalStorageState();
String time = ValueOf.toString(System.currentTimeMillis());
// ContentValues是我们希望这条记录被创建时包含的数据信息
ContentValues values = new ContentValues(3);
values.put(MediaStore.Video.Media.DISPLAY_NAME, DateUtils.getCreateFileName("VID_"));
values.put(MediaStore.Video.Media.DATE_TAKEN, time);
values.put(MediaStore.Video.Media.MIME_TYPE, TextUtils.isEmpty(suffixType) ? PictureMimeType.MIME_TYPE_VIDEO : suffixType);
// 判断是否有SD卡,优先使用SD卡存储,当没有SD卡时使用手机存储
if (status.equals(Environment.MEDIA_MOUNTED)) {
values.put(MediaStore.Video.Media.RELATIVE_PATH, Environment.DIRECTORY_MOVIES);
imageFilePath[0] = context.getContentResolver()
.insert(MediaStore.Video.Media.getContentUri("external"), values);
} else {
imageFilePath[0] = context.getContentResolver()
.insert(MediaStore.Video.Media.getContentUri("internal"), values);
}
return imageFilePath[0];
}
示例17
@OnClick({R.id.vid_agf_select_btn})
@Override
public void onClick(View v) {
super.onClick(v);
switch (v.getId()) {
case R.id.vid_agf_select_btn:
// 初始化图片配置
PictureSelectorUtils.PicConfig picConfig = new PictureSelectorUtils.PicConfig()
.setCompress(false).setMaxSelectNum(1).setCrop(false).setMimeType(PictureMimeType.ofImage())
.setCamera(true).setGif(false);
// 打开图片选择器
PictureSelectorUtils.openGallery(PictureSelector.create(this), picConfig);
break;
}
}
示例18
@OnClick({R.id.vid_aarc_select_btn})
@Override
public void onClick(View v) {
super.onClick(v);
switch (v.getId()) {
case R.id.vid_aarc_select_btn:
AppUtils.startActivityForResult(new ActivityUtils.ResultCallback() {
@Override
public boolean onStartActivityForResult(Activity activity) {
// 初始化图片配置
PictureSelectorUtils.PicConfig picConfig = new PictureSelectorUtils.PicConfig()
.setCompress(false).setMaxSelectNum(1).setCrop(false).setMimeType(PictureMimeType.ofImage())
.setCamera(true).setGif(false);
// 打开图片选择器
PictureSelectorUtils.openGallery(PictureSelector.create(activity), picConfig);
return true;
}
@Override
public void onActivityResult(boolean result, int resultCode, Intent data) {
if (result && data != null) {
LocalMedia localMedia = PictureSelectorUtils.getSingleMedia(data);
// 获取图片地址
String imgPath = PictureSelectorUtils.getLocalMediaPath(localMedia, true);
// 提示
ToastTintUtils.success("选择了图片: " + imgPath);
} else {
showToast(false, "非成功操作");
}
}
});
break;
}
}
示例19
@OnClick({R.id.vid_ass_flashlight_igview, R.id.vid_ass_square_igview,
R.id.vid_ass_hexagon_igview, R.id.vid_ass_annulus_igview, R.id.vid_ass_image_igview})
@Override
public void onClick(View v) {
super.onClick(v);
switch (v.getId()) {
case R.id.vid_ass_flashlight_igview:
if (!FlashlightUtils.isFlashlightEnable()) {
showToast(false, "暂不支持开启手电筒");
return;
}
// 设置开关
setFlashlight(!ViewUtils.isSelected(vid_ass_flashlight_igview));
break;
case R.id.vid_ass_square_igview:
ProjectUtils.refShape(vid_ass_scanview, ScanShapeView.Shape.Square);
break;
case R.id.vid_ass_hexagon_igview:
ProjectUtils.refShape(vid_ass_scanview, ScanShapeView.Shape.Hexagon);
break;
case R.id.vid_ass_annulus_igview:
ProjectUtils.refShape(vid_ass_scanview, ScanShapeView.Shape.Annulus);
break;
case R.id.vid_ass_image_igview:
// 初始化图片配置
PictureSelectorUtils.PicConfig picConfig = new PictureSelectorUtils.PicConfig()
.setCompress(false).setMaxSelectNum(1).setCrop(false).setMimeType(PictureMimeType.ofImage())
.setCamera(true).setGif(false);
// 打开图片选择器
PictureSelectorUtils.openGallery(PictureSelector.create(this), picConfig);
break;
}
}
示例20
@OnClick({R.id.vid_agf_select_btn})
@Override
public void onClick(View v) {
super.onClick(v);
switch (v.getId()) {
case R.id.vid_agf_select_btn:
// 初始化图片配置
PictureSelectorUtils.PicConfig picConfig = new PictureSelectorUtils.PicConfig()
.setCompress(false).setMaxSelectNum(1).setCrop(false).setMimeType(PictureMimeType.ofImage())
.setCamera(true).setGif(false);
// 打开图片选择器
PictureSelectorUtils.openGallery(PictureSelector.create(this), picConfig);
break;
}
}
示例21
/**
* 打开相机
*/
private void openCamera() {
boolean isCrop = this.cameraOptions.getBoolean("isCrop");
int CropW = this.cameraOptions.getInt("CropW");
int CropH = this.cameraOptions.getInt("CropH");
boolean showCropCircle = this.cameraOptions.getBoolean("showCropCircle");
boolean showCropFrame = this.cameraOptions.getBoolean("showCropFrame");
boolean showCropGrid = this.cameraOptions.getBoolean("showCropGrid");
boolean compress = this.cameraOptions.getBoolean("compress");
boolean freeStyleCropEnabled = this.cameraOptions.getBoolean("freeStyleCropEnabled");
boolean rotateEnabled = this.cameraOptions.getBoolean("rotateEnabled");
boolean scaleEnabled = this.cameraOptions.getBoolean("scaleEnabled");
int minimumCompressSize = this.cameraOptions.getInt("minimumCompressSize");
int quality = this.cameraOptions.getInt("quality");
Boolean isAndroidQ = SdkVersionUtils.checkedAndroid_Q();
Activity currentActivity = getCurrentActivity();
PictureSelector.create(currentActivity)
.openCamera(PictureMimeType.ofImage())
.loadImageEngine(GlideEngine.createGlideEngine())
.imageFormat(isAndroidQ ? PictureMimeType.PNG_Q : PictureMimeType.PNG)// 拍照保存图片格式后缀,默认jpeg
.enableCrop(isCrop)// 是否裁剪 true or false
.compress(compress)// 是否压缩 true or false
.glideOverride(160, 160)// int glide 加载宽高,越小图片列表越流畅,但会影响列表图片浏览的清晰度
.withAspectRatio(CropW, CropH)// int 裁剪比例 如16:9 3:2 3:4 1:1 可自定义
.hideBottomControls(isCrop)// 是否显示uCrop工具栏,默认不显示 true or false
.freeStyleCropEnabled(freeStyleCropEnabled)// 裁剪框是否可拖拽 true or false
.circleDimmedLayer(showCropCircle)// 是否圆形裁剪 true or false
.showCropFrame(showCropFrame)// 是否显示裁剪矩形边框 圆形裁剪时建议设为false true or false
.showCropGrid(showCropGrid)// 是否显示裁剪矩形网格 圆形裁剪时建议设为false true or false
.openClickSound(false)// 是否开启点击声音 true or false
.cropCompressQuality(quality)// 裁剪压缩质量 默认90 int
.minimumCompressSize(minimumCompressSize)// 小于100kb的图片不压缩
.synOrAsy(true)//同步true或异步false 压缩 默认同步
.rotateEnabled(rotateEnabled) // 裁剪是否可旋转图片 true or false
.scaleEnabled(scaleEnabled)// 裁剪是否可放大缩小图片 true or false
.forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code
}
示例22
/**
* 选择视频
*/
private void openVideoPicker() {
int quality = this.cameraOptions.getInt("quality");
int MaxSecond = this.cameraOptions.getInt("MaxSecond");
int MinSecond = this.cameraOptions.getInt("MinSecond");
int recordVideoSecond = this.cameraOptions.getInt("recordVideoSecond");
int videoCount = this.cameraOptions.getInt("imageCount");
boolean isCamera = this.cameraOptions.getBoolean("allowTakeVideo");
Activity currentActivity = getCurrentActivity();
PictureSelector.create(currentActivity)
.openGallery(PictureMimeType.ofVideo())//全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
.loadImageEngine(GlideEngine.createGlideEngine())
.selectionMedia(selectList) // 当前已选中的视频 List
.openClickSound(false)// 是否开启点击声音 true or false
.isCamera(isCamera)// 是否显示拍照按钮 true or false
.maxSelectNum(videoCount)// 最大视频选择数量 int
.minSelectNum(1)// 最小选择数量 int
.imageSpanCount(4)// 每行显示个数 int
.selectionMode(PictureConfig.MULTIPLE)// 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE
.previewVideo(true)// 是否可预览视频 true or false
.videoQuality(quality)// 视频录制质量 0 or 1 int
.videoMaxSecond(MaxSecond)// 显示多少秒以内的视频or音频也可适用 int
.videoMinSecond(MinSecond)// 显示多少秒以内的视频or音频也可适用 int
.recordVideoSecond(recordVideoSecond)//视频秒数录制 默认60s int
.forResult(PictureConfig.REQUEST_CAMERA);//结果回调onActivityResult code
}
示例23
/**
* 加载相册目录
*
* @param context 上下文
* @param url 图片路径
* @param imageView 承载图片ImageView
*/
@Override
public void loadFolderImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
VideoRequestHandler videoRequestHandler = new VideoRequestHandler();
if (PictureMimeType.isContent(url)) {
Picasso.get()
.load(Uri.parse(url))
.resize(180, 180)
.centerCrop()
.placeholder(R.drawable.picture_image_placeholder)
.into(imageView);
} else {
if (PictureMimeType.isUrlHasVideo(url)) {
Picasso picasso = new Picasso.Builder(context.getApplicationContext())
.addRequestHandler(videoRequestHandler)
.build();
picasso.load(videoRequestHandler.SCHEME_VIDEO + ":" + url)
.resize(180, 180)
.centerCrop()
.placeholder(R.drawable.picture_image_placeholder)
.into(imageView);
} else {
Picasso.get()
.load(new File(url))
.resize(180, 180)
.centerCrop()
.placeholder(R.drawable.picture_image_placeholder)
.into(imageView);
}
}
}
示例24
/**
* 加载gif
*
* @param context 上下文
* @param url 图片路径
* @param imageView 承载图片ImageView
*/
@Override
public void loadAsGifImage(@NonNull Context context, @NonNull String url,
@NonNull ImageView imageView) {
if (PictureMimeType.isContent(url)) {
Picasso.get()
.load(Uri.parse(url))
.into(imageView);
} else {
Picasso.get()
.load(new File(url))
.into(imageView);
}
}
示例25
/**
* 加载图片列表图片
*
* @param context 上下文
* @param url 图片路径
* @param imageView 承载图片ImageView
*/
@Override
public void loadGridImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
VideoRequestHandler videoRequestHandler = new VideoRequestHandler();
if (PictureMimeType.isContent(url)) {
Picasso.get()
.load(Uri.parse(url))
.resize(200, 200)
.centerCrop()
.placeholder(R.drawable.picture_image_placeholder)
.into(imageView);
} else {
if (PictureMimeType.isUrlHasVideo(url)) {
Picasso picasso = new Picasso.Builder(context.getApplicationContext())
.addRequestHandler(videoRequestHandler)
.build();
picasso.load(videoRequestHandler.SCHEME_VIDEO + ":" + url)
.resize(200, 200)
.centerCrop()
.placeholder(R.drawable.picture_image_placeholder)
.into(imageView);
} else {
Picasso.get()
.load(new File(url))
.resize(200, 200)
.centerCrop()
.placeholder(R.drawable.picture_image_placeholder)
.into(imageView);
}
}
}
示例26
/**
* 针对Q版本创建uri
*
* @return
*/
private Uri createOutImageUri() {
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.Images.Media.DISPLAY_NAME, DateUtils.getCreateFileName("IMG_"));
contentValues.put(MediaStore.Images.Media.DATE_TAKEN, ValueOf.toString(System.currentTimeMillis()));
contentValues.put(MediaStore.Images.Media.MIME_TYPE, mMimeType);
contentValues.put(MediaStore.Images.Media.RELATIVE_PATH, PictureMimeType.DCIM);
return getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
}
示例27
private List<File> get(Context context) throws IOException {
List<File> results = new ArrayList<>();
Iterator<InputStreamProvider> iterator = mStreamProviders.iterator();
while (iterator.hasNext()) {
InputStreamProvider provider = iterator.next();
InputStream inputStream = provider.open();
if (inputStream != null) {
if (provider.getMedia().isCompressed()
&& !TextUtils.isEmpty(provider.getMedia().getCompressPath())) {
// 压缩过的图片不重复压缩 注意:如果是开启了裁剪 就算压缩过也要重新压缩
boolean exists = !provider.getMedia().isCut() && new File(provider.getMedia().getCompressPath()).exists();
File oldFile = exists ? new File(provider.getMedia().getCompressPath())
: compress(context, provider);
results.add(oldFile);
} else {
boolean hasVideo = PictureMimeType.isHasVideo(provider.getMedia().getMimeType());
results.add(hasVideo ? new File(provider.getMedia().getPath()) : compress(context, provider));
}
} else {
// error
results.add(new File(provider.getMedia().getPath()));
}
iterator.remove();
}
return results;
}
示例28
/**
* 扩展符合PictureSelector的压缩策略
*
* @param media LocalMedia对象
* @param <T>
* @return
*/
private Builder load(final LocalMedia media) {
mStreamProviders.add(new InputStreamAdapter() {
@Override
public InputStream openInternal() throws IOException {
if (PictureMimeType.isContent(media.getPath()) && !media.isCut()) {
if (!TextUtils.isEmpty(media.getAndroidQToPath())) {
return new FileInputStream(media.getAndroidQToPath());
}
return context.getContentResolver().openInputStream(Uri.parse(media.getPath()));
} else {
return PictureMimeType.isHasHttp(media.getPath()) ? null : new FileInputStream(media.isCut() ? media.getCutPath() : media.getPath());
}
}
@Override
public String getPath() {
if (media.isCut()) {
return media.getCutPath();
} else {
return TextUtils.isEmpty(media.getAndroidQToPath()) ? media.getPath() : media.getAndroidQToPath();
}
}
@Override
public LocalMedia getMedia() {
return media;
}
});
return this;
}
示例29
@Override
public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
if (mConfigReference.get() != null) {
if (SdkVersionUtils.checkedAndroid_Q() && PictureMimeType.isContent(mConfigReference.get().cameraPath)) {
PictureThreadUtils.executeByIo(new PictureThreadUtils.SimpleTask<Boolean>() {
@Override
public Boolean doInBackground() {
return AndroidQTransformUtils.copyPathToDCIM(mContextReference.get(),
mFileReference.get(), Uri.parse(mConfigReference.get().cameraPath));
}
@Override
public void onSuccess(Boolean result) {
PictureThreadUtils.cancel(PictureThreadUtils.getIoPool());
}
});
}
}
if (mImageCallbackListenerReference.get() != null
&& mFileReference.get() != null
&& mImagePreviewReference.get() != null) {
mImageCallbackListenerReference.get().onLoadImage(mFileReference.get(), mImagePreviewReference.get());
}
if (mImagePreviewReference.get() != null) {
mImagePreviewReference.get().setVisibility(View.VISIBLE);
}
if (mCaptureLayoutReference.get() != null) {
mCaptureLayoutReference.get().startTypeBtnAnimator();
}
}
示例30
/**
* 重置状态
*/
private void resetState() {
if (mCameraView.getCaptureMode() == androidx.camera.view.CameraView.CaptureMode.VIDEO) {
if (mCameraView.isRecording()) {
mCameraView.stopRecording();
}
if (mVideoFile != null && mVideoFile.exists()) {
mVideoFile.delete();
if (SdkVersionUtils.checkedAndroid_Q() && PictureMimeType.isContent(mConfig.cameraPath)) {
getContext().getContentResolver().delete(Uri.parse(mConfig.cameraPath), null, null);
} else {
new PictureMediaScannerConnection(getContext(), mVideoFile.getAbsolutePath());
}
}
} else {
mImagePreview.setVisibility(INVISIBLE);
if (mPhotoFile != null && mPhotoFile.exists()) {
mPhotoFile.delete();
if (SdkVersionUtils.checkedAndroid_Q() && PictureMimeType.isContent(mConfig.cameraPath)) {
getContext().getContentResolver().delete(Uri.parse(mConfig.cameraPath), null, null);
} else {
new PictureMediaScannerConnection(getContext(), mPhotoFile.getAbsolutePath());
}
}
}
mSwitchCamera.setVisibility(VISIBLE);
mFlashLamp.setVisibility(VISIBLE);
mCameraView.setVisibility(View.VISIBLE);
mCaptureLayout.resetCaptureLayout();
}