android:icon="@drawable/ic_menu_trash_holo_light"
android:title="@string/delete"
android:visible="false"
- android:showAsAction="ifRoom">
- <menu>
- <item android:id="@+id/action_confirm_delete"
- android:icon="@drawable/ic_menu_trash_holo_light"
- android:title="@string/confirm_delete" />
- <item android:id="@+id/action_cancel_delete"
- android:icon="@drawable/ic_menu_cancel_holo_light"
- android:title="@string/cancel" />
- </menu>
- </item>
+ android:showAsAction="ifRoom" />
<item android:id="@+id/action_slideshow"
android:icon="@drawable/ic_menu_slideshow_holo_light"
android:title="@string/slideshow"
android:icon="@drawable/ic_menu_trash_holo_light"
android:title="@string/delete"
android:visible="false"
- android:showAsAction="ifRoom">
- <menu>
- <item android:id="@+id/action_confirm_delete"
- android:icon="@drawable/ic_menu_trash_holo_light"
- android:title="@string/confirm_delete" />
- </menu>
- </item>
+ android:showAsAction="ifRoom" />
<item android:id="@+id/action_edit"
android:title="@string/edit"
android:showAsAction="never"
android:icon="@drawable/ic_menu_trash_holo_light"
android:title="@string/delete"
android:visible="false"
- android:showAsAction="never">
- <menu>
- <item android:id="@+id/action_confirm_delete"
- android:icon="@drawable/ic_menu_trash_holo_light"
- android:title="@string/confirm_delete" />
- </menu>
- </item>
+ android:showAsAction="never" />
<item android:id="@+id/action_slideshow"
android:icon="@drawable/ic_menu_slideshow_holo_light"
android:title="@string/slideshow"
<!-- Details dialog "OK" button. Dismisses dialog. -->
<string name="delete">Delete</string>
- <string name="confirm_delete">Delete</string>
+ <string name="confirm_action">Confirm deletion?</string>
+ <string name="confirm">Confirm</string>
<string name="cancel">Cancel</string>
<string name="share">Share</string>
DataManager manager = mActivity.getDataManager();
int action = item.getItemId();
+ boolean needsConfirm = false;
switch (action) {
case android.R.id.home: {
if (mSetPathString != null) {
}
return true;
}
+ case R.id.action_delete:
+ needsConfirm = true;
case R.id.action_setas:
- case R.id.action_confirm_delete:
case R.id.action_rotate_ccw:
case R.id.action_rotate_cw:
case R.id.action_show_on_map:
case R.id.action_edit:
mSelectionManager.deSelectAll();
mSelectionManager.toggle(path);
- mMenuExecutor.onMenuClicked(item, null);
+ mMenuExecutor.onMenuClicked(item, needsConfirm, null);
return true;
case R.id.action_import:
mSelectionManager.deSelectAll();
mSelectionManager.toggle(path);
- mMenuExecutor.onMenuClicked(item,
+ mMenuExecutor.onMenuClicked(item, needsConfirm,
new ImportCompleteListener(mActivity));
return true;
default :
root.lockRenderThread();
try {
boolean result;
+ // Give listener a chance to process this command before it's routed to
+ // ActionModeHandler, which handles command only based on the action id.
+ // Sometimes the listener may have more background information to handle
+ // an action command.
if (mListener != null) {
result = mListener.onActionItemClicked(item);
if (result) {
}
}
ProgressListener listener = null;
- if (item.getItemId() == R.id.action_import) {
+ boolean needsConfirm = false;
+ int action = item.getItemId();
+ if (action == R.id.action_import) {
listener = new ImportCompleteListener(mActivity);
+ } else if (item.getItemId() == R.id.action_delete) {
+ needsConfirm = true;
}
- result = mMenuExecutor.onMenuClicked(item, listener);
- if (item.getItemId() == R.id.action_select_all) {
+ mMenuExecutor.onMenuClicked(item, needsConfirm, listener);
+ if (action == R.id.action_select_all) {
updateSupportedOperation();
updateSelectionMenu();
}
- return result;
} finally {
root.unlockRenderThread();
}
+ return true;
}
private void updateSelectionMenu() {
package com.android.gallery3d.ui;
import android.app.Activity;
+import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
return ids.get(0);
}
- public boolean onMenuClicked(MenuItem menuItem, ProgressListener listener) {
+ private void onMenuClicked(int action, ProgressListener listener) {
int title;
DataManager manager = mActivity.getDataManager();
- int action = menuItem.getItemId();
switch (action) {
case R.id.action_select_all:
if (mSelectionManager.inSelectAllMode()) {
} else {
mSelectionManager.selectAll();
}
- return true;
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 true;
}
case R.id.action_setas: {
Path path = getSingleSelectedPath();
Activity activity = (Activity) mActivity;
activity.startActivity(Intent.createChooser(
intent, activity.getString(R.string.set_as)));
- return true;
}
- case R.id.action_confirm_delete:
+ case R.id.action_delete:
title = R.string.delete;
break;
case R.id.action_rotate_cw:
title = R.string.Import;
break;
default:
- return false;
+ return;
}
startAction(action, title, listener);
- return true;
+ }
+
+ public void onMenuClicked(MenuItem menuItem, boolean needsConfirm,
+ final ProgressListener listener) {
+ final int action = menuItem.getItemId();
+
+ if (needsConfirm) {
+ new AlertDialog.Builder(mActivity.getAndroidContext())
+ .setMessage(R.string.confirm_action)
+ .setPositiveButton(R.string.confirm, new OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ onMenuClicked(action, listener);
+ }
+ })
+ .setNegativeButton(R.string.cancel, null).create().show();
+ } else {
+ onMenuClicked(action, listener);
+ }
}
public void startAction(int action, int title, ProgressListener listener) {
long startTime = System.currentTimeMillis();
switch (cmd) {
- case R.id.action_confirm_delete:
+ case R.id.action_delete:
manager.delete(path);
break;
case R.id.action_rotate_cw: