summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2016-03-29 22:22:40 -0700
committerGerrit - the friendly Code Review server <code-review@localhost>2016-03-29 22:22:40 -0700
commitced8cf330e45b3731722d60ce415c35010c92590 (patch)
treefa8525e2dc94d23719df3658307b24abb272626c
parenteeac78d344acc38d4e2d89a2a89b077161f0bc68 (diff)
parent8f3aa5f6cb9f6c2d829de6224e9ce50edfe0c23e (diff)
downloadandroid_packages_apps_Gallery2-ced8cf330e45b3731722d60ce415c35010c92590.tar.gz
android_packages_apps_Gallery2-ced8cf330e45b3731722d60ce415c35010c92590.tar.bz2
android_packages_apps_Gallery2-ced8cf330e45b3731722d60ce415c35010c92590.zip
Merge "Gallery2: enhance performance of update supported operation." into android_ui.lnx.1.2-dev
-rw-r--r--res/menu/operation.xml2
-rw-r--r--src/com/android/gallery3d/ui/ActionModeHandler.java83
2 files changed, 61 insertions, 24 deletions
diff --git a/res/menu/operation.xml b/res/menu/operation.xml
index 2403f09fc..2429c48b9 100644
--- a/res/menu/operation.xml
+++ b/res/menu/operation.xml
@@ -33,7 +33,7 @@
android:icon="@drawable/multiselect_share"
android:title="@string/share"
android:visible="false"
- android:showAsAction="never">
+ android:showAsAction="ifRoom">
</item>
<item android:id="@+id/action_delete"
android:icon="@drawable/multiselect_delete"
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();