org.chromium.chrome.browser.ntp.NewTabPage Java Examples

The following examples show how to use org.chromium.chrome.browser.ntp.NewTabPage. 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: LocationBarLayout.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Set the background of the omnibox results container.
 * @param visible Whether the background should be made visible.
 */
private void updateOmniboxResultsContainerBackground(boolean visible) {
    if (getToolbarDataProvider() == null) return;

    NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
    boolean locationBarShownInNTP = ntp != null && ntp.isLocationBarShownInNTP();
    if (visible) {
        if (locationBarShownInNTP) {
            mOmniboxResultsContainer.getBackground().setAlpha(0);
        } else {
            fadeInOmniboxResultsContainerBackground();
        }
    } else {
        if (locationBarShownInNTP) {
            updateOmniboxResultsContainerVisibility(false);
        } else {
            fadeOutOmniboxResultsContainerBackground();
        }
    }
}
 
Example #2
Source File: ToolbarTablet.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
            }
        });
    }
}
 
Example #3
Source File: LocationBarLayout.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Update the fading background view that shows when the omnibox is focused. If Chrome Home is
 * enabled, this method is a no-op.
 * @param visible Whether the background should be made visible.
 */
private void updateFadingBackgroundView(boolean visible) {
    if (mFadingView == null) initFadingOverlayView();

    // If Chrome Home is enabled (the bottom sheet is not null), it will be controlling the
    // fading view, so block any updating here.
    if (getToolbarDataProvider() == null || mBottomSheet != null) return;

    NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
    boolean locationBarShownInNTP = ntp != null && ntp.isLocationBarShownInNTP();

    if (visible && !locationBarShownInNTP) {
        // If the location bar is shown in the NTP, the toolbar will eventually trigger a
        // fade in.
        mFadingView.showFadingOverlay();
    } else {
        mFadingView.hideFadingOverlay(!locationBarShownInNTP);
    }
}
 
Example #4
Source File: ToolbarTablet.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
            }
        });
    }
}
 
Example #5
Source File: LocationBarLayout.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Set the background of the omnibox results container.
 * @param visible Whether the background should be made visible.
 */
private void updateOmniboxResultsContainerBackground(boolean visible) {
    if (getToolbarDataProvider() == null) return;

    NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
    boolean locationBarShownInNTP = ntp != null && ntp.isLocationBarShownInNTP();
    if (visible) {
        if (locationBarShownInNTP) {
            mOmniboxResultsContainer.getBackground().setAlpha(0);
        } else {
            fadeInOmniboxResultsContainerBackground();
        }
    } else {
        if (locationBarShownInNTP) {
            updateOmniboxResultsContainerVisibility(false);
        } else {
            fadeOutOmniboxResultsContainerBackground();
        }
    }
}
 
Example #6
Source File: ColorUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return The base color for the textbox given a toolbar background color.
 */
public static int getTextBoxColorForToolbarBackground(Resources res, Tab tab, int color) {
    if (shouldUseOpaqueTextboxBackground(color)) {
        // NTP should have no visible textbox in the toolbar, so just return the toolbar's
        // background color.
        if (tab.getNativePage() instanceof NewTabPage) {
            return ApiCompatibilityUtils.getColor(res, R.color.ntp_bg);
        }

        return Color.WHITE;
    }
    return getColorWithOverlay(color, Color.WHITE, LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA);
}
 
Example #7
Source File: ChromeTabbedActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Create an initial tab for cold start without restored tabs.
 */
private void createInitialTab() {
    String url = HomepageManager.getHomepageUri(getApplicationContext());
    if (TextUtils.isEmpty(url) || NewTabPage.isNTPUrl(url)) {
        url = UrlConstants.NTP_URL;
    }

    getTabCreator(false).launchUrl(url, TabLaunchType.FROM_CHROME_UI);
}
 
Example #8
Source File: ToolbarModelImpl.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public NewTabPage getNewTabPageForCurrentTab() {
    Tab currentTab = getTab();
    if (currentTab != null && currentTab.getNativePage() instanceof NewTabPage) {
        return (NewTabPage) currentTab.getNativePage();
    }
    return null;
}
 
