Color changing in Custom Progress Wheel at runtime in android programmatically

后端 未结 2 1430
醉酒成梦
醉酒成梦 2021-01-05 20:16

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 t

相关标签:
2条回答
  • 2021-01-05 21:01

    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?

    0 讨论(0)
  • 2021-01-05 21:01

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

    0 讨论(0)
提交回复
热议问题