org.chromium.chrome.browser.util.ColorUtils Java Examples

The following examples show how to use org.chromium.chrome.browser.util.ColorUtils. 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: LayoutManagerDocument.java    From delion with Apache License 2.0 6 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_SCHEME);
    int themeColor = tab.getThemeColor();
    boolean canUseLiveTexture =
            tab.getContentViewCore() != null && !tab.isShowingSadTab() && !isNativePage;
    layoutTab.initFromHost(tab.getBackgroundColor(), tab.shouldStall(), canUseLiveTexture,
            themeColor, ColorUtils.getTextBoxColorForToolbarBackground(
                                mContext.getResources(), tab, themeColor),
            ColorUtils.getTextBoxAlphaForToolbarBackground(tab));

    mHost.requestRender();
}
 
Example #2
Source File: BottomToolbarPhone.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected void drawTabSwitcherFadeAnimation(boolean animationFinished, float progress) {
    mNewTabButton.setAlpha(progress);

    mLocationBar.setAlpha(1f - progress);
    if (mUseToolbarHandle) mToolbarHandleView.setAlpha(1f - progress);

    int tabSwitcherThemeColor = getToolbarColorForVisualState(VisualState.TAB_SWITCHER_NORMAL);

    updateToolbarBackground(ColorUtils.getColorWithOverlay(
            getTabThemeColor(), tabSwitcherThemeColor, progress));

    // Don't use transparency for accessibility mode or low-end devices since the
    // {@link OverviewListLayout} will be used instead of the normal tab switcher.
    if (!DeviceClassManager.enableAccessibilityLayout()) {
        float alphaTransition = 1f - TAB_SWITCHER_TOOLBAR_ALPHA;
        mToolbarBackground.setAlpha((int) ((1f - (alphaTransition * progress)) * 255));
    }
}
 
Example #3
Source File: CustomTabToolbar.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void updateVisualsForState() {
    Resources resources = getResources();
    updateSecurityIcon(getSecurityLevel());
    updateButtonsTint();
    mUrlBar.setUseDarkTextColors(mUseDarkColors);

    int titleTextColor = mUseDarkColors
            ? ApiCompatibilityUtils.getColor(resources, R.color.url_emphasis_default_text)
            : ApiCompatibilityUtils.getColor(resources,
                    R.color.url_emphasis_light_default_text);
    mTitleBar.setTextColor(titleTextColor);

    if (getProgressBar() != null) {
        if (!ColorUtils.isUsingDefaultToolbarColor(getResources(),
                getBackground().getColor())) {
            getProgressBar().setThemeColor(getBackground().getColor(), false);
        } else {
            getProgressBar().setBackgroundColor(ApiCompatibilityUtils.getColor(resources,
                    R.color.progress_bar_background));
            getProgressBar().setForegroundColor(ApiCompatibilityUtils.getColor(resources,
                    R.color.progress_bar_foreground));
        }
    }
}
 
Example #4
Source File: WebappActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void initializeWebappData() {
    if (mWebappInfo.displayMode() == WebDisplayMode.FULLSCREEN) {
        enterImmersiveMode();
    }

    final int backgroundColor = ColorUtils.getOpaqueColor(mWebappInfo.backgroundColor(
            ApiCompatibilityUtils.getColor(getResources(), R.color.webapp_default_bg)));

    mSplashScreen = new FrameLayout(this);
    mSplashScreen.setBackgroundColor(backgroundColor);

    ViewGroup contentView = (ViewGroup) findViewById(android.R.id.content);
    contentView.addView(mSplashScreen);

    mWebappUma.splashscreenVisible();
    mWebappUma.recordSplashscreenBackgroundColor(mWebappInfo.hasValidBackgroundColor()
            ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM
            : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT);
    mWebappUma.recordSplashscreenThemeColor(mWebappInfo.hasValidThemeColor()
            ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM
            : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT);

    initializeSplashScreenWidgets(backgroundColor);
}
 
