FontsContractCompat

open class FontsContractCompat
kotlin.Any
   ↳ androidx.core.provider.FontsContractCompat

Utility class to deal with Font ContentProviders.

Summary

Nested classes

Defines the constants used in a response from a Font Provider.

open

Object returned from #fetchFonts.

open

Object represent a font entry in the family returned from #fetchFonts.

open

Interface used to receive asynchronously fetched typefaces.

Public methods
open static Unit

Create a typeface object given a font request.

open static Typeface?
buildTypeface(context: Context, cancellationSignal: CancellationSignal?, fonts: Array<FontsContractCompat.FontInfo!>)

Build a Typeface from an array of FontInfo Results that are marked as not ready will be skipped.

open static FontsContractCompat.FontFamilyResult
fetchFonts(context: Context, cancellationSignal: CancellationSignal?, request: FontRequest)

Fetch fonts given a font request.

Public methods

requestFont

open static fun requestFont(context: Context, request: FontRequest, callback: FontsContractCompat.FontRequestCallback, handler: Handler): Unit

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 caller thread.

Parameters
context Context: A context to be used for fetching from font provider.
request Context: A FontRequest object that identifies the provider and query for the request. May not be null.
callback Context: A callback that will be triggered when results are obtained. May not be null.
handler Context: A handler to be processed the font fetching.

buildTypeface

open static fun buildTypeface(context: Context, cancellationSignal: CancellationSignal?, fonts: Array<FontsContractCompat.FontInfo!>): Typeface?

Build a Typeface from an array of FontInfo Results that are marked as not ready will be skipped.

Parameters
context Context: A Context that will be used to fetch the font contents.
cancellationSignal Context: A signal to cancel the operation in progress, or null if none. If the operation is canceled, then will be thrown.
fonts Context: An array of FontInfo to be used to create a Typeface.
Return
Typeface?: A Typeface object. Returns null if typeface creation fails.

fetchFonts

open static fun fetchFonts(context: Context, cancellationSignal: CancellationSignal?, request: FontRequest): FontsContractCompat.FontFamilyResult

Fetch fonts given a font request.

Parameters
context Context: A Context to be used for fetching fonts.
cancellationSignal Context: A signal to cancel the operation in progress, or null if none. If the operation is canceled, then will be thrown when the query is executed.
request Context: A FontRequest object that identifies the provider and query for the request.
Return
FontsContractCompat.FontFamilyResult: FontFamilyResult
Exceptions
PackageManager.NameNotFoundException If requested package or authority was not found in the system.