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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/NearbyUrlsAdapter.java

Issue 2651553005: Remove ListUrlsActivity (Closed)
Patch Set: Commenting unused fields Created 3 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.physicalweb;
6
7 import android.content.Context;
8 import android.graphics.Bitmap;
9 import android.view.LayoutInflater;
10 import android.view.View;
11 import android.view.ViewGroup;
12 import android.widget.ArrayAdapter;
13 import android.widget.ImageView;
14 import android.widget.TextView;
15
16 import org.chromium.chrome.R;
17
18 import java.util.HashMap;
19
20 /**
21 * Adapter for displaying nearby URLs and associated metadata.
22 */
23 class NearbyUrlsAdapter extends ArrayAdapter<PwsResult> {
24 private final HashMap<String, Bitmap> mIconUrlToIconMap;
25
26 /**
27 * Construct an empty NearbyUrlsAdapter.
28 */
29 public NearbyUrlsAdapter(Context context) {
30 super(context, 0);
31 mIconUrlToIconMap = new HashMap<>();
32 }
33
34 /**
35 * Update the favicon for a nearby URL.
36 * @param iconUrl The icon URL as returned by PWS
37 * @param icon The favicon to display
38 */
39 public void setIcon(String iconUrl, Bitmap icon) {
40 if (iconUrl != null && icon != null) {
41 mIconUrlToIconMap.put(iconUrl, icon);
42 notifyDataSetChanged();
43 }
44 }
45
46 /**
47 * Return true if we already know an icon for this URL.
48 * @param iconUrl The icon URL as returned by PWS
49 * @return true if the icon is present
50 */
51 public boolean hasIcon(String iconUrl) {
52 return mIconUrlToIconMap.containsKey(iconUrl);
53 }
54
55 /**
56 * Return true if we already know we have a given groupId.
57 * @param groupId The requested groupId
58 * @return true if a PwsResult is present that has the given groupId
59 */
60 public boolean hasGroupId(String groupId) {
61 for (int position = 0; position < getCount(); ++position) {
62 if (groupId.equals(getItem(position).groupId)) {
63 return true;
64 }
65 }
66 return false;
67 }
68
69 /**
70 * Get the view for an item in the data set.
71 * @param position Index of the list view item within the array.
72 * @param view The old view to reuse, if possible.
73 * @param viewGroup The parent that this view will eventually be attached to .
74 * @return A view corresponding to the list view item.
75 */
76 @Override
77 public View getView(int position, View view, ViewGroup viewGroup) {
78 if (view == null) {
79 LayoutInflater inflater = LayoutInflater.from(getContext());
80 view = inflater.inflate(R.layout.physical_web_list_item_nearby_url, viewGroup, false);
81 }
82
83 TextView titleTextView = (TextView) view.findViewById(R.id.nearby_urls_t itle);
84 TextView urlTextView = (TextView) view.findViewById(R.id.nearby_urls_url );
85 TextView descriptionTextView = (TextView) view.findViewById(R.id.nearby_ urls_description);
86 ImageView iconImageView = (ImageView) view.findViewById(R.id.nearby_urls _icon);
87
88 PwsResult pwsResult = getItem(position);
89 Bitmap iconBitmap = mIconUrlToIconMap.get(pwsResult.iconUrl);
90
91 titleTextView.setText(pwsResult.title);
92 urlTextView.setText(pwsResult.siteUrl);
93 descriptionTextView.setText(pwsResult.description);
94 iconImageView.setImageBitmap(iconBitmap);
95
96 return view;
97 }
98
99 /**
100 * Gets whether the specified site URL is in the list.
101 * @param siteUrl A string containing the site URL.
102 * @return Boolean true if the specified site URL is already in the list.
103 */
104 public boolean hasSiteUrl(String siteUrl) {
105 int itemCount = getCount();
106 for (int position = 0; position < itemCount; ++position) {
107 PwsResult pwsResult = getItem(position);
108 if (siteUrl.equals(pwsResult.siteUrl)) {
109 return true;
110 }
111 }
112
113 return false;
114 }
115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698