From 6cfe6a8d382002fc9bae18aac4d32f13d49d4324 Mon Sep 17 00:00:00 2001 From: Luan Nguyen Date: Tue, 30 Jun 2015 12:13:48 -0700 Subject: docs: Move scale Bitmap code to onSurfaceChanged bug: 21099578 Change-Id: I5e8d1c6c1757ec512ff2695689bc5b8c2c88706f --- .../html/training/wearables/watch-faces/drawing.jd | 27 ++++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/docs/html/training/wearables/watch-faces/drawing.jd b/docs/html/training/wearables/watch-faces/drawing.jd index 8b6de76..30a7a6f 100644 --- a/docs/html/training/wearables/watch-faces/drawing.jd +++ b/docs/html/training/wearables/watch-faces/drawing.jd @@ -457,9 +457,23 @@ watch face. The bounds take into account any inset areas, such as the "chin" on round devices. You can use this canvas to draw your watch face directly as follows:

    -
  1. If this is the first invocation of the -onDraw() -method, scale your background to fit.
  2. +
  3. Override the +onSurfaceChanged() +method to scale your background to fit the device any time the view changes. +
    +@Override
    +public void onSurfaceChanged(
    +        SurfaceHolder holder, int format, int width, int height) {
    +    if (mBackgroundScaledBitmap == null
    +            || mBackgroundScaledBitmap.getWidth() != width
    +            || mBackgroundScaledBitmap.getHeight() != height) {
    +        mBackgroundScaledBitmap = Bitmap.createScaledBitmap(mBackgroundBitmap,
    +                width, height, true /* filter */);
    +    }
    +    super.onSurfaceChanged(holder, format, width, height);
    +}
    +
    +
  4. Check whether the device is in ambient mode or interactive mode.
  5. Perform any required graphic computations.
  6. Draw your background bitmap on the canvas.
  7. @@ -482,13 +496,6 @@ public void onDraw(Canvas canvas, Rect bounds) { int width = bounds.width(); int height = bounds.height(); - // Draw the background, scaled to fit. - if (mBackgroundScaledBitmap == null - || mBackgroundScaledBitmap.getWidth() != width - || mBackgroundScaledBitmap.getHeight() != height) { - mBackgroundScaledBitmap = Bitmap.createScaledBitmap(mBackgroundBitmap, - width, height, true); - } canvas.drawBitmap(mBackgroundScaledBitmap, 0, 0, null); // Find the center. Ignore the window insets so that, on round watches -- cgit v1.1