diff options
author | Chih-Chung Chang <chihchung@google.com> | 2009-04-30 14:35:02 +0800 |
---|---|---|
committer | Chih-Chung Chang <chihchung@google.com> | 2009-04-30 17:04:33 +0800 |
commit | 3d6c628d8cb0334165b7d49aa5b924b938a0bc4b (patch) | |
tree | ef53beb57c14321b5e5faec714a89915a6528df7 /src | |
parent | 58e7c4584fbb4bdd1b3475186ae8eabac3946bce (diff) | |
download | LegacyCamera-3d6c628d8cb0334165b7d49aa5b924b938a0bc4b.zip LegacyCamera-3d6c628d8cb0334165b7d49aa5b924b938a0bc4b.tar.gz LegacyCamera-3d6c628d8cb0334165b7d49aa5b924b938a0bc4b.tar.bz2 |
Cache NinePatch to Bitmap to reduce drawing time.
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/GridViewSpecial.java | 58 | ||||
-rw-r--r-- | src/com/android/camera/ImageGallery.java | 9 |
2 files changed, 48 insertions, 19 deletions
diff --git a/src/com/android/camera/GridViewSpecial.java b/src/com/android/camera/GridViewSpecial.java index 158076c..9d33521 100644 --- a/src/com/android/camera/GridViewSpecial.java +++ b/src/com/android/camera/GridViewSpecial.java @@ -314,6 +314,41 @@ class GridViewSpecial extends View { } } + // We cache the three outlines from NinePatch to Bitmap to speed up + // drawing. The cache must be updated if the cell size is changed. + private static final int OUTLINE_EMPTY = 0; + private static final int OUTLINE_PRESSED = 1; + private static final int OUTLINE_SELECTED = 2; + + private Bitmap mOutline[] = new Bitmap[3]; + + private void generateOutlineBitmap() { + int w = mCurrentSpec.mCellWidth; + int h = mCurrentSpec.mCellHeight; + + for (int i = 0; i < mOutline.length; i++) { + mOutline[i] = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); + } + + Drawable cellOutline; + cellOutline = GridViewSpecial.this.getResources() + .getDrawable(android.R.drawable.gallery_thumb); + cellOutline.setBounds(0, 0, w, h); + Canvas canvas = new Canvas(); + + canvas.setBitmap(mOutline[OUTLINE_EMPTY]); + cellOutline.setState(EMPTY_STATE_SET); + cellOutline.draw(canvas); + + canvas.setBitmap(mOutline[OUTLINE_PRESSED]); + cellOutline.setState(PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET); + cellOutline.draw(canvas); + + canvas.setBitmap(mOutline[OUTLINE_SELECTED]); + cellOutline.setState(ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET); + cellOutline.draw(canvas); + } + @Override public void onLayout(boolean changed, int left, int top, int right, int bottom) { @@ -343,6 +378,9 @@ class GridViewSpecial extends View { + (rows * (spec.mCellSpacing + spec.mCellHeight)) - (bottom - top); + + generateOutlineBitmap(); + if (mImageBlockManager == null) { mImageBlockManager = new ImageBlockManager(); mImageBlockManager.moveDataWindow(true); @@ -616,7 +654,6 @@ class GridViewSpecial extends View { int currentBlock = (scrollPos < 0) ? ((scrollPos - height + 1) / height) : (scrollPos / height); - Paint paint = new Paint(); while (true) { final int yPos = currentBlock * height; if (yPos >= scrollPos + thisHeight) { @@ -624,7 +661,7 @@ class GridViewSpecial extends View { } if (currentBlock < 0) { - canvas.drawRect(0, yPos, thisWidth, 0, paint); + canvas.drawRect(0, yPos, thisWidth, 0, null); currentBlock += 1; continue; } @@ -641,7 +678,7 @@ class GridViewSpecial extends View { synchronized (block) { Bitmap b = block.mBitmap; - canvas.drawBitmap(b, 0, yPos, paint); + canvas.drawBitmap(b, 0, yPos, null); } } } @@ -652,7 +689,6 @@ class GridViewSpecial extends View { } private class ImageBlock { - Drawable mCellOutline; Bitmap mBitmap = Bitmap.createBitmap(getWidth(), blockHeight(), Bitmap.Config.RGB_565); Canvas mCanvas = new Canvas(mBitmap); @@ -672,8 +708,6 @@ class GridViewSpecial extends View { mPaint.setColor(0xFFDDDDDD); mCanvas.drawColor(0xFF000000); mBlockNumber = SELECT_NONE; - mCellOutline = GridViewSpecial.this.getResources() - .getDrawable(android.R.drawable.gallery_thumb); } private void recycleBitmaps() { @@ -813,20 +847,16 @@ class GridViewSpecial extends View { } private void paintSel(int pos, int xPos, int yPos) { - int[] stateSet = EMPTY_STATE_SET; + int type = OUTLINE_EMPTY; if (pos == mCurrentSelection && mShowSelection) { if (mCurrentSelectionPressed) { - stateSet = PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; + type = OUTLINE_PRESSED; } else { - stateSet = ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; + type = OUTLINE_SELECTED; } } - mCellOutline.setState(stateSet); - mCellOutline.setBounds(xPos, yPos, - xPos + mCurrentSpec.mCellWidth, - yPos + mCurrentSpec.mCellHeight); - mCellOutline.draw(mCanvas); + mCanvas.drawBitmap(mOutline[type], xPos, yPos, null); } private synchronized void loadImage( diff --git a/src/com/android/camera/ImageGallery.java b/src/com/android/camera/ImageGallery.java index e3bf1d6..ef8871e 100644 --- a/src/com/android/camera/ImageGallery.java +++ b/src/com/android/camera/ImageGallery.java @@ -801,8 +801,6 @@ public class ImageGallery extends Activity implements public void drawImage(Canvas canvas, IImage image, Bitmap b, int xPos, int yPos, int w, int h) { - Paint paint = new Paint(); - if (b != null) { // if the image is close to the target size then crop, // otherwise scale both the bitmap and the view should be @@ -820,11 +818,11 @@ public class ImageGallery extends Activity implements Rect src = new Rect(0 + halfDeltaW, 0 + halfDeltaH, bw - halfDeltaW, bh - halfDeltaH); Rect dst = new Rect(xPos, yPos, xPos + w, yPos + h); - canvas.drawBitmap(b, src, dst, paint); + canvas.drawBitmap(b, src, dst, null); } else { Rect src = new Rect(0, 0, bw, bh); Rect dst = new Rect(xPos, yPos, xPos + w, yPos + h); - canvas.drawBitmap(b, src, dst, paint); + canvas.drawBitmap(b, src, dst, null); } } else { // If the thumbnail cannot be drawn, put up an error icon @@ -836,7 +834,7 @@ public class ImageGallery extends Activity implements int left = (w - width) / 2 + xPos; int top = (w - height) / 2 + yPos; Rect dest = new Rect(left, top, left + width, top + height); - canvas.drawBitmap(error, source, dest, paint); + canvas.drawBitmap(error, source, dest, null); } if (ImageManager.isVideo(image)) { Drawable overlay = null; @@ -853,6 +851,7 @@ public class ImageGallery extends Activity implements R.drawable.ic_error_mms_video_overlay); } overlay = mVideoMmsErrorOverlay; + Paint paint = new Paint(); paint.setARGB(0x80, 0x00, 0x00, 0x00); canvas.drawRect(xPos, yPos, xPos + w, yPos + h, paint); } |