Search in sources :

Example 1 with ColorStateListDrawable

use of carbon.drawable.ColorStateListDrawable in project Carbon by ZieIony.

the class FloatingActionButton method initFloatingActionButton.

private void initFloatingActionButton(AttributeSet attrs, int defStyleAttr) {
    AnimUtils.setupElevationAnimator(getStateAnimator(), this);
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, R.style.carbon_FloatingActionButton);
    setCornerRadius(a.getDimension(R.styleable.FloatingActionButton_carbon_cornerRadius, -1));
    if (a.hasValue(R.styleable.FloatingActionButton_carbon_menu)) {
        int resId = a.getResourceId(R.styleable.FloatingActionButton_carbon_menu, 0);
        if (resId != 0)
            setMenu(resId);
    }
    TypedValue bg = new TypedValue();
    a.getValue(R.styleable.FloatingActionButton_android_background, bg);
    if (bg.type >= TypedValue.TYPE_FIRST_COLOR_INT && bg.type <= TypedValue.TYPE_LAST_COLOR_INT && bg.data == 0)
        setBackgroundDrawable(new ColorStateListDrawable(AnimatedColorStateList.fromList(new DefaultAccentColorStateList(getContext()), animation -> postInvalidate())));
    a.recycle();
}
Also used : DefaultAccentColorStateList(carbon.drawable.DefaultAccentColorStateList) Context(android.content.Context) R(carbon.R) ColorStateListDrawable(carbon.drawable.ColorStateListDrawable) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) ColorStateList(android.content.res.ColorStateList) AttributeSet(android.util.AttributeSet) TypedValue(android.util.TypedValue) Menu(android.view.Menu) AnimatedColorStateList(carbon.animation.AnimatedColorStateList) Build(android.os.Build) AnimUtils(carbon.animation.AnimUtils) TargetApi(android.annotation.TargetApi) TypedArray(android.content.res.TypedArray) ColorStateListDrawable(carbon.drawable.ColorStateListDrawable) DefaultAccentColorStateList(carbon.drawable.DefaultAccentColorStateList) TypedValue(android.util.TypedValue)

Example 2 with ColorStateListDrawable

use of carbon.drawable.ColorStateListDrawable in project Carbon by ZieIony.

the class Button method initButton.

