I recently needed to solve the bitmap rotation problem for an Android Wear watchface.
The following onDraw code worked for me. Be sure your bitmaps are scaled before onDraw gets called:
// first draw the background
if (isInAmbientMode()) {
canvas.drawColor(Color.BLACK);
} else {
if (mBackgroundBitmapScaled == null) {
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mBackgroundPaint);
}
else {
canvas.drawBitmap(mBackgroundBitmapScaled, 0, 0, null);
}
}
// now setup to draw the hands..
float centerX = bounds.width() / 2f;
float centerY = bounds.height() / 2f;
float secRot = mCalendar.get(Calendar.SECOND) / 30f * (float) Math.PI;
int minutes = mCalendar.get(Calendar.MINUTE);
float minRot = minutes / 30f * (float) Math.PI;
float hrRot = ((mCalendar.get(Calendar.HOUR) + (minutes / 60f)) / 6f) * (float) Math.PI;
if (isInAmbientMode()) {
mHandPaint.clearShadowLayer();
float minLength = centerX - 40;
float hrLength = centerX - 80;
// hour hand
float hrX = (float) Math.sin(hrRot) * hrLength;
float hrY = (float) -Math.cos(hrRot) * hrLength;
canvas.drawLine(centerX, centerY, centerX + hrX, centerY + hrY, mHandPaint);
// minute hand
float minX = (float) Math.sin(minRot) * minLength;
float minY = (float) -Math.cos(minRot) * minLength;
canvas.drawLine(centerX, centerY, centerX + minX, centerY + minY, mHandPaint);
}
else {
// hour hand
Matrix matrix = new Matrix();
matrix.setRotate (hrRot / (float) Math.PI * 180, mHourHandBitmapScaled.getWidth()/2, mHourHandBitmapScaled.getHeight()/2);
canvas.drawBitmap(mHourHandBitmapScaled, matrix, mHandPaint);
// minute hand
matrix = new Matrix();
matrix.setRotate (minRot / (float) Math.PI * 180, mHourHandBitmapScaled.getWidth()/2, mHourHandBitmapScaled.getHeight()/2);
canvas.drawBitmap(mMinuteHandBitmapScaled, matrix, mHandPaint);
}
if (!mAmbient) {
// second hand
float secLength = centerX - 20;
float secX = (float) Math.sin(secRot) * secLength;
float secY = (float) -Math.cos(secRot) * secLength;
canvas.drawLine(centerX, centerY, centerX + secX, centerY + secY, mHandPaint);
}
and for scaling:
private void scaleWatchFace(int width, int height) {
Log.v(TAG, "scaleWatchFace");
mBackgroundBitmapScaled = Bitmap.createScaledBitmap(mBackgroundBitmap, width, height, true /* filter */);
float ratio = (float) width / mBackgroundBitmap.getWidth();
mMinuteHandBitmapScaled = Bitmap.createScaledBitmap(mMinuteHandBitmap,
(int) (mMinuteHandBitmap.getWidth() * ratio),
(int) (mMinuteHandBitmap.getHeight() * ratio), true);
mHourHandBitmapScaled = Bitmap.createScaledBitmap(mHourHandBitmap,
(int) (mHourHandBitmap.getWidth() * ratio),
(int) (mHourHandBitmap.getHeight() * ratio), true);
}
Note that the image sizes of my background and watch hand resources are all 480x480.
That eliminates any need for translation to center, and (possibly) is easier on the battery.
I hope this is useful.