Java Code Examples for android.graphics.Typeface#NORMAL

The following examples show how to use android.graphics.Typeface#NORMAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReactBaseTextShadowNode.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
/* This code is duplicated in ReactTextInputManager
/* TODO: Factor into a common place they can both use
*/
@ReactProp(name = ViewProps.FONT_WEIGHT)
public void setFontWeight(@Nullable String fontWeightString) {
  int fontWeightNumeric =
      fontWeightString != null ? parseNumericFontWeight(fontWeightString) : -1;
  int fontWeight = UNSET;
  if (fontWeightNumeric >= 500 || "bold".equals(fontWeightString)) {
    fontWeight = Typeface.BOLD;
  } else if ("normal".equals(fontWeightString)
      || (fontWeightNumeric != -1 && fontWeightNumeric < 500)) {
    fontWeight = Typeface.NORMAL;
  }
  if (fontWeight != mFontWeight) {
    mFontWeight = fontWeight;
    markUpdated();
  }
}
 
Example 2
Source File: SVGAndroidRenderer.java    From XDroidAnimation with Apache License 2.0 6 votes vote down vote up
private Typeface  checkGenericFont(String fontName, Integer fontWeight, FontStyle fontStyle)
{
   Typeface font = null;
   int      typefaceStyle;

   boolean  italic = (fontStyle == Style.FontStyle.Italic);
   typefaceStyle = (fontWeight > 500) ? (italic ? Typeface.BOLD_ITALIC : Typeface.BOLD)
                                      : (italic ? Typeface.ITALIC : Typeface.NORMAL);

   if (fontName.equals("serif")) {
      font = Typeface.create(Typeface.SERIF, typefaceStyle);
   } else if (fontName.equals("sans-serif")) {
      font = Typeface.create(Typeface.SANS_SERIF, typefaceStyle);
   } else if (fontName.equals("monospace")) {
      font = Typeface.create(Typeface.MONOSPACE, typefaceStyle);
   } else if (fontName.equals("cursive")) {
      font = Typeface.create(Typeface.SANS_SERIF, typefaceStyle);
   } else if (fontName.equals("fantasy")) {
      font = Typeface.create(Typeface.SANS_SERIF, typefaceStyle);
   }
   return font;
}
 
Example 3
Source File: ClubsAdapter.java    From android with Apache License 2.0 6 votes vote down vote up
@Override public void bind(Club club) {
  ClubStats stats = club.nonNullStats();
  int typeface = selectedClub.nameEquals(club) ? Typeface.BOLD : Typeface.NORMAL;
  views.position.setText(String.valueOf(getAdapterPosition() + 1));
  views.points.setTypeface(null, typeface);
  views.points.setText(String.valueOf(stats.points()));
  views.clubName.setText(club.abbrev_name());
  views.clubName.setTypeface(null, typeface);
  views.wins.setTypeface(null, typeface);
  views.wins.setText(String.valueOf(stats.wins()));
  views.draws.setTypeface(null, typeface);
  views.draws.setText(String.valueOf(stats.draws()));
  views.losses.setTypeface(null, typeface);
  views.losses.setText(String.valueOf(stats.losses()));
  views.goalsDifference.setTypeface(null, typeface);
  views.goalsDifference.setText(String.valueOf(stats.goals()));
  Context context = itemView.getContext();
  views.layout.setOnClickListener(view -> context.startActivity(
      TeamDetailsActivity.newIntent(context, club)));
}
 
Example 4
Source File: ReactAztecManager.java    From react-native-aztec with GNU General Public License v2.0 6 votes vote down vote up
/**
 /* This code was taken from the method setFontWeight of the class ReactTextShadowNode
 /* TODO: Factor into a common place they can both use
 */
@ReactProp(name = ViewProps.FONT_WEIGHT)
public void setFontWeight(ReactAztecText view, @Nullable String fontWeightString) {
    int fontWeightNumeric = fontWeightString != null ?
            parseNumericFontWeight(fontWeightString) : -1;
    int fontWeight = UNSET;
    if (fontWeightNumeric >= 500 || "bold".equals(fontWeightString)) {
        fontWeight = Typeface.BOLD;
    } else if ("normal".equals(fontWeightString) ||
            (fontWeightNumeric != -1 && fontWeightNumeric < 500)) {
        fontWeight = Typeface.NORMAL;
    }
    Typeface currentTypeface = view.getTypeface();
    if (currentTypeface == null) {
        currentTypeface = Typeface.DEFAULT;
    }
    if (fontWeight != currentTypeface.getStyle()) {
        view.setTypeface(currentTypeface, fontWeight);
    }
}
 
