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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java

Issue 2186053002: Add context menu to snippets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge. Created 4 years, 5 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 | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java
index b53b89abe0fbdf8e155baa518051db558bcc9757..18d51dbc3690d30c02f837f85d2f6b31117a0365 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java
@@ -13,6 +13,9 @@ import android.graphics.drawable.TransitionDrawable;
import android.media.ThumbnailUtils;
import android.support.v4.text.BidiFormatter;
import android.text.format.DateUtils;
+import android.view.ContextMenu;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewTreeObserver;
@@ -40,7 +43,8 @@ import java.net.URISyntaxException;
/**
* A class that represents the view for a single card snippet.
*/
-public class SnippetArticleViewHolder extends CardViewHolder {
+public class SnippetArticleViewHolder extends CardViewHolder
+ implements MenuItem.OnMenuItemClickListener {
private static final String TAG = "NtpSnippets";
private static final String PUBLISHER_FORMAT_STRING = "%s - %s";
private static final int FADE_IN_ANIMATION_TIME_MS = 300;
@@ -52,6 +56,12 @@ public class SnippetArticleViewHolder extends CardViewHolder {
private static final String PARAMETER_FAVICON_SERVICE_NAME = "favicons_fetch_from_service";
private static final String PARAMETER_DISABLED_VALUE = "off";
+ // ContextMenu item ids. These must be unique.
+ private static final int ID_OPEN_IN_NEW_WINDOW = 0;
+ private static final int ID_OPEN_IN_NEW_TAB = 1;
+ private static final int ID_OPEN_IN_INCOGNITO_TAB = 2;
+ private static final int ID_REMOVE = 3;
+
private final NewTabPageManager mNewTabPageManager;
private final SnippetsBridge mSnippetsBridge;
private final TextView mHeadlineTextView;
@@ -137,6 +147,51 @@ public class SnippetArticleViewHolder extends CardViewHolder {
}
@Override
+ protected void createContextMenu(ContextMenu menu) {
+ // Create a context menu akin to the one shown for MostVisitedItems.
+ if (mNewTabPageManager.isOpenInNewWindowEnabled()) {
+ addContextMenuItem(menu, ID_OPEN_IN_NEW_WINDOW, R.string.contextmenu_open_in_new_tab);
+ }
+
+ addContextMenuItem(menu, ID_OPEN_IN_NEW_TAB, R.string.contextmenu_open_in_new_tab);
+
+ if (mNewTabPageManager.isOpenInIncognitoEnabled()) {
+ addContextMenuItem(menu, ID_OPEN_IN_INCOGNITO_TAB,
+ R.string.contextmenu_open_in_incognito_tab);
+ }
+
+ addContextMenuItem(menu, ID_REMOVE, R.string.remove);
+ }
+
+ /**
+ * Convenience method to reduce multi-line function call to single line.
+ */
+ private void addContextMenuItem(ContextMenu menu, int id, int resourceId) {
+ menu.add(Menu.NONE, id, Menu.NONE, resourceId).setOnMenuItemClickListener(this);
+ }
+
+ @Override
+ public boolean onMenuItemClick(MenuItem item) {
+ switch (item.getItemId()) {
+ case ID_OPEN_IN_NEW_WINDOW:
+ mNewTabPageManager.openUrlInNewWindow(mArticle.mUrl);
+ return true;
+ case ID_OPEN_IN_NEW_TAB:
+ mNewTabPageManager.openUrlInNewTab(mArticle.mUrl, false);
+ return true;
+ case ID_OPEN_IN_INCOGNITO_TAB:
+ mNewTabPageManager.openUrlInNewTab(mArticle.mUrl, true);
+ return true;
+ case ID_REMOVE:
+ assert isDismissable() : "Context menu should not be shown for peeking card.";
+ dismiss();
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ @Override
public void onBindViewHolder(NewTabPageListItem article) {
super.onBindViewHolder(article);
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698