Search in sources :

Example 6 with NewTabPage

use of org.chromium.chrome.browser.ntp.NewTabPage in project AndroidChromium by JackyAndroid.

the class ToolbarLayout method onTabOrModelChanged.

/**
     * Triggered when the current tab or model has changed.
     * <p>
     * As there are cases where you can select a model with no tabs (i.e. having incognito
     * tabs but no normal tabs will still allow you to select the normal model), this should
     * not guarantee that the model's current tab is non-null.
     */
protected void onTabOrModelChanged() {
    NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
    if (ntp != null) {
        getLocationBar().onTabLoadingNTP(ntp);
    }
    getLocationBar().updateMicButtonState();
}
Also used : NewTabPage(org.chromium.chrome.browser.ntp.NewTabPage)

Example 7 with NewTabPage

use of org.chromium.chrome.browser.ntp.NewTabPage in project AndroidChromium by JackyAndroid.

the class ToolbarTablet method updateNtp.

/**
     * Called when the currently visible New Tab Page changes.
     */
private void updateNtp() {
    NewTabPage newVisibleNtp = getToolbarDataProvider().getNewTabPageForCurrentTab();
    if (mVisibleNtp == newVisibleNtp)
        return;
    if (mVisibleNtp != null) {
        mVisibleNtp.setSearchBoxScrollListener(null);
    }
    mVisibleNtp = newVisibleNtp;
    if (mVisibleNtp != null) {
        mVisibleNtp.setSearchBoxScrollListener(new NewTabPage.OnSearchBoxScrollListener() {

            @Override
            public void onNtpScrollChanged(float scrollPercentage) {
                // Fade the search box out in the first 40% of the scrolling transition.
                float alpha = Math.max(1f - scrollPercentage * 2.5f, 0f);
                mVisibleNtp.setSearchBoxAlpha(alpha);
                mVisibleNtp.setSearchProviderLogoAlpha(alpha);
            }
        });
    }
}
Also used : NewTabPage(org.chromium.chrome.browser.ntp.NewTabPage)

Example 8 with NewTabPage

use of org.chromium.chrome.browser.ntp.NewTabPage in project AndroidChromium by JackyAndroid.

the class ToolbarPhone method updateNtpTransitionAnimation.

/**
     * 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));
    }
}
Also used : NewTabPage(org.chromium.chrome.browser.ntp.NewTabPage) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Aggregations

NewTabPage (org.chromium.chrome.browser.ntp.NewTabPage)8 SuppressLint (android.annotation.SuppressLint)2 Point (android.graphics.Point)2 Tab (org.chromium.chrome.browser.tab.Tab)2 Context (android.content.Context)1 FrameLayout (android.widget.FrameLayout)1 NativePage (org.chromium.chrome.browser.NativePage)1 WindowDelegate (org.chromium.chrome.browser.WindowDelegate)1 IncognitoNewTabPage (org.chromium.chrome.browser.ntp.IncognitoNewTabPage)1