Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.suggestions; | 5 package org.chromium.chrome.browser.suggestions; |
| 6 | 6 |
| 7 import android.content.Context; | |
| 8 import android.content.Intent; | 7 import android.content.Intent; |
| 9 import android.os.Bundle; | 8 import android.os.Bundle; |
| 10 import android.view.LayoutInflater; | 9 import android.view.LayoutInflater; |
| 11 import android.view.Menu; | 10 import android.view.Menu; |
| 12 | 11 |
| 13 import org.chromium.base.Callback; | |
| 14 import org.chromium.base.ObserverList; | |
| 15 import org.chromium.chrome.R; | 12 import org.chromium.chrome.R; |
| 13 import org.chromium.chrome.browser.ChromeActivity; | |
| 16 import org.chromium.chrome.browser.ChromeFeatureList; | 14 import org.chromium.chrome.browser.ChromeFeatureList; |
| 17 import org.chromium.chrome.browser.SynchronousInitializationActivity; | 15 import org.chromium.chrome.browser.SynchronousInitializationActivity; |
| 18 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; | |
| 19 import org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallbac k; | |
| 20 import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback; | |
| 21 import org.chromium.chrome.browser.ntp.ContextMenuManager; | 16 import org.chromium.chrome.browser.ntp.ContextMenuManager; |
| 22 import org.chromium.chrome.browser.ntp.LogoBridge.LogoObserver; | |
| 23 import org.chromium.chrome.browser.ntp.MostVisitedItem; | |
| 24 import org.chromium.chrome.browser.ntp.NewTabPage.DestructionObserver; | |
| 25 import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager; | |
| 26 import org.chromium.chrome.browser.ntp.UiConfig; | 17 import org.chromium.chrome.browser.ntp.UiConfig; |
| 27 import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter; | 18 import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter; |
| 28 import org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView; | 19 import org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView; |
| 29 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; | |
| 30 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; | 20 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; |
| 31 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; | |
| 32 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; | 21 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; |
| 33 import org.chromium.chrome.browser.profiles.MostVisitedSites.MostVisitedURLsObse rver; | |
| 34 import org.chromium.chrome.browser.profiles.Profile; | 22 import org.chromium.chrome.browser.profiles.Profile; |
| 35 | 23 |
| 36 import java.util.Set; | |
| 37 | |
| 38 /** | 24 /** |
| 39 * Experimental activity to show content suggestions outside of the New Tab Page . | 25 * Experimental activity to show content suggestions outside of the New Tab Page . |
| 40 */ | 26 */ |
| 41 public class ContentSuggestionsActivity extends SynchronousInitializationActivit y { | 27 public class ContentSuggestionsActivity extends SynchronousInitializationActivit y { |
| 42 private final ObserverList<DestructionObserver> mDestructionObservers = new ObserverList<>(); | 28 private static ChromeActivity sCallerActivity; |
| 43 | 29 |
| 44 private ContextMenuManager mContextMenuManager; | 30 private ContextMenuManager mContextMenuManager; |
| 45 private SnippetsBridge mSnippetsBridge; | 31 private SuggestionsManagerImpl mSuggestionsManager; |
| 46 private NewTabPageRecyclerView mRecyclerView; | |
| 47 | 32 |
| 48 public static void launch(Context context) { | 33 public static void launch(ChromeActivity activity) { |
| 34 sCallerActivity = activity; | |
|
Bernhard Bauer
2017/01/13 14:17:03
This is pretty ugly, and I can imagine a couple of
| |
| 35 | |
| 49 Intent intent = new Intent(); | 36 Intent intent = new Intent(); |
| 50 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 37 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 51 intent.setClass(context, ContentSuggestionsActivity.class); | 38 intent.setClass(activity, ContentSuggestionsActivity.class); |
| 52 context.startActivity(intent); | 39 activity.startActivity(intent); |
| 53 } | |
| 54 | |
| 55 private class SuggestionsNewTabPageManager implements NewTabPageManager { | |
| 56 @Override | |
| 57 public void removeMostVisitedItem(MostVisitedItem item) {} | |
| 58 | |
| 59 @Override | |
| 60 public void openMostVisitedItem(int windowDisposition, MostVisitedItem i tem) {} | |
| 61 | |
| 62 @Override | |
| 63 public boolean isLocationBarShownInNTP() { | |
| 64 return false; | |
| 65 } | |
| 66 | |
| 67 @Override | |
| 68 public boolean isVoiceSearchEnabled() { | |
| 69 return false; | |
| 70 } | |
| 71 | |
| 72 @Override | |
| 73 public boolean isFakeOmniboxTextEnabledTablet() { | |
| 74 return false; | |
| 75 } | |
| 76 | |
| 77 @Override | |
| 78 public boolean isOpenInNewWindowEnabled() { | |
| 79 return true; | |
| 80 } | |
| 81 | |
| 82 @Override | |
| 83 public boolean isOpenInIncognitoEnabled() { | |
| 84 return true; | |
| 85 } | |
| 86 | |
| 87 @Override | |
| 88 public void navigateToBookmarks() {} | |
| 89 | |
| 90 @Override | |
| 91 public void navigateToRecentTabs() {} | |
| 92 | |
| 93 @Override | |
| 94 public void navigateToDownloadManager() {} | |
| 95 | |
| 96 @Override | |
| 97 public void trackSnippetsPageImpression(int[] categories, int[] suggesti onsPerCategory) {} | |
| 98 | |
| 99 @Override | |
| 100 public void trackSnippetImpression(SnippetArticle article) {} | |
| 101 | |
| 102 @Override | |
| 103 public void trackSnippetMenuOpened(SnippetArticle article) {} | |
| 104 | |
| 105 @Override | |
| 106 public void trackSnippetCategoryActionImpression(int category, int posit ion) {} | |
| 107 | |
| 108 @Override | |
| 109 public void trackSnippetCategoryActionClick(int category, int position) {} | |
| 110 | |
| 111 @Override | |
| 112 public void openSnippet(int windowOpenDisposition, SnippetArticle articl e) {} | |
| 113 | |
| 114 @Override | |
| 115 public void focusSearchBox(boolean beginVoiceSearch, String pastedText) {} | |
| 116 | |
| 117 @Override | |
| 118 public void setMostVisitedURLsObserver(MostVisitedURLsObserver observer, int numResults) {} | |
| 119 | |
| 120 @Override | |
| 121 public void getLocalFaviconImageForURL( | |
| 122 String url, int size, FaviconImageCallback faviconCallback) {} | |
| 123 | |
| 124 @Override | |
| 125 public void getLargeIconForUrl(String url, int size, LargeIconCallback c allback) {} | |
| 126 | |
| 127 @Override | |
| 128 public void ensureIconIsAvailable(String pageUrl, String iconUrl, boolea n isLargeIcon, | |
| 129 boolean isTemporary, IconAvailabilityCallback callback) {} | |
| 130 | |
| 131 @Override | |
| 132 public void getUrlsAvailableOffline(Set<String> pageUrls, Callback<Set<S tring>> callback) {} | |
| 133 | |
| 134 @Override | |
| 135 public void onLogoClicked(boolean isAnimatedLogoShowing) {} | |
| 136 | |
| 137 @Override | |
| 138 public void getSearchProviderLogo(LogoObserver logoObserver) {} | |
| 139 | |
| 140 @Override | |
| 141 public void onLoadingComplete(MostVisitedItem[] mostVisitedItems) {} | |
| 142 | |
| 143 @Override | |
| 144 public void onLearnMoreClicked() {} | |
| 145 | |
| 146 @Override | |
| 147 public SuggestionsSource getSuggestionsSource() { | |
| 148 return mSnippetsBridge; | |
| 149 } | |
| 150 | |
| 151 @Override | |
| 152 public void addDestructionObserver(DestructionObserver destructionObserv er) { | |
| 153 mDestructionObservers.addObserver(destructionObserver); | |
| 154 } | |
| 155 | |
| 156 @Override | |
| 157 public boolean isCurrentPage() { | |
| 158 return true; | |
| 159 } | |
| 160 | |
| 161 @Override | |
| 162 public ContextMenuManager getContextMenuManager() { | |
| 163 return mContextMenuManager; | |
| 164 } | |
| 165 } | 40 } |
| 166 | 41 |
| 167 @Override | 42 @Override |
| 168 protected void onCreate(Bundle savedInstanceState) { | 43 protected void onCreate(Bundle savedInstanceState) { |
| 169 super.onCreate(savedInstanceState); | 44 super.onCreate(savedInstanceState); |
| 170 | 45 |
| 171 assert ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_SUGGESTIONS_STA NDALONE_UI); | 46 assert ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_SUGGESTIONS_STA NDALONE_UI); |
| 172 | 47 |
| 173 mRecyclerView = (NewTabPageRecyclerView) LayoutInflater.from(this).infla te( | 48 NewTabPageRecyclerView recyclerView = |
| 174 R.layout.new_tab_page_recycler_view, null, false); | 49 (NewTabPageRecyclerView) LayoutInflater.from(this).inflate( |
| 50 R.layout.new_tab_page_recycler_view, null, false); | |
| 175 | 51 |
| 176 Profile profile = Profile.getLastUsedProfile(); | 52 Profile profile = Profile.getLastUsedProfile(); |
| 177 mSnippetsBridge = new SnippetsBridge(profile); | 53 UiConfig uiConfig = new UiConfig(recyclerView); |
| 178 | 54 |
| 179 NewTabPageManager manager = new SuggestionsNewTabPageManager(); | 55 SnippetsBridge snippetsBridge = new SnippetsBridge(profile); |
| 180 mContextMenuManager = new ContextMenuManager(this, manager, mRecyclerVie w); | 56 mSuggestionsManager = new SuggestionsManagerImpl(snippetsBridge, this, p rofile, |
| 181 UiConfig uiConfig = new UiConfig(mRecyclerView); | 57 sCallerActivity.getActivityTab(), sCallerActivity.getTabModelSel ector()); |
| 182 NewTabPageAdapter adapter = new NewTabPageAdapter( | 58 mContextMenuManager = new ContextMenuManager(this, mSuggestionsManager, recyclerView); |
| 183 manager, null, uiConfig, OfflinePageBridge.getForProfile(profile )); | |
| 184 mRecyclerView.setAdapter(adapter); | |
| 185 mRecyclerView.setUpSwipeToDismiss(); | |
| 186 | 59 |
| 187 setContentView(mRecyclerView); | 60 NewTabPageAdapter adapter = new NewTabPageAdapter(mSuggestionsManager, n ull, uiConfig, |
| 61 OfflinePageBridge.getForProfile(profile), mContextMenuManager); | |
| 62 recyclerView.setAdapter(adapter); | |
| 63 recyclerView.setUpSwipeToDismiss(); | |
| 64 | |
| 65 setContentView(recyclerView); | |
| 188 } | 66 } |
| 189 | 67 |
| 190 @Override | 68 @Override |
| 191 public void onContextMenuClosed(Menu menu) { | 69 public void onContextMenuClosed(Menu menu) { |
| 192 mContextMenuManager.onContextMenuClosed(); | 70 mContextMenuManager.onContextMenuClosed(); |
| 193 } | 71 } |
| 194 | 72 |
| 195 @Override | 73 @Override |
| 196 protected void onDestroy() { | 74 protected void onDestroy() { |
| 197 for (DestructionObserver observer : mDestructionObservers) { | 75 mSuggestionsManager.onDestroy(); |
| 198 observer.onDestroy(); | |
| 199 } | |
| 200 super.onDestroy(); | 76 super.onDestroy(); |
| 201 } | 77 } |
| 202 } | 78 } |
| OLD | NEW |