Commit b0d7954c authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

Enhance ripple support to work on tap.

To ensure the ripple animation works when transitioning the
search box drawable between the NTP and the Toolbar, we need
to share the same drawable (including local state).  We need
to also ensure the bounds of the drawable is reset when
transitioning owners between the toolbar and the NTP.


Change-Id: I35261971da8f19c81d5764872912ea0cc93379ad
Reviewed-on: https://chromium-review.googlesource.com/1054851
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558873}
parent 82036716
......@@ -5,9 +5,9 @@
found in the LICENSE file.
-->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@android:color/white" >
android:color="@color/google_grey_400" >
<item
android:drawable="@drawable/modern_toolbar_background"/>
</ripple>
\ No newline at end of file
</ripple>
......@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.ntp;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
......@@ -417,6 +418,15 @@ public class NewTabPage
mNewTabPageView.setSearchProviderLogoAlpha(alpha);
}
/**
* Set the search box background drawable.
*
* @param drawable The search box background.
*/
public void setSearchBoxBackground(Drawable drawable) {
mNewTabPageView.setSearchBoxBackground(drawable);
}
/**
* @return Whether the location bar is shown in the NTP.
*/
......
......@@ -9,6 +9,7 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
......@@ -774,6 +775,15 @@ public class NewTabPageView
mSearchProviderLogoView.setAlpha(alpha);
}
/**
* Set the search box background drawable.
*
* @param drawable The search box background.
*/
public void setSearchBoxBackground(Drawable drawable) {
mSearchBoxView.setBackground(drawable);
}
/**
* Get the bounds of the search box in relation to the top level NewTabPage view.
*
......
......@@ -28,6 +28,7 @@ import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.support.v7.graphics.drawable.DrawableWrapper;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Property;
......@@ -191,6 +192,8 @@ public class ToolbarPhone extends ToolbarLayout
* focused or the NTP search box is being scrolled up. Note that in the latter case, the actual
* width of the omnibox is not interpolated linearly from this value. The value will be the
* maximum of {@link #mUrlFocusChangePercent} and {@link #mNtpSearchBoxScrollPercent}.
*
* 0.0 == no expansion, 1.0 == fully expanded.
*/
@ViewDebug.ExportedProperty(category = "chrome")
protected float mUrlExpansionPercent;
......@@ -212,7 +215,8 @@ public class ToolbarPhone extends ToolbarLayout
protected ColorDrawable mToolbarBackground;
/** The omnibox background (white with a shadow). */
protected Drawable mLocationBarBackground;
private Drawable mLocationBarBackground;
private Drawable mActiveLocationBarBackground;
protected boolean mForceDrawLocationBarBackground;
private TabSwitcherDrawable mTabSwitcherButtonDrawable;
......@@ -407,6 +411,7 @@ public class ToolbarPhone extends ToolbarLayout
mLocationBarBackgroundPadding.top, mLocationBarBackgroundPadding.right,
mLocationBarBackgroundPadding.bottom);
}
mActiveLocationBarBackground = mLocationBarBackground;
}
/**
......@@ -913,6 +918,11 @@ public class ToolbarPhone extends ToolbarLayout
}
}
@Override
protected boolean verifyDrawable(Drawable who) {
return super.verifyDrawable(who) || who == mActiveLocationBarBackground;
}
// NewTabPage.OnSearchBoxScrollListener
@Override
public void onNtpScrollChanged(float scrollPercentage) {
......@@ -1162,6 +1172,7 @@ public class ToolbarPhone extends ToolbarLayout
*/
protected void resetNtpAnimationValues() {
mLocationBarBackgroundNtpOffset.setEmpty();
mActiveLocationBarBackground = mLocationBarBackground;
mNtpSearchBoxTranslation.set(0, 0);
mLocationBar.setTranslationY(0);
if (!mUrlFocusChangeInProgress) {
......@@ -1197,12 +1208,12 @@ public class ToolbarPhone extends ToolbarLayout
// Skip if in or entering tab switcher mode.
if (mTabSwitcherState == TAB_SWITCHER || mTabSwitcherState == ENTERING_TAB_SWITCHER) return;
setAncestorsShouldClipChildren(mUrlExpansionPercent == 0f);
if (!mToolbarShadowPermanentlyHidden
&& !(mLocationBar.useModernDesign() && mUrlFocusChangeInProgress)) {
boolean isExpanded = mUrlExpansionPercent > 0f;
boolean useModern = mLocationBar.useModernDesign();
setAncestorsShouldClipChildren(!isExpanded);
if (!mToolbarShadowPermanentlyHidden && !(useModern && mUrlFocusChangeInProgress)) {
float alpha = 0.f;
if (mLocationBar.useModernDesign() && !mUrlBar.hasFocus()
&& mNtpSearchBoxScrollPercent == 1.f) {
if (useModern && !mUrlBar.hasFocus() && mNtpSearchBoxScrollPercent == 1.f) {
alpha = 1.f;
}
mToolbarShadow.setAlpha(alpha);
......@@ -1225,7 +1236,7 @@ public class ToolbarPhone extends ToolbarLayout
int leftBoundDifference = mNtpSearchBoxBounds.left - mLocationBarBackgroundBounds.left;
int rightBoundDifference = mNtpSearchBoxBounds.right - mLocationBarBackgroundBounds.right;
int verticalInset = 0;
if (mLocationBar.useModernDesign()) {
if (useModern) {
verticalInset = (int) (getResources().getDimensionPixelSize(
R.dimen.ntp_search_box_bounds_vertical_inset_modern)
* (1.f - mUrlExpansionPercent));
......@@ -1245,13 +1256,18 @@ public class ToolbarPhone extends ToolbarLayout
mLocationBarNtpOffsetRight =
(rightBoundDifference + mLocationBarBackgroundCornerRadius) * shrinkage;
mLocationBarBackgroundAlpha = mUrlExpansionPercent > 0f ? 255 : 0;
mLocationBarBackgroundAlpha = isExpanded ? 255 : 0;
mForceDrawLocationBarBackground = mLocationBarBackgroundAlpha > 0;
float relativeAlpha = mLocationBarBackgroundAlpha / 255f;
mLocationBar.setAlpha(relativeAlpha);
// The search box on the NTP is visible if our omnibox is invisible, and vice-versa.
ntp.setSearchBoxAlpha(1f - relativeAlpha);
if (!mForceDrawLocationBarBackground) {
if (mActiveLocationBarBackground instanceof NtpSearchBoxDrawable) {
((NtpSearchBoxDrawable) mActiveLocationBarBackground).resetBoundsToLastNonToolbar();
}
}
updateToolbarBackground(mVisualState);
}
......@@ -1494,7 +1510,11 @@ public class ToolbarPhone extends ToolbarLayout
mLocationBarBackground.setAlpha(backgroundAlpha);
if (shouldDrawLocationBarBackground()) {
mLocationBarBackground.setBounds(
if (mActiveLocationBarBackground instanceof NtpSearchBoxDrawable) {
((NtpSearchBoxDrawable) mActiveLocationBarBackground)
.markPendingBoundsUpdateFromToolbar();
}
mActiveLocationBarBackground.setBounds(
mLocationBarBackgroundBounds.left + mLocationBarBackgroundNtpOffset.left
- mLocationBarBackgroundPadding.left,
mLocationBarBackgroundBounds.top + mLocationBarBackgroundNtpOffset.top
......@@ -1503,7 +1523,7 @@ public class ToolbarPhone extends ToolbarLayout
+ mLocationBarBackgroundPadding.right,
mLocationBarBackgroundBounds.bottom + mLocationBarBackgroundNtpOffset.bottom
+ mLocationBarBackgroundPadding.bottom);
mLocationBarBackground.draw(canvas);
mActiveLocationBarBackground.draw(canvas);
}
float locationBarClipLeft =
......@@ -2338,6 +2358,11 @@ public class ToolbarPhone extends ToolbarLayout
mVisibleNewTabPage = getToolbarDataProvider().getNewTabPageForCurrentTab();
if (mVisibleNewTabPage != null && mVisibleNewTabPage.isLocationBarShownInNTP()) {
mVisibleNewTabPage.setSearchBoxScrollListener(this);
if (mLocationBar.useModernDesign()) {
NtpSearchBoxDrawable ntpSearchBox = new NtpSearchBoxDrawable(getContext(), this);
mVisibleNewTabPage.setSearchBoxBackground(ntpSearchBox);
mActiveLocationBarBackground = ntpSearchBox;
}
requestLayout();
} else if (wasShowingNtp) {
// Convert the previous NTP scroll percentage to URL focus percentage because that
......@@ -2708,4 +2733,73 @@ public class ToolbarPhone extends ToolbarLayout
mFullscreenCalloutToken);
}
}
/**
* Custom drawable that allows sharing the NTP search box drawable between the toolbar and the
* NTP. This allows animations to continue as the drawable is switched between the two owning
* views.
*/
private static class NtpSearchBoxDrawable extends DrawableWrapper {
private final Drawable.Callback mCallback;
private int mBoundsLeft, mBoundsTop, mBoundsRight, mBoundsBottom;
private boolean mPendingBoundsUpdateFromToolbar;
private boolean mDrawnByNtp;
/**
* Constructs the NTP search box drawable.
*
* @param context The context used to inflate the drawable.
* @param callback The callback to be notified on changes ot the drawable.
*/
public NtpSearchBoxDrawable(Context context, Drawable.Callback callback) {
super(ApiCompatibilityUtils.getDrawable(
context.getResources(), R.drawable.ntp_search_box));
mCallback = callback;
setCallback(mCallback);
}
/**
* Mark that the pending bounds update is coming from the toolbar.
*/
void markPendingBoundsUpdateFromToolbar() {
mPendingBoundsUpdateFromToolbar = true;
}
/**
* Reset the bounds of the drawable to the last bounds received that was not marked from
* the toolbar.
*/
void resetBoundsToLastNonToolbar() {
setBounds(mBoundsLeft, mBoundsTop, mBoundsRight, mBoundsBottom);
}
@Override
public void setBounds(int left, int top, int right, int bottom) {
super.setBounds(left, top, right, bottom);
if (!mPendingBoundsUpdateFromToolbar) {
mBoundsLeft = left;
mBoundsTop = top;
mBoundsRight = right;
mBoundsBottom = bottom;
mDrawnByNtp = true;
} else {
mDrawnByNtp = false;
}
mPendingBoundsUpdateFromToolbar = false;
}
@Override
public boolean setVisible(boolean visible, boolean restart) {
// Ignore visibility changes. The NTP can toggle the visibility based on the scroll
// position of the page, so we simply ignore all of this as we expect the drawable to
// be visible at all times of the NTP.
return false;
}
@Override
public Callback getCallback() {
return mDrawnByNtp ? super.getCallback() : mCallback;
}
}
}
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