Commit 4ea4dacf authored by Pavel Shmakov's avatar Pavel Shmakov Committed by Commit Bot

Support setNavigationBarColor api for Custom Tabs

The api is introduced in
https://android-review.googlesource.com/c/platform/frameworks/support/+/960642

Bug: 960453
Change-Id: Ie606b4c236ac1aa6000c0c3e501dfcbd8c18cfc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1635609Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Commit-Queue: Pavel Shmakov <pshmakov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664881}
parent 8b6f975d
......@@ -827,7 +827,7 @@ deps = {
},
'src/third_party/custom_tabs_client/src': {
'url': Var('chromium_git') + '/custom-tabs-client.git' + '@' + '8f07fcc8ab004ab697d7b2ac2188db4a2b3e4d2a',
'url': Var('chromium_git') + '/custom-tabs-client.git' + '@' + 'a633542d9854151eb4f0bfd1d93da88f5934a11a',
'condition': 'checkout_android',
},
......
......@@ -429,6 +429,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/customtabs/dynamicmodule/ModuleLoader.java",
"java/src/org/chromium/chrome/browser/customtabs/dynamicmodule/ModuleMetrics.java",
"java/src/org/chromium/chrome/browser/customtabs/dynamicmodule/ObjectWrapper.java",
"java/src/org/chromium/chrome/browser/customtabs/features/CustomTabNavigationBarController.java",
"java/src/org/chromium/chrome/browser/database/SQLiteCursor.java",
"java/src/org/chromium/chrome/browser/datareduction/DataReductionMainMenuItem.java",
"java/src/org/chromium/chrome/browser/datareduction/DataReductionPromoScreen.java",
......
......@@ -1136,6 +1136,7 @@ by a child template that "extends" this file.
<action android:name="android.support.customtabs.action.CustomTabsService" />
<category android:name="androidx.browser.trusted.category.TrustedWebActivities"/>
<category android:name="androidx.browser.trusted.category.TrustedWebActivitySplashScreensV1"/>
<category android:name="androidx.browser.trusted.category.NavBarColorCustomization"/>
</intent-filter>
</service>
<service android:name="android.support.customtabs.PostMessageService" />
......
......@@ -1914,6 +1914,7 @@
tools:ignore="ExportedService">
<intent-filter>
<action android:name="android.support.customtabs.action.CustomTabsService"/>
<category android:name="androidx.browser.trusted.category.NavBarColorCustomization"/>
<category android:name="androidx.browser.trusted.category.TrustedWebActivities"/>
<category
android:name="androidx.browser.trusted.category.TrustedWebActivitySplashScreensV1"/>
......
......@@ -64,6 +64,7 @@ import org.chromium.chrome.browser.customtabs.content.TabCreationMode;
import org.chromium.chrome.browser.customtabs.dependency_injection.CustomTabActivityComponent;
import org.chromium.chrome.browser.customtabs.dependency_injection.CustomTabActivityModule;
import org.chromium.chrome.browser.customtabs.dynamicmodule.DynamicModuleCoordinator;
import org.chromium.chrome.browser.customtabs.features.CustomTabNavigationBarController;
import org.chromium.chrome.browser.dependency_injection.ChromeActivityCommonsModule;
import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor;
import org.chromium.chrome.browser.gsa.GSAState;
......@@ -231,6 +232,7 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent
}
initalizePreviewsObserver();
CustomTabNavigationBarController.updateNavigationBarColor(this, mIntentDataProvider);
}
private int getColorScheme() {
......
......@@ -199,6 +199,8 @@ public class CustomTabIntentDataProvider extends BrowserSessionDataProvider {
private final boolean mIsOpenedByWebApk;
private final boolean mIsTrustedWebActivity;
@Nullable
private final Integer mNavigationBarColor;
@Nullable
private final ComponentName mModuleComponentName;
@Nullable
private final Pattern mModuleManagedUrlsPattern;
......@@ -253,15 +255,6 @@ public class CustomTabIntentDataProvider extends BrowserSessionDataProvider {
IntentHandler.addTrustedIntentExtras(intent);
}
/**
* Deprecated: use the constructor below.
* TODO(pshmakov): remove once no longer used downstream.
*/
@Deprecated
public CustomTabIntentDataProvider(Intent intent, Context context) {
this(intent, context, COLOR_SCHEME_LIGHT);
}
/**
* Constructs a {@link CustomTabIntentDataProvider}.
*
......@@ -290,6 +283,8 @@ public class CustomTabIntentDataProvider extends BrowserSessionDataProvider {
retrieveCustomButtons(intent, context);
retrieveToolbarColor(params, context);
retrieveBottomBarColor(params);
mNavigationBarColor = params.navigationBarColor == null ? null
: removeTransparencyFromColor(params.navigationBarColor);
mInitialBackgroundColor = retrieveInitialBackgroundColor(intent);
mEnableUrlBarHiding = IntentUtils.safeGetBooleanExtra(
......@@ -569,6 +564,14 @@ public class CustomTabIntentDataProvider extends BrowserSessionDataProvider {
return mToolbarColor;
}
/**
* @return The navigation bar color specified in the intent, or null if not specified.
*/
@Nullable
public Integer getNavigationBarColor() {
return mNavigationBarColor;
}
/**
* @return The drawable of the icon of close button shown in the custom tab toolbar. If the
* client app provides an icon in valid size, use this icon; else return the default
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.customtabs.features;
import android.app.Activity;
import android.os.Build;
import android.view.Window;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.customtabs.CustomTabIntentDataProvider;
import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.ui.UiUtils;
/**
* Configures the system navigation bar while a Custom Tab activity is running.
*
* Lifecycle: currently is stateless, so it has only static methods.
*/
public class CustomTabNavigationBarController {
private CustomTabNavigationBarController() {}
/**
* Sets the navigation bar color according to intent extras.
*/
public static void updateNavigationBarColor(Activity activity,
CustomTabIntentDataProvider intentDataProvider) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return; // Window#setNavigationBar not available.
}
Integer color = intentDataProvider.getNavigationBarColor();
if (color == null) return;
Window window = activity.getWindow();
boolean needsDarkButtons = !ColorUtils.shouldUseLightForegroundOnBackground(color);
boolean supportsDarkButtons = Build.VERSION.SDK_INT > Build.VERSION_CODES.O;
if (supportsDarkButtons) {
UiUtils.setNavigationBarIconColor(window.getDecorView().getRootView(),
needsDarkButtons);
} else if (needsDarkButtons) {
// Can't make the buttons dark, darken the background instead with the same algorithm
// as for the status bar.
color = ColorUtils.getDarkenedColorForStatusBar(color);
}
window.setNavigationBarColor(color);
if (needsDarkButtons && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// Add grey divider color if the background is light (similar to
// TabbedNavigationBarColorController#setNavigationBarColor).
// bottom_system_nav_divider_color is overridden to black on Q+, so using it's pre-Q
// value, black_alpha_12, directly.
window.setNavigationBarDividerColor(ApiCompatibilityUtils.getColor(
activity.getResources(), R.color.black_alpha_12));
}
}
}
......@@ -30,10 +30,12 @@ public class CustomTabIntentDataProviderTest {
CustomTabColorSchemeParams lightParams = new CustomTabColorSchemeParams.Builder()
.setToolbarColor(0xff0000ff)
.setSecondaryToolbarColor(0xff00aaff)
.setNavigationBarColor(0xff112233)
.build();
CustomTabColorSchemeParams darkParams = new CustomTabColorSchemeParams.Builder()
.setToolbarColor(0xffff0000)
.setSecondaryToolbarColor(0xffff8800)
.setNavigationBarColor(0xff332211)
.build();
Intent intent = new CustomTabsIntent.Builder()
.setColorSchemeParams(COLOR_SCHEME_LIGHT, lightParams)
......@@ -51,6 +53,9 @@ public class CustomTabIntentDataProviderTest {
assertEquals((int) lightParams.secondaryToolbarColor, lightProvider.getBottomBarColor());
assertEquals((int) darkParams.secondaryToolbarColor, darkProvider.getBottomBarColor());
assertEquals(lightParams.navigationBarColor, lightProvider.getNavigationBarColor());
assertEquals(darkParams.navigationBarColor, darkProvider.getNavigationBarColor());
}
}
......@@ -511,12 +511,12 @@ public class UiUtils {
/**
* Sets the navigation bar icons to dark or light. Note that this is only valid for Android
* O_MR1+.
* O+.
* @param rootView The root view used to request updates to the system UI theme.
* @param useDarkIcons Whether the navigation bar icons should be dark.
*/
public static void setNavigationBarIconColor(View rootView, boolean useDarkIcons) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O_MR1) return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return;
int systemUiVisibility = rootView.getSystemUiVisibility();
if (useDarkIcons) {
......
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