Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsPage.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsPage.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsPage.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..738a0a2f01ade5de132d79e0522ee58e783ad84b |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsPage.java |
| @@ -0,0 +1,126 @@ |
| +// 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.app.Activity; |
| +import android.content.Context; |
| +import android.view.LayoutInflater; |
| +import android.view.View; |
| + |
| +import org.chromium.base.ApiCompatibilityUtils; |
| +import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.NativePage; |
| +import org.chromium.chrome.browser.UrlConstants; |
| +import org.chromium.chrome.browser.ntp.InterestsService.GetInterestsCallback; |
| +import org.chromium.chrome.browser.ntp.InterestsService.Interest; |
| +import org.chromium.chrome.browser.profiles.Profile; |
| +import org.chromium.chrome.browser.tab.Tab; |
| +import org.chromium.ui.widget.Toast; |
| + |
| +import java.util.Arrays; |
| +import java.util.List; |
| + |
| +/** |
| + * List the interests of the user. When an interest is clicked the user is redirected to a search |
| + * for that subject. |
| + */ |
| +public class InterestsPage implements NativePage { |
| + |
| + private static final String TAG = "interests_page"; |
| + |
| + private final InterestsView mPageView; |
| + private final String mTitle; |
| + private final int mBackgroundColor; |
| + private final int mThemeColor; |
| + |
| + /** |
| + * Creates a InterestsPage to be shown in document mode. |
| + * |
| + * @param context The view context for showing the page. |
| + * @param tab The tab from which interests page is loaded. |
| + * @param profile The profile from which to load interests. |
| + * @param activity The activity from which the interests page is loaded. |
| + */ |
| + public InterestsPage(final Context context, Tab tab, Profile profile, Activity activity) { |
| + mTitle = context.getResources().getString(R.string.ntp_interests); |
| + mBackgroundColor = ApiCompatibilityUtils.getColor(activity.getResources(), R.color.ntp_bg); |
| + mThemeColor = ApiCompatibilityUtils.getColor( |
| + activity.getResources(), R.color.default_primary_color); |
| + |
| + LayoutInflater inflater = LayoutInflater.from(context); |
| + |
| + mPageView = (InterestsView) inflater.inflate(R.layout.interests_page, null); |
| + |
| + new InterestsService(profile).getInterests( |
| + new GetInterestsCallback() { |
| + @Override |
| + public void onInterestsAvailableCallback(Interest[] interests) { |
| + if (interests == null) { |
| + Toast toast = Toast.makeText(context, |
| + "Could not retrieve interests.", Toast.LENGTH_SHORT); |
|
knn
2015/12/02 14:18:59
Make this an i18n resource?
PEConn
2015/12/08 17:27:50
Done.
|
| + toast.show(); |
| + return; |
| + } |
| + List<Interest> interestList = Arrays.asList(interests); |
| + |
| + mPageView.setInterests(interestList); |
| + } |
| + }); |
| + } |
| + |
| + public void setListener(InterestsClickListener listener) { |
| + mPageView.setListener(listener); |
| + } |
| + |
| + /** |
| + * Interface to be notified when the user clicks on a interest. |
| + **/ |
| + public interface InterestsClickListener { |
| + /** |
| + * Called when a interest is selected. |
| + * |
| + * @param name The name of the selected interest. |
| + */ |
| + void onInterestClicked(String name); |
| + } |
| + |
| + @Override |
| + public String getTitle() { |
| + return mTitle; |
| + } |
| + |
| + @Override |
| + public int getBackgroundColor() { |
| + return mBackgroundColor; |
| + } |
| + |
| + @Override |
| + public int getThemeColor() { |
| + return mThemeColor; |
| + } |
| + @Override |
| + public View getView() { |
| + return mPageView; |
| + } |
| + |
| + |
| + @Override |
| + public void destroy() { |
| + } |
| + |
| + @Override |
| + public String getHost() { |
| + return "interests"; |
| + } |
| + |
| + @Override |
| + public String getUrl() { |
| + return UrlConstants.INTERESTS_URL; |
| + } |
| + |
| + @Override |
| + public void updateForUrl(String url) { |
| + } |
| +} |