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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuUi.java

Issue 2777773002: Show the image header for the Context Menu (Closed)
Patch Set: Created 3 years, 9 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
Index: chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuUi.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuUi.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuUi.java
index 0fa1a12a14a2fa818bf36c54bf618b07bf0ad9bc..0dbba5305a432afec2803c0b89273656cd6a64d7 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuUi.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuUi.java
@@ -7,6 +7,12 @@ package org.chromium.chrome.browser.contextmenu;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Shader;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
@@ -17,6 +23,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
+import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
@@ -35,6 +42,16 @@ public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl
private Dialog mDialog;
private Callback<Integer> mCallback;
private int mMenuItemHeight;
+ private ContextMenuHelper mContextMenuHelper;
+
+ /**
+ * A context menu that sperates types by tabs.
+ * @param contextMenuHelper This is used to retrieve the thumbnail natively from the Context
Theresa 2017/03/27 18:28:26 nit: The {@link ContextMenuHelper} used to retriev
JJ 2017/03/27 20:47:12 Done.
+ * Menu Helper.
+ */
+ TabularContextMenuUi(ContextMenuHelper contextMenuHelper) {
+ mContextMenuHelper = contextMenuHelper;
+ }
@Override
public void displayMenu(Activity activity, ContextMenuParams params,
@@ -82,16 +99,23 @@ public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl
* items and display only the ones that'll be on that specific group.
* @param activity Used to get the resources of an item.
* @param params used to create the header text.
- * @param items A set of Items to display in a context menu. Filtered based off the type.
+ * @param itemGroup A set of Items to display in a context menu. Filtered based off the type.
* @return Returns a filled LinearLayout with all the context menu items
*/
@VisibleForTesting
ViewGroup createSingleContextView(Activity activity, ContextMenuParams params,
- List<ContextMenuItem> items, int maxCount) {
+ Pair<Integer, List<ContextMenuItem>> itemGroup, int maxCount) {
Theresa 2017/03/27 18:28:26 Can the title string id and list of items be separ
JJ 2017/03/27 20:47:12 Yeah we can do that.
+ List<ContextMenuItem> items = itemGroup.second;
+ int title = itemGroup.first;
ViewGroup baseLayout = (ViewGroup) LayoutInflater.from(activity).inflate(
R.layout.tabular_context_menu_page, null);
ListView listView = (ListView) baseLayout.findViewById(R.id.selectable_items);
- displayHeaderIfVisibleItems(params, baseLayout);
+
+ if (title == R.string.contextmenu_image_title) {
+ displayImageHeader(baseLayout, params, activity.getResources());
+ } else {
+ displayHeaderIfVisibleItems(params, baseLayout);
+ }
// Set the list adapter and get the height to display it appropriately in a dialog.
TabularContextMenuListAdapter listAdapter =
@@ -109,6 +133,7 @@ public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl
String headerText = ChromeContextMenuPopulator.createHeaderText(params);
TextView headerTextView = (TextView) baseLayout.findViewById(R.id.context_header_text);
if (TextUtils.isEmpty(headerText)) {
+ baseLayout.findViewById(R.id.context_header_layout).setVisibility(View.GONE);
headerTextView.setVisibility(View.GONE);
baseLayout.findViewById(R.id.context_divider).setVisibility(View.GONE);
return;
@@ -117,6 +142,47 @@ public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl
headerTextView.setText(headerText);
}
+ private void displayImageHeader(
+ ViewGroup baseLayout, ContextMenuParams params, Resources resources) {
+ final ImageView imageView = (ImageView) baseLayout.findViewById(R.id.context_header_image);
+ TextView headerTextView = (TextView) baseLayout.findViewById(R.id.context_header_text);
+ String headerText = params.getTitleText();
+ if (!TextUtils.isEmpty(headerText)) {
+ headerTextView.setText(headerText);
+ headerTextView.setVisibility(View.VISIBLE);
+ } else {
+ displayHeaderIfVisibleItems(params, baseLayout);
+ // The image is still around so disabling the header is uneccessary
+ baseLayout.findViewById(R.id.context_header_layout).setVisibility(View.VISIBLE);
Theresa 2017/03/27 18:28:26 I think this could be simplified: displayHeaderIf
JJ 2017/03/27 20:47:12 Done.
Theresa 2017/03/28 17:23:08 I meant the whole top of the method private displ
JJ 2017/03/28 23:19:20 Oh whoops, apologies.
+ baseLayout.findViewById(R.id.context_divider).setVisibility(View.VISIBLE);
+ }
+ setBackgroundForImageView(imageView, resources);
+
+ mContextMenuHelper.setOnThumbnailReceivedListener(
+ new ContextMenuHelper.OnThumbnailReceivedListener() {
+ @Override
+ public void onThumbnailReceived(Bitmap bitmap) {
+ imageView.setImageBitmap(bitmap);
+ }
+ });
+ mContextMenuHelper.getThumbnail();
+ }
+
+ private void setBackgroundForImageView(ImageView imageView, Resources resources) {
+ Bitmap bitmap = null;
+ Drawable drawable =
+ ApiCompatibilityUtils.getDrawable(resources, R.drawable.checkerboard_background);
+ bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
+ Bitmap.Config.ARGB_8888);
+ Canvas canvas = new Canvas(bitmap);
+ drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
+ drawable.draw(canvas);
+ BitmapDrawable bm = new BitmapDrawable(resources, bitmap);
+ bm.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
+ imageView.setVisibility(View.VISIBLE);
+ imageView.setBackground(bm);
Theresa 2017/03/27 18:28:26 This method seems more complex than needed. I thin
JJ 2017/03/27 20:47:12 haha we tried. However it was deemed impossible if
+ }
+
/**
* To save time measuring the height, this method gets an item if the height has not been
* previous measured and multiplies it by count of the total amount of items. It is fine if the
@@ -156,7 +222,7 @@ public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl
for (Pair<Integer, List<ContextMenuItem>> itemGroup : itemGroups) {
maxCount = Math.max(maxCount, itemGroup.second.size());
viewGroups.add(new Pair<>(activity.getString(itemGroup.first),
- createSingleContextView(activity, params, itemGroup.second, maxCount)));
+ createSingleContextView(activity, params, itemGroup, maxCount)));
}
TabularContextMenuViewPager pager =
(TabularContextMenuViewPager) view.findViewById(R.id.custom_pager);

Powered by Google App Engine
This is Rietveld 408576698