diff options
author | Ray Chen <raychen@google.com> | 2011-10-21 16:07:12 +0800 |
---|---|---|
committer | Ray Chen <raychen@google.com> | 2011-10-27 17:49:59 +0800 |
commit | 09efcf9a9367bda0a9d28f312c9b3d0e93dd49da (patch) | |
tree | adbbdd51460d52d7b47f5fe2caa35bbde09f320b /src/com/android | |
parent | 773d368357ce50bc299551a768584d5a222fd440 (diff) | |
download | android_packages_apps_Snap-09efcf9a9367bda0a9d28f312c9b3d0e93dd49da.tar.gz android_packages_apps_Snap-09efcf9a9367bda0a9d28f312c9b3d0e93dd49da.tar.bz2 android_packages_apps_Snap-09efcf9a9367bda0a9d28f312c9b3d0e93dd49da.zip |
Fix 5471518 Playing slide show from any picture doesn't start from the current picture which is unexpected IRL17 Crespo
Change-Id: I2ed78cee2f6257254794a7724897845c43a3e0a5
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/gallery3d/app/PhotoPage.java | 48 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/SlideshowDataAdapter.java | 19 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/SlideshowPage.java | 75 |
3 files changed, 82 insertions, 60 deletions
diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index 44b9299fc..ec7d16175 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -16,6 +16,25 @@ package com.android.gallery3d.app; +import android.app.ActionBar; +import android.app.Activity; +import android.app.ActionBar.OnMenuVisibilityListener; +import android.content.ActivityNotFoundException; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.WindowManager; +import android.view.View.MeasureSpec; +import android.widget.ShareActionProvider; +import android.widget.Toast; + import com.android.gallery3d.R; import com.android.gallery3d.data.DataManager; import com.android.gallery3d.data.MediaDetails; @@ -41,25 +60,6 @@ import com.android.gallery3d.ui.SynchronizedHandler; import com.android.gallery3d.ui.UserInteractionListener; import com.android.gallery3d.util.GalleryUtils; -import android.app.ActionBar; -import android.app.ActionBar.OnMenuVisibilityListener; -import android.app.Activity; -import android.content.ActivityNotFoundException; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.View.MeasureSpec; -import android.view.WindowManager; -import android.widget.ShareActionProvider; -import android.widget.Toast; - public class PhotoPage extends ActivityState implements PhotoView.PhotoTapListener, FilmStripView.Listener, UserInteractionListener { @@ -92,7 +92,7 @@ public class PhotoPage extends ActivityState private MediaSet mMediaSet; private Menu mMenu; - private Intent mResultIntent = new Intent(); + private final Intent mResultIntent = new Intent(); private int mCurrentIndex = 0; private Handler mHandler; private boolean mShowBars = true; @@ -121,7 +121,7 @@ public class PhotoPage extends ActivityState } } - private GLView mRootPane = new GLView() { + private final GLView mRootPane = new GLView() { @Override protected void renderBackground(GLCanvas view) { @@ -305,6 +305,11 @@ public class PhotoPage extends ActivityState if (!GalleryUtils.isEditorAvailable((Context) mActivity, "image/*")) { supportedOperations &= ~MediaObject.SUPPORT_EDIT; } + MenuItem item = mMenu.findItem(R.id.action_slideshow); + if (item != null) { + item.setVisible(mCurrentPhoto.getMediaType() == MediaObject.MEDIA_TYPE_IMAGE); + } + MenuExecutor.updateMenuOperation(mMenu, supportedOperations); } @@ -417,6 +422,7 @@ public class PhotoPage extends ActivityState case R.id.action_slideshow: { Bundle data = new Bundle(); data.putString(SlideshowPage.KEY_SET_PATH, mMediaSet.getPath().toString()); + data.putString(SlideshowPage.KEY_ITEM_PATH, path.toString()); data.putInt(SlideshowPage.KEY_PHOTO_INDEX, currentIndex); data.putBoolean(SlideshowPage.KEY_REPEAT, true); mActivity.getStateManager().startStateForResult( diff --git a/src/com/android/gallery3d/app/SlideshowDataAdapter.java b/src/com/android/gallery3d/app/SlideshowDataAdapter.java index fb7eec886..7c934ee3b 100644 --- a/src/com/android/gallery3d/app/SlideshowDataAdapter.java +++ b/src/com/android/gallery3d/app/SlideshowDataAdapter.java @@ -16,18 +16,19 @@ package com.android.gallery3d.app; +import android.graphics.Bitmap; + import com.android.gallery3d.app.SlideshowPage.Slide; import com.android.gallery3d.data.ContentListener; import com.android.gallery3d.data.MediaItem; import com.android.gallery3d.data.MediaObject; +import com.android.gallery3d.data.Path; import com.android.gallery3d.util.Future; import com.android.gallery3d.util.FutureListener; import com.android.gallery3d.util.ThreadPool; import com.android.gallery3d.util.ThreadPool.Job; import com.android.gallery3d.util.ThreadPool.JobContext; -import android.graphics.Bitmap; - import java.util.LinkedList; import java.util.concurrent.atomic.AtomicBoolean; @@ -42,6 +43,7 @@ public class SlideshowDataAdapter implements SlideshowPage.Model { public void removeContentListener(ContentListener listener); public long reload(); public MediaItem getMediaItem(int index); + public int findItemIndex(Path path, int hint); } private final SlideshowSource mSource; @@ -51,6 +53,7 @@ public class SlideshowDataAdapter implements SlideshowPage.Model { private boolean mIsActive = false; private boolean mNeedReset; private boolean mDataReady; + private Path mInitialPath; private final LinkedList<Slide> mImageQueue = new LinkedList<Slide>(); @@ -61,8 +64,11 @@ public class SlideshowDataAdapter implements SlideshowPage.Model { private final AtomicBoolean mNeedReload = new AtomicBoolean(false); private final SourceListener mSourceListener = new SourceListener(); - public SlideshowDataAdapter(GalleryContext context, SlideshowSource source, int index) { + // The index is just a hint if initialPath is set + public SlideshowDataAdapter(GalleryContext context, SlideshowSource source, int index, + Path initialPath) { mSource = source; + mInitialPath = initialPath; mLoadIndex = index; mNextOutput = index; mThreadPool = context.getThreadPool(); @@ -77,7 +83,12 @@ public class SlideshowDataAdapter implements SlideshowPage.Model { return null; } } - return mSource.getMediaItem(mLoadIndex); + int index = mLoadIndex; + if (mInitialPath != null) { + index = mSource.findItemIndex(mInitialPath, index); + mInitialPath = null; + } + return mSource.getMediaItem(index); } private class ReloadTask implements Job<Void> { diff --git a/src/com/android/gallery3d/app/SlideshowPage.java b/src/com/android/gallery3d/app/SlideshowPage.java index 5ba7fc777..629bfd796 100644 --- a/src/com/android/gallery3d/app/SlideshowPage.java +++ b/src/com/android/gallery3d/app/SlideshowPage.java @@ -16,11 +16,23 @@ package com.android.gallery3d.app; +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.graphics.Bitmap; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.os.PowerManager; +import android.os.PowerManager.WakeLock; +import android.view.MotionEvent; + import com.android.gallery3d.common.Utils; import com.android.gallery3d.data.ContentListener; import com.android.gallery3d.data.MediaItem; import com.android.gallery3d.data.MediaObject; import com.android.gallery3d.data.MediaSet; +import com.android.gallery3d.data.Path; import com.android.gallery3d.ui.GLCanvas; import com.android.gallery3d.ui.GLView; import com.android.gallery3d.ui.SlideshowView; @@ -28,17 +40,6 @@ import com.android.gallery3d.ui.SynchronizedHandler; import com.android.gallery3d.util.Future; import com.android.gallery3d.util.FutureListener; -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.graphics.Bitmap; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.os.PowerManager; -import android.os.PowerManager.WakeLock; -import android.view.MotionEvent; - import java.util.ArrayList; import java.util.Random; @@ -58,7 +59,9 @@ public class SlideshowPage extends ActivityState { public static interface Model { public void pause(); + public void resume(); + public Future<Slide> nextSlide(FutureListener<Slide> listener); } @@ -81,12 +84,11 @@ public class SlideshowPage extends ActivityState { private Slide mPendingSlide = null; private boolean mIsActive = false; private WakeLock mWakeLock; - private Intent mResultIntent = new Intent(); + private final Intent mResultIntent = new Intent(); - private GLView mRootPane = new GLView() { + private final GLView mRootPane = new GLView() { @Override - protected void onLayout( - boolean changed, int left, int top, int right, int bottom) { + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { mSlideshowView.layout(0, 0, right - left, bottom - top); } @@ -108,8 +110,8 @@ public class SlideshowPage extends ActivityState { public void onCreate(Bundle data, Bundle restoreState) { mFlags |= (FLAG_HIDE_ACTION_BAR | FLAG_HIDE_STATUS_BAR); - PowerManager pm = (PowerManager) mActivity.getAndroidContext() - .getSystemService(Context.POWER_SERVICE); + PowerManager pm = (PowerManager) mActivity.getAndroidContext().getSystemService( + Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); @@ -142,8 +144,8 @@ public class SlideshowPage extends ActivityState { private void showPendingBitmap() { // mPendingBitmap could be null, if - // 1.) there is no more items - // 2.) mModel is paused + // 1.) there is no more items + // 2.) mModel is paused Slide slide = mPendingSlide; if (slide == null) { if (mIsActive) { @@ -157,8 +159,7 @@ public class SlideshowPage extends ActivityState { setStateResult(Activity.RESULT_OK, mResultIntent .putExtra(KEY_ITEM_PATH, slide.item.getPath().toString()) .putExtra(KEY_PHOTO_INDEX, slide.index)); - mHandler.sendEmptyMessageDelayed(MSG_LOAD_NEXT_BITMAP, - SLIDESHOW_DELAY); + mHandler.sendEmptyMessageDelayed(MSG_LOAD_NEXT_BITMAP, SLIDESHOW_DELAY); } @Override @@ -192,23 +193,21 @@ public class SlideshowPage extends ActivityState { // We only want to show slideshow for images only, not videos. String mediaPath = data.getString(KEY_SET_PATH); - mediaPath = FilterUtils.newFilterPath(mediaPath, - FilterUtils.FILTER_IMAGE_ONLY); + mediaPath = FilterUtils.newFilterPath(mediaPath, FilterUtils.FILTER_IMAGE_ONLY); MediaSet mediaSet = mActivity.getDataManager().getMediaSet(mediaPath); if (random) { boolean repeat = data.getBoolean(KEY_REPEAT); - mModel = new SlideshowDataAdapter( - mActivity, new ShuffleSource(mediaSet, repeat), 0); - setStateResult(Activity.RESULT_OK, - mResultIntent.putExtra(KEY_PHOTO_INDEX, 0)); + mModel = new SlideshowDataAdapter(mActivity, + new ShuffleSource(mediaSet, repeat), 0, null); + setStateResult(Activity.RESULT_OK, mResultIntent.putExtra(KEY_PHOTO_INDEX, 0)); } else { int index = data.getInt(KEY_PHOTO_INDEX); + Path path = Path.fromString(data.getString(KEY_ITEM_PATH)); boolean repeat = data.getBoolean(KEY_REPEAT); - mModel = new SlideshowDataAdapter(mActivity, - new SequentialSource(mediaSet, repeat), index); - setStateResult(Activity.RESULT_OK, - mResultIntent.putExtra(KEY_PHOTO_INDEX, index)); + mModel = new SlideshowDataAdapter(mActivity, new SequentialSource(mediaSet, repeat), + index, path); + setStateResult(Activity.RESULT_OK, mResultIntent.putExtra(KEY_PHOTO_INDEX, index)); } } @@ -236,7 +235,7 @@ public class SlideshowPage extends ActivityState { private final MediaSet mMediaSet; private final Random mRandom = new Random(); private int mOrder[] = new int[0]; - private boolean mRepeat; + private final boolean mRepeat; private long mSourceVersion = MediaSet.INVALID_DATA_VERSION; private int mLastIndex = -1; @@ -245,6 +244,10 @@ public class SlideshowPage extends ActivityState { mRepeat = repeat; } + public int findItemIndex(Path path, int hint) { + return hint; + } + public MediaItem getMediaItem(int index) { if (!mRepeat && index >= mOrder.length) return null; if (mOrder.length == 0) return null; @@ -306,6 +309,10 @@ public class SlideshowPage extends ActivityState { mRepeat = repeat; } + public int findItemIndex(Path path, int hint) { + return mMediaSet.getIndexOfItem(path, hint); + } + public MediaItem getMediaItem(int index) { int dataEnd = mDataStart + mData.size(); @@ -320,9 +327,7 @@ public class SlideshowPage extends ActivityState { dataEnd = index + mData.size(); } - return (index < mDataStart || index >= dataEnd) - ? null - : mData.get(index - mDataStart); + return (index < mDataStart || index >= dataEnd) ? null : mData.get(index - mDataStart); } public long reload() { |