Search in sources :

Example 11 with ColorStateList

use of android.content.res.ColorStateList in project FloatingActionButton by makovkastar.

the class FloatingActionButton method setBackgroundCompat.

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void setBackgroundCompat(Drawable drawable) {
    if (hasLollipopApi()) {
        float elevation;
        if (mShadow) {
            elevation = getElevation() > 0.0f ? getElevation() : getDimension(R.dimen.fab_elevation_lollipop);
        } else {
            elevation = 0.0f;
        }
        setElevation(elevation);
        RippleDrawable rippleDrawable = new RippleDrawable(new ColorStateList(new int[][] { {} }, new int[] { mColorRipple }), drawable, null);
        setOutlineProvider(new ViewOutlineProvider() {

            @Override
            public void getOutline(View view, Outline outline) {
                int size = getDimension(mType == TYPE_NORMAL ? R.dimen.fab_size_normal : R.dimen.fab_size_mini);
                outline.setOval(0, 0, size, size);
            }
        });
        setClipToOutline(true);
        setBackground(rippleDrawable);
    } else if (hasJellyBeanApi()) {
        setBackground(drawable);
    } else {
        setBackgroundDrawable(drawable);
    }
}
Also used : ColorStateList(android.content.res.ColorStateList) Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) View(android.view.View) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) RippleDrawable(android.graphics.drawable.RippleDrawable) SuppressLint(android.annotation.SuppressLint)

Example 12 with ColorStateList

use of android.content.res.ColorStateList in project material by rey5137.

the class SnackBar method applyStyle.

@Override
protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super.applyStyle(context, attrs, defStyleAttr, defStyleRes);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SnackBar, defStyleAttr, defStyleRes);
    int horizontalPadding = -1;
    int verticalPadding = -1;
    int textSize = -1;
    int textColor = 0;
    boolean textColorDefined = false;
    int textAppearance = 0;
    int actionTextSize = -1;
    ColorStateList actionTextColor = null;
    int actionTextAppearance = 0;
    for (int i = 0, count = a.getIndexCount(); i < count; i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.SnackBar_sb_backgroundColor)
            backgroundColor(a.getColor(attr, 0));
        else if (attr == R.styleable.SnackBar_sb_backgroundCornerRadius)
            backgroundRadius(a.getDimensionPixelSize(attr, 0));
        else if (attr == R.styleable.SnackBar_sb_horizontalPadding)
            horizontalPadding = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.SnackBar_sb_verticalPadding)
            verticalPadding = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.SnackBar_sb_width) {
            if (ThemeUtil.getType(a, attr) == TypedValue.TYPE_INT_DEC)
                width(a.getInteger(attr, 0));
            else
                width(a.getDimensionPixelSize(attr, 0));
        } else if (attr == R.styleable.SnackBar_sb_height) {
            if (ThemeUtil.getType(a, attr) == TypedValue.TYPE_INT_DEC)
                height(a.getInteger(attr, 0));
            else
                height(a.getDimensionPixelSize(attr, 0));
        } else if (attr == R.styleable.SnackBar_sb_minWidth)
            minWidth(a.getDimensionPixelSize(attr, 0));
        else if (attr == R.styleable.SnackBar_sb_maxWidth)
            maxWidth(a.getDimensionPixelSize(attr, 0));
        else if (attr == R.styleable.SnackBar_sb_minHeight)
            minHeight(a.getDimensionPixelSize(attr, 0));
        else if (attr == R.styleable.SnackBar_sb_maxHeight)
            maxHeight(a.getDimensionPixelSize(attr, 0));
        else if (attr == R.styleable.SnackBar_sb_marginStart)
            marginStart(a.getDimensionPixelSize(attr, 0));
        else if (attr == R.styleable.SnackBar_sb_marginBottom)
            marginBottom(a.getDimensionPixelSize(attr, 0));
        else if (attr == R.styleable.SnackBar_sb_textSize)
            textSize = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.SnackBar_sb_textColor) {
            textColor = a.getColor(attr, 0);
            textColorDefined = true;
        } else if (attr == R.styleable.SnackBar_sb_textAppearance)
            textAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.SnackBar_sb_text)
            text(a.getString(attr));
        else if (attr == R.styleable.SnackBar_sb_singleLine)
            singleLine(a.getBoolean(attr, true));
        else if (attr == R.styleable.SnackBar_sb_maxLines)
            maxLines(a.getInteger(attr, 0));
        else if (attr == R.styleable.SnackBar_sb_lines)
            lines(a.getInteger(attr, 0));
        else if (attr == R.styleable.SnackBar_sb_ellipsize) {
            int ellipsize = a.getInteger(attr, 0);
            switch(ellipsize) {
                case 1:
                    ellipsize(TruncateAt.START);
                    break;
                case 2:
                    ellipsize(TruncateAt.MIDDLE);
                    break;
                case 3:
                    ellipsize(TruncateAt.END);
                    break;
                case 4:
                    ellipsize(TruncateAt.MARQUEE);
                    break;
                default:
                    ellipsize(TruncateAt.END);
                    break;
            }
        } else if (attr == R.styleable.SnackBar_sb_actionTextSize)
            actionTextSize = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.SnackBar_sb_actionTextColor)
            actionTextColor = a.getColorStateList(attr);
        else if (attr == R.styleable.SnackBar_sb_actionTextAppearance)
            actionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.SnackBar_sb_actionText)
            actionText(a.getString(attr));
        else if (attr == R.styleable.SnackBar_sb_actionRipple)
            actionRipple(a.getResourceId(attr, 0));
        else if (attr == R.styleable.SnackBar_sb_duration)
            duration(a.getInteger(attr, 0));
        else if (attr == R.styleable.SnackBar_sb_removeOnDismiss)
            removeOnDismiss(a.getBoolean(attr, true));
        else if (attr == R.styleable.SnackBar_sb_inAnimation)
            animationIn(AnimationUtils.loadAnimation(getContext(), a.getResourceId(attr, 0)));
        else if (attr == R.styleable.SnackBar_sb_outAnimation)
            animationOut(AnimationUtils.loadAnimation(getContext(), a.getResourceId(attr, 0)));
    }
    a.recycle();
    if (horizontalPadding >= 0 || verticalPadding >= 0)
        padding(horizontalPadding >= 0 ? horizontalPadding : mText.getPaddingLeft(), verticalPadding >= 0 ? verticalPadding : mText.getPaddingTop());
    if (textAppearance != 0)
        textAppearance(textAppearance);
    if (textSize >= 0)
        textSize(textSize);
    if (textColorDefined)
        textColor(textColor);
    if (textAppearance != 0)
        actionTextAppearance(actionTextAppearance);
    if (actionTextSize >= 0)
        actionTextSize(actionTextSize);
    if (actionTextColor != null)
        actionTextColor(actionTextColor);
}
Also used : TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) Paint(android.graphics.Paint)

