use of com.android.gallery3d.util.ThreadPool.JobContext in project android_packages_apps_Gallery2 by LineageOS.
the class ActionModeHandler method updateSupportedOperation.
public void updateSupportedOperation() {
// Interrupt previous unfinished task, mMenuTask is only accessed in main thread
if (mMenuTask != null)
mMenuTask.cancel();
updateSelectionMenu();
// Disable share actions until share intent is in good shape
if (mSharePanoramaMenuItem != null)
mSharePanoramaMenuItem.setEnabled(false);
if (mShareMenuItem != null)
mShareMenuItem.setEnabled(false);
isThreadComplete = false;
// Generate sharing intent and update supported operations in the background
// The task can take a long time and be canceled in the mean time.
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) {
mMainHandler.post(new Runnable() {
@Override
public void run() {
mMenuTask = null;
if (jc.isCancelled())
return;
// Disable all the operations when no item is selected
MenuExecutor.updateMenuOperation(mMenu, 0);
}
});
return null;
}
final int operation = computeMenuOptions(selected);
if (jc.isCancelled()) {
return null;
}
// 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) : null;
// Pass2: Deal with expanded media object list for sharing operation.
final Intent share_panorama_intent = canSharePanoramas ? computePanoramaSharingIntent(jc, MAX_SELECTED_ITEMS_FOR_PANORAMA_SHARE_INTENT) : new Intent();
final Intent share_intent = canShare ? computeSharingIntent(jc, MAX_SELECTED_ITEMS_FOR_SHARE_INTENT) : new Intent();
if (canSharePanoramas) {
supportCallback.waitForPanoramaSupport();
}
if (jc.isCancelled()) {
return null;
}
mMainHandler.post(new Runnable() {
@Override
public void run() {
mMenuTask = null;
if (jc.isCancelled())
return;
MenuExecutor.updateMenuOperation(mMenu, operation);
MenuExecutor.updateMenuForPanorama(mMenu, canSharePanoramas && supportCallback.mAllPanorama360, canSharePanoramas && supportCallback.mHasPanorama360);
if (mSharePanoramaMenuItem != null) {
mSharePanoramaMenuItem.setEnabled(true);
if (canSharePanoramas && supportCallback.mAllPanorama360) {
mShareMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
mShareMenuItem.setTitle(mActivity.getResources().getString(R.string.share_as_photo));
} else {
mSharePanoramaMenuItem.setVisible(false);
mShareMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
mShareMenuItem.setTitle(mActivity.getResources().getString(R.string.share));
}
mSharePanoramaIntent = share_panorama_intent;
}
if (mShareMenuItem != null) {
showShareMaxDialogIfNeed(canShare);
mShareMenuItem.setEnabled(canShare);
isThreadComplete = true;
mShareIntent = share_intent;
}
}
});
return null;
}
});
}
Aggregations