Search in sources :

Example 1 with ItemConsumer

use of com.android.gallery3d.data.MediaSet.ItemConsumer in project android_packages_apps_Gallery2 by LineageOS.

the class MediaItemsLoader method loadInBackground.

@Override
public Cursor loadInBackground() {
    // TODO: This probably doesn't work
    mMediaSet.reload();
    final MatrixCursor cursor = new MatrixCursor(PhotoSetLoader.PROJECTION);
    final Object[] row = new Object[PhotoSetLoader.PROJECTION.length];
    final SparseArray<MediaItem> mediaItems = new SparseArray<MediaItem>();
    mMediaSet.enumerateTotalMediaItems(new ItemConsumer() {

        @Override
        public void consume(int index, MediaItem item) {
            row[PhotoSetLoader.INDEX_ID] = index;
            row[PhotoSetLoader.INDEX_DATA] = item.getContentUri().toString();
            row[PhotoSetLoader.INDEX_DATE_ADDED] = item.getDateInMs();
            row[PhotoSetLoader.INDEX_HEIGHT] = item.getHeight();
            row[PhotoSetLoader.INDEX_WIDTH] = item.getWidth();
            row[PhotoSetLoader.INDEX_WIDTH] = item.getWidth();
            int rawMediaType = item.getMediaType();
            int mappedMediaType = FileColumns.MEDIA_TYPE_NONE;
            if (rawMediaType == MediaItem.MEDIA_TYPE_IMAGE) {
                mappedMediaType = FileColumns.MEDIA_TYPE_IMAGE;
            } else if (rawMediaType == MediaItem.MEDIA_TYPE_VIDEO) {
                mappedMediaType = FileColumns.MEDIA_TYPE_VIDEO;
            }
            row[PhotoSetLoader.INDEX_MEDIA_TYPE] = mappedMediaType;
            row[PhotoSetLoader.INDEX_SUPPORTED_OPERATIONS] = item.getSupportedOperations();
            cursor.addRow(row);
            mediaItems.append(index, item);
        }
    });
    synchronized (mMediaSet) {
        mMediaItems = mediaItems;
    }
    return cursor;
}
Also used : ItemConsumer(com.android.gallery3d.data.MediaSet.ItemConsumer) SparseArray(android.util.SparseArray) MediaItem(com.android.gallery3d.data.MediaItem) MediaObject(com.android.gallery3d.data.MediaObject) MatrixCursor(android.database.MatrixCursor)

Aggregations

MatrixCursor (android.database.MatrixCursor)1 SparseArray (android.util.SparseArray)1 MediaItem (com.android.gallery3d.data.MediaItem)1 MediaObject (com.android.gallery3d.data.MediaObject)1 ItemConsumer (com.android.gallery3d.data.MediaSet.ItemConsumer)1