Android-Circular-Progress icon indicating copy to clipboard operation
Android-Circular-Progress copied to clipboard

change progress ring color with array of color

Open ksandyasa opened this issue 8 years ago • 11 comments

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?

ksandyasa avatar Apr 12 '16 09:04 ksandyasa

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.

grojasv avatar Apr 12 '16 10:04 grojasv

circular_progress

I would like showing progress ring like the image above..

ksandyasa avatar Apr 12 '16 10:04 ksandyasa

Aha, it seems some kind of gradient color. Let's wait for @kuassivi reply.

grojasv avatar Apr 12 '16 10:04 grojasv

Hi, thanks @ksandyasa. As @grojasv mentioned that feature is not yet implemented, but such interesting options are wellcome. Suggestion accepted 😃

FranRiadigos avatar Apr 13 '16 09:04 FranRiadigos

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.

FranRiadigos avatar Apr 14 '16 17:04 FranRiadigos

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..

ksandyasa avatar Apr 16 '16 15:04 ksandyasa

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 avatar Jun 29 '16 12:06 abhinavkorpal

@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.

viswakarmalovekush avatar Jul 05 '16 16:07 viswakarmalovekush

@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 avatar Jul 12 '16 16:07 viswakarmalovekush

@viswakarmalovekush amazing it's working. Thanks

abhinavkorpal avatar Jul 12 '16 17:07 abhinavkorpal

Welcome dude :+1:

viswakarmalovekush avatar Jul 12 '16 17:07 viswakarmalovekush