Also adjust the upload order to upload nearby textures first.
Change-Id: I2d6a8807a14b4602882dd2e5c03030c356f49e47
private static final int FONT_COLOR_TITLE = Color.WHITE;
private static final int FONT_COLOR_COUNT = 0x80FFFFFF; // 50% white
+ // We keep a border around the album label to prevent aliasing
+ private static final int BORDER_SIZE = 1;
+ private static final int BACKGROUND_COLOR = 0x60000000; // 36% Dark
+
private final AlbumSetView.LabelSpec mSpec;
private final TextPaint mTitlePaint;
private final TextPaint mCountPaint;
mMtpIcon = new LazyLoadedBitmap(R.drawable.frame_overlay_gallery_ptp);
}
+ public static int getBorderSize() {
+ return BORDER_SIZE;
+ }
+
private Bitmap getOverlayAlbumIcon(int sourceType) {
switch (sourceType) {
case DataSourceType.TYPE_CAMERA:
public synchronized void setLabelWidth(int width) {
if (mLabelWidth == width) return;
mLabelWidth = width;
- mBitmapPool = new BitmapPool(mLabelWidth, mSpec.labelBackgroundHeight);
+ int borders = 2 * BORDER_SIZE;
+ mBitmapPool = new BitmapPool(
+ width + borders, mSpec.labelBackgroundHeight + borders);
}
public ThreadPool.Job<Bitmap> requestLabel(
: String.valueOf(album.getTotalMediaItemCount());
Bitmap icon = getOverlayAlbumIcon(mSourceType);
- Bitmap bitmap = null;
- Canvas canvas;
+ Bitmap bitmap;
int labelWidth;
synchronized (this) {
labelWidth = mLabelWidth;
bitmap = mBitmapPool.getBitmap();
}
+
if (bitmap == null) {
- bitmap = Bitmap.createBitmap(labelWidth,
- s.labelBackgroundHeight, Config.ARGB_8888);
- canvas = new Canvas(bitmap);
- } else {
- canvas = new Canvas(bitmap);
- canvas.drawColor(0, PorterDuff.Mode.SRC);
+ int borders = 2 * BORDER_SIZE;
+ bitmap = Bitmap.createBitmap(labelWidth + borders,
+ s.labelBackgroundHeight + borders, Config.ARGB_8888);
}
+ Canvas canvas = new Canvas(bitmap);
+ canvas.clipRect(BORDER_SIZE, BORDER_SIZE,
+ bitmap.getWidth() - BORDER_SIZE,
+ bitmap.getHeight() - BORDER_SIZE);
+ canvas.drawColor(BACKGROUND_COLOR, PorterDuff.Mode.SRC);
+
+ canvas.translate(BORDER_SIZE, BORDER_SIZE);
+
// draw title
if (jc.isCancelled()) return null;
int x = s.leftMargin;
return loader.isRequestInProgress();
}
- private void queueTextureForUpload(boolean isActive, Texture texture) {
- if ((texture == null) || !(texture instanceof BitmapTexture)) return;
- if (isActive) {
- mTextureUploader.addFgTexture((BitmapTexture) texture);
- } else {
- mTextureUploader.addBgTexture((BitmapTexture) texture);
+ private void uploadBackgroundTextureInSlot(int index) {
+ if (index < mContentStart || index >= mContentEnd) return;
+ AlbumSetEntry entry = mData[index % mData.length];
+ if (entry.content instanceof BitmapTexture) {
+ mTextureUploader.addBgTexture((BitmapTexture) entry.content);
+ }
+ if (entry.label instanceof BitmapTexture) {
+ mTextureUploader.addBgTexture((BitmapTexture) entry.label);
}
}
private void updateTextureUploadQueue() {
if (!mIsActive) return;
mTextureUploader.clear();
- for (int i = mContentStart, n = mContentEnd; i < n; ++i) {
+
+ // Upload foreground texture
+ for (int i = mActiveStart, n = mActiveEnd; i < n; ++i) {
AlbumSetEntry entry = mData[i % mData.length];
- boolean isActive = isActiveSlot(i);
- queueTextureForUpload(isActive, entry.label);
- queueTextureForUpload(isActive, entry.content);
+ if (entry.content instanceof BitmapTexture) {
+ mTextureUploader.addFgTexture((BitmapTexture) entry.content);
+ }
+ if (entry.label instanceof BitmapTexture) {
+ mTextureUploader.addFgTexture((BitmapTexture) entry.label);
+ }
+ }
+
+ // add background textures
+ int range = Math.max(
+ (mContentEnd - mActiveEnd), (mActiveStart - mContentStart));
+ for (int i = 0; i < range; ++i) {
+ uploadBackgroundTextureInSlot(mActiveEnd + i);
+ uploadBackgroundTextureInSlot(mActiveStart - i - 1);
}
}
import android.content.Context;
-import com.android.gallery3d.R;
import com.android.gallery3d.app.GalleryActivity;
import com.android.gallery3d.data.MediaItem;
import com.android.gallery3d.data.MediaObject;
public class AlbumSetView extends AbstractSlotRenderer {
@SuppressWarnings("unused")
private static final String TAG = "AlbumSetView";
- private static final int CACHE_SIZE = 64;
+ private static final int CACHE_SIZE = 96;
private static final int PLACEHOLDER_COLOR = 0xFF222222;
private final ColorTexture mWaitLoadingTexture;
protected AlbumSetSlidingWindow mDataWindow;
private SlotView mSlotView;
- private NinePatchTexture mDarkStrip;
private int mPressedIndex = -1;
private Path mHighlightItemPath = null;
mWaitLoadingTexture.setSize(1, 1);
Context context = activity.getAndroidContext();
- mDarkStrip = new NinePatchTexture(context, R.drawable.dark_strip);
}
public void setPressedIndex(int index) {
content = mDataWindow.getLoadingTexture();
}
if (content != null) {
- int h = mLabelSpec.labelBackgroundHeight;
- drawFrame(canvas, mDarkStrip, 0, height - h, width, h);
- content.draw(canvas, 0, height - h, width, h);
+ int b = AlbumLabelMaker.getBorderSize();
+ int h = content.getHeight();
+ content.draw(canvas, -b, height - h + b, width + b + b, h);
}
return 0;
}
import android.os.Message;
import com.android.gallery3d.app.GalleryActivity;
-import com.android.gallery3d.common.BitmapUtils;
import com.android.gallery3d.common.Utils;
import com.android.gallery3d.data.MediaItem;
import com.android.gallery3d.data.Path;
0, Math.max(0, mSize - data.length));
int contentEnd = Math.min(contentStart + data.length, mSize);
setContentWindow(contentStart, contentEnd);
- updateUploadedTextures();
+ updateTextureUploadQueue();
if (mIsActive) updateAllImageRequests();
}
- private void uploadTexture(boolean isActive, Texture texture) {
- if ((texture == null) || !(texture instanceof BitmapTexture)) return;
- if (isActive) {
- mTextureUploader.addFgTexture((BitmapTexture) texture);
- } else {
- mTextureUploader.addBgTexture((BitmapTexture) texture);
+ private void uploadBgTextureInSlot(int index) {
+ if (index < mContentEnd && index >= mContentStart) {
+ AlbumEntry entry = mData[index % mData.length];
+ if (entry.content instanceof BitmapTexture) {
+ mTextureUploader.addBgTexture((BitmapTexture) entry.content);
+ }
}
}
- private void updateUploadedTextures() {
+ private void updateTextureUploadQueue() {
if (!mIsActive) return;
mTextureUploader.clear();
- for (int i = mContentStart, n = mContentEnd; i < n; ++i) {
+
+ // add foreground textures
+ for (int i = mActiveStart, n = mActiveEnd; i < n; ++i) {
AlbumEntry entry = mData[i % mData.length];
- boolean isActive = isActiveSlot(i);
- uploadTexture(isActive, entry.content);
+ if (entry.content instanceof BitmapTexture) {
+ mTextureUploader.addFgTexture((BitmapTexture) entry.content);
+ }
+ }
+
+ // add background textures
+ int range = Math.max(
+ (mContentEnd - mActiveEnd), (mActiveStart - mContentStart));
+ for (int i = 0; i < range; ++i) {
+ uploadBgTextureInSlot(mActiveEnd + i);
+ uploadBgTextureInSlot(mActiveStart - i - 1);
}
}
@SuppressWarnings("unused")
private static final String TAG = "AlbumView";
- private static final int CACHE_SIZE = 64;
+ private static final int CACHE_SIZE = 96;
private AlbumSlidingWindow mDataWindow;
private final GalleryActivity mActivity;