Search in sources :

Example 1 with DefaultBootstrapBrand

use of com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapBrand in project Android-Bootstrap by Bearded-Hen.

the class BootstrapDrawableFactory method bootstrapButtonText.

/**
     * Generates a colorstatelist for a bootstrap button
     *
     * @param context the current context
     * @param outline whether the button is outlined
     * @param brand   the button brand
     * @return the color state list
     */
static ColorStateList bootstrapButtonText(Context context, boolean outline, BootstrapBrand brand) {
    int defaultColor = outline ? brand.defaultFill(context) : brand.defaultTextColor(context);
    int activeColor = outline ? ColorUtils.resolveColor(android.R.color.white, context) : brand.activeTextColor(context);
    int disabledColor = outline ? brand.disabledFill(context) : brand.disabledTextColor(context);
    if (outline && brand instanceof DefaultBootstrapBrand) {
        // special case
        DefaultBootstrapBrand db = (DefaultBootstrapBrand) brand;
        if (db == DefaultBootstrapBrand.SECONDARY) {
            defaultColor = ColorUtils.resolveColor(R.color.bootstrap_brand_secondary_border, context);
            disabledColor = defaultColor;
        }
    }
    return new ColorStateList(getStateList(), getColorList(defaultColor, activeColor, disabledColor));
}
Also used : DefaultBootstrapBrand(com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapBrand) ColorStateList(android.content.res.ColorStateList) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 2 with DefaultBootstrapBrand

use of com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapBrand in project Android-Bootstrap by Bearded-Hen.

the class BootstrapDrawableFactory method bootstrapButton.

/**
     * Generates a background drawable for a Bootstrap Button
     *
     * @param context      the current context
     * @param brand        the bootstrap brand
     * @param strokeWidth  the stroke width in px
     * @param cornerRadius the corner radius in px
     * @param position     the position of the button in its parent view
     * @param showOutline  whether the button should be outlined
     * @param rounded      whether the corners should be rounded
     * @return a background drawable for the BootstrapButton
     */
static Drawable bootstrapButton(Context context, BootstrapBrand brand, int strokeWidth, int cornerRadius, ViewGroupPosition position, boolean showOutline, boolean rounded) {
    GradientDrawable defaultGd = new GradientDrawable();
    GradientDrawable activeGd = new GradientDrawable();
    GradientDrawable disabledGd = new GradientDrawable();
    defaultGd.setColor(showOutline ? Color.TRANSPARENT : brand.defaultFill(context));
    activeGd.setColor(showOutline ? brand.activeFill(context) : brand.activeFill(context));
    disabledGd.setColor(showOutline ? Color.TRANSPARENT : brand.disabledFill(context));
    defaultGd.setStroke(strokeWidth, brand.defaultEdge(context));
    activeGd.setStroke(strokeWidth, brand.activeEdge(context));
    disabledGd.setStroke(strokeWidth, brand.disabledEdge(context));
    if (showOutline && brand instanceof DefaultBootstrapBrand) {
        DefaultBootstrapBrand db = (DefaultBootstrapBrand) brand;
        if (db == DefaultBootstrapBrand.SECONDARY) {
            int color = ColorUtils.resolveColor(R.color.bootstrap_brand_secondary_border, context);
            defaultGd.setStroke(strokeWidth, color);
            activeGd.setStroke(strokeWidth, color);
            disabledGd.setStroke(strokeWidth, color);
        }
    }
    setupDrawableCorners(position, rounded, cornerRadius, defaultGd, activeGd, disabledGd);
    return setupStateDrawable(position, strokeWidth, defaultGd, activeGd, disabledGd);
}
Also used : DefaultBootstrapBrand(com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapBrand) GradientDrawable(android.graphics.drawable.GradientDrawable) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Aggregations

Paint (android.graphics.Paint)2 TextPaint (android.text.TextPaint)2 DefaultBootstrapBrand (com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapBrand)2 ColorStateList (android.content.res.ColorStateList)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1