org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager Java Examples
The following examples show how to use
org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SnippetArticleViewHolder.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Constructs a {@link SnippetArticleViewHolder} item used to display snippets. * * @param parent The NewTabPageRecyclerView that is going to contain the newly created view. * @param manager The NewTabPageManager object used to open an article. * @param uiConfig The NTP UI configuration object used to adjust the article UI. */ public SnippetArticleViewHolder(NewTabPageRecyclerView parent, NewTabPageManager manager, UiConfig uiConfig) { super(R.layout.new_tab_page_snippets_card, parent, uiConfig, manager); mNewTabPageManager = manager; mThumbnailView = (ImageView) itemView.findViewById(R.id.article_thumbnail); mHeadlineTextView = (TextView) itemView.findViewById(R.id.article_headline); mPublisherTextView = (TextView) itemView.findViewById(R.id.article_publisher); mArticleSnippetTextView = (TextView) itemView.findViewById(R.id.article_snippet); mPublisherBar = itemView.findViewById(R.id.publisher_bar); mOfflineBadge = (ImageView) itemView.findViewById(R.id.offline_icon); new ImpressionTracker(itemView, this); mUiConfig = uiConfig; new DisplayStyleObserverAdapter(itemView, uiConfig, new DisplayStyleObserver() { @Override public void onDisplayStyleChanged(@UiConfig.DisplayStyle int newDisplayStyle) { updateLayout(); } }); mUseFaviconService = CardsVariationParameters.isFaviconServiceEnabled(); }
Example #2
Source File: NewTabPageAdapter.java From delion with Apache License 2.0 | 6 votes |
/** * Constructor to create the manager for all the cards to display on the NTP * * @param manager the NewTabPageManager to use to interact with the rest of the system. * @param newTabPageLayout the layout encapsulating all the above-the-fold elements * (logo, search box, most visited tiles) * @param snippetsBridge the bridge to interact with the snippets service. */ public NewTabPageAdapter(NewTabPageManager manager, NewTabPageLayout newTabPageLayout, SnippetsBridge snippetsBridge) { mNewTabPageManager = manager; mNewTabPageLayout = newTabPageLayout; mAboveTheFoldListItem = new AboveTheFoldListItem(); mHeaderListItem = new SnippetHeaderListItem(); mItemTouchCallbacks = new ItemTouchCallbacks(); mNewTabPageListItems = new ArrayList<NewTabPageListItem>(); mWantsSnippets = true; mSnippetsBridge = snippetsBridge; mStatusListItem = StatusListItem.create(snippetsBridge.getDisabledReason(), this, manager); loadSnippets(new ArrayList<SnippetArticle>()); mSnippetsBridge.setObserver(this); }
Example #3
Source File: ActionItem.java From AndroidChromium with Apache License 2.0 | 6 votes |
public ViewHolder(final NewTabPageRecyclerView recyclerView, final NewTabPageManager manager, UiConfig uiConfig) { super(R.layout.new_tab_page_action_card, recyclerView, uiConfig, manager); itemView.findViewById(R.id.action_button) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mActionListItem.performAction( manager, recyclerView.getNewTabPageAdapter()); } }); new ImpressionTracker(itemView, new ImpressionTracker.Listener() { @Override public void onImpression() { if (mActionListItem != null && !mActionListItem.mImpressionTracked) { mActionListItem.mImpressionTracked = true; manager.trackSnippetCategoryActionImpression( mActionListItem.mCategoryInfo.getCategory(), mActionListItem.getPosition()); } } }); }
Example #4
Source File: ActionItem.java From AndroidChromium with Apache License 2.0 | 6 votes |
@VisibleForTesting void performAction(NewTabPageManager manager, NewTabPageAdapter adapter) { manager.trackSnippetCategoryActionClick(mCategoryInfo.getCategory(), getPosition()); switch (mCurrentAction) { case ACTION_VIEW_ALL: mCategoryInfo.performViewAllAction(manager); return; case ACTION_FETCH_MORE: manager.getSuggestionsSource().fetchSuggestions( mCategoryInfo.getCategory(), mParentSection.getDisplayedSuggestionIds()); mParentSection.onFetchMore(); return; case ACTION_RELOAD: // TODO(dgn): reload only the current section. https://crbug.com/634892 adapter.reloadSnippets(); return; case ACTION_NONE: default: // Should never be reached. assert false; } }
Example #5
Source File: AllDismissedItem.java From AndroidChromium with Apache License 2.0 | 6 votes |
public ViewHolder( ViewGroup root, final NewTabPageManager manager, final NewTabPageAdapter adapter) { super(LayoutInflater.from(root.getContext()) .inflate(R.layout.new_tab_page_all_dismissed, root, false)); mBodyTextView = (TextView) itemView.findViewById(R.id.body_text); ((Button) itemView.findViewById(R.id.action_button)) .setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { NewTabPageUma.recordAction( NewTabPageUma.ACTION_CLICKED_ALL_DISMISSED_REFRESH); manager.getSuggestionsSource().restoreDismissedCategories(); adapter.resetSections(/*allowEmptySections=*/true); adapter.reloadSnippets(); } }); }
Example #6
Source File: Footer.java From AndroidChromium with Apache License 2.0 | 6 votes |
public ViewHolder(ViewGroup root, final NewTabPageManager manager) { super(LayoutInflater.from(root.getContext()) .inflate(R.layout.new_tab_page_footer, root, false)); NoUnderlineClickableSpan link = new NoUnderlineClickableSpan() { @Override public void onClick(View view) { // TODO(mvanouwerkerk): Ensure this can be activated when using TalkBack. manager.onLearnMoreClicked(); } }; TextView textView = (TextView) itemView.findViewById(R.id.text); textView.setText(SpanApplier.applySpans( root.getResources().getString(R.string.ntp_learn_more_about_suggested_content), new SpanApplier.SpanInfo("<link>", "</link>", link))); textView.setMovementMethod(LinkMovementMethod.getInstance()); }
Example #7
Source File: SuggestionsCategoryInfo.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Performs the View All action for the provided category, navigating navigating to the view * showing all the content. */ public void performViewAllAction(NewTabPageManager manager) { switch (mCategory) { case KnownCategories.BOOKMARKS: manager.navigateToBookmarks(); break; case KnownCategories.DOWNLOADS: manager.navigateToDownloadManager(); break; case KnownCategories.FOREIGN_TABS: manager.navigateToRecentTabs(); break; case KnownCategories.PHYSICAL_WEB_PAGES: case KnownCategories.RECENT_TABS: case KnownCategories.ARTICLES: default: Log.wtf(TAG, "'Empty State' action called for unsupported category: %d", mCategory); break; } }
Example #8
Source File: StatusListItem.java From delion with Apache License 2.0 | 5 votes |
public static StatusListItem create( int disabledReason, NewTabPageAdapter adapter, NewTabPageManager manager) { switch (disabledReason) { case DisabledReason.NONE: return new NoSnippets(adapter); case DisabledReason.SIGNED_OUT: return new SignedOut(); case DisabledReason.SYNC_DISABLED: return new SyncDisabled(); case DisabledReason.PASSPHRASE_ENCRYPTION_ENABLED: return new PassphraseEncryptionEnabled(manager); case DisabledReason.HISTORY_SYNC_STATE_UNKNOWN: // This should only be a transient state: during app launch, or when the sync // settings are being modified, and the user should never see a card showing this. // So let's just use HistorySyncDisabled as fallback. // TODO(dgn): If we add a spinner at some point (e.g. to show that we are fetching // snippets) we could use it here too. case DisabledReason.HISTORY_SYNC_DISABLED: return new HistorySyncDisabled(); case DisabledReason.EXPLICITLY_DISABLED: Log.wtf(TAG, "FATAL: Attempted to create a status card while the feature should be " + "off."); return null; default: Log.wtf(TAG, "FATAL: Attempted to create a status card for an unknown value: %d", disabledReason); return null; } }
Example #9
Source File: NewTabPageAdapter.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Creates the adapter that will manage all the cards to display on the NTP. * * @param manager the NewTabPageManager to use to interact with the rest of the system. * @param aboveTheFoldView the layout encapsulating all the above-the-fold elements * (logo, search box, most visited tiles) * @param uiConfig the NTP UI configuration, to be passed to created views. * @param offlinePageBridge the OfflinePageBridge used to determine if articles are available * offline. * */ public NewTabPageAdapter(NewTabPageManager manager, View aboveTheFoldView, UiConfig uiConfig, OfflinePageBridge offlinePageBridge) { mNewTabPageManager = manager; mAboveTheFoldView = aboveTheFoldView; mUiConfig = uiConfig; mOfflinePageBridge = offlinePageBridge; mRoot = new InnerNode(this) { @Override protected List<TreeNode> getChildren() { return mChildren; } @Override public void onItemRangeChanged(TreeNode child, int index, int count) { if (mChildren.isEmpty()) return; // The sections have not been initialised yet. super.onItemRangeChanged(child, index, count); } @Override public void onItemRangeInserted(TreeNode child, int index, int count) { if (mChildren.isEmpty()) return; // The sections have not been initialised yet. super.onItemRangeInserted(child, index, count); } @Override public void onItemRangeRemoved(TreeNode child, int index, int count) { if (mChildren.isEmpty()) return; // The sections have not been initialised yet. super.onItemRangeRemoved(child, index, count); } }; mSigninPromo = new SignInPromo(mRoot, this); DestructionObserver signInObserver = mSigninPromo.getObserver(); if (signInObserver != null) mNewTabPageManager.addDestructionObserver(signInObserver); resetSections(/*alwaysAllowEmptySections=*/false); mNewTabPageManager.getSuggestionsSource().setObserver(this); }
Example #10
Source File: SuggestionsSection.java From AndroidChromium with Apache License 2.0 | 5 votes |
private void setupOfflinePageBridgeObserver(NewTabPageManager manager) { final OfflinePageBridge.OfflinePageModelObserver observer = new OfflinePageBridge.OfflinePageModelObserver() { @Override public void offlinePageModelLoaded() { updateAllSnippetOfflineAvailability(); } @Override public void offlinePageModelChanged() { updateAllSnippetOfflineAvailability(); } @Override public void offlinePageDeleted(long offlineId, ClientId clientId) { for (SnippetArticle article : mSuggestionsList) { if (article.requiresExactOfflinePage()) continue; Long articleOfflineId = article.getOfflinePageOfflineId(); if (articleOfflineId == null) continue; if (articleOfflineId.longValue() != offlineId) continue; // The old value cannot be simply removed without a request to the // model, because there may be an older offline page for the same // URL. updateSnippetOfflineAvailability(article); } } }; mOfflinePageBridge.addObserver(observer); manager.addDestructionObserver(new DestructionObserver() { @Override public void onDestroy() { mIsNtpDestroyed = true; mOfflinePageBridge.removeObserver(observer); } }); }
Example #11
Source File: SuggestionsSection.java From AndroidChromium with Apache License 2.0 | 5 votes |
public SuggestionsSection(NodeParent parent, SuggestionsCategoryInfo info, NewTabPageManager manager, OfflinePageBridge offlinePageBridge) { super(parent); mCategoryInfo = info; mOfflinePageBridge = offlinePageBridge; mHeader = new SectionHeader(info.getTitle()); mSuggestionsList = new SuggestionsList(this); mStatus = StatusItem.createNoSuggestionsItem(this); mMoreButton = new ActionItem(this); mProgressIndicator = new ProgressItem(this); initializeChildren(); setupOfflinePageBridgeObserver(manager); }
Example #12
Source File: StatusCardViewHolder.java From AndroidChromium with Apache License 2.0 | 5 votes |
public StatusCardViewHolder( NewTabPageRecyclerView parent, NewTabPageManager newTabPageManager, UiConfig config) { super(R.layout.new_tab_page_status_card, parent, config, newTabPageManager); mTitleView = (TextView) itemView.findViewById(R.id.status_title); mBodyView = (TextView) itemView.findViewById(R.id.status_body); mActionView = (Button) itemView.findViewById(R.id.status_action_button); }
Example #13
Source File: StatusListItem.java From delion with Apache License 2.0 | 5 votes |
public PassphraseEncryptionEnabled(NewTabPageManager manager) { super(R.string.snippets_disabled_generic_prompt, R.string.snippets_disabled_passphrase_instructions, R.string.learn_more); mNewTabPageManager = manager; Log.d(TAG, "Registering card for status: Passphrase Encryption Enabled"); }
Example #14
Source File: CardViewHolder.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** * @param layoutId resource id of the layout to inflate and to use as card. * @param recyclerView ViewGroup that will contain the newly created view. * @param uiConfig The NTP UI configuration object used to adjust the card UI. */ public CardViewHolder(int layoutId, final NewTabPageRecyclerView recyclerView, UiConfig uiConfig, NewTabPageManager ntpManager) { super(inflateView(layoutId, recyclerView)); mCards9PatchAdjustment = recyclerView.getResources().getDimensionPixelSize( R.dimen.snippets_card_9_patch_adjustment); mMaxPeekPadding = recyclerView.getResources().getDimensionPixelSize( R.dimen.snippets_padding); mRecyclerView = recyclerView; itemView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (isPeeking()) { recyclerView.scrollToFirstCard(); } else { onCardTapped(); } } }); itemView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { if (isPeeking()) return; ContextMenuManager.Delegate delegate = getContextMenuDelegate(); if (delegate == null) return; mNtpManager.getContextMenuManager().createContextMenu(menu, itemView, delegate); } }); mUiConfig = uiConfig; mMarginResizer = MarginResizer.createWithViewAdapter(itemView, mUiConfig); // Configure the resizer to use negative margins on regular display to balance out the // lateral shadow of the card 9-patch and avoid a rounded corner effect. mMarginResizer.setMargins(-mCards9PatchAdjustment); mNtpManager = ntpManager; }
Example #15
Source File: SignInPromo.java From AndroidChromium with Apache License 2.0 | 4 votes |
public ViewHolder(NewTabPageRecyclerView parent, NewTabPageManager newTabPageManager, UiConfig config) { super(parent, newTabPageManager, config); mSeparationSpaceSize = parent.getResources().getDimensionPixelSize( R.dimen.ntp_sign_in_promo_margin_top); }
Example #16
Source File: LogoView.java From delion with Apache License 2.0 | 4 votes |
/** * Sets the NewTabPageManager to notify when the logo is pressed. */ public void setMananger(NewTabPageManager manager) { mManager = manager; }
Example #17
Source File: LogoView.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** * Sets the NewTabPageManager to notify when the logo is pressed. */ public void setMananger(NewTabPageManager manager) { mManager = manager; }
Example #18
Source File: ContextMenuManager.java From AndroidChromium with Apache License 2.0 | 4 votes |
public ContextMenuManager(NewTabPageManager newTabPageManager, ChromeActivity activity, TouchDisableableView outerView) { mManager = newTabPageManager; mActivity = activity; mOuterView = outerView; }
Example #19
Source File: NewTabPage.java From 365browser with Apache License 2.0 | 4 votes |
@VisibleForTesting public NewTabPageManager getManagerForTesting() { return mNewTabPageManager; }
Example #20
Source File: MostVisitedItem.java From AndroidChromium with Apache License 2.0 | 3 votes |
/** * Constructs a MostVisitedItem with the given manager, title, URL, whitelist icon path, index, * and view. * * @param manager The NewTabPageManager used to handle clicks and context menu events. * @param title The title of the page. * @param url The URL of the page. * @param whitelistIconPath The path to the icon image file, if this is a whitelisted most * visited item. Empty otherwise. * @param offlineAvailable Whether there is an offline copy of the URL available. * @param index The index of this item in the list of most visited items. * @param source The {@code MostVisitedSource} that generated this item. */ public MostVisitedItem(NewTabPageManager manager, String title, String url, String whitelistIconPath, boolean offlineAvailable, int index, int source) { mManager = manager; mTitle = title; mUrl = url; mWhitelistIconPath = whitelistIconPath; mOfflineAvailable = offlineAvailable; mIndex = index; mTileType = MostVisitedTileType.NONE; mSource = source; }