OLD | NEW |
---|---|
(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.ntp; | |
6 | |
7 import android.content.Context; | |
8 import android.util.AttributeSet; | |
9 import android.util.LruCache; | |
10 import android.view.View; | |
11 import android.view.ViewGroup; | |
12 import android.widget.ArrayAdapter; | |
13 import android.widget.FrameLayout; | |
14 import android.widget.GridView; | |
15 | |
16 import org.chromium.chrome.R; | |
17 import org.chromium.chrome.browser.ntp.InterestsItemView.DrawingData; | |
18 import org.chromium.chrome.browser.ntp.InterestsItemView.ImagePlaceholder; | |
19 import org.chromium.chrome.browser.ntp.InterestsPage.InterestsClickListener; | |
20 import org.chromium.chrome.browser.ntp.InterestsService.Interest; | |
21 | |
22 import java.util.List; | |
23 | |
24 /** | |
25 * The user's interests, displayed with a two column grid view. | |
newt (away)
2015/12/12 00:30:31
Can you perhaps explain "interests" using some sta
PEConn
2015/12/14 17:05:15
Done.
| |
26 */ | |
27 public class InterestsView extends FrameLayout { | |
newt (away)
2015/12/12 00:30:31
can this be package private?
PEConn
2015/12/14 17:05:15
I don't think so (trying to compile with this pack
newt (away)
2015/12/14 21:18:39
Fair point. Android guidelines recommend that all
| |
28 private InterestsClickListener mListener; | |
29 private GridView mInterestsGrid; | |
30 private final InterestsListAdapter mAdapter; | |
31 private final LruCache<String, ImagePlaceholder> mImageCache; | |
32 private final DrawingData mDrawingData; | |
33 | |
34 public InterestsView(Context context, AttributeSet attrs) { | |
35 super(context, attrs); | |
36 mAdapter = new InterestsListAdapter(context); | |
37 mImageCache = new LruCache<>(30); | |
newt (away)
2015/12/12 00:30:31
Might as well move mImageCache and mDrawingData in
PEConn
2015/12/14 17:05:15
Done.
| |
38 mDrawingData = new InterestsItemView.DrawingData(getContext()); | |
39 } | |
40 | |
41 /** | |
42 * This must be called before {@link InterestsView setInterests}. | |
43 * @param listener | |
44 */ | |
45 public void setListener(InterestsClickListener listener) { | |
46 mListener = listener; | |
47 } | |
48 | |
49 public void setInterests(List<Interest> interests) { | |
newt (away)
2015/12/12 00:30:31
javadoc
PEConn
2015/12/14 17:05:15
Done.
| |
50 assert mListener != null; | |
51 mAdapter.addAll(interests); | |
52 } | |
53 | |
54 @Override | |
55 protected void onFinishInflate() { | |
56 super.onFinishInflate(); | |
57 | |
58 mInterestsGrid = (GridView) findViewById(R.id.interests_list_view); | |
59 mInterestsGrid.setAdapter(mAdapter); | |
60 } | |
61 | |
62 private class InterestsListAdapter extends ArrayAdapter<Interest> { | |
63 | |
64 public InterestsListAdapter(Context context) { | |
65 super(context, 0); | |
66 } | |
67 | |
68 @Override | |
69 public View getView(int position, View convertView, ViewGroup parent) { | |
70 assert mListener != null; | |
71 | |
72 Interest interest = getItem(position); | |
73 | |
74 InterestsItemView view; | |
75 if (convertView instanceof InterestsItemView) { | |
76 view = (InterestsItemView) convertView; | |
77 view.reset(interest); | |
78 } else { | |
79 view = new InterestsItemView(getContext(), interest, | |
80 mListener, mImageCache, mDrawingData); | |
81 } | |
82 return view; | |
83 } | |
84 } | |
85 } | |
OLD | NEW |