Search in sources :

Example 61 with Typeface

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);
}
Also used : Typeface(android.graphics.Typeface)

Example 62 with Typeface

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);
    }
}
Also used : MultimediaCardEditorActivity(com.ichi2.anki.multimediacard.activity.MultimediaCardEditorActivity) Typeface(android.graphics.Typeface) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ImageButton(android.widget.ImageButton) TextView(android.widget.TextView)

Example 63 with Typeface

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);
    }
}
Also used : Typeface(android.graphics.Typeface)

Example 64 with Typeface

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;
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray)

Example 65 with Typeface

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);
        }
    }
}
Also used : Toolbar(android.support.v7.widget.Toolbar) Typeface(android.graphics.Typeface) TextView(android.widget.TextView) Method(java.lang.reflect.Method) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Typeface (android.graphics.Typeface)266 Paint (android.graphics.Paint)57 TextPaint (android.text.TextPaint)40 TypedArray (android.content.res.TypedArray)34 TextView (android.widget.TextView)21 View (android.view.View)20 Canvas (android.graphics.Canvas)15 Bitmap (android.graphics.Bitmap)13 Context (android.content.Context)11 Resources (android.content.res.Resources)10 Test (org.junit.Test)8 ColorStateList (android.content.res.ColorStateList)7 Legend (com.github.mikephil.charting.components.Legend)7 File (java.io.File)7 Intent (android.content.Intent)6 Attributes (com.cengalabs.flatui.Attributes)6 XAxis (com.github.mikephil.charting.components.XAxis)6 YAxis (com.github.mikephil.charting.components.YAxis)6 ContentResolver (android.content.ContentResolver)5 Drawable (android.graphics.drawable.Drawable)5