Example 5
Source File: RowSong.java    From SMP with GNU General Public License v3.0 6 votes vote down vote up
public RowSong(int pos, int level, long songID, String songTitle, String songArtist, String songAlbum,
               int dur, int songTrack, String songPath, long albumId, int year) {
    super(pos, level, Typeface.NORMAL);
    id = songID;
    title = songTitle;
    artist = songArtist;
    album = songAlbum;
    duration = dur;
    track = songTrack;
    path = songPath;
    this.albumId = albumId;
    this.year = year;
    if(path != null) {
        folder = Path.getFolder(path);
    }
}
 
Example 6
Source File: PXFontRegistry.java    From pixate-freestyle-android with Apache License 2.0 6 votes vote down vote up
public static Typeface getTypeface(String family, String weight, String style) {
    String key = deriveKey(family, weight, style);
    Typeface match = FONT_BY_KEY.get(key);
    Typeface result;

    if (match != null) {
        result = match;

    } else {
        int typefaceStyle = Typeface.NORMAL; // default

        if ("bold".equals(weight) && "italic".equals(style)) {
            typefaceStyle = Typeface.BOLD_ITALIC;
        } else if ("bold".equals(weight)) {
            typefaceStyle = Typeface.BOLD;
        } else if ("italic".equals(style)) {
            typefaceStyle = Typeface.ITALIC;
        }

        result = Typeface.create(family, typefaceStyle);
        FONT_BY_KEY.put(key, result);
    }

    return result;

}
 
