use of android.graphics.Typeface in project HoloEverywhere by Prototik.
the class Switch method setSwitchTypefaceByIndex.
private void setSwitchTypefaceByIndex(int typefaceIndex, int styleIndex) {
Typeface tf = null;
switch(typefaceIndex) {
case SANS:
tf = Typeface.SANS_SERIF;
break;
case SERIF:
tf = Typeface.SERIF;
break;
case MONOSPACE:
tf = Typeface.MONOSPACE;
break;
}
setSwitchTypeface(tf, styleIndex);
}
use of android.graphics.Typeface in project Anki-Android by Ramblurr.
the class CardEditor method populateEditFields.
private void populateEditFields() {
mFieldsLayoutContainer.removeAllViews();
mEditFields = new LinkedList<FieldEditText>();
String[][] fields = mEditorNote.items();
// Use custom font if selected from preferences
Typeface mCustomTypeface = null;
SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
String customFont = preferences.getString("browserEditorFont", "");
if (!customFont.equals("")) {
mCustomTypeface = AnkiFont.getTypeface(this, customFont);
}
for (int i = 0; i < fields.length; i++) {
View editline_view = getLayoutInflater().inflate(R.layout.card_multimedia_editline, null);
FieldEditText newTextbox = (FieldEditText) editline_view.findViewById(R.id.id_note_editText);
initFieldEditText(newTextbox, i, fields[i], mCustomTypeface);
TextView label = newTextbox.getLabel();
label.setTextColor(Color.BLACK);
label.setPadding((int) UIUtils.getDensityAdjustedValue(this, 3.4f), 0, 0, 0);
mEditFields.add(newTextbox);
ImageButton mediaButton = (ImageButton) editline_view.findViewById(R.id.id_media_button);
mediaButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent editCard = new Intent(CardEditor.this, MultimediaCardEditorActivity.class);
if (!mAddNote) {
editCard.putExtra(CardEditor.EXTRA_CARD_ID, mCurrentEditedCard.getId());
} else {
editCard.putExtra(CardEditor.EXTRA_CARD_ID, 0);
}
startActivityForResult(editCard, REQUEST_MULTIMEDIA_EDIT);
}
});
mFieldsLayoutContainer.addView(label);
mFieldsLayoutContainer.addView(editline_view);
}
}
use of android.graphics.Typeface in project Titanic by RomainPiel.
the class Typefaces method get.
public static Typeface get(Context c, String assetPath) {
synchronized (cache) {
if (!cache.containsKey(assetPath)) {
try {
Typeface t = Typeface.createFromAsset(c.getAssets(), assetPath);
cache.put(assetPath, t);
} catch (Exception e) {
Log.e(TAG, "Could not get typeface '" + assetPath + "' because " + e.getMessage());
return null;
}
}
return cache.get(assetPath);
}
}
use of android.graphics.Typeface in project CustomFontLib by daniribalbert.
the class CustomFontUtils method getTypeFace.
public static Typeface getTypeFace(final TextView v, final AttributeSet attrs) {
final TypedArray tArray = v.getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.customFont, 0, 0);
String fontName = "";
try {
fontName = tArray.getString(R.styleable.customFont_font);
} finally {
tArray.recycle();
}
if (!TextUtils.isEmpty(fontName)) {
final int style;
final Typeface typeface = v.getTypeface();
if (typeface == null) {
style = Typeface.NORMAL;
} else {
style = typeface.getStyle();
}
String mFontName = getFontFile(v.getContext(), fontName, style);
if (sTypefaceMap.containsKey(mFontName)) {
return sTypefaceMap.get(mFontName);
}
Typeface newTypeface = typeface;
if (!TextUtils.isEmpty(mFontName)) {
try {
newTypeface = Typeface.createFromAsset(v.getContext().getAssets(), FONTS_DIR + "/" + mFontName);
} catch (Exception e) {
newTypeface = typeface;
}
}
sTypefaceMap.put(mFontName, newTypeface);
return newTypeface;
}
return null;
}
use of android.graphics.Typeface in project Calligraphy by chrisjenx.
the class CalligraphyFactory method onViewCreatedInternal.
void onViewCreatedInternal(View view, final Context context, AttributeSet attrs) {
if (view instanceof TextView) {
// TextView's inside the Toolbar/ActionBar).
if (TypefaceUtils.isLoaded(((TextView) view).getTypeface())) {
return;
}
// Try to get typeface attribute value
// Since we're not using namespace it's a little bit tricky
// Check xml attrs, style attrs and text appearance for font path
String textViewFont = resolveFontPath(context, attrs);
// Try theme attributes
if (TextUtils.isEmpty(textViewFont)) {
final int[] styleForTextView = getStyleForTextView((TextView) view);
if (styleForTextView[1] != -1)
textViewFont = CalligraphyUtils.pullFontPathFromTheme(context, styleForTextView[0], styleForTextView[1], mAttributeId);
else
textViewFont = CalligraphyUtils.pullFontPathFromTheme(context, styleForTextView[0], mAttributeId);
}
// Still need to defer the Native action bar, appcompat-v7:21+ uses the Toolbar underneath. But won't match these anyway.
final boolean deferred = matchesResourceIdName(view, ACTION_BAR_TITLE) || matchesResourceIdName(view, ACTION_BAR_SUBTITLE);
CalligraphyUtils.applyFontToTextView(context, (TextView) view, CalligraphyConfig.get(), textViewFont, deferred);
}
// Toolbar(Which underlies the ActionBar) for its children.
if (CalligraphyUtils.canCheckForV7Toolbar() && view instanceof android.support.v7.widget.Toolbar) {
final Toolbar toolbar = (Toolbar) view;
toolbar.getViewTreeObserver().addOnGlobalLayoutListener(new ToolbarLayoutListener(this, context, toolbar));
}
// Try to set typeface for custom views using interface method or via reflection if available
if (view instanceof HasTypeface) {
Typeface typeface = getDefaultTypeface(context, resolveFontPath(context, attrs));
if (typeface != null) {
((HasTypeface) view).setTypeface(typeface);
}
} else if (CalligraphyConfig.get().isCustomViewTypefaceSupport() && CalligraphyConfig.get().isCustomViewHasTypeface(view)) {
final Method setTypeface = ReflectionUtils.getMethod(view.getClass(), "setTypeface");
String fontPath = resolveFontPath(context, attrs);
Typeface typeface = getDefaultTypeface(context, fontPath);
if (setTypeface != null && typeface != null) {
ReflectionUtils.invokeMethod(view, setTypeface, typeface);
}
}
}
Aggregations