Commit 4982f7ba authored by Matthew Jones's avatar Matthew Jones Committed by Commit Bot

[Modern] Improve tab switcher theme color animations

This change removes the use of transparency on the location bar when
modern is enabled. This simplifies the logic required to run animations
and fixes a flickering issue when entering and exiting the tab switcher.

This change also changes the background color of the asset to white.
This allows it to be easily tinted which will also be required for the
composited version.

BUG=803098,803091

Change-Id: Ia56660da21f615840f6ea2902a3252b8809d337f
Reviewed-on: https://chromium-review.googlesource.com/899772
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534839}
parent e544a1ed
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<shape <shape
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" > android:shape="rectangle" >
<solid android:color="@color/modern_light_grey" /> <solid android:color="@android:color/white" />
<size <size
android:width="@dimen/modern_toolbar_background_size" android:width="@dimen/modern_toolbar_background_size"
android:height="@dimen/modern_toolbar_background_size" /> android:height="@dimen/modern_toolbar_background_size" />
...@@ -16,4 +16,4 @@ ...@@ -16,4 +16,4 @@
android:bottom="0dp" android:bottom="0dp"
android:left="@dimen/modern_toolbar_background_lateral_inset" android:left="@dimen/modern_toolbar_background_lateral_inset"
android:right="@dimen/modern_toolbar_background_lateral_inset" /> android:right="@dimen/modern_toolbar_background_lateral_inset" />
</shape> </shape>
\ No newline at end of file
...@@ -284,6 +284,9 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -284,6 +284,9 @@ public class ToolbarPhone extends ToolbarLayout
*/ */
private int mModernLocationBarExtraFocusedStartMargin; private int mModernLocationBarExtraFocusedStartMargin;
/** The current color of the location bar. */
private int mCurrentLocationBarColor;
/** /**
* Used to specify the visual state of the toolbar. * Used to specify the visual state of the toolbar.
*/ */
...@@ -388,8 +391,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -388,8 +391,7 @@ public class ToolbarPhone extends ToolbarLayout
Resources res = getResources(); Resources res = getResources();
mModernLocationBarBackgroundHeight = mModernLocationBarBackgroundHeight =
res.getDimensionPixelSize(R.dimen.modern_toolbar_background_size); res.getDimensionPixelSize(R.dimen.modern_toolbar_background_size);
mLocationBarBackground = mLocationBarBackground = createModernLocationBarBackground();
ApiCompatibilityUtils.getDrawable(res, R.drawable.modern_toolbar_background);
mLocationBarBackground.getPadding(mLocationBarBackgroundPadding); mLocationBarBackground.getPadding(mLocationBarBackgroundPadding);
mLocationBarBackground.mutate(); mLocationBarBackground.mutate();
mLocationBar.setPadding(mLocationBarBackgroundPadding.left, mLocationBar.setPadding(mLocationBarBackgroundPadding.left,
...@@ -418,6 +420,37 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -418,6 +420,37 @@ public class ToolbarPhone extends ToolbarLayout
} }
} }
/**
* @return The drawable for the modern location bar background.
*/
public Drawable createModernLocationBarBackground() {
Drawable drawable = ApiCompatibilityUtils.getDrawable(
getResources(), R.drawable.modern_toolbar_background);
drawable.setColorFilter(
ApiCompatibilityUtils.getColor(getResources(), R.color.modern_light_grey),
PorterDuff.Mode.SRC_IN);
return drawable;
}
/**
* Set the background color of the location bar to appropriately match the theme color.
*/
private void updateModernLocationBarColor(int color) {
if (mCurrentLocationBarColor == color) return;
mCurrentLocationBarColor = color;
mLocationBarBackground.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
/**
* Get the corresponding location bar color for a toolbar color.
* @param toolbarColor The color of the toolbar.
* @return The location bar color.
*/
private int getLocationBarColorForToolbarColor(int toolbarColor) {
return ColorUtils.getTextBoxColorForToolbarBackground(
getResources(), false, toolbarColor, mLocationBar.useModernDesign());
}
private void inflateTabSwitchingResources() { private void inflateTabSwitchingResources() {
mToggleTabStackButton = (ImageView) findViewById(R.id.tab_switcher_button); mToggleTabStackButton = (ImageView) findViewById(R.id.tab_switcher_button);
mNewTabButton = (NewTabButton) findViewById(R.id.new_tab_button); mNewTabButton = (NewTabButton) findViewById(R.id.new_tab_button);
...@@ -1435,6 +1468,12 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1435,6 +1468,12 @@ public class ToolbarPhone extends ToolbarLayout
} else { } else {
backgroundAlpha = mLocationBarBackgroundAlpha; backgroundAlpha = mLocationBarBackgroundAlpha;
} }
// If modern is enabled the location bar background is opaque.
// TODO(mdjones): The location bar background should always be opaque. We have the
// capability to determine the foreground color without alpha and it reduces the amount
// of state that this class tracks.
if (mLocationBar.useModernDesign()) backgroundAlpha = 255;
mLocationBarBackground.setAlpha(backgroundAlpha); mLocationBarBackground.setAlpha(backgroundAlpha);
if (shouldDrawLocationBarBackground()) { if (shouldDrawLocationBarBackground()) {
...@@ -2214,6 +2253,9 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2214,6 +2253,9 @@ public class ToolbarPhone extends ToolbarLayout
final int finalColor = getToolbarDataProvider().getPrimaryColor(); final int finalColor = getToolbarDataProvider().getPrimaryColor();
if (initialColor == finalColor) return; if (initialColor == finalColor) return;
final int initialLocationBarColor = getLocationBarColorForToolbarColor(initialColor);
final int finalLocationBarColor = getLocationBarColorForToolbarColor(finalColor);
if (!isVisualStateValidForBrandColorTransition(mVisualState)) return; if (!isVisualStateValidForBrandColorTransition(mVisualState)) return;
if (!shouldAnimate) { if (!shouldAnimate) {
...@@ -2239,6 +2281,10 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2239,6 +2281,10 @@ public class ToolbarPhone extends ToolbarLayout
} }
updateToolbarBackground( updateToolbarBackground(
ColorUtils.getColorWithOverlay(initialColor, finalColor, fraction)); ColorUtils.getColorWithOverlay(initialColor, finalColor, fraction));
if (mLocationBar.useModernDesign()) {
updateModernLocationBarColor(ColorUtils.getColorWithOverlay(
initialLocationBarColor, finalLocationBarColor, fraction));
}
} }
}); });
mBrandColorTransitionAnimation.addListener(new AnimatorListenerAdapter() { mBrandColorTransitionAnimation.addListener(new AnimatorListenerAdapter() {
...@@ -2473,6 +2519,9 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2473,6 +2519,9 @@ public class ToolbarPhone extends ToolbarLayout
} }
mMenuButton.setTint(mUseLightToolbarDrawables ? mLightModeTint : mDarkModeTint); mMenuButton.setTint(mUseLightToolbarDrawables ? mLightModeTint : mDarkModeTint);
if (mLocationBar.useModernDesign()) {
updateModernLocationBarColor(getLocationBarColorForToolbarColor(currentPrimaryColor));
}
setMenuButtonHighlightDrawable(mHighlightingMenu); setMenuButtonHighlightDrawable(mHighlightingMenu);
if (mShowMenuBadge && inOrEnteringStaticTab) { if (mShowMenuBadge && inOrEnteringStaticTab) {
......
...@@ -72,13 +72,18 @@ public class ColorUtils { ...@@ -72,13 +72,18 @@ public class ColorUtils {
*/ */
public static int getTextBoxColorForToolbarBackground( public static int getTextBoxColorForToolbarBackground(
Resources res, boolean isNtp, int color, boolean useModernDesign) { Resources res, boolean isNtp, int color, boolean useModernDesign) {
// If modern is enabled, it is a special case. It's toolbar is white with a darker text box
// background.
boolean usingDefaultThemeColor =
ColorUtils.isUsingDefaultToolbarColor(res, useModernDesign, false, color);
if (usingDefaultThemeColor && useModernDesign) {
return ApiCompatibilityUtils.getColor(res, R.color.modern_light_grey);
}
if (shouldUseOpaqueTextboxBackground(color)) { if (shouldUseOpaqueTextboxBackground(color)) {
// NTP should have no visible textbox in the toolbar, so just return the toolbar's // NTP should have no visible textbox in the toolbar, so just return the toolbar's
// background color. // background color.
if (isNtp) return ApiCompatibilityUtils.getColor(res, R.color.ntp_bg); return isNtp ? ApiCompatibilityUtils.getColor(res, R.color.ntp_bg) : Color.WHITE;
return useModernDesign ? ApiCompatibilityUtils.getColor(res, R.color.modern_light_grey)
: Color.WHITE;
} }
return getColorWithOverlay(color, Color.WHITE, LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA); return getColorWithOverlay(color, Color.WHITE, LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA);
} }
......
...@@ -68,6 +68,11 @@ public class MockResourcesForLayout extends MockResources { ...@@ -68,6 +68,11 @@ public class MockResourcesForLayout extends MockResources {
mFloats.put(org.chromium.chrome.R.dimen.contextual_search_bar_banner_padding, 12.f); mFloats.put(org.chromium.chrome.R.dimen.contextual_search_bar_banner_padding, 12.f);
mFloats.put(org.chromium.chrome.R.dimen.contextual_search_end_button_width, 41.f); mFloats.put(org.chromium.chrome.R.dimen.contextual_search_end_button_width, 41.f);
mFloats.put(org.chromium.chrome.R.dimen.toolbar_height_no_shadow, 56.f); mFloats.put(org.chromium.chrome.R.dimen.toolbar_height_no_shadow, 56.f);
mIntegers.put(R.color.modern_light_grey, 0xFFF1F3F4);
mIntegers.put(R.color.modern_primary_color, Color.WHITE);
mIntegers.put(R.color.default_primary_color, 0xFFF2F2F2);
mIntegers.put(R.color.incognito_primary_color, 0xFF505050);
mIntegers.put(R.color.ntp_bg, 0xFFF2F2F2);
} }
@Override @Override
......
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