Search in sources :

Example 1 with ImageFolder

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

the class ImageFolderAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.adapter_folder_list_item, parent, false);
        holder = new ViewHolder(convertView);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    ImageFolder folder = getItem(position);
    holder.folderName.setText(folder.name);
    holder.imageCount.setText(mActivity.getString(R.string.folder_image_count, folder.images.size()));
    imagePicker.getImageLoader().displayImage(mActivity, folder.cover.path, holder.cover, mImageSize, mImageSize);
    if (lastSelected == position) {
        holder.folderCheck.setVisibility(View.VISIBLE);
    } else {
        holder.folderCheck.setVisibility(View.INVISIBLE);
    }
    return convertView;
}
Also used : ImageFolder(com.lzy.imagepicker.bean.ImageFolder)

Example 2 with ImageFolder

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

the class ImageGridActivity method createPopupFolderList.

/** 创建弹出的ListView */
private void createPopupFolderList() {
    mFolderPopupWindow = new FolderPopUpWindow(this, mImageFolderAdapter);
    mFolderPopupWindow.setOnItemClickListener(new FolderPopUpWindow.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            mImageFolderAdapter.setSelectIndex(position);
            imagePicker.setCurrentImageFolderPosition(position);
            mFolderPopupWindow.dismiss();
            ImageFolder imageFolder = (ImageFolder) adapterView.getAdapter().getItem(position);
            if (null != imageFolder) {
                mImageGridAdapter.refreshData(imageFolder.images);
                mBtnDir.setText(imageFolder.name);
            }
            //滑动到顶部
            mGridView.smoothScrollToPosition(0);
        }
    });
    mFolderPopupWindow.setMargin(mFooterBar.getHeight());
}
Also used : ImageFolder(com.lzy.imagepicker.bean.ImageFolder) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) SuppressLint(android.annotation.SuppressLint) FolderPopUpWindow(com.lzy.imagepicker.view.FolderPopUpWindow)

Example 3 with ImageFolder

use of com.lzy.imagepicker.bean.ImageFolder 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]));
            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) {
            //构造所有图片的集合
            ImageFolder allImagesFolder = new ImageFolder();
            allImagesFolder.name = activity.getResources().getString(R.string.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

ImageFolder (com.lzy.imagepicker.bean.ImageFolder)3 SuppressLint (android.annotation.SuppressLint)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 GridView (android.widget.GridView)1 ImageItem (com.lzy.imagepicker.bean.ImageItem)1 FolderPopUpWindow (com.lzy.imagepicker.view.FolderPopUpWindow)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1