From 1de93cc0cbd940ed1d07048dda56406e7c3a7d96 Mon Sep 17 00:00:00 2001 From: Bobby Georgescu Date: Wed, 12 Sep 2012 13:48:50 -0700 Subject: Reskin: Fix stability bugs introduced by reskin Bug: 7150348 Bug: 7144206 Bug: 7050303 If PhotoPage is launched/resumed on a completely empty album (for instance, if Gallery was opened to the Camera folder and paused, all photos were deleted via the Camera app, and then Gallery is resumed), bail out of PhotoPage since it cannot handle this. Also fixes an NPE. Change-Id: I162ff5ad149c322704c8af7d4705d87ae6c6098a --- src/com/android/gallery3d/app/AlbumPage.java | 2 +- src/com/android/gallery3d/app/PhotoPage.java | 110 +++++++++++++++------------ 2 files changed, 62 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java index cbf9c1a62..363b87689 100644 --- a/src/com/android/gallery3d/app/AlbumPage.java +++ b/src/com/android/gallery3d/app/AlbumPage.java @@ -560,7 +560,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster } private void prepareAnimationBackToFilmstrip(int slotIndex) { - if (!mAlbumDataAdapter.isActive(slotIndex)) return; + if (mAlbumDataAdapter == null || !mAlbumDataAdapter.isActive(slotIndex)) return; prepareFadeOutTexture(); TransitionStore transitions = mActivity.getTransitionStore(); transitions.put(PhotoPage.KEY_INDEX_HINT, slotIndex); diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index 0f927df64..d7f701ab5 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -245,6 +245,51 @@ public class PhotoPage extends ActivityState implements mOrientationManager.addListener(this); mActivity.getGLRoot().setOrientationSource(mOrientationManager); + mHandler = new SynchronizedHandler(mActivity.getGLRoot()) { + @Override + public void handleMessage(Message message) { + switch (message.what) { + case MSG_HIDE_BARS: { + hideBars(); + break; + } + case MSG_REFRESH_GRID_BUTTON: { + setGridButtonVisibility(mPhotoView.getFilmMode()); + break; + } + case MSG_REFRESH_EDIT_BUTTON: { + refreshEditButton(); + break; + } + case MSG_LOCK_ORIENTATION: { + mOrientationManager.lockOrientation(); + break; + } + case MSG_UNLOCK_ORIENTATION: { + mOrientationManager.unlockOrientation(); + break; + } + case MSG_ON_FULL_SCREEN_CHANGED: { + mAppBridge.onFullScreenChanged(message.arg1 == 1); + break; + } + case MSG_UPDATE_ACTION_BAR: { + updateBars(); + break; + } + case MSG_WANT_BARS: { + wantBars(); + break; + } + case MSG_UNFREEZE_GLROOT: { + mActivity.getGLRoot().unfreeze(); + break; + } + default: throw new AssertionError(message.what); + } + } + }; + mSetPathString = data.getString(KEY_MEDIA_SET_PATH); mOriginalSetPathString = mSetPathString; mNfcAdapter = NfcAdapter.getDefaultAdapter(mActivity.getAndroidContext()); @@ -306,8 +351,13 @@ public class PhotoPage extends ActivityState implements Log.w(TAG, "failed to restore " + mSetPathString); } if (itemPath == null) { - itemPath = mMediaSet.getMediaItem(mCurrentIndex, 1) - .get(0).getPath(); + mMediaSet.reload(); + if (mMediaSet.getMediaItemCount() > 0) { + itemPath = mMediaSet.getMediaItem(mCurrentIndex, 1) + .get(0).getPath(); + } else { + return; + } } PhotoDataAdapter pda = new PhotoDataAdapter( mActivity, mPhotoView, mMediaSet, itemPath, mCurrentIndex, @@ -357,51 +407,6 @@ public class PhotoPage extends ActivityState implements updateCurrentPhoto(mediaItem); } - mHandler = new SynchronizedHandler(mActivity.getGLRoot()) { - @Override - public void handleMessage(Message message) { - switch (message.what) { - case MSG_HIDE_BARS: { - hideBars(); - break; - } - case MSG_REFRESH_GRID_BUTTON: { - setGridButtonVisibility(mPhotoView.getFilmMode()); - break; - } - case MSG_REFRESH_EDIT_BUTTON: { - refreshEditButton(); - break; - } - case MSG_LOCK_ORIENTATION: { - mOrientationManager.lockOrientation(); - break; - } - case MSG_UNLOCK_ORIENTATION: { - mOrientationManager.unlockOrientation(); - break; - } - case MSG_ON_FULL_SCREEN_CHANGED: { - mAppBridge.onFullScreenChanged(message.arg1 == 1); - break; - } - case MSG_UPDATE_ACTION_BAR: { - updateBars(); - break; - } - case MSG_WANT_BARS: { - wantBars(); - break; - } - case MSG_UNFREEZE_GLROOT: { - mActivity.getGLRoot().unfreeze(); - break; - } - default: throw new AssertionError(message.what); - } - } - }; - mPhotoView.setFilmMode(mStartInFilmstrip); setupEditButton(); } @@ -725,6 +730,7 @@ public class PhotoPage extends ActivityState implements @Override protected boolean onItemSelected(MenuItem item) { + if (mModel == null) return true; refreshHidingMessage(); MediaItem current = mModel.getMediaItem(0); @@ -1048,11 +1054,13 @@ public class PhotoPage extends ActivityState implements mActivity.getGLRoot().unfreeze(); mHandler.removeMessages(MSG_UNFREEZE_GLROOT); - if (isFinishing()) preparePhotoFallbackView(); DetailsHelper.pause(); + if (mModel != null) { + if (isFinishing()) preparePhotoFallbackView(); + mModel.pause(); + } mPhotoView.pause(); - mModel.pause(); mHandler.removeMessages(MSG_HIDE_BARS); mActionBar.removeOnMenuVisibilityListener(mMenuVisibilityListener); @@ -1118,6 +1126,10 @@ public class PhotoPage extends ActivityState implements protected void onResume() { super.onResume(); + if (mModel == null) { + mActivity.getStateManager().finishState(this); + return; + } transitionFromAlbumPageIfNeeded(); mActivity.getGLRoot().freeze(); -- cgit v1.2.3