-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemeted of direct/indirect subclasses of TextView with native support for the Roboto fonts (`RobotoAutoCompleteTextView`, `RobotoButton`, `RobotoCheckBox`, `RobotoCheckedTextView`, `RobotoChronometer`, `RobotoCompoundButton`, `RobotoDigitalClock`, `RobotoEditText`, `RobotoExtractEditText`, `RobotoMultiAutoCompleteTextView`, `RobotoRadioButton`, `RobotoSwitch`, `RobotoTextClock`, `RobotoToggleButton`).
- Loading branch information
Showing
21 changed files
with
1,607 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<declare-styleable name="RobotoTextView"> | ||
<attr name="typeface"/> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="RobotoAutoCompleteTextView"> | ||
<attr name="typeface"/> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="RobotoButton"> | ||
<attr name="typeface"/> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="RobotoCheckBox"> | ||
<attr name="typeface"/> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="RobotoCheckedTextView"> | ||
<attr name="typeface"/> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="RobotoChronometer"> | ||
<attr name="typeface"/> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="RobotoCompoundButton"> | ||
<attr name="typeface"/> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="RobotoDigitalClock"> | ||
<attr name="typeface"/> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="RobotoEditText"> | ||
<attr name="typeface"/> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="RobotoExtractEditText"> | ||
<attr name="typeface"/> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="RobotoMultiAutoCompleteTextView"> | ||
<attr name="typeface"/> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="RobotoRadioButton"> | ||
<attr name="typeface"/> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="RobotoSwitch"> | ||
<attr name="typeface"/> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="RobotoTextClock"> | ||
<attr name="typeface"/> | ||
</declare-styleable> | ||
|
||
<declare-styleable name="RobotoToggleButton"> | ||
<attr name="typeface"/> | ||
</declare-styleable> | ||
|
||
<!-- Changing the attribute must be reflected in the com.devspark.robototextview.RobotoTypefaceManager --> | ||
<attr name="typeface" format="enum"> | ||
<enum name="roboto_thin" value="0"/> | ||
<enum name="roboto_thin_italic" value="1"/> | ||
<enum name="roboto_light" value="2"/> | ||
<enum name="roboto_light_italic" value="3"/> | ||
<enum name="roboto_regular" value="4"/> | ||
<enum name="roboto_italic" value="5"/> | ||
<enum name="roboto_medium" value="6"/> | ||
<enum name="roboto_medium_italic" value="7"/> | ||
<enum name="roboto_bold" value="8"/> | ||
<enum name="roboto_bold_italic" value="9"/> | ||
<enum name="roboto_black" value="10"/> | ||
<enum name="roboto_black_italic" value="11"/> | ||
<enum name="roboto_condensed" value="12"/> | ||
<enum name="roboto_condensed_italic" value="13"/> | ||
<enum name="roboto_condensed_bold" value="14"/> | ||
<enum name="roboto_condensed_bold_italic" value="15"/> | ||
<enum name="robotoslab_thin" value="16"/> | ||
<enum name="robotoslab_light" value="17"/> | ||
<enum name="robotoslab_regular" value="18"/> | ||
<enum name="robotoslab_bold" value="19"/> | ||
</attr> | ||
|
||
</resources> |
138 changes: 138 additions & 0 deletions
138
src/com/devspark/robototextview/RobotoTypefaceManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package com.devspark.robototextview; | ||
|
||
import android.content.Context; | ||
import android.graphics.Typeface; | ||
import android.util.SparseArray; | ||
|
||
/** | ||
* The manager of roboto typefaces. | ||
* | ||
* @author e.shishkin | ||
*/ | ||
public class RobotoTypefaceManager { | ||
|
||
/* | ||
* Available values for the "typeface" attribute. | ||
*/ | ||
private final static int ROBOTO_THIN = 0; | ||
private final static int ROBOTO_THIN_ITALIC = 1; | ||
private final static int ROBOTO_LIGHT = 2; | ||
private final static int ROBOTO_LIGHT_ITALIC = 3; | ||
private final static int ROBOTO_REGULAR = 4; | ||
private final static int ROBOTO_ITALIC = 5; | ||
private final static int ROBOTO_MEDIUM = 6; | ||
private final static int ROBOTO_MEDIUM_ITALIC = 7; | ||
private final static int ROBOTO_BOLD = 8; | ||
private final static int ROBOTO_BOLD_ITALIC = 9; | ||
private final static int ROBOTO_BLACK = 10; | ||
private final static int ROBOTO_BLACK_ITALIC = 11; | ||
private final static int ROBOTO_CONDENSED = 12; | ||
private final static int ROBOTO_CONDENSED_ITALIC = 13; | ||
private final static int ROBOTO_CONDENSED_BOLD = 14; | ||
private final static int ROBOTO_CONDENSED_BOLD_ITALIC = 15; | ||
private final static int ROBOTOSLAB_THIN = 16; | ||
private final static int ROBOTOSLAB_LIGHT = 17; | ||
private final static int ROBOTOSLAB_REGULAR = 18; | ||
private final static int ROBOTOSLAB_BOLD = 19; | ||
|
||
/** | ||
* Array of created typefaces for later reused. | ||
*/ | ||
private final static SparseArray<Typeface> mTypefaces = new SparseArray<Typeface>(20); | ||
|
||
/** | ||
* Obtain typeface. | ||
* | ||
* @param context The Context the widget is running in, through which it can access the current theme, resources, etc. | ||
* @param typefaceValue The value of "typeface" attribute | ||
* @return specify {@link Typeface} | ||
* @throws IllegalArgumentException if unknown `typeface` attribute value. | ||
*/ | ||
public static Typeface obtaintTypeface(Context context, int typefaceValue) throws IllegalArgumentException { | ||
Typeface typeface = mTypefaces.get(typefaceValue); | ||
if (typeface == null) { | ||
typeface = createTypeface(context, typefaceValue); | ||
mTypefaces.put(typefaceValue, typeface); | ||
} | ||
return typeface; | ||
} | ||
|
||
/** | ||
* Create typeface from assets. | ||
* | ||
* @param context The Context the widget is running in, through which it can | ||
* access the current theme, resources, etc. | ||
* @param typefaceValue The value of "typeface" attribute | ||
* @return Roboto {@link Typeface} | ||
* @throws IllegalArgumentException if unknown `typeface` attribute value. | ||
*/ | ||
private static Typeface createTypeface(Context context, int typefaceValue) throws IllegalArgumentException { | ||
Typeface typeface; | ||
switch (typefaceValue) { | ||
case ROBOTO_THIN: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Thin.ttf"); | ||
break; | ||
case ROBOTO_THIN_ITALIC: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-ThinItalic.ttf"); | ||
break; | ||
case ROBOTO_LIGHT: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Light.ttf"); | ||
break; | ||
case ROBOTO_LIGHT_ITALIC: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-LightItalic.ttf"); | ||
break; | ||
case ROBOTO_REGULAR: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Regular.ttf"); | ||
break; | ||
case ROBOTO_ITALIC: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Italic.ttf"); | ||
break; | ||
case ROBOTO_MEDIUM: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Medium.ttf"); | ||
break; | ||
case ROBOTO_MEDIUM_ITALIC: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-MediumItalic.ttf"); | ||
break; | ||
case ROBOTO_BOLD: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Bold.ttf"); | ||
break; | ||
case ROBOTO_BOLD_ITALIC: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-BoldItalic.ttf"); | ||
break; | ||
case ROBOTO_BLACK: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Black.ttf"); | ||
break; | ||
case ROBOTO_BLACK_ITALIC: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-BlackItalic.ttf"); | ||
break; | ||
case ROBOTO_CONDENSED: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Condensed.ttf"); | ||
break; | ||
case ROBOTO_CONDENSED_ITALIC: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-CondensedItalic.ttf"); | ||
break; | ||
case ROBOTO_CONDENSED_BOLD: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-BoldCondensed.ttf"); | ||
break; | ||
case ROBOTO_CONDENSED_BOLD_ITALIC: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-BoldCondensedItalic.ttf"); | ||
break; | ||
case ROBOTOSLAB_THIN: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/RobotoSlab-Thin.ttf"); | ||
break; | ||
case ROBOTOSLAB_LIGHT: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/RobotoSlab-Light.ttf"); | ||
break; | ||
case ROBOTOSLAB_REGULAR: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/RobotoSlab-Regular.ttf"); | ||
break; | ||
case ROBOTOSLAB_BOLD: | ||
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/RobotoSlab-Bold.ttf"); | ||
break; | ||
default: | ||
throw new IllegalArgumentException("Unknown `typeface` attribute value " + typefaceValue); | ||
} | ||
return typeface; | ||
} | ||
|
||
} |
Oops, something went wrong.