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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsPage.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, 1 month 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;
6
7 import android.app.Activity;
8 import android.content.Context;
9 import android.view.LayoutInflater;
10 import android.view.View;
11
12 import org.chromium.base.ApiCompatibilityUtils;
13 import org.chromium.base.Log;
14 import org.chromium.chrome.R;
15 import org.chromium.chrome.browser.NativePage;
16 import org.chromium.chrome.browser.UrlConstants;
17 import org.chromium.chrome.browser.ntp.InterestsService.GetInterestsCallback;
18 import org.chromium.chrome.browser.ntp.InterestsService.Interest;
19 import org.chromium.chrome.browser.profiles.Profile;
20 import org.chromium.chrome.browser.tab.Tab;
21 import org.chromium.ui.widget.Toast;
22
23 import java.util.Arrays;
24 import java.util.List;
25
26 /**
27 * List the interests of the user. When an interest is clicked the user is redir ect to a google
Marc Treib 2015/11/19 12:42:18 s/redirect/redirected
PEConn 2015/11/20 11:23:40 Done.
28 * search with news about that subject.
29 */
30 public class InterestsPage implements NativePage {
31
32 private static final String TAG = "interests_page";
33
34 private final Profile mProfile;
Marc Treib 2015/11/19 12:42:18 This member seems unnecessary
PEConn 2015/11/20 11:23:40 Done.
35 private final InterestsView mPageView;
36 private final String mTitle;
37 private final int mBackgroundColor;
38 private final int mThemeColor;
39
40 /**
41 * Creates a InterestsPage to be shown in document mode.
42 *
43 * @param context The view context for showing the page.
44 * @param tab The tab from which interests page is loaded.
45 * @param profile The profile from which to load interests.
46 * @param listener The InterestsSelectedListener to notify when the user cli cks an interest.
47 * @param activity The activity from which the interests page is loaded.
48 */
49 public InterestsPage(final Context context, Tab tab, Profile profile, Activi ty activity) {
50 mProfile = profile;
51 mTitle = context.getResources().getString(R.string.ntp_interests);
52 mBackgroundColor = ApiCompatibilityUtils.getColor(activity.getResources( ), R.color.ntp_bg);
53 mThemeColor = ApiCompatibilityUtils.getColor(
54 activity.getResources(), R.color.default_primary_color);
55
56 LayoutInflater inflater = LayoutInflater.from(context);
57
58 mPageView = (InterestsView) inflater.inflate(R.layout.interests_page, nu ll);
59
60 new InterestsService(profile).getInterests(
61 new GetInterestsCallback() {
62 @Override
63 public void onInterestsAvailableCallback(Interest[] interest s) {
64 if (interests == null) {
65 Log.w(TAG, "Interests Callback returned null.");
Bernhard Bauer 2015/11/19 17:15:15 This seems kind of unnecessary if you should a use
PEConn 2015/11/20 11:23:40 Done.
66 Toast toast = Toast.makeText(context,
67 "Could not retrieve interests.", Toast.LENGT H_SHORT);
68 toast.show();
69 return;
70 }
71 List<Interest> interestList = Arrays.asList(interests);
72
73 mPageView.setInterests(interestList);
74 }
75 });
76 }
77
78 public void setListener(InterestsListener listener) {
79 mPageView.setListener(listener);
80 }
81
82 /**
83 * Interface to be notified when the user clicks on a interest.
84 **/
85 public interface InterestsListener {
Marc Treib 2015/11/19 12:42:19 I find this name a bit confusing, I read it as "th
PEConn 2015/11/20 11:23:40 Done.
86 /**
87 * Called when a interest is selected.
88 *
89 * @param name The name of the selected interest.
90 */
91 void onInterestClicked(String name);
92 }
93
94 @Override
95 public String getTitle() {
96 return mTitle;
97 }
98
99 @Override
100 public int getBackgroundColor() {
101 return mBackgroundColor;
102 }
103
104 @Override
105 public int getThemeColor() {
106 return mThemeColor;
107 }
108 @Override
109 public View getView() {
110 return mPageView;
111 }
112
113
114 @Override
115 public void destroy() {
116 }
117
118 @Override
119 public String getHost() {
120 return "interests";
121 }
122
123 @Override
124 public String getUrl() {
125 return UrlConstants.INTERESTS_URL;
126 }
127
128 @Override
129 public void updateForUrl(String url) {
130 }
131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698