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;
}
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();
}
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;
}
}
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;
}
}
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;
}
}
Aggregations