Commit 26b6cf4a authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

Revert "Merge WebAPK/TWA status bar behaviour 1/3"

This reverts commit 513ca106.

Reason for revert: Tests are failing on Lollipop

Bug: 1015406

Original change's description:
> Merge WebAPK/TWA status bar behaviour 1/3
> 
> This CL matches the status bar behaviour of WebAPKs to that of TWAs by:
> - Changing the status bar colour used by WebAPKs when the Web Manifest
>   does not provide a "theme_color" to white. This requires increasing
>   MINIMUM_REQUIRED_CHROMIUM_VERSION_NEW_SPLASH
> - Making the status bar use dark icons if the Web Manifest provides
> a light colour.
> 
> BUG=997793
> 
> Change-Id: Ia628810345af90cd45bb9762e0ce24f500ed4bba
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1857205
> Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
> Reviewed-by: Yaron Friedman <yfriedman@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#706765}

TBR=yfriedman@chromium.org,pkotwicz@chromium.org

Change-Id: I84ef085dd2421f28dba39f77a982e2812a6462cd
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 997793
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1866515Reviewed-by: default avatarRayan Kanso <rayankans@chromium.org>
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706913}
parent 73a5a05e
......@@ -689,7 +689,7 @@ public class WebappActivity extends SingleTabActivity {
@Override
public int getBaseStatusBarColor() {
return isStatusBarDefaultThemeColor() ? Color.WHITE : mBrandColor;
return isStatusBarDefaultThemeColor() ? Color.BLACK : mBrandColor;
}
@Override
......
......@@ -86,7 +86,7 @@ public class WebappSplashScreenTest {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;
Assert.assertEquals(
Color.WHITE, mActivityTestRule.getActivity().getWindow().getStatusBarColor());
Color.BLACK, mActivityTestRule.getActivity().getWindow().getStatusBarColor());
}
@Test
......
......@@ -29,7 +29,7 @@ public class HostBrowserUtils {
private static final int MINIMUM_REQUIRED_INTENT_HELPER_VERSION = 2;
// Lowest version of Chromium which supports ShellAPK showing the splash screen.
public static final int MINIMUM_REQUIRED_CHROMIUM_VERSION_NEW_SPLASH = 78;
public static final int MINIMUM_REQUIRED_CHROMIUM_VERSION_NEW_SPLASH = 77;
private static final String VERSION_NAME_DEVELOPER_BUILD = "Developer Build";
......
......@@ -44,6 +44,9 @@ import java.util.Map;
public class WebApkUtils {
private static final String TAG = "cr_WebApkUtils";
/** Percentage to darken a color by when setting the status bar color. */
private static final float DARKEN_COLOR_FRACTION = 0.6f;
private static final float CONTRAST_LIGHT_ITEM_THRESHOLD = 3f;
/** Returns whether the application is installed and enabled. */
......@@ -201,6 +204,28 @@ public class WebApkUtils {
return Math.abs((1.05f) / (bgL + 0.05f));
}
/**
* 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) {
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) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
hsv[2] *= darkenFraction;
return Color.HSVToColor(hsv);
}
/**
* Check whether lighter or darker foreground elements (i.e. text, drawables etc.)
* should be used depending on the given background color.
......@@ -232,25 +257,6 @@ public class WebApkUtils {
}
}
/**
* Sets the status bar icons to dark or light. Note that this is only valid for
* Android M+.
*
* @param rootView The root view used to request updates to the system UI theming.
* @param useDarkIcons Whether the status bar icons should be dark.
*/
public static void setStatusBarIconColor(View rootView, boolean useDarkIcons) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
int systemUiVisibility = rootView.getSystemUiVisibility();
if (useDarkIcons) {
systemUiVisibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
} else {
systemUiVisibility &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
}
rootView.setSystemUiVisibility(systemUiVisibility);
}
/**
* @see android.view.Window#setStatusBarColor(int color).
*/
......
......@@ -150,7 +150,10 @@ public class SplashActivity extends Activity {
private void showSplashScreen() {
Bundle metadata = WebApkUtils.readMetaData(this);
updateStatusBar(metadata);
int themeColor = (int) WebApkMetaDataUtils.getLongFromMetaData(
metadata, WebApkMetaDataKeys.THEME_COLOR, Color.BLACK);
WebApkUtils.setStatusBarColor(
getWindow(), WebApkUtils.getDarkenedColorForStatusBar(themeColor));
int orientation = WebApkUtils.computeScreenLockOrientationFromMetaData(this, metadata);
if (orientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
......@@ -172,19 +175,6 @@ public class SplashActivity extends Activity {
setContentView(mSplashView);
}
/**
* Sets the the color of the status bar and status bar icons.
*/
private void updateStatusBar(Bundle metadata) {
int statusBarColor = (int) WebApkMetaDataUtils.getLongFromMetaData(
metadata, WebApkMetaDataKeys.THEME_COLOR, Color.WHITE);
WebApkUtils.setStatusBarColor(getWindow(), statusBarColor);
boolean needsDarkStatusBarIcons =
!WebApkUtils.shouldUseLightForegroundOnBackground(statusBarColor);
WebApkUtils.setStatusBarIconColor(
getWindow().getDecorView().getRootView(), needsDarkStatusBarIcons);
}
/** Called once the host browser has been selected. */
private void onHostBrowserSelected(HostBrowserLauncherParams params) {
if (params == null) {
......
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