Project import generated by Copybara.
GitOrigin-RevId: d682a6c371196760900ffc6962fb92f75c6b77ed
diff --git a/browser/browser/src/main/java/androidx/browser/customtabs/CustomTabsIntent.java b/browser/browser/src/main/java/androidx/browser/customtabs/CustomTabsIntent.java
index 009f579..68f360e 100644
--- a/browser/browser/src/main/java/androidx/browser/customtabs/CustomTabsIntent.java
+++ b/browser/browser/src/main/java/androidx/browser/customtabs/CustomTabsIntent.java
@@ -357,6 +357,8 @@
private boolean mInstantAppsEnabled = true;
@Nullable
private SparseArray<Bundle> mColorSchemeParamBundles;
+ @Nullable
+ private Bundle mDefaultColorSchemeBundle;
/**
* Creates a {@link CustomTabsIntent.Builder} object associated with no
@@ -427,7 +429,10 @@
* Can be overridden for particular color schemes, see {@link #setColorSchemeParams}.
*
* @param color {@link Color}
+ *
+ * @deprecated Use {@link #setDefaultColorSchemeParams} instead.
*/
+ @Deprecated
@NonNull
public Builder setToolbarColor(@ColorInt int color) {
mDefaultColorSchemeBuilder.setToolbarColor(color);
@@ -599,7 +604,10 @@
* Can be overridden for particular color schemes, see {@link #setColorSchemeParams}.
*
* @param color The color for the secondary toolbar.
+ *
+ * @deprecated Use {@link #setDefaultColorSchemeParams} instead.
*/
+ @Deprecated
@NonNull
public Builder setSecondaryToolbarColor(@ColorInt int color) {
mDefaultColorSchemeBuilder.setSecondaryToolbarColor(color);
@@ -616,7 +624,10 @@
* Can be overridden for particular color schemes, see {@link #setColorSchemeParams}.
*
* @param color The color for the navigation bar.
+ *
+ * @deprecated Use {@link #setDefaultColorSchemeParams} instead.
*/
+ @Deprecated
@NonNull
public Builder setNavigationBarColor(@ColorInt int color) {
mDefaultColorSchemeBuilder.setNavigationBarColor(color);
@@ -629,7 +640,10 @@
* Can be overridden for particular color schemes, see {@link #setColorSchemeParams}.
*
* @param color The color for the navigation bar divider.
+ *
+ * @deprecated Use {@link #setDefaultColorSchemeParams} instead.
*/
+ @Deprecated
@NonNull
public Builder setNavigationBarDividerColor(@ColorInt int color) {
mDefaultColorSchemeBuilder.setNavigationBarDividerColor(color);
@@ -728,26 +742,22 @@
* will follow the system settings and apply the corresponding
* {@link CustomTabColorSchemeParams} "on the fly" when the settings change.
*
- * The method {@link #setToolbarColor} will set the given color as a default color to both
- * schemes.
- *
* If there is no {@link CustomTabColorSchemeParams} for the current scheme, or a particular
* field of it is null, Custom Tabs will fall back to the defaults provided via
- * {@link #setToolbarColor}. If, on the other hand, a non-null value is present, it will
- * override the default color from {@link #setToolbarColor}.
+ * {@link #setDefaultColorSchemeParams}.
*
- * **Note**: to maintain compatibility with browsers not supporting this API, do provide the
- * defaults via {@link #setToolbarColor}.
- *
- * Example of setting two toolbar colors in backwards-compatible way:
+ * Example:
* <pre><code>
* CustomTabColorSchemeParams darkParams = new CustomTabColorSchemeParams.Builder()
* .setToolbarColor(darkColor)
* .build();
+ * CustomTabColorSchemeParams otherParams = new CustomTabColorSchemeParams.Builder()
+ * .setNavigationBarColor(otherColor)
+ * .build();
* CustomTabIntent intent = new CustomTabIntent.Builder()
- * .setToolbarColor(lightColor)
* .setColorScheme(COLOR_SCHEME_SYSTEM)
* .setColorSchemeParams(COLOR_SCHEME_DARK, darkParams)
+ * .setDefaultColorSchemeParams(otherParams)
* .build();
* </code></pre>
*
@@ -770,6 +780,21 @@
return this;
}
+
+ /**
+ * Sets the default {@link CustomTabColorSchemeParams}.
+ *
+ * This will set a default color scheme that applies when no CustomTabColorSchemeParams
+ * specified for current color scheme via {@link #setColorSchemeParams}.
+ *
+ * @param params An instance of {@link CustomTabColorSchemeParams}.
+ */
+ @NonNull
+ public Builder setDefaultColorSchemeParams(@NonNull CustomTabColorSchemeParams params) {
+ mDefaultColorSchemeBundle = params.toBundle();
+ return this;
+ }
+
/**
* Combines all the options that have been set and returns a new {@link CustomTabsIntent}
* object.
@@ -789,6 +814,10 @@
mIntent.putExtra(EXTRA_ENABLE_INSTANT_APPS, mInstantAppsEnabled);
mIntent.putExtras(mDefaultColorSchemeBuilder.build().toBundle());
+ if (mDefaultColorSchemeBundle != null) {
+ mIntent.putExtras(mDefaultColorSchemeBundle);
+ }
+
if (mColorSchemeParamBundles != null) {
Bundle bundle = new Bundle();
bundle.putSparseParcelableArray(EXTRA_COLOR_SCHEME_PARAMS,
diff --git a/browser/browser/src/main/java/androidx/browser/trusted/TrustedWebActivityIntentBuilder.java b/browser/browser/src/main/java/androidx/browser/trusted/TrustedWebActivityIntentBuilder.java
index 6d14e55..708106b 100644
--- a/browser/browser/src/main/java/androidx/browser/trusted/TrustedWebActivityIntentBuilder.java
+++ b/browser/browser/src/main/java/androidx/browser/trusted/TrustedWebActivityIntentBuilder.java
@@ -114,6 +114,8 @@
* When a Trusted Web Activity is on the verified origin, the toolbar is hidden, so the color
* applies only to the status bar. When it's on an unverified origin, the toolbar is shown, and
* the color applies to both toolbar and status bar.
+ *
+ * @deprecated Use {@link #setDefaultColorSchemeParams} instead.
*/
@NonNull
public TrustedWebActivityIntentBuilder setToolbarColor(@ColorInt int color) {
@@ -123,6 +125,8 @@
/**
* Sets the navigation bar color, see {@link CustomTabsIntent.Builder#setNavigationBarColor}.
+ *
+ * @deprecated Use {@link #setDefaultColorSchemeParams} instead.
*/
@NonNull
public TrustedWebActivityIntentBuilder setNavigationBarColor(@ColorInt int color) {
@@ -133,6 +137,8 @@
/**
* Sets the navigation bar divider color, see
* {@link CustomTabsIntent.Builder#setNavigationBarDividerColor}.
+ *
+ * @deprecated Use {@link #setDefaultColorSchemeParams} instead.
*/
@NonNull
public TrustedWebActivityIntentBuilder setNavigationBarDividerColor(@ColorInt int color) {
@@ -171,6 +177,21 @@
}
/**
+ * Sets the default {@link CustomTabColorSchemeParams}.
+ *
+ * This will set a default color scheme that applies when no CustomTabColorSchemeParams
+ * specified for current color scheme via {@link #setColorSchemeParams}.
+ *
+ * @param params An instance of {@link CustomTabColorSchemeParams}.
+ */
+ @NonNull
+ public TrustedWebActivityIntentBuilder setDefaultColorSchemeParams(
+ @NonNull CustomTabColorSchemeParams params) {
+ mIntentBuilder.setDefaultColorSchemeParams(params);
+ return this;
+ }
+
+ /**
* Sets a list of additional trusted origins that the user may navigate or be redirected to
* from the starting uri.
*