org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView Java Examples

The following examples show how to use org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView. 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 vote down vote up
/**
 * 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: SnippetHeaderViewHolder.java    From delion with Apache License 2.0 5 votes vote down vote up
public SnippetHeaderViewHolder(final View cardView, final NewTabPageRecyclerView recyclerView) {
    super(cardView);
    mMaxSnippetHeaderHeight = cardView.getResources().getDimensionPixelSize(
            R.dimen.snippets_article_header_height);

    mMaxPeekPadding = cardView.getResources().getDimensionPixelSize(
            R.dimen.snippets_padding_and_peeking_card_height);

    mRecyclerView = recyclerView;
}
 
Example #3
Source File: SectionHeaderViewHolder.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
public SectionHeaderViewHolder(final NewTabPageRecyclerView recyclerView, UiConfig config) {
    super(LayoutInflater.from(recyclerView.getContext())
                    .inflate(R.layout.new_tab_page_snippets_header, recyclerView, false));
    mMaxSnippetHeaderHeight = itemView.getResources().getDimensionPixelSize(
            R.dimen.snippets_article_header_height);
    MarginResizer.createWithViewAdapter(itemView, config);
}
 
Example #4
Source File: NewTabPageView.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public NewTabPageRecyclerView getRecyclerView() {
    return mRecyclerView;
}
 
Example #5
Source File: NewTabPageLayout.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Uses the total vertical space to determine and configure the layout. This can be one of:
 * - If our contents cannot fit on the screen, increase the spacing to push the Most Likely
 *   partially off the screen, suggesting to users they can scroll.
 * - If our contents can fit on the screen, increase the spacing to fill the space (minus space
 *   for the CardsUI Peeking card).
 */
private void calculateVerticalSpacing(int widthMeasureSpec, int heightMeasureSpec) {
    mLogoSpacer.setVisibility(View.GONE);
    mSearchBoxSpacer.setVisibility(View.GONE);

    // Remove the extra spacing before measuring because it might not be needed anymore.
    mTileGridLayout.setExtraVerticalSpacing(0);

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    boolean hasSpaceForPeekingCard = false;
    int spaceToFill = mParentViewportHeight - mPeekingCardHeight - mTabStripHeight;
    @NTPLayoutResult int layoutResult;

    if (ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_CONDENSED_LAYOUT)) {
        layoutResult = NewTabPageUma.NTP_LAYOUT_CONDENSED;
    } else if (getMeasuredHeight() > spaceToFill) {
        // We need to make sure we have just enough space to show the peeking card.
        layoutResult = NewTabPageUma.NTP_LAYOUT_DOES_NOT_FIT;

        // We don't have enough, we will push the peeking card completely below the fold
        // and let the tile grid get cut to make it clear that the page is scrollable.
        if (mTileGridLayout.getChildCount() > 0) {
            // Add some extra space if needed (the 'bleed' is the amount of the layout that
            // will be cut off by the bottom of the screen).
            int currentBleed = getMeasuredHeight() - mParentViewportHeight - mTabStripHeight;
            int minimumBleed = (int) (mTileGridLayout.getChildAt(0).getMeasuredHeight() * 0.44);
            if (currentBleed < minimumBleed) {
                int extraBleed = minimumBleed - currentBleed;
                mLogoSpacer.getLayoutParams().height = (int) (extraBleed * 0.25);
                mLogoSpacer.setVisibility(View.INVISIBLE);
                mSearchBoxSpacer.getLayoutParams().height = (int) (extraBleed * 0.25);
                mSearchBoxSpacer.setVisibility(View.INVISIBLE);
                mTileGridLayout.setExtraVerticalSpacing((int) (extraBleed * 0.5));
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);

                layoutResult = NewTabPageUma.NTP_LAYOUT_DOES_NOT_FIT_PUSH_MOST_LIKELY;
            }
        }
    } else {
        hasSpaceForPeekingCard = true;
        // We leave more than or just enough space needed for the peeking card. Redistribute
        // any weighted space.

        // There is a field trial experiment to determine the effect of raising the peeking
        // card, allowing the user to see some of it's contents when scrolled to the top. This
        // is achieved by making the NewTabPageLayout smaller.
        // If there is enough space, reduce the space we are going to fill.
        if (mFieldTrialLayoutAdjustment != 0f) {
            if (getMeasuredHeight() < spaceToFill - mFieldTrialLayoutAdjustment) {
                spaceToFill -= mFieldTrialLayoutAdjustment;
                layoutResult = NewTabPageUma.NTP_LAYOUT_FITS_WITH_FIELD_TRIAL;
            } else {
                layoutResult = NewTabPageUma.NTP_LAYOUT_FITS_WITHOUT_FIELD_TRIAL;
            }
        } else {
            layoutResult = NewTabPageUma.NTP_LAYOUT_FITS_NO_FIELD_TRIAL;
        }

        // Call super.onMeasure with mode EXACTLY and the target height to allow the top
        // spacer (which has a weight of 1) to grow and take up the remaining space.
        heightMeasureSpec =
                MeasureSpec.makeMeasureSpec(spaceToFill, MeasureSpec.EXACTLY);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        distributeExtraSpace(mTopSpacer.getMeasuredHeight());
    }

    NewTabPageRecyclerView recyclerView = (NewTabPageRecyclerView) getParent();
    recyclerView.setHasSpaceForPeekingCard(hasSpaceForPeekingCard);

    // The first few runs of this method occur before the tile grid layout has loaded its
    // contents. We want to record what the user sees when the layout has stabilized.
    if (mTileGridLayout.getChildCount() > 0 && !mLayoutResultRecorded) {
        mLayoutResultRecorded = true;
        NewTabPageUma.recordNTPLayoutResult(layoutResult);
    }
}