Example 13 with ColorStateList

use of android.content.res.ColorStateList in project material by rey5137.

the class Dialog method applyStyle.

public Dialog applyStyle(int resId) {
    Context context = getContext();
    TypedArray a = context.obtainStyledAttributes(resId, R.styleable.Dialog);
    int layout_width = mLayoutWidth;
    int layout_height = mLayoutHeight;
    boolean layoutParamsDefined = false;
    int titleTextAppearance = 0;
    int titleTextColor = 0;
    boolean titleTextColorDefined = false;
    int actionBackground = 0;
    int actionRipple = 0;
    int actionTextAppearance = 0;
    ColorStateList actionTextColors = null;
    int positiveActionBackground = 0;
    int positiveActionRipple = 0;
    int positiveActionTextAppearance = 0;
    ColorStateList positiveActionTextColors = null;
    int negativeActionBackground = 0;
    int negativeActionRipple = 0;
    int negativeActionTextAppearance = 0;
    ColorStateList negativeActionTextColors = null;
    int neutralActionBackground = 0;
    int neutralActionRipple = 0;
    int neutralActionTextAppearance = 0;
    ColorStateList neutralActionTextColors = null;
    for (int i = 0, count = a.getIndexCount(); i < count; i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.Dialog_android_layout_width) {
            layout_width = a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParamsDefined = true;
        } else if (attr == R.styleable.Dialog_android_layout_height) {
            layout_height = a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParamsDefined = true;
        } else if (attr == R.styleable.Dialog_di_maxWidth)
            maxWidth(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_maxHeight)
            maxHeight(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_dimAmount)
            dimAmount(a.getFloat(attr, 0));
        else if (attr == R.styleable.Dialog_di_backgroundColor)
            backgroundColor(a.getColor(attr, 0));
        else if (attr == R.styleable.Dialog_di_maxElevation)
            maxElevation(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_elevation)
            elevation(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_cornerRadius)
            cornerRadius(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_layoutDirection)
            layoutDirection(a.getInteger(attr, 0));
        else if (attr == R.styleable.Dialog_di_titleTextAppearance)
            titleTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_titleTextColor) {
            titleTextColor = a.getColor(attr, 0);
            titleTextColorDefined = true;
        } else if (attr == R.styleable.Dialog_di_actionBackground)
            actionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_actionRipple)
            actionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_actionTextAppearance)
            actionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_actionTextColor)
            actionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_positiveActionBackground)
            positiveActionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_positiveActionRipple)
            positiveActionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_positiveActionTextAppearance)
            positiveActionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_positiveActionTextColor)
            positiveActionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_negativeActionBackground)
            negativeActionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_negativeActionRipple)
            negativeActionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_negativeActionTextAppearance)
            negativeActionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_negativeActionTextColor)
            negativeActionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_neutralActionBackground)
            neutralActionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_neutralActionRipple)
            neutralActionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_neutralActionTextAppearance)
            neutralActionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_neutralActionTextColor)
            neutralActionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_inAnimation)
            inAnimation(a.getResourceId(attr, 0));
        else if (attr == R.styleable.Dialog_di_outAnimation)
            outAnimation(a.getResourceId(attr, 0));
        else if (attr == R.styleable.Dialog_di_dividerColor)
            dividerColor(a.getColor(attr, 0));
        else if (attr == R.styleable.Dialog_di_dividerHeight)
            dividerHeight(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_cancelable)
            cancelable(a.getBoolean(attr, true));
        else if (attr == R.styleable.Dialog_di_canceledOnTouchOutside)
            canceledOnTouchOutside(a.getBoolean(attr, true));
    }
    a.recycle();
    if (layoutParamsDefined)
        layoutParams(layout_width, layout_height);
    if (titleTextAppearance != 0)
        titleTextAppearance(titleTextAppearance);
    if (titleTextColorDefined)
        titleColor(titleTextColor);
    if (actionBackground != 0)
        actionBackground(actionBackground);
    if (actionRipple != 0)
        actionRipple(actionRipple);
    if (actionTextAppearance != 0)
        actionTextAppearance(actionTextAppearance);
    if (actionTextColors != null)
        actionTextColor(actionTextColors);
    if (positiveActionBackground != 0)
        positiveActionBackground(positiveActionBackground);
    if (positiveActionRipple != 0)
        positiveActionRipple(positiveActionRipple);
    if (positiveActionTextAppearance != 0)
        positiveActionTextAppearance(positiveActionTextAppearance);
    if (positiveActionTextColors != null)
        positiveActionTextColor(positiveActionTextColors);
    if (negativeActionBackground != 0)
        negativeActionBackground(negativeActionBackground);
    if (negativeActionRipple != 0)
        negativeActionRipple(negativeActionRipple);
    if (negativeActionTextAppearance != 0)
        negativeActionTextAppearance(negativeActionTextAppearance);
    if (negativeActionTextColors != null)
        negativeActionTextColor(negativeActionTextColors);
    if (neutralActionBackground != 0)
        neutralActionBackground(neutralActionBackground);
    if (neutralActionRipple != 0)
        neutralActionRipple(neutralActionRipple);
    if (neutralActionTextAppearance != 0)
        neutralActionTextAppearance(neutralActionTextAppearance);
    if (neutralActionTextColors != null)
        neutralActionTextColor(neutralActionTextColors);
    return this;
}
Also used : Context(android.content.Context) TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) Paint(android.graphics.Paint)

