Android-Circular-Progress
Android-Circular-Progress copied to clipboard
change progress ring color with array of color
Hello,
I'm using your library into my project apps and it's really awesome library. So i want to ask how to set progress ring color from array of colors? I want to show progress ring color with 3 different type colors. How i do that?
From what I've seen this is not implemented. How would you show 3 colors in a progress? IMHO only makes sense a color to fill the ring and an empty color.
I would like showing progress ring like the image above..
Aha, it seems some kind of gradient color. Let's wait for @kuassivi reply.
Hi, thanks @ksandyasa. As @grojasv mentioned that feature is not yet implemented, but such interesting options are wellcome. Suggestion accepted 😃
Create an array of colors as a resource value.
<resources>
<array name="gradient">
<item>@color/white</item>
<item>@color/black</item>
</array>
</resources>
Then apply it with some few configs in the ProgressProfileView as follow:
<com.kuassivi.view.ProgressProfileView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
tools:src="@drawable/ic_icon_user_default"
app:progress="65"
app:progressRingCorner="ROUND"
app:progressRingSize="10dp"
app:progressRingOutline="true"
app:progressGradient="@array/gradient" <---
app:backgroundRingColor="@android:color/darker_gray"
app:joinGradient="true" <---
app:gradientFactor="5.0"/> <---
Gradient ring cannot be shown in Preview for now.
I wish the feature of gradient ring color can be implemented as soon as possible.. Your library is awesome and it will be more awesome if the gradient ring color can be implemented.. Will be waited for the update of gradient ring color in ProfileProgressView..
i want to ask how to set progress ring color from array of colors? I want to show progress ring color with 3 different type colors. How i do that?
@abhinavkorpal hi, as per you question, if want to set multiple color to progress ring than you need to set color array as integer as Gradient but is this lib, setProgressGredient is not working. I solved this problem and i have added one method setProgressGredientColor(int []color_array) by this you can achieve your problem. i am committing some changes you can update and use it. enjoye.
@abhinavkorpal , Add this method in ProgressProfileView.java cass in Lib,
public void setProgressGredientColor(int[] mProgressGradient) { mProgressRingPaint = new Paint(); mProgressRingPaint.setAntiAlias(true); mProgressRingPaint.setStrokeCap(mProgressRingCorner); mProgressRingPaint.setStyle(Paint.Style.STROKE); mProgressRingPaint.setStrokeWidth(mProgressRingSize); mProgressRingPaint.setColor(mProgressRingColor);
if (mProgressGradient != null) {
int[] colors = mProgressGradient;
float[] positions;
if (isJoinGradient()) {
colors = new int[mProgressGradient.length + 1];
positions = new float[colors.length];
int i = 0;
positions[i] = i;
for (int color : mProgressGradient) {
colors[i] = color;
if (i == mProgressGradient.length - 1) {
positions[i] = (ANGLE_360 - mProgressRingSize * getGradientFactor())
/ ANGLE_360;
} else if (i > 0) {
positions[i] = ((float) i / (float) colors.length);
}
i++;
}
colors[i] = colors[0];
positions[i] = 1;
}
SweepGradient gradient = new SweepGradient(mRingBounds.centerX(),
mRingBounds.centerY(),
colors, null);
mProgressRingPaint.setShader(gradient);
Matrix matrix = new Matrix();
mProgressRingPaint.getShader().setLocalMatrix(matrix);
matrix.postTranslate(-mRingBounds.centerX(), -mRingBounds.centerY());
matrix.postRotate(-ANGLE_90);
matrix.postTranslate(mRingBounds.centerX(), mRingBounds.centerY());
mProgressRingPaint.getShader().setLocalMatrix(matrix);
mProgressRingPaint.setColor(mProgressGradient[0]);
}
}
use this method you can set gradient color to progressview.
@viswakarmalovekush amazing it's working. Thanks
Welcome dude :+1: