Search in sources :

Example 1 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project circular-progress-button by dmytrodanylyk.

the class CircularProgressButton method createDrawable.

private StrokeGradientDrawable createDrawable(int color) {
    GradientDrawable drawable = (GradientDrawable) getResources().getDrawable(R.drawable.cpb_background).mutate();
    drawable.setColor(color);
    drawable.setCornerRadius(mCornerRadius);
    StrokeGradientDrawable strokeGradientDrawable = new StrokeGradientDrawable(drawable);
    strokeGradientDrawable.setStrokeColor(color);
    strokeGradientDrawable.setStrokeWidth(mStrokeWidth);
    return strokeGradientDrawable;
}
Also used : GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 2 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project circular-progress-button by dmytrodanylyk.

the class MorphingAnimation method start.

public void start() {
    ValueAnimator widthAnimation = ValueAnimator.ofInt(mFromWidth, mToWidth);
    final GradientDrawable gradientDrawable = mDrawable.getGradientDrawable();
    widthAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Integer value = (Integer) animation.getAnimatedValue();
            int leftOffset;
            int rightOffset;
            int padding;
            if (mFromWidth > mToWidth) {
                leftOffset = (mFromWidth - value) / 2;
                rightOffset = mFromWidth - leftOffset;
                padding = (int) (mPadding * animation.getAnimatedFraction());
            } else {
                leftOffset = (mToWidth - value) / 2;
                rightOffset = mToWidth - leftOffset;
                padding = (int) (mPadding - mPadding * animation.getAnimatedFraction());
            }
            gradientDrawable.setBounds(leftOffset + padding, padding, rightOffset - padding, mView.getHeight() - padding);
        }
    });
    ObjectAnimator bgColorAnimation = ObjectAnimator.ofInt(gradientDrawable, "color", mFromColor, mToColor);
    bgColorAnimation.setEvaluator(new ArgbEvaluator());
    ObjectAnimator strokeColorAnimation = ObjectAnimator.ofInt(mDrawable, "strokeColor", mFromStrokeColor, mToStrokeColor);
    strokeColorAnimation.setEvaluator(new ArgbEvaluator());
    ObjectAnimator cornerAnimation = ObjectAnimator.ofFloat(gradientDrawable, "cornerRadius", mFromCornerRadius, mToCornerRadius);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setDuration(mDuration);
    animatorSet.playTogether(widthAnimation, bgColorAnimation, strokeColorAnimation, cornerAnimation);
    animatorSet.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mListener != null) {
                mListener.onAnimationEnd();
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    animatorSet.start();
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) ObjectAnimator(android.animation.ObjectAnimator) ArgbEvaluator(android.animation.ArgbEvaluator) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 3 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project UltimateAndroid by cymcsg.

the class RoundCornerProgressBar method setProgressColor.

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public void setProgressColor(int color) {
    progressColor = color;
    int radius = this.radius - padding / 2;
    GradientDrawable gradient = new GradientDrawable();
    gradient.setShape(GradientDrawable.RECTANGLE);
    gradient.setColor(progressColor);
    gradient.setCornerRadii(new float[] { radius, radius, radius, radius, radius, radius, radius, radius });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        layoutProgress.setBackground(gradient);
    } else {
        layoutProgress.setBackgroundDrawable(gradient);
    }
    if (!isProgressBarCreated) {
        isProgressColorSetBeforeDraw = true;
    }
}
Also used : SuppressLint(android.annotation.SuppressLint) GradientDrawable(android.graphics.drawable.GradientDrawable) SuppressLint(android.annotation.SuppressLint)

Example 4 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project UltimateAndroid by cymcsg.

the class RoundCornerProgressBar method setBackgroundColor.

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public void setBackgroundColor(int color) {
    backgroundColor = color;
    GradientDrawable gradient = new GradientDrawable();
    gradient.setShape(GradientDrawable.RECTANGLE);
    gradient.setColor(backgroundColor);
    gradient.setCornerRadius(radius);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        layoutBackground.setBackgroundDrawable(gradient);
    } else {
        layoutBackground.setBackground(gradient);
    }
    if (!isProgressBarCreated) {
        isBackgroundColorSetBeforeDraw = true;
    }
}
Also used : GradientDrawable(android.graphics.drawable.GradientDrawable) SuppressLint(android.annotation.SuppressLint)

Example 5 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project UltimateAndroid by cymcsg.

the class TextRoundCornerProgressBar method setProgressColor.

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public void setProgressColor(int color) {
    progressColor = color;
    int radius = this.radius - (padding / 2);
    GradientDrawable gradient = new GradientDrawable();
    gradient.setShape(GradientDrawable.RECTANGLE);
    gradient.setColor(progressColor);
    gradient.setCornerRadii(new float[] { radius, radius, radius, radius, radius, radius, radius, radius });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        layoutProgress.setBackground(gradient);
    } else {
        layoutProgress.setBackgroundDrawable(gradient);
    }
    if (!isProgressBarCreated) {
        isProgressColorSetBeforeDraw = true;
    }
}
Also used : SuppressLint(android.annotation.SuppressLint) GradientDrawable(android.graphics.drawable.GradientDrawable) SuppressLint(android.annotation.SuppressLint)

Aggregations

GradientDrawable (android.graphics.drawable.GradientDrawable)163 Paint (android.graphics.Paint)19 Drawable (android.graphics.drawable.Drawable)19 StateListDrawable (android.graphics.drawable.StateListDrawable)19 SuppressLint (android.annotation.SuppressLint)18 View (android.view.View)18 TextView (android.widget.TextView)18 LayerDrawable (android.graphics.drawable.LayerDrawable)15 ImageView (android.widget.ImageView)14 LinearLayout (android.widget.LinearLayout)12 TypedArray (android.content.res.TypedArray)8 FrameLayout (android.widget.FrameLayout)6 TimeAnimator (android.animation.TimeAnimator)5 Typeface (android.graphics.Typeface)5 LayoutInflater (android.view.LayoutInflater)5 ViewGroup (android.view.ViewGroup)5 Attributes (com.cengalabs.flatui.Attributes)5 Resources (android.content.res.Resources)4 TextPaint (android.text.TextPaint)4 Button (android.widget.Button)4