FontsContractCompat

Added in 1.1.0

public class FontsContractCompat


Utility class to deal with Font ContentProviders.

Summary

Nested types

public final class FontsContractCompat.Columns implements BaseColumns

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

Object returned from fetchFonts.

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

Interface used to receive asynchronously fetched typefaces.

Public methods

static @Nullable Typeface
buildTypeface(
    @NonNull Context context,
    @Nullable CancellationSignal cancellationSignal,
    @NonNull FontsContractCompat.FontInfo[] fonts
)

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

static @NonNull FontsContractCompat.FontFamilyResult
fetchFonts(
    @NonNull Context context,
    @Nullable CancellationSignal cancellationSignal,
    @NonNull FontRequest request
)

Fetch fonts given a font request.

static void
requestFont(
    @NonNull Context context,
    @NonNull FontRequest request,
    @NonNull FontsContractCompat.FontRequestCallback callback,
    @NonNull Handler handler
)

Create a typeface object given a font request.

Public methods

buildTypeface

Added in 1.1.0
public static @Nullable Typeface buildTypeface(
    @NonNull Context context,
    @Nullable CancellationSignal cancellationSignal,
    @NonNull FontsContractCompat.FontInfo[] fonts
)

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

Parameters
@NonNull Context context

A Context that will be used to fetch the font contents.

@Nullable CancellationSignal cancellationSignal

A signal to cancel the operation in progress, or null if none. If the operation is canceled, then will be thrown.

@NonNull FontsContractCompat.FontInfo[] fonts

An array of FontInfo to be used to create a Typeface.

Returns
@Nullable Typeface

A Typeface object. Returns null if typeface creation fails.

fetchFonts

Added in 1.1.0
public static @NonNull FontsContractCompat.FontFamilyResult fetchFonts(
    @NonNull Context context,
    @Nullable CancellationSignal cancellationSignal,
    @NonNull FontRequest request
)

Fetch fonts given a font request.

Parameters
@NonNull Context context

A Context to be used for fetching fonts.

@Nullable CancellationSignal cancellationSignal

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.

@NonNull FontRequest request

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

Throws
android.content.pm.PackageManager.NameNotFoundException

If requested package or authority was not found in the system.

requestFont

Added in 1.1.0
public static void requestFont(
    @NonNull Context context,
    @NonNull FontRequest request,
    @NonNull FontsContractCompat.FontRequestCallback callback,
    @NonNull Handler handler
)

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
@NonNull Context context

A context to be used for fetching from font provider.

@NonNull FontRequest request

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

@NonNull FontsContractCompat.FontRequestCallback callback

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

@NonNull Handler handler

A handler to be processed the font fetching.