| Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardViewHolder.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardViewHolder.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardViewHolder.java
|
| index 565c0fdb149a0dd1ad6e0da6a1cc2699d78014cd..6071cae9572dbe56ee18047cba28c4a78547cb6d 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardViewHolder.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardViewHolder.java
|
| @@ -6,6 +6,7 @@
|
|
|
| import android.support.annotation.CallSuper;
|
| import android.support.annotation.DrawableRes;
|
| +import android.support.annotation.Nullable;
|
| import android.support.v4.view.animation.FastOutSlowInInterpolator;
|
| import android.support.v7.widget.RecyclerView;
|
| import android.view.ContextMenu;
|
| @@ -18,6 +19,8 @@
|
| import android.view.animation.Interpolator;
|
|
|
| import org.chromium.chrome.R;
|
| +import org.chromium.chrome.browser.ntp.ContextMenuManager;
|
| +import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager;
|
| import org.chromium.chrome.browser.ntp.UiConfig;
|
| import org.chromium.chrome.browser.util.MathUtils;
|
| import org.chromium.chrome.browser.util.ViewUtils;
|
| @@ -39,7 +42,7 @@
|
| * Note: If a subclass overrides {@link #onBindViewHolder()}, it should call the
|
| * parent implementation to reset the private state when a card is recycled.
|
| */
|
| -public class CardViewHolder extends NewTabPageViewHolder {
|
| +public abstract class CardViewHolder extends NewTabPageViewHolder {
|
| private static final Interpolator TRANSITION_INTERPOLATOR = new FastOutSlowInInterpolator();
|
|
|
| /** Value used for max peeking card height and padding. */
|
| @@ -56,6 +59,7 @@
|
|
|
| private final UiConfig mUiConfig;
|
| private final MarginResizer mMarginResizer;
|
| + private final NewTabPageManager mNtpManager;
|
|
|
| /**
|
| * To what extent the card is "peeking". 0 means the card is not peeking at all and spans the
|
| @@ -71,8 +75,8 @@
|
| * @param recyclerView ViewGroup that will contain the newly created view.
|
| * @param uiConfig The NTP UI configuration object used to adjust the card UI.
|
| */
|
| - public CardViewHolder(
|
| - int layoutId, final NewTabPageRecyclerView recyclerView, UiConfig uiConfig) {
|
| + public CardViewHolder(int layoutId, final NewTabPageRecyclerView recyclerView,
|
| + UiConfig uiConfig, NewTabPageManager ntpManager) {
|
| super(inflateView(layoutId, recyclerView));
|
|
|
| mCards9PatchAdjustment = recyclerView.getResources().getDimensionPixelSize(
|
| @@ -97,9 +101,12 @@ public void onClick(View v) {
|
| itemView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
|
| @Override
|
| public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
|
| - if (!isPeeking()) {
|
| - CardViewHolder.this.createContextMenu(menu);
|
| - }
|
| + if (isPeeking()) return;
|
| +
|
| + ContextMenuManager.Delegate delegate = getContextMenuDelegate();
|
| + if (delegate == null) return;
|
| +
|
| + mNtpManager.getContextMenuManager().createContextMenu(menu, itemView, delegate);
|
| }
|
| });
|
|
|
| @@ -110,6 +117,8 @@ public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo men
|
| // Configure the resizer to use negative margins on regular display to balance out the
|
| // lateral shadow of the card 9-patch and avoid a rounded corner effect.
|
| mMarginResizer.setMargins(-mCards9PatchAdjustment);
|
| +
|
| + mNtpManager = ntpManager;
|
| }
|
|
|
| /**
|
| @@ -212,11 +221,11 @@ public boolean isPeeking() {
|
| protected void onCardTapped() {}
|
|
|
| /**
|
| - * Override this to provide a context menu for the card. This method will not be called if the
|
| - * card is currently peeking.
|
| - * @param menu The menu to add menu items to.
|
| + * @return a context menu delegate for the card, or {@code null} if context menu should not be
|
| + * supported.
|
| */
|
| - protected void createContextMenu(ContextMenu menu) {}
|
| + @Nullable
|
| + protected abstract ContextMenuManager.Delegate getContextMenuDelegate();
|
|
|
| private void setPeekingPercentage(float peekingPercentage) {
|
| if (mPeekingPercentage == peekingPercentage) return;
|
|
|