Example 7
Source File: FromTextView.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
public void setText(Recipient recipient, boolean read) {
  String fromString = recipient.toShortString();

  int typeface;

  if (!read) {
    typeface = Typeface.BOLD;
  } else {
    typeface = Typeface.NORMAL;
  }

  SpannableStringBuilder builder = new SpannableStringBuilder();

  SpannableString fromSpan = new SpannableString(fromString);
  fromSpan.setSpan(new StyleSpan(typeface), 0, builder.length(),
                   Spannable.SPAN_INCLUSIVE_EXCLUSIVE);

  if (recipient.getName() == null && !TextUtils.isEmpty(recipient.getProfileName())) {
    SpannableString profileName = new SpannableString(" (~" + recipient.getProfileName() + ") ");
    profileName.setSpan(new CenterAlignedRelativeSizeSpan(0.75f), 0, profileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    profileName.setSpan(new TypefaceSpan("sans-serif-light"), 0, profileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    profileName.setSpan(new ForegroundColorSpan(ResUtil.getColor(getContext(), R.attr.conversation_list_item_subject_color)), 0, profileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL){
      builder.append(profileName);
      builder.append(fromSpan);
    } else {
      builder.append(fromSpan);
      builder.append(profileName);
    }
  } else {
    builder.append(fromSpan);
  }

  setText(builder);
}
 
Example 8
Source File: TypefaceCollection.java    From android-typeface-helper with Apache License 2.0 5 votes vote down vote up
private static void validateTypefaceStyle(int typefaceStyle) {
	switch (typefaceStyle) {
	case Typeface.NORMAL:
	case Typeface.BOLD:
	case Typeface.ITALIC:
	case Typeface.BOLD_ITALIC:
		break;
	default:
		throw new IllegalArgumentException("Invalid typeface style! Have to be one of " +
				"Typeface.NORMAL, Typeface.BOLD, Typeface.ITALIC or Typeface.BOLD_ITALIC");
	}
}
 
Example 9
Source File: TypefaceHelper.java    From android-typeface-helper with Apache License 2.0 5 votes vote down vote up
/**
 * Check if typeface style int is one of:
 * <ul>
 *      <li>{@link android.graphics.Typeface#NORMAL}</li>
 *      <li>{@link android.graphics.Typeface#BOLD}</li>
 *      <li>{@link android.graphics.Typeface#ITALIC}</li>
 *      <li>{@link android.graphics.Typeface#BOLD_ITALIC}</li>
 * </ul>
 * @param style
 */
private static void checkTypefaceStyleThrowing(int style) {
	switch (style) {
	case Typeface.NORMAL:
	case Typeface.BOLD:
	case Typeface.ITALIC:
	case Typeface.BOLD_ITALIC:
		break;
	default:
		throw new IllegalArgumentException("Style have to be in (Typeface.NORMAL, Typeface.BOLD, Typeface.ITALIC, Typeface.BOLD_ITALIC)");
	}
}
 
Example 10
Source File: ReactTextInputManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactProp(name = ViewProps.FONT_FAMILY)
public void setFontFamily(ReactEditText view, String fontFamily) {
  int style = Typeface.NORMAL;
  if (view.getTypeface() != null) {
    style = view.getTypeface().getStyle();
  }
  Typeface newTypeface = ReactFontManager.getInstance().getTypeface(
      fontFamily,
      style,
      view.getContext().getAssets());
  view.setTypeface(newTypeface);
}
 
Example 11
Source File: TypefaceManager.java    From Android-Font-Library with The Unlicense 5 votes vote down vote up
/**
 * Converts a style constant from {@link Typeface} to a style constant from the {@link
 * TypefaceManager}.
 *
 * @param typefaceStyle A style from the constants in Typeface
 * @return The corresponding internal style
 */
private static byte toInternalStyle(int typefaceStyle) {
	switch (typefaceStyle) {
		//@formatter:off
		case Typeface.NORMAL:      return REGULAR;
		case Typeface.BOLD:        return BOLD;
		case Typeface.ITALIC:      return ITALIC;
		case Typeface.BOLD_ITALIC: return BOLD_ITALIC;
		default:                   return INVALID;
		//@formatter:on
	}
}
 
Example 12
Source File: TextViewStyleProfile.java    From SublimeNavigationView with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the typeface style to the given value. The typeface style
 * defaults to Typeface.NORMAL if the value isn't one of
 * Typeface.NORMAL, Typeface.BOLD, Typeface.ITALIC, Typeface.BOLD_ITALIC.
 *
 * @param typefaceStyle The style to set.
 * @return This {@link TextViewStyleProfile} for chaining.
 */
public TextViewStyleProfile setTypefaceStyle(int typefaceStyle) {
    if (typefaceStyle < Typeface.NORMAL || typefaceStyle > Typeface.BOLD_ITALIC) {
        Log.e(TAG, "'setTypefaceStyle(int)' was called with a invalid value " +
                "- allowed values are Typeface.NORMAL, Typeface.BOLD, " +
                "Typeface.ITALIC and Typeface.BOLD_ITALIC.");
        mTypefaceStyle = Typeface.NORMAL;
    } else {
        mTypefaceStyle = typefaceStyle;
    }

    return this;
}
 
Example 13
Source File: ReactBaseTextShadowNode.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
/* This code is duplicated in ReactTextInputManager
/* TODO: Factor into a common place they can both use
*/
@ReactProp(name = ViewProps.FONT_STYLE)
public void setFontStyle(@Nullable String fontStyleString) {
  int fontStyle = UNSET;
  if ("italic".equals(fontStyleString)) {
    fontStyle = Typeface.ITALIC;
  } else if ("normal".equals(fontStyleString)) {
    fontStyle = Typeface.NORMAL;
  }
  if (fontStyle != mFontStyle) {
    mFontStyle = fontStyle;
    markUpdated();
  }
}
 
Example 14
Source File: UDFontStyle.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public static int getValue(String name) {
    if (!TextUtils.isEmpty(name)) {
        if (STYLE_NORMAL.equalsIgnoreCase(name)) {
            return Typeface.NORMAL;
        } else if (STYLE_BOLD.equalsIgnoreCase(name)) {
            return Typeface.BOLD;
        } else if (STYLE_ITALIC.equalsIgnoreCase(name)) {
            return Typeface.ITALIC;
        }
    }
    return Typeface.NORMAL;
}
 
Example 15
Source File: TypefaceLoader.java    From react-native-navigation with MIT License 5 votes vote down vote up
private int getStyle(String fontFamilyName) {
	int style = Typeface.NORMAL;
	if (fontFamilyName.toLowerCase().contains("bold")) {
		style = Typeface.BOLD;
	} else if (fontFamilyName.toLowerCase().contains("italic")) {
		style = Typeface.ITALIC;
	}
	return style;
}
 
Example 16
Source File: Style.java    From SuperToasts with Apache License 2.0 5 votes vote down vote up
/**
 * Public constructor for a new {@link com.github.johnpersano.supertoasts.library.Style}.
 * This constructor will assign a few default values.
 */
public Style() {
    // General SuperToast items
    this.duration = DURATION_MEDIUM;
    this.color = PaletteUtils.getSolidColor(PaletteUtils.MATERIAL_GREY);
    this.gravity = Gravity.BOTTOM | Gravity.CENTER;
    this.yOffset = BackgroundUtils.convertToDIP(64);
    this.width = FrameLayout.LayoutParams.WRAP_CONTENT;
    this.height = FrameLayout.LayoutParams.WRAP_CONTENT;
    this.priorityLevel = PRIORITY_MEDIUM;

    // Message TextView items
    this.messageTypefaceStyle = Typeface.NORMAL;
    this.messageTextColor = PaletteUtils.getSolidColor(PaletteUtils.WHITE);
    this.messageTextSize = TEXTSIZE_SMALL;
    this.messageIconPosition = ICONPOSITION_LEFT;

    // SuperActivityToast Button items
    this.buttonTypefaceStyle = Typeface.BOLD;
    this.buttonTextColor = PaletteUtils.getSolidColor(PaletteUtils.WHITE);
    this.buttonTextSize = TEXTSIZE_VERY_SMALL;
    this.buttonDividerColor = PaletteUtils.getSolidColor(PaletteUtils.WHITE);

    //SuperActivityToast Progress items
    this.progressBarColor = PaletteUtils.getSolidColor(PaletteUtils.WHITE);
    this.progressIndeterminate = true;
}
 
Example 17
Source File: KnifeText.java    From Knife with Apache License 2.0 5 votes vote down vote up
protected boolean containStyle(int style, int start, int end) {
    switch (style) {
        case Typeface.NORMAL:
        case Typeface.BOLD:
        case Typeface.ITALIC:
        case Typeface.BOLD_ITALIC:
            break;
        default:
            return false;
    }

    if (start > end) {
        return false;
    }

    if (start == end) {
        if (start - 1 < 0 || start + 1 > getEditableText().length()) {
            return false;
        } else {
            StyleSpan[] before = getEditableText().getSpans(start - 1, start, StyleSpan.class);
            StyleSpan[] after = getEditableText().getSpans(start, start + 1, StyleSpan.class);
            return before.length > 0 && after.length > 0 && before[0].getStyle() == style && after[0].getStyle() == style;
        }
    } else {
        StringBuilder builder = new StringBuilder();

        // Make sure no duplicate characters be added
        for (int i = start; i < end; i++) {
            StyleSpan[] spans = getEditableText().getSpans(i, i + 1, StyleSpan.class);
            for (StyleSpan span : spans) {
                if (span.getStyle() == style) {
                    builder.append(getEditableText().subSequence(i, i + 1).toString());
                    break;
                }
            }
        }

        return getEditableText().subSequence(start, end).toString().equals(builder.toString());
    }
}
 
Example 18
Source File: AndroidPaint.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
private static Typeface getTypeface(org.oscim.backend.canvas.Paint.FontFamily fontFamily,
                                    org.oscim.backend.canvas.Paint.FontStyle fontStyle) {
    final int style;
    switch (fontStyle) {
        case BOLD:
            style = Typeface.BOLD;
            break;
        case BOLD_ITALIC:
            style = Typeface.BOLD_ITALIC;
            break;
        case ITALIC:
            style = Typeface.ITALIC;
            break;
        default:
            style = Typeface.NORMAL;
            break;
    }

    switch (fontFamily) {
        case DEFAULT:
            return Typeface.create(Typeface.DEFAULT, style);
        case DEFAULT_BOLD:
            return Typeface.create(Typeface.DEFAULT_BOLD, style);
        case MONOSPACE:
            return Typeface.create(Typeface.MONOSPACE, style);
        case SANS_SERIF:
            return Typeface.create(Typeface.SANS_SERIF, style);
        case SERIF:
            return Typeface.create(Typeface.SERIF, style);
        case THIN:
            return Typeface.create("sans-serif-thin", style);
        case LIGHT:
            return Typeface.create("sans-serif-light", style);
        case MEDIUM:
            return Typeface.create("sans-serif-medium", style);
        case BLACK:
            return Typeface.create("sans-serif-black", style);
        case CONDENSED:
            return Typeface.create("sans-serif-condensed", style);
    }

    throw new IllegalArgumentException("unknown font family: " + fontFamily);
}
 
Example 19
Source File: FromTextView.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public void setText(Recipient recipient, boolean read, @Nullable String suffix) {
  String fromString = recipient.toShortString(getContext());

  int typeface;

  if (!read) {
    typeface = Typeface.BOLD;
  } else {
    typeface = Typeface.NORMAL;
  }

  SpannableStringBuilder builder = new SpannableStringBuilder();

  SpannableString fromSpan = new SpannableString(fromString);
  fromSpan.setSpan(new StyleSpan(typeface), 0, builder.length(),
                   Spannable.SPAN_INCLUSIVE_EXCLUSIVE);


  if (recipient.isLocalNumber()) {
    builder.append(getContext().getString(R.string.note_to_self));
  } else if (!FeatureFlags.profileDisplay() && recipient.getName(getContext()) == null && !recipient.getProfileName().isEmpty()) {
    SpannableString profileName = new SpannableString(" (~" + recipient.getProfileName().toString() + ") ");
    profileName.setSpan(new CenterAlignedRelativeSizeSpan(0.75f), 0, profileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    profileName.setSpan(new TypefaceSpan("sans-serif-light"), 0, profileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    profileName.setSpan(new ForegroundColorSpan(ResUtil.getColor(getContext(), R.attr.conversation_list_item_subject_color)), 0, profileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL){
      builder.append(profileName);
      builder.append(fromSpan);
    } else {
      builder.append(fromSpan);
      builder.append(profileName);
    }
  } else {
    builder.append(fromSpan);
  }

  if (suffix != null) {
    builder.append(suffix);
  }

  setText(builder);

  if      (recipient.isBlocked()) setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_block_grey600_18dp, 0, 0, 0);
  else if (recipient.isMuted())   setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_volume_off_grey600_18dp, 0, 0, 0);
  else                            setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
 
Example 20
Source File: ARTTextShadowNode.java    From art with MIT License 4 votes vote down vote up
private void applyTextPropertiesToPaint(Paint paint) {
  int alignment = mTextAlignment;
  switch (alignment) {
    case TEXT_ALIGNMENT_LEFT:
      paint.setTextAlign(Paint.Align.LEFT);
      break;
    case TEXT_ALIGNMENT_RIGHT:
      paint.setTextAlign(Paint.Align.RIGHT);
      break;
    case TEXT_ALIGNMENT_CENTER:
      paint.setTextAlign(Paint.Align.CENTER);
      break;
  }
  if (mFrame != null) {
    if (mFrame.hasKey(PROP_FONT)) {
      ReadableMap font = mFrame.getMap(PROP_FONT);
      if (font != null) {
        float fontSize = DEFAULT_FONT_SIZE;
        if (font.hasKey(PROP_FONT_SIZE)) {
          fontSize = (float) font.getDouble(PROP_FONT_SIZE);
        }
        paint.setTextSize(fontSize * mScale);
        boolean isBold =
            font.hasKey(PROP_FONT_WEIGHT) && "bold".equals(font.getString(PROP_FONT_WEIGHT));
        boolean isItalic =
            font.hasKey(PROP_FONT_STYLE) && "italic".equals(font.getString(PROP_FONT_STYLE));
        int fontStyle;
        if (isBold && isItalic) {
          fontStyle = Typeface.BOLD_ITALIC;
        } else if (isBold) {
          fontStyle = Typeface.BOLD;
        } else if (isItalic) {
          fontStyle = Typeface.ITALIC;
        } else {
          fontStyle = Typeface.NORMAL;
        }
        // NB: if the font family is null / unsupported, the default one will be used
        paint.setTypeface(Typeface.create(font.getString(PROP_FONT_FAMILY), fontStyle));
      }
    }
  }
}