Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsView.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsView.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsView.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8e8baf50a9a4ce73d6858223683286fe25a0df81 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsView.java |
| @@ -0,0 +1,85 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.ntp; |
| + |
| +import android.content.Context; |
| +import android.graphics.drawable.Drawable; |
| +import android.util.AttributeSet; |
| +import android.util.LruCache; |
| +import android.view.View; |
| +import android.view.ViewGroup; |
| +import android.widget.ArrayAdapter; |
| +import android.widget.FrameLayout; |
| +import android.widget.GridView; |
| + |
| +import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.ntp.InterestsItemView.DrawingData; |
| +import org.chromium.chrome.browser.ntp.InterestsPage.InterestsClickListener; |
| +import org.chromium.chrome.browser.ntp.InterestsService.Interest; |
| + |
| +import java.util.List; |
| + |
| +/** |
| + * The user's interests, displayed with a two column grid view. |
| + */ |
| +public class InterestsView extends FrameLayout { |
| + private InterestsClickListener mListener; |
| + private GridView mInterestsGrid; |
| + private final InterestsListAdapter mAdapter; |
| + private final LruCache<String, Drawable> mImageCache; |
| + private final DrawingData mDrawingData; |
| + |
| + public InterestsView(Context context, AttributeSet attrs) { |
| + super(context, attrs); |
| + mAdapter = new InterestsListAdapter(context); |
| + mImageCache = new LruCache<>(30); |
| + mDrawingData = new InterestsItemView.DrawingData(getContext()); |
| + } |
| + |
| + /** |
| + * 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.
|
| + * @param listener |
| + */ |
| + public void setListener(InterestsClickListener listener) { |
| + mListener = listener; |
| + } |
| + |
| + public void setInterests(List<Interest> interests) { |
| + assert mListener != null; |
| + mAdapter.addAll(interests); |
| + } |
| + |
| + @Override |
| + protected void onFinishInflate() { |
| + super.onFinishInflate(); |
| + |
| + mInterestsGrid = (GridView) findViewById(R.id.interests_list_view); |
| + mInterestsGrid.setAdapter(mAdapter); |
| + } |
| + |
| + private class InterestsListAdapter extends ArrayAdapter<Interest> { |
| + |
| + public InterestsListAdapter(Context context) { |
| + super(context, 0); |
| + } |
| + |
| + @Override |
| + public View getView(int position, View convertView, ViewGroup parent) { |
| + assert mListener != null; |
| + |
| + Interest interest = getItem(position); |
| + |
| + InterestsItemView view; |
| + if (convertView instanceof InterestsItemView) { |
| + view = (InterestsItemView) convertView; |
| + view.reset(interest); |
| + } else { |
| + view = new InterestsItemView(getContext(), interest, |
| + mListener, mImageCache, mDrawingData); |
| + } |
| + return view; |
| + } |
| + } |
| +} |