Search in sources :

Example 21 with ImageItem

use of com.lzy.imagepicker.bean.ImageItem in project ImagePicker by jeasonlzy.

the class WxDemoActivity method onItemClick.

@Override
public void onItemClick(View view, int position) {
    switch(position) {
        case IMAGE_ITEM_ADD:
            List<String> names = new ArrayList<>();
            names.add("拍照");
            names.add("相册");
            showDialog(new SelectDialog.SelectDialogListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    switch(position) {
                        case // 直接调起相机
                        0:
                            /**
                             * 0.4.7 目前直接调起相机不支持裁剪,如果开启裁剪后不会返回图片,请注意,后续版本会解决
                             *
                             * 但是当前直接依赖的版本已经解决,考虑到版本改动很少,所以这次没有上传到远程仓库
                             *
                             * 如果实在有所需要,请直接下载源码引用。
                             */
                            // 打开选择,本次允许选择的数量
                            ImagePicker.getInstance().setSelectLimit(maxImgCount - selImageList.size());
                            Intent intent = new Intent(WxDemoActivity.this, ImageGridActivity.class);
                            // 是否是直接打开相机
                            intent.putExtra(ImageGridActivity.EXTRAS_TAKE_PICKERS, true);
                            startActivityForResult(intent, REQUEST_CODE_SELECT);
                            break;
                        case 1:
                            // 打开选择,本次允许选择的数量
                            ImagePicker.getInstance().setSelectLimit(maxImgCount - selImageList.size());
                            Intent intent1 = new Intent(WxDemoActivity.this, ImageGridActivity.class);
                            /* 如果需要进入选择的时候显示已经选中的图片,
                                 * 详情请查看ImagePickerActivity
                                 * */
                            // intent1.putExtra(ImageGridActivity.EXTRAS_IMAGES,images);
                            startActivityForResult(intent1, REQUEST_CODE_SELECT);
                            break;
                        default:
                            break;
                    }
                }
            }, names);
            break;
        default:
            // 打开预览
            Intent intentPreview = new Intent(this, ImagePreviewDelActivity.class);
            intentPreview.putExtra(ImagePicker.EXTRA_IMAGE_ITEMS, (ArrayList<ImageItem>) adapter.getImages());
            intentPreview.putExtra(ImagePicker.EXTRA_SELECTED_IMAGE_POSITION, position);
            intentPreview.putExtra(ImagePicker.EXTRA_FROM_ITEMS, true);
            startActivityForResult(intentPreview, REQUEST_CODE_PREVIEW);
            break;
    }
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) ImageGridActivity(com.lzy.imagepicker.ui.ImageGridActivity) RecyclerView(android.support.v7.widget.RecyclerView) CropImageView(com.lzy.imagepicker.view.CropImageView) View(android.view.View) AdapterView(android.widget.AdapterView) SelectDialog(com.lzy.imagepickerdemo.SelectDialog) ImageItem(com.lzy.imagepicker.bean.ImageItem)

Example 22 with ImageItem

use of com.lzy.imagepicker.bean.ImageItem in project ImagePicker by jeasonlzy.

the class ImageDataSource method onLoadFinished.

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    imageFolders.clear();
    if (data != null) {
        // 所有图片的集合,不分文件夹
        ArrayList<ImageItem> allImages = new ArrayList<>();
        while (data.moveToNext()) {
            // 查询数据
            String imageName = data.getString(data.getColumnIndexOrThrow(IMAGE_PROJECTION[0]));
            String imagePath = data.getString(data.getColumnIndexOrThrow(IMAGE_PROJECTION[1]));
            File file = new File(imagePath);
            if (!file.exists() || file.length() <= 0) {
                continue;
            }
            long imageSize = data.getLong(data.getColumnIndexOrThrow(IMAGE_PROJECTION[2]));
            int imageWidth = data.getInt(data.getColumnIndexOrThrow(IMAGE_PROJECTION[3]));
            int imageHeight = data.getInt(data.getColumnIndexOrThrow(IMAGE_PROJECTION[4]));
            String imageMimeType = data.getString(data.getColumnIndexOrThrow(IMAGE_PROJECTION[5]));
            long imageAddTime = data.getLong(data.getColumnIndexOrThrow(IMAGE_PROJECTION[6]));
            // 封装实体
            ImageItem imageItem = new ImageItem();
            imageItem.name = imageName;
            imageItem.path = imagePath;
            imageItem.size = imageSize;
            imageItem.width = imageWidth;
            imageItem.height = imageHeight;
            imageItem.mimeType = imageMimeType;
            imageItem.addTime = imageAddTime;
            allImages.add(imageItem);
            // 根据父路径分类存放图片
            File imageFile = new File(imagePath);
            File imageParentFile = imageFile.getParentFile();
            ImageFolder imageFolder = new ImageFolder();
            imageFolder.name = imageParentFile.getName();
            imageFolder.path = imageParentFile.getAbsolutePath();
            if (!imageFolders.contains(imageFolder)) {
                ArrayList<ImageItem> images = new ArrayList<>();
                images.add(imageItem);
                imageFolder.cover = imageItem;
                imageFolder.images = images;
                imageFolders.add(imageFolder);
            } else {
                imageFolders.get(imageFolders.indexOf(imageFolder)).images.add(imageItem);
            }
        }
        // 防止没有图片报异常
        if (data.getCount() > 0 && allImages.size() > 0) {
            // 构造所有图片的集合
            ImageFolder allImagesFolder = new ImageFolder();
            allImagesFolder.name = activity.getResources().getString(R.string.ip_all_images);
            allImagesFolder.path = "/";
            allImagesFolder.cover = allImages.get(0);
            allImagesFolder.images = allImages;
            // 确保第一条是所有图片
            imageFolders.add(0, allImagesFolder);
        }
    }
    // 回调接口,通知图片数据准备完成
    ImagePicker.getInstance().setImageFolders(imageFolders);
    loadedListener.onImagesLoaded(imageFolders);
}
Also used : ImageFolder(com.lzy.imagepicker.bean.ImageFolder) ArrayList(java.util.ArrayList) ImageItem(com.lzy.imagepicker.bean.ImageItem) File(java.io.File)

Aggregations

ImageItem (com.lzy.imagepicker.bean.ImageItem)22 ArrayList (java.util.ArrayList)11 Intent (android.content.Intent)5 View (android.view.View)5 File (java.io.File)4 Bitmap (android.graphics.Bitmap)2 ParseManager (com.benmu.framework.manager.impl.ParseManager)2 ParseManager (com.eros.framework.manager.impl.ParseManager)2 IntentResult (com.google.zxing.integration.android.IntentResult)2 HashMap (java.util.HashMap)2 ViewPager (android.support.v4.view.ViewPager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1 AxiosManager (com.benmu.framework.manager.impl.AxiosManager)1 ImageManager (com.benmu.framework.manager.impl.ImageManager)1 UploadImageBean (com.benmu.framework.model.UploadImageBean)1