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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/interests/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 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.interests;
6
7 import android.content.Context;
8 import android.view.View;
9
10 import org.chromium.base.ApiCompatibilityUtils;
11 import org.chromium.chrome.R;
12 import org.chromium.chrome.browser.NativePage;
13 import org.chromium.chrome.browser.UrlConstants;
14 import org.chromium.chrome.browser.ntp.interests.InterestsService.GetInterestsCa llback;
15 import org.chromium.chrome.browser.ntp.interests.InterestsService.Interest;
16 import org.chromium.chrome.browser.profiles.Profile;
17 import org.chromium.chrome.browser.tab.Tab;
18 import org.chromium.ui.widget.Toast;
19
20 import java.util.Arrays;
21 import java.util.List;
22
23 /**
24 * Displays a list of topics that we think the user is interested in. When an in terest is clicked
25 * the user is redirected to a search for that subject.
26 */
27 public class InterestsPage implements NativePage {
28
29 private static final String TAG = "interests_page";
30
31 private final InterestsView mPageView;
32 private final String mTitle;
33 private final int mBackgroundColor;
34 private final int mThemeColor;
35
36 /**
37 * Creates an InterestsPage.
38 *
39 * @param context The view context for showing the page.
40 * @param tab The tab from which interests page is loaded.
41 * @param profile The profile from which to load interests.
42 */
43 public InterestsPage(final Context context, Tab tab, Profile profile) {
44 mTitle = context.getResources().getString(R.string.ntp_interests);
45 mBackgroundColor = ApiCompatibilityUtils.getColor(context.getResources() , R.color.ntp_bg);
46 mThemeColor = ApiCompatibilityUtils.getColor(
47 context.getResources(), R.color.default_primary_color);
48 mPageView = (InterestsView) View.inflate(context, R.layout.interests_pag e, null);
49
50 new InterestsService(profile).getInterests(
51 new GetInterestsCallback() {
52 @Override
53 public void onInterestsAvailable(Interest[] interests) {
54 if (interests == null) {
55 Toast toast = Toast.makeText(context,
56 R.string.ntp_no_interests_toast, Toast.LENGT H_SHORT);
57 toast.show();
58 return;
59 }
60 List<Interest> interestList = Arrays.asList(interests);
61
62 mPageView.setInterests(interestList);
63 }
64 });
65 }
66
67 public void setListener(InterestsClickListener listener) {
68 mPageView.setListener(listener);
69 }
70
71 /**
72 * Interface to be notified when the user clicks on an interest.
73 **/
74 public interface InterestsClickListener {
75 /**
76 * Called when an interest is selected.
77 *
78 * @param name The name of the selected interest.
79 */
80 void onInterestClicked(String name);
81 }
82
83 @Override
84 public String getTitle() {
85 return mTitle;
86 }
87
88 @Override
89 public int getBackgroundColor() {
90 return mBackgroundColor;
91 }
92
93 @Override
94 public int getThemeColor() {
95 return mThemeColor;
96 }
97 @Override
98 public View getView() {
99 return mPageView;
100 }
101
102
103 @Override
104 public void destroy() {
105 }
106
107 @Override
108 public String getHost() {
109 return UrlConstants.INTERESTS_HOST;
110 }
111
112 @Override
113 public String getUrl() {
114 return UrlConstants.INTERESTS_URL;
115 }
116
117 @Override
118 public void updateForUrl(String url) {
119 }
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698