Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change progress ring color with array of color #23

Open
ksandyasa opened this issue Apr 12, 2016 · 11 comments
Open

change progress ring color with array of color #23

ksandyasa opened this issue Apr 12, 2016 · 11 comments

Comments

@ksandyasa
Copy link

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?

@grojasv
Copy link

grojasv commented Apr 12, 2016

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.

@ksandyasa
Copy link
Author

circular_progress

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

@grojasv
Copy link

grojasv commented Apr 12, 2016

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

@FranRiadigos
Copy link
Owner

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

FranRiadigos added a commit that referenced this issue Apr 14, 2016
Added new feature for gradient progress ring #23
FranRiadigos added a commit that referenced this issue Apr 14, 2016
@FranRiadigos
Copy link
Owner

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.

@ksandyasa
Copy link
Author

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

@abhinavkorpal
Copy link

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?

@viswakarmalovekush
Copy link

@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
Copy link

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

@abhinavkorpal
Copy link

@viswakarmalovekush amazing it's working. Thanks

@viswakarmalovekush
Copy link

Welcome dude 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants