package org.skia.clock;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;

import java.util.Calendar;
import java.util.Date;

/**
 *
 */
public class CoolClock extends View {
    private Paint fPaint;
    private Date fDate;
    private Calendar fCalendar;

    public CoolClock(Context ctx) {
        super(ctx);
        fPaint = new Paint();
        fPaint.setAntiAlias(true);
        fPaint.setTextSize(120);
        fDate = new Date();
        fCalendar = Calendar.getInstance();
    }

    protected void onDraw(android.graphics.Canvas canvas) {
        fDate.setTime(System.currentTimeMillis());
        fCalendar.setTime(fDate);

        // // You may want these values.
        // int day_of_month = fCalendar.get(Calendar.DAY_OF_MONTH);
        // int month = 1 + fCalendar.get(Calendar.MONTH);
        // int year = fCalendar.get(Calendar.YEAR);
        // int millisecond = fCalendar.get(Calendar.MILLISECOND);

        int hour = fCalendar.get(Calendar.HOUR);
        int minute = fCalendar.get(Calendar.MINUTE);
        int second = fCalendar.get(Calendar.SECOND);
        boolean is_pm = Calendar.PM == fCalendar.get(Calendar.AM_PM);

        // ====================================
        // REPLACE THIS CODE WITH A COOL CLOCK!
        String date = String.format("%2d:%02d:%02d %s",
                hour, minute, second, is_pm ? "p.m." : "a.m.");
        canvas.drawRGB(255, 255, 128);
        canvas.drawText(date, 10, 130, fPaint);
        // REPLACE THIS CODE WITH A COOL CLOCK!
        // ====================================

        long DELAY_MILLISECONDS = 300;
        this.postInvalidateDelayed(DELAY_MILLISECONDS);
    }

}

@@ -165,16 +165,106 @@
 %0A%0A/**%0A *
+  /class CoolClock displays time (and maybe date).%0A *%0A *  TODO(you): make this clock cool.
 %0A */%0Apub
@@ -1774,10 +1774,507 @@
 %0A    %7D%0A%0A
+    private static double RadiansFrom60(double angle) %7B%0A        return Math.toRadians(angle * 6 - 90);%0A    %7D%0A    private static double RadiansFrom12(double angle) %7B%0A        return Math.toRadians(angle * 30 - 90);%0A    %7D%0A    private static float FaceX(double angle, int length, int centerX) %7B%0A        return (float) (length * Math.cos(angle) + centerX);%0A    %7D%0A    private static float FaceY(double angle, int length, int centerY) %7B%0A        return (float) (length * Math.sin(angle) + centerY);%0A    %7D%0A
 %7D%0A

add utility functions