androidx.ui.res

Classes

DeferredResource

A class used for the result of the asynchronous resource loading.

FailedResource

A class represents the alternative resource due to failed to load the requested resource.

LoadedResource

A class represents the loaded resource.

PendingResource

A class represents the alternative resource due to background loading.

Resource

The base resource class for background resource loading.

Top-level functions summary

Boolean
booleanResource(@BoolRes id: Int)

Load a boolean resource.

Color
colorResource(@ColorRes id: Int)

Load a string resource.

Dp
dimensionResource(@DimenRes id: Int)

Load a boolean resource.

ImageAsset
imageResource(@DrawableRes id: Int)

Synchronously load an image resource.

IntArray
integerArrayResource(@ArrayRes id: Int)

Load an array of integer resource.

Int
integerResource(@IntegerRes id: Int)

Load an integer resource.

DeferredResource<ImageAsset>
loadImageResource(id: Int, pendingImage: ImageAsset? = null, failedImage: ImageAsset? = null)

Load the image in background thread.

DeferredResource<VectorAsset>
loadVectorResource(id: Int, pendingResource: VectorAsset? = null, failedResource: VectorAsset? = null)

Load the vector drawable in background thread.

Array<String>
stringArrayResource(@ArrayRes id: Int)

Load a string resource.

String
stringResource(@StringRes id: Int)

Load a string resource.

String
stringResource(@StringRes id: Int, vararg formatArgs: Any)

Load a string resource with formatting.

VectorAsset
vectorResource(@DrawableRes id: Int)

Effect used to load a VectorAsset from an Android resource id This is useful for querying top level properties of the VectorAsset such as it's intrinsic width and height to be able to size components based off of it's dimensions appropriately

Top-level functions

booleanResource

@Composable fun booleanResource(@BoolRes id: Int): Boolean

Load a boolean resource.

Parameters
id: Int the resource identifier
Return
the boolean associated with the resource

colorResource

@Composable fun colorResource(@ColorRes id: Int): Color

Load a string resource.

Parameters
id: Int the resource identifier
Return
the color associated with the resource

dimensionResource

@Composable fun dimensionResource(@DimenRes id: Int): Dp

Load a boolean resource.

Parameters
id: Int the resource identifier
Return
the dimension value associated with the resource

imageResource

@Composable fun imageResource(@DrawableRes id: Int): ImageAsset

Synchronously load an image resource.

Note: This API is transient and will be likely removed for encouraging async resource loading.

Parameters
id: Int the resource identifier
Return
the decoded image data associated with the resource

integerArrayResource

@Composable fun integerArrayResource(@ArrayRes id: Int): IntArray

Load an array of integer resource.

Parameters
id: Int the resource identifier
Return
the integer array associated with the resource

integerResource

@Composable fun integerResource(@IntegerRes id: Int): Int

Load an integer resource.

Parameters
id: Int the resource identifier
Return
the integer associated with the resource

loadImageResource

@Composable fun loadImageResource(
    id: Int,
    pendingImage: ImageAsset? = null,
    failedImage: ImageAsset? = null
): DeferredResource<ImageAsset>

Load the image in background thread.

Until resource loading complete, this function returns deferred image resource with PendingResource. Once the loading finishes, recompose is scheduled and this function will return deferred image resource with LoadedResource or FailedResource.

Parameters
id: Int the resource identifier
pendingImage: ImageAsset? = null an optional image to be used during loading instead.
failedImage: ImageAsset? = null an optional image to be used if image loading failed.
Return
the deferred image resource.

loadVectorResource

@Composable fun loadVectorResource(
    id: Int,
    pendingResource: VectorAsset? = null,
    failedResource: VectorAsset? = null
): DeferredResource<VectorAsset>

Load the vector drawable in background thread.

Until resource loading complete, this function returns deferred vector drawable resource with PendingResource. Once the loading finishes, recompose is scheduled and this function will return deferred vector drawable resource with LoadedResource or FailedResource.

Parameters
id: Int the resource identifier
pendingResource: VectorAsset? = null an optional resource to be used during loading instead.
failedResource: VectorAsset? = null an optional resource to be used if resource loading failed.
Return
the deferred vector drawable resource.

stringArrayResource

@Composable fun stringArrayResource(@ArrayRes id: Int): Array<String>

Load a string resource.

Parameters
id: Int the resource identifier
Return
the string data associated with the resource

stringResource

@Composable fun stringResource(@StringRes id: Int): String

Load a string resource.

Parameters
id: Int the resource identifier
Return
the string data associated with the resource

stringResource

@Composable fun stringResource(
    @StringRes id: Int,
    vararg formatArgs: Any
): String

Load a string resource with formatting.

Parameters
id: Int the resource identifier
vararg formatArgs: Any the format arguments
Return
the string data associated with the resource

vectorResource

@Composable fun vectorResource(@DrawableRes id: Int): VectorAsset

Effect used to load a VectorAsset from an Android resource id This is useful for querying top level properties of the VectorAsset such as it's intrinsic width and height to be able to size components based off of it's dimensions appropriately

Note: This API is transient and will be likely removed for encouraging async resource loading.