summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChih-Chung Chang <chihchung@google.com>2009-05-13 17:51:11 +0800
committerChih-Chung Chang <chihchung@google.com>2009-05-14 10:16:59 +0800
commitdd42edfae98465a19aefba49f558e0b43ceca4c4 (patch)
treee9a9bb47593f0d63350c1ffbec1de0725c00332f /src
parent77e110b93d904a19d9d454c825688cf1706f2392 (diff)
downloadLegacyCamera-dd42edfae98465a19aefba49f558e0b43ceca4c4.zip
LegacyCamera-dd42edfae98465a19aefba49f558e0b43ceca4c4.tar.gz
LegacyCamera-dd42edfae98465a19aefba49f558e0b43ceca4c4.tar.bz2
Tweak to speed up Gallery.
Diffstat (limited to 'src')
-rw-r--r--src/com/android/camera/ImageGallery.java34
-rw-r--r--src/com/android/camera/ImageManager.java5
-rw-r--r--src/com/android/camera/gallery/BaseImageList.java16
3 files changed, 32 insertions, 23 deletions
diff --git a/src/com/android/camera/ImageGallery.java b/src/com/android/camera/ImageGallery.java
index 58df5fe..a8db347 100644
--- a/src/com/android/camera/ImageGallery.java
+++ b/src/com/android/camera/ImageGallery.java
@@ -814,6 +814,12 @@ public class ImageGallery extends Activity implements
private Drawable mMultiSelectTrue;
private Drawable mMultiSelectFalse;
+ // mSrcRect and mDstRect are only used in drawImage, but we put them as
+ // instance variables to reduce the memory allocation overhead because
+ // drawImage() is called a lot.
+ private Rect mSrcRect = new Rect();
+ private Rect mDstRect = new Rect();
+
public void drawImage(Canvas canvas, IImage image,
Bitmap b, int xPos, int yPos, int w, int h) {
if (b != null) {
@@ -830,14 +836,14 @@ public class ImageGallery extends Activity implements
if (deltaW < 10 && deltaH < 10) {
int halfDeltaW = deltaW / 2;
int halfDeltaH = deltaH / 2;
- Rect src = new Rect(0 + halfDeltaW, 0 + halfDeltaH,
+ mSrcRect.set(0 + halfDeltaW, 0 + halfDeltaH,
bw - halfDeltaW, bh - halfDeltaH);
- Rect dst = new Rect(xPos, yPos, xPos + w, yPos + h);
- canvas.drawBitmap(b, src, dst, null);
+ mDstRect.set(xPos, yPos, xPos + w, yPos + h);
+ canvas.drawBitmap(b, mSrcRect, mDstRect, 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, null);
+ mSrcRect.set(0, 0, bw, bh);
+ mDstRect.set(xPos, yPos, xPos + w, yPos + h);
+ canvas.drawBitmap(b, mSrcRect, mDstRect, null);
}
} else {
// If the thumbnail cannot be drawn, put up an error icon
@@ -845,12 +851,13 @@ public class ImageGallery extends Activity implements
Bitmap error = getErrorBitmap(image);
int width = error.getWidth();
int height = error.getHeight();
- Rect source = new Rect(0, 0, width, height);
+ mSrcRect.set(0, 0, width, height);
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, null);
+ mDstRect.set(left, top, left + width, top + height);
+ canvas.drawBitmap(error, mSrcRect, mDstRect, null);
}
+
if (ImageManager.isVideo(image)) {
Drawable overlay = null;
long size = MenuHelper.getImageFileSize(image);
@@ -874,9 +881,8 @@ public class ImageGallery extends Activity implements
int height = overlay.getIntrinsicHeight();
int left = (w - width) / 2 + xPos;
int top = (h - height) / 2 + yPos;
- Rect newBounds =
- new Rect(left, top, left + width, top + height);
- overlay.setBounds(newBounds);
+ mSrcRect.set(left, top, left + width, top + height);
+ overlay.setBounds(mSrcRect);
overlay.draw(canvas);
}
@@ -890,8 +896,8 @@ public class ImageGallery extends Activity implements
int height = checkBox.getIntrinsicHeight();
int left = 5 + xPos;
int top = h - height - 5 + yPos;
- checkBox.setBounds(new Rect(
- left, top, left + width, top + height));
+ mSrcRect.set(left, top, left + width, top + height);
+ checkBox.setBounds(mSrcRect);
checkBox.draw(canvas);
}
}
diff --git a/src/com/android/camera/ImageManager.java b/src/com/android/camera/ImageManager.java
index 40d650a..80a7790 100644
--- a/src/com/android/camera/ImageManager.java
+++ b/src/com/android/camera/ImageManager.java
@@ -27,6 +27,7 @@ import com.android.camera.gallery.ImageList;
import com.android.camera.gallery.ImageListUber;
import com.android.camera.gallery.SingleImageList;
import com.android.camera.gallery.VideoList;
+import com.android.camera.gallery.VideoObject;
import android.content.ContentResolver;
import android.content.ContentUris;
@@ -156,7 +157,9 @@ public class ImageManager {
* @return true if the image is a video.
*/
public static boolean isVideo(IImage image) {
- return Util.isVideoMimeType(image.getMimeType());
+ // This is the right implementation, but we use instanceof for speed.
+ //return Util.isVideoMimeType(image.getMimeType());
+ return (image instanceof VideoObject);
}
public static void setImageSize(ContentResolver cr, Uri uri, long size) {
diff --git a/src/com/android/camera/gallery/BaseImageList.java b/src/com/android/camera/gallery/BaseImageList.java
index 7798e04..5a5f141 100644
--- a/src/com/android/camera/gallery/BaseImageList.java
+++ b/src/com/android/camera/gallery/BaseImageList.java
@@ -375,16 +375,16 @@ public abstract class BaseImageList implements IImageList {
if (moved) {
try {
long id = c.getLong(indexId());
- long miniThumbMagic = 0;
- int rotation = 0;
- if (indexMiniThumbMagic() != -1) {
- miniThumbMagic = c.getLong(indexMiniThumbMagic());
- }
- if (indexOrientation() != -1) {
- rotation = c.getInt(indexOrientation());
- }
IImage img = mCache.get(id);
if (img == null) {
+ long miniThumbMagic = 0;
+ int rotation = 0;
+ if (indexMiniThumbMagic() != -1) {
+ miniThumbMagic = c.getLong(indexMiniThumbMagic());
+ }
+ if (indexOrientation() != -1) {
+ rotation = c.getInt(indexOrientation());
+ }
img = make(id, miniThumbMagic, mContentResolver, this,
i, rotation);
mCache.put(id, img);