Search in sources :

Example 1 with ProviderResourceEntry

use of androidx.core.content.res.FontResourcesParserCompat.ProviderResourceEntry in project Carbon by ZieIony.

the class TypefaceCompat method createFromResourcesFamilyXml.

/**
 * Create Typeface from XML resource which root node is font-family.
 *
 * @return null if failed to create.
 * @hide
 */
@Nullable
@RestrictTo(LIBRARY_GROUP_PREFIX)
public static Typeface createFromResourcesFamilyXml(@NonNull Context context, @NonNull FamilyResourceEntry entry, @NonNull Resources resources, int id, int style, int weight, @Nullable ResourcesCompat.FontCallback fontCallback, @Nullable Handler handler, boolean isRequestFromLayoutInflator) {
    Typeface typeface;
    if (entry instanceof ProviderResourceEntry) {
        ProviderResourceEntry providerEntry = (ProviderResourceEntry) entry;
        final boolean isBlocking = isRequestFromLayoutInflator ? providerEntry.getFetchStrategy() == FontResourcesParserCompat.FETCH_STRATEGY_BLOCKING : fontCallback == null;
        final int timeout = isRequestFromLayoutInflator ? providerEntry.getTimeout() : FontResourcesParserCompat.INFINITE_TIMEOUT_VALUE;
        typeface = FontsContractCompat.getFontSync(context, providerEntry.getRequest(), fontCallback, handler, isBlocking, timeout, style);
    } else {
        typeface = sTypefaceCompatImpl.createFromFontFamilyFilesResourceEntry(context, (FontFamilyFilesResourceEntry) entry, resources, (style & Typeface.ITALIC) != 0, weight);
        if (fontCallback != null) {
            if (typeface != null) {
                fontCallback.callbackSuccessAsync(typeface, handler);
            } else {
                fontCallback.callbackFailAsync(FontsContractCompat.FontRequestCallback.FAIL_REASON_FONT_LOAD_ERROR, handler);
            }
        }
    }
    if (typeface != null) {
        sTypefaceCache.put(createResourceUid(resources, id, (style & Typeface.ITALIC) != 0, weight), typeface);
    }
    return typeface;
}
Also used : FontFamilyFilesResourceEntry(androidx.core.content.res.FontResourcesParserCompat.FontFamilyFilesResourceEntry) Typeface(android.graphics.Typeface) ProviderResourceEntry(androidx.core.content.res.FontResourcesParserCompat.ProviderResourceEntry) RestrictTo(androidx.annotation.RestrictTo) Nullable(androidx.annotation.Nullable)

Aggregations

Typeface (android.graphics.Typeface)1 Nullable (androidx.annotation.Nullable)1 RestrictTo (androidx.annotation.RestrictTo)1 FontFamilyFilesResourceEntry (androidx.core.content.res.FontResourcesParserCompat.FontFamilyFilesResourceEntry)1 ProviderResourceEntry (androidx.core.content.res.FontResourcesParserCompat.ProviderResourceEntry)1