Example #5
Source File: LocationBarLayout.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the current specs and updates {@link LocationBar#mUseDarkColors} if necessary.
 * @return Whether {@link LocationBar#mUseDarkColors} has been updated.
 */
private boolean updateUseDarkColors() {
    Tab tab = getCurrentTab();
    boolean brandColorNeedsLightText = false;
    if (getToolbarDataProvider().isUsingBrandColor() && !mUrlHasFocus) {
        int currentPrimaryColor = getToolbarDataProvider().getPrimaryColor();
        brandColorNeedsLightText =
                ColorUtils.shouldUseLightForegroundOnBackground(currentPrimaryColor);
    }

    boolean useDarkColors =
            (mToolbarDataProvider == null || !mToolbarDataProvider.isIncognito())
            && (tab == null || !(tab.isIncognito() || brandColorNeedsLightText));
    boolean hasChanged = useDarkColors != mUseDarkColors;
    mUseDarkColors = useDarkColors;

    return hasChanged;
}
 
Example #6
Source File: ToolbarProgressBar.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Color the progress bar based on the toolbar theme color.
 * @param color The Android color the toolbar is using.
 */
public void setThemeColor(int color, boolean isIncognito) {
    mThemeColor = color;

    // The default toolbar has specific colors to use.
    if ((ColorUtils.isUsingDefaultToolbarColor(getResources(), color)
            || !ColorUtils.isValidThemeColor(color)) && !isIncognito) {
        setForegroundColor(ApiCompatibilityUtils.getColor(getResources(),
                R.color.progress_bar_foreground));
        setBackgroundColor(ApiCompatibilityUtils.getColor(getResources(),
                R.color.progress_bar_background));
        return;
    }

    setForegroundColor(ColorUtils.getThemedAssetColor(color, isIncognito));

    if (mAnimatingView != null
            && (ColorUtils.shouldUseLightForegroundOnBackground(color) || isIncognito)) {
        mAnimatingView.setColor(ColorUtils.getColorWithOverlay(color, Color.WHITE,
                ANIMATION_WHITE_FRACTION));
    }

    setBackgroundColor(ColorUtils.getColorWithOverlay(color, Color.WHITE,
            THEMED_BACKGROUND_WHITE_FRACTION));
}
 
Example #7
Source File: CustomTabToolbar.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void updateVisualsForState() {
    Resources resources = getResources();
    updateSecurityIcon(getSecurityLevel());
    updateButtonsTint();
    mUrlBar.setUseDarkTextColors(mUseDarkColors);

    int titleTextColor = mUseDarkColors
            ? ApiCompatibilityUtils.getColor(resources, R.color.url_emphasis_default_text)
            : ApiCompatibilityUtils.getColor(resources,
                    R.color.url_emphasis_light_default_text);
    mTitleBar.setTextColor(titleTextColor);

    if (getProgressBar() != null) {
        if (!ColorUtils.isUsingDefaultToolbarColor(getResources(),
                getBackground().getColor())) {
            getProgressBar().setThemeColor(getBackground().getColor(), false);
        } else {
            getProgressBar().setBackgroundColor(ApiCompatibilityUtils.getColor(resources,
                    R.color.progress_bar_background));
            getProgressBar().setForegroundColor(ApiCompatibilityUtils.getColor(resources,
                    R.color.progress_bar_foreground));
        }
    }
}
 
Example #8
Source File: WebappActivity.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void initializeWebappData() {
    final int backgroundColor = ColorUtils.getOpaqueColor(mWebappInfo.backgroundColor(
            ApiCompatibilityUtils.getColor(getResources(), R.color.webapp_default_bg)));

    mSplashScreen = new FrameLayout(this);
    mSplashScreen.setBackgroundColor(backgroundColor);

    ViewGroup contentView = (ViewGroup) findViewById(android.R.id.content);
    contentView.addView(mSplashScreen);

    mWebappUma.splashscreenVisible();
    mWebappUma.recordSplashscreenBackgroundColor(mWebappInfo.hasValidBackgroundColor()
            ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM
            : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT);
    mWebappUma.recordSplashscreenThemeColor(mWebappInfo.hasValidThemeColor()
            ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM
            : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT);

    initializeSplashScreenWidgets(backgroundColor);
}
 
Example #9
Source File: LocationBarLayout.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the current specs and updates {@link LocationBar#mUseDarkColors} if necessary.
 * @return Whether {@link LocationBar#mUseDarkColors} has been updated.
 */
private boolean updateUseDarkColors() {
    Tab tab = getCurrentTab();
    boolean brandColorNeedsLightText = false;
    if (getToolbarDataProvider().isUsingBrandColor() && !mUrlHasFocus) {
        int currentPrimaryColor = getToolbarDataProvider().getPrimaryColor();
        brandColorNeedsLightText =
                ColorUtils.shouldUseLightForegroundOnBackground(currentPrimaryColor);
    }

    boolean useDarkColors = tab == null || !(tab.isIncognito() || brandColorNeedsLightText);
    boolean hasChanged = useDarkColors != mUseDarkColors;
    mUseDarkColors = useDarkColors;

    return hasChanged;
}
 
Example #10
Source File: WebappActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
private void initializeWebappData() {
    final int backgroundColor = ColorUtils.getOpaqueColor(mWebappInfo.backgroundColor(
            ApiCompatibilityUtils.getColor(getResources(), R.color.webapp_default_bg)));

    mSplashScreen = new FrameLayout(this);
    mSplashScreen.setBackgroundColor(backgroundColor);

    ViewGroup contentView = (ViewGroup) findViewById(android.R.id.content);
    contentView.addView(mSplashScreen);

    mWebappUma.splashscreenVisible();
    mWebappUma.recordSplashscreenBackgroundColor(mWebappInfo.hasValidBackgroundColor()
            ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM
            : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT);
    mWebappUma.recordSplashscreenThemeColor(mWebappInfo.hasValidThemeColor()
            ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM
            : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT);

    initializeSplashScreenWidgets(backgroundColor);
}
 
Example #11
Source File: CustomTabToolbar.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void updateVisualsForState() {
    Resources resources = getResources();
    updateSecurityIcon(getSecurityLevel());
    updateButtonsTint();
    mUrlBar.setUseDarkTextColors(mUseDarkColors);

    int titleTextColor = mUseDarkColors
            ? ApiCompatibilityUtils.getColor(resources, R.color.url_emphasis_default_text)
            : ApiCompatibilityUtils.getColor(resources,
                    R.color.url_emphasis_light_default_text);
    mTitleBar.setTextColor(titleTextColor);

    if (getProgressBar() != null) {
        if (!ColorUtils.isUsingDefaultToolbarColor(getResources(),
                getBackground().getColor())) {
            getProgressBar().setThemeColor(getBackground().getColor(), false);
        } else {
            getProgressBar().setBackgroundColor(ApiCompatibilityUtils.getColor(resources,
                    R.color.progress_bar_background));
            getProgressBar().setForegroundColor(ApiCompatibilityUtils.getColor(resources,
                    R.color.progress_bar_foreground));
        }
    }
}
 
Example #12
Source File: LocationBarLayout.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the current specs and updates {@link LocationBar#mUseDarkColors} if necessary.
 * @return Whether {@link LocationBar#mUseDarkColors} has been updated.
 */
private boolean updateUseDarkColors() {
    Tab tab = getCurrentTab();
    boolean brandColorNeedsLightText = false;
    if (getToolbarDataProvider().isUsingBrandColor() && !mUrlHasFocus) {
        int currentPrimaryColor = getToolbarDataProvider().getPrimaryColor();
        brandColorNeedsLightText =
                ColorUtils.shouldUseLightForegroundOnBackground(currentPrimaryColor);
    }

    boolean useDarkColors = tab == null || !(tab.isIncognito() || brandColorNeedsLightText);
    boolean hasChanged = useDarkColors != mUseDarkColors;
    mUseDarkColors = useDarkColors;

    return hasChanged;
}
 
Example #13
Source File: ToolbarPhone.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void setUseLightDrawablesForTextureCapture() {
    int currentPrimaryColor = getToolbarDataProvider().getPrimaryColor();
    mUseLightDrawablesForTextureCapture =
            isIncognito()
            || (currentPrimaryColor != 0
                       && ColorUtils.shouldUseLightForegroundOnBackground(currentPrimaryColor));
}
 
Example #14
Source File: LocationBarPhone.java    From delion with Apache License 2.0 5 votes vote down vote up
private boolean shouldUseLightDrawables() {
    Tab tab = getCurrentTab();
    boolean isIncognito = tab != null && tab.isIncognito();
    boolean useLightDrawables = isIncognito;
    if (getToolbarDataProvider().isUsingBrandColor()) {
        int currentPrimaryColor = getToolbarDataProvider().getPrimaryColor();
        useLightDrawables |=
                ColorUtils.shouldUseLightForegroundOnBackground(currentPrimaryColor);
    }
    return useLightDrawables;
}
 
Example #15
Source File: ToolbarProgressBar.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void setForegroundColor(int color) {
    super.setForegroundColor(color);
    if (mAnimatingView != null) {
        mAnimatingView.setColor(ColorUtils.getColorWithOverlay(color, Color.WHITE,
                ANIMATION_WHITE_FRACTION));
    }
}
 
Example #16
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 #17
Source File: LayerTitleCache.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private String getUpdatedTitleInternal(Tab tab, String titleString,
        boolean fetchFaviconFromHistory) {
    final int tabId = tab.getId();
    Bitmap originalFavicon = tab.getFavicon();

    boolean isDarkTheme = tab.isIncognito();
    // The theme might require lighter text.
    if (!DeviceFormFactor.isTablet()) {
        isDarkTheme |= ColorUtils.shouldUseLightForegroundOnBackground(tab.getThemeColor());
    }

    ColorUtils.shouldUseLightForegroundOnBackground(tab.getThemeColor());
    boolean isRtl = tab.isTitleDirectionRtl();
    TitleBitmapFactory titleBitmapFactory = isDarkTheme
            ? mDarkTitleBitmapFactory : mStandardTitleBitmapFactory;

    Title title = mTitles.get(tabId);
    if (title == null) {
        title = new Title();
        mTitles.put(tabId, title);
        title.register();
    }

    title.set(titleBitmapFactory.getTitleBitmap(mContext, titleString),
            titleBitmapFactory.getFaviconBitmap(mContext, originalFavicon),
            fetchFaviconFromHistory);

    if (mNativeLayerTitleCache != 0) {
        nativeUpdateLayer(mNativeLayerTitleCache, tabId, title.getTitleResId(),
                title.getFaviconResId(), isDarkTheme, isRtl);
    }
    return titleString;
}
 
Example #18
Source File: CustomTabActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void postInflationStartup() {
    super.postInflationStartup();

    getToolbarManager().setCloseButtonDrawable(mIntentDataProvider.getCloseButtonDrawable());
    getToolbarManager().setShowTitle(mIntentDataProvider.getTitleVisibilityState()
            == CustomTabsIntent.SHOW_PAGE_TITLE);
    if (CustomTabsConnection.getInstance(getApplication())
            .shouldHideDomainForSession(mSession)) {
        getToolbarManager().setUrlBarHidden(true);
    }
    int toolbarColor = mIntentDataProvider.getToolbarColor();
    getToolbarManager().updatePrimaryColor(toolbarColor, false);
    if (!mIntentDataProvider.isOpenedByChrome()) {
        getToolbarManager().setShouldUpdateToolbarPrimaryColor(false);
    }
    if (toolbarColor != ApiCompatibilityUtils.getColor(
            getResources(), R.color.default_primary_color)) {
        ApiCompatibilityUtils.setStatusBarColor(getWindow(),
                ColorUtils.getDarkenedColorForStatusBar(toolbarColor));
    }
    // Properly attach tab's infobar to the view hierarchy, as the main tab might have been
    // initialized prior to inflation.
    if (mMainTab != null) {
        ViewGroup bottomContainer = (ViewGroup) findViewById(R.id.bottom_container);
        mMainTab.getInfoBarContainer().setParentView(bottomContainer);
    }

    // Setting task title and icon to be null will preserve the client app's title and icon.
    ApiCompatibilityUtils.setTaskDescription(this, null, null, toolbarColor);
    showCustomButtonOnToolbar();
    mBottomBarDelegate = new CustomTabBottomBarDelegate(this, mIntentDataProvider,
            getFullscreenManager());
    mBottomBarDelegate.showBottomBarIfNecessary();
}
 
Example #19
Source File: LocationBarLayout.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the security icon displayed in the LocationBar.
 */
@Override
public void updateSecurityIcon(int securityLevel) {
    boolean isSmallDevice = !DeviceFormFactor.isTablet();
    boolean isOfflinePage =
            getCurrentTab() != null && OfflinePageUtils.isOfflinePage(getCurrentTab());
    int id = getSecurityIconResource(securityLevel, isSmallDevice, isOfflinePage);
    if (id == 0) {
        mSecurityButton.setImageDrawable(null);
    } else {
        // ImageView#setImageResource is no-op if given resource is the current one.
        mSecurityButton.setImageResource(id);
        mSecurityButton.setTint(getColorStateList(securityLevel, getToolbarDataProvider(),
                getResources(), ColorUtils.shouldUseOpaqueTextboxBackground(
                        getToolbarDataProvider().getPrimaryColor())));
    }

    updateVerboseStatusVisibility();

    boolean shouldEmphasizeHttpsScheme = shouldEmphasizeHttpsScheme();
    if (mSecurityIconResource == id
            && mIsEmphasizingHttpsScheme == shouldEmphasizeHttpsScheme) {
        return;
    }
    mSecurityIconResource = id;

    changeLocationBarIcon();
    updateLocationBarIconContainerVisibility();
    // Since we emphasize the scheme of the URL based on the security type, we need to
    // refresh the emphasis.
    mUrlBar.deEmphasizeUrl();
    emphasizeUrl();
    mIsEmphasizingHttpsScheme = shouldEmphasizeHttpsScheme;
}
 
Example #20
Source File: Tab.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Calculate the theme color based on if the page is native, the theme color changed, etc.
 * @param didWebContentsThemeColorChange If the theme color of the web contents is known to have
 *                                       changed.
 * @return The theme color that should be used for this tab.
 */
private int calculateThemeColor(boolean didWebContentsThemeColorChange) {
    if (isNativePage()) return mNativePage.getThemeColor();

    // Start by assuming the current theme color is that one that should be used. This will
    // either be transparent, the last theme color, or the color restored from TabState.
    int themeColor = mThemeColor;

    // Only use the web contents for the theme color if it is known to have changed, This
    // corresponds to the didChangeThemeColor in WebContentsObserver.
    if (getWebContents() != null && didWebContentsThemeColorChange) {
        themeColor = getWebContents().getThemeColor();
        if (themeColor != 0 && !ColorUtils.isValidThemeColor(themeColor)) themeColor = 0;
    }

    // Do not apply the theme color if there are any security issues on the page.
    int securityLevel = getSecurityLevel();
    if (securityLevel == ConnectionSecurityLevel.DANGEROUS
            || securityLevel == ConnectionSecurityLevel.SECURITY_WARNING
            || securityLevel == ConnectionSecurityLevel.SECURE_WITH_POLICY_INSTALLED_CERT) {
        themeColor = getDefaultThemeColor();
    }

    if (isShowingInterstitialPage()) themeColor = getDefaultThemeColor();

    if (themeColor == Color.TRANSPARENT) themeColor = getDefaultThemeColor();
    if (isIncognito()) themeColor = getDefaultThemeColor();

    // Ensure there is no alpha component to the theme color as that is not supported in the
    // dependent UI.
    themeColor |= 0xFF000000;
    return themeColor;
}
 
Example #21
Source File: CustomTabActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void postInflationStartup() {
    super.postInflationStartup();
    setTabModelSelector(new TabModelSelectorImpl(this,
            TabModelSelectorImpl.CUSTOM_TABS_SELECTOR_INDEX, getWindowAndroid(), false));
    getToolbarManager().setCloseButtonDrawable(mIntentDataProvider.getCloseButtonDrawable());
    getToolbarManager().setShowTitle(mIntentDataProvider.getTitleVisibilityState()
            == CustomTabsIntent.SHOW_PAGE_TITLE);
    if (CustomTabsConnection.getInstance(getApplication())
            .shouldHideDomainForSession(mSession)) {
        getToolbarManager().setUrlBarHidden(true);
    }
    int toolbarColor = mIntentDataProvider.getToolbarColor();
    getToolbarManager().updatePrimaryColor(toolbarColor, false);
    if (!mIntentDataProvider.isOpenedByChrome()) {
        getToolbarManager().setShouldUpdateToolbarPrimaryColor(false);
    }
    if (toolbarColor != ApiCompatibilityUtils.getColor(
            getResources(), R.color.default_primary_color)) {
        ApiCompatibilityUtils.setStatusBarColor(getWindow(),
                ColorUtils.getDarkenedColorForStatusBar(toolbarColor));
    }

    // Setting task title and icon to be null will preserve the client app's title and icon.
    ApiCompatibilityUtils.setTaskDescription(this, null, null, toolbarColor);
    showCustomButtonOnToolbar();
    mBottomBarDelegate = new CustomTabBottomBarDelegate(this, mIntentDataProvider);
    mBottomBarDelegate.showBottomBarIfNecessary();
}
 
Example #22
Source File: WebappActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void updateTaskDescription() {
    String title = null;
    if (!TextUtils.isEmpty(mWebappInfo.shortName())) {
        title = mWebappInfo.shortName();
    } else if (getActivityTab() != null) {
        title = getActivityTab().getTitle();
    }

    Bitmap icon = null;
    if (mWebappInfo.icon() != null) {
        icon = mWebappInfo.icon();
    } else if (getActivityTab() != null) {
        icon = mLargestFavicon;
    }

    if (mBrandColor == null && mWebappInfo.hasValidThemeColor()) {
        mBrandColor = (int) mWebappInfo.themeColor();
    }

    int taskDescriptionColor =
            ApiCompatibilityUtils.getColor(getResources(), R.color.default_primary_color);

    // Don't use the brand color for the status bars if we're in display: fullscreen. This works
    // around an issue where the status bars go transparent and can't be seen on top of the page
    // content when users swipe them in or they appear because the on-screen keyboard was
    // triggered.
    int statusBarColor = Color.BLACK;
    if (mBrandColor != null && mWebappInfo.displayMode() != WebDisplayMode.FULLSCREEN) {
        taskDescriptionColor = mBrandColor;
        statusBarColor = ColorUtils.getDarkenedColorForStatusBar(mBrandColor);
    }

    ApiCompatibilityUtils.setTaskDescription(this, title, icon,
            ColorUtils.getOpaqueColor(taskDescriptionColor));
    ApiCompatibilityUtils.setStatusBarColor(getWindow(), statusBarColor);
}
 
Example #23
Source File: LayerTitleCache.java    From delion with Apache License 2.0 5 votes vote down vote up
private String getUpdatedTitleInternal(Tab tab, String titleString,
        boolean fetchFaviconFromHistory) {
    final int tabId = tab.getId();
    Bitmap originalFavicon = tab.getFavicon();

    boolean isDarkTheme = tab.isIncognito();
    // If theme colors are enabled in the tab switcher, the theme might require lighter text.
    if (FeatureUtilities.areTabSwitcherThemeColorsEnabled()
            && !DeviceFormFactor.isTablet(mContext)) {
        isDarkTheme |= ColorUtils.shouldUseLightForegroundOnBackground(tab.getThemeColor());
    }

    ColorUtils.shouldUseLightForegroundOnBackground(tab.getThemeColor());
    boolean isRtl = tab.isTitleDirectionRtl();
    TitleBitmapFactory titleBitmapFactory = isDarkTheme
            ? mDarkTitleBitmapFactory : mStandardTitleBitmapFactory;

    Title title = mTitles.get(tabId);
    if (title == null) {
        title = new Title();
        mTitles.put(tabId, title);
        title.register();
    }

    title.set(titleBitmapFactory.getTitleBitmap(mContext, titleString),
            titleBitmapFactory.getFaviconBitmap(mContext, originalFavicon),
            fetchFaviconFromHistory);

    if (mNativeLayerTitleCache != 0) {
        nativeUpdateLayer(mNativeLayerTitleCache, tabId, title.getTitleResId(),
                title.getFaviconResId(), isDarkTheme, isRtl);
    }
    return titleString;
}
 
Example #24
Source File: ToolbarPhone.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateTabCountVisuals(int numberOfTabs) {
    if (mHomeButton != null) mHomeButton.setEnabled(true);

    if (mToggleTabStackButton == null) return;

    mToggleTabStackButton.setEnabled(numberOfTabs >= 1);
    mToggleTabStackButton.setContentDescription(
            getResources().getQuantityString(
                    R.plurals.accessibility_toolbar_btn_tabswitcher_toggle,
                    numberOfTabs, numberOfTabs));
    mTabSwitcherButtonDrawableLight.updateForTabCount(numberOfTabs, isIncognito());
    mTabSwitcherButtonDrawable.updateForTabCount(numberOfTabs, isIncognito());

    boolean useTabStackDrawableLight = isIncognito()
            || ColorUtils.shouldUseLightForegroundOnBackground(getTabThemeColor());
    if (mTabSwitcherAnimationTabStackDrawable == null
            || mIsOverlayTabStackDrawableLight != useTabStackDrawableLight) {
        mTabSwitcherAnimationTabStackDrawable =
                TabSwitcherDrawable.createTabSwitcherDrawable(
                        getResources(), useTabStackDrawableLight);
        int[] stateSet = {android.R.attr.state_enabled};
        mTabSwitcherAnimationTabStackDrawable.setState(stateSet);
        mTabSwitcherAnimationTabStackDrawable.setBounds(
                mToggleTabStackButton.getDrawable().getBounds());
        mIsOverlayTabStackDrawableLight = useTabStackDrawableLight;
    }

    if (mTabSwitcherAnimationTabStackDrawable != null) {
        mTabSwitcherAnimationTabStackDrawable.updateForTabCount(
                numberOfTabs, isIncognito());
    }
}
 
Example #25
Source File: ToolbarPhone.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void setUseLightDrawablesForTextureCapture() {
    int currentPrimaryColor = getToolbarDataProvider().getPrimaryColor();
    mUseLightDrawablesForTextureCapture =
            isIncognito()
            || (currentPrimaryColor != 0
                       && ColorUtils.shouldUseLightForegroundOnBackground(currentPrimaryColor));
}
 
Example #26
Source File: ToolbarProgressBar.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Color the progress bar based on the toolbar theme color.
 * @param color The Android color the toolbar is using.
 */
public void setThemeColor(int color, boolean isIncognito) {
    mThemeColor = color;
    boolean isDefaultTheme = ColorUtils.isUsingDefaultToolbarColor(getResources(), color);

    // All colors use a single path if using the status bar color as the background.
    if (mUseStatusBarColorAsBackground) {
        if (isDefaultTheme) color = Color.BLACK;
        setForegroundColor(
                ApiCompatibilityUtils.getColor(getResources(), R.color.white_alpha_70));
        setBackgroundColor(ColorUtils.getDarkenedColorForStatusBar(color));
        return;
    }

    // The default toolbar has specific colors to use.
    if ((isDefaultTheme || !ColorUtils.isValidThemeColor(color)) && !isIncognito) {
        setForegroundColor(ApiCompatibilityUtils.getColor(getResources(),
                R.color.progress_bar_foreground));
        setBackgroundColor(ApiCompatibilityUtils.getColor(getResources(),
                R.color.progress_bar_background));
        return;
    }

    setForegroundColor(ColorUtils.getThemedAssetColor(color, isIncognito));

    if (mAnimatingView != null
            && (ColorUtils.shouldUseLightForegroundOnBackground(color) || isIncognito)) {
        mAnimatingView.setColor(ColorUtils.getColorWithOverlay(color, Color.WHITE,
                ANIMATION_WHITE_FRACTION));
    }

    setBackgroundColor(ColorUtils.getColorWithOverlay(color, Color.WHITE,
            THEMED_BACKGROUND_WHITE_FRACTION));
}
 
Example #27
Source File: ToolbarProgressBar.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void setForegroundColor(int color) {
    super.setForegroundColor(color);
    if (mAnimatingView != null) {
        mAnimatingView.setColor(ColorUtils.getColorWithOverlay(color, Color.WHITE,
                ANIMATION_WHITE_FRACTION));
    }
}
 
Example #28
Source File: LayerTitleCache.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private String getUpdatedTitleInternal(Tab tab, String titleString,
        boolean fetchFaviconFromHistory) {
    final int tabId = tab.getId();
    Bitmap originalFavicon = tab.getFavicon();

    boolean isDarkTheme = tab.isIncognito();
    // The theme might require lighter text.
    if (!DeviceFormFactor.isTablet(mContext)) {
        isDarkTheme |= ColorUtils.shouldUseLightForegroundOnBackground(tab.getThemeColor());
    }

    ColorUtils.shouldUseLightForegroundOnBackground(tab.getThemeColor());
    boolean isRtl = tab.isTitleDirectionRtl();
    TitleBitmapFactory titleBitmapFactory = isDarkTheme
            ? mDarkTitleBitmapFactory : mStandardTitleBitmapFactory;

    Title title = mTitles.get(tabId);
    if (title == null) {
        title = new Title();
        mTitles.put(tabId, title);
        title.register();
    }

    title.set(titleBitmapFactory.getTitleBitmap(mContext, titleString),
            titleBitmapFactory.getFaviconBitmap(mContext, originalFavicon),
            fetchFaviconFromHistory);

    if (mNativeLayerTitleCache != 0) {
        nativeUpdateLayer(mNativeLayerTitleCache, tabId, title.getTitleResId(),
                title.getFaviconResId(), isDarkTheme, isRtl);
    }
    return titleString;
}
 
Example #29
Source File: ToolbarPhone.java    From delion with Apache License 2.0 5 votes vote down vote up
private void setUseLightDrawablesForTextureCapture() {
    int currentPrimaryColor = getToolbarDataProvider().getPrimaryColor();
    mUseLightDrawablesForTextureCapture =
            isIncognito()
            || (currentPrimaryColor != 0
                       && ColorUtils.shouldUseLightForegroundOnBackground(currentPrimaryColor));
}
 
Example #30
Source File: ToolbarProgressBar.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Color the progress bar based on the toolbar theme color.
 * @param color The Android color the toolbar is using.
 */
public void setThemeColor(int color, boolean isIncognito) {
    mThemeColor = color;

    // The default toolbar has specific colors to use.
    if (ColorUtils.isUsingDefaultToolbarColor(getResources(), color) && !isIncognito) {
        setForegroundColor(ApiCompatibilityUtils.getColor(getResources(),
                R.color.progress_bar_foreground));
        setBackgroundColor(ApiCompatibilityUtils.getColor(getResources(),
                R.color.progress_bar_background));
        return;
    }

    // All other theme colors are computed.
    if (!ColorUtils.shouldUseLightForegroundOnBackground(color) && !isIncognito) {
        // Light theme.
        setForegroundColor(ColorUtils.getColorWithOverlay(color, Color.BLACK,
                THEMED_FOREGROUND_BLACK_FRACTION));
    } else {
        // Dark theme.
        setForegroundColor(Color.WHITE);
        if (mAnimatingView != null) {
            mAnimatingView.setColor(ColorUtils.getColorWithOverlay(color, Color.WHITE,
                    ANIMATION_WHITE_FRACTION));
        }
    }

    setBackgroundColor(ColorUtils.getColorWithOverlay(color, Color.WHITE,
            THEMED_BACKGROUND_WHITE_FRACTION));
}