diff options
author | Chih-Chung Chang <chihchung@google.com> | 2011-09-28 00:18:27 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-09-28 00:18:27 -0700 |
commit | 5be6dbe487c9db0945d332fc1cc6a6d96d7c016f (patch) | |
tree | 3b0899d5734c19e2fd9a26f4f907ad128dc451a6 /src/com/android/gallery3d | |
parent | c29a5a347120a9aed277b578b0ea888c7e89b060 (diff) | |
parent | 1b2af5e5a75cf4c117e3e6c8d02fdb4587dff0be (diff) | |
download | android_packages_apps_Snap-5be6dbe487c9db0945d332fc1cc6a6d96d7c016f.tar.gz android_packages_apps_Snap-5be6dbe487c9db0945d332fc1cc6a6d96d7c016f.tar.bz2 android_packages_apps_Snap-5be6dbe487c9db0945d332fc1cc6a6d96d7c016f.zip |
Merge "Fix 5367072: Add thumbnail fade-in animation."
Diffstat (limited to 'src/com/android/gallery3d')
-rw-r--r-- | src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java | 21 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/AlbumSlidingWindow.java | 19 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/DisplayItem.java | 9 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/FadeInTexture.java | 90 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/GridDrawer.java | 19 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/HighlightDrawer.java | 15 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/IconDrawer.java | 13 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/ManageCacheDrawer.java | 23 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/SelectionDrawer.java | 25 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/SlotView.java | 18 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/StripDrawer.java | 2 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/Texture.java | 1 |
12 files changed, 166 insertions, 89 deletions
diff --git a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java index 3b363978c..1809084c8 100644 --- a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java +++ b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java @@ -36,6 +36,7 @@ import android.os.Message; public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { private static final String TAG = "GallerySlidingWindow"; private static final int MSG_LOAD_BITMAP_DONE = 0; + private static final int PLACEHOLDER_COLOR = 0xFF222222; public static interface Listener { public void onSizeChanged(int size); @@ -85,7 +86,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { mData = new MyAlbumSetItem[cacheSize]; mSize = source.size(); - mWaitLoadingTexture = new ColorTexture(Color.TRANSPARENT); + mWaitLoadingTexture = new ColorTexture(PLACEHOLDER_COLOR); mWaitLoadingTexture.setSize(1, 1); mHandler = new SynchronizedHandler(activity.getGLRoot()) { @@ -359,7 +360,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { if (bitmap != null) { BitmapTexture texture = new BitmapTexture(bitmap, true); texture.setThrottled(true); - updateContent(texture); + updateContent(new FadeInTexture(PLACEHOLDER_COLOR, texture)); if (mListener != null) mListener.onContentInvalidated(); } } @@ -369,7 +370,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { } @Override - public boolean render(GLCanvas canvas, int pass) { + public int render(GLCanvas canvas, int pass) { // Fit the content into the box int width = mContent.getWidth(); int height = mContent.getHeight(); @@ -394,12 +395,18 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { } mSelectionDrawer.draw(canvas, mContent, width, height, - getRotation(), path, mCoverIndex, sourceType, mMediaType, + getRotation(), path, sourceType, mMediaType, mIsPanorama, mLabelSpec.labelBackgroundHeight, cacheFlag == MediaSet.CACHE_FLAG_FULL, (cacheFlag == MediaSet.CACHE_FLAG_FULL) && (cacheStatus != MediaSet.CACHE_STATUS_CACHED_FULL)); - return false; + + if (mContent != mWaitLoadingTexture && + ((FadeInTexture) mContent).isAnimating()) { + return RENDER_MORE_FRAME; + } else { + return 0; + } } @Override @@ -519,7 +526,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { } @Override - public boolean render(GLCanvas canvas, int pass) { + public int render(GLCanvas canvas, int pass) { if (mBoxWidth != mLastWidth) { updateContent(); } @@ -532,7 +539,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { y += s.titleFontSize + s.countOffset; x += mHasIcon ? s.iconSize : s.leftMargin; mTextureCount.draw(canvas, x, y); - return false; + return 0; } @Override diff --git a/src/com/android/gallery3d/ui/AlbumSlidingWindow.java b/src/com/android/gallery3d/ui/AlbumSlidingWindow.java index 5f7143479..6dd9c10b9 100644 --- a/src/com/android/gallery3d/ui/AlbumSlidingWindow.java +++ b/src/com/android/gallery3d/ui/AlbumSlidingWindow.java @@ -40,6 +40,7 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener { private static final int MSG_LOAD_BITMAP_DONE = 0; private static final int MSG_UPDATE_SLOT = 1; private static final int JOB_LIMIT = 2; + private static final int PLACEHOLDER_COLOR = 0xFF222222; public static interface Listener { public void onSizeChanged(int size); @@ -81,7 +82,7 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener { mData = new AlbumDisplayItem[cacheSize]; mSize = source.size(); - mWaitLoadingTexture = new ColorTexture(Color.TRANSPARENT); + mWaitLoadingTexture = new ColorTexture(PLACEHOLDER_COLOR); mWaitLoadingTexture.setSize(1, 1); mHandler = new SynchronizedHandler(activity.getGLRoot()) { @@ -306,7 +307,7 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener { if (bitmap != null) { BitmapTexture texture = new BitmapTexture(bitmap, true); texture.setThrottled(true); - updateContent(texture); + updateContent(new FadeInTexture(PLACEHOLDER_COLOR, texture)); if (mListener != null && isActiveSlot) { mListener.onContentInvalidated(); } @@ -318,7 +319,7 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener { } @Override - public boolean render(GLCanvas canvas, int pass) { + public int render(GLCanvas canvas, int pass) { // Fit the content into the box int width = mContent.getWidth(); int height = mContent.getHeight(); @@ -336,11 +337,19 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener { if (mMediaItem != null) path = mMediaItem.getPath(); mSelectionDrawer.draw(canvas, mContent, width, height, getRotation(), path, mMediaType, mIsPanorama); - return (mFocusIndex == mSlotIndex); + int result = 0; + if (mFocusIndex == mSlotIndex) { + result |= RENDER_MORE_PASS; + } + if (mContent != mWaitLoadingTexture && + ((FadeInTexture) mContent).isAnimating()) { + result |= RENDER_MORE_FRAME; + } + return result; } else if (pass == 1) { mSelectionDrawer.drawFocus(canvas, width, height); } - return false; + return 0; } @Override diff --git a/src/com/android/gallery3d/ui/DisplayItem.java b/src/com/android/gallery3d/ui/DisplayItem.java index 50264c4a3..6b76ed022 100644 --- a/src/com/android/gallery3d/ui/DisplayItem.java +++ b/src/com/android/gallery3d/ui/DisplayItem.java @@ -29,8 +29,13 @@ public abstract class DisplayItem { mBoxHeight = height; } - // returns true if more pass is needed - public abstract boolean render(GLCanvas canvas, int pass); + // 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 long getIdentity(); diff --git a/src/com/android/gallery3d/ui/FadeInTexture.java b/src/com/android/gallery3d/ui/FadeInTexture.java new file mode 100644 index 000000000..1c44b5aed --- /dev/null +++ b/src/com/android/gallery3d/ui/FadeInTexture.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2011 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; + +import com.android.gallery3d.common.Utils; + +import android.os.SystemClock; + +// FadeInTexture is a texture which begins with a color, then gradually animates +// into a given texture. +public class FadeInTexture implements Texture { + private static final String TAG = "FadeInTexture"; + + // The duration of the animation in milliseconds + private static final int DURATION = 180; + + private final BasicTexture mTexture; + private final int mColor; + private final long mStartTime; + private final int mWidth; + private final int mHeight; + private final boolean mIsOpaque; + private boolean mIsAnimating; + + public FadeInTexture(int color, BasicTexture texture) { + mColor = color; + mTexture = texture; + mWidth = mTexture.getWidth(); + mHeight = mTexture.getHeight(); + mIsOpaque = mTexture.isOpaque(); + mStartTime = now(); + mIsAnimating = true; + } + + public void draw(GLCanvas canvas, int x, int y) { + draw(canvas, x, y, mWidth, mHeight); + } + + public void draw(GLCanvas canvas, int x, int y, int w, int h) { + if (isAnimating()) { + canvas.drawMixed(mTexture, mColor, getRatio(), x, y, w, h); + } else { + mTexture.draw(canvas, x, y, w, h); + } + } + + public boolean isOpaque() { + return mIsOpaque; + } + + public int getWidth() { + return mWidth; + } + + public int getHeight() { + return mHeight; + } + + public boolean isAnimating() { + if (mIsAnimating) { + if (now() - mStartTime >= DURATION) { + mIsAnimating = false; + } + } + return mIsAnimating; + } + + private float getRatio() { + float r = (float)(now() - mStartTime) / DURATION; + return Utils.clamp(1.0f - r, 0.0f, 1.0f); + } + + private long now() { + return SystemClock.uptimeMillis(); + } +} diff --git a/src/com/android/gallery3d/ui/GridDrawer.java b/src/com/android/gallery3d/ui/GridDrawer.java index fbd9e7851..e8e072dc8 100644 --- a/src/com/android/gallery3d/ui/GridDrawer.java +++ b/src/com/android/gallery3d/ui/GridDrawer.java @@ -46,15 +46,14 @@ public class GridDrawer extends IconDrawer { @Override public void draw(GLCanvas canvas, Texture content, int width, - int height, int rotation, Path path, int topIndex, + int height, int rotation, Path path, int dataSourceType, int mediaType, boolean isPanorama, int labelBackgroundHeight, boolean wantCache, boolean isCaching) { int x = -width / 2; int y = -height / 2; - drawWithRotationAndGray(canvas, content, x, y, width, height, rotation, - topIndex); + drawWithRotation(canvas, content, x, y, width, height, rotation); if (((rotation / 90) & 0x01) == 1) { int temp = width; @@ -64,15 +63,11 @@ public class GridDrawer extends IconDrawer { y = -height / 2; } - drawMediaTypeOverlay(canvas, mediaType, isPanorama, x, y, width, height, - topIndex); - - if (topIndex == 0) { - drawLabelBackground(canvas, width, height, labelBackgroundHeight); - drawIcon(canvas, width, height, dataSourceType); - if (dataSourceType == DATASOURCE_TYPE_MTP) { - drawImportLabel(canvas, width, height); - } + drawMediaTypeOverlay(canvas, mediaType, isPanorama, x, y, width, height); + drawLabelBackground(canvas, width, height, labelBackgroundHeight); + drawIcon(canvas, width, height, dataSourceType); + if (dataSourceType == DATASOURCE_TYPE_MTP) { + drawImportLabel(canvas, width, height); } if (mSelectionManager.isPressedPath(path)) { diff --git a/src/com/android/gallery3d/ui/HighlightDrawer.java b/src/com/android/gallery3d/ui/HighlightDrawer.java index d23a00d0c..f6a4695cb 100644 --- a/src/com/android/gallery3d/ui/HighlightDrawer.java +++ b/src/com/android/gallery3d/ui/HighlightDrawer.java @@ -35,14 +35,13 @@ public class HighlightDrawer extends IconDrawer { @Override public void draw(GLCanvas canvas, Texture content, int width, - int height, int rotation, Path path, int topIndex, + int height, int rotation, Path path, int dataSourceType, int mediaType, boolean isPanorama, int labelBackgroundHeight, boolean wantCache, boolean isCaching) { int x = -width / 2; int y = -height / 2; - drawWithRotationAndGray(canvas, content, x, y, width, height, rotation, - topIndex); + drawWithRotation(canvas, content, x, y, width, height, rotation); if (((rotation / 90) & 0x01) == 1) { int temp = width; @@ -52,13 +51,9 @@ public class HighlightDrawer extends IconDrawer { y = -height / 2; } - drawMediaTypeOverlay(canvas, mediaType, isPanorama, x, y, width, height, - topIndex); - - if (topIndex == 0) { - drawLabelBackground(canvas, width, height, labelBackgroundHeight); - drawIcon(canvas, width, height, dataSourceType); - } + drawMediaTypeOverlay(canvas, mediaType, isPanorama, x, y, width, height); + drawLabelBackground(canvas, width, height, labelBackgroundHeight); + drawIcon(canvas, width, height, dataSourceType); if (mSelectionManager.isPressedPath(path)) { drawPressedFrame(canvas, x, y, width, height); diff --git a/src/com/android/gallery3d/ui/IconDrawer.java b/src/com/android/gallery3d/ui/IconDrawer.java index 586bd6cdf..25440bca5 100644 --- a/src/com/android/gallery3d/ui/IconDrawer.java +++ b/src/com/android/gallery3d/ui/IconDrawer.java @@ -108,10 +108,9 @@ public abstract class IconDrawer extends SelectionDrawer { } protected void drawMediaTypeOverlay(GLCanvas canvas, int mediaType, - boolean isPanorama, int x, int y, int width, int height, - int topIndex) { + boolean isPanorama, int x, int y, int width, int height) { if (mediaType == MediaObject.MEDIA_TYPE_VIDEO) { - drawVideoOverlay(canvas, x, y, width, height, topIndex); + drawVideoOverlay(canvas, x, y, width, height); } if (isPanorama) { drawPanoramaBorder(canvas, x, y, width, height); @@ -119,7 +118,7 @@ public abstract class IconDrawer extends SelectionDrawer { } protected void drawVideoOverlay(GLCanvas canvas, int x, int y, - int width, int height, int topIndex) { + int width, int height) { // Scale the video overlay to the height of the thumbnail and put it // on the left side. float scale = (float) height / mVideoOverlay.getHeight(); @@ -127,10 +126,8 @@ public abstract class IconDrawer extends SelectionDrawer { int h = Math.round(scale * mVideoOverlay.getHeight()); mVideoOverlay.draw(canvas, x, y, w, h); - if (topIndex == 0) { - int side = Math.min(width, height) / 6; - mVideoPlayIcon.draw(canvas, -side / 2, -side / 2, side, side); - } + int side = Math.min(width, height) / 6; + mVideoPlayIcon.draw(canvas, -side / 2, -side / 2, side, side); } protected void drawPanoramaBorder(GLCanvas canvas, int x, int y, diff --git a/src/com/android/gallery3d/ui/ManageCacheDrawer.java b/src/com/android/gallery3d/ui/ManageCacheDrawer.java index b1ed24948..1a94bca88 100644 --- a/src/com/android/gallery3d/ui/ManageCacheDrawer.java +++ b/src/com/android/gallery3d/ui/ManageCacheDrawer.java @@ -56,16 +56,14 @@ public class ManageCacheDrawer extends IconDrawer { @Override public void draw(GLCanvas canvas, Texture content, int width, - int height, int rotation, Path path, int topIndex, + int height, int rotation, Path path, int dataSourceType, int mediaType, boolean isPanorama, int labelBackgroundHeight, boolean wantCache, boolean isCaching) { - int x = -width / 2; int y = -height / 2; - drawWithRotationAndGray(canvas, content, x, y, width, height, rotation, - topIndex); + drawWithRotation(canvas, content, x, y, width, height, rotation); if (((rotation / 90) & 0x01) == 1) { int temp = width; @@ -75,18 +73,11 @@ public class ManageCacheDrawer extends IconDrawer { y = -height / 2; } - drawMediaTypeOverlay(canvas, mediaType, isPanorama, x, y, width, height, - topIndex); - - if (topIndex == 0) { - drawLabelBackground(canvas, width, height, labelBackgroundHeight); - drawIcon(canvas, width, height, dataSourceType); - } - - if (topIndex == 0) { - drawCachingPin(canvas, path, dataSourceType, isCaching, wantCache, - width, height); - } + drawMediaTypeOverlay(canvas, mediaType, isPanorama, x, y, width, height); + drawLabelBackground(canvas, width, height, labelBackgroundHeight); + drawIcon(canvas, width, height, dataSourceType); + drawCachingPin(canvas, path, dataSourceType, isCaching, wantCache, + width, height); if (mSelectionManager.isPressedPath(path)) { drawPressedFrame(canvas, x, y, width, height); diff --git a/src/com/android/gallery3d/ui/SelectionDrawer.java b/src/com/android/gallery3d/ui/SelectionDrawer.java index 70d8ad57a..43b368f6f 100644 --- a/src/com/android/gallery3d/ui/SelectionDrawer.java +++ b/src/com/android/gallery3d/ui/SelectionDrawer.java @@ -34,13 +34,13 @@ public abstract class SelectionDrawer { public abstract void prepareDrawing(); public abstract void draw(GLCanvas canvas, Texture content, int width, int height, int rotation, Path path, - int topIndex, int dataSourceType, int mediaType, boolean isPanorama, + int dataSourceType, int mediaType, boolean isPanorama, int labelBackgroundHeight, boolean wantCache, boolean isCaching); public abstract void drawFocus(GLCanvas canvas, int width, int height); public void draw(GLCanvas canvas, Texture content, int width, int height, int rotation, Path path, int mediaType, boolean isPanorama) { - draw(canvas, content, width, height, rotation, path, 0, + draw(canvas, content, width, height, rotation, path, DATASOURCE_TYPE_NOT_CATEGORIZED, mediaType, isPanorama, 0, false, false); } @@ -59,27 +59,6 @@ public abstract class SelectionDrawer { } } - public static void drawWithRotationAndGray(GLCanvas canvas, Texture content, - int x, int y, int width, int height, int rotation, - int topIndex) { - if (rotation != 0) { - canvas.save(GLCanvas.SAVE_FLAG_MATRIX); - canvas.rotate(rotation, 0, 0, 1); - } - - if (topIndex > 0 && (content instanceof BasicTexture)) { - float ratio = Utils.clamp(0.3f + 0.2f * topIndex, 0f, 1f); - canvas.drawMixed((BasicTexture) content, 0xFF222222, ratio, - x, y, width, height); - } else { - content.draw(canvas, x, y, width, height); - } - - if (rotation != 0) { - canvas.restore(); - } - } - public static void drawFrame(GLCanvas canvas, NinePatchTexture frame, int x, int y, int width, int height) { Rect p = frame.getPaddings(); diff --git a/src/com/android/gallery3d/ui/SlotView.java b/src/com/android/gallery3d/ui/SlotView.java index 4b0dc2950..5d0922e93 100644 --- a/src/com/android/gallery3d/ui/SlotView.java +++ b/src/com/android/gallery3d/ui/SlotView.java @@ -265,7 +265,11 @@ public class SlotView extends GLView { if (oldX > 0 && newX == 0 || oldX < limit && newX == limit) { float v = mScroller.getCurrVelocity(); if (newX == limit) v = -v; - mPaper.edgeReached(v); + + // I don't know why, but getCurrVelocity() can return NaN. + if (!Float.isNaN(v)) { + mPaper.edgeReached(v); + } } paperActive = mPaper.advanceAnimation(); } @@ -286,9 +290,11 @@ public class SlotView extends GLView { LinkedNode.List<ItemEntry> list = mItemList; for (ItemEntry entry = list.getLast(); entry != null;) { - if (renderItem(canvas, entry, interpolate, 0, paperActive)) { + 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); } @@ -296,9 +302,11 @@ public class SlotView extends GLView { while (!mCurrentItems.isEmpty()) { for (int i = 0, n = mCurrentItems.size(); i < n; i++) { ItemEntry entry = mCurrentItems.get(i); - if (renderItem(canvas, entry, interpolate, pass, paperActive)) { + 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); } mCurrentItems.clear(); // swap mNextItems with mCurrentItems @@ -321,7 +329,7 @@ public class SlotView extends GLView { mMoreAnimation = more; } - private boolean renderItem(GLCanvas canvas, ItemEntry entry, + private int renderItem(GLCanvas canvas, ItemEntry entry, float interpolate, int pass, boolean paperActive) { canvas.save(GLCanvas.SAVE_FLAG_ALPHA | GLCanvas.SAVE_FLAG_MATRIX); Position position = entry.target; @@ -346,7 +354,7 @@ public class SlotView extends GLView { canvas.translate(position.x, position.y, position.z); } canvas.rotate(position.theta, 0, 0, 1); - boolean more = entry.item.render(canvas, pass); + int more = entry.item.render(canvas, pass); canvas.restore(); return more; } diff --git a/src/com/android/gallery3d/ui/StripDrawer.java b/src/com/android/gallery3d/ui/StripDrawer.java index 5120a0cdf..5c67ee458 100644 --- a/src/com/android/gallery3d/ui/StripDrawer.java +++ b/src/com/android/gallery3d/ui/StripDrawer.java @@ -48,7 +48,7 @@ public class StripDrawer extends SelectionDrawer { @Override public void draw(GLCanvas canvas, Texture content, - int width, int height, int rotation, Path path, int topIndex, + int width, int height, int rotation, Path path, int dataSourceType, int mediaType, boolean isPanorama, int labelBackgroundHeight, boolean wantCache, boolean isCaching) { diff --git a/src/com/android/gallery3d/ui/Texture.java b/src/com/android/gallery3d/ui/Texture.java index feb7b0ab7..4d1749bb6 100644 --- a/src/com/android/gallery3d/ui/Texture.java +++ b/src/com/android/gallery3d/ui/Texture.java @@ -24,6 +24,7 @@ package com.android.gallery3d.ui; // // Texture // -- ColorTexture +// -- FadeInTexture // -- BasicTexture // -- RawTexture // -- UploadedTexture |