Chromium Code Reviews| 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..177aed09146de67a39e34fbe3edb231245135220 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 The {@link ContextMenuHelper} is used to retrieve the thumbnail |
| + * natively from the Context Menu Helper. |
| + */ |
| + TabularContextMenuUi(ContextMenuHelper contextMenuHelper) { |
| + mContextMenuHelper = contextMenuHelper; |
| + } |
| @Override |
| public void displayMenu(Activity activity, ContextMenuParams params, |
| @@ -87,11 +104,16 @@ public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl |
| */ |
| @VisibleForTesting |
| ViewGroup createSingleContextView(Activity activity, ContextMenuParams params, |
| - List<ContextMenuItem> items, int maxCount) { |
| + List<ContextMenuItem> items, boolean isImage, int maxCount) { |
| 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 (isImage) { |
| + 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 +131,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 +140,48 @@ 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); |
| + // #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); |
| + } |
| + 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); |
|
Theresa
2017/03/28 17:23:08
I think this can be simplified to something like:
JJ
2017/03/28 23:19:20
Doesn't work :< Doesn't keep the repetition up, sa
|
| + 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 |
| @@ -155,8 +220,10 @@ public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl |
| int maxCount = 0; |
| for (Pair<Integer, List<ContextMenuItem>> itemGroup : itemGroups) { |
| maxCount = Math.max(maxCount, itemGroup.second.size()); |
| + boolean isImage = itemGroup.first == R.string.contextmenu_image_title; |
| viewGroups.add(new Pair<>(activity.getString(itemGroup.first), |
| - createSingleContextView(activity, params, itemGroup.second, maxCount))); |
| + createSingleContextView( |
| + activity, params, itemGroup.second, isImage, maxCount))); |
| } |
| TabularContextMenuViewPager pager = |
| (TabularContextMenuViewPager) view.findViewById(R.id.custom_pager); |