private final MediaSet[] mData;
private final MediaItem[] mCoverItem;
+ private final int[] mTotalCount;
private final long[] mItemVersion;
private final long[] mSetVersion;
mSource = Utils.checkNotNull(albumSet);
mCoverItem = new MediaItem[cacheSize];
mData = new MediaSet[cacheSize];
+ mTotalCount = new int[cacheSize];
mItemVersion = new long[cacheSize];
mSetVersion = new long[cacheSize];
Arrays.fill(mItemVersion, MediaObject.INVALID_DATA_VERSION);
mReloadTask.start();
}
- public MediaSet getMediaSet(int index) {
+ private void assertIsActive(int index) {
if (index < mActiveStart && index >= mActiveEnd) {
throw new IllegalArgumentException(String.format(
"%s not in (%s, %s)", index, mActiveStart, mActiveEnd));
}
+ }
+
+ public MediaSet getMediaSet(int index) {
+ assertIsActive(index);
return mData[index % mData.length];
}
public MediaItem getCoverItem(int index) {
- if (index < mActiveStart && index >= mActiveEnd) {
- throw new IllegalArgumentException(String.format(
- "%s not in (%s, %s)", index, mActiveStart, mActiveEnd));
- }
+ assertIsActive(index);
return mCoverItem[index % mCoverItem.length];
}
+ public int getTotalCount(int index) {
+ assertIsActive(index);
+ return mTotalCount[index % mTotalCount.length];
+ }
+
public int getActiveStart() {
return mActiveStart;
}
private void clearSlot(int slotIndex) {
mData[slotIndex] = null;
mCoverItem[slotIndex] = null;
+ mTotalCount[slotIndex] = 0;
mItemVersion[slotIndex] = MediaObject.INVALID_DATA_VERSION;
mSetVersion[slotIndex] = MediaObject.INVALID_DATA_VERSION;
}
public int size;
public MediaSet item;
public MediaItem cover;
+ public int totalCount;
}
private class GetUpdateInfo implements Callable<UpdateInfo> {
mItemVersion[pos] = itemVersion;
mData[pos] = info.item;
mCoverItem[pos] = info.cover;
+ mTotalCount[pos] = info.totalCount;
if (mDataListener != null
&& info.index >= mActiveStart && info.index < mActiveEnd) {
mDataListener.onContentChanged(info.index);
info.item = mSource.getSubMediaSet(info.index);
if (info.item == null) continue;
info.cover = info.item.getCoverMediaItem();
+ info.totalCount = info.item.getTotalMediaItemCount();
}
}
executeAndWait(new UpdateContent(info));
import android.text.TextUtils;
import com.android.gallery3d.R;
-import com.android.gallery3d.common.Utils;
import com.android.gallery3d.data.DataSourceType;
-import com.android.gallery3d.data.MediaSet;
import com.android.gallery3d.util.ThreadPool;
import com.android.gallery3d.util.ThreadPool.JobContext;
public ThreadPool.Job<Bitmap> requestLabel(
String title, String count, int sourceType) {
- return new AlbumLabelJob(null, title, count, sourceType);
+ return new AlbumLabelJob(title, count, sourceType);
}
- public ThreadPool.Job<Bitmap> requestLabel(
- MediaSet album, int sourceType) {
- return new AlbumLabelJob(album, null, null, sourceType);
- }
-
- private static void drawText(Canvas canvas,
+ static void drawText(Canvas canvas,
int x, int y, String text, int lengthLimit, TextPaint p) {
// The TextPaint cannot be used concurrently
synchronized (p) {
}
private class AlbumLabelJob implements ThreadPool.Job<Bitmap> {
- private final MediaSet mAlbum;
private final String mTitle;
private final String mCount;
private final int mSourceType;
- public AlbumLabelJob(MediaSet album,
- String title, String count, int sourceType) {
- mAlbum = album;
+ public AlbumLabelJob(String title, String count, int sourceType) {
mTitle = title;
mCount = count;
mSourceType = sourceType;
@Override
public Bitmap run(JobContext jc) {
- MediaSet album = mAlbum;
AlbumSetSlotRenderer.LabelSpec s = mSpec;
- String title = Utils.ensureNotNull(
- (album == null) ? mTitle : album.getName());
- String count = album == null
- ? Utils.ensureNotNull(mCount)
- : String.valueOf(album.getTotalMediaItemCount());
+ String title = mTitle;
+ String count = mCount;
Bitmap icon = getOverlayAlbumIcon(mSourceType);
Bitmap bitmap;
-/*
+/*T
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
public Texture content;
public Texture label;
public Path setPath;
+ public String title;
+ public int totalCount;
public int sourceType;
public int cacheFlag;
public int cacheStatus;
mData[slotIndex % mData.length] = null;
}
- private void updateAlbumSetEntry(AlbumSetEntry entry,
- int slotIndex, MediaSet album, MediaItem cover) {
+ private boolean isLabelChanged(
+ AlbumSetEntry entry, String title, int totalCount, int sourceType) {
+ return !Utils.equals(entry.title, title)
+ || entry.totalCount != totalCount
+ || entry.sourceType != sourceType;
+ }
+
+ private void updateAlbumSetEntry(AlbumSetEntry entry, int slotIndex) {
+ MediaSet album = mSource.getMediaSet(slotIndex);
+ MediaItem cover = mSource.getCoverItem(slotIndex);
+ int totalCount = mSource.getTotalCount(slotIndex);
+
entry.album = album;
entry.setDataVersion = getDataVersion(album);
- entry.sourceType = DataSourceType.identifySourceType(album);
entry.cacheFlag = identifyCacheFlag(album);
entry.cacheStatus = identifyCacheStatus(album);
entry.setPath = (album == null) ? null : album.getPath();
- if (entry.labelLoader != null) {
- entry.labelLoader.recycle();
- entry.labelLoader = null;
- entry.label = null;
- }
- if (album != null) {
- entry.labelLoader =
- new AlbumLabelLoader(slotIndex, album, entry.sourceType);
+ String title = (album == null) ? "" : Utils.ensureNotNull(album.getName());
+ int sourceType = DataSourceType.identifySourceType(album);
+ if (isLabelChanged(entry, title, totalCount, sourceType)) {
+ entry.title = title;
+ entry.totalCount = totalCount;
+ entry.sourceType = sourceType;
+ if (entry.labelLoader != null) {
+ entry.labelLoader.recycle();
+ entry.labelLoader = null;
+ entry.label = null;
+ }
+ if (album != null) {
+ entry.labelLoader = new AlbumLabelLoader(
+ slotIndex, title, totalCount, sourceType);
+ }
}
entry.coverItem = cover;
}
private void prepareSlotContent(int slotIndex) {
- MediaSet set = mSource.getMediaSet(slotIndex);
- MediaItem coverItem = mSource.getCoverItem(slotIndex);
AlbumSetEntry entry = new AlbumSetEntry();
- updateAlbumSetEntry(entry, slotIndex, set, coverItem);
+ updateAlbumSetEntry(entry, slotIndex);
mData[slotIndex % mData.length] = entry;
}
}
AlbumSetEntry entry = mData[index % mData.length];
- MediaSet set = mSource.getMediaSet(index);
- MediaItem coverItem = mSource.getCoverItem(index);
- updateAlbumSetEntry(entry, index, set, coverItem);
+ updateAlbumSetEntry(entry, index);
updateAllImageRequests();
updateTextureUploadQueue();
if (mListener != null && isActiveSlot(index)) {
public BitmapTexture getLoadingTexture() {
if (mLoadingLabel == null) {
- Bitmap bitmap = mLabelMaker.requestLabel(mLoadingText, null,
- DataSourceType.TYPE_NOT_CATEGORIZED)
+ Bitmap bitmap = mLabelMaker.requestLabel(
+ mLoadingText, "", DataSourceType.TYPE_NOT_CATEGORIZED)
.run(ThreadPool.JOB_CONTEXT_STUB);
mLoadingLabel = new BitmapTexture(bitmap);
mLoadingLabel.setOpaque(false);
}
private class AlbumLabelLoader extends BitmapLoader implements EntryUpdater {
- private final MediaSet mMediaSet;
private final int mSlotIndex;
+ private final String mTitle;
+ private final int mTotalCount;
private final int mSourceType;
public AlbumLabelLoader(
- int slotIndex, MediaSet mediaSet, int sourceType) {
+ int slotIndex, String title, int totalCount, int sourceType) {
mSlotIndex = slotIndex;
- mMediaSet = mediaSet;
+ mTitle = title;
+ mTotalCount = totalCount;
mSourceType = sourceType;
}
@Override
protected Future<Bitmap> submitBitmapTask(FutureListener<Bitmap> l) {
return mThreadPool.submit(mLabelMaker.requestLabel(
- mMediaSet, mSourceType), l);
+ mTitle, String.valueOf(mTotalCount), mSourceType), l);
}
@Override
entry.labelLoader = null;
entry.label = null;
}
- entry.labelLoader = (entry.album == null)
- ? null
- : new AlbumLabelLoader(i, entry.album, entry.sourceType);
+ if (entry.album != null) {
+ entry.labelLoader = new AlbumLabelLoader(i,
+ entry.title, entry.totalCount, entry.sourceType);
+ }
}
updateAllImageRequests();
updateTextureUploadQueue();