requestFont

open fun requestFont(@NonNull context: Context, @NonNull request: FontRequest, style: Int, @Nullable loadingExecutor: Executor, @NonNull callbackExecutor: Executor, @NonNull callback: FontsContractCompat.FontRequestCallback)(source)

Request a font async as specified with FontRequest Loading may take several seconds, and the loadingExecutor passed should be available to run blocking requests for several seconds. Results will be returned via callbackExecutor.

Parameters

context

A context to be used for fetching from font provider

request

A FontRequest object that identifies the provider and query for the request.

style

Typeface Style such as NORMAL, BOLDITALIC, BOLD_ITALIC.

loadingExecutor

executor to load font on. Loading may take several _seconds_. If null, a default executor shared with other null-requests will be used.

callbackExecutor

Used to dispatch callback

callback

A callback that will be triggered when results are obtained.


open fun requestFont(@NonNull context: Context, @NonNull requests: List<FontRequest>, style: Int, isBlockingFetch: Boolean, @IntRange(from = 0) timeout: Int, @NonNull handler: Handler, @NonNull callback: FontsContractCompat.FontRequestCallback): Typeface(source)

Loads a Typeface. Based on the parameters isBlockingFetch, and timeoutInMillis, the fetch is either sync or async. - If timeoutInMillis is infinite, and isBlockingFetch is true -> sync - If timeoutInMillis is NOT infinite, and isBlockingFetch is true -> sync with timeout - else -> async without timeout. Used by TypefaceCompat and tests.

Return

the resulting Typeface if the requested font is in the cache or the request is a sync request.

Parameters

context

Context

requests

List of FontRequests that define the font to be loaded, followed by any custom fallbacks, in order

style

Typeface Style such as NORMAL, BOLDITALIC, BOLD_ITALIC.

isBlockingFetch

when true the call will be synchronous.

timeout

timeout in milliseconds for the request. It is not used for async request.

handler

the handler to call the callback on.

callback

the callback to be called.


open fun requestFont(@NonNull context: Context, @NonNull request: FontRequest, style: Int, isBlockingFetch: Boolean, @IntRange(from = 0) timeout: Int, @NonNull handler: Handler, @NonNull callback: FontsContractCompat.FontRequestCallback): Typeface(source)

Loads a Typeface. Based on the parameters isBlockingFetch, and timeoutInMillis, the fetch is either sync or async. - If timeoutInMillis is infinite, and isBlockingFetch is true -> sync - If timeoutInMillis is NOT infinite, and isBlockingFetch is true -> sync with timeout - else -> async without timeout. Used by TypefaceCompat and tests.

Return

the resulting Typeface if the requested font is in the cache or the request is a sync request.

Parameters

context

Context

request

FontRequest that define the font to be loaded and any fallbacks

style

Typeface Style such as NORMAL, BOLDITALIC, BOLD_ITALIC.

isBlockingFetch

when true the call will be synchronous.

timeout

timeout in milliseconds for the request. It is not used for async request.

handler

the handler to call the callback on.

callback

the callback to be called.


Deprecated

due to the non-standard pattern of taking a handler for a non-UI thread - leading to both easily passing an incorrect handler and requiring all callers spin up an extra thread.

Create a typeface object given a font request. The font will be asynchronously fetched, therefore the result is delivered to the given callback. See FontRequest. Only one of the methods in callback will be invoked, depending on whether the request succeeds or fails. These calls will happen on the main thread.

Parameters

context

A context to be used for fetching from font provider.

request

A FontRequest object that identifies the provider and query for the request. May not be null.

callback

A callback that will be triggered when results are obtained. May not be null.

handler

A handler to be processed the font fetching.

See also