Search in sources :

Example 26 with Typeface

use of android.graphics.Typeface in project FlatUI by eluleci.

the class FlatCheckBox method init.

private void init(AttributeSet attrs) {
    if (attributes == null)
        attributes = new Attributes(this, getResources());
    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatCheckBox);
        // getting common attributes
        int customTheme = a.getResourceId(R.styleable.fl_FlatCheckBox_fl_theme, Attributes.DEFAULT_THEME);
        attributes.setThemeSilent(customTheme, getResources());
        attributes.setFontFamily(a.getString(R.styleable.fl_FlatCheckBox_fl_fontFamily));
        attributes.setFontWeight(a.getString(R.styleable.fl_FlatCheckBox_fl_fontWeight));
        attributes.setFontExtension(a.getString(R.styleable.fl_FlatCheckBox_fl_fontExtension));
        attributes.setSize(a.getDimensionPixelSize(R.styleable.fl_FlatCheckBox_fl_size, Attributes.DEFAULT_SIZE_PX));
        attributes.setRadius(a.getDimensionPixelSize(R.styleable.fl_FlatCheckBox_fl_cornerRadius, Attributes.DEFAULT_RADIUS_PX));
        attributes.setBorderWidth(attributes.getSize() / 10);
        // getting view specific attributes
        dotMargin = a.getDimensionPixelSize(R.styleable.fl_FlatCheckBox_fl_dotMargin, dotMargin);
        a.recycle();
    }
    // creating unchecked-enabled state drawable
    GradientDrawable uncheckedEnabled = new GradientDrawable();
    uncheckedEnabled.setCornerRadius(attributes.getRadius());
    uncheckedEnabled.setSize(attributes.getSize(), attributes.getSize());
    uncheckedEnabled.setColor(Color.TRANSPARENT);
    uncheckedEnabled.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
    // creating checked-enabled state drawable
    GradientDrawable checkedOutside = new GradientDrawable();
    checkedOutside.setCornerRadius(attributes.getRadius());
    checkedOutside.setSize(attributes.getSize(), attributes.getSize());
    checkedOutside.setColor(Color.TRANSPARENT);
    checkedOutside.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
    PaintDrawable checkedCore = new PaintDrawable(attributes.getColor(2));
    checkedCore.setCornerRadius(attributes.getRadius());
    checkedCore.setIntrinsicHeight(attributes.getSize());
    checkedCore.setIntrinsicWidth(attributes.getSize());
    InsetDrawable checkedInside = new InsetDrawable(checkedCore, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin);
    Drawable[] checkedEnabledDrawable = { checkedOutside, checkedInside };
    LayerDrawable checkedEnabled = new LayerDrawable(checkedEnabledDrawable);
    // creating unchecked-enabled state drawable
    GradientDrawable uncheckedDisabled = new GradientDrawable();
    uncheckedDisabled.setCornerRadius(attributes.getRadius());
    uncheckedDisabled.setSize(attributes.getSize(), attributes.getSize());
    uncheckedDisabled.setColor(Color.TRANSPARENT);
    uncheckedDisabled.setStroke(attributes.getBorderWidth(), attributes.getColor(3));
    // creating checked-disabled state drawable
    GradientDrawable checkedOutsideDisabled = new GradientDrawable();
    checkedOutsideDisabled.setCornerRadius(attributes.getRadius());
    checkedOutsideDisabled.setSize(attributes.getSize(), attributes.getSize());
    checkedOutsideDisabled.setColor(Color.TRANSPARENT);
    checkedOutsideDisabled.setStroke(attributes.getBorderWidth(), attributes.getColor(3));
    PaintDrawable checkedCoreDisabled = new PaintDrawable(attributes.getColor(3));
    checkedCoreDisabled.setCornerRadius(attributes.getRadius());
    checkedCoreDisabled.setIntrinsicHeight(attributes.getSize());
    checkedCoreDisabled.setIntrinsicWidth(attributes.getSize());
    InsetDrawable checkedInsideDisabled = new InsetDrawable(checkedCoreDisabled, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin);
    Drawable[] checkedDisabledDrawable = { checkedOutsideDisabled, checkedInsideDisabled };
    LayerDrawable checkedDisabled = new LayerDrawable(checkedDisabledDrawable);
    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { -android.R.attr.state_checked, android.R.attr.state_enabled }, uncheckedEnabled);
    states.addState(new int[] { android.R.attr.state_checked, android.R.attr.state_enabled }, checkedEnabled);
    states.addState(new int[] { -android.R.attr.state_checked, -android.R.attr.state_enabled }, uncheckedDisabled);
    states.addState(new int[] { android.R.attr.state_checked, -android.R.attr.state_enabled }, checkedDisabled);
    setButtonDrawable(states);
    // setting padding for avoiding text to appear on icon
    setPadding(attributes.getSize() / 4 * 5, 0, 0, 0);
    setTextColor(attributes.getColor(2));
    // check for IDE preview render
    if (!this.isInEditMode()) {
        Typeface typeface = FlatUI.getFont(getContext(), attributes);
        if (typeface != null)
            setTypeface(typeface);
    }
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray) LayerDrawable(android.graphics.drawable.LayerDrawable) Attributes(com.cengalabs.flatui.Attributes) LayerDrawable(android.graphics.drawable.LayerDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) Drawable(android.graphics.drawable.Drawable) PaintDrawable(android.graphics.drawable.PaintDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) PaintDrawable(android.graphics.drawable.PaintDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 27 with Typeface

use of android.graphics.Typeface in project FlatUI by eluleci.

the class FlatRadioButton method init.

private void init(AttributeSet attrs) {
    if (attributes == null)
        attributes = new Attributes(this, getResources());
    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatRadioButton);
        // getting common attributes
        int customTheme = a.getResourceId(R.styleable.fl_FlatRadioButton_fl_theme, Attributes.DEFAULT_THEME);
        attributes.setThemeSilent(customTheme, getResources());
        attributes.setFontFamily(a.getString(R.styleable.fl_FlatRadioButton_fl_fontFamily));
        attributes.setFontWeight(a.getString(R.styleable.fl_FlatRadioButton_fl_fontWeight));
        attributes.setFontExtension(a.getString(R.styleable.fl_FlatRadioButton_fl_fontExtension));
        attributes.setSize(a.getDimensionPixelSize(R.styleable.fl_FlatRadioButton_fl_size, Attributes.DEFAULT_SIZE_PX));
        attributes.setRadius(attributes.getSize() / 2);
        attributes.setBorderWidth(a.getDimensionPixelSize(R.styleable.fl_FlatRadioButton_fl_borderWidth, Attributes.DEFAULT_BORDER_WIDTH_PX));
        // getting view specific attributes
        dotMargin = a.getDimensionPixelSize(R.styleable.fl_FlatRadioButton_fl_dotMargin, dotMargin);
        a.recycle();
    }
    // creating unchecked-enabled state drawable
    GradientDrawable uncheckedEnabled = new GradientDrawable();
    uncheckedEnabled.setCornerRadius(attributes.getRadius());
    uncheckedEnabled.setSize(attributes.getSize(), attributes.getSize());
    uncheckedEnabled.setColor(Color.TRANSPARENT);
    uncheckedEnabled.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
    // creating checked-enabled state drawable
    GradientDrawable checkedOutside = new GradientDrawable();
    checkedOutside.setCornerRadius(attributes.getSize());
    checkedOutside.setSize(attributes.getSize(), attributes.getSize());
    checkedOutside.setColor(Color.TRANSPARENT);
    checkedOutside.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
    PaintDrawable checkedCore = new PaintDrawable(attributes.getColor(2));
    checkedCore.setCornerRadius(attributes.getSize());
    checkedCore.setIntrinsicHeight(attributes.getSize());
    checkedCore.setIntrinsicWidth(attributes.getSize());
    InsetDrawable checkedInside = new InsetDrawable(checkedCore, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin);
    Drawable[] checkedEnabledDrawable = { checkedOutside, checkedInside };
    LayerDrawable checkedEnabled = new LayerDrawable(checkedEnabledDrawable);
    // creating unchecked-enabled state drawable
    GradientDrawable uncheckedDisabled = new GradientDrawable();
    uncheckedDisabled.setCornerRadius(attributes.getRadius());
    uncheckedDisabled.setSize(attributes.getSize(), attributes.getSize());
    uncheckedDisabled.setColor(Color.TRANSPARENT);
    uncheckedDisabled.setStroke(attributes.getBorderWidth(), attributes.getColor(3));
    // creating checked-disabled state drawable
    GradientDrawable checkedOutsideDisabled = new GradientDrawable();
    checkedOutsideDisabled.setCornerRadius(attributes.getRadius());
    checkedOutsideDisabled.setSize(attributes.getSize(), attributes.getSize());
    checkedOutsideDisabled.setColor(Color.TRANSPARENT);
    checkedOutsideDisabled.setStroke(attributes.getBorderWidth(), attributes.getColor(3));
    PaintDrawable checkedCoreDisabled = new PaintDrawable(attributes.getColor(3));
    checkedCoreDisabled.setCornerRadius(attributes.getRadius());
    checkedCoreDisabled.setIntrinsicHeight(attributes.getSize());
    checkedCoreDisabled.setIntrinsicWidth(attributes.getSize());
    InsetDrawable checkedInsideDisabled = new InsetDrawable(checkedCoreDisabled, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin);
    Drawable[] checkedDisabledDrawable = { checkedOutsideDisabled, checkedInsideDisabled };
    LayerDrawable checkedDisabled = new LayerDrawable(checkedDisabledDrawable);
    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { -android.R.attr.state_checked, android.R.attr.state_enabled }, uncheckedEnabled);
    states.addState(new int[] { android.R.attr.state_checked, android.R.attr.state_enabled }, checkedEnabled);
    states.addState(new int[] { -android.R.attr.state_checked, -android.R.attr.state_enabled }, uncheckedDisabled);
    states.addState(new int[] { android.R.attr.state_checked, -android.R.attr.state_enabled }, checkedDisabled);
    setButtonDrawable(states);
    // setting padding for avoiding text to be appear on icon
    setPadding(attributes.getSize() / 4 * 5, 0, 0, 0);
    setTextColor(attributes.getColor(2));
    // check for IDE preview render
    if (!this.isInEditMode()) {
        Typeface typeface = FlatUI.getFont(getContext(), attributes);
        if (typeface != null)
            setTypeface(typeface);
    }
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray) LayerDrawable(android.graphics.drawable.LayerDrawable) Attributes(com.cengalabs.flatui.Attributes) LayerDrawable(android.graphics.drawable.LayerDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) Drawable(android.graphics.drawable.Drawable) PaintDrawable(android.graphics.drawable.PaintDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) PaintDrawable(android.graphics.drawable.PaintDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 28 with Typeface

use of android.graphics.Typeface in project TextSurface by elevenetc.

the class CookieThumperSample method play.

public static void play(TextSurface textSurface, AssetManager assetManager) {
    final Typeface robotoBlack = Typeface.createFromAsset(assetManager, "fonts/Roboto-Black.ttf");
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setTypeface(robotoBlack);
    Text textDaai = TextBuilder.create("Daai").setPaint(paint).setSize(64).setAlpha(0).setColor(Color.WHITE).setPosition(Align.SURFACE_CENTER).build();
    Text textBraAnies = TextBuilder.create("bra Anies").setPaint(paint).setSize(44).setAlpha(0).setColor(Color.RED).setPosition(Align.BOTTOM_OF, textDaai).build();
    Text textFokkenGamBra = TextBuilder.create(" hy's n fokken gam bra.").setPaint(paint).setSize(44).setAlpha(0).setColor(Color.RED).setPosition(Align.RIGHT_OF, textBraAnies).build();
    Text textHaai = TextBuilder.create("Haai!!").setPaint(paint).setSize(74).setAlpha(0).setColor(Color.RED).setPosition(Align.BOTTOM_OF, textFokkenGamBra).build();
    Text textDaaiAnies = TextBuilder.create("Daai Anies").setPaint(paint).setSize(44).setAlpha(0).setColor(Color.WHITE).setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textHaai).build();
    Text texThyLamInnie = TextBuilder.create(" hy lam innie mang ja.").setPaint(paint).setSize(44).setAlpha(0).setColor(Color.WHITE).setPosition(Align.RIGHT_OF, textDaaiAnies).build();
    Text textThrowDamn = TextBuilder.create("Throw damn").setPaint(paint).setSize(44).setAlpha(0).setColor(Color.RED).setPosition(Align.BOTTOM_OF | Align.CENTER_OF, texThyLamInnie).build();
    Text textDevilishGang = TextBuilder.create("devilish gang").setPaint(paint).setSize(44).setAlpha(0).setColor(Color.RED).setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textThrowDamn).build();
    Text textSignsInTheAir = TextBuilder.create("signs in the air.").setPaint(paint).setSize(44).setAlpha(0).setColor(Color.RED).setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textDevilishGang).build();
    textSurface.play(new Sequential(ShapeReveal.create(textDaai, 750, SideCut.show(Side.LEFT), false), new Parallel(ShapeReveal.create(textDaai, 600, SideCut.hide(Side.LEFT), false), new Sequential(Delay.duration(300), ShapeReveal.create(textDaai, 600, SideCut.show(Side.LEFT), false))), new Parallel(new TransSurface(500, textBraAnies, Pivot.CENTER), ShapeReveal.create(textBraAnies, 1300, SideCut.show(Side.LEFT), false)), Delay.duration(500), new Parallel(new TransSurface(750, textFokkenGamBra, Pivot.CENTER), Slide.showFrom(Side.LEFT, textFokkenGamBra, 750), ChangeColor.to(textFokkenGamBra, 750, Color.WHITE)), Delay.duration(500), new Parallel(TransSurface.toCenter(textHaai, 500), Rotate3D.showFromSide(textHaai, 750, Pivot.TOP)), new Parallel(TransSurface.toCenter(textDaaiAnies, 500), Slide.showFrom(Side.TOP, textDaaiAnies, 500)), new Parallel(TransSurface.toCenter(texThyLamInnie, 750), Slide.showFrom(Side.LEFT, texThyLamInnie, 500)), Delay.duration(500), new Parallel(new TransSurface(1500, textSignsInTheAir, Pivot.CENTER), new Sequential(new Sequential(ShapeReveal.create(textThrowDamn, 500, Circle.show(Side.CENTER, Direction.OUT), false)), new Sequential(ShapeReveal.create(textDevilishGang, 500, Circle.show(Side.CENTER, Direction.OUT), false)), new Sequential(ShapeReveal.create(textSignsInTheAir, 500, Circle.show(Side.CENTER, Direction.OUT), false)))), Delay.duration(200), new Parallel(ShapeReveal.create(textThrowDamn, 1500, SideCut.hide(Side.LEFT), true), new Sequential(Delay.duration(250), ShapeReveal.create(textDevilishGang, 1500, SideCut.hide(Side.LEFT), true)), new Sequential(Delay.duration(500), ShapeReveal.create(textSignsInTheAir, 1500, SideCut.hide(Side.LEFT), true)), Alpha.hide(texThyLamInnie, 1500), Alpha.hide(textDaaiAnies, 1500))));
}
Also used : TransSurface(su.levenetc.android.textsurface.animations.TransSurface) Sequential(su.levenetc.android.textsurface.animations.Sequential) Typeface(android.graphics.Typeface) Text(su.levenetc.android.textsurface.Text) Paint(android.graphics.Paint) Parallel(su.levenetc.android.textsurface.animations.Parallel)

