diff options
author | Owen Lin <owenlin@google.com> | 2012-10-11 15:50:38 +0800 |
---|---|---|
committer | Owen Lin <owenlin@google.com> | 2012-10-16 10:29:28 +0800 |
commit | d3cd5c499ce58f3ad69d58acafd4f251a149fdbb (patch) | |
tree | e4477f8db5f3322ecafd343bb71a043053163c56 /src/com/android/gallery3d/ui/BitmapScreenNail.java | |
parent | a942400efc37c5dd05b3c615092ae8d0f2ca7e2c (diff) | |
download | android_packages_apps_Snap-d3cd5c499ce58f3ad69d58acafd4f251a149fdbb.tar.gz android_packages_apps_Snap-d3cd5c499ce58f3ad69d58acafd4f251a149fdbb.tar.bz2 android_packages_apps_Snap-d3cd5c499ce58f3ad69d58acafd4f251a149fdbb.zip |
Fixes bugs in TiledTexture.
1. Upload tiles in SinglePhotoDataAdapter
2. Rebuild the upload queue after the screen nails being recycled
bug: 6399444
Change-Id: I57e756f8d1d84742bf82dd34c83baf8df89ae4cc
Diffstat (limited to 'src/com/android/gallery3d/ui/BitmapScreenNail.java')
-rw-r--r-- | src/com/android/gallery3d/ui/BitmapScreenNail.java | 180 |
1 files changed, 11 insertions, 169 deletions
diff --git a/src/com/android/gallery3d/ui/BitmapScreenNail.java b/src/com/android/gallery3d/ui/BitmapScreenNail.java index 9b629160c..741eefbe3 100644 --- a/src/com/android/gallery3d/ui/BitmapScreenNail.java +++ b/src/com/android/gallery3d/ui/BitmapScreenNail.java @@ -19,198 +19,40 @@ package com.android.gallery3d.ui; import android.graphics.Bitmap; import android.graphics.RectF; -import com.android.gallery3d.common.Utils; -import com.android.gallery3d.data.BitmapPool; -import com.android.gallery3d.data.MediaItem; - -// This is a ScreenNail wraps a Bitmap. There are some extra functions: -// -// - If we need to draw before the bitmap is available, we draw a rectange of -// placeholder color (gray). -// -// - When the the bitmap is available, and we have drawn the placeholder color -// before, we will do a fade-in animation. public class BitmapScreenNail implements ScreenNail { - @SuppressWarnings("unused") - private static final String TAG = "BitmapScreenNail"; - - // The duration of the fading animation in milliseconds - private static final int DURATION = 180; - - private static int sMaxSide = 640; - - // These are special values for mAnimationStartTime - private static final long ANIMATION_NOT_NEEDED = -1; - private static final long ANIMATION_NEEDED = -2; - private static final long ANIMATION_DONE = -3; - - private int mWidth; - private int mHeight; - private long mAnimationStartTime = ANIMATION_NOT_NEEDED; - - private Bitmap mBitmap; - private TiledTexture mTexture; + private final BitmapTexture mBitmapTexture; public BitmapScreenNail(Bitmap bitmap) { - mWidth = bitmap.getWidth(); - mHeight = bitmap.getHeight(); - mBitmap = bitmap; - mTexture = new TiledTexture(bitmap); - } - - public BitmapScreenNail(int width, int height) { - setSize(width, height); - } - - // This gets overridden by bitmap_screennail_placeholder - // in GalleryUtils.initialize - private static int mPlaceholderColor = 0xFF222222; - private static boolean mDrawPlaceholder = true; - - public static void setPlaceholderColor(int color) { - mPlaceholderColor = color; - } - - private void setSize(int width, int height) { - if (width == 0 || height == 0) { - width = sMaxSide; - height = sMaxSide * 3 / 4; - } - float scale = Math.min(1, (float) sMaxSide / Math.max(width, height)); - mWidth = Math.round(scale * width); - mHeight = Math.round(scale * height); - } - - private static void recycleBitmap(BitmapPool pool, Bitmap bitmap) { - if (pool == null || bitmap == null) return; - pool.recycle(bitmap); - } - - // Combines the two ScreenNails. - // Returns the used one and recycle the unused one. - public ScreenNail combine(ScreenNail other) { - if (other == null) { - return this; - } - - if (!(other instanceof BitmapScreenNail)) { - recycle(); - return other; - } - - // Now both are BitmapScreenNail. Move over the information about width, - // height, and Bitmap, then recycle the other. - BitmapScreenNail newer = (BitmapScreenNail) other; - mWidth = newer.mWidth; - mHeight = newer.mHeight; - if (newer.mTexture != null) { - recycleBitmap(MediaItem.getThumbPool(), mBitmap); - if (mTexture != null) mTexture.recycle(); - mBitmap = newer.mBitmap; - mTexture = newer.mTexture; - newer.mBitmap = null; - newer.mTexture = null; - } - newer.recycle(); - return this; - } - - public void updatePlaceholderSize(int width, int height) { - if (mBitmap != null) return; - if (width == 0 || height == 0) return; - setSize(width, height); + mBitmapTexture = new BitmapTexture(bitmap); } @Override public int getWidth() { - return mWidth; + return mBitmapTexture.getWidth(); } @Override public int getHeight() { - return mHeight; + return mBitmapTexture.getHeight(); } @Override - public void noDraw() { + public void draw(GLCanvas canvas, int x, int y, int width, int height) { + mBitmapTexture.draw(canvas, x, y, width, height); } @Override - public void recycle() { - if (mTexture != null) { - mTexture.recycle(); - mTexture = null; - } - recycleBitmap(MediaItem.getThumbPool(), mBitmap); - mBitmap = null; - } - - public static void disableDrawPlaceholder() { - mDrawPlaceholder = false; - } - - public static void enableDrawPlaceholder() { - mDrawPlaceholder = true; + public void noDraw() { + // do nothing } @Override - public void draw(GLCanvas canvas, int x, int y, int width, int height) { - if (mTexture == null || !mTexture.isReady()) { - if (mAnimationStartTime == ANIMATION_NOT_NEEDED) { - mAnimationStartTime = ANIMATION_NEEDED; - } - if(mDrawPlaceholder) { - canvas.fillRect(x, y, width, height, mPlaceholderColor); - } - return; - } - - if (mAnimationStartTime == ANIMATION_NEEDED) { - mAnimationStartTime = AnimationTime.get(); - } - - if (isAnimating()) { - mTexture.drawMixed(canvas, mPlaceholderColor, getRatio(), x, y, - width, height); - } else { - mTexture.draw(canvas, x, y, width, height); - } + public void recycle() { + mBitmapTexture.recycle(); } @Override public void draw(GLCanvas canvas, RectF source, RectF dest) { - if (mTexture == null || !mTexture.isReady()) { - canvas.fillRect(dest.left, dest.top, dest.width(), dest.height(), - mPlaceholderColor); - return; - } - - mTexture.draw(canvas, source, dest); - } - - public boolean isAnimating() { - if (mAnimationStartTime < 0) return false; - if (AnimationTime.get() - mAnimationStartTime >= DURATION) { - mAnimationStartTime = ANIMATION_DONE; - return false; - } - return true; - } - - private float getRatio() { - float r = (float) (AnimationTime.get() - mAnimationStartTime) / DURATION; - return Utils.clamp(1.0f - r, 0.0f, 1.0f); - } - - public boolean isShowingPlaceholder() { - return (mBitmap == null) || isAnimating(); - } - - public TiledTexture getTexture() { - return mTexture; - } - - public static void setMaxSide(int size) { - sMaxSide = size; + canvas.drawTexture(mBitmapTexture, source, dest); } } |