package com.ianhanniballake.contractiontimer;

import android.content.Context;
import android.graphics.Canvas;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
import android.view.View;

import com.google.android.glass.timeline.DirectRenderingCallback;

/**
 * SurfaceHolder.Callback used to draw the timer on the timeline {@link com.google.android.glass.timeline.LiveCard}.
 */
public class TimerRenderer implements DirectRenderingCallback {
    private final View mView;
    private SurfaceHolder mHolder;
    private boolean mRenderingPaused;

    public TimerRenderer(Context context) {
        LayoutInflater inflater = LayoutInflater.from(context);
        mView = inflater.inflate(R.layout.main, null);
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        // Measure and layout the view with the canvas dimensions.
        int measuredWidth = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
        int measuredHeight = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
        mView.measure(measuredWidth, measuredHeight);
        mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight());
        draw();
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        // The creation of a new Surface implicitly resumes the rendering.
        mRenderingPaused = false;
        mHolder = holder;
        draw();
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        mHolder = null;
    }

    @Override
    public void renderingPaused(SurfaceHolder holder, boolean paused) {
        mRenderingPaused = paused;
        draw();
    }

    public void draw() {
        if (!mRenderingPaused && mHolder != null) {
            Canvas canvas;
            try {
                canvas = mHolder.lockCanvas();
            } catch (Exception e) {
                return;
            }
            if (canvas != null) {
                mView.draw(canvas);
                mHolder.unlockCanvasAndPost(canvas);
            }
        }
    }
}

@@ -104,16 +104,41 @@
 Canvas;%0A
+import android.util.Log;%0A
 import a
@@ -857,24 +857,95 @@
 t height) %7B%0A
+        Log.d(TimerRenderer.class.getSimpleName(), %22Surface Changed%22);%0A
         // M
@@ -1410,32 +1410,103 @@
 older holder) %7B%0A
+        Log.d(TimerRenderer.class.getSimpleName(), %22Surface Created%22);%0A
         // The c
@@ -1710,32 +1710,105 @@
 older holder) %7B%0A
+        Log.d(TimerRenderer.class.getSimpleName(), %22Surface Destroyed%22);%0A
         mHolder 
@@ -1904,24 +1904,125 @@
 n paused) %7B%0A
+        Log.d(TimerRenderer.class.getSimpleName(), %22Rendering %22 + (paused ? %22paused%22 : %22unpaused%22));%0A
         mRen

Add logging messages for surface changes