FontsContractCompat
public class FontsContractCompat
Utility class to deal with Font ContentProviders.
Summary
Nested types |
|---|
public final class FontsContractCompat.Columns implements BaseColumnsDefines the constants used in a response from a Font Provider. |
public class FontsContractCompat.FontFamilyResultObject returned from |
public class FontsContractCompat.FontInfoObject represent a font entry in the family returned from |
public class FontsContractCompat.FontRequestCallbackInterface used to receive asynchronously fetched typefaces. |
Public methods |
|
|---|---|
static @Nullable Typeface |
buildTypeface(Build a Typeface from an array of |
static @NonNull FontsContractCompat.FontFamilyResult |
fetchFonts(Fetch fonts given a font request. |
static void |
This method is 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. |
static void |
requestFont(Request a font async as specified with |
static void |
requestFontWithFallbackChain(Request a font async as specified with |
Public methods
buildTypeface
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 |
@Nullable CancellationSignal cancellationSignal |
A signal to cancel the operation in progress, or null if none. If the operation is canceled, then |
@NonNull FontsContractCompat.FontInfo[] fonts |
An array of |
fetchFonts
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 |
@Nullable CancellationSignal cancellationSignal |
A signal to cancel the operation in progress, or null if none. If the operation is canceled, then |
@NonNull FontRequest request |
A |
| Throws | |
|---|---|
android.content.pm.PackageManager.NameNotFoundException |
If requested package or authority was not found in the system. |
public static voidrequestFont(
@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 main thread.
| Parameters | |
|---|---|
@NonNull Context context |
A context to be used for fetching from font provider. |
@NonNull FontRequest request |
A |
@NonNull FontsContractCompat.FontRequestCallback callback |
A callback that will be triggered when results are obtained. May not be null. |
@NonNull Handler handler |
A handler for running font fetch tasks on. |
| See also | |
|---|---|
requestFont |
requestFont
public static void requestFont(
@NonNull Context context,
@NonNull FontRequest request,
int style,
@Nullable Executor loadingExecutor,
@NonNull Executor callbackExecutor,
@NonNull FontsContractCompat.FontRequestCallback callback
)
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 | |
|---|---|
@NonNull Context context |
A context to be used for fetching from font provider |
@NonNull FontRequest request |
A |
int style |
Typeface Style such as |
@Nullable Executor loadingExecutor |
executor to load font on. Loading may take several _seconds_. If |
@NonNull Executor callbackExecutor |
Used to dispatch callback |
@NonNull FontsContractCompat.FontRequestCallback callback |
A callback that will be triggered when results are obtained. |
requestFontWithFallbackChain
public static void requestFontWithFallbackChain(
@NonNull Context context,
@NonNull List<FontRequest> requests,
int style,
@Nullable Executor loadingExecutor,
@NonNull Executor callbackExecutor,
@NonNull FontsContractCompat.FontRequestCallback callback
)
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 | |
|---|---|
@NonNull Context context |
A context to be used for fetching from font provider |
@NonNull List<FontRequest> requests |
An array of |
int style |
Typeface Style such as |
@Nullable Executor loadingExecutor |
executor to load font on. Loading may take several _seconds_. If |
@NonNull Executor callbackExecutor |
Used to dispatch callback |
@NonNull FontsContractCompat.FontRequestCallback callback |
A callback that will be triggered when results are obtained. |