From 67098d1a72fd04e2af06d3a5939cde28c65f70d9 Mon Sep 17 00:00:00 2001 From: Ray Chen Date: Thu, 5 Apr 2012 17:25:43 +0800 Subject: [PATCH] Fix 6046544 Deleting a photo takes multiple steps and the flow is inconsistent with other deleting flows on other core apps This CL adds a confirm dialog to delete command and removes all confirm/cancel menu items from the actionbar. b:6046544 Change-Id: I3afe7b59b4f6d1216e192a621621f7bf544e1919 --- res/menu-land/photo.xml | 11 +------ res/menu/operation.xml | 8 +---- res/menu/photo.xml | 8 +---- res/values/strings.xml | 3 +- src/com/android/gallery3d/app/PhotoPage.java | 8 +++-- .../android/gallery3d/ui/ActionModeHandler.java | 16 +++++++--- src/com/android/gallery3d/ui/MenuExecutor.java | 34 ++++++++++++++++------ 7 files changed, 47 insertions(+), 41 deletions(-) diff --git a/res/menu-land/photo.xml b/res/menu-land/photo.xml index 023a93bed..21f802a25 100644 --- a/res/menu-land/photo.xml +++ b/res/menu-land/photo.xml @@ -30,16 +30,7 @@ android:icon="@drawable/ic_menu_trash_holo_light" android:title="@string/delete" android:visible="false" - android:showAsAction="ifRoom"> - - - - - + android:showAsAction="ifRoom" /> - - - - + android:showAsAction="ifRoom" /> - - - - + android:showAsAction="never" /> Delete - Delete + Confirm deletion? + Confirm Cancel Share diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index 78bb34cab..6be302b24 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -435,6 +435,7 @@ public class PhotoPage extends ActivityState DataManager manager = mActivity.getDataManager(); int action = item.getItemId(); + boolean needsConfirm = false; switch (action) { case android.R.id.home: { if (mSetPathString != null) { @@ -480,20 +481,21 @@ public class PhotoPage extends ActivityState } 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 : diff --git a/src/com/android/gallery3d/ui/ActionModeHandler.java b/src/com/android/gallery3d/ui/ActionModeHandler.java index 32820f327..018839314 100644 --- a/src/com/android/gallery3d/ui/ActionModeHandler.java +++ b/src/com/android/gallery3d/ui/ActionModeHandler.java @@ -110,6 +110,10 @@ public class ActionModeHandler implements ActionMode.Callback { 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) { @@ -118,18 +122,22 @@ public class ActionModeHandler implements ActionMode.Callback { } } 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() { diff --git a/src/com/android/gallery3d/ui/MenuExecutor.java b/src/com/android/gallery3d/ui/MenuExecutor.java index 918feead9..a0f344982 100644 --- a/src/com/android/gallery3d/ui/MenuExecutor.java +++ b/src/com/android/gallery3d/ui/MenuExecutor.java @@ -17,8 +17,11 @@ 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; @@ -172,10 +175,9 @@ public class MenuExecutor { 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()) { @@ -183,14 +185,12 @@ public class MenuExecutor { } 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(); @@ -203,9 +203,8 @@ public class MenuExecutor { 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: @@ -224,10 +223,27 @@ public class MenuExecutor { 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) { @@ -257,7 +273,7 @@ public class MenuExecutor { 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: -- 2.11.0