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.graphics.drawable.Drawable; | |
9 import android.util.AttributeSet; | |
10 import android.util.LruCache; | |
11 import android.view.View; | |
12 import android.view.ViewGroup; | |
13 import android.widget.ArrayAdapter; | |
14 import android.widget.FrameLayout; | |
15 import android.widget.GridView; | |
16 | |
17 import org.chromium.chrome.R; | |
18 import org.chromium.chrome.browser.ntp.InterestsItemView.DrawingData; | |
19 import org.chromium.chrome.browser.ntp.InterestsPage.InterestsListener; | |
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. | |
26 */ | |
27 public class InterestsView extends FrameLayout { | |
28 private InterestsListener mListener; | |
29 private GridView mInterestsGrid; | |
30 private final InterestsListAdapter mAdapter; | |
31 private final LruCache<String, Drawable> mImageCache; | |
32 private DrawingData mDrawingData; | |
33 | |
34 public InterestsView(Context context, AttributeSet attrs) { | |
35 super(context, attrs); | |
36 mAdapter = new InterestsListAdapter(context); | |
37 mImageCache = new LruCache<>(30); | |
38 } | |
39 | |
40 public void setListener(InterestsListener listener) { | |
Marc Treib
2015/11/19 12:42:19
Comment that this must be called before setInteres
PEConn
2015/11/20 11:23:41
Done.
| |
41 mListener = listener; | |
42 } | |
43 | |
44 public void setInterests(List<Interest> interests) { | |
45 mAdapter.addAll(interests); | |
46 } | |
47 | |
48 @Override | |
49 protected void onFinishInflate() { | |
50 super.onFinishInflate(); | |
51 | |
52 mInterestsGrid = (GridView) findViewById(R.id.interests_list_view); | |
53 mInterestsGrid.setAdapter(mAdapter); | |
54 } | |
55 | |
56 private class InterestsListAdapter extends ArrayAdapter<Interest> { | |
57 private Context mContext = null; | |
Marc Treib
2015/11/19 12:42:19
Do you need this? |getContext()| should give you t
PEConn
2015/11/20 11:23:40
Done.
| |
58 | |
59 public InterestsListAdapter(Context context) { | |
60 super(context, 0); | |
61 mContext = context; | |
62 } | |
63 | |
64 @Override | |
65 public View getView(int position, View convertView, ViewGroup parent) { | |
66 assert mListener != null; | |
67 | |
68 if (mDrawingData == null) { | |
69 mDrawingData = new InterestsItemView.DrawingData(getContext()); | |
Marc Treib
2015/11/19 12:42:19
Can you just initialize this in the InterestsView
PEConn
2015/11/20 11:23:40
Done.
| |
70 } | |
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(mContext, interest, | |
80 mListener, mImageCache, mDrawingData); | |
81 } | |
82 return view; | |
83 } | |
84 } | |
85 } | |
OLD | NEW |