Created
December 14, 2014 17:16
-
-
Save ntakouris/a94afe57a67b1aae6a2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onDraw(Canvas canvas, Rect bounds) { | |
/* draw your watch face */ | |
// Update the time | |
mTime.setToNow(); | |
int width = bounds.width(); | |
int height = bounds.height(); | |
// Find the center. Ignore the window insets so that, on round watches | |
// with a "chin", the watch face is centered on the entire screen, not | |
// just the usable portion. | |
float centerX = width / 2f; | |
float centerY = height / 2f; | |
float circleCenter = centerY + FLAT_TIRE_OFFSET; | |
float minsPassed = mTime.minute; | |
float hoursPassed = mTime.hour; | |
float secsPassed = mTime.second; | |
float timePassedForCircle = minsPassed + hoursPassed * 60; | |
double rads = 0.87222222292 * timePassedForCircle; | |
canvas.drawArc(); | |
// Compute rotations and lengths for the clock hands. | |
float secRot = mTime.second / 30f * (float) Math.PI; | |
int minutes = mTime.minute; | |
float minRot = minutes / 30f * (float) Math.PI; | |
float hrRot = ((mTime.hour + (minutes / 60f)) / 6f ) * (float) Math.PI; | |
float secLength = centerX - 20; | |
float minLength = centerX - 40; | |
float hrLength = centerX - 80; | |
// Only draw the second hand in interactive mode. | |
/*if (!mAmbient) { | |
float secX = (float) Math.sin(secRot) * secLength; | |
float secY = (float) -Math.cos(secRot) * secLength; | |
canvas.drawLine(centerX, centerY, centerX + secX, centerY + | |
secY, mSecondPaint); | |
}*/ | |
// Draw the minute and hour hands. | |
float minX = (float) Math.sin(minRot) * minLength; | |
float minY = (float) -Math.cos(minRot) * minLength; | |
canvas.drawLine(centerX, centerY, centerX + minX, centerY + minY, | |
mMinutePaint); | |
float hrX = (float) Math.sin(hrRot) * hrLength; | |
float hrY = (float) -Math.cos(hrRot) * hrLength; | |
canvas.drawLine(centerX, centerY, centerX + hrX, centerY + hrY, | |
mHourPaint); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment