package io.caster.customviews;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v4.content.ContextCompat;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;

/**
 *
 */
public class TimerView extends View {
    private Paint backgroundPaint;
    private TextPaint numberPaint;

    private long startTime;

    private Runnable updateRunnable = new Runnable() {
        @Override
        public void run() {
            updateTimer();
        }
    };

    public TimerView(Context context) {
        super(context);
        init();
    }

    public TimerView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        backgroundPaint = new Paint();
        backgroundPaint.setColor(Color.parseColor("#880E4F"));

        numberPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        numberPaint.setColor(ContextCompat.getColor(getContext(), android.R.color.white));
        numberPaint.setTextSize(64f * getResources().getDisplayMetrics().scaledDensity);
    }

    public void start() {
        startTime = System.currentTimeMillis();

        updateTimer();
    }

    public void stop() {
        startTime = 0;

        removeCallbacks(updateRunnable);
    }

    private void updateTimer() {
        invalidate();

        postDelayed(updateRunnable, 200L);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        int canvasWidth = canvas.getWidth();
        int canvasHeight = canvas.getHeight();

        float centerX = Math.round(canvasWidth * 0.5f);
        float centerY = Math.round(canvasHeight * 0.5f);

        float radius = (canvasWidth < canvasHeight ? canvasWidth : canvasHeight) * 0.5f;

        String number = String.valueOf((long) ((System.currentTimeMillis() - startTime) * 0.001));
        float textOffsetX = numberPaint.measureText(number) * 0.5f;
        float textOffsetY = numberPaint.getFontMetrics().ascent * -0.4f;

        canvas.drawCircle(centerX, centerY, radius, backgroundPaint);
        canvas.drawText(number, centerX - textOffsetX, centerY + textOffsetY, numberPaint);
    }
}

@@ -298,17 +298,201 @@
 %0A%0A/**%0A *
+ A simple custom %7B@link View%7D subclass that counts up the number of seconds since it was started.%0A * When a TimerView is stopped, the seconds count is reset when the timer next starts.
 %0A
-
  */%0Apubl
@@ -771,16 +771,66 @@
     %7D;%0A%0A
+    //%0A    // Constructors/initialization%0A    //%0A%0A
     publ
@@ -1390,32 +1390,80 @@
 ensity);%0A    %7D%0A%0A
+    //%0A    // Timer interface + helpers%0A    //%0A%0A
     public void 
@@ -1747,23 +1747,60 @@
  200L);%0A
-
     %7D%0A%0A
+    //%0A    // View overrides%0A    //%0A%0A
     @Ove

Add some comments and file headers to `TimerView`.