@Test public void testProviderFont_nonXmlRequest_noCallback() { Typeface typeface = TypefaceCompat.createFromResourcesFamilyXml(mContext, getProviderResourceEntry(R.font.samplexmldownloadedfontblocking), mResources, R.font.samplexmldownloadedfontblocking, Typeface.NORMAL, null, null , false ); assertNotNull(typeface); assertNotEquals(Typeface.DEFAULT, typeface); }
@Nullable public static Typeface createFromResourcesFamilyXml( @NonNull Context context, @NonNull FamilyResourceEntry entry, @NonNull Resources resources, int id, int style, @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); 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); } return typeface; }
TypefaceCompat { @Nullable public static Typeface createFromResourcesFamilyXml( @NonNull Context context, @NonNull FamilyResourceEntry entry, @NonNull Resources resources, int id, int style, @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); 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); } return typeface; } }
TypefaceCompat { @Nullable public static Typeface createFromResourcesFamilyXml( @NonNull Context context, @NonNull FamilyResourceEntry entry, @NonNull Resources resources, int id, int style, @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); 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); } return typeface; } private  TypefaceCompat(); }
TypefaceCompat { @Nullable public static Typeface createFromResourcesFamilyXml( @NonNull Context context, @NonNull FamilyResourceEntry entry, @NonNull Resources resources, int id, int style, @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); 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); } return typeface; } private  TypefaceCompat(); @Nullable static Typeface findFromCache(@NonNull Resources resources, int id, int style); @Nullable static Typeface createFromResourcesFamilyXml(
            @NonNull Context context, @NonNull FamilyResourceEntry entry,
            @NonNull Resources resources, int id, int style,
            @Nullable ResourcesCompat.FontCallback fontCallback, @Nullable Handler handler,
            boolean isRequestFromLayoutInflator); @Nullable static Typeface createFromResourcesFontFile(
            @NonNull Context context, @NonNull Resources resources, int id, String path,
            int style); @Nullable static Typeface createFromFontInfo(@NonNull Context context,
            @Nullable CancellationSignal cancellationSignal, @NonNull FontInfo[] fonts, int style); }
TypefaceCompat { @Nullable public static Typeface createFromResourcesFamilyXml( @NonNull Context context, @NonNull FamilyResourceEntry entry, @NonNull Resources resources, int id, int style, @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); 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); } return typeface; } private  TypefaceCompat(); @Nullable static Typeface findFromCache(@NonNull Resources resources, int id, int style); @Nullable static Typeface createFromResourcesFamilyXml(
            @NonNull Context context, @NonNull FamilyResourceEntry entry,
            @NonNull Resources resources, int id, int style,
            @Nullable ResourcesCompat.FontCallback fontCallback, @Nullable Handler handler,
            boolean isRequestFromLayoutInflator); @Nullable static Typeface createFromResourcesFontFile(
            @NonNull Context context, @NonNull Resources resources, int id, String path,
            int style); @Nullable static Typeface createFromFontInfo(@NonNull Context context,
            @Nullable CancellationSignal cancellationSignal, @NonNull FontInfo[] fonts, int style);  }