如何根据具体时间进行循环进度暂停到计时器和进度?

时间:2017-01-03 10:39:32

标签: android timer progress-bar pause

**现在的问题是: 1 - 当一个百分比完成计时器从00:00:00开始时 2-当暂停并再次开始进度增加1 **

private long millisInFuture = 28800000;
private long countDownInterval = 288000;

   int progressBarMaximumValue = (int) (millisInFuture / countDownInterval);
    donutProgress.setMax(progressBarMaximumValue);

btnProgress.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (resumed) {
                resumed = false;
                butnstart.setText("Start");
                timeSwapBuff += timeInMilliseconds;
                handler.removeCallbacks(updateTimer);
                t = 1;
            } else {
                resumed = true;
                donutProgress.setProgress(pStatus);
                myCountDownTimer = new MyCountDownTimer(millisInFuture, countDownInterval);
                myCountDownTimer.start();
                runProgress();
            }
        }
    });

 public Runnable updateTimer = new Runnable() {
    public void run() {

        timeInMilliseconds = SystemClock.uptimeMillis() - starttime;
        updatedtime = timeSwapBuff + timeInMilliseconds;
        secs = (int) (updatedtime / 1000);
        milliseconds = (int) (updatedtime % 1000);
        tv_Time.setText(String.format("%02d:%02d:%02d", secs / 3600, (secs % 3600) / 60, (secs % 60)));
        handler.postDelayed(this, 0);
    }
};     

检查进度是否已暂停

public void runProgress() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            while (pStatus < 100) {
                if (resumed) {
                    pStatus = i;

                }
                handler.post(new Runnable() {
                    @Override
                    public void run() {

                        donutProgress.setProgress(pStatus);
                    }
                });
                try {
                    Thread.sleep(countDownInterval);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }).start();

CountDownTimer类

      public class MyCountDownTimer extends CountDownTimer {

    public MyCountDownTimer(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    @Override
    public void onTick(long millisUntilFinished) {
        butnstart.setText("Pause");
        starttime = SystemClock.uptimeMillis();
        handler.postDelayed(updateTimer, 0);
        t = 0;
        i++;
        donutProgress.setProgress(pStatus);
    }

    @Override
    public void onFinish() {
        tv_Time.setText("Task completed");
        donutProgress.setProgress(pStatus);

        if (pStatus == 100) {

            tv_Time.setTextColor(Color.BLUE);
            timeSwapBuff += timeInMilliseconds;
            handler.removeCallbacks(updateTimer);
            t = 1;
        }
    }

}

请帮助。 提前谢谢

enter image description here

0 个答案:

没有答案