0

Add @ColorInt in toolbar.

Change-Id: Ib9b9c4470a365b06b533a6eb1d4d84884836dd0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5066869
Reviewed-by: Jinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: Patrick Noland <pnoland@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Sky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1230255}
This commit is contained in:
Sky Malice
2023-11-28 22:54:07 +00:00
committed by Chromium LUCI CQ
parent fa4c46b573
commit bb54d42a2f
11 changed files with 100 additions and 74 deletions
chrome/browser/ui/android
ui/android/java/src/org/chromium/ui/util

@@ -12,6 +12,7 @@ import android.graphics.Typeface;
import android.view.ActionMode;
import android.view.View;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
@@ -91,7 +92,6 @@ public class LocationBarCoordinator
private StatusCoordinator mStatusCoordinator;
private WindowDelegate mWindowDelegate;
private WindowAndroid mWindowAndroid;
private View mAutocompleteAnchorView;
private LocationBarMediator mLocationBarMediator;
private View mUrlBar;
private View mDeleteButton;
@@ -101,10 +101,10 @@ public class LocationBarCoordinator
private boolean mDestroyed;
private boolean mNativeInitialized;
private final int mDropdownStandardBackgroundColor;
private final int mDropdownIncognitoBackgroundColor;
private final int mSuggestionStandardBackgroundColor;
private final int mSuggestionIncognitoBackgroundColor;
private final @ColorInt int mDropdownStandardBackgroundColor;
private final @ColorInt int mDropdownIncognitoBackgroundColor;
private final @ColorInt int mSuggestionStandardBackgroundColor;
private final @ColorInt int mSuggestionIncognitoBackgroundColor;
private boolean mShortCircuitUnfocusAnimation;
/**
@@ -185,7 +185,6 @@ public class LocationBarCoordinator
mWindowAndroid = windowAndroid;
mActivityLifecycleDispatcher = activityLifecycleDispatcher;
mActivityLifecycleDispatcher.register(this);
mAutocompleteAnchorView = autocompleteAnchorView;
Context context = mLocationBarLayout.getContext();
OneshotSupplierImpl<TemplateUrlService> templateUrlServiceSupplier =
new OneshotSupplierImpl<>();
@@ -287,8 +286,7 @@ public class LocationBarCoordinator
mUrlCoordinator.setUrlDirectionListener(
mCallbackController.makeCancelable(
layoutDirection -> {
ViewCompat.setLayoutDirection(
mLocationBarLayout, (Integer) layoutDirection);
ViewCompat.setLayoutDirection(mLocationBarLayout, layoutDirection);
mAutocompleteCoordinator.updateSuggestionListLayoutDirection();
}));
@@ -794,15 +792,11 @@ public class LocationBarCoordinator
return mLocationBarMediator;
}
/* package */ StatusCoordinator getStatusCoordinatorForTesting() {
return mStatusCoordinator;
}
/**
* @param isIncognito Whether we are currently in incognito mode.
* @return The background color for the Omnibox suggestion dropdown list.
*/
public int getDropdownBackgroundColor(boolean isIncognito) {
public @ColorInt int getDropdownBackgroundColor(boolean isIncognito) {
return isIncognito ? mDropdownIncognitoBackgroundColor : mDropdownStandardBackgroundColor;
}
@@ -810,7 +804,7 @@ public class LocationBarCoordinator
* @param isIncognito Whether we are currently in incognito mode.
* @return The the background color for each individual suggestion.
*/
public int getSuggestionBackgroundColor(boolean isIncognito) {
public @ColorInt int getSuggestionBackgroundColor(boolean isIncognito) {
return isIncognito
? mSuggestionIncognitoBackgroundColor
: mSuggestionStandardBackgroundColor;

@@ -22,7 +22,7 @@ public abstract class ThemeColorProvider {
* @param color The new color the observer should use.
* @param shouldAnimate Whether the change of color should be animated.
*/
void onThemeColorChanged(int color, boolean shouldAnimate);
void onThemeColorChanged(@ColorInt int color, boolean shouldAnimate);
}
/** An interface to be notified about changes to the tint. */
@@ -35,7 +35,7 @@ public abstract class ThemeColorProvider {
}
/** Current primary color. */
private int mPrimaryColor;
private @ColorInt int mPrimaryColor;
/** The current {@link BrandedColorScheme}. */
private @Nullable @BrandedColorScheme Integer mBrandedColorScheme;
@@ -53,8 +53,8 @@ public abstract class ThemeColorProvider {
* @param context The {@link Context} that is used to retrieve color related resources.
*/
public ThemeColorProvider(Context context) {
mThemeColorObservers = new ObserverList<ThemeColorObserver>();
mTintObservers = new ObserverList<TintObserver>();
mThemeColorObservers = new ObserverList<>();
mTintObservers = new ObserverList<>();
mTint = ThemeUtils.getThemedToolbarIconTint(context, BrandedColorScheme.APP_DEFAULT);
}
@@ -115,7 +115,7 @@ public abstract class ThemeColorProvider {
mTintObservers.clear();
}
protected void updatePrimaryColor(int color, boolean shouldAnimate) {
protected void updatePrimaryColor(@ColorInt int color, boolean shouldAnimate) {
if (mPrimaryColor == color) return;
mPrimaryColor = color;
for (ThemeColorObserver observer : mThemeColorObservers) {

@@ -32,16 +32,18 @@ public class ThemeUtils {
/**
* The background color to use for a given {@link Tab}. This will either be the color specified
* by the associated web content or a default color if not specified.
*
* @param tab {@link Tab} object to get the background color for.
* @return The background color of {@link Tab}.
*/
public static int getBackgroundColor(Tab tab) {
public static @ColorInt int getBackgroundColor(Tab tab) {
if (tab.isNativePage()) return tab.getNativePage().getBackgroundColor();
WebContents tabWebContents = tab.getWebContents();
RenderWidgetHostView rwhv =
tabWebContents == null ? null : tabWebContents.getRenderWidgetHostView();
final int backgroundColor = rwhv != null ? rwhv.getBackgroundColor() : Color.TRANSPARENT;
final @ColorInt int backgroundColor =
rwhv != null ? rwhv.getBackgroundColor() : Color.TRANSPARENT;
if (backgroundColor != Color.TRANSPARENT) return backgroundColor;
return ChromeColors.getPrimaryBackgroundColor(tab.getContext(), false);
}
@@ -78,10 +80,10 @@ public class ThemeUtils {
// Text box color on default toolbar background in incognito mode is a pre-defined
// color. We calculate the equivalent opaque color from the pre-defined translucent color.
if (isIncognito) {
final int overlayColor =
final @ColorInt int overlayColor =
context.getColor(R.color.toolbar_text_box_background_incognito);
final float overlayColorAlpha = Color.alpha(overlayColor) / 255f;
final int overlayColorOpaque = overlayColor & 0xFF000000;
final @ColorInt int overlayColorOpaque = overlayColor & 0xFF000000;
return ColorUtils.getColorWithOverlay(color, overlayColorOpaque, overlayColorAlpha);
}
@@ -162,13 +164,14 @@ public class ThemeUtils {
/**
* Test if the toolbar is using the default color.
*
* @param context The context to get the toolbar surface color.
* @param isIncognito Whether to retrieve the default theme color for incognito mode.
* @param color The color that the toolbar is using.
* @return If the color is the default toolbar color.
*/
public static boolean isUsingDefaultToolbarColor(
Context context, boolean isIncognito, int color) {
Context context, boolean isIncognito, @ColorInt int color) {
return color == ChromeColors.getDefaultThemeColor(context, isIncognito);
}
@@ -189,7 +192,7 @@ public class ThemeUtils {
}
final float alpha = ResourcesCompat.getFloat(res, R.dimen.toolbar_hairline_overlay_alpha);
final int hairlineColorOpaque =
final @ColorInt int hairlineColorOpaque =
res.getColor(R.color.toolbar_hairline_overlay_opaque) & 0xFF000000;
return ColorUtils.getColorWithOverlay(toolbarColor, hairlineColorOpaque, alpha);
}

@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.toolbar;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -66,6 +67,7 @@ public interface ToolbarDataProvider {
/**
* @return The primary color to use for the background drawable.
*/
@ColorInt
int getPrimaryColor();
/**

@@ -10,6 +10,7 @@ import android.graphics.Rect;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.ColorInt;
import androidx.annotation.IntDef;
import org.chromium.base.Callback;
@@ -201,9 +202,10 @@ public class OptionalButtonCoordinator {
* #updateButton(ButtonData)} is called with a {@link
* org.chromium.chrome.browser.toolbar.ButtonData.ButtonSpec} where {@code isDynamicAction()} is
* true).
*
* @param backgroundColor
*/
public void setBackgroundColorFilter(int backgroundColor) {
public void setBackgroundColorFilter(@ColorInt int backgroundColor) {
mMediator.setBackgroundColorFilter(backgroundColor);
}

@@ -6,6 +6,8 @@ package org.chromium.chrome.browser.toolbar.optional_button;
import android.content.res.ColorStateList;
import androidx.annotation.ColorInt;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.toolbar.ButtonData;
import org.chromium.ui.modelutil.PropertyModel;
@@ -32,7 +34,7 @@ class OptionalButtonMediator {
mModel.set(OptionalButtonProperties.ICON_TINT_LIST, colorStateList);
}
void setBackgroundColorFilter(int backgroundColor) {
void setBackgroundColorFilter(@ColorInt int backgroundColor) {
mModel.set(OptionalButtonProperties.ICON_BACKGROUND_COLOR, backgroundColor);
}

@@ -240,7 +240,7 @@ public abstract class ToolbarLayout extends FrameLayout
public void onTintChanged(ColorStateList tint, @BrandedColorScheme int brandedColorScheme) {}
@Override
public void onThemeColorChanged(int color, boolean shouldAnimate) {}
public void onThemeColorChanged(@ColorInt int color, boolean shouldAnimate) {}
/**
* Set the height that the progress bar should be.
@@ -336,7 +336,7 @@ public abstract class ToolbarLayout extends FrameLayout
}
@Override
public int getPrimaryColor() {
public @ColorInt int getPrimaryColor() {
return 0;
}
@@ -873,7 +873,7 @@ public abstract class ToolbarLayout extends FrameLayout
* Notify the observer that the toolbar color is changed and pass the toolbar color to the
* observer.
*/
protected void notifyToolbarColorChanged(int color) {
protected void notifyToolbarColorChanged(@ColorInt int color) {
if (mToolbarColorObserver != null) {
mToolbarColorObserver.onToolbarColorChanged(color);
}

@@ -37,6 +37,8 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -249,7 +251,7 @@ public class ToolbarPhone extends ToolbarLayout
private int mLocationBarBackgroundVerticalInset;
/** The current color of the location bar. */
private int mCurrentLocationBarColor;
private @ColorInt int mCurrentLocationBarColor;
/** Whether the toolbar has a pending request to call {@link triggerUrlFocusAnimation()}. */
private boolean mPendingTriggerUrlFocusRequest;
@@ -267,7 +269,7 @@ public class ToolbarPhone extends ToolbarLayout
private boolean mIsShowingStartSurfaceTabSwitcher;
private NtpSearchBoxDrawable mNtpSearchBoxBackground;
private int mHomeSurfaceToolbarBackgroundColor;
private @ColorInt int mHomeSurfaceToolbarBackgroundColor;
private boolean mHasFocus;
/** Used to specify the visual state of the toolbar. */
@@ -433,7 +435,7 @@ public class ToolbarPhone extends ToolbarLayout
}
/** Set the background color of the location bar to appropriately match the theme color. */
private void updateModernLocationBarColor(int color) {
private void updateModernLocationBarColor(@ColorInt int color) {
if (mCurrentLocationBarColor == color) return;
mCurrentLocationBarColor = color;
mLocationBarBackground.setTint(color);
@@ -462,16 +464,17 @@ public class ToolbarPhone extends ToolbarLayout
/**
* Get the corresponding location bar color for a toolbar color.
*
* @param toolbarColor The color of the toolbar.
* @return The location bar color.
*/
private int getLocationBarColorForToolbarColor(int toolbarColor) {
private @ColorInt int getLocationBarColorForToolbarColor(@ColorInt int toolbarColor) {
return ThemeUtils.getTextBoxColorForToolbarBackgroundInNonNativePage(
getContext(), toolbarColor, isIncognito());
}
/** Get the toolbar default color depending on the toolbar's status. */
private int getToolbarDefaultColor() {
private @ColorInt int getToolbarDefaultColor() {
if (mShouldShowModernizeVisualUpdate && mLocationBar.getPhoneCoordinator().hasFocus()) {
if (mDropdownListScrolled) {
return isIncognito()
@@ -485,14 +488,14 @@ public class ToolbarPhone extends ToolbarLayout
}
/**
* Get the corresponding default location bar color for a toolbar color.
* If location bar has focus, return the Omnibox suggestion background color.
* If location bar does not have focus, return {@link getLocationBarColorForToolbarColor(int
* toolbarColor)}.
* Get the corresponding default location bar color for a toolbar color. If location bar has
* focus, return the Omnibox suggestion background color. If location bar does not have focus,
* return {@link getLocationBarColorForToolbarColor(int toolbarColor)}.
*
* @param toolbarColor The color of the toolbar.
* @return The default location bar color.
*/
private int getLocationBarDefaultColorForToolbarColor(int toolbarColor) {
private @ColorInt int getLocationBarDefaultColorForToolbarColor(@ColorInt int toolbarColor) {
if (mShouldShowModernizeVisualUpdate && mLocationBar.getPhoneCoordinator().hasFocus()) {
if (OmniboxFeatures.shouldShowActiveColorOnOmnibox()) {
// Omnibox has same background as the Omnibox suggestion.
@@ -847,7 +850,7 @@ public class ToolbarPhone extends ToolbarLayout
&& mStartSurfaceScrollFraction != 1.0f;
}
private void updateToolbarBackground(int color) {
private void updateToolbarBackground(@ColorInt int color) {
if (mToolbarBackground.getColor() == color) return;
mToolbarBackground.setColor(color);
setToolbarHairlineColor(color);
@@ -861,7 +864,7 @@ public class ToolbarPhone extends ToolbarLayout
updateToolbarBackground(getToolbarColorForVisualState(visualState));
}
private int getToolbarColorForVisualState(final @VisualState int visualState) {
private @ColorInt int getToolbarColorForVisualState(final @VisualState int visualState) {
switch (visualState) {
case VisualState.NEW_TAB_NORMAL:
// We are likely in the middle of a layout animation, and the NTP cannot draw itself
@@ -1210,10 +1213,12 @@ public class ToolbarPhone extends ToolbarLayout
? (!isLocationBarShownInNTP && !mIsShowingStartSurfaceHomepage)
: !isLocationBarShownInNTP))
&& mTabSwitcherState == STATIC_TAB) {
int defaultColor = getToolbarDefaultColor();
@ColorInt int defaultColor = getToolbarDefaultColor();
@ColorInt
int defaultLocationBarColor =
getLocationBarDefaultColorForToolbarColor(defaultColor);
int primaryColor = getToolbarDataProvider().getPrimaryColor();
@ColorInt int primaryColor = getToolbarDataProvider().getPrimaryColor();
@ColorInt
int themedLocationBarColor = getLocationBarColorForToolbarColor(primaryColor);
updateToolbarBackground(
@@ -1866,7 +1871,7 @@ public class ToolbarPhone extends ToolbarLayout
private PhoneCaptureStateToken generateToolbarSnapshotState() {
UrlBarData urlBarData;
int securityIconResource;
@DrawableRes int securityIconResource;
if (ToolbarFeatures.shouldSuppressCaptures()) {
urlBarData = mLocationBar.getUrlBarData();
if (urlBarData == null) urlBarData = getToolbarDataProvider().getUrlBarData();
@@ -2471,9 +2476,10 @@ public class ToolbarPhone extends ToolbarLayout
/**
* Get the theme color for the currently active tab. This is not affected by the tab switcher's
* theme color.
*
* @return The current tab's theme color.
*/
private int getTabThemeColor() {
private @ColorInt int getTabThemeColor() {
if (getToolbarDataProvider() != null) return getToolbarDataProvider().getPrimaryColor();
return getToolbarColorForVisualState(
isIncognito() ? VisualState.INCOGNITO : VisualState.NORMAL);
@@ -2502,12 +2508,13 @@ public class ToolbarPhone extends ToolbarLayout
super.onPrimaryColorChanged(shouldAnimate);
if (mBrandColorTransitionActive) mBrandColorTransitionAnimation.end();
final int initialColor = mToolbarBackground.getColor();
final int finalColor = getToolbarDataProvider().getPrimaryColor();
final @ColorInt int initialColor = mToolbarBackground.getColor();
final @ColorInt int finalColor = getToolbarDataProvider().getPrimaryColor();
if (initialColor == finalColor) return;
final int initialLocationBarColor = getLocationBarColorForToolbarColor(initialColor);
final int finalLocationBarColor = getLocationBarColorForToolbarColor(finalColor);
final @ColorInt int initialLocationBarColor =
getLocationBarColorForToolbarColor(initialColor);
final @ColorInt int finalLocationBarColor = getLocationBarColorForToolbarColor(finalColor);
// Ignore theme color changes while the omnibox is focused, since we want a standard,
// app-defined color for the toolbar in this scenario, not the site's color. We'll
@@ -2663,7 +2670,7 @@ public class ToolbarPhone extends ToolbarLayout
/**
* @return The color that progress bar should use.
*/
private int getProgressBarColor() {
private @ColorInt int getProgressBarColor() {
return getToolbarDataProvider().getPrimaryColor();
}
@@ -2757,8 +2764,8 @@ public class ToolbarPhone extends ToolbarLayout
boolean visualStateChanged = mVisualState != newVisualState;
int currentPrimaryColor = getToolbarDataProvider().getPrimaryColor();
int themeColorForProgressBar = getProgressBarColor();
@ColorInt int currentPrimaryColor = getToolbarDataProvider().getPrimaryColor();
@ColorInt int themeColorForProgressBar = getProgressBarColor();
// If The page is native force the use of the standard theme for the progress bar.
if (getToolbarDataProvider() != null
@@ -3178,7 +3185,7 @@ public class ToolbarPhone extends ToolbarLayout
}
private void updateToolbarAndLocationBarColor() {
int toolbarDefaultColor = getToolbarDefaultColor();
@ColorInt int toolbarDefaultColor = getToolbarDefaultColor();
updateToolbarBackground(toolbarDefaultColor);
updateModernLocationBarColor(
getLocationBarDefaultColorForToolbarColor(toolbarDefaultColor));

@@ -469,6 +469,7 @@ public class ToolbarTablet extends ToolbarLayout
private TabletCaptureStateToken generateCaptureStateToken() {
UrlBarData urlBarData = getToolbarDataProvider().getUrlBarData();
@DrawableRes
int securityIconResource =
getToolbarDataProvider().getSecurityIconResource(/* isTablet= */ true);
VisibleUrlText visibleUrlText =
@@ -522,7 +523,7 @@ public class ToolbarTablet extends ToolbarLayout
}
@Override
public void onThemeColorChanged(int color, boolean shouldAnimate) {
public void onThemeColorChanged(@ColorInt int color, boolean shouldAnimate) {
setBackgroundColor(color);
final @ColorInt int textBoxColor =
ThemeUtils.getTextBoxColorForToolbarBackgroundInNonNativePage(

@@ -10,6 +10,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewStub;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -70,8 +71,10 @@ public class TopToolbarCoordinator implements Toolbar {
/** Observes toolbar color change. */
public interface ToolbarColorObserver {
/** @param color The toolbar color value. */
void onToolbarColorChanged(int color);
/**
* @param color The toolbar color value.
*/
void onToolbarColorChanged(@ColorInt int color);
}
/** Observes toolbar alpha value change during overview mode fading animation. */

@@ -36,7 +36,7 @@ public class ColorUtils {
}
/** Computes the lightness value in HSL standard for the given color. */
public static float getLightnessForColor(int color) {
public static float getLightnessForColor(@ColorInt int color) {
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
@@ -50,7 +50,7 @@ public class ColorUtils {
* Calculates the contrast between the given color and white, using the algorithm provided by
* the WCAG v2 in http://www.w3.org/TR/WCAG20/#contrast-ratiodef.
*/
private static float getContrastForColor(int color) {
private static float getContrastForColor(@ColorInt int color) {
float bgR = Color.red(color) / 255f;
float bgG = Color.green(color) / 255f;
float bgB = Color.blue(color) / 255f;
@@ -64,30 +64,34 @@ public class ColorUtils {
/**
* Get a color when overlaid with a different color. Note that colors returned by this method
* are always opaque.
*
* @param baseColor The base Android color.
* @param overlayColor The overlay Android color.
* @param overlayAlpha The alpha |overlayColor| should have on the base color.
*/
public static int getColorWithOverlay(int baseColor, int overlayColor, float overlayAlpha) {
public static @ColorInt int getColorWithOverlay(
@ColorInt int baseColor, @ColorInt int overlayColor, float overlayAlpha) {
return getColorWithOverlay(baseColor, overlayColor, overlayAlpha, false);
}
/**
* Darkens the given color to use on the status bar.
*
* @param color Color which should be darkened.
* @return Color that should be used for Android status bar.
*/
public static int getDarkenedColorForStatusBar(int color) {
public static @ColorInt int getDarkenedColorForStatusBar(@ColorInt int color) {
return getDarkenedColor(color, DARKEN_COLOR_FRACTION);
}
/**
* Darken a color to a fraction of its current brightness.
*
* @param color The input color.
* @param darkenFraction The fraction of the current brightness the color should be.
* @return The new darkened color.
*/
public static int getDarkenedColor(int color, float darkenFraction) {
public static @ColorInt int getDarkenedColor(@ColorInt int color, float darkenFraction) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
hsv[2] *= darkenFraction;
@@ -95,50 +99,54 @@ public class ColorUtils {
}
/**
* Check whether lighter or darker foreground elements (i.e. text, drawables etc.)
* should be used depending on the given background color.
* Check whether lighter or darker foreground elements (i.e. text, drawables etc.) should be
* used depending on the given background color.
*
* @param backgroundColor The background color value which is being queried.
* @return Whether light colored elements should be used.
*/
public static boolean shouldUseLightForegroundOnBackground(int backgroundColor) {
public static boolean shouldUseLightForegroundOnBackground(@ColorInt int backgroundColor) {
return getContrastForColor(backgroundColor) >= CONTRAST_LIGHT_ITEM_THRESHOLD;
}
/**
* Check which version of the textbox background should be used depending on the given
* color.
* Check which version of the textbox background should be used depending on the given color.
*
* @param color The color value we are querying for.
* @return Whether the transparent version of the background should be used.
*/
public static boolean shouldUseOpaqueTextboxBackground(int color) {
public static boolean shouldUseOpaqueTextboxBackground(@ColorInt int color) {
return getLightnessForColor(color) > LIGHTNESS_OPAQUE_BOX_THRESHOLD;
}
/**
* Returns an opaque version of the given color.
*
* @param color Color for which an opaque version should be returned.
* @return Opaque version of the given color.
*/
public static int getOpaqueColor(int color) {
public static @ColorInt int getOpaqueColor(@ColorInt int color) {
return Color.rgb(Color.red(color), Color.green(color), Color.blue(color));
}
/**
* Determine if a theme color is too bright. A theme color is too bright if its luminance is >
* 0.94.
*
* @param color The color to test.
* @return True if the theme color is too bright.
*/
public static boolean isThemeColorTooBright(int color) {
public static boolean isThemeColorTooBright(@ColorInt int color) {
return ColorUtils.getLightnessForColor(color) > MAX_LUMINANCE_FOR_VALID_THEME_COLOR;
}
/**
* Compute a color to use for assets that sit on top of a themed background.
*
* @param themeColor The base theme color.
* @return A color to use for elements in the foreground (on top of the base theme color).
*/
public static int getThemedAssetColor(int themeColor, boolean isIncognito) {
public static @ColorInt int getThemedAssetColor(@ColorInt int themeColor, boolean isIncognito) {
if (ColorUtils.shouldUseLightForegroundOnBackground(themeColor) || isIncognito) {
// Dark theme.
return Color.WHITE;
@@ -151,14 +159,18 @@ public class ColorUtils {
/**
* Get a color when overlaid with a different color.
*
* @param baseColor The base Android color.
* @param overlayColor The overlay Android color.
* @param overlayAlpha The alpha |overlayColor| should have on the base color.
* @param considerOpacity indicates whether to take color opacity into consideration when
* calculating the new color.
* calculating the new color.
*/
public static int getColorWithOverlay(
int baseColor, int overlayColor, float overlayAlpha, boolean considerOpacity) {
public static @ColorInt int getColorWithOverlay(
@ColorInt int baseColor,
@ColorInt int overlayColor,
float overlayAlpha,
boolean considerOpacity) {
int red =
(int)
MathUtils.interpolate(