Java Code Examples for org.chromium.chrome.browser.ntp.NewTabPage#getSearchBoxBounds()

The following examples show how to use org.chromium.chrome.browser.ntp.NewTabPage#getSearchBoxBounds() . 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: ToolbarPhone.java    From delion with Apache License 2.0 4 votes vote down vote up
private void updateNtpTransitionAnimation() {
    if (mIsInTabSwitcherMode) return;

    NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();

    setAncestorsShouldClipChildren(mUrlExpansionPercent == 0f);
    mToolbarShadow.setAlpha(0f);

    float growthPercent = 0f;
    if (ntp.isCardsUiEnabled() || mUrlExpansionPercent == 0f || mUrlExpansionPercent == 1f) {
        growthPercent = 1f - mUrlExpansionPercent;
    } else {
        // During the transition from search box to omnibox, keep the omnibox drawing
        // at the same size of the search box for first 40% of the scroll transition.
        growthPercent = mUrlExpansionPercent <= 0.4f
                ? 1f : Math.min(1f, (1f - mUrlExpansionPercent) * 1.66667f);
    }

    int paddingTop = mPhoneLocationBar.getPaddingTop();
    int paddingBottom = mPhoneLocationBar.getPaddingBottom();

    ntp.getSearchBoxBounds(mNtpSearchBoxOriginalBounds, mNtpSearchBoxTransformedBounds);
    float halfHeightDifference = (mNtpSearchBoxTransformedBounds.height()
            - (mPhoneLocationBar.getMeasuredHeight() - paddingTop - paddingBottom
                    + mLocationBarInsets)) / 2f;
    mPhoneLocationBar.setTranslationY(growthPercent == 0f ? 0 : Math.max(0,
            (mNtpSearchBoxTransformedBounds.top - mPhoneLocationBar.getTop()
                    + halfHeightDifference)));
    if (!mUrlFocusChangeInProgress) {
        float searchBoxTranslationY =
                mNtpSearchBoxTransformedBounds.top - mNtpSearchBoxOriginalBounds.top;
        searchBoxTranslationY = Math.min(searchBoxTranslationY, 0);
        mToolbarButtonsContainer.setTranslationY(searchBoxTranslationY);
        mReturnButton.setTranslationY(searchBoxTranslationY);
        mHomeButton.setTranslationY(searchBoxTranslationY);
    }

    mLocationBarBackgroundOffset.set(
            (int) ((mNtpSearchBoxTransformedBounds.left - mUrlViewportBounds.left
                    - mPhoneLocationBar.getPaddingLeft()) * growthPercent),
            (int) ((-halfHeightDifference - paddingTop) * growthPercent),
            (int) ((mNtpSearchBoxTransformedBounds.right - mUrlViewportBounds.right
                    + mPhoneLocationBar.getPaddingRight()) * growthPercent),
            (int) ((halfHeightDifference - paddingBottom + mLocationBarInsets)
                    * growthPercent));

    // The transparency of the location bar is dependent on how different its size is
    // from the final value.  This is based on how much growth is applied between the
    // desired size of the location bar to its drawn size.  The location bar then only
    // starts becoming opaque once the growth is at least half done.
    if (growthPercent >= 0.5f) {
        mPhoneLocationBar.setAlpha(0);
    } else {
        mPhoneLocationBar.setAlpha(1f - growthPercent * 2);
    }

    // Go from a transparent url background to a fully opaque one in the first 40% of the
    // scroll transition.
    mUrlBackgroundAlpha =
            mUrlExpansionPercent >= 0.4f ? 255 : (int) ((mUrlExpansionPercent * 2.5f) * 255);
    if (mUrlExpansionPercent == 1f) mUrlBackgroundAlpha = 255;
    mForceDrawLocationBarBackground = mUrlExpansionPercent != 0f;
}
 
Example 2
Source File: ToolbarPhone.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the parameters of the New Tab Page transition animation (expanding the location bar
 * as a result of scrolling the New Tab Page).
 */
