Chromium Code Reviews| 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.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. | |
| 26 */ | |
| 27 public class InterestsView extends FrameLayout { | |
| 28 private InterestsClickListener mListener; | |
| 29 private GridView mInterestsGrid; | |
| 30 private final InterestsListAdapter mAdapter; | |
| 31 private final LruCache<String, Drawable> 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); | |
| 38 mDrawingData = new InterestsItemView.DrawingData(getContext()); | |
| 39 } | |
| 40 | |
| 41 /** | |
| 42 * This must be called before setInterests. | |
|
Bernhard Bauer
2015/12/02 14:09:47
You could wrap setInterests in a {@link} block.
PEConn
2015/12/08 17:27:50
Done.
| |
| 43 * @param listener | |
| 44 */ | |
| 45 public void setListener(InterestsClickListener listener) { | |
| 46 mListener = listener; | |
| 47 } | |
| 48 | |
| 49 public void setInterests(List<Interest> interests) { | |
| 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 |