** Now the problem is:
1-when one percentage finished timer start from 00:00:00
2- when make pause and start again progress increase 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);
}
};
check if progress Paused
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 Class
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;
}
}
}
any help please . thanks in advance