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

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: git rebase 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 387ffd6ff1527f263358be2da7cd416b091a8f97..dd8a66d03401aa4e73b1bac63811870bf61453d2 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.Dialog;
import android.content.Context;
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;
David Trainor- moved to gerrit 2017/03/30 05:03:14 final?
JJ 2017/03/30 16:00:26 final!
+
+ /**
+ * A context menu that sperates types by tabs.
+ * @param contextMenuHelper The {@link ContextMenuHelper} is used to retrieve the thumbnail
+ * natively from the Context Menu Helper.
+ */
+ TabularContextMenuUi(ContextMenuHelper contextMenuHelper) {
+ mContextMenuHelper = contextMenuHelper;
+ }
@Override
public void displayMenu(Context context, ContextMenuParams params,
@@ -83,15 +100,24 @@ public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl
* @param context 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.
- * @return Returns a filled LinearLayout with all the context menu items
+ * @param isImage Whether or not the view should have an image layout or not.
+ * @param maxCount The maximum amount of {@link ContextMenuItem}s that could exist in this view
+ * or any other views calculated in the context menu. Used to estimate the size
+ * of the list.
+ * @return Returns a filled LinearLayout with all the context menu items.
*/
@VisibleForTesting
- ViewGroup createContextMenuPageUi(
- Context context, ContextMenuParams params, List<ContextMenuItem> items, int maxCount) {
+ ViewGroup createContextMenuPageUi(Context context, ContextMenuParams params,
+ List<ContextMenuItem> items, boolean isImage, int maxCount) {
ViewGroup baseLayout = (ViewGroup) LayoutInflater.from(context).inflate(
R.layout.tabular_context_menu_page, null);
ListView listView = (ListView) baseLayout.findViewById(R.id.selectable_items);
- displayHeaderIfVisibleItems(params, baseLayout);
+
+ if (isImage) {
+ displayImageHeader(baseLayout, params, context.getResources());
+ } else {
+ displayHeaderIfVisibleItems(params, baseLayout);
+ }
// Set the list adapter and get the height to display it appropriately in a dialog.
TabularContextMenuListAdapter listAdapter =
@@ -109,6 +135,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 +144,47 @@ public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl
headerTextView.setText(headerText);
}
+ private void displayImageHeader(
+ ViewGroup baseLayout, ContextMenuParams params, Resources resources) {
+ displayHeaderIfVisibleItems(params, baseLayout);
+ // #displayHeaderIfVisibleItems() sets these two views to GONE if the header text is
+ // empty but they should still be visible because we have an image to display.
+ baseLayout.findViewById(R.id.context_header_layout).setVisibility(View.VISIBLE);
+ baseLayout.findViewById(R.id.context_divider).setVisibility(View.VISIBLE);
+
+ 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);
+ }
+ 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) {
David Trainor- moved to gerrit 2017/03/30 05:03:14 This still makes me sad! :P
JJ 2017/03/30 16:00:26 It makes me even sadder!
Theresa 2017/03/30 18:34:34 I concur, but I still haven't come up with a bette
David Trainor- moved to gerrit 2017/03/30 23:45:14 Custom drawable!? (future work...?) Might be slo
+ Drawable drawable =
+ ApiCompatibilityUtils.getDrawable(resources, R.drawable.checkerboard_background);
+ Bitmap 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);
+ }
+
/**
* 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
@@ -159,8 +227,9 @@ public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl
}
for (int i = 0; i < itemGroups.size(); i++) {
Pair<Integer, List<ContextMenuItem>> itemGroup = itemGroups.get(i);
+ boolean isImage = itemGroup.first == R.string.contextmenu_image_title;
viewGroups.add(new Pair<>(context.getString(itemGroup.first),
- createContextMenuPageUi(context, params, itemGroup.second, maxCount)));
+ createContextMenuPageUi(context, params, itemGroup.second, isImage, maxCount)));
}
TabularContextMenuViewPager pager =
(TabularContextMenuViewPager) view.findViewById(R.id.custom_pager);

Powered by Google App Engine
This is Rietveld 408576698