TextureBitmapStore


public fun interface TextureBitmapStore


Interface for a callback to allow the caller to provide a particular Bitmap corresponding to a client-provided texture ID.

Summary

Public methods

abstract Bitmap
get(@NonNull String clientTextureId)

Retrieve a Bitmap for the given texture id.

default @NonNull String

Returns the texture ID to write in place of clientTextureId when a BrushFamily is encoded with this store using androidx.ink.storage.

Public methods

get

Added in 1.0.0
abstract Bitmap get(@NonNull String clientTextureId)

Retrieve a Bitmap for the given texture id. This may be called synchronously during onDraw, so loading of texture files from disk and decoding them into Bitmap objects should be done on init. The result may be cached by consumers, so this should return a deterministic result for a given input.

Textures can be disabled by having load always return null. null should also be returned when a texture can not be loaded. If null is returned, the texture layer in question should be ignored, allowing for graceful fallback. It's recommended that implementations log when a texture can not be loaded.

Returns
Bitmap

The texture bitmap, if any, associated with the given id.

getEncodedTextureId

Added in 1.1.0-alpha13
@ExperimentalInkBrushCompatibilityApi
default @NonNull String getEncodedTextureId(@NonNull String clientTextureId)

Returns the texture ID to write in place of clientTextureId when a BrushFamily is encoded with this store using androidx.ink.storage. By default, texture IDs are written unchanged. This is not used for rendering.

Override this to undo any change made to texture IDs when decoding (in androidx.ink.storage.BrushFamilyDecodeCallback.onDecodeTexture), for example to remove a prefix that was added to keep texture IDs unique within this store, so that re-encoding a decoded BrushFamily writes the texture IDs that it was originally serialized with.

This is called whether or not get returns a bitmap for clientTextureId. The result may be cached by consumers, so this should return a deterministic result for a given input. If two different client texture IDs used in the same BrushFamily return the same encoded ID, their layers will share that encoded ID in the serialized form and only the first texture's bitmap will be stored. If BrushFamily.hasFallbacks is true for a BrushFamily that is encoded on its own, its stored serialized form, which already has the original texture IDs, is written instead, so this has no effect.

Parameters
@NonNull String clientTextureId

The texture ID used by the BrushFamily being encoded.

Returns
@NonNull String

The texture ID to write into the serialized BrushFamily.