Example 29 with Typeface

use of android.graphics.Typeface in project FlatUI by eluleci.

the class FlatAutoCompleteTextView method init.

private void init(AttributeSet attrs) {
    if (attributes == null)
        attributes = new Attributes(this, getResources());
    if (attrs != null) {
        // getting android default tags for textColor and textColorHint
        hasOwnTextColor = attrs.getAttributeValue(FlatUI.androidStyleNameSpace, "textColor") != null;
        hasOwnHintColor = attrs.getAttributeValue(FlatUI.androidStyleNameSpace, "textColorHint") != null;
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatAutoCompleteTextView);
        // getting common attributes
        int customTheme = a.getResourceId(R.styleable.fl_FlatAutoCompleteTextView_fl_theme, Attributes.DEFAULT_THEME);
        attributes.setThemeSilent(customTheme, getResources());
        attributes.setFontFamily(a.getString(R.styleable.fl_FlatAutoCompleteTextView_fl_fontFamily));
        attributes.setFontWeight(a.getString(R.styleable.fl_FlatAutoCompleteTextView_fl_fontWeight));
        attributes.setFontExtension(a.getString(R.styleable.fl_FlatAutoCompleteTextView_fl_fontExtension));
        attributes.setTextAppearance(a.getInt(R.styleable.fl_FlatAutoCompleteTextView_fl_textAppearance, Attributes.DEFAULT_TEXT_APPEARANCE));
        attributes.setRadius(a.getDimensionPixelSize(R.styleable.fl_FlatAutoCompleteTextView_fl_cornerRadius, Attributes.DEFAULT_RADIUS_PX));
        attributes.setBorderWidth(a.getDimensionPixelSize(R.styleable.fl_FlatAutoCompleteTextView_fl_borderWidth, Attributes.DEFAULT_BORDER_WIDTH_PX));
        // getting view specific attributes
        style = a.getInt(R.styleable.fl_FlatAutoCompleteTextView_fl_autoFieldStyle, 0);
        a.recycle();
    }
    GradientDrawable backgroundDrawable = new GradientDrawable();
    backgroundDrawable.setCornerRadius(attributes.getRadius());
    if (style == 0) {
        // flat
        if (!hasOwnTextColor)
            setTextColor(attributes.getColor(3));
        backgroundDrawable.setColor(attributes.getColor(2));
        backgroundDrawable.setStroke(0, attributes.getColor(2));
    } else if (style == 1) {
        // box
        if (!hasOwnTextColor)
            setTextColor(attributes.getColor(2));
        backgroundDrawable.setColor(Color.WHITE);
        backgroundDrawable.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
    } else if (style == 2) {
        // transparent
        if (!hasOwnTextColor)
            setTextColor(attributes.getColor(1));
        backgroundDrawable.setColor(Color.TRANSPARENT);
        backgroundDrawable.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
    }
    setBackgroundDrawable(backgroundDrawable);
    if (!hasOwnHintColor)
        setHintTextColor(attributes.getColor(3));
    if (attributes.getTextAppearance() == 1)
        setTextColor(attributes.getColor(0));
    else if (attributes.getTextAppearance() == 2)
        setTextColor(attributes.getColor(3));
    // check for IDE preview render
    if (!this.isInEditMode()) {
        Typeface typeface = FlatUI.getFont(getContext(), attributes);
        if (typeface != null)
            setTypeface(typeface);
    }
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray) Attributes(com.cengalabs.flatui.Attributes) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 30 with Typeface

use of android.graphics.Typeface in project RobotoViews by eeVoskos.

the class RobotoRadioButton method robotize.

private void robotize(Context context, AttributeSet attrs, int defStyle) {
    if (isInEditMode()) {
        return;
    }
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.RobotoRadioButton, defStyle, 0);
    int value = 0;
    try {
        value = a.getInteger(R.styleable.RobotoRadioButton_typeface, 0);
    } finally {
        a.recycle();
    }
    Typeface typeface = Roboto.getInstance(context).getTypeface(value);
    setTypeface(typeface);
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray)

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