List of usage examples for android.graphics Typeface create
public static Typeface create(Typeface family, @Style int style)
From source file:org.mariotaku.twidere.util.ThemeUtils.java
public static Typeface getUserTypeface(final Context context, final String fontFamily, final Typeface defTypeface) { if (context == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return Typeface.DEFAULT; final int fontStyle = defTypeface != null ? defTypeface.getStyle() : Typeface.NORMAL; final Typeface tf = Typeface.create(fontFamily, fontStyle); if (tf != null) return tf; return Typeface.create(Typeface.DEFAULT, fontStyle); }
From source file:de.vanita5.twittnuker.util.ThemeUtils.java
public static Typeface getUserTypeface(final Context context, final Typeface defTypeface) { if (context == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return Typeface.DEFAULT; final int fontStyle = defTypeface != null ? defTypeface.getStyle() : Typeface.NORMAL; final String fontFamily = getThemeFontFamily(context); final Typeface tf = Typeface.create(fontFamily, fontStyle); if (tf != null) return tf; return Typeface.create(Typeface.DEFAULT, fontStyle); }
From source file:org.telegram.ui.ArticleViewer.java
private TextPaint getTextPaint(TLRPC.RichText parentRichText, TLRPC.RichText richText, TLRPC.PageBlock parentBlock) {// w w w . ja va 2 s. c om int flags = getTextFlags(richText); HashMap<Integer, TextPaint> currentMap = null; int textSize = AndroidUtilities.dp(14); int textColor = 0xffff0000; if (parentBlock instanceof TLRPC.TL_pageBlockPhoto) { currentMap = captionTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockTitle) { currentMap = titleTextPaints; textSize = AndroidUtilities.dp(24); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockAuthorDate) { currentMap = authorTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockFooter) { currentMap = footerTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockSubtitle) { currentMap = subtitleTextPaints; textSize = AndroidUtilities.dp(21); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockHeader) { currentMap = headerTextPaints; textSize = AndroidUtilities.dp(21); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockSubheader) { currentMap = subheaderTextPaints; textSize = AndroidUtilities.dp(18); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockBlockquote || parentBlock instanceof TLRPC.TL_pageBlockPullquote) { if (parentBlock.text == parentRichText) { currentMap = quoteTextPaints; textSize = AndroidUtilities.dp(15); textColor = 0xff000000; } else if (parentBlock.caption == parentRichText) { currentMap = subquoteTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } } else if (parentBlock instanceof TLRPC.TL_pageBlockPreformatted) { currentMap = preformattedTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockParagraph) { if (parentBlock.caption == parentRichText) { currentMap = embedPostCaptionTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else { currentMap = paragraphTextPaints; textSize = AndroidUtilities.dp(16); textColor = 0xff000000; } } else if (parentBlock instanceof TLRPC.TL_pageBlockList) { currentMap = listTextPaints; textSize = AndroidUtilities.dp(15); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockEmbed) { currentMap = embedTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockSlideshow) { currentMap = slideshowTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockEmbedPost) { if (richText != null) { currentMap = embedPostTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff000000; } } else if (parentBlock instanceof TLRPC.TL_pageBlockVideo) { currentMap = videoTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff000000; } if (currentMap == null) { if (errorTextPaint == null) { errorTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); errorTextPaint.setColor(0xffff0000); } errorTextPaint.setTextSize(AndroidUtilities.dp(14)); return errorTextPaint; } TextPaint paint = currentMap.get(flags); if (paint == null) { paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); if ((flags & TEXT_FLAG_MONO) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/rmono.ttf")); } else { if (parentBlock instanceof TLRPC.TL_pageBlockTitle || parentBlock instanceof TLRPC.TL_pageBlockHeader || parentBlock instanceof TLRPC.TL_pageBlockSubtitle || parentBlock instanceof TLRPC.TL_pageBlockSubheader) { if ((flags & TEXT_FLAG_MEDIUM) != 0 && (flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(Typeface.create("serif", Typeface.BOLD_ITALIC)); } else if ((flags & TEXT_FLAG_MEDIUM) != 0) { paint.setTypeface(Typeface.create("serif", Typeface.BOLD)); } else if ((flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(Typeface.create("serif", Typeface.ITALIC)); } else { paint.setTypeface(Typeface.create("serif", Typeface.NORMAL)); } } else { if ((flags & TEXT_FLAG_MEDIUM) != 0 && (flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/rmediumitalic.ttf")); } else if ((flags & TEXT_FLAG_MEDIUM) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); } else if ((flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/ritalic.ttf")); } } } if ((flags & TEXT_FLAG_STRIKE) != 0) { paint.setFlags(paint.getFlags() | TextPaint.STRIKE_THRU_TEXT_FLAG); } if ((flags & TEXT_FLAG_UNDERLINE) != 0) { paint.setFlags(paint.getFlags() | TextPaint.UNDERLINE_TEXT_FLAG); } if ((flags & TEXT_FLAG_URL) != 0) { textColor = 0xff4d83b3; } paint.setColor(textColor); currentMap.put(flags, paint); } paint.setTextSize(textSize); return paint; }
From source file:com.forrestguice.suntimeswidget.SuntimesActivity.java
public void highlightTimeField(SolarEvents.SolarEventField highlightField) { int nextCardOffset = 0; int currentCard = this.card_flipper.getDisplayedChild(); for (SolarEvents.SolarEventField field : timeFields.keySet()) { TextView txtField = timeFields.get(field); if (txtField != null) { if (field.equals(highlightField)) { txtField.setTypeface(txtField.getTypeface(), Typeface.BOLD); txtField.setPaintFlags(txtField.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); if (currentCard == 0 && field.tomorrow) { nextCardOffset = 1;//from ww w . jav a 2 s . c om } else if (currentCard == 1 && !field.tomorrow) { nextCardOffset = -1; } } else { txtField.setTypeface(Typeface.create(txtField.getTypeface(), Typeface.NORMAL), Typeface.NORMAL); txtField.setPaintFlags(txtField.getPaintFlags() & (~Paint.UNDERLINE_TEXT_FLAG)); } } } if (!userSwappedCard) { //Log.d("DEBUG", "Swapping card to show highlighted :: userSwappedCard " + userSwappedCard); if (nextCardOffset > 0) { showNextCard(); } else if (nextCardOffset < 0) { showPreviousCard(); } } }
From source file:org.openintents.notepad.NoteEditor.java
private boolean setRemoteStyle(String styleName, int size) { if (TextUtils.isEmpty(styleName)) { if (DEBUG) { Log.e(TAG, "Empty style name: " + styleName); }/* w ww. j a va 2 s .c o m*/ return false; } PackageManager pm = getPackageManager(); String packageName = ThemeUtils.getPackageNameFromStyle(styleName); if (packageName == null) { Log.e(TAG, "Invalid style name: " + styleName); return false; } Context c = null; try { c = createPackageContext(packageName, 0); } catch (NameNotFoundException e) { Log.e(TAG, "Package for style not found: " + packageName + ", " + styleName); return false; } Resources res = c.getResources(); int themeid = res.getIdentifier(styleName, null, null); if (DEBUG) { Log.d(TAG, "Retrieving theme: " + styleName + ", " + themeid); } if (themeid == 0) { Log.e(TAG, "Theme name not found: " + styleName); return false; } try { ThemeAttributes ta = new ThemeAttributes(c, packageName, themeid); mTextTypeface = ta.getString(ThemeNotepad.TEXT_TYPEFACE); if (DEBUG) { Log.d(TAG, "textTypeface: " + mTextTypeface); } mCurrentTypeface = null; // Look for special cases: if ("monospace".equals(mTextTypeface)) { mCurrentTypeface = Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL); } else if ("sans".equals(mTextTypeface)) { mCurrentTypeface = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL); } else if ("serif".equals(mTextTypeface)) { mCurrentTypeface = Typeface.create(Typeface.SERIF, Typeface.NORMAL); } else if (!TextUtils.isEmpty(mTextTypeface)) { try { if (DEBUG) { Log.d(TAG, "Reading typeface: package: " + packageName + ", typeface: " + mTextTypeface); } Resources remoteRes = pm.getResourcesForApplication(packageName); mCurrentTypeface = Typeface.createFromAsset(remoteRes.getAssets(), mTextTypeface); if (DEBUG) { Log.d(TAG, "Result: " + mCurrentTypeface); } } catch (NameNotFoundException e) { Log.e(TAG, "Package not found for Typeface", e); } } mTextUpperCaseFont = ta.getBoolean(ThemeNotepad.TEXT_UPPER_CASE_FONT, false); mTextColor = ta.getColor(ThemeNotepad.TEXT_COLOR, android.R.color.white); if (DEBUG) { Log.d(TAG, "textColor: " + mTextColor); } if (size == 0) { mTextSize = getTextSizeTiny(ta); } else if (size == 1) { mTextSize = getTextSizeSmall(ta); } else if (size == 2) { mTextSize = getTextSizeMedium(ta); } else { mTextSize = getTextSizeLarge(ta); } if (DEBUG) { Log.d(TAG, "textSize: " + mTextSize); } if (mText != null) { mBackgroundPadding = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING, -1); int backgroundPaddingLeft = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_LEFT, mBackgroundPadding); int backgroundPaddingTop = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_TOP, mBackgroundPadding); int backgroundPaddingRight = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_RIGHT, mBackgroundPadding); int backgroundPaddingBottom = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_BOTTOM, mBackgroundPadding); if (DEBUG) { Log.d(TAG, "Padding: " + mBackgroundPadding + "; " + backgroundPaddingLeft + "; " + backgroundPaddingTop + "; " + backgroundPaddingRight + "; " + backgroundPaddingBottom + "; "); } try { Resources remoteRes = pm.getResourcesForApplication(packageName); int resid = ta.getResourceId(ThemeNotepad.BACKGROUND, 0); if (resid != 0) { Drawable d = remoteRes.getDrawable(resid); mText.setBackgroundDrawable(d); } else { // remove background mText.setBackgroundResource(0); } } catch (NameNotFoundException e) { Log.e(TAG, "Package not found for Theme background.", e); } catch (Resources.NotFoundException e) { Log.e(TAG, "Resource not found for Theme background.", e); } // Apply padding if (mBackgroundPadding >= 0 || backgroundPaddingLeft >= 0 || backgroundPaddingTop >= 0 || backgroundPaddingRight >= 0 || backgroundPaddingBottom >= 0) { mText.setPadding(backgroundPaddingLeft, backgroundPaddingTop, backgroundPaddingRight, backgroundPaddingBottom); } else { // 9-patches do the padding automatically // todo clear padding } } mLinesMode = ta.getInteger(ThemeNotepad.LINE_MODE, 2); mLinesColor = ta.getColor(ThemeNotepad.LINE_COLOR, 0xFF000080); if (DEBUG) { Log.d(TAG, "line color: " + mLinesColor); } return true; } catch (UnsupportedOperationException e) { // This exception is thrown e.g. if one attempts // to read an integer attribute as dimension. Log.e(TAG, "UnsupportedOperationException", e); return false; } catch (NumberFormatException e) { // This exception is thrown e.g. if one attempts // to read a string as integer. Log.e(TAG, "NumberFormatException", e); return false; } }
From source file:com.codename1.impl.android.AndroidImplementation.java
private Typeface fontToRoboto(String fontName) { if ("native:MainThin".equals(fontName)) { return Typeface.create("sans-serif-thin", Typeface.NORMAL); }// ww w .jav a 2 s.c o m if ("native:MainLight".equals(fontName)) { return Typeface.create("sans-serif-light", Typeface.NORMAL); } if ("native:MainRegular".equals(fontName)) { return Typeface.create("sans-serif", Typeface.NORMAL); } if ("native:MainBold".equals(fontName)) { return Typeface.create("sans-serif-condensed", Typeface.BOLD); } if ("native:MainBlack".equals(fontName)) { return Typeface.create("sans-serif-black", Typeface.BOLD); } if ("native:ItalicThin".equals(fontName)) { return Typeface.create("sans-serif-thin", Typeface.ITALIC); } if ("native:ItalicLight".equals(fontName)) { return Typeface.create("sans-serif-thin", Typeface.ITALIC); } if ("native:ItalicRegular".equals(fontName)) { return Typeface.create("sans-serif", Typeface.ITALIC); } if ("native:ItalicBold".equals(fontName)) { return Typeface.create("sans-serif-condensed", Typeface.BOLD_ITALIC); } if ("native:ItalicBlack".equals(fontName)) { return Typeface.create("sans-serif-black", Typeface.BOLD_ITALIC); } throw new IllegalArgumentException("Unsupported native font type: " + fontName); }
From source file:com.skytree.epubtest.BookViewActivity.java
public Typeface getTypeface(String fontName, int fontStyle) { Typeface tf = null;/*from w w w . j ava2 s .c o m*/ if (fontName.toLowerCase().contains("book")) { tf = Typeface.create(Typeface.DEFAULT, fontStyle); } else if (fontName.toLowerCase().contains("default")) { tf = Typeface.create(Typeface.DEFAULT, fontStyle); } else if (fontName.toLowerCase().contains("mono")) { tf = Typeface.create(Typeface.MONOSPACE, fontStyle); } else if ((fontName.toLowerCase().contains("sans"))) { tf = Typeface.create(Typeface.SANS_SERIF, fontStyle); } else if ((fontName.toLowerCase().contains("serif"))) { tf = Typeface.create(Typeface.SERIF, fontStyle); } return tf; }
From source file:com.codename1.impl.android.AndroidImplementation.java
@Override public Object deriveTrueTypeFont(Object font, float size, int weight) { NativeFont fnt = (NativeFont) font;/*from w w w . j ava2 s. c om*/ CodenameOneTextPaint paint = (CodenameOneTextPaint) fnt.font; paint.setAntiAlias(true); Typeface type = paint.getTypeface(); int fontstyle = Typeface.NORMAL; if ((weight & Font.STYLE_BOLD) != 0 || type.isBold()) { fontstyle |= Typeface.BOLD; } if ((weight & Font.STYLE_ITALIC) != 0 || type.isItalic()) { fontstyle |= Typeface.ITALIC; } type = Typeface.create(type, fontstyle); CodenameOneTextPaint newPaint = new CodenameOneTextPaint(type); newPaint.setTextSize(size); newPaint.setAntiAlias(true); NativeFont n = new NativeFont(com.codename1.ui.Font.FACE_SYSTEM, weight, com.codename1.ui.Font.SIZE_MEDIUM, newPaint, fnt.fileName, size, weight); return n; }
From source file:com.codename1.impl.android.AndroidImplementation.java
@Override public Object createFont(int face, int style, int size) { Typeface typeface = null;//www . j a v a 2 s. c o m switch (face) { case Font.FACE_MONOSPACE: typeface = Typeface.MONOSPACE; break; default: typeface = Typeface.DEFAULT; break; } int fontstyle = Typeface.NORMAL; if ((style & Font.STYLE_BOLD) != 0) { fontstyle |= Typeface.BOLD; } if ((style & Font.STYLE_ITALIC) != 0) { fontstyle |= Typeface.ITALIC; } int height = this.defaultFontHeight; int diff = height / 3; switch (size) { case Font.SIZE_SMALL: height -= diff; break; case Font.SIZE_LARGE: height += diff; break; } Paint font = new CodenameOneTextPaint(Typeface.create(typeface, fontstyle)); font.setAntiAlias(true); font.setUnderlineText((style & Font.STYLE_UNDERLINED) != 0); font.setTextSize(height); return new NativeFont(face, style, size, font); }
From source file:com.codename1.impl.android.AndroidImplementation.java
/** * Loads a native font based on a lookup for a font name and attributes. * Font lookup values can be separated by commas and thus allow fallback if * the primary font isn't supported by the platform. * * @param lookup string describing the font * @return the native font object/*ww w. ja v a 2 s.c om*/ */ public Object loadNativeFont(String lookup) { try { lookup = lookup.split(";")[0]; int typeface = Typeface.NORMAL; String familyName = lookup.substring(0, lookup.indexOf("-")); String style = lookup.substring(lookup.indexOf("-") + 1, lookup.lastIndexOf("-")); String size = lookup.substring(lookup.lastIndexOf("-") + 1, lookup.length()); if (style.equals("bolditalic")) { typeface = Typeface.BOLD_ITALIC; } else if (style.equals("italic")) { typeface = Typeface.ITALIC; } else if (style.equals("bold")) { typeface = Typeface.BOLD; } Paint font = new CodenameOneTextPaint(Typeface.create(familyName, typeface)); font.setAntiAlias(true); font.setTextSize(Integer.parseInt(size)); return new NativeFont(0, 0, 0, font); } catch (Exception err) { return null; } }