Commit 59505e5f authored by Becky Zhou's avatar Becky Zhou Committed by Commit Bot

[Dark] Apply a white tint on the default logo in dark mode

Bug: 934498
Change-Id: I67d031386146680fafb87cfab5fa8800531b5abb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1546860
Commit-Queue: Becky Zhou <huayinz@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#646495}
parent f29590d5
......@@ -111,6 +111,7 @@
<color name="ntp_bg_incognito">@color/incognito_modern_primary_color</color>
<color name="suggestions_modern_bg">@color/modern_primary_color</color>
<color name="suggestions_offline_badge_tint">@color/default_icon_color_blue</color>
<color name="google_logo_tint">@android:color/transparent</color>
<!-- Incognito NTP Colors. -->
<color name="incognito_emphasis">@android:color/white</color>
......
......@@ -9,6 +9,8 @@
<color name="toolbar_text_box_background">@color/modern_grey_800</color>
<color name="google_logo_tint">@android:color/white</color>
<color name="bottom_system_nav_color">@android:color/black</color>
<color name="bottom_system_nav_divider_color">@android:color/black</color>
</resources>
......@@ -11,9 +11,13 @@ import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Property;
......@@ -22,6 +26,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ntp.LogoBridge.Logo;
import org.chromium.chrome.browser.search_engines.TemplateUrlService;
......@@ -44,6 +49,7 @@ public class LogoView extends FrameLayout implements OnClickListener {
// The default logo is shared across all NTPs.
private static WeakReference<Bitmap> sDefaultLogo;
private static @ColorInt int sDefaultLogoTint;
// mLogo and mNewLogo are remembered for cross fading animation.
private Bitmap mLogo;
......@@ -300,9 +306,26 @@ public class LogoView extends FrameLayout implements OnClickListener {
if (!TemplateUrlService.getInstance().isDefaultSearchEngineGoogle()) return null;
Bitmap defaultLogo = sDefaultLogo == null ? null : sDefaultLogo.get();
if (defaultLogo == null) {
defaultLogo = BitmapFactory.decodeResource(getResources(), R.drawable.google_logo);
final int tint = ApiCompatibilityUtils.getColor(getResources(), R.color.google_logo_tint);
if (defaultLogo == null || sDefaultLogoTint != tint) {
if (tint == Color.TRANSPARENT) {
defaultLogo = BitmapFactory.decodeResource(getResources(), R.drawable.google_logo);
} else {
// Apply color filter on a bitmap, which will cause some performance overhead, but
// it is worth the APK space savings by avoiding adding another large asset for the
// logo in night mode. Not using vector drawable here because it is close to the
// maximum recommended vector drawable size 200dpx200dp.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;
defaultLogo = BitmapFactory.decodeResource(
getResources(), R.drawable.google_logo, options);
Paint paint = new Paint();
paint.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.SRC_ATOP));
Canvas canvas = new Canvas(defaultLogo);
canvas.drawBitmap(defaultLogo, 0, 0, paint);
}
sDefaultLogo = new WeakReference<>(defaultLogo);
sDefaultLogoTint = tint;
}
return defaultLogo;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment