diff options
author | Chao Zhang <chaoz@codeaurora.org> | 2016-03-25 16:52:41 +0800 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2016-03-27 22:51:28 -0700 |
commit | 8f3aa5f6cb9f6c2d829de6224e9ce50edfe0c23e (patch) | |
tree | 8c2f3b82a2d4492c388f77f742b1243a68ef1d0f /src/com/android/gallery3d/ui | |
parent | 7f8e26df135b81971e409ce36c4aacce7b6cab58 (diff) | |
download | android_packages_apps_Gallery2-8f3aa5f6cb9f6c2d829de6224e9ce50edfe0c23e.tar.gz android_packages_apps_Gallery2-8f3aa5f6cb9f6c2d829de6224e9ce50edfe0c23e.tar.bz2 android_packages_apps_Gallery2-8f3aa5f6cb9f6c2d829de6224e9ce50edfe0c23e.zip |
Gallery2: enhance performance of update supported operation.
getSelectedMediaObjects() in updateSupportedOperation() is low performance
if there are lots of photos, so menu options will not in correct state
immediately, then crash occurred if click menu option.
Use mSelectionManager.getSelectedCount() before getSelectedMediaObjects()
to disable menu options and share items if need.
Change-Id: I937a219ed294151c464f1d7b6ba2e526eef00c82
CRs-Fixed: 985315
Diffstat (limited to 'src/com/android/gallery3d/ui')
-rw-r--r-- | src/com/android/gallery3d/ui/ActionModeHandler.java | 83 |
1 files changed, 60 insertions, 23 deletions
diff --git a/src/com/android/gallery3d/ui/ActionModeHandler.java b/src/com/android/gallery3d/ui/ActionModeHandler.java index 301d2e4e4..4024fc9d7 100644 --- a/src/com/android/gallery3d/ui/ActionModeHandler.java +++ b/src/com/android/gallery3d/ui/ActionModeHandler.java @@ -316,17 +316,23 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi } break; default: - operation &= SUPPORT_MULTIPLE_MASK; + operation = computeMenuOptionsMultiple(operation, selected.size()); } + return operation; + } + private int computeMenuOptionsMultiple(int operationBefore, int selectedSize) { + int operation = operationBefore; + if (selectedSize > 1) { + operation &= SUPPORT_MULTIPLE_MASK; + } return operation; } private boolean computeCanShare(ArrayList<MediaObject> selected, int max) { int numSelected = selected.size(); - if (numSelected > max) { - return false; - } + boolean ret = computeCanShare(numSelected, max); + if (!ret) return false; numSelected = 0; for (MediaObject mediaObject : selected) { @@ -335,13 +341,16 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi } else { numSelected = numSelected + 1; } - if (numSelected > max) { - return false; - } + ret = computeCanShare(numSelected, max); + if (!ret) return false; } return true; } + private boolean computeCanShare(int size, int max) { + return size <= max; + } + @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN) private void setNfcBeamPushUris(Uri[] uris) { if (mNfcAdapter != null && ApiHelper.HAS_SET_BEAM_PUSH_URIS) { @@ -447,6 +456,28 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi mMenuTask = mActivity.getThreadPool().submit(new Job<Void>() { @Override public Void run(final JobContext jc) { + // use selected count to disable menu options and share items if need + // to enhance performance. + int multipleOperation = SUPPORT_MULTIPLE_MASK; + int count = mSelectionManager.getSelectedCount(); + final int operationPre = computeMenuOptionsMultiple(multipleOperation, count); + final boolean canSharePanoramasPre = computeCanShare(count, + MAX_SELECTED_ITEMS_FOR_PANORAMA_SHARE_INTENT); + final boolean canSharePre = computeCanShare(count, + MAX_SELECTED_ITEMS_FOR_SHARE_INTENT); + + mMainHandler.post(new Runnable() { + @Override + public void run() { + if (jc.isCancelled()) return; + MenuExecutor.updateMenuOperation(mMenu, operationPre); + if (mShareMenuItem != null && !canSharePre) { + mShareMenuItem.setEnabled(false); + showShareMaxDialogIfNeed(false); + } + } + }); + // Pass1: Deal with unexpanded media object list for menu operation. ArrayList<MediaObject> selected = getSelectedMediaObjects(jc); if (selected == null) { @@ -465,10 +496,12 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi if (jc.isCancelled()) { return null; } - final boolean canSharePanoramas = computeCanShare(selected, - MAX_SELECTED_ITEMS_FOR_PANORAMA_SHARE_INTENT); - final boolean canShare = computeCanShare(selected, - MAX_SELECTED_ITEMS_FOR_SHARE_INTENT); + + // use selected items to compute menu options and share items again. + final boolean canShare = canSharePre + && computeCanShare(selected, MAX_SELECTED_ITEMS_FOR_SHARE_INTENT); + final boolean canSharePanoramas = canSharePanoramasPre + && computeCanShare(selected, MAX_SELECTED_ITEMS_FOR_PANORAMA_SHARE_INTENT); final GetAllPanoramaSupports supportCallback = canSharePanoramas ? new GetAllPanoramaSupports(selected, jc) @@ -512,18 +545,7 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi mSharePanoramaActionProvider.setShareIntent(share_panorama_intent); } if (mShareMenuItem != null) { - if (!canShare && !mShareMaxDialog) { - AlertDialog.Builder shareMaxDialog = new AlertDialog.Builder(mActivity); - shareMaxDialog - .setMessage(R.string.cannot_share_items) - .setPositiveButton(R.string.ok, null) - .create(); - shareMaxDialog.show(); - mShareMaxDialog = true; - } - if (canShare && mShareMaxDialog) { - mShareMaxDialog = false; - } + showShareMaxDialogIfNeed(canShare); mShareMenuItem.setEnabled(canShare); shareIntent = share_intent; @@ -535,6 +557,21 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi }); } + private void showShareMaxDialogIfNeed(boolean canShare) { + if (!canShare && !mShareMaxDialog) { + AlertDialog.Builder shareMaxDialog = new AlertDialog.Builder(mActivity); + shareMaxDialog + .setMessage(R.string.cannot_share_items) + .setPositiveButton(R.string.ok, null) + .create(); + shareMaxDialog.show(); + mShareMaxDialog = true; + } + if (canShare && mShareMaxDialog) { + mShareMaxDialog = false; + } + } + public void pause() { if (mMenuTask != null) { mMenuTask.cancel(); |