Color changing in Custom Progress Wheel at runtime in android programmatically

风格不统一 提交于 2019-11-30 21:03:35

Inside ProgressWheel.java (com.todddavies.components.progressbar.ProgressWheel), add a method:

public void refreshTheWheel() {

    setupPaints();

}

I click on a button, the progress starts progressing. that progress bar circle already one color. After the progress complete 100%, I want it to start again, that time , i need to change the color to be red runtimely

When you need to change the color:

// Progress is 100%
if (progress == 360) {

    // Change the color
    mProgressWheel.setBarColor(Color.RED);

    // Refresh
    mProgressWheel.refreshTheWheel();

    // Reset progress
    progress = 0;
    mProgressWheel.setProgress(0);

    // You can also use:
    // mProgressWheel.resetCount();
}

Note: Please make sure that editing/adding to this library is allowed.

Edit:

See if the following changes get you the desired output:

Declare global variables:

// `progress` isn't needed
// int progress = 360;
int progress1 = 0;
int progress2 = 0;

....
....

increment.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {

        Log.v("test", "-----increment button clicked--------");

        if(!running) {

            // I am not sure what you are using `progress1` for
            // progress1 = (int) 370 ;

            progress1 = 0;
            progress2 = 0;

            // reset `pw_two`
            pw_two.resetCount();

            Thread s = new Thread(r);
            s.start();
        }
    }
});    

Now, the Runnable:

final Runnable r = new Runnable() {
    public void run() {
        running = true;

        // I could not figure out why you are using this
        // Can you explain what this does?
        // progress2 = progress - progress1 ;

        while(progress2 < 361) {
            pw_two.incrementProgress();

            // Increment both `progress1` and `progress2`
            progress2++;
            progress1++;        

            try {
                Thread.sleep(15);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            // Here, reset `progress2`, but not `progress1`
            if (progress2 == 360) {
                pw_two.setRimColor(Color.parseColor("#fe854c")); //1988c4   //fe854c
                pw_two.setBarColor(Color.RED);
                pw_two.refreshWheel();
                progress2 = 0;
                pw_two.setProgress(0);

                // Log value of `progress1`
                Log.v("Progress 1", "progress1 is " + progress1);
            }
        }
        running = false;
    }
};

You do not need to call another method. At progressValue = 360, the color will switch. If I somehow misunderstood what you are trying to achieve, could you explain with some use-cases?

Check this example, it have a circular progress bar that change color when progress increased.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!