List of usage examples for android.graphics Typeface NORMAL
int NORMAL
To view the source code for android.graphics Typeface NORMAL.
Click Source Link
From source file:com.wanikani.androidnotifier.ItemsFragment.java
/** * Internal implementation of the {@link #selectLevel(Filter, int, boolean)} * logic. This gets called when it is certain that we are being called * by the correct filter, or no filter is involved, so checks are skipped. * In addition, this method may be called also to <i>unselect</i> a level. * @param row the level row on which to act. This parameter may be <code>null</code>, * if the label is not visible. Calling the method is still important, to * show the levels list, if hidden/*w w w. j a v a 2s. c o m*/ * @param select <code>true</code> if the level should be selected. * Otherwise it is unselected * @param spin <code>true</code> if the spinner should be displayed. * Otherwise it is hidden. Makes sense only if <code>select</code> * is <code>true</code> too */ private void selectLevel(View row, boolean select, boolean spin) { TextView tw; View sw; selectOtherFilter(false, false); if (row == null) return; tw = (TextView) row.findViewById(R.id.tgr_level); sw = row.findViewById(R.id.pb_level); if (spin) { tw.setVisibility(View.GONE); sw.setVisibility(View.VISIBLE); } else { tw.setVisibility(View.VISIBLE); sw.setVisibility(View.GONE); } if (select) { tw.setTextColor(selectedColor); tw.setTypeface(null, Typeface.BOLD); } else { tw.setTextColor(unselectedColor); tw.setTypeface(null, Typeface.NORMAL); } }
From source file:org.telegram.ui.ArticleViewer.java
private TextPaint getTextPaint(TLRPC.RichText parentRichText, TLRPC.RichText richText, TLRPC.PageBlock parentBlock) {/* w w w .j a va2s . 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:plugin.google.maps.GoogleMaps.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @Override/* ww w .ja va2 s. c o m*/ public View getInfoContents(Marker marker) { String title = marker.getTitle(); String snippet = marker.getSnippet(); if ((title == null) && (snippet == null)) { return null; } JSONObject properties = null; JSONObject styles = null; String propertyId = "marker_property_" + marker.getId(); PluginEntry pluginEntry = this.plugins.get("Marker"); PluginMarker pluginMarker = (PluginMarker) pluginEntry.plugin; if (pluginMarker.objects.containsKey(propertyId)) { properties = (JSONObject) pluginMarker.objects.get(propertyId); if (properties.has("styles")) { try { styles = (JSONObject) properties.getJSONObject("styles"); } catch (JSONException e) { } } } // Linear layout LinearLayout windowLayer = new LinearLayout(activity); windowLayer.setPadding(3, 3, 3, 3); windowLayer.setOrientation(LinearLayout.VERTICAL); LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER; windowLayer.setLayoutParams(layoutParams); //---------------------------------------- // text-align = left | center | right //---------------------------------------- int gravity = Gravity.LEFT; int textAlignment = View.TEXT_ALIGNMENT_GRAVITY; if (styles != null) { try { String textAlignValue = styles.getString("text-align"); switch (TEXT_STYLE_ALIGNMENTS.valueOf(textAlignValue)) { case left: gravity = Gravity.LEFT; textAlignment = View.TEXT_ALIGNMENT_GRAVITY; break; case center: gravity = Gravity.CENTER; textAlignment = View.TEXT_ALIGNMENT_CENTER; break; case right: gravity = Gravity.RIGHT; textAlignment = View.TEXT_ALIGNMENT_VIEW_END; break; } } catch (Exception e) { } } if (title != null) { if (title.indexOf("data:image/") > -1 && title.indexOf(";base64,") > -1) { String[] tmp = title.split(","); Bitmap image = PluginUtil.getBitmapFromBase64encodedImage(tmp[1]); image = PluginUtil.scaleBitmapForDevice(image); ImageView imageView = new ImageView(this.cordova.getActivity()); imageView.setImageBitmap(image); windowLayer.addView(imageView); } else { TextView textView = new TextView(this.cordova.getActivity()); textView.setText(title); textView.setSingleLine(false); int titleColor = Color.BLACK; if (styles != null && styles.has("color")) { try { titleColor = PluginUtil.parsePluginColor(styles.getJSONArray("color")); } catch (JSONException e) { } } textView.setTextColor(titleColor); textView.setGravity(gravity); if (VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setTextAlignment(textAlignment); } //---------------------------------------- // font-style = normal | italic // font-weight = normal | bold //---------------------------------------- int fontStyle = Typeface.NORMAL; if (styles != null) { try { if ("italic".equals(styles.getString("font-style"))) { fontStyle = Typeface.ITALIC; } } catch (JSONException e) { } try { if ("bold".equals(styles.getString("font-weight"))) { fontStyle = fontStyle | Typeface.BOLD; } } catch (JSONException e) { } } textView.setTypeface(Typeface.DEFAULT, fontStyle); windowLayer.addView(textView); } } if (snippet != null) { //snippet = snippet.replaceAll("\n", ""); TextView textView2 = new TextView(this.cordova.getActivity()); textView2.setText(snippet); textView2.setTextColor(Color.GRAY); textView2.setTextSize((textView2.getTextSize() / 6 * 5) / density); textView2.setGravity(gravity); if (VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView2.setTextAlignment(textAlignment); } windowLayer.addView(textView2); } return windowLayer; }
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 w w w. j ava 2s . c o m } 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:com.albedinsky.android.ui.widget.SeekBarWidget.java
/** * Returns the style of the typeface used to draw the discrete indicator's text. * * @return Typeface style./*w ww .jav a2s .c o m*/ * @see #getDiscreteIndicatorTypeface() * @see #setDiscreteIndicatorTypeface(Typeface, int) */ @TextAppearance.TextStyle @SuppressWarnings("ResourceType") public int getDiscreteIndicatorTypefaceStyle() { final Typeface typeface = DISCRETE_INDICATOR_TEXT_INFO.paint.getTypeface(); return typeface != null ? typeface.getStyle() : Typeface.NORMAL; }
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); }/*from ww w. ja va2 s . c om*/ 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); }/*from ww w . j a v a 2 s. c om*/ 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.codename1.impl.android.AndroidImplementation.java
@Override public Object deriveTrueTypeFont(Object font, float size, int weight) { NativeFont fnt = (NativeFont) font;//from w w w . j ava 2 s . c o m 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;/*from w w w .ja v a 2s . 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/*from w w w. j a va2 s .c o m*/ */ 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; } }