Index: chrome/android/java/src/org/chromium/chrome/browser/contextmenu/CustomContextMenuListAdapter.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/CustomContextMenuListAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/CustomContextMenuListAdapter.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d8c36d9c3751f39ea82b31131ba007a3a72d30a9 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/CustomContextMenuListAdapter.java |
@@ -0,0 +1,82 @@ |
+// 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.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 CustomContextMenuListAdapter extends BaseAdapter { |
+ private List<ContextMenuItem> mMenuItems; |
David Trainor- moved to gerrit
2017/03/21 16:30:02
eh final for these as well?
JJ
2017/03/22 23:35:32
Done.
|
+ private Activity mActivity; |
+ |
+ /** |
+ * Used to create a the base adapter for the list view using custom_context_menu_row.xml |
+ * @param menuItems The list of items to display in the view. |
+ * @param activity Used to inflate the layout. |
+ */ |
+ CustomContextMenuListAdapter(List<ContextMenuItem> menuItems, Activity activity) { |
+ this.mMenuItems = menuItems; |
+ this.mActivity = activity; |
+ } |
+ |
+ @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)); |
+ viewHolder.mIcon.setImageDrawable(menuItem.getDrawable(mActivity)); |
+ return convertView; |
+ } |
+ |
+ private static class ViewHolderItem { |
+ ImageView mIcon; |
+ TextView mText; |
+ ImageView mShareIcon; |
+ } |
+} |