Example 14 with ColorStateList

use of android.content.res.ColorStateList in project fresco by facebook.

the class DraweeView method init.

/** This method is idempotent so it only has effect the first time it's called */
private void init(Context context) {
    if (mInitialised) {
        return;
    }
    mInitialised = true;
    mDraweeHolder = DraweeHolder.create(null, context);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ColorStateList imageTintList = getImageTintList();
        if (imageTintList == null) {
            return;
        }
        setColorFilter(imageTintList.getDefaultColor());
    }
}
Also used : ColorStateList(android.content.res.ColorStateList)

Example 15 with ColorStateList

use of android.content.res.ColorStateList in project SwipeRecyclerView by yanzhenjie.

the class SwipeMenuView method createTitle.

private TextView createTitle(SwipeMenuItem item) {
    TextView textView = new TextView(getContext());
    textView.setText(item.getText());
    textView.setGravity(Gravity.CENTER);
    int textSize = item.getTextSize();
    if (textSize > 0)
        textView.setTextSize(textSize);
    ColorStateList textColor = item.getTitleColor();
    if (textColor != null)
        textView.setTextColor(textColor);
    int textAppearance = item.getTextAppearance();
    if (textAppearance != 0)
        ResCompat.setTextAppearance(textView, textAppearance);
    Typeface typeface = item.getTextTypeface();
    if (typeface != null)
        textView.setTypeface(typeface);
    return textView;
}
Also used : Typeface(android.graphics.Typeface) ColorStateList(android.content.res.ColorStateList) TextView(android.widget.TextView)

Aggregations

ColorStateList (android.content.res.ColorStateList)280 Paint (android.graphics.Paint)90 TypedArray (android.content.res.TypedArray)76 Drawable (android.graphics.drawable.Drawable)48 TextPaint (android.text.TextPaint)42 Resources (android.content.res.Resources)25 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)22 TypedValue (android.util.TypedValue)21 TextView (android.widget.TextView)19 Context (android.content.Context)18 SuppressLint (android.annotation.SuppressLint)17 SmallTest (android.test.suitebuilder.annotation.SmallTest)13 AllCapsTransformationMethod (android.text.method.AllCapsTransformationMethod)13 RippleDrawable (android.graphics.drawable.RippleDrawable)12 StateListDrawable (android.graphics.drawable.StateListDrawable)12 View (android.view.View)12 Nullable (android.annotation.Nullable)10 Bitmap (android.graphics.Bitmap)10 TextAppearanceSpan (android.text.style.TextAppearanceSpan)9 PorterDuff (android.graphics.PorterDuff)8