Example #9
Source File: ToolbarLayout.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #10
Source File: ActivityTabTaskDescriptionHelper.java    From delion with Apache License 2.0 5 votes vote down vote up
private void updateTaskDescription() {
    if (mCurrentTab == null) {
        updateTaskDescription(null, null);
        return;
    }

    if (NewTabPage.isNTPUrl(mCurrentTab.getUrl()) && !mCurrentTab.isIncognito()) {
        // NTP needs a new color in recents, but uses the default application title and icon
        updateTaskDescription(null, null);
        return;
    }

    String label = mCurrentTab.getTitle();
    String domain = UrlUtilities.getDomainAndRegistry(mCurrentTab.getUrl(), false);
    if (TextUtils.isEmpty(label)) {
        label = domain;
    }
    if (mLargestFavicon == null && TextUtils.isEmpty(label)) {
        updateTaskDescription(null, null);
        return;
    }

    Bitmap bitmap = null;
    if (!mCurrentTab.isIncognito()) {
        bitmap = mIconGenerator.getBitmap(mCurrentTab.getUrl(), mLargestFavicon);
    }

    updateTaskDescription(label, bitmap);
}
 
Example #11
Source File: ToolbarPhone.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent ev) {
    // Forward touch events to the NTP if the toolbar is moved away but the search box hasn't
    // reached the top of the page yet.
    if (mNtpSearchBoxTranslation.y < 0 && mLocationBar.getTranslationY() > 0) {
        NewTabPage newTabPage = getToolbarDataProvider().getNewTabPageForCurrentTab();

        // No null check -- the toolbar should not be moved if we are not on an NTP.
        return newTabPage.getView().dispatchTouchEvent(ev);
    }
    return super.onTouchEvent(ev);
}
 
Example #12
Source File: ToolbarModelImpl.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public NewTabPage getNewTabPageForCurrentTab() {
    Tab currentTab = getTab();
    if (currentTab != null && currentTab.getNativePage() instanceof NewTabPage) {
        return (NewTabPage) currentTab.getNativePage();
    }
    return null;
}
 
Example #13
Source File: ColorUtils.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * @return Alpha for the textbox given a Tab.
 */
public static float getTextBoxAlphaForToolbarBackground(Tab tab) {
    int color = tab.getThemeColor();
    if (tab.getNativePage() instanceof NewTabPage) {
        if (((NewTabPage) tab.getNativePage()).isLocationBarShownInNTP()) return 0f;
    }
    return shouldUseOpaqueTextboxBackground(color)
            ? 1f : LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA;
}
 
Example #14
Source File: ColorUtils.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * @return The base color for the textbox given a toolbar background color.
 */
public static int getTextBoxColorForToolbarBackground(Resources res, Tab tab, int color) {
    if (shouldUseOpaqueTextboxBackground(color)) {
        // NTP should have no visible textbox in the toolbar, so just return the toolbar's
        // background color.
        if (tab.getNativePage() instanceof NewTabPage) {
            return NtpColorUtils.getToolbarBackgroundColorResource(res);
        }

        return Color.WHITE;
    }
    return getColorWithOverlay(color, Color.WHITE, LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA);
}
 
Example #15
Source File: ActivityTabTaskDescriptionHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void updateTaskDescription() {
    if (mCurrentTab == null) {
        updateTaskDescription(null, null);
        return;
    }

    if (NewTabPage.isNTPUrl(mCurrentTab.getUrl()) && !mCurrentTab.isIncognito()) {
        // NTP needs a new color in recents, but uses the default application title and icon
        updateTaskDescription(null, null);
        return;
    }

    String label = mCurrentTab.getTitle();
    String domain = UrlUtilities.getDomainAndRegistry(mCurrentTab.getUrl(), false);
    if (TextUtils.isEmpty(label)) {
        label = domain;
    }
    if (mLargestFavicon == null && TextUtils.isEmpty(label)) {
        updateTaskDescription(null, null);
        return;
    }

    Bitmap bitmap = null;
    if (!mCurrentTab.isIncognito()) {
        bitmap = mIconGenerator.getBitmap(mCurrentTab.getUrl(), mLargestFavicon);
    }

    updateTaskDescription(label, bitmap);
}
 
Example #16
Source File: ToolbarLayout.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #17
Source File: ToolbarManager.java    From delion with Apache License 2.0 5 votes vote down vote up
private boolean shouldShowCusrsorInLocationBar() {
    Tab tab = mToolbarModel.getTab();
    if (tab == null) return false;
    NativePage nativePage = tab.getNativePage();
    if (!(nativePage instanceof NewTabPage) && !(nativePage instanceof IncognitoNewTabPage)) {
        return false;
    }

    Context context = mToolbar.getContext();
    return DeviceFormFactor.isTablet(context)
            && context.getResources().getConfiguration().keyboard
            == Configuration.KEYBOARD_QWERTY;
}
 
