项目:DownloadableCalligraphy
文件:CalligraphyUtils.java
/**
* Tries to pull the Custom Attribute directly from the TextView.
*
* @param context Activity Context
* @param attrs View Attributes
* @param attributeId if -1 returns null.
* @return null if attribute is not defined or added to View
*/
@FontRes
static int pullFontPathFromView(Context context,AttributeSet attrs,int[] attributeId) {
if (attributeId == null || attrs == null)
return 0;
final String attributeName;
try {
attributeName = context.getResources().getResourceEntryName(attributeId[0]);
} catch (Resources.NotFoundException e) {
// invalid attribute ID
return 0;
}
final int stringResourceId = attrs.getAttributeResourceValue(null,attributeName,-1);
return stringResourceId > 0
? stringResourceId
: attrs.getAttributeIntValue(null,0);
}
项目:DownloadableCalligraphy
文件:CalligraphyUtils.java
/**
* Tries to pull the Font Path from the View Style as this is the next decendent after being
* defined in the View's xml.
*
* @param context Activity Activity Context
* @param attrs View Attributes
* @param attributeId if -1 returns null.
* @return null if attribute is not defined or found in the Style
*/
@FontRes
static int pullFontPathFromStyle(Context context,int[] attributeId) {
if (attributeId == null || attrs == null)
return 0;
final TypedArray typedArray = context.obtainStyledAttributes(attrs,attributeId);
if (typedArray != null) {
try {
// First defined attribute
int fontFromAttribute = typedArray.getResourceId(0,0);
if (fontFromAttribute != 0) {
return fontFromAttribute;
}
} catch (Exception ignore) {
// Failed for some reason.
} finally {
typedArray.recycle();
}
}
return 0;
}
项目:DownloadableCalligraphy
文件:CalligraphyUtils.java
/**
* Tries to pull the Font Path from the Text Appearance.
*
* @param context Activity Context
* @param attrs View Attributes
* @param attributeId if -1 returns null.
* @return returns null if attribute is not defined or if no TextAppearance is found.
*/
@FontRes
static int pullFontPathFromTextAppearance(final Context context,int[] attributeId) {
if (attributeId == null || attrs == null)
return 0;
int textAppearanceId = -1;
// For prevent using default component font
final ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(context,android.R.style.Theme_Nodisplay);
final TypedArray typedArrayAttr = contextThemeWrapper.obtainStyledAttributes(attrs,ANDROID_ATTR_TEXT_APPEaraNCE);
if (typedArrayAttr != null) {
try {
textAppearanceId = typedArrayAttr.getResourceId(0,0);
} catch (Exception ignored) {
// Failed for some reason
return 0;
} finally {
typedArrayAttr.recycle();
}
}
final Integer textAppearanceAttrs = getFontFromTextAppearance(context,attributeId,textAppearanceId);
if (textAppearanceAttrs != null) return textAppearanceAttrs;
return 0;
}
项目:DownloadableCalligraphy
文件:CalligraphyUtils.java
/**
* Last but not least,try to pull the Font Path from the Theme,which is defined.
*
* @param context Activity Context
* @param styleAttrId Theme style id
* @param attributeId if -1 returns null.
* @return null if no theme or attribute defined.
*/
@FontRes
static int pullFontPathFromTheme(Context context,int styleAttrId,int[] attributeId) {
if (styleAttrId == -1 || attributeId == null)
return 0;
final Resources.Theme theme = context.getTheme();
final TypedValue value = new TypedValue();
theme.resolveAttribute(styleAttrId,value,true);
final TypedArray typedArray = theme.obtainStyledAttributes(value.resourceId,attributeId);
try {
return typedArray.getResourceId(0,0);
} catch (Exception ignore) {
// Failed for some reason.
return 0;
} finally {
typedArray.recycle();
}
}
项目:DownloadableCalligraphy
文件:CalligraphyFactory.java
private Typeface getDefaultTypeface(Context context,@FontRes int fontFamily) {
if (fontFamily == 0) {
fontFamily = CalligraphyConfig.get().getFontFamily();
}
if (fontFamily != 0) {
return ResourcesCompat.getFont(context,fontFamily);
}
return null;
}
private void setTabFont(int textViewId,@FontRes int font,int position) {
if (font == 0)
return;
Typeface typeface = ResourcesCompat.getFont(getContext(),font);
setTabFont(textViewId,typeface,position);
}
/**
* @return mFontFamily for text views might be null
*/
@FontRes
public int getFontFamily() {
return mFontFamily;
}
public TabbedViewPager setSelectedTabFont(@FontRes int font) {
selectedTabFont = font;
return this;
}
项目:Downloadable-Fonts
文件:CustomDownloadableFontProvider.java
public CustomDownloadableFontProvider(@FontRes int resourceFont) {
this.resourceFont = resourceFont;
}
项目:plaid
文件:BaselineGridTextView.java
public @FontRes int getFontResId() {
return fontResId;
}
/**
* Set the default font if you don't define one else where in your styles.
*
* @param defaultFont a path to a font file in the assets folder,e.g. "fonts/Roboto-light.ttf",* passing null will default to the device font-family.
* @return this builder.
*/
public Builder setDefaultFont(@FontRes int defaultFont) {
this.isFontSet = defaultFont != 0;
this.fontFamily = defaultFont;
return this;
}
项目:plaid
文件:ReflowText.java
@FontRes int getFontResId();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。