Commit 20db613a authored by Pavel Yatsuk's avatar Pavel Yatsuk Committed by Commit Bot

[Touchless] Add context menu to "More" button on NTP

BUG=959317
R=skym@chromium.org,mdjones@chromium.org

Change-Id: Icb49eaac8aed5f66fbe16d12d615bb1f8567bbaa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1636854Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarSky Malice <skym@chromium.org>
Commit-Queue: Pavel Yatsuk <pavely@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665007}
parent e24a9d8b
......@@ -84,6 +84,36 @@ public class ContextMenuManager implements OnCloseContextMenuListener {
void onContextMenuCreated();
}
/**
* Empty implementation of Delegate to allow derived classes to only implement methods they
* need.
*/
public static class EmptyDelegate implements Delegate {
@Override
public void openItem(int windowDisposition) {}
@Override
public void removeItem() {}
@Override
public String getUrl() {
return null;
}
@Override
public String getContextMenuTitle() {
return null;
}
@Override
public boolean isItemSupported(@ContextMenuItemId int menuItemId) {
return false;
}
@Override
public void onContextMenuCreated() {}
}
/**
* Delegate used by the {@link ContextMenuManager} to disable touch events on the outer view
* while the context menu is open.
......
......@@ -11,6 +11,7 @@ import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.native_page.ContextMenuManager;
import org.chromium.chrome.browser.native_page.ContextMenuManager.ContextMenuItemId;
import org.chromium.chrome.browser.ntp.cards.ActionItem;
import org.chromium.chrome.browser.suggestions.SuggestionsRecyclerView;
import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegate;
......@@ -48,6 +49,18 @@ class TouchlessActionItemViewHolder extends ActionItem.ViewHolder {
ApiCompatibilityUtils.getDrawable(itemView.getResources(), R.drawable.ic_note_add));
// Image view defaults to GONE.
mImageView.setVisibility(View.VISIBLE);
ContextMenuManager.registerViewForTouchlessContextMenu(
mButton, new ContextMenuManager.EmptyDelegate() {
@Override
public String getContextMenuTitle() {
return mButton.getResources().getString(R.string.more_articles);
}
@Override
public boolean isItemSupported(@ContextMenuItemId int menuItemId) {
return menuItemId == ContextMenuItemId.LEARN_MORE;
}
});
}
@Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment