Commit 59e3c75c authored by Calder Kitagawa's avatar Calder Kitagawa Committed by Commit Bot

[Webapps] Fix splash screen scaling on Android P

When loading splash_icon.xml on Android P, scaling doesn't occur until
after the image is drawn. As a result, if we try to show a lower DPI image
such as the mdpi icon, the Bitmap#getWidth/Bitmap#getHeight values will
only return the original image size on Android P. What we actually want is
the scaled image size. To do so we use
Bitmap#getScaledWidth/Bitmap#getScaledHeight which return the scaled image
size in pixels. This wasn't a problem on O and earlier since this scaling
occurred when the bitmap was loaded into memory (prior to rendering).

Bug: 819755
Change-Id: I86ad9466d653d4d8501a8c672925b2ba86819d8d
Reviewed-on: https://chromium-review.googlesource.com/1148815Reviewed-by: default avatarPeter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577987}
parent fde71806
......@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.webapps;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -240,16 +241,19 @@ class WebappSplashScreenController extends EmptyTabObserver {
int bigThreshold =
resources.getDimensionPixelSize(R.dimen.webapp_splash_image_size_threshold);
DisplayMetrics metrics =
ContextUtils.getApplicationContext().getResources().getDisplayMetrics();
// Inflate the correct layout for the image.
int layoutId;
if (displayIcon == null || displayIcon.getWidth() < minimiumSizeThreshold
if (displayIcon == null || displayIcon.getScaledWidth(metrics) < minimiumSizeThreshold
|| (displayIcon == webappInfo.icon() && webappInfo.isIconGenerated())) {
mWebappUma.recordSplashscreenIconType(WebappUma.SplashScreenIconType.NONE);
layoutId = R.layout.webapp_splash_screen_no_icon;
} else {
// The size of the splash screen image determines which layout to use.
boolean isUsingSmallSplashImage = displayIcon.getWidth() <= bigThreshold
|| displayIcon.getHeight() <= bigThreshold;
boolean isUsingSmallSplashImage = displayIcon.getScaledWidth(metrics) <= bigThreshold
|| displayIcon.getScaledHeight(metrics) <= bigThreshold;
if (isUsingSmallSplashImage) {
layoutId = R.layout.webapp_splash_screen_small;
} else {
......
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