DataSourceBitmapLoader


@UnstableApi
public final class DataSourceBitmapLoader implements BitmapLoader


A BitmapLoader implementation that uses a DataSource to support fetching images from URIs and BitmapFactory to load them into Bitmap.

Loading tasks are delegated to a ListeningExecutorService defined during construction. If no executor service is passed, all tasks are delegated to a single-thread executor service that is shared between instances of this class.

Summary

Public constructors

Creates an instance that uses a DefaultHttpDataSource for image loading and delegates loading tasks to a newSingleThreadExecutor.

DataSourceBitmapLoader(
    ListeningExecutorService listeningExecutorService,
    DataSource.Factory dataSourceFactory
)

Creates an instance that delegates loading tasks to the ListeningExecutorService.

DataSourceBitmapLoader(
    ListeningExecutorService listeningExecutorService,
    DataSource.Factory dataSourceFactory,
    @Nullable BitmapFactory.Options options
)

Creates an instance that delegates loading tasks to the ListeningExecutorService.

Public methods

ListenableFuture<Bitmap>
decodeBitmap(byte[] data)

Decodes an image from compressed binary data.

ListenableFuture<Bitmap>

Loads an image from uri.

boolean

Returns whether the given mimeType is supported.

Constants

DEFAULT_EXECUTOR_SERVICE

public static final Supplier<ListeningExecutorServiceDEFAULT_EXECUTOR_SERVICE

Public constructors

DataSourceBitmapLoader

public DataSourceBitmapLoader(Context context)

Creates an instance that uses a DefaultHttpDataSource for image loading and delegates loading tasks to a newSingleThreadExecutor.

DataSourceBitmapLoader

public DataSourceBitmapLoader(
    ListeningExecutorService listeningExecutorService,
    DataSource.Factory dataSourceFactory
)

Creates an instance that delegates loading tasks to the ListeningExecutorService.

Parameters
ListeningExecutorService listeningExecutorService

The ListeningExecutorService.

DataSource.Factory dataSourceFactory

The DataSource.Factory that creates the DataSource used to load the image.

DataSourceBitmapLoader

public DataSourceBitmapLoader(
    ListeningExecutorService listeningExecutorService,
    DataSource.Factory dataSourceFactory,
    @Nullable BitmapFactory.Options options
)

Creates an instance that delegates loading tasks to the ListeningExecutorService.

Parameters
ListeningExecutorService listeningExecutorService

The ListeningExecutorService.

DataSource.Factory dataSourceFactory

The DataSource.Factory that creates the DataSource used to load the image.

@Nullable BitmapFactory.Options options

The BitmapFactory.Options the image should be loaded with.

Public methods

decodeBitmap

public ListenableFuture<BitmapdecodeBitmap(byte[] data)

Decodes an image from compressed binary data.

loadBitmap

public ListenableFuture<BitmaploadBitmap(Uri uri)

Loads an image from uri.

supportsMimeType

public boolean supportsMimeType(String mimeType)

Returns whether the given mimeType is supported.