diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/GridViewSpecial.java | 71 | ||||
-rw-r--r-- | src/com/android/camera/ImageGallery.java | 13 |
2 files changed, 51 insertions, 33 deletions
diff --git a/src/com/android/camera/GridViewSpecial.java b/src/com/android/camera/GridViewSpecial.java index be2a0e3..0ccc034 100644 --- a/src/com/android/camera/GridViewSpecial.java +++ b/src/com/android/camera/GridViewSpecial.java @@ -60,6 +60,9 @@ class GridViewSpecial extends View { public static interface DrawAdapter { public void drawImage(Canvas canvas, IImage image, Bitmap b, int xPos, int yPos, int w, int h); + public void drawDecoration(Canvas canvas, IImage image, + int xPos, int yPos, int w, int h); + public boolean needsDecoration(); } public static final int ORIGINAL_SELECT = -2; @@ -349,16 +352,6 @@ class GridViewSpecial extends View { return mCurrentSelection; } - public void invalidateImage(int index) { - if (!canHandleEvent()) return; - mImageBlockManager.invalidateImage(index); - } - - public void invalidateAllImages() { - if (!canHandleEvent()) return; - mImageBlockManager.invalidateAllImages(); - } - /** * * @param newSel ORIGINAL_SELECT (-2) means use old selection, @@ -458,6 +451,7 @@ class GridViewSpecial extends View { super.onDraw(canvas); if (!canHandleEvent()) return; mImageBlockManager.doDraw(canvas, getWidth(), getHeight(), mScrollY); + paintDecoration(canvas); paintSelection(canvas); moveDataWindow(); } @@ -627,6 +621,43 @@ class GridViewSpecial extends View { return super.onKeyUp(keyCode, event); } + private void paintDecoration(Canvas canvas) { + if (!mDrawAdapter.needsDecoration()) return; + + // Calculate visible region according to scroll position. + int startRow = (mScrollY - mSpec.mCellSpacing) / mBlockHeight; + int endRow = (mScrollY + getHeight() - mSpec.mCellSpacing - 1) + / mBlockHeight + 1; + + // Limit startRow and endRow to the valid range. + // Make sure we handle the mRows == 0 case right. + startRow = Math.max(Math.min(startRow, mRows - 1), 0); + endRow = Math.max(Math.min(endRow, mRows), 0); + + int startIndex = startRow * mColumns; + int endIndex = Math.min(endRow * mColumns, mCount); + + int xPos = mSpec.mLeftEdgePadding; + int yPos = mSpec.mCellSpacing + startRow * mBlockHeight; + int off = 0; + for (int i = startIndex; i < endIndex; i++) { + IImage image = mAllImages.getImageAt(i); + + mDrawAdapter.drawDecoration(canvas, image, xPos, yPos, + mSpec.mCellWidth, mSpec.mCellHeight); + + // Calculate next position + off += 1; + if (off == mColumns) { + xPos = mSpec.mLeftEdgePadding; + yPos += mBlockHeight; + off = 0; + } else { + xPos += mSpec.mCellWidth + mSpec.mCellSpacing; + } + } + } + private void paintSelection(Canvas canvas) { if (mCurrentSelection == SELECT_NONE) return; @@ -814,26 +845,6 @@ class ImageBlockManager { return mCache.remove(bestIndex); } - // invalidateAllImages and invalidateImage causes bitmaps in the blocks - // to be re-drawn. This is used to draw the check mark for multiselect. - public void invalidateAllImages() { - for (ImageBlock blk : mCache.values()) { - blk.invalidate(); - } - startLoading(); - } - - public void invalidateImage(int index) { - int row = index / mColumns; - int col = index - (row * mColumns); - ImageBlock blk = mCache.get(row); - if (blk == null) return; - if ((blk.mCompletedMask & (1 << col)) != 0) { - blk.mCompletedMask &= ~(1 << col); - } - startLoading(); - } - // After calling recycle(), the instance should not be used anymore. public void recycle() { for (ImageBlock blk : mCache.values()) { diff --git a/src/com/android/camera/ImageGallery.java b/src/com/android/camera/ImageGallery.java index 2235dea..993d4f3 100644 --- a/src/com/android/camera/ImageGallery.java +++ b/src/com/android/camera/ImageGallery.java @@ -660,7 +660,7 @@ public class ImageGallery extends Activity implements if (mMultiSelected != null) { int original = mMultiSelected.size(); if (!mMultiSelected.add(img)) mMultiSelected.remove(img); - mGvs.invalidateImage(index); + mGvs.invalidate(); if (original == 0) showFooter(); if (mMultiSelected.size() == 0) hideFooter(); return; @@ -915,7 +915,14 @@ public class ImageGallery extends Activity implements overlay.setBounds(mSrcRect); overlay.draw(canvas); } + } + public boolean needsDecoration() { + return (mMultiSelected != null); + } + + public void drawDecoration(Canvas canvas, IImage image, + int xPos, int yPos, int w, int h) { if (mMultiSelected != null) { initializeMultiSelectDrawables(); @@ -1016,13 +1023,13 @@ public class ImageGallery extends Activity implements private void closeMultiSelectMode() { if (mMultiSelected == null) return; mMultiSelected = null; - mGvs.invalidateAllImages(); + mGvs.invalidate(); hideFooter(); } private void openMultiSelectMode() { if (mMultiSelected != null) return; mMultiSelected = new HashSet<IImage>(); - mGvs.invalidateAllImages(); + mGvs.invalidate(); } } |