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..f66e4f2c0343dc7116e5c491475b2e0e7a476638 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsPage.java |
@@ -0,0 +1,114 @@ |
+// 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.chrome.R; |
+import org.chromium.chrome.browser.NativePage; |
+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 java.util.Arrays; |
+import java.util.List; |
+ |
+/** |
+ * List the interests of the user. When an interest is clicked the user is redirect to a google |
+ * search with news about that subject. |
+ */ |
+public class InterestsPage implements NativePage { |
newt (away)
2015/09/29 17:33:22
Will this ever be displayed as a webpage, or only
|
+ private final Profile mProfile; |
+ private final InterestsPageView mPageView; |
+ private final String mTitle; |
+ private final int mBackgroundColor; |
+ |
+ private static final String TAG = "cr.browser.ntp"; |
Bernhard Bauer
2015/09/29 14:33:28
Tags are not supposed to start with "cr." anymore;
PEConn
2015/11/18 15:26:57
Done.
|
+ |
+ /** |
+ * 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 listener The InterestsSelectedListener to notify when the user clicks an interest. |
+ * @param activity The activity from which the interests page is loaded. |
+ */ |
+ public InterestsPage(Context context, Tab tab, final Profile profile, |
+ InterestsListener listener, Activity activity) { |
+ mProfile = profile; |
+ mTitle = context.getResources().getString(R.string.ntp_interests); |
+ mBackgroundColor = context.getResources().getColor(R.color.ntp_bg); |
+ |
+ LayoutInflater inflater = LayoutInflater.from(context); |
+ |
+ mPageView = (InterestsPageView) inflater.inflate(R.layout.interests_page, null); |
+ mPageView.setListener(listener); |
+ |
+ new InterestsService(profile).getInterests( |
+ new GetInterestsCallback() { |
+ @Override |
+ public void onInterestsAvailableCallback(Interest[] interests) { |
+ List<Interest> interestList = Arrays.asList(interests); |
+ |
+ mPageView.setInterests(interestList); |
+ } |
+ }); |
+ |
newt (away)
2015/09/29 17:33:22
remove empty line
PEConn
2015/11/18 15:26:57
Done.
|
+ } |
+ |
+ /** |
+ * Interface to be notified when the user clicks on a interest. |
+ **/ |
+ public interface InterestsListener { |
+ /** |
+ * 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 View getView() { |
+ return mPageView; |
+ } |
+ |
+ /** |
+ * Releases internal resources. This must be called eventually, and the object should not used |
Bernhard Bauer
2015/09/29 14:33:28
This comment is unnecessary.
PEConn
2015/11/18 15:26:57
Done.
|
+ * after calling this. |
+ */ |
+ @Override |
+ public void destroy() { |
+ } |
+ |
+ @Override |
+ public String getHost() { |
+ return "interests"; |
+ } |
+ |
+ @Override |
+ public String getUrl() { |
+ return "chrome-native://interests"; |
newt (away)
2015/09/29 17:33:22
If this does need to be a NativePage, then add the
|
+ } |
+ |
+ @Override |
+ public void updateForUrl(String url) { |
+ } |
+} |