Android Open Source - Llama Custom Typeface Span






From Project

Back to project page Llama.

License

The source code is released under:

MIT License

If you think the Android project Llama listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package io.github.nick11roberts.llamaspawningbuttonthing;
/* w  ww .  j a  v  a 2  s .co m*/
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.text.style.TypefaceSpan;

public class CustomTypefaceSpan extends TypefaceSpan {

    private final Typeface newType;

    public CustomTypefaceSpan(String family, Typeface type) {
        super(family);
        newType = type;
    }

    @Override
    public void updateDrawState(TextPaint ds) {
        applyCustomTypeFace(ds, newType);
    }

    @Override
    public void updateMeasureState(TextPaint paint) {
        applyCustomTypeFace(paint, newType);
    }

    private static void applyCustomTypeFace(Paint paint, Typeface tf) {
        int oldStyle;
        Typeface old = paint.getTypeface();
        if (old == null) {
            oldStyle = 0;
        } else {
            oldStyle = old.getStyle();
        }

        int fake = oldStyle & ~tf.getStyle();
        if ((fake & Typeface.BOLD) != 0) {
            paint.setFakeBoldText(true);
        }

        if ((fake & Typeface.ITALIC) != 0) {
            paint.setTextSkewX(-0.25f);
        }

        paint.setTypeface(tf);
    }
}




Java Source Code List

io.github.nick11roberts.llamaspawningbuttonthing.AnuRandom.java
io.github.nick11roberts.llamaspawningbuttonthing.ApplicationTest.java
io.github.nick11roberts.llamaspawningbuttonthing.AsyncTaskParams.java
io.github.nick11roberts.llamaspawningbuttonthing.CustomTypefaceSpan.java
io.github.nick11roberts.llamaspawningbuttonthing.CustomTypefaceTextView.java
io.github.nick11roberts.llamaspawningbuttonthing.ListenerService.java
io.github.nick11roberts.llamaspawningbuttonthing.LlamaActivity.java
io.github.nick11roberts.llamaspawningbuttonthing.LlamaWearActivity.java
io.github.nick11roberts.llamaspawningbuttonthing.RandomLlamaAttributes.java
io.github.nick11roberts.llamaspawningbuttonthing.RetrieveQRandResponse.java
io.github.nick11roberts.llamaspawningbuttonthing.RetrieveQRandTask.java
io.github.nick11roberts.llamaspawningbuttonthing.SendToDataLayerThread.java
io.github.nick11roberts.llamaspawningbuttonthing.UniqueViewIdCreator.java