diff options
author | Luan Nguyen <luann@google.com> | 2015-06-30 22:02:23 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-06-30 22:02:23 +0000 |
commit | a4ac253bc36bbced5acad8a7ddf1838b11f6e44c (patch) | |
tree | 7ff8897bec4e7134a5f91b526a0026261f3fcec4 /docs | |
parent | 45e50f87bb2b2cd11b19ee102223c03356d77042 (diff) | |
parent | ed053477d0f76edad4853f0a5aac275acfe2d6ce (diff) | |
download | frameworks_base-a4ac253bc36bbced5acad8a7ddf1838b11f6e44c.zip frameworks_base-a4ac253bc36bbced5acad8a7ddf1838b11f6e44c.tar.gz frameworks_base-a4ac253bc36bbced5acad8a7ddf1838b11f6e44c.tar.bz2 |
am ed053477: Merge "docs: Move scale Bitmap code to onSurfaceChanged" into mnc-preview-docs
* commit 'ed053477d0f76edad4853f0a5aac275acfe2d6ce':
docs: Move scale Bitmap code to onSurfaceChanged
Diffstat (limited to 'docs')
-rw-r--r-- | docs/html/training/wearables/watch-faces/drawing.jd | 27 |
1 files 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:</p> <ol> -<li>If this is the first invocation of the -<a href="{@docRoot}reference/android/support/wearable/watchface/CanvasWatchFaceService.Engine.html#onDraw(android.graphics.Canvas, android.graphics.Rect)"><code>onDraw()</code></a> -method, scale your background to fit.</li> +<li>Override the +<a href="{@docRoot}reference/android/support/wearable/watchface/CanvasWatchFaceService.Engine.html#onSurfaceChanged(android.view.SurfaceHolder, int, int, int)"><code>onSurfaceChanged()</code></a> +method to scale your background to fit the device any time the view changes. +<pre> +@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); +} +</pre> +</li> <li>Check whether the device is in ambient mode or interactive mode.</li> <li>Perform any required graphic computations.</li> <li>Draw your background bitmap on the canvas.</li> @@ -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 |