Java Code Examples for org.chromium.chrome.browser.ntp.snippets.SnippetsConfig#isIncreasedCardVisibilityEnabled()

The following examples show how to use org.chromium.chrome.browser.ntp.snippets.SnippetsConfig#isIncreasedCardVisibilityEnabled() . 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: NewTabPageRecyclerView.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the peeking state of the provided card. Relies on the dimensions of the header to
 * be correct, prefer {@link #updatePeekingCardAndHeader} that updates both together.
 */
public void updatePeekingCard(CardViewHolder peekingCard) {
    SectionHeaderViewHolder header = findFirstHeader();
    if (header == null) {
        // No header, we must have scrolled quite far. Fallback to a non animated (full bleed)
        // card.
        peekingCard.updatePeek(0, /* shouldAnimate */ false);
        return;
    }

    // Peeking is disabled in the card offset field trial and the increased visibility feature.
    if (CardsVariationParameters.getFirstCardOffsetDp() != 0
            || SnippetsConfig.isIncreasedCardVisibilityEnabled()) {
        peekingCard.updatePeek(0, /* shouldAnimate */ false);
        return;
    }

    // Here we consider that if the header is animating (is not completely expanded), the card
    // should as well. In that case, the space below the header is what we have available.
    boolean shouldAnimate = header.itemView.getHeight() < mMaxHeaderHeight;
    peekingCard.updatePeek(getHeight() - header.itemView.getBottom(), shouldAnimate);
}
 
Example 2
Source File: NewTabPageRecyclerView.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * To be triggered when a snippet is bound to a ViewHolder.
 */
public void onSnippetBound(View cardView) {
    // We only run if the feature is enabled and once per NTP.
    if (!SnippetsConfig.isIncreasedCardVisibilityEnabled() || mFirstCardAnimationRun) return;
    mFirstCardAnimationRun = true;

    // We only want an animation to run if we are not scrolled.
    if (computeVerticalScrollOffset() != 0) return;

    // We only show the animation a certain number of times to a user.
    ChromePreferenceManager manager = ChromePreferenceManager.getInstance(getContext());
    int animCount = manager.getNewTabPageFirstCardAnimationRunCount();
    if (animCount > CardsVariationParameters.getFirstCardAnimationMaxRuns()) return;
    manager.setNewTabPageFirstCardAnimationRunCount(animCount + 1);

    // We do not show the animation if the user has previously seen it then scrolled.
    if (manager.getCardsImpressionAfterAnimation()) return;

    // The peeking card bounces up twice from its position.
    ObjectAnimator animator = ObjectAnimator.ofFloat(cardView, View.TRANSLATION_Y,
            0f, -mPeekingCardBounceDistance, 0f, -mPeekingCardBounceDistance, 0f);
    animator.setStartDelay(PEEKING_CARD_ANIMATION_START_DELAY_MS);
    animator.setDuration(PEEKING_CARD_ANIMATION_TIME_MS);
    animator.setInterpolator(PEEKING_CARD_INTERPOLATOR);
    animator.start();
}
 
Example 3
Source File: NewTabPageLayout.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor for inflating from XML.
 */
public NewTabPageLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    Resources res = getResources();
    float density = res.getDisplayMetrics().density;
    mTopSpacerIdealHeight = Math.round(density * TOP_SPACER_HEIGHT_DP);
    mMiddleSpacerIdealHeight = Math.round(density * MIDDLE_SPACER_HEIGHT_DP);
    mBottomSpacerIdealHeight = Math.round(density * BOTTOM_SPACER_HEIGHT_DP);
    mTotalSpacerIdealHeight = Math.round(density * TOTAL_SPACER_HEIGHT_DP);
    mMostVisitedLayoutBleed = res.getDimensionPixelSize(R.dimen.most_visited_layout_bleed);
    mPeekingCardHeight = SnippetsConfig.isIncreasedCardVisibilityEnabled()
            ? res.getDimensionPixelSize(R.dimen.snippets_peeking_card_peek_amount)
            : res.getDimensionPixelSize(R.dimen.snippets_padding);
    mTabStripHeight = res.getDimensionPixelSize(R.dimen.tab_strip_height);
    mFieldTrialLayoutAdjustment = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            CardsVariationParameters.getFirstCardOffsetDp(), res.getDisplayMetrics());
    mSearchboxShadowWidth = res.getDimensionPixelOffset(R.dimen.ntp_search_box_shadow_width);
}
 
Example 4
Source File: NewTabPageLayout.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor for inflating from XML.
 */
public NewTabPageLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    Resources res = getResources();
    float density = res.getDisplayMetrics().density;
    mTopSpacerIdealHeight = Math.round(density * TOP_SPACER_HEIGHT_DP);
    mMiddleSpacerIdealHeight = Math.round(density * MIDDLE_SPACER_HEIGHT_DP);
    mBottomSpacerIdealHeight = Math.round(density * BOTTOM_SPACER_HEIGHT_DP);
    mTotalSpacerIdealHeight = Math.round(density * TOTAL_SPACER_HEIGHT_DP);
    mTileGridLayoutBleed = res.getDimensionPixelSize(R.dimen.tile_grid_layout_bleed);
    mPeekingCardHeight = SnippetsConfig.isIncreasedCardVisibilityEnabled()
            ? res.getDimensionPixelSize(R.dimen.snippets_peeking_card_peek_amount)
            : res.getDimensionPixelSize(R.dimen.snippets_padding);
    mTabStripHeight = res.getDimensionPixelSize(R.dimen.tab_strip_height);
    mFieldTrialLayoutAdjustment = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            CardsVariationParameters.getFirstCardOffsetDp(), res.getDisplayMetrics());
    mSearchboxShadowWidth = res.getDimensionPixelOffset(R.dimen.ntp_search_box_shadow_width);
}
 
Example 5
Source File: NewTabPageRecyclerView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private boolean shouldAnimateFirstCard() {
    // The "bouncing" animation for the first card is only enabled if
    // 1) there is space for it, ...
    if (!mHasSpaceForPeekingCard) return false;

    // ... 2) the corresponding feature is enabled, ...
    if (!SnippetsConfig.isIncreasedCardVisibilityEnabled()) return false;

    // ... 3) and the animation hasn't run yet.
    return !mFirstCardAnimationRun;
}
 
Example 6
Source File: NewTabPageRecyclerView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private boolean shouldPeekFirstCard() {
    // Peeking above the fold is only enabled if there is space.
    if (!mHasSpaceForPeekingCard) return false;

    // It's also disabled in the card offset field trial...
    if (CardsVariationParameters.getFirstCardOffsetDp() > 0) return false;

    // ...and in the increased visibility (bouncing animation) feature.
    return !SnippetsConfig.isIncreasedCardVisibilityEnabled();
}