Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(747)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/SelectActionModeCallback.java

Issue 23672055: [Android] Inflate Select Action Bar from XML. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/android/java/resource_map/org/chromium/content/R.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/src/org/chromium/content/browser/SelectActionModeCallback.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/SelectActionModeCallback.java b/content/public/android/java/src/org/chromium/content/browser/SelectActionModeCallback.java
index 21dcbd2e4b5cae4299f967b284192fe3a6e3c668..374e6802a924812a3af1480e4e5dfe9a20073d60 100644
--- a/content/public/android/java/src/org/chromium/content/browser/SelectActionModeCallback.java
+++ b/content/public/android/java/src/org/chromium/content/browser/SelectActionModeCallback.java
@@ -10,7 +10,6 @@ import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
-import android.content.res.TypedArray;
import android.provider.Browser;
import android.text.TextUtils;
import android.view.ActionMode;
@@ -24,28 +23,6 @@ import org.chromium.content.R;
* non-editable cases.
*/
public class SelectActionModeCallback implements ActionMode.Callback {
- private static final int SELECT_ALL_ATTR_INDEX = 0;
- private static final int CUT_ATTR_INDEX = 1;
- private static final int COPY_ATTR_INDEX = 2;
- private static final int PASTE_ATTR_INDEX = 3;
- private static final int SHARE_ATTR_INDEX = 4;
- private static final int WEB_SEARCH_ATTR_INDEX = 5;
- private static final int[] ACTION_MODE_ATTRS = {
- android.R.attr.actionModeSelectAllDrawable,
- android.R.attr.actionModeCutDrawable,
- android.R.attr.actionModeCopyDrawable,
- android.R.attr.actionModePasteDrawable,
- R.attr.action_mode_share_drawable,
- R.attr.action_mode_web_search_drawable
- };
-
- private static final int ID_SELECTALL = 0;
- private static final int ID_COPY = 1;
- private static final int ID_SHARE = 2;
- private static final int ID_SEARCH = 3;
- private static final int ID_CUT = 4;
- private static final int ID_PASTE = 5;
-
/**
* An interface to retrieve information about the current selection, and also to perform
* actions based on the selection or when the action bar is dismissed.
@@ -140,82 +117,45 @@ public class SelectActionModeCallback implements ActionMode.Callback {
}
private void createActionMenu(ActionMode mode, Menu menu) {
- TypedArray styledAttributes = getContext().obtainStyledAttributes(
- R.style.ContentActionBar, ACTION_MODE_ATTRS);
-
- menu.add(Menu.NONE, ID_SELECTALL, Menu.NONE, android.R.string.selectAll).
- setAlphabeticShortcut('a').
- setIcon(styledAttributes.getResourceId(SELECT_ALL_ATTR_INDEX, 0)).
- setShowAsAction(
- MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
-
- if (mEditable) {
- menu.add(Menu.NONE, ID_CUT, Menu.NONE, android.R.string.cut).
- setIcon(styledAttributes.getResourceId(CUT_ATTR_INDEX, 0)).
- setAlphabeticShortcut('x').
- setShowAsAction(
- MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
+ mode.getMenuInflater().inflate(R.menu.select_action_menu, menu);
+ if (!mEditable || !canPaste()) {
+ menu.removeItem(R.id.select_action_menu_paste);
}
- menu.add(Menu.NONE, ID_COPY, Menu.NONE, android.R.string.copy).
- setIcon(styledAttributes.getResourceId(COPY_ATTR_INDEX, 0)).
- setAlphabeticShortcut('c').
- setShowAsAction(
- MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
-
- if (mEditable && canPaste()) {
- menu.add(Menu.NONE, ID_PASTE, Menu.NONE, android.R.string.paste).
- setIcon(styledAttributes.getResourceId(PASTE_ATTR_INDEX, 0)).
- setAlphabeticShortcut('v').
- setShowAsAction(
- MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
+ if (!mEditable) {
+ menu.removeItem(R.id.select_action_menu_cut);
}
- if (!mEditable) {
- if (mActionHandler.isShareAvailable()) {
- menu.add(Menu.NONE, ID_SHARE, Menu.NONE, R.string.actionbar_share).
- setIcon(styledAttributes.getResourceId(SHARE_ATTR_INDEX, 0)).
- setShowAsAction(
- MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
- }
-
- if (!mIncognito && mActionHandler.isWebSearchAvailable()) {
- menu.add(Menu.NONE, ID_SEARCH, Menu.NONE, R.string.actionbar_web_search).
- setIcon(styledAttributes.getResourceId(WEB_SEARCH_ATTR_INDEX, 0)).
- setShowAsAction(
- MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
- }
+ if (mEditable || !mActionHandler.isShareAvailable()) {
+ menu.removeItem(R.id.select_action_menu_share);
}
- styledAttributes.recycle();
+ if (mEditable || mIncognito || !mActionHandler.isWebSearchAvailable()) {
+ menu.removeItem(R.id.select_action_menu_web_search);
+ }
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- switch(item.getItemId()) {
- case ID_SELECTALL:
- mActionHandler.selectAll();
- break;
- case ID_CUT:
- mActionHandler.cut();
- break;
- case ID_COPY:
- mActionHandler.copy();
- mode.finish();
- break;
- case ID_PASTE:
- mActionHandler.paste();
- break;
- case ID_SHARE:
- mActionHandler.share();
- mode.finish();
- break;
- case ID_SEARCH:
- mActionHandler.search();
- mode.finish();
- break;
- default:
- return false;
+ int id = item.getItemId();
+
+ if (id == R.id.select_action_menu_select_all) {
+ mActionHandler.selectAll();
+ } else if (id == R.id.select_action_menu_cut) {
+ mActionHandler.cut();
+ } else if (id == R.id.select_action_menu_copy) {
+ mActionHandler.copy();
+ mode.finish();
+ } else if (id == R.id.select_action_menu_paste) {
+ mActionHandler.paste();
+ } else if (id == R.id.select_action_menu_share) {
+ mActionHandler.share();
+ mode.finish();
+ } else if (id == R.id.select_action_menu_web_search) {
+ mActionHandler.search();
+ mode.finish();
+ } else {
+ return false;
}
return true;
}
« no previous file with comments | « content/public/android/java/resource_map/org/chromium/content/R.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698