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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/interests/InterestsView.java

Issue 1459593002: Added a UI for the Interests Prototype. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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.ntp.interests;
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.interests.InterestsItemView.DrawingData;
18 import org.chromium.chrome.browser.ntp.interests.InterestsItemView.ImageHolder;
19 import org.chromium.chrome.browser.ntp.interests.InterestsPage.InterestsClickLis tener;
20 import org.chromium.chrome.browser.ntp.interests.InterestsService.Interest;
21
22 import java.util.List;
23
24 /**
25 * Displays a user's Interests in a two column view. A user's Interests are a li st of topics (eg.
26 * Movies, Artists, Sports Events) that Google Now Context data shows they are i nterested in.
27 */
28 public class InterestsView extends FrameLayout {
29 private InterestsClickListener mListener;
30 private GridView mInterestsGrid;
31 private final InterestsListAdapter mAdapter;
32
33 public InterestsView(Context context, AttributeSet attrs) {
34 super(context, attrs);
35 mAdapter = new InterestsListAdapter(context);
36 }
37
38 /**
39 * This must be called before {@link InterestsView setInterests}.
40 * @param listener
41 */
42 public void setListener(InterestsClickListener listener) {
43 mListener = listener;
44 }
45
46 /**
47 * Sets the Interests to display. Must not be called before {@link Interests View setListener}.
48 * @param interests
49 */
50 public void setInterests(List<Interest> interests) {
51 assert mListener != null;
52 mAdapter.addAll(interests);
53 }
54
55 @Override
56 protected void onFinishInflate() {
57 super.onFinishInflate();
58
59 mInterestsGrid = (GridView) findViewById(R.id.interests_list_view);
60 mInterestsGrid.setAdapter(mAdapter);
61 }
62
63 private class InterestsListAdapter extends ArrayAdapter<Interest> {
64 private final LruCache<String, ImageHolder> mImageCache;
65 private final DrawingData mDrawingData;
66
67 public InterestsListAdapter(Context context) {
68 super(context, 0);
69 mImageCache = new LruCache<>(30);
70 mDrawingData = new InterestsItemView.DrawingData(getContext());
71 }
72
73 @Override
74 public View getView(int position, View convertView, ViewGroup parent) {
75 assert mListener != null;
76
77 Interest interest = getItem(position);
78
79 InterestsItemView view;
80 if (convertView instanceof InterestsItemView) {
81 view = (InterestsItemView) convertView;
82 view.reset(interest);
83 } else {
84 view = new InterestsItemView(getContext(), interest,
85 mListener, mImageCache, mDrawingData);
86 }
87 return view;
88 }
89 }
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698