private void updateNtpTransitionAnimation() {
    // Skip if in or entering tab switcher mode.
    if (mTabSwitcherState == TAB_SWITCHER || mTabSwitcherState == ENTERING_TAB_SWITCHER) return;

    setAncestorsShouldClipChildren(mUrlExpansionPercent == 0f);
    mToolbarShadow.setAlpha(0f);

    NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
    ntp.getSearchBoxBounds(mNtpSearchBoxBounds, mNtpSearchBoxTranslation);
    int locationBarTranslationY =
            Math.max(0, (mNtpSearchBoxBounds.top - mLocationBar.getTop()));
    mLocationBar.setTranslationY(locationBarTranslationY);
    updateButtonsTranslationY();

    // Linearly interpolate between the bounds of the search box on the NTP and the omnibox
    // background bounds. |shrinkage| is the scaling factor for the offset -- if it's 1, we are
    // shrinking the omnibox down to the size of the search box.
    float shrinkage;
    if (ntp.isCardsUiEnabled()) {
        shrinkage = 1f
                - NTP_SEARCH_BOX_EXPANSION_INTERPOLATOR.getInterpolation(mUrlExpansionPercent);
    } else {
        // During the transition from middle of the NTP to the top, keep the omnibox drawing
        // at the same size of the search box for first 40% of the scroll transition.
        shrinkage = Math.min(1f, (1f - mUrlExpansionPercent) * 1.66667f);
    }

    int leftBoundDifference = mNtpSearchBoxBounds.left - mLocationBarBackgroundBounds.left;
    int rightBoundDifference = mNtpSearchBoxBounds.right - mLocationBarBackgroundBounds.right;
    mLocationBarBackgroundNtpOffset.set(
            Math.round(leftBoundDifference * shrinkage),
            locationBarTranslationY,
            Math.round(rightBoundDifference * shrinkage),
            locationBarTranslationY);

    // The omnibox background bounds are outset by |mLocationBarBackgroundCornerRadius| in the
    // fully expanded state (and only there!) to hide the rounded corners, so undo that before
    // applying the shrinkage factor.
    mLocationBarNtpOffsetLeft =
            (leftBoundDifference - mLocationBarBackgroundCornerRadius) * shrinkage;
    mLocationBarNtpOffsetRight =
            (rightBoundDifference + mLocationBarBackgroundCornerRadius) * shrinkage;

    mLocationBarBackgroundAlpha = mUrlExpansionPercent > 0f ? 255 : 0;
    mForceDrawLocationBarBackground = mLocationBarBackgroundAlpha > 0;
    float relativeAlpha = mLocationBarBackgroundAlpha / 255f;
    mLocationBar.setAlpha(relativeAlpha);

    // The search box on the NTP is visible if our omnibox is invisible, and vice-versa.
    ntp.setSearchBoxAlpha(1f - relativeAlpha);

    if (!ntp.isCardsUiEnabled()) {
        ntp.setSearchProviderLogoAlpha(Math.max(1f - mUrlExpansionPercent * 2.5f, 0f));
    }
}
 
Example 3
Source File: ToolbarPhone.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the parameters of the New Tab Page transition animation (expanding the location bar
 * as a result of scrolling the New Tab Page).
 */
private void updateNtpTransitionAnimation() {
    // Skip if in or entering tab switcher mode.
    if (mTabSwitcherState == TAB_SWITCHER || mTabSwitcherState == ENTERING_TAB_SWITCHER) return;

    setAncestorsShouldClipChildren(mUrlExpansionPercent == 0f);
    mToolbarShadow.setAlpha(0f);

    NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
    ntp.getSearchBoxBounds(mNtpSearchBoxBounds, mNtpSearchBoxTranslation);
    int locationBarTranslationY =
            Math.max(0, (mNtpSearchBoxBounds.top - mLocationBar.getTop()));
    mLocationBar.setTranslationY(locationBarTranslationY);
    updateButtonsTranslationY();

    // Linearly interpolate between the bounds of the search box on the NTP and the omnibox
    // background bounds. |shrinkage| is the scaling factor for the offset -- if it's 1, we are
    // shrinking the omnibox down to the size of the search box.
    float shrinkage =
            1f - NTP_SEARCH_BOX_EXPANSION_INTERPOLATOR.getInterpolation(mUrlExpansionPercent);

    int leftBoundDifference = mNtpSearchBoxBounds.left - mLocationBarBackgroundBounds.left;
    int rightBoundDifference = mNtpSearchBoxBounds.right - mLocationBarBackgroundBounds.right;
    mLocationBarBackgroundNtpOffset.set(
            Math.round(leftBoundDifference * shrinkage),
            locationBarTranslationY,
            Math.round(rightBoundDifference * shrinkage),
            locationBarTranslationY);

    // The omnibox background bounds are outset by |mLocationBarBackgroundCornerRadius| in the
    // fully expanded state (and only there!) to hide the rounded corners, so undo that before
    // applying the shrinkage factor.
    mLocationBarNtpOffsetLeft =
            (leftBoundDifference - mLocationBarBackgroundCornerRadius) * shrinkage;
    mLocationBarNtpOffsetRight =
            (rightBoundDifference + mLocationBarBackgroundCornerRadius) * shrinkage;

    mLocationBarBackgroundAlpha = mUrlExpansionPercent > 0f ? 255 : 0;
    mForceDrawLocationBarBackground = mLocationBarBackgroundAlpha > 0;
    float relativeAlpha = mLocationBarBackgroundAlpha / 255f;
    mLocationBar.setAlpha(relativeAlpha);

    // The search box on the NTP is visible if our omnibox is invisible, and vice-versa.
    ntp.setSearchBoxAlpha(1f - relativeAlpha);
}