Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuListAdapter.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuListAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuListAdapter.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..43a51b065d90eee753dc0ced095fc9ed7fca6f20 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuListAdapter.java |
| @@ -0,0 +1,89 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.contextmenu; |
| + |
| +import android.app.Activity; |
| +import android.graphics.drawable.Drawable; |
| +import android.util.Pair; |
| +import android.view.LayoutInflater; |
| +import android.view.View; |
| +import android.view.ViewGroup; |
| +import android.widget.BaseAdapter; |
| +import android.widget.ImageView; |
| +import android.widget.TextView; |
| + |
| +import org.chromium.chrome.R; |
| + |
| +import java.util.List; |
| + |
| +/** |
| + * Takes a list of {@link ContextMenuItem} and puts them in an adapter meant to be used within a |
| + * list view. |
| + */ |
| +class TabularContextMenuListAdapter extends BaseAdapter { |
| + private final List<ContextMenuItem> mMenuItems; |
| + private final Activity mActivity; |
| + |
| + /** |
| + * Used to create a the base adapter for the list view using custom_context_menu_row.xml |
|
Ted C
2017/03/24 04:32:53
I wouldn't mention the xml file here. Just someth
JJ
2017/03/25 01:40:25
Done.
|
| + * @param menuItems The list of items to display in the view. |
|
Ted C
2017/03/24 04:32:53
one too many spaces after menuItems
JJ
2017/03/25 01:40:25
Done.
|
| + * @param activity Used to inflate the layout. |
| + */ |
| + TabularContextMenuListAdapter(List<ContextMenuItem> menuItems, Activity activity) { |
| + this.mMenuItems = menuItems; |
|
Ted C
2017/03/24 04:32:53
this. isn't necessary as the names are different
JJ
2017/03/25 01:40:25
Done.
|
| + this.mActivity = activity; |
|
David Trainor- moved to gerrit
2017/03/24 17:24:20
Can this just be a Context?
|
| + } |
| + |
| + @Override |
| + public int getCount() { |
| + return mMenuItems.size(); |
| + } |
| + |
| + @Override |
| + public Object getItem(int position) { |
| + return mMenuItems.get(position); |
| + } |
| + |
| + @Override |
| + public long getItemId(int position) { |
| + return mMenuItems.get(position).menuId; |
| + } |
| + |
| + @Override |
| + public View getView(int position, View convertView, ViewGroup parent) { |
| + ContextMenuItem menuItem = mMenuItems.get(position); |
| + ViewHolderItem viewHolder; |
| + |
| + if (convertView == null) { |
| + LayoutInflater inflater = LayoutInflater.from(mActivity); |
| + convertView = inflater.inflate(R.layout.custom_context_menu_row, null); |
| + |
| + viewHolder = new ViewHolderItem(); |
| + viewHolder.mIcon = (ImageView) convertView.findViewById(R.id.context_menu_icon); |
| + viewHolder.mText = (TextView) convertView.findViewById(R.id.context_text); |
| + viewHolder.mShareIcon = |
| + (ImageView) convertView.findViewById(R.id.context_menu_share_icon); |
| + |
| + convertView.setTag(viewHolder); |
| + } else { |
| + viewHolder = (ViewHolderItem) convertView.getTag(); |
| + } |
| + |
| + viewHolder.mText.setText(menuItem.getString(mActivity)); |
| + Pair<Drawable, String> iconPair = menuItem.getDrawableAndDescription(mActivity); |
| + if (iconPair.first != null) { |
| + viewHolder.mIcon.setImageDrawable(iconPair.first); |
| + } |
|
Ted C
2017/03/24 04:32:53
if there is no drawable, should we make the view e
David Trainor- moved to gerrit
2017/03/24 17:24:20
Ah sorry I misread your comment! Says exactly wha
|
| + viewHolder.mIcon.setContentDescription(iconPair.second); |
|
Ted C
2017/03/24 04:32:53
I think we should only set this in the if above.
JJ
2017/03/25 01:40:25
Thanks, was having trouble with this line.
|
| + |
| + return convertView; |
| + } |
| + |
| + private static class ViewHolderItem { |
| + ImageView mIcon; |
| + TextView mText; |
| + ImageView mShareIcon; |
| + } |
| +} |