title: AsyncTask onDraw method with time delay
body: <p>I want to make an activity where user at the beginning will see  first statement then after 2 sec, there'll be second statement and at last there show up timer with progress drawn on canvas in onDraw method. </p>
  
  <p>Timer should only last 5 seconds, but when I add those two 2 sec breaks, user will see only last second (5-2-2). I tried to change code where progress is calculated, but I just make things worse.</p>
  
  <p>I cutted out variable declaration and all content about shapes being drawing. Maybe i should declarate in diffrent moment startTime and currentTime.</p>
  
  <pre><code>public class CircleTimer extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
         final CircularCountdown view  = new CircularCountdown(this);
          setContentView(view);
  
          AsyncTask&lt;Void, Boolean, Void&gt; task = new AsyncTask&lt;Void, Boolean, Void&gt;() {
  
              @Override
              protected Void doInBackground(Void... params) {
                  try {
                      Thread.sleep(2000);
                      publishProgress(true);
                      Thread.sleep(2000);
                  } catch (InterruptedException e) {
                  }
                  return null;
              }
  
              protected void onProgressUpdate(Boolean... progress) {
                  view.setSecondDrawStep(progress[0]);
                  view.invalidate();
              }
  
              @Override
              protected void onPostExecute(Void result) {
                  view.setThirdDrawStep(true);
                  view.invalidate();
              }
          };
          task.execute((Void[])null);
      }
  
      private class CircularCountdown extends View {
  
  
          public CircularCountdown(Context context) {
              super(context);
  
  
              maxTime = 5000;
  
              startTime = System.currentTimeMillis();
              currentTime = startTime;
  
              viewHandler = new Handler();
              updateView = new Runnable(){
                  @Override
                  public void run(){
                      currentTime = System.currentTimeMillis();
                      progressMillisecond = Math.abs(startTime - currentTime) % maxTime;
                      progress = (double) (progressMillisecond) / maxTime;
                      CircularCountdown.this.invalidate();
                      viewHandler.postDelayed(updateView, 1000/60);
                  }
              };
              viewHandler.post(updateView);
          }
  
          boolean secondDrawStep = false;
          boolean thirdDrawStep = false;
  
          public void setSecondDrawStep(boolean flag) {
              secondDrawStep = flag;
          }
  
          public void setThirdDrawStep(boolean flag) {
              thirdDrawStep = flag;
          }
  
          @Override
          protected void onDraw(Canvas canvas) {
              super.onDraw(canvas);
  
              canvas.drawText("FIRST statement",
                      centerWidthCenter,
                      centerHeightCenter + textOffset,
                      nameTextPaint);
  
              if (secondDrawStep) {
                  canvas.drawColor(Color.WHITE);
  
                  canvas.drawText("SECOND statement",
                          centerWidthCenter,
                          centerHeightCenter + textOffset,
                          nameTextPaint);
              }
  
              if (thirdDrawStep) {
                  canvas.drawColor(Color.WHITE);
  
                  canvas.drawArc(circleBounds, -90, (float) (progress * 360), false, progressPaint);
  
                  canvas.drawText((int) Math.abs(5 - (progressMillisecond / 1000)) + "s",
                          centerWidth,
                          centerHeight + textOffset,
                          textPaint);
              }
  
          }
      }
  
  }
  </code></pre>