diff options
author | Owen Lin <owenlin@google.com> | 2012-03-28 00:31:07 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-03-28 00:31:07 -0700 |
commit | 68299015ac722e050794c5b3d8a3991871cac9f5 (patch) | |
tree | 06e08806db05aa6ac270f9462b95cfd965ad8089 | |
parent | 4062ad476a6fdf65a29a3d2716d7ac3179a02055 (diff) | |
parent | 83a036c52d6c157ca52bee67b9c6ec3018b4a47d (diff) | |
download | android_packages_apps_Snap-68299015ac722e050794c5b3d8a3991871cac9f5.tar.gz android_packages_apps_Snap-68299015ac722e050794c5b3d8a3991871cac9f5.tar.bz2 android_packages_apps_Snap-68299015ac722e050794c5b3d8a3991871cac9f5.zip |
Merge "Refactor. Make the code simpler."
-rw-r--r-- | src/com/android/gallery3d/app/AlbumPage.java | 49 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/AlbumSetPage.java | 45 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/ManageCachePage.java | 17 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java | 14 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/AlbumSetView.java | 161 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/AlbumSlidingWindow.java | 12 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/AlbumView.java | 143 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/DisplayItem.java | 6 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/FilmStripView.java | 23 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/Paper.java | 12 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/RelativePosition.java | 42 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/SlotView.java | 192 |
12 files changed, 269 insertions, 447 deletions
diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java index 818a2ff3d..8bd2badf8 100644 --- a/src/com/android/gallery3d/app/AlbumPage.java +++ b/src/com/android/gallery3d/app/AlbumPage.java @@ -82,6 +82,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster private AlbumView mAlbumView; private Path mMediaSetPath; private String mParentMediaSetString; + private SlotView mSlotView; private AlbumDataAdapter mAlbumDataAdapter; @@ -129,7 +130,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster mAlbumView.setSelectionDrawer(mGridDrawer); } - mAlbumView.layout(0, slotViewTop, slotViewRight, slotViewBottom); + mSlotView.layout(0, slotViewTop, slotViewRight, slotViewBottom); GalleryUtils.setViewPointMatrix(mMatrix, (right - left) / 2, (bottom - top) / 2, -mUserDistance); // Reset position offset after the layout is changed. @@ -153,7 +154,8 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster } else if (mSelectionManager.inSelectionMode()) { mSelectionManager.leaveSelectionMode(); } else { - mAlbumView.savePositions(PositionRepository.getInstance(mActivity)); + // TODO: fix this regression + // mAlbumView.savePositions(PositionRepository.getInstance(mActivity)); super.onBackPressed(); } } @@ -162,12 +164,12 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster MediaItem item = mAlbumDataAdapter.get(index); Path path = (item == null) ? null : item.getPath(); mSelectionManager.setPressedPath(path); - mAlbumView.invalidate(); + mSlotView.invalidate(); } private void onUp() { mSelectionManager.setPressedPath(null); - mAlbumView.invalidate(); + mSlotView.invalidate(); } private void onSingleTapUp(int slotIndex) { @@ -185,7 +187,8 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster } else { // Get into the PhotoPage. Bundle data = new Bundle(); - mAlbumView.savePositions(PositionRepository.getInstance(mActivity)); + + // mAlbumView.savePositions(PositionRepository.getInstance(mActivity)); data.putInt(PhotoPage.KEY_INDEX_HINT, slotIndex); data.putParcelable(PhotoPage.KEY_OPEN_ANIMATION_RECT, getSlotRect(slotIndex)); @@ -199,17 +202,17 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster } else { mSelectionManager.toggle(item.getPath()); mDetailsSource.findIndex(slotIndex); - mAlbumView.invalidate(); + mSlotView.invalidate(); } } private Rect getSlotRect(int slotIndex) { // Get slot rectangle relative to this root pane. Rect offset = new Rect(); - mRootPane.getBoundsOf(mAlbumView, offset); - Rect r = mAlbumView.getSlotRect(slotIndex); - r.offset(offset.left - mAlbumView.getScrollX(), - offset.top - mAlbumView.getScrollY()); + mRootPane.getBoundsOf(mSlotView, offset); + Rect r = mSlotView.getSlotRect(slotIndex); + r.offset(offset.left - mSlotView.getScrollX(), + offset.top - mSlotView.getScrollY()); return r; } @@ -244,7 +247,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster mSelectionManager.setAutoLeaveSelectionMode(true); mSelectionManager.toggle(item.getPath()); mDetailsSource.findIndex(slotIndex); - mAlbumView.invalidate(); + mSlotView.invalidate(); } } @@ -260,7 +263,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster GalleryActionBar.getClusterByTypeString(context, clusterType)); } - mAlbumView.savePositions(PositionRepository.getInstance(mActivity)); + // mAlbumView.savePositions(PositionRepository.getInstance(mActivity)); mActivity.getStateManager().startStateForResult( AlbumSetPage.class, REQUEST_DO_ANIMATION, data); } @@ -287,7 +290,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster private void startTransition() { final PositionRepository repository = PositionRepository.getInstance(mActivity); - mAlbumView.startTransition(new PositionProvider() { + mSlotView.startTransition(new PositionProvider() { private final Position mTempPosition = new Position(); public Position getPosition(int identity, Position target) { Position p = repository.get(identity); @@ -306,7 +309,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster ? null : data.getIntArray(KEY_SET_CENTER); final Random random = new Random(); - mAlbumView.startTransition(new PositionProvider() { + mSlotView.startTransition(new PositionProvider() { private final Position mTempPosition = new Position(); public Position getPosition(int identity, Position target) { Position p = repository.get(identity); @@ -331,7 +334,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster setContentPane(mRootPane); // Reset position offset for resuming. PositionRepository.getInstance(mActivity).setOffset( - mAlbumView.bounds().left, mAlbumView.bounds().top); + mSlotView.bounds().left, mSlotView.bounds().top); Path path = mMediaSet.getPath(); boolean enableHomeButton = (mActivity.getStateManager().getStateCount() > 1) | @@ -380,11 +383,13 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster mSelectionManager.setSelectionListener(this); mGridDrawer = new GridDrawer((Context) mActivity, mSelectionManager); Config.AlbumPage config = Config.AlbumPage.get((Context) mActivity); - mAlbumView = new AlbumView(mActivity, config.slotViewSpec, - 0 /* don't cache thumbnail */); + mSlotView = new SlotView((Context) mActivity, config.slotViewSpec); + mAlbumView = new AlbumView( + mActivity, mSlotView, 0/* don't cache thumbnail */); + mSlotView.setSlotRenderer(mAlbumView); mAlbumView.setSelectionDrawer(mGridDrawer); - mRootPane.addComponent(mAlbumView); - mAlbumView.setListener(new SlotView.SimpleListener() { + mRootPane.addComponent(mSlotView); + mSlotView.setListener(new SlotView.SimpleListener() { @Override public void onDown(int index) { AlbumPage.this.onDown(index); @@ -446,7 +451,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster mShowDetails = false; mDetailsHelper.hide(); mAlbumView.setSelectionDrawer(mGridDrawer); - mAlbumView.invalidate(); + mSlotView.invalidate(); } @Override @@ -540,13 +545,13 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster // data could be null, if there is no images in the album if (data == null) return; mFocusIndex = data.getIntExtra(SlideshowPage.KEY_PHOTO_INDEX, 0); - mAlbumView.setCenterIndex(mFocusIndex); + mSlotView.setCenterIndex(mFocusIndex); break; } case REQUEST_PHOTO: { if (data == null) return; mFocusIndex = data.getIntExtra(PhotoPage.KEY_INDEX_HINT, 0); - mAlbumView.setCenterIndex(mFocusIndex); + mSlotView.setCenterIndex(mFocusIndex); startTransition(); break; } diff --git a/src/com/android/gallery3d/app/AlbumSetPage.java b/src/com/android/gallery3d/app/AlbumSetPage.java index d00c03c4f..d526b667c 100644 --- a/src/com/android/gallery3d/app/AlbumSetPage.java +++ b/src/com/android/gallery3d/app/AlbumSetPage.java @@ -73,6 +73,7 @@ public class AlbumSetPage extends ActivityState implements private static final int BIT_LOADING_SYNC = 2; private boolean mIsActive = false; + private SlotView mSlotView; private AlbumSetView mAlbumSetView; private MediaSet mMediaSet; @@ -131,7 +132,8 @@ public class AlbumSetPage extends ActivityState implements mAlbumSetView.setSelectionDrawer(mGridDrawer); } - mAlbumSetView.layout(0, slotViewTop, slotViewRight, slotViewBottom); + mSlotView.layout(0, slotViewTop, slotViewRight, slotViewBottom); + // Reset position offset after the layout is changed. PositionRepository.getInstance(mActivity).setOffset( 0, slotViewTop); @@ -165,19 +167,21 @@ public class AlbumSetPage extends ActivityState implements } else if (mSelectionManager.inSelectionMode()) { mSelectionManager.leaveSelectionMode(); } else { - mAlbumSetView.savePositions( - PositionRepository.getInstance(mActivity)); + // TODO: fix this regression during refactoring + // mSlotView.savePositions( + // PositionRepository.getInstance(mActivity)); super.onBackPressed(); } } private void savePositions(int slotIndex, int center[]) { Rect offset = new Rect(); - mRootPane.getBoundsOf(mAlbumSetView, offset); - mAlbumSetView.savePositions(PositionRepository.getInstance(mActivity)); - Rect r = mAlbumSetView.getSlotRect(slotIndex); - int scrollX = mAlbumSetView.getScrollX(); - int scrollY = mAlbumSetView.getScrollY(); + mRootPane.getBoundsOf(mSlotView, offset); + // TODO: fix this regression during refactoring + // mSlotView.savePositions(PositionRepository.getInstance(mActivity)); + Rect r = mSlotView.getSlotRect(slotIndex); + int scrollX = mSlotView.getScrollX(); + int scrollY = mSlotView.getScrollY(); center[0] = offset.left + (r.left + r.right) / 2 - scrollX; center[1] = offset.top + (r.top + r.bottom) / 2 - scrollY; } @@ -220,7 +224,7 @@ public class AlbumSetPage extends ActivityState implements } } else { mSelectionManager.toggle(targetSet.getPath()); - mAlbumSetView.invalidate(); + mSlotView.invalidate(); } } @@ -228,12 +232,12 @@ public class AlbumSetPage extends ActivityState implements MediaSet set = mAlbumSetDataAdapter.getMediaSet(index); Path path = (set == null) ? null : set.getPath(); mSelectionManager.setPressedPath(path); - mAlbumSetView.invalidate(); + mSlotView.invalidate(); } private void onUp() { mSelectionManager.setPressedPath(null); - mAlbumSetView.invalidate(); + mSlotView.invalidate(); } public void onLongTap(int slotIndex) { @@ -246,7 +250,7 @@ public class AlbumSetPage extends ActivityState implements mSelectionManager.setAutoLeaveSelectionMode(true); mSelectionManager.toggle(set.getPath()); mDetailsSource.findIndex(slotIndex); - mAlbumSetView.invalidate(); + mSlotView.invalidate(); } } @@ -256,7 +260,6 @@ public class AlbumSetPage extends ActivityState implements Bundle data = new Bundle(getData()); data.putString(AlbumSetPage.KEY_MEDIA_PATH, newPath); data.putInt(KEY_SELECTED_CLUSTER_TYPE, clusterType); - mAlbumSetView.savePositions(PositionRepository.getInstance(mActivity)); mActivity.getStateManager().switchState(this, AlbumSetPage.class, data); } @@ -330,7 +333,7 @@ public class AlbumSetPage extends ActivityState implements setContentPane(mRootPane); // Reset position offset for resuming. PositionRepository.getInstance(mActivity).setOffset( - mAlbumSetView.bounds().left, mAlbumSetView.bounds().top); + mSlotView.bounds().left, mSlotView.bounds().top); // Set the reload bit here to prevent it exit this page in clearLoadingBit(). setLoadingBit(BIT_LOADING_RELOAD); @@ -364,9 +367,11 @@ public class AlbumSetPage extends ActivityState implements mGridDrawer = new GridDrawer((Context) mActivity, mSelectionManager); Config.AlbumSetPage config = Config.AlbumSetPage.get((Context) mActivity); - mAlbumSetView = new AlbumSetView(mActivity, mGridDrawer, - config.slotViewSpec, config.labelSpec); - mAlbumSetView.setListener(new SlotView.SimpleListener() { + mSlotView = new SlotView((Context) mActivity, config.slotViewSpec); + mAlbumSetView = new AlbumSetView( + mActivity, mGridDrawer, mSlotView, config.labelSpec); + mSlotView.setSlotRenderer(mAlbumSetView); + mSlotView.setListener(new SlotView.SimpleListener() { @Override public void onDown(int index) { AlbumSetPage.this.onDown(index); @@ -394,7 +399,7 @@ public class AlbumSetPage extends ActivityState implements return onItemSelected(item); } }); - mRootPane.addComponent(mAlbumSetView); + mRootPane.addComponent(mSlotView); } @Override @@ -511,7 +516,7 @@ public class AlbumSetPage extends ActivityState implements private void startTransition() { final PositionRepository repository = PositionRepository.getInstance(mActivity); - mAlbumSetView.startTransition(new PositionProvider() { + mSlotView.startTransition(new PositionProvider() { private final Position mTempPosition = new Position(); public Position getPosition(int identity, Position target) { Position p = repository.get(identity); @@ -569,7 +574,7 @@ public class AlbumSetPage extends ActivityState implements mShowDetails = false; mDetailsHelper.hide(); mAlbumSetView.setSelectionDrawer(mGridDrawer); - mAlbumSetView.invalidate(); + mSlotView.invalidate(); } private void showDetails() { diff --git a/src/com/android/gallery3d/app/ManageCachePage.java b/src/com/android/gallery3d/app/ManageCachePage.java index 124eb7bf0..718c59fbf 100644 --- a/src/com/android/gallery3d/app/ManageCachePage.java +++ b/src/com/android/gallery3d/app/ManageCachePage.java @@ -66,6 +66,7 @@ public class ManageCachePage extends ActivityState implements private static final int MSG_REQUEST_LAYOUT = 2; private static final int PROGRESS_BAR_MAX = 10000; + private SlotView mSlotView; private AlbumSetView mAlbumSetView; private MediaSet mMediaSet; @@ -122,7 +123,7 @@ public class ManageCachePage extends ActivityState implements slotViewBottom = location[1]; } - mAlbumSetView.layout(0, slotViewTop, right - left, slotViewBottom); + mSlotView.layout(0, slotViewTop, right - left, slotViewBottom); } @Override @@ -149,12 +150,12 @@ public class ManageCachePage extends ActivityState implements MediaSet set = mAlbumSetDataAdapter.getMediaSet(index); Path path = (set == null) ? null : set.getPath(); mSelectionManager.setPressedPath(path); - mAlbumSetView.invalidate(); + mSlotView.invalidate(); } private void onUp() { mSelectionManager.setPressedPath(null); - mAlbumSetView.invalidate(); + mSlotView.invalidate(); } public void onSingleTapUp(int slotIndex) { @@ -190,7 +191,7 @@ public class ManageCachePage extends ActivityState implements refreshCacheStorageInfo(); mSelectionManager.toggle(path); - mAlbumSetView.invalidate(); + mSlotView.invalidate(); } @Override @@ -294,9 +295,11 @@ public class ManageCachePage extends ActivityState implements Config.ManageCachePage config = Config.ManageCachePage.get(activity); mSelectionDrawer = new ManageCacheDrawer((Context) mActivity, mSelectionManager, config.cachePinSize, config.cachePinMargin); + mSlotView = new SlotView((Context) mActivity, config.slotViewSpec); mAlbumSetView = new AlbumSetView(mActivity, mSelectionDrawer, - config.slotViewSpec, config.labelSpec); - mAlbumSetView.setListener(new SlotView.SimpleListener() { + mSlotView, config.labelSpec); + mSlotView.setSlotRenderer(mAlbumSetView); + mSlotView.setListener(new SlotView.SimpleListener() { @Override public void onDown(int index) { ManageCachePage.this.onDown(index); @@ -312,7 +315,7 @@ public class ManageCachePage extends ActivityState implements ManageCachePage.this.onSingleTapUp(slotIndex); } }); - mRootPane.addComponent(mAlbumSetView); + mRootPane.addComponent(mSlotView); initializeFooterViews(); } diff --git a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java index 5bead6297..1d94c69a1 100644 --- a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java +++ b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java @@ -41,9 +41,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { public static interface Listener { public void onSizeChanged(int size); - public void onContentInvalidated(); - public void onWindowContentChanged( - int slot, AlbumSetItem old, AlbumSetItem update); + public void onContentChanged(); } private final AlbumSetView.Model mSource; @@ -276,7 +274,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { original.cacheStatus = identifyCacheStatus(set); original.setPath = set == null ? null : set.getPath(); ((LabelDisplayItem) original.labelItem).updateContent(); - if (mListener != null) mListener.onContentInvalidated(); + if (mListener != null) mListener.onContentChanged(); return; } @@ -284,7 +282,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { AlbumSetItem update = data[pos]; if (mListener != null && isActiveSlot(slotIndex)) { - mListener.onWindowContentChanged(slotIndex, original, update); + mListener.onContentChanged(); } if (original != null) { for (DisplayItem item : original.covers) { @@ -370,7 +368,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { } else { updateContent(texture); } - if (mListener != null) mListener.onContentInvalidated(); + if (mListener != null) mListener.onContentChanged(); } } @@ -416,7 +414,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { if ((mContent instanceof FadeInTexture) && ((FadeInTexture) mContent).isAnimating()) { - return RENDER_MORE_FRAME; + return SlotView.RENDER_MORE_FRAME; } else { return 0; } @@ -561,6 +559,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { } } + @Override public void onSizeChanged(int size) { if (mIsActive && mSize != size) { mSize = size; @@ -568,6 +567,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { } } + @Override public void onWindowContentChanged(int index) { if (!mIsActive) { // paused, ignore slot changed event diff --git a/src/com/android/gallery3d/ui/AlbumSetView.java b/src/com/android/gallery3d/ui/AlbumSetView.java index 577d54e33..7a4b651a6 100644 --- a/src/com/android/gallery3d/ui/AlbumSetView.java +++ b/src/com/android/gallery3d/ui/AlbumSetView.java @@ -16,33 +16,21 @@ package com.android.gallery3d.ui; -import android.graphics.Rect; - import com.android.gallery3d.app.GalleryActivity; -import com.android.gallery3d.common.Utils; import com.android.gallery3d.data.MediaItem; import com.android.gallery3d.data.MediaSet; -import com.android.gallery3d.ui.PositionRepository.Position; - -import java.util.Random; -public class AlbumSetView extends SlotView { +public class AlbumSetView implements SlotView.SlotRenderer { @SuppressWarnings("unused") private static final String TAG = "AlbumSetView"; private static final int CACHE_SIZE = 32; - private static final float PHOTO_DISTANCE = 35f; - - private int mVisibleStart; - private int mVisibleEnd; - - private final Random mRandom = new Random(); - private final long mSeed = mRandom.nextLong(); private AlbumSetSlidingWindow mDataWindow; private final GalleryActivity mActivity; private final LabelSpec mLabelSpec; private SelectionDrawer mSelectionDrawer; + private SlotView mSlotView; public static interface Model { public MediaItem[] getCoverItems(int index); @@ -74,12 +62,11 @@ public class AlbumSetView extends SlotView { } public AlbumSetView(GalleryActivity activity, SelectionDrawer drawer, - SlotView.Spec slotViewSpec, LabelSpec labelSpec) { - super(activity.getAndroidContext()); + SlotView slotView, LabelSpec labelSpec) { mActivity = activity; setSelectionDrawer(drawer); - setSlotSpec(slotViewSpec); mLabelSpec = labelSpec; + mSlotView = slotView; } public void setSelectionDrawer(SelectionDrawer drawer) { @@ -92,151 +79,69 @@ public class AlbumSetView extends SlotView { public void setModel(AlbumSetView.Model model) { if (mDataWindow != null) { mDataWindow.setListener(null); - setSlotCount(0); mDataWindow = null; + mSlotView.setSlotCount(0); } if (model != null) { mDataWindow = new AlbumSetSlidingWindow(mActivity, mLabelSpec, mSelectionDrawer, model, CACHE_SIZE); mDataWindow.setListener(new MyCacheListener()); - setSlotCount(mDataWindow.size()); - updateVisibleRange(getVisibleStart(), getVisibleEnd()); + mSlotView.setSlotCount(mDataWindow.size()); } } - private void putSlotContent(int slotIndex, AlbumSetItem entry) { - // Get displayItems from mItemsetMap or create them from MediaSet. - Utils.assertTrue(entry != null); - Rect rect = getSlotRect(slotIndex); - - DisplayItem[] items = entry.covers; - mRandom.setSeed(slotIndex ^ mSeed); - - int x = (rect.left + rect.right) / 2; - int y = (rect.top + rect.bottom) / 2; - - Position basePosition = new Position(x, y, 0); + @Override + public int renderSlot(GLCanvas canvas, int index, int pass, int width, int height) { + AlbumSetItem entry = mDataWindow.get(index); + DisplayItem cover = entry.covers.length > 0 ? entry.covers[0] : null; + DisplayItem label = entry.labelItem; // Put the cover items in reverse order, so that the first item is on // top of the rest. - Position position = new Position(x, y, 0f); - putDisplayItem(position, position, entry.labelItem); - - for (int i = 0, n = items.length; i < n; ++i) { - DisplayItem item = items[i]; - float dx = 0; - float dy = 0; - float dz = 0f; - float theta = 0; - if (i != 0) { - dz = i * PHOTO_DISTANCE; - } - position = new Position(x + dx, y + dy, dz); - position.theta = theta; - putDisplayItem(position, basePosition, item); + canvas.translate(width / 2, height / 2); + int r = 0; + if (cover != null) { + cover.setBox(width, height); + r |= cover.render(canvas, pass); } - - } - - private void freeSlotContent(int index, AlbumSetItem entry) { - if (entry == null) return; - for (DisplayItem item : entry.covers) { - removeDisplayItem(item); + if (label != null) { + label.setBox(width, height); + r |= entry.labelItem.render(canvas, pass); } - removeDisplayItem(entry.labelItem); + canvas.translate(-width / 2, -height / 2); + return r; } @Override - public void onLayoutChanged(int width, int height) { - updateVisibleRange(0, 0); - updateVisibleRange(getVisibleStart(), getVisibleEnd()); - } - - @Override - public void onScrollPositionChanged(int position) { - super.onScrollPositionChanged(position); - updateVisibleRange(getVisibleStart(), getVisibleEnd()); - } - - private void updateVisibleRange(int start, int end) { - if (start == mVisibleStart && end == mVisibleEnd) { - // we need to set the mDataWindow active range in any case. - mDataWindow.setActiveWindow(start, end); - return; - } - if (start >= mVisibleEnd || mVisibleStart >= end) { - for (int i = mVisibleStart, n = mVisibleEnd; i < n; ++i) { - freeSlotContent(i, mDataWindow.get(i)); - } - mDataWindow.setActiveWindow(start, end); - for (int i = start; i < end; ++i) { - putSlotContent(i, mDataWindow.get(i)); - } - } else { - for (int i = mVisibleStart; i < start; ++i) { - freeSlotContent(i, mDataWindow.get(i)); - } - for (int i = end, n = mVisibleEnd; i < n; ++i) { - freeSlotContent(i, mDataWindow.get(i)); - } - mDataWindow.setActiveWindow(start, end); - for (int i = start, n = mVisibleStart; i < n; ++i) { - putSlotContent(i, mDataWindow.get(i)); - } - for (int i = mVisibleEnd; i < end; ++i) { - putSlotContent(i, mDataWindow.get(i)); - } - } - mVisibleStart = start; - mVisibleEnd = end; - - invalidate(); - } - - @Override - protected void render(GLCanvas canvas) { + public void prepareDrawing() { mSelectionDrawer.prepareDrawing(); - super.render(canvas); } private class MyCacheListener implements AlbumSetSlidingWindow.Listener { + @Override public void onSizeChanged(int size) { - if (setSlotCount(size)) { - // If the layout parameters are changed, we need reput all items. - // We keep the visible range at the same center but with size 0. - // So that we can: - // 1.) flush all visible items - // 2.) keep the cached data - int center = (getVisibleStart() + getVisibleEnd()) / 2; - updateVisibleRange(center, center); - } - updateVisibleRange(getVisibleStart(), getVisibleEnd()); - invalidate(); + mSlotView.setSlotCount(size); } - public void onWindowContentChanged(int slot, AlbumSetItem old, AlbumSetItem update) { - freeSlotContent(slot, old); - putSlotContent(slot, update); - invalidate(); - } - - public void onContentInvalidated() { - invalidate(); + @Override + public void onContentChanged() { + mSlotView.invalidate(); } } public void pause() { - for (int i = mVisibleStart, n = mVisibleEnd; i < n; ++i) { - freeSlotContent(i, mDataWindow.get(i)); - } mDataWindow.pause(); } public void resume() { mDataWindow.resume(); - for (int i = mVisibleStart, n = mVisibleEnd; i < n; ++i) { - putSlotContent(i, mDataWindow.get(i)); + } + + @Override + public void onVisibleRangeChanged(int visibleStart, int visibleEnd) { + if (mDataWindow != null) { + mDataWindow.setActiveWindow(visibleStart, visibleEnd); } } } diff --git a/src/com/android/gallery3d/ui/AlbumSlidingWindow.java b/src/com/android/gallery3d/ui/AlbumSlidingWindow.java index 3f1a18bd1..056bb5a51 100644 --- a/src/com/android/gallery3d/ui/AlbumSlidingWindow.java +++ b/src/com/android/gallery3d/ui/AlbumSlidingWindow.java @@ -44,9 +44,7 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener { public static interface Listener { public void onSizeChanged(int size); - public void onContentInvalidated(); - public void onWindowContentChanged( - int slot, DisplayItem old, DisplayItem update); + public void onContentChanged(); } private final AlbumView.Model mSource; @@ -242,7 +240,7 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener { data[index] = update; boolean isActive = isActiveSlot(slotIndex); if (mListener != null && isActive) { - mListener.onWindowContentChanged(slotIndex, original, update); + mListener.onContentChanged(); } if (original != null) { if (isActive && original.isRequestInProgress()) { @@ -318,7 +316,7 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener { updateContent(texture); } if (mListener != null && isActiveSlot) { - mListener.onContentInvalidated(); + mListener.onContentChanged(); } } } @@ -351,11 +349,11 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener { } int result = 0; if (mFocusIndex == mSlotIndex) { - result |= RENDER_MORE_PASS; + result |= SlotView.RENDER_MORE_PASS; } if ((mContent instanceof FadeInTexture) && ((FadeInTexture) mContent).isAnimating()) { - result |= RENDER_MORE_FRAME; + result |= SlotView.RENDER_MORE_FRAME; } return result; } else if (pass == 1) { diff --git a/src/com/android/gallery3d/ui/AlbumView.java b/src/com/android/gallery3d/ui/AlbumView.java index 634485178..bf07ab2b1 100644 --- a/src/com/android/gallery3d/ui/AlbumView.java +++ b/src/com/android/gallery3d/ui/AlbumView.java @@ -16,26 +16,20 @@ package com.android.gallery3d.ui; -import android.graphics.Rect; - import com.android.gallery3d.app.GalleryActivity; import com.android.gallery3d.data.MediaItem; -import com.android.gallery3d.ui.PositionRepository.Position; -public class AlbumView extends SlotView { +public class AlbumView implements SlotView.SlotRenderer { @SuppressWarnings("unused") private static final String TAG = "AlbumView"; private static final int CACHE_SIZE = 64; - private int mVisibleStart = 0; - private int mVisibleEnd = 0; - private AlbumSlidingWindow mDataWindow; private final GalleryActivity mActivity; private SelectionDrawer mSelectionDrawer; private int mCacheThumbSize; - private boolean mIsActive = false; + private final SlotView mSlotView; public static interface Model { public int size(); @@ -49,11 +43,10 @@ public class AlbumView extends SlotView { public void onSizeChanged(int size); } - public AlbumView(GalleryActivity activity, SlotView.Spec spec, + public AlbumView(GalleryActivity activity, SlotView slotView, int cacheThumbSize) { - super(activity.getAndroidContext()); mCacheThumbSize = cacheThumbSize; - setSlotSpec(spec); + mSlotView = slotView; mActivity = activity; } @@ -65,7 +58,7 @@ public class AlbumView extends SlotView { public void setModel(Model model) { if (mDataWindow != null) { mDataWindow.setListener(null); - setSlotCount(0); + mSlotView.setSlotCount(0); mDataWindow = null; } if (model != null) { @@ -74,8 +67,7 @@ public class AlbumView extends SlotView { mCacheThumbSize); mDataWindow.setSelectionDrawer(mSelectionDrawer); mDataWindow.setListener(new MyDataModelListener()); - setSlotCount(model.size()); - updateVisibleRange(getVisibleStart(), getVisibleEnd()); + mSlotView.setSlotCount(model.size()); } } @@ -85,117 +77,48 @@ public class AlbumView extends SlotView { } } - private void putSlotContent(int slotIndex, DisplayItem item) { - Rect rect = getSlotRect(slotIndex); - Position position = new Position( - (rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2, 0); - putDisplayItem(position, position, item); - } - - private void updateVisibleRange(int start, int end) { - if (start == mVisibleStart && end == mVisibleEnd) { - // we need to set the mDataWindow active range in any case. - mDataWindow.setActiveWindow(start, end); - return; - } - - if (!mIsActive) { - mVisibleStart = start; - mVisibleEnd = end; - mDataWindow.setActiveWindow(start, end); - return; - } - - if (start >= mVisibleEnd || mVisibleStart >= end) { - for (int i = mVisibleStart, n = mVisibleEnd; i < n; ++i) { - DisplayItem item = mDataWindow.get(i); - if (item != null) removeDisplayItem(item); - } - mDataWindow.setActiveWindow(start, end); - for (int i = start; i < end; ++i) { - putSlotContent(i, mDataWindow.get(i)); - } - } else { - for (int i = mVisibleStart; i < start; ++i) { - DisplayItem item = mDataWindow.get(i); - if (item != null) removeDisplayItem(item); - } - for (int i = end, n = mVisibleEnd; i < n; ++i) { - DisplayItem item = mDataWindow.get(i); - if (item != null) removeDisplayItem(item); - } - mDataWindow.setActiveWindow(start, end); - for (int i = start, n = mVisibleStart; i < n; ++i) { - putSlotContent(i, mDataWindow.get(i)); - } - for (int i = mVisibleEnd; i < end; ++i) { - putSlotContent(i, mDataWindow.get(i)); - } - } - - mVisibleStart = start; - mVisibleEnd = end; - } - - @Override - protected void onLayoutChanged(int width, int height) { - // Reput all the items - updateVisibleRange(0, 0); - updateVisibleRange(getVisibleStart(), getVisibleEnd()); - } - - @Override - protected void onScrollPositionChanged(int position) { - super.onScrollPositionChanged(position); - updateVisibleRange(getVisibleStart(), getVisibleEnd()); - } - @Override - protected void render(GLCanvas canvas) { - mSelectionDrawer.prepareDrawing(); - super.render(canvas); + public int renderSlot(GLCanvas canvas, int index, int pass, int width, int height) { + DisplayItem item = mDataWindow.get(index); + if (item != null) { + canvas.translate(width / 2, height / 2); + item.setBox(width, height); + int r = item.render(canvas, pass); + canvas.translate(-width / 2, -height / 2); + return r; + } + return 0; } private class MyDataModelListener implements AlbumSlidingWindow.Listener { - - public void onContentInvalidated() { - invalidate(); + @Override + public void onContentChanged() { + mSlotView.invalidate(); } + @Override public void onSizeChanged(int size) { - if (setSlotCount(size)) { - // If the layout parameters are changed, we need reput all items. - // We keep the visible range at the same center but with size 0. - // So that we can: - // 1.) flush all visible items - // 2.) keep the cached data - int center = (getVisibleStart() + getVisibleEnd()) / 2; - updateVisibleRange(center, center); - } - updateVisibleRange(getVisibleStart(), getVisibleEnd()); - invalidate(); - } - - public void onWindowContentChanged( - int slotIndex, DisplayItem old, DisplayItem update) { - removeDisplayItem(old); - putSlotContent(slotIndex, update); + mSlotView.setSlotCount(size); } } public void resume() { - mIsActive = true; mDataWindow.resume(); - for (int i = mVisibleStart, n = mVisibleEnd; i < n; ++i) { - putSlotContent(i, mDataWindow.get(i)); - } } public void pause() { - mIsActive = false; - for (int i = mVisibleStart, n = mVisibleEnd; i < n; ++i) { - removeDisplayItem(mDataWindow.get(i)); - } mDataWindow.pause(); } + + @Override + public void prepareDrawing() { + mSelectionDrawer.prepareDrawing(); + } + + @Override + public void onVisibleRangeChanged(int visibleStart, int visibleEnd) { + if (mDataWindow != null) { + mDataWindow.setActiveWindow(visibleStart, visibleEnd); + } + } } diff --git a/src/com/android/gallery3d/ui/DisplayItem.java b/src/com/android/gallery3d/ui/DisplayItem.java index 8d0226212..b389daebc 100644 --- a/src/com/android/gallery3d/ui/DisplayItem.java +++ b/src/com/android/gallery3d/ui/DisplayItem.java @@ -29,12 +29,6 @@ public abstract class DisplayItem { mBoxHeight = height; } - // Return values of render(): - // RENDER_MORE_PASS: more pass is needed for this item - // RENDER_MORE_FRAME: need to render next frame (used for animation) - public static final int RENDER_MORE_PASS = 1; - public static final int RENDER_MORE_FRAME = 2; - public abstract int render(GLCanvas canvas, int pass); public abstract int getIdentity(); diff --git a/src/com/android/gallery3d/ui/FilmStripView.java b/src/com/android/gallery3d/ui/FilmStripView.java index 58a01dae5..6f339e2a9 100644 --- a/src/com/android/gallery3d/ui/FilmStripView.java +++ b/src/com/android/gallery3d/ui/FilmStripView.java @@ -42,6 +42,7 @@ public class FilmStripView extends GLView implements UserInteractionListener { private int mTopMargin, mMidMargin, mBottomMargin; private int mContentSize, mBarSize, mGripSize; private AlbumView mAlbumView; + private SlotView mSlotView; private ScrollBarView mScrollBarView; private AlbumDataAdapter mAlbumDataAdapter; private StripDrawer mStripDrawer; @@ -77,10 +78,12 @@ public class FilmStripView extends GLView implements UserInteractionListener { SlotView.Spec spec = new SlotView.Spec(); spec.slotWidth = thumbSize; spec.slotHeight = thumbSize; - mAlbumView = new AlbumView(activity, spec, thumbSize); - mAlbumView.setOverscrollEffect(SlotView.OVERSCROLL_NONE); + mSlotView = new SlotView((Context) activity, spec); + mAlbumView = new AlbumView(activity, mSlotView, thumbSize); + mSlotView.setSlotRenderer(mAlbumView); + mSlotView.setOverscrollEffect(SlotView.OVERSCROLL_NONE); mAlbumView.setSelectionDrawer(mStripDrawer); - mAlbumView.setListener(new SlotView.SimpleListener() { + mSlotView.setListener(new SlotView.SimpleListener() { @Override public void onDown(int index) { FilmStripView.this.onDown(index); @@ -102,9 +105,9 @@ public class FilmStripView extends GLView implements UserInteractionListener { FilmStripView.this.onScrollPositionChanged(position, total); } }); - mAlbumView.setUserInteractionListener(this); + mSlotView.setUserInteractionListener(this); mAlbumDataAdapter = new AlbumDataAdapter(activity, mediaSet); - addComponent(mAlbumView); + addComponent(mSlotView); mScrollBarView = new ScrollBarView(activity.getAndroidContext(), mGripSize, gripWidth); addComponent(mScrollBarView); @@ -156,7 +159,7 @@ public class FilmStripView extends GLView implements UserInteractionListener { protected void onLayout( boolean changed, int left, int top, int right, int bottom) { if (!changed) return; - mAlbumView.layout(0, mTopMargin, right - left, mTopMargin + mContentSize); + mSlotView.layout(0, mTopMargin, right - left, mTopMargin + mContentSize); int barStart = mTopMargin + mContentSize + mMidMargin; mScrollBarView.layout(0, barStart, right - left, barStart + mBarSize); int width = right - left; @@ -197,12 +200,12 @@ public class FilmStripView extends GLView implements UserInteractionListener { MediaItem item = mAlbumDataAdapter.get(index); Path path = (item == null) ? null : item.getPath(); mStripDrawer.setPressedPath(path); - mAlbumView.invalidate(); + mSlotView.invalidate(); } private void onUp() { mStripDrawer.setPressedPath(null); - mAlbumView.invalidate(); + mSlotView.invalidate(); } private void onSingleTapUp(int slotIndex) { @@ -239,11 +242,11 @@ public class FilmStripView extends GLView implements UserInteractionListener { public void setFocusIndex(int slotIndex) { mAlbumView.setFocusIndex(slotIndex); - mAlbumView.makeSlotVisible(slotIndex); + mSlotView.makeSlotVisible(slotIndex); } public void setStartIndex(int slotIndex) { - mAlbumView.setStartIndex(slotIndex); + mSlotView.setStartIndex(slotIndex); } public void pause() { diff --git a/src/com/android/gallery3d/ui/Paper.java b/src/com/android/gallery3d/ui/Paper.java index 36d1f7515..3b67a049a 100644 --- a/src/com/android/gallery3d/ui/Paper.java +++ b/src/com/android/gallery3d/ui/Paper.java @@ -16,12 +16,12 @@ package com.android.gallery3d.ui; +import android.graphics.Rect; import android.opengl.Matrix; import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; import com.android.gallery3d.common.Utils; -import com.android.gallery3d.ui.PositionRepository.Position; // This class does the overscroll effect. class Paper { @@ -65,11 +65,10 @@ class Paper { mHeight = height; } - public float[] getTransform(Position target, Position base, - float scrollX, float scrollY) { + public float[] getTransform(Rect rect, float scrollX) { float left = mAnimationLeft.getValue(); float right = mAnimationRight.getValue(); - float screenX = target.x - scrollX; + float screenX = rect.centerX() - scrollX; // We linearly interpolate the value [left, right] for the screenX // range int [-1/4, 5/4]*mWidth. So if part of the thumbnail is outside // the screen, we still get some transform. @@ -82,10 +81,9 @@ class Paper { float degrees = (1 / (1 + (float) Math.exp(-t * ROTATE_FACTOR)) - 0.5f) * 2 * -45; Matrix.setIdentityM(mMatrix, 0); - Matrix.translateM(mMatrix, 0, mMatrix, 0, base.x, base.y, base.z); + Matrix.translateM(mMatrix, 0, mMatrix, 0, rect.centerX(), rect.centerY(), 0); Matrix.rotateM(mMatrix, 0, degrees, 0, 1, 0); - Matrix.translateM(mMatrix, 0, mMatrix, 0, - target.x - base.x, target.y - base.y, target.z - base.z); + Matrix.translateM(mMatrix, 0, mMatrix, 0, -rect.width() / 2, -rect.height() / 2, 0); return mMatrix; } } diff --git a/src/com/android/gallery3d/ui/RelativePosition.java b/src/com/android/gallery3d/ui/RelativePosition.java new file mode 100644 index 000000000..98292e36f --- /dev/null +++ b/src/com/android/gallery3d/ui/RelativePosition.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.gallery3d.ui; + +public class RelativePosition { + private float mAbsoluteX; + private float mAbsoluteY; + private float mReferenceX; + private float mReferenceY; + + public void setAbsolute(int absoluteX, int absoluteY) { + mAbsoluteX = absoluteX; + mAbsoluteY = absoluteY; + } + + public void setReference(int x, int y) { + mReferenceX = x; + mReferenceY = y; + } + + public float getX() { + return mAbsoluteX - mReferenceX; + } + + public float getY() { + return mAbsoluteY - mReferenceY; + } +} diff --git a/src/com/android/gallery3d/ui/SlotView.java b/src/com/android/gallery3d/ui/SlotView.java index 863e66869..529a496d3 100644 --- a/src/com/android/gallery3d/ui/SlotView.java +++ b/src/com/android/gallery3d/ui/SlotView.java @@ -25,20 +25,17 @@ import android.view.animation.DecelerateInterpolator; import com.android.gallery3d.anim.Animation; import com.android.gallery3d.common.Utils; -import com.android.gallery3d.ui.PositionRepository.Position; -import com.android.gallery3d.util.LinkedNode; - -import java.util.ArrayList; -import java.util.HashMap; public class SlotView extends GLView { @SuppressWarnings("unused") private static final String TAG = "SlotView"; private static final boolean WIDE = true; - private static final int INDEX_NONE = -1; + public static final int RENDER_MORE_PASS = 1; + public static final int RENDER_MORE_FRAME = 2; + public interface Listener { public void onDown(int index); public void onUp(); @@ -48,11 +45,17 @@ public class SlotView extends GLView { } public static class SimpleListener implements Listener { - public void onDown(int index) {} - public void onUp() {} - public void onSingleTapUp(int index) {} - public void onLongTap(int index) {} - public void onScrollPositionChanged(int position, int total) {} + @Override public void onDown(int index) {} + @Override public void onUp() {} + @Override public void onSingleTapUp(int index) {} + @Override public void onLongTap(int index) {} + @Override public void onScrollPositionChanged(int position, int total) {} + } + + public static interface SlotRenderer { + public void prepareDrawing(); + public void onVisibleRangeChanged(int visibleStart, int visibleEnd); + public int renderSlot(GLCanvas canvas, int index, int pass, int width, int height); } private final GestureDetector mGestureDetector; @@ -62,21 +65,9 @@ public class SlotView extends GLView { private Listener mListener; private UserInteractionListener mUIListener; - // Use linked hash map to keep the rendering order - private final HashMap<DisplayItem, ItemEntry> mItems = - new HashMap<DisplayItem, ItemEntry>(); - - public LinkedNode.List<ItemEntry> mItemList = LinkedNode.newList(); - - // This is used for multipass rendering - private ArrayList<ItemEntry> mCurrentItems = new ArrayList<ItemEntry>(); - private ArrayList<ItemEntry> mNextItems = new ArrayList<ItemEntry>(); - private boolean mMoreAnimation = false; private MyAnimation mAnimation = null; - private final Position mTempPosition = new Position(); private final Layout mLayout = new Layout(); - private PositionProvider mPositions; private int mStartIndex = INDEX_NONE; // whether the down action happened while the view is scrolling. @@ -84,15 +75,27 @@ public class SlotView extends GLView { private int mOverscrollEffect = OVERSCROLL_3D; private final Handler mHandler; + private SlotRenderer mRenderer; + + private int[] mRequestRenderSlots = new int[16]; + public static final int OVERSCROLL_3D = 0; public static final int OVERSCROLL_SYSTEM = 1; public static final int OVERSCROLL_NONE = 2; - public SlotView(Context context) { + public SlotView(Context context, Spec spec) { mGestureDetector = new GestureDetector(context, new MyGestureListener()); mScroller = new ScrollerHelper(context); mHandler = new Handler(context.getMainLooper()); + setSlotSpec(spec); + } + + public void setSlotRenderer(SlotRenderer slotDrawer) { + mRenderer = slotDrawer; + if (mRenderer != null) { + mRenderer.onVisibleRangeChanged(getVisibleStart(), getVisibleEnd()); + } } public void setCenterIndex(int index) { @@ -163,25 +166,11 @@ public class SlotView extends GLView { protected void onLayoutChanged(int width, int height) { } + // TODO: Fix this regression. Transition is disabled in this change public void startTransition(PositionProvider position) { - mPositions = position; mAnimation = new MyAnimation(); mAnimation.start(); - if (mItems.size() != 0) invalidate(); - } - - public void savePositions(PositionRepository repository) { - repository.clear(); - LinkedNode.List<ItemEntry> list = mItemList; - ItemEntry entry = list.getFirst(); - Position position = new Position(); - while (entry != null) { - position.set(entry.target); - position.x -= mScrollX; - position.y -= mScrollY; - repository.putPosition(entry.item.getIdentity(), position); - entry = list.nextOf(entry); - } + if (mLayout.mSlotCount != 0) invalidate(); } private void updateScrollPosition(int position, boolean force) { @@ -200,18 +189,6 @@ public class SlotView extends GLView { mListener.onScrollPositionChanged(newPosition, limit); } - public void putDisplayItem(Position target, Position base, DisplayItem item) { - item.setBox(mLayout.getSlotWidth(), mLayout.getSlotHeight()); - ItemEntry entry = new ItemEntry(item, target, base); - mItemList.insertLast(entry); - mItems.put(item, entry); - } - - public void removeDisplayItem(DisplayItem item) { - ItemEntry entry = mItems.remove(item); - if (entry != null) entry.remove(); - } - public Rect getSlotRect(int slotIndex) { return mLayout.getSlotRect(slotIndex); } @@ -246,10 +223,20 @@ public class SlotView extends GLView { mScroller.setOverfling(kind == OVERSCROLL_SYSTEM); } + private static int[] expandIntArray(int array[], int capacity) { + while (array.length < capacity) { + array = new int[array.length * 2]; + } + return array; + } + @Override protected void render(GLCanvas canvas) { super.render(canvas); + if (mRenderer == null) return; + mRenderer.prepareDrawing(); + long animTime = AnimationTime.get(); boolean more = mScroller.advanceAnimation(animTime); int oldX = mScrollX; @@ -280,45 +267,30 @@ public class SlotView extends GLView { interpolate = mAnimation.value; } - if (WIDE) { - canvas.translate(-mScrollX, 0); - } else { - canvas.translate(0, -mScrollY); - } + canvas.translate(-mScrollX, -mScrollY); - LinkedNode.List<ItemEntry> list = mItemList; - for (ItemEntry entry = list.getLast(); entry != null;) { - int r = renderItem(canvas, entry, interpolate, 0, paperActive); - if ((r & DisplayItem.RENDER_MORE_PASS) != 0) { - mCurrentItems.add(entry); - } - more |= ((r & DisplayItem.RENDER_MORE_FRAME) != 0); - entry = list.previousOf(entry); + int requestCount = 0; + int requestedSlot[] = expandIntArray(mRequestRenderSlots, + mLayout.mVisibleEnd - mLayout.mVisibleStart); + + for (int i = mLayout.mVisibleStart; i < mLayout.mVisibleEnd; ++i) { + int r = renderItem(canvas, i, 0, interpolate, paperActive); + if ((r & RENDER_MORE_FRAME) != 0) more = true; + if ((r & RENDER_MORE_PASS) != 0) requestedSlot[requestCount++] = i; } - int pass = 1; - while (!mCurrentItems.isEmpty()) { - for (int i = 0, n = mCurrentItems.size(); i < n; i++) { - ItemEntry entry = mCurrentItems.get(i); - int r = renderItem(canvas, entry, interpolate, pass, paperActive); - if ((r & DisplayItem.RENDER_MORE_PASS) != 0) { - mNextItems.add(entry); - } - more |= ((r & DisplayItem.RENDER_MORE_FRAME) != 0); + for (int pass = 1; requestCount != 0; ++pass) { + int newCount = 0; + for (int i = 0; i < requestCount; ++i) { + int r = renderItem(canvas, + requestedSlot[i], pass, interpolate, paperActive); + if ((r & RENDER_MORE_FRAME) != 0) more = true; + if ((r & RENDER_MORE_PASS) != 0) requestedSlot[newCount++] = i; } - mCurrentItems.clear(); - // swap mNextItems with mCurrentItems - ArrayList<ItemEntry> tmp = mNextItems; - mNextItems = mCurrentItems; - mCurrentItems = tmp; - pass += 1; + requestCount = newCount; } - if (WIDE) { - canvas.translate(mScrollX, 0); - } else { - canvas.translate(0, mScrollY); - } + canvas.translate(mScrollX, mScrollY); if (more) invalidate(); @@ -334,36 +306,19 @@ public class SlotView extends GLView { mMoreAnimation = more; } - private int renderItem(GLCanvas canvas, ItemEntry entry, - float interpolate, int pass, boolean paperActive) { + private int renderItem(GLCanvas canvas, + int index, int pass, float interpolate, boolean paperActive) { canvas.save(GLCanvas.SAVE_FLAG_ALPHA | GLCanvas.SAVE_FLAG_MATRIX); - Position position = entry.target; - if (mPositions != null) { - position = mTempPosition; - position.set(entry.target); - position.x -= mScrollX; - position.y -= mScrollY; - Position source = mPositions - .getPosition(entry.item.getIdentity(), position); - source.x += mScrollX; - source.y += mScrollY; - position = mTempPosition; - Position.interpolate( - source, entry.target, position, interpolate); - } - canvas.multiplyAlpha(position.alpha); + Rect rect = getSlotRect(index); if (paperActive) { - canvas.multiplyMatrix(mPaper.getTransform( - position, entry.base, mScrollX, mScrollY), 0); + canvas.multiplyMatrix(mPaper.getTransform(rect, mScrollX), 0); } else { - canvas.translate(position.x, position.y, position.z); + canvas.translate(rect.left, rect.top, 0); } - if (position.theta != 0) { - canvas.rotate(position.theta, 0, 0, 1); - } - int more = entry.item.render(canvas, pass); + int result = mRenderer.renderSlot( + canvas, index, pass, rect.right - rect.left, rect.bottom - rect.top); canvas.restore(); - return more; + return result; } public static class MyAnimation extends Animation { @@ -380,18 +335,6 @@ public class SlotView extends GLView { } } - private static class ItemEntry extends LinkedNode { - public DisplayItem item; - public Position target; - public Position base; - - public ItemEntry(DisplayItem item, Position target, Position base) { - this.item = item; - this.target = target; - this.base = base; - } - } - // This Spec class is used to specify the size of each slot in the SlotView. // There are two ways to do it: // @@ -412,7 +355,7 @@ public class SlotView extends GLView { public int slotGap = -1; } - public static class Layout { + public class Layout { private int mVisibleStart; private int mVisibleEnd; @@ -570,6 +513,9 @@ public class SlotView extends GLView { } else { mVisibleStart = mVisibleEnd = 0; } + if (mRenderer != null) { + mRenderer.onVisibleRangeChanged(mVisibleStart, mVisibleEnd); + } } public int getVisibleStart() { |