Circular Progress Bar ( for a countdown timer )

后端 未结 3 1790
臣服心动
臣服心动 2020-12-13 02:39

Ok so I have a countdown timer of 15 seconds that works perfectly fine and I\'d like to make a custom circular progress bar for that timer.

I want to create a full c

3条回答
  •  天命终不由人
    2020-12-13 03:35

    I found this example very good: http://mrigaen.blogspot.it/2013/12/create-circular-progress-bar-in-android.html

    So I created my progress bar in this way

    
    

    Then I made a function for the countdown where:

    private void startTimer(final int minuti) {
        countDownTimer = new CountDownTimer(60 * minuti * 1000, 500) {
            // 500 means, onTick function will be called at every 500 milliseconds
    
            @Override
            public void onTick(long leftTimeInMilliseconds) {
                long seconds = leftTimeInMilliseconds / 1000;
                int barVal= (barMax) - ((int)(seconds/60*100)+(int)(seconds%60));
                barTimer.setProgress(barVal);
                textTimer.setText(String.format("%02d", seconds/60) + ":" + String.format("%02d", seconds%60));
                // format the textview to show the easily readable format
    
            }
            @Override
            public void onFinish() {
                if(textTimer.getText().equals("00:00")){
                    textTimer.setText("STOP");          
                }
                else{
                    textTimer.setText("2:00");
                }
            }
        }.start();
    
    }
    

    UPDATE

    private void startTimer(final int minuti) {
        countDownTimer = new CountDownTimer(60 * minuti * 1000, 500) {
            // 500 means, onTick function will be called at every 500 milliseconds
    
            @Override
            public void onTick(long leftTimeInMilliseconds) {
                long seconds = leftTimeInMilliseconds / 1000;
                barTimer.setProgress((int)seconds);
                textTimer.setText(String.format("%02d", seconds/60) + ":" + String.format("%02d", seconds%60));
                // format the textview to show the easily readable format
    
            }
            @Override
            public void onFinish() {
                if(textTimer.getText().equals("00:00")){
                    textTimer.setText("STOP"); 
                }
                else{
                    textTimer.setText("2:00");
                    barTimer.setProgress(60*minuti);
                }
            }
        }.start();
    
    }  
    

提交回复
热议问题