diff options
author | Paul Westbrook <pwestbro@google.com> | 2012-08-28 22:03:22 -0700 |
---|---|---|
committer | Paul Westbrook <pwestbro@google.com> | 2012-08-28 23:13:44 -0700 |
commit | 114cef99189d693ed9cd8cf778a60823d06d5298 (patch) | |
tree | 55ce425ed599da7eab3ba9548f9fcc6186acdf44 /photoviewer/src | |
parent | 26e3f68ae8342cedd57353e399e7d0e920228a4e (diff) | |
download | android_frameworks_ex-114cef99189d693ed9cd8cf778a60823d06d5298.tar.gz android_frameworks_ex-114cef99189d693ed9cd8cf778a60823d06d5298.tar.bz2 android_frameworks_ex-114cef99189d693ed9cd8cf778a60823d06d5298.zip |
Fix crash in email with attachments
There isn't a need to call swapCursor in a runnable
Bug: 7072747
Change-Id: I0a0a9b6835acc4a1d1748c94f4d8bec4551638b0
Diffstat (limited to 'photoviewer/src')
-rw-r--r-- | photoviewer/src/com/android/ex/photo/PhotoViewActivity.java | 66 | ||||
-rw-r--r-- | photoviewer/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java | 13 |
2 files changed, 38 insertions, 41 deletions
diff --git a/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java b/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java index 2e54569..54feada 100644 --- a/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java +++ b/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java @@ -133,7 +133,7 @@ public class PhotoViewActivity extends Activity implements private boolean mRestartLoader; /** Whether or not this activity is paused */ private boolean mIsPaused = true; - private Handler mActionBarHideHandler; + private final Handler mHandler = new Handler(); // TODO Find a better way to do this. We basically want the activity to display the // "loading..." progress until the fragment takes over and shows it's own "loading..." // progress [located in photo_header_view.xml]. We could potentially have all status displayed @@ -197,7 +197,6 @@ public class PhotoViewActivity extends Activity implements R.integer.action_bar_delay_time_in_millis); actionBar.addOnMenuVisibilityListener(this); actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE); - mActionBarHideHandler = new Handler(); } @Override @@ -297,39 +296,29 @@ public class PhotoViewActivity extends Activity implements } else { mAlbumCount = data.getCount(); - // Cannot do this directly; need to be out of the loader - // TODO(pwestbro): Fix this as this could cause a problem as the cursor may be - // closed before the runnable runs. - new Handler().post(new Runnable() { - @Override - public void run() { - // If the cursor is closed, we can leave, as another runnable will have - // been posted (this means our Cursor is already out-of-date) - if (data.isClosed()) return; - - // We're paused; don't do anything now, we'll get re-invoked - // when the activity becomes active again - if (mIsPaused) { - mRestartLoader = true; - return; - } - mIsEmpty = false; - - // set the selected photo - int itemIndex = mPhotoIndex; - - // Use an index of 0 if the index wasn't specified or couldn't be found - if (itemIndex < 0) { - itemIndex = 0; - } - - mAdapter.swapCursor(data); - notifyCursorListeners(data); - - mViewPager.setCurrentItem(itemIndex, false); - setViewActivated(); - } - }); + // We're paused; don't do anything now, we'll get re-invoked + // when the activity becomes active again + // TODO(pwestbro): This shouldn't be necessary, as the loader manager should + // restart the loader + if (mIsPaused) { + mRestartLoader = true; + return; + } + mIsEmpty = false; + + // set the selected photo + int itemIndex = mPhotoIndex; + + // Use an index of 0 if the index wasn't specified or couldn't be found + if (itemIndex < 0) { + itemIndex = 0; + } + + mAdapter.swapCursor(data); + notifyCursorListeners(data); + + mViewPager.setCurrentItem(itemIndex, false); + setViewActivated(); } } } @@ -344,6 +333,9 @@ public class PhotoViewActivity extends Activity implements @Override public void onLoaderReset(Loader<Cursor> loader) { + // If the loader is reset, remove the reference in the adapter to this cursor + // TODO(pwestbro): reenable this when b/7075236 is fixed + // mAdapter.swapCursor(null); } @Override @@ -422,12 +414,12 @@ public class PhotoViewActivity extends Activity implements } private void postActionBarHideRunnableWithDelay() { - mActionBarHideHandler.postDelayed(mActionBarHideRunnable, + mHandler.postDelayed(mActionBarHideRunnable, mActionBarHideDelayTime); } private void cancelActionBarHideRunnable() { - mActionBarHideHandler.removeCallbacks(mActionBarHideRunnable); + mHandler.removeCallbacks(mActionBarHideRunnable); } private void setLightsOutMode(boolean enabled) { diff --git a/photoviewer/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java b/photoviewer/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java index 3cc387f..bf75ecb 100644 --- a/photoviewer/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java +++ b/photoviewer/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java @@ -55,10 +55,15 @@ public class PhotoPagerAdapter extends BaseCursorPagerAdapter { @Override public Cursor swapCursor(Cursor newCursor) { - mContentUriIndex = - newCursor.getColumnIndex(PhotoContract.PhotoViewColumns.CONTENT_URI); - mThumbnailUriIndex = - newCursor.getColumnIndex(PhotoContract.PhotoViewColumns.THUMBNAIL_URI); + if (newCursor != null) { + mContentUriIndex = + newCursor.getColumnIndex(PhotoContract.PhotoViewColumns.CONTENT_URI); + mThumbnailUriIndex = + newCursor.getColumnIndex(PhotoContract.PhotoViewColumns.THUMBNAIL_URI); + } else { + mContentUriIndex = -1; + mThumbnailUriIndex = -1; + } return super.swapCursor(newCursor); } |