blob: 28fd71e1033b59726c224b378cabafedbeab7f80 [file] [log] [blame]
Owen Linf9a0a432011-08-17 22:07:43 +08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.gallery3d.ui;
18
Ray Chen0c1f2c82011-10-05 14:32:58 +080019import android.app.Activity;
Ray Chen67098d12012-04-05 17:25:43 +080020import android.app.AlertDialog;
Ray Chen0c1f2c82011-10-05 14:32:58 +080021import android.app.ProgressDialog;
22import android.content.Context;
Ray Chen67098d12012-04-05 17:25:43 +080023import android.content.DialogInterface;
Owen Lind759b7c2012-05-16 15:32:02 -070024import android.content.DialogInterface.OnCancelListener;
Ray Chen67098d12012-04-05 17:25:43 +080025import android.content.DialogInterface.OnClickListener;
Ray Chen0c1f2c82011-10-05 14:32:58 +080026import android.content.Intent;
27import android.os.Handler;
28import android.os.Message;
John Reck2abaaf72012-12-12 13:43:43 -080029import android.view.Menu;
30import android.view.MenuItem;
Ray Chen0c1f2c82011-10-05 14:32:58 +080031
Owen Linf9a0a432011-08-17 22:07:43 +080032import com.android.gallery3d.R;
Owen Linb21b8e52012-08-24 12:25:57 +080033import com.android.gallery3d.app.AbstractGalleryActivity;
Owen Linf9a0a432011-08-17 22:07:43 +080034import com.android.gallery3d.common.Utils;
35import com.android.gallery3d.data.DataManager;
36import com.android.gallery3d.data.MediaItem;
37import com.android.gallery3d.data.MediaObject;
38import com.android.gallery3d.data.Path;
Ruben Brunk5aa454b2012-10-25 15:53:42 -070039import com.android.gallery3d.filtershow.FilterShowActivity;
Owen Linf9a0a432011-08-17 22:07:43 +080040import com.android.gallery3d.util.Future;
41import com.android.gallery3d.util.GalleryUtils;
42import com.android.gallery3d.util.ThreadPool.Job;
43import com.android.gallery3d.util.ThreadPool.JobContext;
44
Owen Linf9a0a432011-08-17 22:07:43 +080045import java.util.ArrayList;
46
47public class MenuExecutor {
48 @SuppressWarnings("unused")
49 private static final String TAG = "MenuExecutor";
50
51 private static final int MSG_TASK_COMPLETE = 1;
52 private static final int MSG_TASK_UPDATE = 2;
Bobby Georgescuba50b942012-08-08 00:09:50 -070053 private static final int MSG_TASK_START = 3;
54 private static final int MSG_DO_SHARE = 4;
Owen Linf9a0a432011-08-17 22:07:43 +080055
56 public static final int EXECUTION_RESULT_SUCCESS = 1;
57 public static final int EXECUTION_RESULT_FAIL = 2;
58 public static final int EXECUTION_RESULT_CANCEL = 3;
59
60 private ProgressDialog mDialog;
61 private Future<?> mTask;
Chih-Chung Chang6b891c62012-06-07 20:09:13 +080062 // wait the operation to finish when we want to stop it.
63 private boolean mWaitOnStop;
Bobby Georgescua2d0d342012-12-03 13:56:00 -080064 private boolean mPaused;
Owen Linf9a0a432011-08-17 22:07:43 +080065
Owen Linb21b8e52012-08-24 12:25:57 +080066 private final AbstractGalleryActivity mActivity;
Owen Linf9a0a432011-08-17 22:07:43 +080067 private final SelectionManager mSelectionManager;
68 private final Handler mHandler;
69
Chih-Chung Chang6b891c62012-06-07 20:09:13 +080070 private static ProgressDialog createProgressDialog(
Owen Linf9a0a432011-08-17 22:07:43 +080071 Context context, int titleId, int progressMax) {
72 ProgressDialog dialog = new ProgressDialog(context);
73 dialog.setTitle(titleId);
74 dialog.setMax(progressMax);
75 dialog.setCancelable(false);
76 dialog.setIndeterminate(false);
77 if (progressMax > 1) {
78 dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
79 }
Owen Linf9a0a432011-08-17 22:07:43 +080080 return dialog;
81 }
82
83 public interface ProgressListener {
Owen Lind759b7c2012-05-16 15:32:02 -070084 public void onConfirmDialogShown();
85 public void onConfirmDialogDismissed(boolean confirmed);
Bobby Georgescuba50b942012-08-08 00:09:50 -070086 public void onProgressStart();
Owen Linf9a0a432011-08-17 22:07:43 +080087 public void onProgressUpdate(int index);
88 public void onProgressComplete(int result);
89 }
90
91 public MenuExecutor(
Owen Linb21b8e52012-08-24 12:25:57 +080092 AbstractGalleryActivity activity, SelectionManager selectionManager) {
Owen Linf9a0a432011-08-17 22:07:43 +080093 mActivity = Utils.checkNotNull(activity);
94 mSelectionManager = Utils.checkNotNull(selectionManager);
95 mHandler = new SynchronizedHandler(mActivity.getGLRoot()) {
96 @Override
97 public void handleMessage(Message message) {
98 switch (message.what) {
Bobby Georgescuba50b942012-08-08 00:09:50 -070099 case MSG_TASK_START: {
100 if (message.obj != null) {
101 ProgressListener listener = (ProgressListener) message.obj;
102 listener.onProgressStart();
103 }
104 break;
105 }
Owen Linf9a0a432011-08-17 22:07:43 +0800106 case MSG_TASK_COMPLETE: {
Ray Chenb2b45182011-08-31 16:37:04 +0800107 stopTaskAndDismissDialog();
Owen Linf9a0a432011-08-17 22:07:43 +0800108 if (message.obj != null) {
109 ProgressListener listener = (ProgressListener) message.obj;
110 listener.onProgressComplete(message.arg1);
111 }
112 mSelectionManager.leaveSelectionMode();
113 break;
114 }
115 case MSG_TASK_UPDATE: {
Bobby Georgescua2d0d342012-12-03 13:56:00 -0800116 if (mDialog != null && !mPaused) mDialog.setProgress(message.arg1);
Owen Linf9a0a432011-08-17 22:07:43 +0800117 if (message.obj != null) {
118 ProgressListener listener = (ProgressListener) message.obj;
119 listener.onProgressUpdate(message.arg1);
120 }
121 break;
122 }
123 case MSG_DO_SHARE: {
124 ((Activity) mActivity).startActivity((Intent) message.obj);
125 break;
126 }
127 }
128 }
129 };
130 }
131
Ray Chenb2b45182011-08-31 16:37:04 +0800132 private void stopTaskAndDismissDialog() {
Owen Linf9a0a432011-08-17 22:07:43 +0800133 if (mTask != null) {
Chih-Chung Chang6b891c62012-06-07 20:09:13 +0800134 if (!mWaitOnStop) mTask.cancel();
Owen Linf9a0a432011-08-17 22:07:43 +0800135 mTask.waitDone();
Bobby Georgescua2d0d342012-12-03 13:56:00 -0800136 if (mDialog != null && mDialog.isShowing()) mDialog.dismiss();
Owen Linf9a0a432011-08-17 22:07:43 +0800137 mDialog = null;
138 mTask = null;
139 }
140 }
141
Bobby Georgescua2d0d342012-12-03 13:56:00 -0800142 public void resume() {
143 mPaused = false;
144 if (mDialog != null) mDialog.show();
145 }
146
Ray Chenb2b45182011-08-31 16:37:04 +0800147 public void pause() {
Bobby Georgescua2d0d342012-12-03 13:56:00 -0800148 mPaused = true;
149 if (mDialog != null && mDialog.isShowing()) mDialog.hide();
150 }
151
152 public void destroy() {
Ray Chenb2b45182011-08-31 16:37:04 +0800153 stopTaskAndDismissDialog();
154 }
155
Owen Linf9a0a432011-08-17 22:07:43 +0800156 private void onProgressUpdate(int index, ProgressListener listener) {
157 mHandler.sendMessage(
158 mHandler.obtainMessage(MSG_TASK_UPDATE, index, 0, listener));
159 }
160
Bobby Georgescuba50b942012-08-08 00:09:50 -0700161 private void onProgressStart(ProgressListener listener) {
162 mHandler.sendMessage(mHandler.obtainMessage(MSG_TASK_START, listener));
163 }
164
Owen Linf9a0a432011-08-17 22:07:43 +0800165 private void onProgressComplete(int result, ProgressListener listener) {
166 mHandler.sendMessage(mHandler.obtainMessage(MSG_TASK_COMPLETE, result, 0, listener));
167 }
168
Owen Linb21b8e52012-08-24 12:25:57 +0800169 public static void updateMenuOperation(Menu menu, int supported) {
Owen Linf9a0a432011-08-17 22:07:43 +0800170 boolean supportDelete = (supported & MediaObject.SUPPORT_DELETE) != 0;
171 boolean supportRotate = (supported & MediaObject.SUPPORT_ROTATE) != 0;
172 boolean supportCrop = (supported & MediaObject.SUPPORT_CROP) != 0;
Teng-Hui Zhu5e926682012-09-26 14:20:46 -0700173 boolean supportTrim = (supported & MediaObject.SUPPORT_TRIM) != 0;
Teng-Hui Zhu648b3392012-11-13 10:39:26 -0800174 boolean supportMute = (supported & MediaObject.SUPPORT_MUTE) != 0;
Owen Linf9a0a432011-08-17 22:07:43 +0800175 boolean supportShare = (supported & MediaObject.SUPPORT_SHARE) != 0;
176 boolean supportSetAs = (supported & MediaObject.SUPPORT_SETAS) != 0;
177 boolean supportShowOnMap = (supported & MediaObject.SUPPORT_SHOW_ON_MAP) != 0;
178 boolean supportCache = (supported & MediaObject.SUPPORT_CACHE) != 0;
179 boolean supportEdit = (supported & MediaObject.SUPPORT_EDIT) != 0;
180 boolean supportInfo = (supported & MediaObject.SUPPORT_INFO) != 0;
Owen Linf9a0a432011-08-17 22:07:43 +0800181
Owen Linb21b8e52012-08-24 12:25:57 +0800182 setMenuItemVisible(menu, R.id.action_delete, supportDelete);
183 setMenuItemVisible(menu, R.id.action_rotate_ccw, supportRotate);
184 setMenuItemVisible(menu, R.id.action_rotate_cw, supportRotate);
185 setMenuItemVisible(menu, R.id.action_crop, supportCrop);
Teng-Hui Zhu50ea2d22012-08-23 16:45:11 -0700186 setMenuItemVisible(menu, R.id.action_trim, supportTrim);
Teng-Hui Zhu648b3392012-11-13 10:39:26 -0800187 setMenuItemVisible(menu, R.id.action_mute, supportMute);
George Mount4b4dbd22012-10-18 14:20:39 -0700188 // Hide panorama until call to updateMenuForPanorama corrects it
189 setMenuItemVisible(menu, R.id.action_share_panorama, false);
Owen Linb21b8e52012-08-24 12:25:57 +0800190 setMenuItemVisible(menu, R.id.action_share, supportShare);
191 setMenuItemVisible(menu, R.id.action_setas, supportSetAs);
192 setMenuItemVisible(menu, R.id.action_show_on_map, supportShowOnMap);
193 setMenuItemVisible(menu, R.id.action_edit, supportEdit);
194 setMenuItemVisible(menu, R.id.action_details, supportInfo);
Owen Linb21b8e52012-08-24 12:25:57 +0800195 }
196
George Mount4b4dbd22012-10-18 14:20:39 -0700197 public static void updateMenuForPanorama(Menu menu, boolean shareAsPanorama360,
198 boolean disablePanorama360Options) {
199 setMenuItemVisible(menu, R.id.action_share_panorama, shareAsPanorama360);
200 if (disablePanorama360Options) {
201 setMenuItemVisible(menu, R.id.action_rotate_ccw, false);
202 setMenuItemVisible(menu, R.id.action_rotate_cw, false);
George Mount4b4dbd22012-10-18 14:20:39 -0700203 }
204 }
205
Owen Linb21b8e52012-08-24 12:25:57 +0800206 private static void setMenuItemVisible(Menu menu, int itemId, boolean visible) {
207 MenuItem item = menu.findItem(itemId);
208 if (item != null) item.setVisible(visible);
Owen Linf9a0a432011-08-17 22:07:43 +0800209 }
210
211 private Path getSingleSelectedPath() {
212 ArrayList<Path> ids = mSelectionManager.getSelected(true);
213 Utils.assertTrue(ids.size() == 1);
214 return ids.get(0);
215 }
216
Yuli Huangf50ce2b2012-05-02 00:50:56 +0800217 private Intent getIntentBySingleSelectedPath(String action) {
218 DataManager manager = mActivity.getDataManager();
219 Path path = getSingleSelectedPath();
Mangesh Ghiware5172dee2012-09-27 21:05:41 -0700220 String mimeType = getMimeType(manager.getMediaType(path));
Yuli Huangf50ce2b2012-05-02 00:50:56 +0800221 return new Intent(action).setDataAndType(manager.getContentUri(path), mimeType);
222 }
223
Ray Chen67098d12012-04-05 17:25:43 +0800224 private void onMenuClicked(int action, ProgressListener listener) {
Chih-Chung Chang6b891c62012-06-07 20:09:13 +0800225 onMenuClicked(action, listener, false, true);
226 }
227
228 public void onMenuClicked(int action, ProgressListener listener,
229 boolean waitOnStop, boolean showDialog) {
Owen Linf9a0a432011-08-17 22:07:43 +0800230 int title;
Owen Linf9a0a432011-08-17 22:07:43 +0800231 switch (action) {
232 case R.id.action_select_all:
233 if (mSelectionManager.inSelectAllMode()) {
234 mSelectionManager.deSelectAll();
235 } else {
236 mSelectionManager.selectAll();
237 }
Wu-cheng Li57263d32012-04-30 23:49:17 +0800238 return;
Owen Linf9a0a432011-08-17 22:07:43 +0800239 case R.id.action_crop: {
Ruben Brunk5aa454b2012-10-25 15:53:42 -0700240 Intent intent = getIntentBySingleSelectedPath(FilterShowActivity.CROP_ACTION)
241 .setClass((Activity) mActivity, FilterShowActivity.class);
Owen Linf9a0a432011-08-17 22:07:43 +0800242 ((Activity) mActivity).startActivity(intent);
Wu-cheng Li57263d32012-04-30 23:49:17 +0800243 return;
Owen Linf9a0a432011-08-17 22:07:43 +0800244 }
Yuli Huangf50ce2b2012-05-02 00:50:56 +0800245 case R.id.action_edit: {
246 Intent intent = getIntentBySingleSelectedPath(Intent.ACTION_EDIT)
247 .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
248 ((Activity) mActivity).startActivity(Intent.createChooser(intent, null));
249 return;
250 }
Owen Linf9a0a432011-08-17 22:07:43 +0800251 case R.id.action_setas: {
Yuli Huangf50ce2b2012-05-02 00:50:56 +0800252 Intent intent = getIntentBySingleSelectedPath(Intent.ACTION_ATTACH_DATA)
253 .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
254 intent.putExtra("mimeType", intent.getType());
Owen Lin28cb4162012-08-29 11:53:10 +0800255 Activity activity = mActivity;
Owen Linf9a0a432011-08-17 22:07:43 +0800256 activity.startActivity(Intent.createChooser(
257 intent, activity.getString(R.string.set_as)));
Wu-cheng Li57263d32012-04-30 23:49:17 +0800258 return;
Owen Linf9a0a432011-08-17 22:07:43 +0800259 }
Ray Chen67098d12012-04-05 17:25:43 +0800260 case R.id.action_delete:
Owen Linf9a0a432011-08-17 22:07:43 +0800261 title = R.string.delete;
262 break;
263 case R.id.action_rotate_cw:
264 title = R.string.rotate_right;
265 break;
266 case R.id.action_rotate_ccw:
267 title = R.string.rotate_left;
268 break;
269 case R.id.action_show_on_map:
270 title = R.string.show_on_map;
271 break;
Owen Linf9a0a432011-08-17 22:07:43 +0800272 default:
Ray Chen67098d12012-04-05 17:25:43 +0800273 return;
Owen Linf9a0a432011-08-17 22:07:43 +0800274 }
Chih-Chung Chang6b891c62012-06-07 20:09:13 +0800275 startAction(action, title, listener, waitOnStop, showDialog);
Ray Chen67098d12012-04-05 17:25:43 +0800276 }
277
Owen Lind759b7c2012-05-16 15:32:02 -0700278 private class ConfirmDialogListener implements OnClickListener, OnCancelListener {
279 private final int mActionId;
280 private final ProgressListener mListener;
281
282 public ConfirmDialogListener(int actionId, ProgressListener listener) {
283 mActionId = actionId;
284 mListener = listener;
285 }
286
287 @Override
288 public void onClick(DialogInterface dialog, int which) {
289 if (which == DialogInterface.BUTTON_POSITIVE) {
290 if (mListener != null) {
291 mListener.onConfirmDialogDismissed(true);
292 }
293 onMenuClicked(mActionId, mListener);
294 } else {
295 if (mListener != null) {
296 mListener.onConfirmDialogDismissed(false);
297 }
298 }
299 }
300
301 @Override
302 public void onCancel(DialogInterface dialog) {
303 if (mListener != null) {
304 mListener.onConfirmDialogDismissed(false);
305 }
306 }
307 }
308
Ray Chen9a033b02012-05-15 11:22:21 +0800309 public void onMenuClicked(MenuItem menuItem, String confirmMsg,
Ray Chen67098d12012-04-05 17:25:43 +0800310 final ProgressListener listener) {
311 final int action = menuItem.getItemId();
312
Ray Chen9a033b02012-05-15 11:22:21 +0800313 if (confirmMsg != null) {
Owen Lind759b7c2012-05-16 15:32:02 -0700314 if (listener != null) listener.onConfirmDialogShown();
315 ConfirmDialogListener cdl = new ConfirmDialogListener(action, listener);
Ray Chen67098d12012-04-05 17:25:43 +0800316 new AlertDialog.Builder(mActivity.getAndroidContext())
Ray Chen9a033b02012-05-15 11:22:21 +0800317 .setMessage(confirmMsg)
Owen Lind759b7c2012-05-16 15:32:02 -0700318 .setOnCancelListener(cdl)
319 .setPositiveButton(R.string.ok, cdl)
320 .setNegativeButton(R.string.cancel, cdl)
321 .create().show();
Ray Chen67098d12012-04-05 17:25:43 +0800322 } else {
323 onMenuClicked(action, listener);
324 }
Owen Linf9a0a432011-08-17 22:07:43 +0800325 }
326
327 public void startAction(int action, int title, ProgressListener listener) {
Chih-Chung Chang6b891c62012-06-07 20:09:13 +0800328 startAction(action, title, listener, false, true);
329 }
330
331 public void startAction(int action, int title, ProgressListener listener,
332 boolean waitOnStop, boolean showDialog) {
Owen Linf9a0a432011-08-17 22:07:43 +0800333 ArrayList<Path> ids = mSelectionManager.getSelected(false);
Ray Chenb2b45182011-08-31 16:37:04 +0800334 stopTaskAndDismissDialog();
Owen Linf9a0a432011-08-17 22:07:43 +0800335
Owen Lin28cb4162012-08-29 11:53:10 +0800336 Activity activity = mActivity;
Chih-Chung Chang6b891c62012-06-07 20:09:13 +0800337 mDialog = createProgressDialog(activity, title, ids.size());
338 if (showDialog) {
339 mDialog.show();
340 }
Owen Linf9a0a432011-08-17 22:07:43 +0800341 MediaOperation operation = new MediaOperation(action, ids, listener);
Bobby Georgescua2d0d342012-12-03 13:56:00 -0800342 mTask = mActivity.getBatchServiceThreadPoolIfAvailable().submit(operation, null);
Chih-Chung Chang6b891c62012-06-07 20:09:13 +0800343 mWaitOnStop = waitOnStop;
Owen Linf9a0a432011-08-17 22:07:43 +0800344 }
345
Mangesh Ghiware5172dee2012-09-27 21:05:41 -0700346 public static String getMimeType(int type) {
Owen Linf9a0a432011-08-17 22:07:43 +0800347 switch (type) {
348 case MediaObject.MEDIA_TYPE_IMAGE :
Mangesh Ghiware5172dee2012-09-27 21:05:41 -0700349 return GalleryUtils.MIME_TYPE_IMAGE;
Owen Linf9a0a432011-08-17 22:07:43 +0800350 case MediaObject.MEDIA_TYPE_VIDEO :
Mangesh Ghiware5172dee2012-09-27 21:05:41 -0700351 return GalleryUtils.MIME_TYPE_VIDEO;
352 default: return GalleryUtils.MIME_TYPE_ALL;
Owen Linf9a0a432011-08-17 22:07:43 +0800353 }
354 }
355
356 private boolean execute(
357 DataManager manager, JobContext jc, int cmd, Path path) {
358 boolean result = true;
Ray Chenb2b45182011-08-31 16:37:04 +0800359 Log.v(TAG, "Execute cmd: " + cmd + " for " + path);
360 long startTime = System.currentTimeMillis();
361
Owen Linf9a0a432011-08-17 22:07:43 +0800362 switch (cmd) {
Ray Chen67098d12012-04-05 17:25:43 +0800363 case R.id.action_delete:
Owen Linf9a0a432011-08-17 22:07:43 +0800364 manager.delete(path);
365 break;
366 case R.id.action_rotate_cw:
367 manager.rotate(path, 90);
368 break;
369 case R.id.action_rotate_ccw:
370 manager.rotate(path, -90);
371 break;
372 case R.id.action_toggle_full_caching: {
373 MediaObject obj = manager.getMediaObject(path);
374 int cacheFlag = obj.getCacheFlag();
375 if (cacheFlag == MediaObject.CACHE_FLAG_FULL) {
376 cacheFlag = MediaObject.CACHE_FLAG_SCREENNAIL;
377 } else {
378 cacheFlag = MediaObject.CACHE_FLAG_FULL;
379 }
380 obj.cache(cacheFlag);
381 break;
382 }
383 case R.id.action_show_on_map: {
384 MediaItem item = (MediaItem) manager.getMediaObject(path);
385 double latlng[] = new double[2];
386 item.getLatLong(latlng);
387 if (GalleryUtils.isValidLocation(latlng[0], latlng[1])) {
Owen Lin28cb4162012-08-29 11:53:10 +0800388 GalleryUtils.showOnMap(mActivity, latlng[0], latlng[1]);
Owen Linf9a0a432011-08-17 22:07:43 +0800389 }
390 break;
391 }
Owen Linf9a0a432011-08-17 22:07:43 +0800392 default:
393 throw new AssertionError();
394 }
Ray Chenb2b45182011-08-31 16:37:04 +0800395 Log.v(TAG, "It takes " + (System.currentTimeMillis() - startTime) +
396 " ms to execute cmd for " + path);
Owen Linf9a0a432011-08-17 22:07:43 +0800397 return result;
398 }
399
400 private class MediaOperation implements Job<Void> {
401 private final ArrayList<Path> mItems;
402 private final int mOperation;
403 private final ProgressListener mListener;
404
Chih-Chung Chang6b891c62012-06-07 20:09:13 +0800405 public MediaOperation(int operation, ArrayList<Path> items,
406 ProgressListener listener) {
Owen Linf9a0a432011-08-17 22:07:43 +0800407 mOperation = operation;
408 mItems = items;
409 mListener = listener;
410 }
411
Ahbong Chang78179792012-07-30 11:34:13 +0800412 @Override
Owen Linf9a0a432011-08-17 22:07:43 +0800413 public Void run(JobContext jc) {
414 int index = 0;
415 DataManager manager = mActivity.getDataManager();
416 int result = EXECUTION_RESULT_SUCCESS;
Ray Chenb2b45182011-08-31 16:37:04 +0800417 try {
Bobby Georgescuba50b942012-08-08 00:09:50 -0700418 onProgressStart(mListener);
Ray Chenb2b45182011-08-31 16:37:04 +0800419 for (Path id : mItems) {
420 if (jc.isCancelled()) {
421 result = EXECUTION_RESULT_CANCEL;
422 break;
423 }
424 if (!execute(manager, jc, mOperation, id)) {
425 result = EXECUTION_RESULT_FAIL;
426 }
427 onProgressUpdate(index++, mListener);
Owen Linf9a0a432011-08-17 22:07:43 +0800428 }
Ray Chenb2b45182011-08-31 16:37:04 +0800429 } catch (Throwable th) {
430 Log.e(TAG, "failed to execute operation " + mOperation
431 + " : " + th);
432 } finally {
433 onProgressComplete(result, mListener);
Owen Linf9a0a432011-08-17 22:07:43 +0800434 }
Owen Linf9a0a432011-08-17 22:07:43 +0800435 return null;
436 }
437 }
438}