private void initButton(AttributeSet attrs, int defStyleAttr) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Button, defStyleAttr, R.style.carbon_Button);
    int ap = a.getResourceId(R.styleable.Button_android_textAppearance, -1);
    if (ap != -1)
        setTextAppearanceInternal(ap);
    for (int i = 0; i < a.getIndexCount(); i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.Button_carbon_textAllCaps) {
            setAllCaps(a.getBoolean(R.styleable.Button_carbon_textAllCaps, true));
        } else if (!isInEditMode() && attr == R.styleable.Button_carbon_fontPath) {
            String path = a.getString(attr);
            Typeface typeface = TypefaceUtils.getTypeface(getContext(), path);
            setTypeface(typeface);
        } else if (attr == R.styleable.Button_carbon_fontFamily) {
            int textStyle = a.getInt(R.styleable.Button_android_textStyle, 0);
            Typeface typeface = TypefaceUtils.getTypeface(getContext(), a.getString(attr), textStyle);
            setTypeface(typeface);
        }
    }
    TypedValue bg = new TypedValue();
    a.getValue(R.styleable.Button_android_background, bg);
    if (bg.type >= TypedValue.TYPE_FIRST_COLOR_INT && bg.type <= TypedValue.TYPE_LAST_COLOR_INT && bg.data == 0)
        setBackgroundDrawable(new ColorStateListDrawable(AnimatedColorStateList.fromList(new DefaultPrimaryColorStateList(getContext()), animation -> postInvalidate())));
    Carbon.initRippleDrawable(this, a, rippleIds);
    Carbon.initElevation(this, a, elevationIds);
    Carbon.initTint(this, a, tintIds);
    Carbon.initAnimations(this, a, animationIds);
    Carbon.initTouchMargin(this, a, touchMarginIds);
    Carbon.initHtmlText(this, a, R.styleable.Button_carbon_htmlText);
    Carbon.initStroke(this, a, strokeIds);
    setCornerRadius(a.getDimension(R.styleable.Button_carbon_cornerRadius, 0));
    a.recycle();
}
Also used : Typeface(android.graphics.Typeface) Context(android.content.Context) Path(android.graphics.Path) Rect(android.graphics.Rect) NEEDS_PROXY(com.nineoldandroids.view.animation.AnimatorProxy.NEEDS_PROXY) ShadowShape(carbon.shadow.ShadowShape) AnimatorProxy.wrap(com.nineoldandroids.view.animation.AnimatorProxy.wrap) AnimatorListenerAdapter(com.nineoldandroids.animation.AnimatorListenerAdapter) AnimatedView(carbon.animation.AnimatedView) ViewOutlineProvider(android.view.ViewOutlineProvider) NonNull(android.support.annotation.NonNull) Drawable(android.graphics.drawable.Drawable) TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) MatrixHelper(carbon.internal.MatrixHelper) AttributeSet(android.util.AttributeSet) MotionEvent(android.view.MotionEvent) ShadowGenerator(carbon.shadow.ShadowGenerator) View(android.view.View) RippleDrawable(carbon.drawable.ripple.RippleDrawable) Canvas(android.graphics.Canvas) ViewCompat(android.support.v4.view.ViewCompat) Animation(android.view.animation.Animation) Matrix(android.graphics.Matrix) Build(android.os.Build) TargetApi(android.annotation.TargetApi) DefaultPrimaryColorStateList(carbon.drawable.DefaultPrimaryColorStateList) RectF(android.graphics.RectF) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) R(carbon.R) RippleView(carbon.drawable.ripple.RippleView) TypefaceUtils(carbon.internal.TypefaceUtils) Animator(com.nineoldandroids.animation.Animator) StateAnimator(carbon.animation.StateAnimator) ColorStateListDrawable(carbon.drawable.ColorStateListDrawable) PorterDuff(android.graphics.PorterDuff) Shadow(carbon.shadow.Shadow) Carbon(carbon.Carbon) TypedValue(android.util.TypedValue) AllCapsTransformationMethod(carbon.internal.AllCapsTransformationMethod) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Transformation(android.view.animation.Transformation) Paint(android.graphics.Paint) AnimatedColorStateList(carbon.animation.AnimatedColorStateList) ShadowView(carbon.shadow.ShadowView) AnimUtils(carbon.animation.AnimUtils) Typeface(android.graphics.Typeface) DefaultPrimaryColorStateList(carbon.drawable.DefaultPrimaryColorStateList) TypedArray(android.content.res.TypedArray) ColorStateListDrawable(carbon.drawable.ColorStateListDrawable) Paint(android.graphics.Paint) TypedValue(android.util.TypedValue)

Aggregations

TargetApi (android.annotation.TargetApi)2 Context (android.content.Context)2 ColorStateList (android.content.res.ColorStateList)2 TypedArray (android.content.res.TypedArray)2 Build (android.os.Build)2 AttributeSet (android.util.AttributeSet)2 TypedValue (android.util.TypedValue)2 R (carbon.R)2 AnimUtils (carbon.animation.AnimUtils)2 AnimatedColorStateList (carbon.animation.AnimatedColorStateList)2 ColorStateListDrawable (carbon.drawable.ColorStateListDrawable)2 Canvas (android.graphics.Canvas)1 Matrix (android.graphics.Matrix)1 Paint (android.graphics.Paint)1 Path (android.graphics.Path)1 PorterDuff (android.graphics.PorterDuff)1 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)1 Rect (android.graphics.Rect)1 RectF (android.graphics.RectF)1 Typeface (android.graphics.Typeface)1