com.luck.picture.lib.entity.LocalMedia Java Examples
The following examples show how to use
com.luck.picture.lib.entity.LocalMedia.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Luban.java From PictureSelector with Apache License 2.0 | 6 votes |
@Override public boolean handleMessage(Message msg) { if (mCompressListener == null) return false; switch (msg.what) { case MSG_COMPRESS_START: mCompressListener.onStart(); break; case MSG_COMPRESS_SUCCESS: mCompressListener.onSuccess((List<LocalMedia>) msg.obj); break; case MSG_COMPRESS_ERROR: mCompressListener.onError((Throwable) msg.obj); break; } return false; }
Example #2
Source File: PictureSelector.java From PictureSelector with Apache License 2.0 | 6 votes |
/** * set preview image * * @param position * @param medias */ public void externalPicturePreview(int position, List<LocalMedia> medias, int enterAnimation) { if (!DoubleUtils.isFastDoubleClick()) { if (getActivity() != null) { Intent intent = new Intent(getActivity(), PictureExternalPreviewActivity.class); intent.putParcelableArrayListExtra(PictureConfig.EXTRA_PREVIEW_SELECT_LIST, (ArrayList<? extends Parcelable>) medias); intent.putExtra(PictureConfig.EXTRA_POSITION, position); getActivity().startActivity(intent); getActivity().overridePendingTransition(enterAnimation != 0 ? enterAnimation : R.anim.picture_anim_enter, R.anim.picture_anim_fade_in); } else { throw new NullPointerException("Starting the PictureSelector Activity cannot be empty "); } } }
Example #3
Source File: PictureSelectorActivity.java From PictureSelector with Apache License 2.0 | 6 votes |
/** * 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; }
Example #4
Source File: ImagePickerHelper.java From FastLib with Apache License 2.0 | 6 votes |
public void onActivityResult(int requestCode, int resultCode, Intent data) { LoggerManager.i("onActivityResult", "path:"); if (resultCode == Activity.RESULT_OK) { if (requestCode != mRequestCode) return; // 图片、视频、音频选择结果回调 List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data); // 例如 LocalMedia 里面返回三种path // 1.media.getPath(); 为原图path // 2.media.getCutPath();为裁剪后path,需判断media.isCut();是否为true 注意:音视频除外 // 3.media.getCompressPath();为压缩后path,需判断media.isCompressed();是否为true 注意:音视频除外 // 如果裁剪并压缩了,以取压缩路径为准,因为是先裁剪后压缩的 List<String> list = new ArrayList<>(); for (LocalMedia item : selectList) { list.add(item.getPath()); LoggerManager.i("onActivityResult", "path:" + item.getPath()); } if (mOnImageSelect != null) { mOnImageSelect.onImageSelect(mRequestCode, list); } } }
Example #5
Source File: PicturePreviewActivity.java From PictureSelector with Apache License 2.0 | 6 votes |
/** * 加载更多 */ private void loadMoreData() { long bucketId = getIntent().getLongExtra(PictureConfig.EXTRA_BUCKET_ID, -1); mPage++; LocalMediaPageLoader.getInstance(getContext(), config).loadPageMediaData(bucketId, mPage, config.pageSize, (OnQueryDataResultListener<LocalMedia>) (result, currentPage, isHasMore) -> { if (!isFinishing()) { this.isHasMore = isHasMore; if (isHasMore) { int size = result.size(); if (size > 0 && adapter != null) { adapter.getData().addAll(result); adapter.notifyDataSetChanged(); } else { // 这种情况就是开启过滤损坏文件刚好导致某一页全是损坏的虽然result为0,但还要请求下一页数据 loadMoreData(); } } } }); }
Example #6
Source File: PictureVideoPlayActivity.java From PictureSelector with Apache License 2.0 | 6 votes |
@Override public void onClick(View v) { int id = v.getId(); if (id == R.id.pictureLeftBack) { onBackPressed(); } else if (id == R.id.iv_play) { mVideoView.start(); iv_play.setVisibility(View.INVISIBLE); } else if (id == R.id.tv_confirm) { List<LocalMedia> result = new ArrayList<>(); result.add(getIntent().getParcelableExtra(PictureConfig.EXTRA_MEDIA_KEY)); setResult(RESULT_OK, new Intent() .putParcelableArrayListExtra(PictureConfig.EXTRA_SELECT_LIST, (ArrayList<? extends Parcelable>) result)); onBackPressed(); } }
Example #7
Source File: PicturePreviewActivity.java From PictureSelector with Apache License 2.0 | 6 votes |
/** * 从本地获取数据 */ private void loadData() { long bucketId = getIntent().getLongExtra(PictureConfig.EXTRA_BUCKET_ID, -1); mPage++; LocalMediaPageLoader.getInstance(getContext(), config).loadPageMediaData(bucketId, mPage, config.pageSize, (OnQueryDataResultListener<LocalMedia>) (result, currentPage, isHasMore) -> { if (!isFinishing()) { this.isHasMore = isHasMore; if (isHasMore) { int size = result.size(); if (size > 0 && adapter != null) { adapter.getData().addAll(result); adapter.notifyDataSetChanged(); } else { // 这种情况就是开启过滤损坏文件刚好导致某一页全是损坏的虽然result为0,但还要请求下一页数据 loadMoreData(); } } } }); }
Example #8
Source File: PictureSelectorEngineImp.java From PictureSelector with Apache License 2.0 | 6 votes |
@Override public OnResultCallbackListener<LocalMedia> getResultCallbackListener() { return new OnResultCallbackListener<LocalMedia>() { @Override public void onResult(List<LocalMedia> result) { // TODO 这种情况是内存极度不足的情况下,比如开启开发者选项中的不保留活动或后台进程限制,导致OnResultCallbackListener被回收 // 可以在这里进行一些补救措施,通过广播或其他方式将结果推送到相应页面,防止结果丢失的情况 Log.i(TAG, "onResult:" + result.size()); } @Override public void onCancel() { Log.i(TAG, "PictureSelector onCancel"); } }; }
Example #9
Source File: MainActivity.java From PictureSelector with Apache License 2.0 | 6 votes |
@Override public void onResult(List<LocalMedia> result) { for (LocalMedia media : result) { Log.i(TAG, "是否压缩:" + media.isCompressed()); Log.i(TAG, "压缩:" + media.getCompressPath()); Log.i(TAG, "原图:" + media.getPath()); Log.i(TAG, "是否裁剪:" + media.isCut()); Log.i(TAG, "裁剪:" + media.getCutPath()); Log.i(TAG, "是否开启原图:" + media.isOriginal()); Log.i(TAG, "原图路径:" + media.getOriginalPath()); Log.i(TAG, "Android Q 特有Path:" + media.getAndroidQToPath()); Log.i(TAG, "宽高: " + media.getWidth() + "x" + media.getHeight()); Log.i(TAG, "Size: " + media.getSize()); // TODO 可以通过PictureSelectorExternalUtils.getExifInterface();方法获取一些额外的资源信息,如旋转角度、经纬度等信息 } if (mAdapterWeakReference.get() != null) { mAdapterWeakReference.get().setList(result); mAdapterWeakReference.get().notifyDataSetChanged(); } }
Example #10
Source File: PictureWeChatPreviewGalleryAdapter.java From PictureSelector with Apache License 2.0 | 6 votes |
@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); } }); } }
Example #11
Source File: PhotoFragment.java From PictureSelector with Apache License 2.0 | 6 votes |
@Override public void onResult(List<LocalMedia> result) { for (LocalMedia media : result) { Log.i(TAG, "是否压缩:" + media.isCompressed()); Log.i(TAG, "压缩:" + media.getCompressPath()); Log.i(TAG, "原图:" + media.getPath()); Log.i(TAG, "是否裁剪:" + media.isCut()); Log.i(TAG, "裁剪:" + media.getCutPath()); Log.i(TAG, "是否开启原图:" + media.isOriginal()); Log.i(TAG, "原图路径:" + media.getOriginalPath()); Log.i(TAG, "Android Q 特有Path:" + media.getAndroidQToPath()); Log.i(TAG, "宽高: " + media.getWidth() + "x" + media.getHeight()); Log.i(TAG, "Size: " + media.getSize()); // TODO 可以通过PictureSelectorExternalUtils.getExifInterface();方法获取一些额外的资源信息,如旋转角度、经纬度等信息 } if (mAdapterWeakReference.get() != null) { mAdapterWeakReference.get().setList(result); mAdapterWeakReference.get().notifyDataSetChanged(); } }
Example #12
Source File: PictureImageGridAdapter.java From PictureSelector with Apache License 2.0 | 6 votes |
public void bindSelectData(List<LocalMedia> images) { // 这里重新构构造一个新集合,不然会产生已选集合一变,结果集合也会添加的问题 List<LocalMedia> selection = new ArrayList<>(); int size = images.size(); for (int i = 0; i < size; i++) { LocalMedia media = images.get(i); selection.add(media); } this.selectData = selection; if (!config.isSingleDirectReturn) { subSelectPosition(); if (imageSelectChangedListener != null) { imageSelectChangedListener.onChange(selectData); } } }
Example #13
Source File: PictureSelectorPreviewWeChatStyleActivity.java From PictureSelector with Apache License 2.0 | 6 votes |
/** * onChangeMediaStatus * * @param media */ private void onChangeMediaStatus(LocalMedia media) { if (mGalleryAdapter != null) { int itemCount = mGalleryAdapter.getItemCount(); if (itemCount > 0) { boolean isChangeData = false; for (int i = 0; i < itemCount; i++) { LocalMedia item = mGalleryAdapter.getItem(i); if (item == null || TextUtils.isEmpty(item.getPath())) { continue; } boolean isOldChecked = item.isChecked(); boolean isNewChecked = item.getPath().equals(media.getPath()) || item.getId() == media.getId(); if (!isChangeData) { isChangeData = (isOldChecked && !isNewChecked) || (!isOldChecked && isNewChecked); } item.setChecked(isNewChecked); } if (isChangeData) { mGalleryAdapter.notifyDataSetChanged(); } } } }
Example #14
Source File: Luban.java From PictureSelector with Apache License 2.0 | 6 votes |
public Builder load(final Uri uri) { mStreamProviders.add(new InputStreamAdapter() { @Override public InputStream openInternal() throws IOException { return context.getContentResolver().openInputStream(uri); } @Override public String getPath() { return uri.getPath(); } @Override public LocalMedia getMedia() { return null; } }); return this; }
Example #15
Source File: PictureExternalPreviewActivity.java From PictureSelector with Apache License 2.0 | 6 votes |
@Override protected void initWidgets() { super.initWidgets(); titleViewBg = findViewById(R.id.titleViewBg); tvTitle = findViewById(R.id.picture_title); ibLeftBack = findViewById(R.id.left_back); ibDelete = findViewById(R.id.ib_delete); viewPager = findViewById(R.id.preview_pager); position = getIntent().getIntExtra(PictureConfig.EXTRA_POSITION, 0); images = (List<LocalMedia>) getIntent().getSerializableExtra(PictureConfig.EXTRA_PREVIEW_SELECT_LIST); ibLeftBack.setOnClickListener(this); ibDelete.setOnClickListener(this); ibDelete.setVisibility(config.style != null ? config.style.pictureExternalPreviewGonePreviewDelete ? View.VISIBLE : View.GONE : View.GONE); initViewPageAdapterData(); }
Example #16
Source File: PicturePreviewActivity.java From PictureSelector with Apache License 2.0 | 6 votes |
/** * 初始化ViewPage数据 * * @param list */ private void initViewPageAdapterData(List<LocalMedia> list) { adapter = new PictureSimpleFragmentAdapter(config, this); adapter.bindData(list); viewPager.setAdapter(adapter); viewPager.setCurrentItem(position); setTitle(); onImageChecked(position); LocalMedia media = adapter.getItem(position); if (media != null) { index = media.getPosition(); if (config.checkNumMode) { tvMediaNum.setSelected(true); check.setText(ValueOf.toString(media.getNum())); notifyCheckChanged(media); } } }
Example #17
Source File: PictureSelectorActivity.java From PictureSelector with Apache License 2.0 | 6 votes |
/** * Update Folder * * @param imageFolders */ private void updateMediaFolder(List<LocalMediaFolder> imageFolders, LocalMedia media) { File imageFile = new File(media.getRealPath()); File folderFile = imageFile.getParentFile(); if (folderFile == null) { return; } int size = imageFolders.size(); for (int i = 0; i < size; i++) { LocalMediaFolder folder = imageFolders.get(i); String name = folder.getName(); if (TextUtils.isEmpty(name)) { continue; } if (name.equals(folderFile.getName())) { folder.setFirstImagePath(config.cameraPath); folder.setImageNum(folder.getImageNum() + 1); folder.setCheckedNum(1); folder.getData().add(0, media); break; } } }
Example #18
Source File: Luban.java From PictureSelector with Apache License 2.0 | 5 votes |
/** * 扩展符合PictureSelector的压缩策略 * * @param list LocalMedia集合 * @param <T> * @return */ public <T> Builder loadMediaData(List<LocalMedia> list) { this.mediaList = list; this.dataCount = list.size(); for (LocalMedia src : list) { load(src); } return this; }
Example #19
Source File: PictureVideoPlayActivity.java From PictureSelector with Apache License 2.0 | 5 votes |
@Override protected void initWidgets() { super.initWidgets(); videoPath = getIntent().getStringExtra(PictureConfig.EXTRA_VIDEO_PATH); boolean isExternalPreview = getIntent().getBooleanExtra (PictureConfig.EXTRA_PREVIEW_VIDEO, false); if (TextUtils.isEmpty(videoPath)) { LocalMedia media = getIntent().getParcelableExtra(PictureConfig.EXTRA_MEDIA_KEY); if (media == null || TextUtils.isEmpty(media.getPath())) { finish(); return; } videoPath = media.getPath(); } if (TextUtils.isEmpty(videoPath)) { closeActivity(); return; } ibLeftBack = findViewById(R.id.pictureLeftBack); mVideoView = findViewById(R.id.video_view); tvConfirm = findViewById(R.id.tv_confirm); mVideoView.setBackgroundColor(Color.BLACK); iv_play = findViewById(R.id.iv_play); mMediaController = new MediaController(this); mVideoView.setOnCompletionListener(this); mVideoView.setOnPreparedListener(this); mVideoView.setMediaController(mMediaController); ibLeftBack.setOnClickListener(this); iv_play.setOnClickListener(this); tvConfirm.setOnClickListener(this); tvConfirm.setVisibility(config.selectionMode == PictureConfig.SINGLE && config.enPreviewVideo && !isExternalPreview ? View.VISIBLE : View.GONE); }
Example #20
Source File: Luban.java From PictureSelector with Apache License 2.0 | 5 votes |
/** * 扩展符合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; }
Example #21
Source File: PictureSelectorActivity.java From PictureSelector with Apache License 2.0 | 5 votes |
/** * Same type of image or video processing logic * * @param isHasImage * @param images */ private void separateMimeTypeWith(boolean isHasImage, List<LocalMedia> images) { LocalMedia image = images.size() > 0 ? images.get(0) : null; if (image == null) { return; } if (config.enableCrop && isHasImage) { if (config.selectionMode == PictureConfig.SINGLE) { config.originalPath = image.getPath(); startCrop(config.originalPath, image.getMimeType()); } else { ArrayList<CutInfo> cuts = new ArrayList<>(); int count = images.size(); for (int i = 0; i < count; i++) { LocalMedia media = images.get(i); if (media == null || TextUtils.isEmpty(media.getPath())) { continue; } CutInfo cutInfo = new CutInfo(); cutInfo.setId(media.getId()); cutInfo.setPath(media.getPath()); cutInfo.setImageWidth(media.getWidth()); cutInfo.setImageHeight(media.getHeight()); cutInfo.setMimeType(media.getMimeType()); cutInfo.setDuration(media.getDuration()); cutInfo.setRealPath(media.getRealPath()); cuts.add(cutInfo); } startCrop(cuts); } } else if (config.isCompress && isHasImage) { compressImage(images); } else { onResult(images); } }
Example #22
Source File: PictureSelectionModel.java From PictureSelector with Apache License 2.0 | 5 votes |
/** * 提供外部预览图片方法-带自定义下载保存路径 * # 废弃 由于Android Q沙盒机制 此方法不在需要了 * * @param position * @param medias */ @Deprecated public void openExternalPreview(int position, String directory_path, List<LocalMedia> medias) { if (selector != null) { selector.externalPicturePreview(position, directory_path, medias, selectionConfig.windowAnimationStyle != null && selectionConfig.windowAnimationStyle.activityPreviewEnterAnimation != 0 ? selectionConfig.windowAnimationStyle.activityPreviewEnterAnimation : 0); } else { throw new NullPointerException("This PictureSelector is Null"); } }
Example #23
Source File: PicturePreviewActivity.java From PictureSelector with Apache License 2.0 | 5 votes |
/** * 这里没实际意义,好处是预览图片时 滑动到屏幕一半以上可看到下一张图片是否选中了 * * @param previewEggs 是否显示预览友好体验 * @param positionOffsetPixels 滑动偏移量 */ private void isPreviewEggs(boolean previewEggs, int position, int positionOffsetPixels) { if (previewEggs) { if (adapter.getSize() > 0) { LocalMedia media; int num; if (positionOffsetPixels < screenWidth / 2) { media = adapter.getItem(position); if (media != null) { check.setSelected(isSelected(media)); if (config.isWeChatStyle) { onUpdateSelectedChange(media); } else { if (config.checkNumMode) { num = media.getNum(); check.setText(ValueOf.toString(num)); notifyCheckChanged(media); onImageChecked(position); } } } } else { media = adapter.getItem(position + 1); if (media != null) { check.setSelected(isSelected(media)); if (config.isWeChatStyle) { onUpdateSelectedChange(media); } else { if (config.checkNumMode) { num = media.getNum(); check.setText(ValueOf.toString(num)); notifyCheckChanged(media); onImageChecked(position + 1); } } } } } } }
Example #24
Source File: PictureSelectionModel.java From PictureSelector with Apache License 2.0 | 5 votes |
/** * 提供外部预览图片方法 * * @param position * @param medias */ public void openExternalPreview(int position, List<LocalMedia> medias) { if (selector != null) { selector.externalPicturePreview(position, medias, selectionConfig.windowAnimationStyle != null && selectionConfig.windowAnimationStyle.activityPreviewEnterAnimation != 0 ? selectionConfig.windowAnimationStyle.activityPreviewEnterAnimation : 0); } else { throw new NullPointerException("This PictureSelector is Null"); } }
Example #25
Source File: PictureBaseActivity.java From PictureSelector with Apache License 2.0 | 5 votes |
/** * handleCompressCallBack * * @param images * @param files */ private void handleCompressCallBack(List<LocalMedia> images, List<File> files) { if (images == null || files == null) { closeActivity(); return; } boolean isAndroidQ = SdkVersionUtils.checkedAndroid_Q(); int size = images.size(); if (files.size() == size) { for (int i = 0, j = size; i < j; i++) { File file = files.get(i); if (file == null) { continue; } String path = file.getAbsolutePath(); LocalMedia image = images.get(i); boolean http = PictureMimeType.isHasHttp(path); boolean flag = !TextUtils.isEmpty(path) && http; boolean isHasVideo = PictureMimeType.isHasVideo(image.getMimeType()); image.setCompressed(!isHasVideo && !flag); image.setCompressPath(isHasVideo || flag ? null : path); if (isAndroidQ) { image.setAndroidQToPath(image.getCompressPath()); } } } onResult(images); }
Example #26
Source File: PictureSelector.java From PictureSelector with Apache License 2.0 | 5 votes |
/** * @param data * @return Selector Multiple LocalMedia */ public static List<LocalMedia> obtainMultipleResult(Intent data) { if (data != null) { List<LocalMedia> result = data.getParcelableArrayListExtra(PictureConfig.EXTRA_RESULT_SELECTION); return result == null ? new ArrayList<>() : result; } return new ArrayList<>(); }
Example #27
Source File: PictureSelector.java From PictureSelector with Apache License 2.0 | 5 votes |
/** * @param bundle * @return get Selector LocalMedia */ public static List<LocalMedia> obtainSelectorList(Bundle bundle) { if (bundle != null) { List<LocalMedia> selectionMedias = bundle.getParcelableArrayList(PictureConfig.EXTRA_SELECT_LIST); return selectionMedias == null ? new ArrayList<>() : selectionMedias; } return new ArrayList<>(); }
Example #28
Source File: PictureBaseActivity.java From PictureSelector with Apache License 2.0 | 5 votes |
/** * compress or callback * * @param result */ protected void handlerResult(List<LocalMedia> result) { if (config.isCompress && !config.isCheckOriginalImage) { compressImage(result); } else { onResult(result); } }
Example #29
Source File: PicturePreviewActivity.java From PictureSelector with Apache License 2.0 | 5 votes |
/** * 当前图片是否选中 * * @param image * @return */ protected boolean isSelected(LocalMedia image) { int size = selectData.size(); for (int i = 0; i < size; i++) { LocalMedia media = selectData.get(i); if (media.getPath().equals(image.getPath()) || media.getId() == image.getId()) { return true; } } return false; }
Example #30
Source File: PictureWeChatPreviewGalleryAdapter.java From PictureSelector with Apache License 2.0 | 5 votes |
public void addSingleMediaToData(LocalMedia media) { if (this.list != null) { list.clear(); list.add(media); notifyDataSetChanged(); } }