From 8ed226f1d1a05dc94d512fc183f0a539b0361e6b Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Thu, 15 Mar 2012 15:23:00 -0700 Subject: bug #6176711: guard against null GalleryActionBar. When entering Gallery app from WallPaper picker, the activity is DialogPicker, which doesn't initialize GalleryActionbar so getGalleryActionbar() returns null. Guard against using the null object. I fixed the obvious NPE here, but Ray or Yuli should take a closer look, to see why this is broken. Change-Id: Ic6923c388ea7b72ab402131fc3b039546509e340 --- src/com/android/gallery3d/app/ActivityState.java | 5 ++++- src/com/android/gallery3d/app/AlbumPage.java | 5 ++++- src/com/android/gallery3d/app/PhotoPage.java | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/com/android/gallery3d/app/ActivityState.java b/src/com/android/gallery3d/app/ActivityState.java index 443e2bd29..384ae734b 100644 --- a/src/com/android/gallery3d/app/ActivityState.java +++ b/src/com/android/gallery3d/app/ActivityState.java @@ -141,7 +141,10 @@ abstract public class ActivityState { actionBar.show(); } int stateCount = mActivity.getStateManager().getStateCount(); - mActivity.getGalleryActionBar().setDisplayOptions(stateCount > 1, true); + GalleryActionBar galleryActionbar = mActivity.getGalleryActionBar(); + if (galleryActionbar != null) { + galleryActionbar.setDisplayOptions(stateCount > 1, true); + } // Default behavior, this can be overridden in ActivityState's onResume. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); } diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java index 411464e86..32c5b7fc2 100644 --- a/src/com/android/gallery3d/app/AlbumPage.java +++ b/src/com/android/gallery3d/app/AlbumPage.java @@ -319,7 +319,10 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster Path path = mMediaSet.getPath(); boolean enableHomeButton = (mActivity.getStateManager().getStateCount() > 1) | mParentMediaSetString != null; - mActivity.getGalleryActionBar().setDisplayOptions(enableHomeButton, true); + GalleryActionBar galleryActionBar = mActivity.getGalleryActionBar(); + if (galleryActionBar != null) { + galleryActionBar.setDisplayOptions(enableHomeButton, true); + } // Set the reload bit here to prevent it exit this page in clearLoadingBit(). setLoadingBit(BIT_LOADING_RELOAD); diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index 8040a2fc6..a8c69b567 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -630,8 +630,10 @@ public class PhotoPage extends ActivityState if (mMenuVisibilityListener == null) { mMenuVisibilityListener = new MyMenuVisibilityListener(); } - mActivity.getGalleryActionBar().setDisplayOptions(mSetPathString != null, true); - + GalleryActionBar galleryActionBar = mActivity.getGalleryActionBar(); + if (galleryActionBar != null) { + galleryActionBar.setDisplayOptions(mSetPathString != null, true); + } mActionBar.addOnMenuVisibilityListener(mMenuVisibilityListener); onUserInteraction(); } -- cgit v1.2.3 From bc1c49cc2614e521cafdcfcfe5c26326ab5127b7 Mon Sep 17 00:00:00 2001 From: The Android Automerger Date: Tue, 20 Mar 2012 14:15:05 -0700 Subject: merge in jb-release history after reset to master --- .../gallery3d/app/AbstractGalleryActivity.java | 6 +- src/com/android/gallery3d/app/AlbumPage.java | 2 +- src/com/android/gallery3d/app/AlbumSetPage.java | 39 ++++---- src/com/android/gallery3d/app/Gallery.java | 7 ++ .../android/gallery3d/app/GalleryActionBar.java | 108 +++++++++------------ src/com/android/gallery3d/app/ManageCachePage.java | 2 +- src/com/android/gallery3d/app/PhotoPage.java | 11 ++- src/com/android/gallery3d/app/PickerActivity.java | 8 ++ 8 files changed, 91 insertions(+), 92 deletions(-) diff --git a/src/com/android/gallery3d/app/AbstractGalleryActivity.java b/src/com/android/gallery3d/app/AbstractGalleryActivity.java index 9a1d3d300..03f522f48 100644 --- a/src/com/android/gallery3d/app/AbstractGalleryActivity.java +++ b/src/com/android/gallery3d/app/AbstractGalleryActivity.java @@ -43,7 +43,6 @@ public class AbstractGalleryActivity extends Activity implements GalleryActivity private static final String TAG = "AbstractGalleryActivity"; private GLRootView mGLRootView; private StateManager mStateManager; - private GalleryActionBar mActionBar; private AlertDialog mAlertDialog = null; private BroadcastReceiver mMountReceiver = new BroadcastReceiver() { @@ -193,10 +192,7 @@ public class AbstractGalleryActivity extends Activity implements GalleryActivity @Override public GalleryActionBar getGalleryActionBar() { - if (mActionBar == null) { - mActionBar = new GalleryActionBar(this); - } - return mActionBar; + return null; } @Override diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java index c83321671..411464e86 100644 --- a/src/com/android/gallery3d/app/AlbumPage.java +++ b/src/com/android/gallery3d/app/AlbumPage.java @@ -118,7 +118,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster protected void onLayout( boolean changed, int left, int top, int right, int bottom) { - int slotViewTop = mActivity.getGalleryActionBar().getHeight(); + int slotViewTop = GalleryActionBar.getHeight((Activity) mActivity); int slotViewBottom = bottom - top; int slotViewRight = right - left; diff --git a/src/com/android/gallery3d/app/AlbumSetPage.java b/src/com/android/gallery3d/app/AlbumSetPage.java index e79a3ae04..c52cd8c05 100644 --- a/src/com/android/gallery3d/app/AlbumSetPage.java +++ b/src/com/android/gallery3d/app/AlbumSetPage.java @@ -79,7 +79,6 @@ public class AlbumSetPage extends ActivityState implements private String mTitle; private String mSubtitle; private boolean mShowClusterMenu; - private GalleryActionBar mActionBar; private int mSelectedAction; private Vibrator mVibrator; @@ -121,7 +120,7 @@ public class AlbumSetPage extends ActivityState implements boolean changed, int left, int top, int right, int bottom) { mEyePosition.resetPosition(); - int slotViewTop = mActionBar.getHeight(); + int slotViewTop = GalleryActionBar.getHeight((Activity) mActivity); int slotViewBottom = bottom - top; int slotViewRight = right - left; @@ -271,9 +270,11 @@ public class AlbumSetPage extends ActivityState implements mEyePosition = new EyePosition(context, this); mDetailsSource = new MyDetailsSource(); mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); - mActionBar = mActivity.getGalleryActionBar(); - mSelectedAction = data.getInt(AlbumSetPage.KEY_SELECTED_CLUSTER_TYPE, - FilterUtils.CLUSTER_BY_ALBUM); + GalleryActionBar actionBar = mActivity.getGalleryActionBar(); + if (actionBar != null) { + mSelectedAction = data.getInt( + AlbumSetPage.KEY_SELECTED_CLUSTER_TYPE, FilterUtils.CLUSTER_BY_ALBUM); + } startTransition(); } @@ -310,10 +311,11 @@ public class AlbumSetPage extends ActivityState implements mAlbumSetView.pause(); mEyePosition.pause(); DetailsHelper.pause(); + GalleryActionBar actionBar = mActivity.getGalleryActionBar(); // Call disableClusterMenu to avoid receiving callback after paused. // Don't hide menu here otherwise the list menu will disappear earlier than // the action bar, which is janky and unwanted behavior. - mActionBar.disableClusterMenu(false); + if (actionBar != null) actionBar.disableClusterMenu(false); if (mSyncTask != null) { mSyncTask.cancel(); mSyncTask = null; @@ -335,8 +337,9 @@ public class AlbumSetPage extends ActivityState implements mAlbumSetView.resume(); mEyePosition.resume(); mActionModeHandler.resume(); - if (mShowClusterMenu) { - mActionBar.enableClusterMenu(mSelectedAction, this); + GalleryActionBar actionBar = mActivity.getGalleryActionBar(); + if (mShowClusterMenu && actionBar != null) { + actionBar.enableClusterMenu(mSelectedAction, this); } if (!mInitialSynced) { setLoadingBit(BIT_LOADING_SYNC); @@ -396,6 +399,7 @@ public class AlbumSetPage extends ActivityState implements @Override protected boolean onCreateActionBar(Menu menu) { Activity activity = (Activity) mActivity; + GalleryActionBar actionBar = mActivity.getGalleryActionBar(); MenuInflater inflater = activity.getMenuInflater(); final boolean inAlbum = mActivity.getStateManager().hasStateClass( @@ -411,10 +415,10 @@ public class AlbumSetPage extends ActivityState implements ? R.string.select_video : R.string.select_item; } - mActionBar.setTitle(id); + actionBar.setTitle(id); } else if (mGetAlbum) { inflater.inflate(R.menu.pickup, menu); - mActionBar.setTitle(R.string.select_album); + actionBar.setTitle(R.string.select_album); } else { mShowClusterMenu = !inAlbum; inflater.inflate(R.menu.albumset, menu); @@ -422,7 +426,7 @@ public class AlbumSetPage extends ActivityState implements if (selectItem != null) { boolean selectAlbums = !inAlbum && - mActionBar.getClusterTypeAction() == FilterUtils.CLUSTER_BY_ALBUM; + actionBar.getClusterTypeAction() == FilterUtils.CLUSTER_BY_ALBUM; if (selectAlbums) { selectItem.setTitle(R.string.select_album); } else { @@ -430,14 +434,14 @@ public class AlbumSetPage extends ActivityState implements } } - FilterUtils.setupMenuItems(mActionBar, mMediaSet.getPath(), false); + FilterUtils.setupMenuItems(actionBar, mMediaSet.getPath(), false); MenuItem switchCamera = menu.findItem(R.id.action_camera); if (switchCamera != null) { switchCamera.setVisible(GalleryUtils.isCameraAvailable(activity)); } - mActionBar.setTitle(mTitle); - mActionBar.setSubtitle(mSubtitle); + actionBar.setTitle(mTitle); + actionBar.setSubtitle(mSubtitle); } return true; } @@ -521,8 +525,9 @@ public class AlbumSetPage extends ActivityState implements } private String getSelectedString() { + GalleryActionBar actionBar = mActivity.getGalleryActionBar(); int count = mSelectionManager.getSelectedCount(); - int action = mActionBar.getClusterTypeAction(); + int action = actionBar.getClusterTypeAction(); int string = action == FilterUtils.CLUSTER_BY_ALBUM ? R.plurals.number_of_albums_selected : R.plurals.number_of_groups_selected; @@ -534,7 +539,7 @@ public class AlbumSetPage extends ActivityState implements switch (mode) { case SelectionManager.ENTER_SELECTION_MODE: { - mActionBar.disableClusterMenu(true); + mActivity.getGalleryActionBar().disableClusterMenu(true); mActionMode = mActionModeHandler.startActionMode(); mVibrator.vibrate(100); break; @@ -542,7 +547,7 @@ public class AlbumSetPage extends ActivityState implements case SelectionManager.LEAVE_SELECTION_MODE: { mActionMode.finish(); if (mShowClusterMenu) { - mActionBar.enableClusterMenu(mSelectedAction, this); + mActivity.getGalleryActionBar().enableClusterMenu(mSelectedAction, this); } mRootPane.invalidate(); break; diff --git a/src/com/android/gallery3d/app/Gallery.java b/src/com/android/gallery3d/app/Gallery.java index e3937bcd0..cd93c45ee 100644 --- a/src/com/android/gallery3d/app/Gallery.java +++ b/src/com/android/gallery3d/app/Gallery.java @@ -52,6 +52,7 @@ public final class Gallery extends AbstractGalleryActivity implements OnCancelLi public static final String KEY_MEDIA_TYPES = "mediaTypes"; private static final String TAG = "Gallery"; + private GalleryActionBar mActionBar; private Dialog mVersionCheckDialog; @Override @@ -62,6 +63,7 @@ public final class Gallery extends AbstractGalleryActivity implements OnCancelLi requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.main); + mActionBar = new GalleryActionBar(this); if (savedInstanceState != null) { getStateManager().restoreFromState(savedInstanceState); @@ -273,6 +275,11 @@ public final class Gallery extends AbstractGalleryActivity implements OnCancelLi } } + @Override + public GalleryActionBar getGalleryActionBar() { + return mActionBar; + } + @Override public void onCancel(DialogInterface dialog) { if (dialog == mVersionCheckDialog) { diff --git a/src/com/android/gallery3d/app/GalleryActionBar.java b/src/com/android/gallery3d/app/GalleryActionBar.java index c99cd60d7..35cb8b4cb 100644 --- a/src/com/android/gallery3d/app/GalleryActionBar.java +++ b/src/com/android/gallery3d/app/GalleryActionBar.java @@ -19,7 +19,6 @@ package com.android.gallery3d.app; import android.app.ActionBar; import android.app.Activity; import android.app.AlertDialog; -import android.app.ActionBar.OnMenuVisibilityListener; import android.content.Context; import android.content.DialogInterface; import android.view.LayoutInflater; @@ -38,16 +37,6 @@ import java.util.ArrayList; public class GalleryActionBar implements ActionBar.OnNavigationListener { private static final String TAG = "GalleryActionBar"; - private ClusterRunner mClusterRunner; - private CharSequence[] mTitles; - private ArrayList mActions; - private Context mContext; - private LayoutInflater mInflater; - private GalleryActivity mActivity; - private ActionBar mActionBar; - private int mCurrentIndex; - private ClusterAdapter mAdapter = new ClusterAdapter(); - public interface ClusterRunner { public void doCluster(int id); } @@ -114,23 +103,15 @@ public class GalleryActionBar implements ActionBar.OnNavigationListener { } } - public static String getClusterByTypeString(Context context, int type) { - for (ActionItem item : sClusterItems) { - if (item.action == type) { - return context.getString(item.clusterBy); - } - } - return null; - } - - public static ShareActionProvider initializeShareActionProvider(Menu menu) { - MenuItem item = menu.findItem(R.id.action_share); - ShareActionProvider shareActionProvider = null; - if (item != null) { - shareActionProvider = (ShareActionProvider) item.getActionProvider(); - } - return shareActionProvider; - } + private ClusterRunner mClusterRunner; + private CharSequence[] mTitles; + private ArrayList mActions; + private Context mContext; + private LayoutInflater mInflater; + private GalleryActivity mActivity; + private ActionBar mActionBar; + private int mCurrentIndex; + private ClusterAdapter mAdapter = new ClusterAdapter(); public GalleryActionBar(GalleryActivity activity) { mActionBar = ((Activity) activity).getActionBar(); @@ -140,6 +121,11 @@ public class GalleryActionBar implements ActionBar.OnNavigationListener { mCurrentIndex = 0; } + public static int getHeight(Activity activity) { + ActionBar actionBar = activity.getActionBar(); + return actionBar != null ? actionBar.getHeight() : 0; + } + private void createDialogData() { ArrayList titles = new ArrayList(); mActions = new ArrayList(); @@ -153,10 +139,6 @@ public class GalleryActionBar implements ActionBar.OnNavigationListener { titles.toArray(mTitles); } - public int getHeight() { - return mActionBar != null ? mActionBar.getHeight() : 0; - } - public void setClusterItemEnabled(int id, boolean enabled) { for (ActionItem item : sClusterItems) { if (item.action == id) { @@ -179,26 +161,41 @@ public class GalleryActionBar implements ActionBar.OnNavigationListener { return sClusterItems[mCurrentIndex].action; } - public void enableClusterMenu(int action, ClusterRunner runner) { - if (mActionBar != null) { - // Don't set cluster runner until action bar is ready. - mClusterRunner = null; - mActionBar.setListNavigationCallbacks(mAdapter, this); - mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); - setSelectedAction(action); - mClusterRunner = runner; + public static String getClusterByTypeString(Context context, int type) { + for (ActionItem item : sClusterItems) { + if (item.action == type) { + return context.getString(item.clusterBy); + } } + return null; + } + + public static ShareActionProvider initializeShareActionProvider(Menu menu) { + MenuItem item = menu.findItem(R.id.action_share); + ShareActionProvider shareActionProvider = null; + if (item != null) { + shareActionProvider = (ShareActionProvider) item.getActionProvider(); + } + return shareActionProvider; + } + + public void enableClusterMenu(int action, ClusterRunner runner) { + Log.v(TAG, "showClusterMenu: runner=" + runner); + // Don't set cluster runner until action bar is ready. + mClusterRunner = null; + mActionBar.setListNavigationCallbacks(mAdapter, this); + mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); + setSelectedAction(action); + mClusterRunner = runner; } // The only use case not to hideMenu in this method is to ensure // all elements disappear at the same time when exiting gallery. // hideMenu should always be true in all other cases. public void disableClusterMenu(boolean hideMenu) { - if (mActionBar != null) { - mClusterRunner = null; - if (hideMenu) { - mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); - } + mClusterRunner = null; + if (hideMenu) { + mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); } } @@ -217,7 +214,8 @@ public class GalleryActionBar implements ActionBar.OnNavigationListener { if (mActionBar != null) { int options = (displayHomeAsUp ? ActionBar.DISPLAY_HOME_AS_UP : 0) | (showTitle ? ActionBar.DISPLAY_SHOW_TITLE : 0); - mActionBar.setDisplayOptions(options, + mActionBar.setDisplayOptions( + options, ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE); mActionBar.setHomeButtonEnabled(displayHomeAsUp); } @@ -235,25 +233,7 @@ public class GalleryActionBar implements ActionBar.OnNavigationListener { if (mActionBar != null) mActionBar.setSubtitle(title); } - public void show() { - if (mActionBar != null) mActionBar.show(); - } - - public void hide() { - if (mActionBar != null) mActionBar.hide(); - } - - public void addOnMenuVisibilityListener(OnMenuVisibilityListener listener) { - if (mActionBar != null) mActionBar.addOnMenuVisibilityListener(listener); - } - - public void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener) { - if (mActionBar != null) mActionBar.removeOnMenuVisibilityListener(listener); - } - public boolean setSelectedAction(int type) { - if (mActionBar == null) return false; - for (int i = 0, n = sClusterItems.length; i < n; i++) { ActionItem item = sClusterItems[i]; if (item.action == type) { diff --git a/src/com/android/gallery3d/app/ManageCachePage.java b/src/com/android/gallery3d/app/ManageCachePage.java index 124eb7bf0..4134e3273 100644 --- a/src/com/android/gallery3d/app/ManageCachePage.java +++ b/src/com/android/gallery3d/app/ManageCachePage.java @@ -112,7 +112,7 @@ public class ManageCachePage extends ActivityState implements mEyePosition.resetPosition(); Activity activity = (Activity) mActivity; - int slotViewTop = mActivity.getGalleryActionBar().getHeight(); + int slotViewTop = GalleryActionBar.getHeight(activity); int slotViewBottom = bottom - top; View footer = activity.findViewById(R.id.footer); diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index 502530a42..8040a2fc6 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -16,6 +16,7 @@ package com.android.gallery3d.app; +import android.app.ActionBar; import android.app.ActionBar.OnMenuVisibilityListener; import android.app.Activity; import android.content.ActivityNotFoundException; @@ -96,7 +97,7 @@ public class PhotoPage extends ActivityState private int mCurrentIndex = 0; private Handler mHandler; private boolean mShowBars = true; - private GalleryActionBar mActionBar; + private ActionBar mActionBar; private MyMenuVisibilityListener mMenuVisibilityListener; private boolean mIsMenuVisible; private boolean mIsInteracting; @@ -144,7 +145,8 @@ public class PhotoPage extends ActivityState right - left, bottom - top); } if (mShowDetails) { - mDetailsHelper.layout(left, mActionBar.getHeight(), right, bottom); + mDetailsHelper.layout(left, GalleryActionBar.getHeight((Activity) mActivity), + right, bottom); } } }; @@ -167,7 +169,7 @@ public class PhotoPage extends ActivityState @Override public void onCreate(Bundle data, Bundle restoreState) { - mActionBar = mActivity.getGalleryActionBar(); + mActionBar = ((Activity) mActivity).getActionBar(); mSelectionManager = new SelectionManager(mActivity, false); mMenuExecutor = new MenuExecutor(mActivity, mSelectionManager); @@ -628,7 +630,8 @@ public class PhotoPage extends ActivityState if (mMenuVisibilityListener == null) { mMenuVisibilityListener = new MyMenuVisibilityListener(); } - mActionBar.setDisplayOptions(mSetPathString != null, true); + mActivity.getGalleryActionBar().setDisplayOptions(mSetPathString != null, true); + mActionBar.addOnMenuVisibilityListener(mMenuVisibilityListener); onUserInteraction(); } diff --git a/src/com/android/gallery3d/app/PickerActivity.java b/src/com/android/gallery3d/app/PickerActivity.java index d63e23733..855a0cee7 100644 --- a/src/com/android/gallery3d/app/PickerActivity.java +++ b/src/com/android/gallery3d/app/PickerActivity.java @@ -33,6 +33,8 @@ public class PickerActivity extends AbstractGalleryActivity public static final String KEY_ALBUM_PATH = "album-path"; + private GalleryActionBar mActionBar; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -44,6 +46,7 @@ public class PickerActivity extends AbstractGalleryActivity if (!isDialog) { requestWindowFeature(Window.FEATURE_ACTION_BAR); requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); + mActionBar = new GalleryActionBar(this); } setContentView(R.layout.dialog_picker); @@ -93,4 +96,9 @@ public class PickerActivity extends AbstractGalleryActivity public void onClick(View v) { if (v.getId() == R.id.cancel) finish(); } + + @Override + public GalleryActionBar getGalleryActionBar() { + return mActionBar; + } } -- cgit v1.2.3 From e0dff0321fa4175346019fee3c0909e12fea6093 Mon Sep 17 00:00:00 2001 From: Yuli Huang Date: Thu, 12 Apr 2012 23:45:49 +0800 Subject: Fix SinglePhotoDataAdapter getScreenNail() bug:6322259 Change-Id: I6cf5de88fc07e4b73b028faa3b2a063b4d47fd20 --- src/com/android/gallery3d/app/SinglePhotoDataAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java b/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java index 6ef5040f3..315f5b59c 100644 --- a/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java +++ b/src/com/android/gallery3d/app/SinglePhotoDataAdapter.java @@ -158,7 +158,7 @@ public class SinglePhotoDataAdapter extends TileImageViewAdapter } public ScreenNail getScreenNail(int offset) { - return null; + return (offset == 0) ? getScreenNail() : null; } public void next() { -- cgit v1.2.3 From f35ae59d9e9d19bbfe2705d9b29db164e5082df1 Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Fri, 13 Apr 2012 12:33:29 +0800 Subject: Fix ANR in PhotoPage. This bugs happens because we open too many PhotoPage(s) (and onSingleTapUp is a delayed event). However, each of the PhotoPage need a Thread to run tile decoder. When we close one of the PhotoPage, it will wait the tile decoder to get finished first. However, the title decoder may still waiting in the queue and never got a chance to run. Change-Id: I113d1150729892edb4fe36bc5a1dc131db300476 fix: 6319833 --- src/com/android/gallery3d/app/AlbumPage.java | 1 + src/com/android/gallery3d/app/AlbumSetPage.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java index efffe4075..0fcd7a759 100644 --- a/src/com/android/gallery3d/app/AlbumPage.java +++ b/src/com/android/gallery3d/app/AlbumPage.java @@ -164,6 +164,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster } private void onSingleTapUp(int slotIndex) { + if (!mIsActive) return; MediaItem item = mAlbumDataAdapter.get(slotIndex); if (item == null) { Log.w(TAG, "item not ready yet, ignore the click"); diff --git a/src/com/android/gallery3d/app/AlbumSetPage.java b/src/com/android/gallery3d/app/AlbumSetPage.java index cbd6789b4..60de019de 100644 --- a/src/com/android/gallery3d/app/AlbumSetPage.java +++ b/src/com/android/gallery3d/app/AlbumSetPage.java @@ -172,6 +172,7 @@ public class AlbumSetPage extends ActivityState implements } public void onSingleTapUp(int slotIndex) { + if (!mIsActive) return; MediaSet targetSet = mAlbumSetDataAdapter.getMediaSet(slotIndex); if (targetSet == null) return; // Content is dirty, we shall reload soon -- cgit v1.2.3 From 955e71d986fd0472fef899fd5ab56e1b86a0f325 Mon Sep 17 00:00:00 2001 From: Wu-cheng Li Date: Mon, 30 Apr 2012 23:49:17 +0800 Subject: Fix crash when select all is pressed. bug:6411186 Change-Id: Iaa71a320bc4d6d70aade41d5144f75ba6db36e6d --- src/com/android/gallery3d/ui/MenuExecutor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/com/android/gallery3d/ui/MenuExecutor.java b/src/com/android/gallery3d/ui/MenuExecutor.java index a0f344982..a052c500d 100644 --- a/src/com/android/gallery3d/ui/MenuExecutor.java +++ b/src/com/android/gallery3d/ui/MenuExecutor.java @@ -185,12 +185,14 @@ public class MenuExecutor { } else { mSelectionManager.selectAll(); } + return; case R.id.action_crop: { Path path = getSingleSelectedPath(); String mimeType = getMimeType(manager.getMediaType(path)); Intent intent = new Intent(CropImage.ACTION_CROP) .setDataAndType(manager.getContentUri(path), mimeType); ((Activity) mActivity).startActivity(intent); + return; } case R.id.action_setas: { Path path = getSingleSelectedPath(); @@ -203,6 +205,7 @@ public class MenuExecutor { Activity activity = (Activity) mActivity; activity.startActivity(Intent.createChooser( intent, activity.getString(R.string.set_as))); + return; } case R.id.action_delete: title = R.string.delete; @@ -368,4 +371,3 @@ public class MenuExecutor { } } } - -- cgit v1.2.3 From 85f22697b5b8d00a2c9210743d9b54120a4f5e9d Mon Sep 17 00:00:00 2001 From: Chih-Chung Chang Date: Tue, 1 May 2012 02:25:09 +0800 Subject: Fix black screen when viewing Gmail image file attachment. Bug: 6415848 Change-Id: Iec369866be6b5546fbd8cb77eb95a29f92e00b84 --- src/com/android/gallery3d/ui/PositionController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/com/android/gallery3d/ui/PositionController.java b/src/com/android/gallery3d/ui/PositionController.java index ac0d191f4..03fe65b1c 100644 --- a/src/com/android/gallery3d/ui/PositionController.java +++ b/src/com/android/gallery3d/ui/PositionController.java @@ -1012,7 +1012,8 @@ class PositionController { float hFactor = 1.0f; int viewW, viewH; - if (!mFilmMode && mConstrained && b == mBoxes.get(0)) { + if (!mFilmMode && mConstrained && !mConstrainedFrame.isEmpty() + && b == mBoxes.get(0)) { viewW = mConstrainedFrame.width(); viewH = mConstrainedFrame.height(); } else { -- cgit v1.2.3 From 48961c4469c01816fad41d057fca7a02f9b1ae71 Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Wed, 16 May 2012 10:54:14 -0700 Subject: Fix a dead lock while we freeze the screen. bug: 6504696 Change-Id: If960967142bb0df773ce075bf76f5726c37e1d27 --- src/com/android/gallery3d/app/PhotoPage.java | 1 - src/com/android/gallery3d/ui/GLRoot.java | 1 + src/com/android/gallery3d/ui/GLRootView.java | 40 +++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index a46c777fa..2022a6e2d 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -56,7 +56,6 @@ import com.android.gallery3d.ui.GLView; import com.android.gallery3d.ui.ImportCompleteListener; import com.android.gallery3d.ui.MenuExecutor; import com.android.gallery3d.ui.PhotoView; -import com.android.gallery3d.ui.ScreenNail; import com.android.gallery3d.ui.SelectionManager; import com.android.gallery3d.ui.SynchronizedHandler; import com.android.gallery3d.util.GalleryUtils; diff --git a/src/com/android/gallery3d/ui/GLRoot.java b/src/com/android/gallery3d/ui/GLRoot.java index 5ed323a88..f4b7572a7 100644 --- a/src/com/android/gallery3d/ui/GLRoot.java +++ b/src/com/android/gallery3d/ui/GLRoot.java @@ -17,6 +17,7 @@ package com.android.gallery3d.ui; import android.graphics.Matrix; + import com.android.gallery3d.anim.CanvasAnimation; public interface GLRoot { diff --git a/src/com/android/gallery3d/ui/GLRootView.java b/src/com/android/gallery3d/ui/GLRootView.java index 1f25b9085..73e982509 100644 --- a/src/com/android/gallery3d/ui/GLRootView.java +++ b/src/com/android/gallery3d/ui/GLRootView.java @@ -19,12 +19,12 @@ package com.android.gallery3d.ui; import android.content.Context; import android.graphics.Matrix; import android.graphics.PixelFormat; -import android.graphics.Rect; import android.opengl.GLSurfaceView; import android.os.Process; import android.os.SystemClock; import android.util.AttributeSet; import android.view.MotionEvent; +import android.view.SurfaceHolder; import com.android.gallery3d.anim.CanvasAnimation; import com.android.gallery3d.common.Utils; @@ -467,6 +467,7 @@ public class GLRootView extends GLSurfaceView @Override public void onPause() { + unfreeze(); super.onPause(); if (DEBUG_PROFILE) { Log.d(TAG, "Stop profiling"); @@ -510,4 +511,41 @@ public class GLRootView extends GLSurfaceView mFreezeCondition.signalAll(); mRenderLock.unlock(); } + + // We need to unfreeze in the following methods and in onPause(). + // These methods will wait on GLThread. If we have freezed the GLRootView, + // the GLThread will wait on main thread to call unfreeze and cause dead + // lock. + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { + unfreeze(); + super.surfaceChanged(holder, format, w, h); + } + + @Override + public void surfaceCreated(SurfaceHolder holder) { + unfreeze(); + super.surfaceCreated(holder); + } + + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + unfreeze(); + super.surfaceDestroyed(holder); + } + + @Override + protected void onDetachedFromWindow() { + unfreeze(); + super.onDetachedFromWindow(); + } + + @Override + protected void finalize() throws Throwable { + try { + unfreeze(); + } finally { + super.finalize(); + } + } } -- cgit v1.2.3 From 8dc6061a9019e4e091d8e0d10f05d96d2d0db14d Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Thu, 17 May 2012 13:04:35 -0700 Subject: Fix a NPE found by Moneky. AlbumLabelMaker.mBitmapPool could be null if the setLabelWidth() has never been called or called with width as 0. bug:6510386 Change-Id: Idaaa0a1a7239271ba3ae3217e65029b382464c10 --- src/com/android/gallery3d/ui/AlbumLabelMaker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/android/gallery3d/ui/AlbumLabelMaker.java b/src/com/android/gallery3d/ui/AlbumLabelMaker.java index f837092b8..93b37ce13 100644 --- a/src/com/android/gallery3d/ui/AlbumLabelMaker.java +++ b/src/com/android/gallery3d/ui/AlbumLabelMaker.java @@ -211,6 +211,6 @@ public class AlbumLabelMaker { } public void clearRecycledLabels() { - mBitmapPool.clear(); + if (mBitmapPool != null) mBitmapPool.clear(); } } -- cgit v1.2.3 From d0eabeec017489d907b0c7a70d8d0859414c9350 Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Mon, 21 May 2012 16:52:25 -0700 Subject: Limit the size of a ScreenNail. bug:6528366 This bug was happened because we are trying to make a texture beyond the max size allowed in GL. Here is what we do in this CL: 1. Limit the size of a screen nail 2. Print warning message, if we try to allocate a texture beyond the size 3. Don't show fall-back animation if the image is not loaded yet. Change-Id: I004b1138efd0eef7ba11aa89556f67743ca46745 --- src/com/android/gallery3d/app/PhotoDataAdapter.java | 6 +++--- src/com/android/gallery3d/ui/BasicTexture.java | 6 ++++++ src/com/android/gallery3d/ui/BitmapScreenNail.java | 21 +++++++++++++++------ src/com/android/gallery3d/ui/GLRootView.java | 2 +- src/com/android/gallery3d/ui/PhotoView.java | 5 ++++- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/com/android/gallery3d/app/PhotoDataAdapter.java b/src/com/android/gallery3d/app/PhotoDataAdapter.java index 6ba1ff69b..29154a082 100644 --- a/src/com/android/gallery3d/app/PhotoDataAdapter.java +++ b/src/com/android/gallery3d/app/PhotoDataAdapter.java @@ -415,7 +415,7 @@ public class PhotoDataAdapter implements PhotoPage.Model { // Create a default ScreenNail if the real one is not available yet. if (entry.screenNail == null) { - entry.screenNail = newDefaultScreenNail(item); + entry.screenNail = newPlaceholderScreenNail(item); if (offset == 0) updateTileProvider(entry); } @@ -632,7 +632,7 @@ public class PhotoDataAdapter implements PhotoPage.Model { // If this is a temporary item, don't try to get its bitmap because // it won't be available. We will get its bitmap after a data reload. if (isTemporaryItem(mItem)) { - return newDefaultScreenNail(mItem); + return newPlaceholderScreenNail(mItem); } Bitmap bitmap = mItem.requestImage(MediaItem.TYPE_THUMBNAIL).run(jc); @@ -687,7 +687,7 @@ public class PhotoDataAdapter implements PhotoPage.Model { // Create a default ScreenNail when a ScreenNail is needed, but we don't yet // have one available (because the image data is still being saved, or the // Bitmap is still being loaded. - private ScreenNail newDefaultScreenNail(MediaItem item) { + private ScreenNail newPlaceholderScreenNail(MediaItem item) { int width = item.getWidth(); int height = item.getHeight(); return new BitmapScreenNail(width, height); diff --git a/src/com/android/gallery3d/ui/BasicTexture.java b/src/com/android/gallery3d/ui/BasicTexture.java index 6a9a17d92..68a5b7d32 100644 --- a/src/com/android/gallery3d/ui/BasicTexture.java +++ b/src/com/android/gallery3d/ui/BasicTexture.java @@ -33,6 +33,8 @@ abstract class BasicTexture implements Texture { protected static final int STATE_LOADED = 1; protected static final int STATE_ERROR = -1; + private static final int MAX_TEXTURE_SIZE = 2048; + protected int mId; protected int mState; @@ -75,6 +77,10 @@ abstract class BasicTexture implements Texture { mHeight = height; mTextureWidth = Utils.nextPowerOf2(width); mTextureHeight = Utils.nextPowerOf2(height); + if (mTextureWidth > MAX_TEXTURE_SIZE || mTextureHeight > MAX_TEXTURE_SIZE) { + Log.w(TAG, String.format("texture is too large: %d x %d", + mTextureWidth, mTextureHeight), new Exception()); + } } public int getId() { diff --git a/src/com/android/gallery3d/ui/BitmapScreenNail.java b/src/com/android/gallery3d/ui/BitmapScreenNail.java index 14d3f1919..5c917570d 100644 --- a/src/com/android/gallery3d/ui/BitmapScreenNail.java +++ b/src/com/android/gallery3d/ui/BitmapScreenNail.java @@ -18,7 +18,6 @@ package com.android.gallery3d.ui; import android.graphics.Bitmap; import android.graphics.RectF; -import android.util.Log; import com.android.gallery3d.common.Utils; import com.android.gallery3d.data.MediaItem; @@ -35,6 +34,9 @@ public class BitmapScreenNail implements ScreenNail { private static final int PLACEHOLDER_COLOR = 0xFF222222; // The duration of the fading animation in milliseconds private static final int DURATION = 180; + + private static final int MAX_SIDE = 640; + // These are special values for mAnimationStartTime private static final long ANIMATION_NOT_NEEDED = -1; private static final long ANIMATION_NEEDED = -2; @@ -44,7 +46,6 @@ public class BitmapScreenNail implements ScreenNail { private int mHeight; private Bitmap mBitmap; private BitmapTexture mTexture; - private FadeInTexture mFadeInTexture; private long mAnimationStartTime = ANIMATION_NOT_NEEDED; public BitmapScreenNail(Bitmap bitmap) { @@ -56,12 +57,17 @@ public class BitmapScreenNail implements ScreenNail { } public BitmapScreenNail(int width, int height) { + setSize(width, height); + } + + private void setSize(int width, int height) { if (width == 0 || height == 0) { width = 640; height = 480; } - mWidth = width; - mHeight = height; + float scale = Math.min(1, (float) MAX_SIDE / Math.max(width, height)); + mWidth = Math.round(scale * width); + mHeight = Math.round(scale * height); } // Combines the two ScreenNails. @@ -101,8 +107,7 @@ public class BitmapScreenNail implements ScreenNail { public void updatePlaceholderSize(int width, int height) { if (mBitmap != null) return; if (width == 0 || height == 0) return; - mWidth = width; - mHeight = height; + setSize(width, height); } @Override @@ -189,4 +194,8 @@ public class BitmapScreenNail implements ScreenNail { float r = (float)(now() - mAnimationStartTime) / DURATION; return Utils.clamp(1.0f - r, 0.0f, 1.0f); } + + public boolean isShowingPlaceholder() { + return (mBitmap == null) || isAnimating(); + } } diff --git a/src/com/android/gallery3d/ui/GLRootView.java b/src/com/android/gallery3d/ui/GLRootView.java index 987e9a2ae..8783b66bb 100644 --- a/src/com/android/gallery3d/ui/GLRootView.java +++ b/src/com/android/gallery3d/ui/GLRootView.java @@ -118,7 +118,7 @@ public class GLRootView extends GLSurfaceView getHolder().setFormat(PixelFormat.RGB_565); // Uncomment this to enable gl error check. - //setDebugFlags(DEBUG_CHECK_GL_ERROR); + // setDebugFlags(DEBUG_CHECK_GL_ERROR); } @Override diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java index fd08e0eb3..654fcd586 100644 --- a/src/com/android/gallery3d/ui/PhotoView.java +++ b/src/com/android/gallery3d/ui/PhotoView.java @@ -1334,7 +1334,10 @@ public class PhotoView extends GLView { MediaItem item = mModel.getMediaItem(i); if (item == null) continue; ScreenNail sc = mModel.getScreenNail(i); - if (sc == null) continue; + if (!(sc instanceof BitmapScreenNail) + || ((BitmapScreenNail) sc).isShowingPlaceholder()) continue; + + // Now, sc is BitmapScreenNail and is not showing placeholder Rect rect = new Rect(getPhotoRect(i)); if (!Rect.intersects(fullRect, rect)) continue; rect.offset(location.left, location.top); -- cgit v1.2.3 From 1430b63b486564829da060813c005bb601994782 Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Tue, 19 Jun 2012 14:35:06 +0800 Subject: Make SystemUI always consists with the contrller overlay. Change-Id: I81f2a71fd38fc2588a9acb97b9d333978ffb5e48 fix: 6679875 --- src/com/android/gallery3d/app/MoviePlayer.java | 11 +---------- src/com/android/gallery3d/app/TimeBar.java | 1 + 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/com/android/gallery3d/app/MoviePlayer.java b/src/com/android/gallery3d/app/MoviePlayer.java index 13a77f472..11b40bdf8 100644 --- a/src/com/android/gallery3d/app/MoviePlayer.java +++ b/src/com/android/gallery3d/app/MoviePlayer.java @@ -86,9 +86,6 @@ public class MoviePlayer implements // If the time bar is visible. private boolean mShowing; - // Control when system UI can be shown - private boolean mAllowShowingSystemUI; - private final Runnable mPlayingChecker = new Runnable() { @Override public void run() { @@ -162,7 +159,6 @@ public class MoviePlayer implements mLastSystemUiVis = visibility; if ((diff & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 && (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) { - mAllowShowingSystemUI = true; mController.show(); // We need to set the background to clear ghosting images @@ -371,12 +367,7 @@ public class MoviePlayer implements public void onShown() { mShowing = true; setProgress(); - - // System UI is invisible by default until the flag is set by user interaction - // See VideoView's onSystemUiVisibilityChange listener for details. - if (mAllowShowingSystemUI) { - showSystemUi(true); - } + showSystemUi(true); } @Override diff --git a/src/com/android/gallery3d/app/TimeBar.java b/src/com/android/gallery3d/app/TimeBar.java index 1f5bfd96b..1f3630622 100644 --- a/src/com/android/gallery3d/app/TimeBar.java +++ b/src/com/android/gallery3d/app/TimeBar.java @@ -255,6 +255,7 @@ public class TimeBar extends View { return true; } break; + case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (scrubbing) { listener.onScrubbingEnd(getScrubberTime()); -- cgit v1.2.3