Example #18
Source File: ColorUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return Alpha for the textbox given a Tab.
 */
public static float getTextBoxAlphaForToolbarBackground(Tab tab) {
    int color = tab.getThemeColor();
    if (tab.getNativePage() instanceof NewTabPage) {
        if (((NewTabPage) tab.getNativePage()).isLocationBarShownInNTP()) return 0f;
    }
    return shouldUseOpaqueTextboxBackground(color)
            ? 1f : LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA;
}
 
Example #19
Source File: ToolbarManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private boolean shouldShowCusrsorInLocationBar() {
    Tab tab = mToolbarModel.getTab();
    if (tab == null) return false;
    NativePage nativePage = tab.getNativePage();
    if (!(nativePage instanceof NewTabPage) && !(nativePage instanceof IncognitoNewTabPage)) {
        return false;
    }

    Context context = mToolbar.getContext();
    return DeviceFormFactor.isTablet(context)
            && context.getResources().getConfiguration().keyboard
            == Configuration.KEYBOARD_QWERTY;
}
 
Example #20
Source File: LayoutManagerDocument.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void initLayoutTabFromHost(final int tabId) {
    if (getTabModelSelector() == null || getActiveLayout() == null) return;

    TabModelSelector selector = getTabModelSelector();
    Tab tab = selector.getTabById(tabId);
    if (tab == null) return;

    LayoutTab layoutTab = mTabCache.get(tabId);
    if (layoutTab == null) return;

    String url = tab.getUrl();
    boolean isNativePage = url != null && url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX);
    int themeColor = tab.getThemeColor();

    boolean canUseLiveTexture =
            tab.getContentViewCore() != null && !tab.isShowingSadTab() && !isNativePage;

    boolean isNtp = tab.getNativePage() instanceof NewTabPage;
    boolean needsUpdate = layoutTab.initFromHost(tab.getBackgroundColor(), tab.shouldStall(),
            canUseLiveTexture, themeColor,
            ColorUtils.getTextBoxColorForToolbarBackground(
                    mContext.getResources(), isNtp, themeColor),
            ColorUtils.getTextBoxAlphaForToolbarBackground(tab));
    if (needsUpdate) requestUpdate();

    mHost.requestRender();
}
 
Example #21
Source File: MainIntentBehaviorMetrics.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Signal that an intent with ACTION_MAIN was received.
 *
 * This must only be called after the native libraries have been initialized.
 */
@SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
public void onMainIntentWithNative(long backgroundDurationMs) {
    sLastMainIntentBehavior = null;

    RecordUserAction.record("MobileStartup.MainIntentReceived");

    if (backgroundDurationMs >= BACKGROUND_TIME_24_HOUR_MS) {
        RecordUserAction.record("MobileStartup.MainIntentReceived.After24Hours");
    } else if (backgroundDurationMs >= BACKGROUND_TIME_12_HOUR_MS) {
        RecordUserAction.record("MobileStartup.MainIntentReceived.After12Hours");
    } else if (backgroundDurationMs >= BACKGROUND_TIME_6_HOUR_MS) {
        RecordUserAction.record("MobileStartup.MainIntentReceived.After6Hours");
    } else if (backgroundDurationMs >= BACKGROUND_TIME_1_HOUR_MS) {
        RecordUserAction.record("MobileStartup.MainIntentReceived.After1Hour");
    }

    if (mPendingActionRecordForMainIntent) return;
    mBackgroundDurationMs = backgroundDurationMs;

    ApplicationStatus.registerStateListenerForActivity(this, mActivity);
    mPendingActionRecordForMainIntent = true;

    mHandler.postDelayed(mTimeoutRunnable, sTimeoutDurationMs);

    mTabModelObserver = new TabModelSelectorTabModelObserver(
            mActivity.getTabModelSelector()) {
        @Override
        public void didAddTab(Tab tab, TabLaunchType type) {
            if (TabLaunchType.FROM_RESTORE.equals(type)) return;
            if (NewTabPage.isNTPUrl(tab.getUrl())) recordUserBehavior(NTP_CREATED);
        }

        @Override
        public void didSelectTab(Tab tab, TabSelectionType type, int lastId) {
            recordUserBehavior(SWITCH_TABS);
        }
    };
}
 
