Skip to content

Commit

Permalink
updated with newest fonts from AOSP
Browse files Browse the repository at this point in the history
  • Loading branch information
corsc committed Feb 12, 2014
1 parent a3e0776 commit e84aa91
Show file tree
Hide file tree
Showing 22 changed files with 122 additions and 72 deletions.
Binary file modified library/res/raw/roboto_black.ttf
Binary file not shown.
Binary file modified library/res/raw/roboto_black_italic.ttf
Binary file not shown.
Binary file modified library/res/raw/roboto_bold.ttf
Binary file not shown.
Binary file modified library/res/raw/roboto_bold_condensed.ttf
Binary file not shown.
Binary file modified library/res/raw/roboto_bold_condensed_italic.ttf
Binary file not shown.
Binary file modified library/res/raw/roboto_bold_italic.ttf
Binary file not shown.
Binary file modified library/res/raw/roboto_condensed.ttf
Binary file not shown.
Binary file modified library/res/raw/roboto_condensed_italic.ttf
Binary file not shown.
Binary file added library/res/raw/roboto_condensed_light.ttf
Binary file not shown.
Binary file not shown.
Binary file modified library/res/raw/roboto_light.ttf
Binary file not shown.
Binary file modified library/res/raw/roboto_light_italic.ttf
Binary file not shown.
Binary file modified library/res/raw/roboto_medium.ttf
Binary file not shown.
Binary file modified library/res/raw/roboto_medium_italic.ttf
Binary file not shown.
Binary file modified library/res/raw/roboto_regular.ttf
Binary file not shown.
Binary file modified library/res/raw/roboto_regular_italic.ttf
Binary file not shown.
Binary file modified library/res/raw/roboto_thin.ttf
Binary file not shown.
Binary file modified library/res/raw/roboto_thin_italic.ttf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,10 @@
*
* @author Corey Scott (corey.scott@sage42.com)
*
* Reference: http://sriramramani.wordpress.com/2012/11/29/custom-fonts/
*/
public class FontManager
{
public static final String FONT_NAME_ROBOTO_THIN = "roboto-thin"; //$NON-NLS-1$
public static final String FONT_NAME_ROBOTO_LIGHT = "roboto-light"; //$NON-NLS-1$
public static final String FONT_NAME_ROBOTO_REGULAR = "roboto-regular"; //$NON-NLS-1$
public static final String FONT_NAME_ROBOTO_MEDIUM = "roboto-medium"; //$NON-NLS-1$
public static final String FONT_NAME_ROBOTO_BOLD = "roboto-bold"; //$NON-NLS-1$
public static final String FONT_NAME_ROBOTO_BLACK = "roboto-black"; //$NON-NLS-1$
public static final String FONT_NAME_ROBOTO_CONDENSED = "roboto-condensed"; //$NON-NLS-1$
public static final String FONT_NAME_ROBOTO_BOLD_CONDENSED = "roboto-bold-condensed"; //$NON-NLS-1$

private static final String TAG = FontManager.class.getSimpleName();
private static final String TAG = FontManager.class.getSimpleName();

private final Map<String, Font> mFonts;

Expand Down Expand Up @@ -146,56 +136,22 @@ private void loadFont(final Context context, final String fontFamily)
{
final String fontFamilyLower = fontFamily.toLowerCase(Locale.US);

if (fontFamilyLower.equals(FontManager.FONT_NAME_ROBOTO_THIN))
{
this.mFonts.put(fontFamilyLower, this.addFont(context, FontManager.FONT_NAME_ROBOTO_THIN,
R.raw.roboto_thin, R.raw.roboto_thin_italic));
}
else if (fontFamilyLower.equals(FontManager.FONT_NAME_ROBOTO_LIGHT))
{
this.mFonts.put(fontFamilyLower, this.addFont(context, FontManager.FONT_NAME_ROBOTO_LIGHT,
R.raw.roboto_light, R.raw.roboto_light_italic));
}
else if (fontFamilyLower.equals(FontManager.FONT_NAME_ROBOTO_REGULAR))
{
this.mFonts.put(fontFamilyLower, this.addFont(context, FontManager.FONT_NAME_ROBOTO_REGULAR,
R.raw.roboto_regular, R.raw.roboto_regular_italic));
}
else if (fontFamilyLower.equals(FontManager.FONT_NAME_ROBOTO_MEDIUM))
{
this.mFonts.put(fontFamilyLower, this.addFont(context, FontManager.FONT_NAME_ROBOTO_MEDIUM,
R.raw.roboto_medium, R.raw.roboto_medium_italic));
}
else if (fontFamilyLower.equals(FontManager.FONT_NAME_ROBOTO_BOLD))
RobotoTypes type = RobotoTypes.getByFamilyName(fontFamily);
if (type == null)
{
this.mFonts.put(fontFamilyLower, this.addFont(context, FontManager.FONT_NAME_ROBOTO_BOLD,
R.raw.roboto_bold, R.raw.roboto_bold_italic));
}
else if (fontFamilyLower.equals(FontManager.FONT_NAME_ROBOTO_BLACK))
{
this.mFonts.put(fontFamilyLower, this.addFont(context, FontManager.FONT_NAME_ROBOTO_BLACK,
R.raw.roboto_black, R.raw.roboto_black_italic));
}
else if (fontFamilyLower.equals(FontManager.FONT_NAME_ROBOTO_CONDENSED))
{
this.mFonts.put(fontFamilyLower, this.addFont(context, FontManager.FONT_NAME_ROBOTO_CONDENSED,
R.raw.roboto_condensed, R.raw.roboto_condensed_italic));
}
else if (fontFamilyLower.equals(FontManager.FONT_NAME_ROBOTO_BOLD_CONDENSED))
{
this.mFonts.put(fontFamilyLower, this.addFont(context, FontManager.FONT_NAME_ROBOTO_BOLD_CONDENSED,
R.raw.roboto_bold_condensed, R.raw.roboto_bold_condensed_italic));
Log.e(FontManager.TAG, "Failed to load font, unknown fontFamily: " + fontFamilyLower); //$NON-NLS-1$
}
else
{
Log.e(FontManager.TAG, "Failed to load font, unknown fontFamily: " + fontFamilyLower); //$NON-NLS-1$
this.mFonts.put(fontFamilyLower,
this.addFont(context, type.getFontName(), type.getNormalResId(), type.getItalicResId()));
}
}

/**
* Extend this class and override this method for custom error handling.
*
* @param exception
* @param exception
*/
public void logError(final Exception exception)
{
Expand Down Expand Up @@ -275,7 +231,7 @@ public void addCustomFont(final Context context, final String fontFamily, final

public static Typeface extractTypeface(final Context context, final AttributeSet attrs)
{
// Fonts work as a combination of particular family and the style.
// Fonts work as a combination of particular family and the style.
final TypedArray args = context.obtainStyledAttributes(attrs, R.styleable.fonts);
final String family = args.getString(R.styleable.fonts_fontFamily);
final int style = args.getInt(R.styleable.fonts_android_textStyle, -1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.sage42.android.view.fonts;

import java.util.Locale;

import com.sage42.android.view.R;

public enum RobotoTypes
{
BLACK("roboto-black", R.raw.roboto_black, R.raw.roboto_black_italic), //$NON-NLS-1$
BOLD("roboto-bold", R.raw.roboto_bold, R.raw.roboto_bold_italic), //$NON-NLS-1$
BOLD_CONDENSED("roboto-bold-condensed", R.raw.roboto_bold_condensed, R.raw.roboto_bold_condensed_italic), //$NON-NLS-1$
CONDENSED("roboto-condensed", R.raw.roboto_condensed, R.raw.roboto_condensed_italic), //$NON-NLS-1$
CONDENSED_LIGHT("roboto-condensed-light", R.raw.roboto_condensed_light, R.raw.roboto_condensed_light_italic), //$NON-NLS-1$
LIGHT("roboto-light", R.raw.roboto_light, R.raw.roboto_light_italic), //$NON-NLS-1$
MEDIUM("roboto-medium", R.raw.roboto_medium, R.raw.roboto_medium_italic), //$NON-NLS-1$
REGULAR("roboto-regular", R.raw.roboto_regular, R.raw.roboto_regular_italic), //$NON-NLS-1$
THIN("roboto-thin", R.raw.roboto_thin, R.raw.roboto_thin_italic); //$NON-NLS-1$

private final String mFontName;
private int mNormalResId;
private int mItalicResId;

private RobotoTypes(final String fontName, final int normalResId, final int italicResId)
{
this.mFontName = fontName;
this.mNormalResId = normalResId;
this.mItalicResId = italicResId;
}

public static RobotoTypes getByFamilyName(final String familyName)
{
if ((familyName == null) || (familyName.length() == 0))
{
// sanity check
return null;
}

final String familyNameLower = familyName.toLowerCase(Locale.US);
for (final RobotoTypes thisFamily : RobotoTypes.values())
{
if (thisFamily.getFontName().toLowerCase(Locale.US).equals(familyNameLower))
{
return thisFamily;
}
}

return null;
}

/**
* @return the fontName
*/
public String getFontName()
{
return this.mFontName;
}

/**
* @return the normalResId
*/
public int getNormalResId()
{
return this.mNormalResId;
}

/**
* @return the italicResId
*/
public int getItalicResId()
{
return this.mItalicResId;
}
}
59 changes: 39 additions & 20 deletions samples/res/layout/custom_fonts_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,45 @@
android:textStyle="italic"
sage42:fontFamily="Roboto-Black" />

<com.sage42.android.view.fonts.MyTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:text="@string/custom_font_roboto_condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
sage42:fontFamily="Roboto-Condensed" />

<com.sage42.android.view.fonts.MyTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:text="@string/custom_font_roboto_condensed_italic"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="italic"
sage42:fontFamily="Roboto-Condensed" />

<com.sage42.android.view.fonts.MyTextView
<com.sage42.android.view.fonts.MyTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:text="@string/custom_font_roboto_condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
sage42:fontFamily="Roboto-Condensed" />

<com.sage42.android.view.fonts.MyTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:text="@string/custom_font_roboto_condensed_italic"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="italic"
sage42:fontFamily="Roboto-Condensed" />

<com.sage42.android.view.fonts.MyTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:text="@string/custom_font_roboto_condensed_light"
android:textAppearance="?android:attr/textAppearanceMedium"
sage42:fontFamily="Roboto-Condensed-Light" />

<com.sage42.android.view.fonts.MyTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:text="@string/custom_font_roboto_condensed_light_italic"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="italic"
sage42:fontFamily="Roboto-Condensed-Light" />

<com.sage42.android.view.fonts.MyTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
Expand Down
2 changes: 2 additions & 0 deletions samples/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<string name="custom_font_roboto_black_italic">Roboto Black Italic</string>
<string name="custom_font_roboto_condensed">Roboto Condensed</string>
<string name="custom_font_roboto_condensed_italic">Roboto Condensed Italic</string>
<string name="custom_font_roboto_condensed_light">Roboto Condensed Light</string>
<string name="custom_font_roboto_condensed_light_italic">Roboto Condensed Light Italic</string>
<string name="custom_font_roboto_bold_condensed">Roboto Bold Condensed</string>
<string name="custom_font_roboto_bold_condensed_italic">Roboto Bold Condensed Italic</string>
<string name="custom_font_baroque_script">Baroque Script from www.1001freefonts.com</string>
Expand Down

0 comments on commit e84aa91

Please sign in to comment.