Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.contextmenu; | 5 package org.chromium.chrome.browser.contextmenu; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.graphics.drawable.Drawable; | 8 import android.graphics.drawable.Drawable; |
| 9 import android.util.Pair; | 9 import android.util.Pair; |
| 10 import android.view.LayoutInflater; | 10 import android.view.LayoutInflater; |
| 11 import android.view.View; | 11 import android.view.View; |
| 12 import android.view.ViewGroup; | 12 import android.view.ViewGroup; |
| 13 import android.widget.BaseAdapter; | 13 import android.widget.BaseAdapter; |
| 14 import android.widget.ImageView; | 14 import android.widget.ImageView; |
| 15 import android.widget.TextView; | 15 import android.widget.TextView; |
| 16 | 16 |
| 17 import org.chromium.chrome.R; | 17 import org.chromium.chrome.R; |
| 18 import org.chromium.chrome.browser.share.ShareHelper; | |
| 18 | 19 |
| 19 import java.util.List; | 20 import java.util.List; |
| 20 | 21 |
| 21 /** | 22 /** |
| 22 * Takes a list of {@link ContextMenuItem} and puts them in an adapter meant to be used within a | 23 * Takes a list of {@link ContextMenuItem} and puts them in an adapter meant to be used within a |
| 23 * list view. | 24 * list view. |
| 24 */ | 25 */ |
| 25 class TabularContextMenuListAdapter extends BaseAdapter { | 26 class TabularContextMenuListAdapter extends BaseAdapter { |
| 26 private final List<ContextMenuItem> mMenuItems; | 27 private final List<ContextMenuItem> mMenuItems; |
| 27 private final Activity mActivity; | 28 private final Activity mActivity; |
| 29 private final ContextMenuHelper mContextMenuHelper; | |
| 28 | 30 |
| 29 /** | 31 /** |
| 30 * Adapter for the tabular context menu UI | 32 * Adapter for the tabular context menu UI |
| 31 * @param menuItems The list of items to display in the view. | 33 * @param menuItems The list of items to display in the view. |
| 32 * @param activity Used to inflate the layout. | 34 * @param activity Used to inflate the layout. |
| 35 * @param contextMenuHelper Used to directly share an image through the icon . | |
|
Theresa
2017/03/27 21:17:43
nit: ... through an icon.
JJ
2017/03/27 23:23:09
Done.
| |
| 33 */ | 36 */ |
| 34 TabularContextMenuListAdapter(List<ContextMenuItem> menuItems, Activity acti vity) { | 37 TabularContextMenuListAdapter(List<ContextMenuItem> menuItems, Activity acti vity, |
| 38 ContextMenuHelper contextMenuHelper) { | |
| 35 mMenuItems = menuItems; | 39 mMenuItems = menuItems; |
| 36 mActivity = activity; | 40 mActivity = activity; |
| 41 mContextMenuHelper = contextMenuHelper; | |
| 37 } | 42 } |
| 38 | 43 |
| 39 @Override | 44 @Override |
| 40 public int getCount() { | 45 public int getCount() { |
| 41 return mMenuItems.size(); | 46 return mMenuItems.size(); |
| 42 } | 47 } |
| 43 | 48 |
| 44 @Override | 49 @Override |
| 45 public Object getItem(int position) { | 50 public Object getItem(int position) { |
| 46 return mMenuItems.get(position); | 51 return mMenuItems.get(position); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 75 Pair<Drawable, String> iconPair = menuItem.getDrawableAndDescription(mAc tivity); | 80 Pair<Drawable, String> iconPair = menuItem.getDrawableAndDescription(mAc tivity); |
| 76 viewHolder.mIcon.setImageDrawable(iconPair.first); | 81 viewHolder.mIcon.setImageDrawable(iconPair.first); |
| 77 if (iconPair.first != null) { | 82 if (iconPair.first != null) { |
| 78 viewHolder.mIcon.setVisibility(View.VISIBLE); | 83 viewHolder.mIcon.setVisibility(View.VISIBLE); |
| 79 viewHolder.mIcon.setContentDescription(iconPair.second); | 84 viewHolder.mIcon.setContentDescription(iconPair.second); |
| 80 } else { | 85 } else { |
| 81 viewHolder.mIcon.setVisibility(View.INVISIBLE); | 86 viewHolder.mIcon.setVisibility(View.INVISIBLE); |
| 82 viewHolder.mIcon.setContentDescription(null); | 87 viewHolder.mIcon.setContentDescription(null); |
| 83 } | 88 } |
| 84 | 89 |
| 90 if (menuItem == ContextMenuItem.SHARE_IMAGE) { | |
| 91 final Pair<Drawable, CharSequence> shareInfo = | |
| 92 ShareHelper.getShareableIconAndName(mActivity); | |
| 93 if (shareInfo.first != null) { | |
| 94 viewHolder.mShareIcon.setImageDrawable(shareInfo.first); | |
| 95 viewHolder.mShareIcon.setVisibility(View.VISIBLE); | |
| 96 viewHolder.mShareIcon.setContentDescription(mActivity.getString( | |
| 97 R.string.accessibility_menu_share_via, iconPair.second)) ; | |
| 98 viewHolder.mShareIcon.setOnClickListener(new View.OnClickListene r() { | |
| 99 @Override | |
| 100 public void onClick(View view) { | |
| 101 mContextMenuHelper.shareImageDirectly( | |
| 102 ShareHelper.getLastShareComponentName()); | |
| 103 } | |
| 104 }); | |
| 105 } | |
| 106 } else { | |
| 107 viewHolder.mShareIcon.setImageDrawable(null); | |
| 108 viewHolder.mShareIcon.setVisibility(View.GONE); | |
|
Theresa
2017/03/27 21:17:43
You should just be able to set visibility to GONE
JJ
2017/03/27 23:23:09
True. I'll change it so!
| |
| 109 viewHolder.mShareIcon.setOnClickListener(null); | |
| 110 viewHolder.mShareIcon.setContentDescription(null); | |
| 111 } | |
| 112 | |
| 85 return convertView; | 113 return convertView; |
| 86 } | 114 } |
| 87 | 115 |
| 88 private static class ViewHolderItem { | 116 private static class ViewHolderItem { |
| 89 ImageView mIcon; | 117 ImageView mIcon; |
| 90 TextView mText; | 118 TextView mText; |
| 91 ImageView mShareIcon; | 119 ImageView mShareIcon; |
| 92 } | 120 } |
| 93 } | 121 } |
| OLD | NEW |