Color changing in Custom Progress Wheel at runtime

2019-02-14 00:32发布

I am doing for custom circular progress wheel. here what i need for, once the progress wheel finish it hundred percent progress. then , when i click again,i need to change the progressing color at runtime...

I downloaded code from this link.. https://github.com/Todd-Davies/ProgressWheel

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

I tried this link also.. this link is for having for default progress bar. but, i am using for custom progress bar.thats why, i cant used this method like... http://myandroidsolutions.blogspot.in/2012/11/android-change-indeterminate-progress.html http://www.tiemenschut.com/how-to-customize-android-progress-bars/

can anyone help me to complete this task.. Thanks Advance....

my code : onCreate Method:

increment.setOnClickListener(new OnClickListener() {
@SuppressLint("WrongCall")
public void onClick(View v) {
Log.v("test", "-----increment button clicked--------");
if(!running) {
progress1 = (int) 370 ; 
Thread s = new Thread(r);
s.start();
}
}
});

final Runnable r = new Runnable() {
        @SuppressLint("WrongCall")
        public void run() {
            //Log.v("test", "----- thread called--------");
            running = true;
            //Log.v("test", "progress:"+progress);
            //Log.v("test", "progress1:"+progress1);
            progress2 = progress - progress1 ;   
                          //progress = 360 , progress1 = uservalue
            Log.v("test", "progress:"+progress);
            Log.v("test", "progress1:"+progress1);
            Log.v("test", "progress2 = progress - progress1:"+progress2);
            //percentage = pw_two.incrementProgress();
            // pw_two.setBarColor(Color.parseColor("#FF0000"));

            while(progress2<360) {    
            percentage = pw_two.incrementProgress();
            Log.v("test","percentage:"+percentage);
                progress2++;
                try {
                    Thread.sleep(15);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }



 // here when crossing 360 above , then color change effect needed..
 //why we using this function, when put ten minutes for break,
    who taking more than ten minutes,, 
 // then that time itself, need to change color..
   i finish that time calculation....
                if(progress2 > 359) {
// here.. need to call this method two times.. then only, wheel will be refreshed......
                    //onPause_Reset_ProgressWheelOne();
                    onPause_Reset_ProgressWheelOne();
                    //break;
                }
            }

            running = false;
        }
     };

  public void onPause_Reset_ProgressWheelOne() {

     Log.v("test", "onPause_Reset_ProgressWheelOne--------");

    progress = 360;
    pw_two.setRimColor(Color.parseColor("#fe854c")); //1988c4   //fe854c
    pw_two.setBarColor(Color.RED);
    //pw_two.resetCount();  
    pw_two.refreshWheel();
    // progress = 0;
    // pw_two.setProgress(0);

  }

 ProgressWheel.java CLass  :

  public void refreshWheel() {

    setupPaints();
}

2条回答
Luminary・发光体
2楼-- · 2019-02-14 00:51

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

查看更多
我命由我不由天
3楼-- · 2019-02-14 01:06

Inside ProgressWheel.java (com.toffffdavies.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?

查看更多
登录 后发表回答