Example #22
Source File: TabPersistentStore.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void addTabToSaveQueueIfApplicable(Tab tab) {
    if (tab == null) return;
    if (mTabsToSave.contains(tab) || !tab.isTabStateDirty() || isTabUrlContentScheme(tab)) {
        return;
    }

    if (NewTabPage.isNTPUrl(tab.getUrl()) && !tab.canGoBack() && !tab.canGoForward()) {
        return;
    }
    mTabsToSave.addLast(tab);
}
 
Example #23
Source File: ActivityTabTaskDescriptionHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void updateTaskDescription() {
    if (mCurrentTab == null) {
        updateTaskDescription(null, null);
        return;
    }

    if (NewTabPage.isNTPUrl(mCurrentTab.getUrl()) && !mCurrentTab.isIncognito()) {
        // NTP needs a new color in recents, but uses the default application title and icon
        updateTaskDescription(null, null);
        return;
    }

    String label = mCurrentTab.getTitle();
    String domain = UrlUtilities.getDomainAndRegistry(mCurrentTab.getUrl(), false);
    if (TextUtils.isEmpty(label)) {
        label = domain;
    }
    if (mLargestFavicon == null && TextUtils.isEmpty(label)) {
        updateTaskDescription(null, null);
        return;
    }

    Bitmap bitmap = null;
    if (!mCurrentTab.isIncognito()) {
        bitmap = mIconGenerator.getBitmap(mCurrentTab.getUrl(), mLargestFavicon);
    }

    updateTaskDescription(label, bitmap);
}
 
Example #24
Source File: VrShellImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void updateHistoryButtonsVisibility() {
    if (mTab == null) {
        nativeSetHistoryButtonsEnabled(mNativeVrShell, false, false);
        return;
    }
    // Hitting back when on the NTP usually closes Chrome, which we don't allow in VR, so we
    // just disable the back button.
    boolean shouldAlwaysGoBack = mActivity instanceof ChromeTabbedActivity
            && (mNativePage == null || !(mNativePage instanceof NewTabPage));
    boolean canGoBack = mTab.canGoBack() || shouldAlwaysGoBack;
    nativeSetHistoryButtonsEnabled(mNativeVrShell, canGoBack, mTab.canGoForward());
}
 
Example #25
Source File: LocationBarTablet.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Updates percentage of current the URL focus change animation.
 * @param percent 1.0 is 100% focused, 0 is completely unfocused.
 */
private void setUrlFocusChangePercent(float percent) {
    mUrlFocusChangePercent = percent;

    NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
    if (ntp != null) ntp.setUrlFocusChangeAnimationPercent(percent);
}
 
Example #26
Source File: ToolbarPhone.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent ev) {
    // Forward touch events to the NTP if the toolbar is moved away but the search box hasn't
    // reached the top of the page yet.
    if (mNtpSearchBoxTranslation.y < 0 && mLocationBar.getTranslationY() > 0) {
        NewTabPage newTabPage = getToolbarDataProvider().getNewTabPageForCurrentTab();

        // No null check -- the toolbar should not be moved if we are not on an NTP.
        return newTabPage.getView().dispatchTouchEvent(ev);
    }
    return super.onTouchEvent(ev);
}
 
Example #27
Source File: ToolbarManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private boolean shouldShowCusrsorInLocationBar() {
    Tab tab = mToolbarModel.getTab();
    if (tab == null) return false;
    NativePage nativePage = tab.getNativePage();
    if (!(nativePage instanceof NewTabPage) && !(nativePage instanceof IncognitoNewTabPage)) {
        return false;
    }

    Context context = mToolbar.getContext();
    return DeviceFormFactor.isTablet()
            && context.getResources().getConfiguration().keyboard
            == Configuration.KEYBOARD_QWERTY;
}
 
Example #28
Source File: ToolbarLayout.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #29
Source File: ToolbarModelImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public NewTabPage getNewTabPageForCurrentTab() {
    Tab currentTab = getTab();
    if (currentTab != null && currentTab.getNativePage() instanceof NewTabPage) {
        return (NewTabPage) currentTab.getNativePage();
    }
    return null;
}
 
Example #30
Source File: ColorUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return Alpha for the textbox given a Tab.
 */
public static float getTextBoxAlphaForToolbarBackground(Tab tab) {
    int color = tab.getThemeColor();
    if (tab.getNativePage() instanceof NewTabPage) {
        if (((NewTabPage) tab.getNativePage()).isLocationBarShownInNTP()) return 0f;
    }
    return shouldUseOpaqueTextboxBackground(color)
            ? 1f : LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA;
}