From 09efcf9a9367bda0a9d28f312c9b3d0e93dd49da Mon Sep 17 00:00:00 2001 From: Ray Chen Date: Fri, 21 Oct 2011 16:07:12 +0800 Subject: Fix 5471518 Playing slide show from any picture doesn't start from the current picture which is unexpected IRL17 Crespo Change-Id: I2ed78cee2f6257254794a7724897845c43a3e0a5 --- src/com/android/gallery3d/app/SlideshowPage.java | 75 +++++++++++++----------- 1 file changed, 40 insertions(+), 35 deletions(-) (limited to 'src/com/android/gallery3d/app/SlideshowPage.java') 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 nextSlide(FutureListener 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() { -- cgit v1.2.3