Commit 96a44948 authored by Mehran Mahmoudi's avatar Mehran Mahmoudi Committed by Commit Bot

[TTS] Hide In-Product Help BarBanner on second trigger

This CL hides the BarBanner with an animation if it is triggered
while already showing.

Bug: 786459
Change-Id: I252dbad91ebbcca0ce1e7449e556a3e74cc1109a
Reviewed-on: https://chromium-review.googlesource.com/803906Reviewed-by: default avatarDonn Denman <donnd@chromium.org>
Commit-Queue: Mehran Mahmoudi <mahmoudi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521160}
parent 7f80bcc5
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.compositor.bottombar.contextualsearch; package org.chromium.chrome.browser.compositor.bottombar.contextualsearch;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context; import android.content.Context;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -30,6 +32,11 @@ public class ContextualSearchBarBannerControl extends OverlayPanelInflater { ...@@ -30,6 +32,11 @@ public class ContextualSearchBarBannerControl extends OverlayPanelInflater {
*/ */
private boolean mIsVisible; private boolean mIsVisible;
/**
* Whether the Bar Banner is in the process of hiding.
*/
private boolean mIsHiding;
/** /**
* The height of the Bar Banner, in pixels. * The height of the Bar Banner, in pixels.
*/ */
...@@ -111,15 +118,18 @@ public class ContextualSearchBarBannerControl extends OverlayPanelInflater { ...@@ -111,15 +118,18 @@ public class ContextualSearchBarBannerControl extends OverlayPanelInflater {
void hide() { void hide() {
if (!mIsVisible) return; if (!mIsVisible) return;
mIsVisible = false; if (mHeightPx == 0.f) {
mHeightPx = 0.f; mIsVisible = false;
} else {
animateDisappearance();
}
} }
/** /**
* @return The height of the Bar Banner when the Panel is the peeked state. * @return The height of the Bar Banner when the Panel is the peeked state.
*/ */
float getHeightPeekingPx() { float getHeightPeekingPx() {
return mIsVisible ? getPaddedHeightPx() : 0.f; return (!isVisible() || mIsHiding) ? 0.f : getPaddedHeightPx();
} }
/** Calculates the padded height of the bar banner if it has not been calculated before. /** Calculates the padded height of the bar banner if it has not been calculated before.
...@@ -204,7 +214,7 @@ public class ContextualSearchBarBannerControl extends OverlayPanelInflater { ...@@ -204,7 +214,7 @@ public class ContextualSearchBarBannerControl extends OverlayPanelInflater {
* @param percentage The completion percentage. * @param percentage The completion percentage.
*/ */
public void onUpdateFromCloseToPeek(float percentage) { public void onUpdateFromCloseToPeek(float percentage) {
if (!isVisible()) return; if (!isVisible() || mIsHiding) return;
mHeightPx = Math.round(getPaddedHeightPx()); mHeightPx = Math.round(getPaddedHeightPx());
} }
...@@ -215,7 +225,7 @@ public class ContextualSearchBarBannerControl extends OverlayPanelInflater { ...@@ -215,7 +225,7 @@ public class ContextualSearchBarBannerControl extends OverlayPanelInflater {
* @param percentage The completion percentage. * @param percentage The completion percentage.
*/ */
public void onUpdateFromPeekToExpand(float percentage) { public void onUpdateFromPeekToExpand(float percentage) {
if (!isVisible()) return; if (!isVisible() || mIsHiding) return;
mHeightPx = Math.round(MathUtils.interpolate(getPaddedHeightPx(), 0.f, percentage)); mHeightPx = Math.round(MathUtils.interpolate(getPaddedHeightPx(), 0.f, percentage));
mTextOpacity = MathUtils.interpolate(1.f, 0.f, percentage); mTextOpacity = MathUtils.interpolate(1.f, 0.f, percentage);
...@@ -227,7 +237,7 @@ public class ContextualSearchBarBannerControl extends OverlayPanelInflater { ...@@ -227,7 +237,7 @@ public class ContextualSearchBarBannerControl extends OverlayPanelInflater {
* @param percentage The completion percentage. * @param percentage The completion percentage.
*/ */
public void onUpdateFromExpandToMaximize(float percentage) { public void onUpdateFromExpandToMaximize(float percentage) {
if (!isVisible()) return; if (!isVisible() || mIsHiding) return;
mHeightPx = 0.f; mHeightPx = 0.f;
mTextOpacity = 0.f; mTextOpacity = 0.f;
...@@ -262,4 +272,32 @@ public class ContextualSearchBarBannerControl extends OverlayPanelInflater { ...@@ -262,4 +272,32 @@ public class ContextualSearchBarBannerControl extends OverlayPanelInflater {
OverlayPanelAnimation.BASE_ANIMATION_DURATION_MS, listener); OverlayPanelAnimation.BASE_ANIMATION_DURATION_MS, listener);
appearance.start(); appearance.start();
} }
/**
* Animates the Bar Banner disappearance.
*/
private void animateDisappearance() {
mIsHiding = true;
CompositorAnimator disappearance =
CompositorAnimator.ofFloat(mOverlayPanel.getAnimationHandler(), 1.f, 0.f,
OverlayPanelAnimation.BASE_ANIMATION_DURATION_MS, null);
disappearance.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(CompositorAnimator animator) {
if (isVisible()) {
float percentage = animator.getAnimatedFraction();
mHeightPx = MathUtils.interpolate(getPaddedHeightPx(), 0.f, percentage);
}
}
});
disappearance.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mHeightPx = 0.f;
mIsHiding = false;
hide();
}
});
disappearance.start();
}
} }
\ No newline at end of file
...@@ -29,7 +29,7 @@ public class ContextualSearchIPH { ...@@ -29,7 +29,7 @@ public class ContextualSearchIPH {
private boolean mIsShowing; private boolean mIsShowing;
/** /**
* Constructs the helper class and initializes string ids according to featureName. * Constructs the helper class.
*/ */
ContextualSearchIPH() {} ContextualSearchIPH() {}
...@@ -55,7 +55,13 @@ public class ContextualSearchIPH { ...@@ -55,7 +55,13 @@ public class ContextualSearchIPH {
*/ */
void beforePanelShown(boolean wasActivatedByTap, boolean isTapSupported, Profile profile) { void beforePanelShown(boolean wasActivatedByTap, boolean isTapSupported, Profile profile) {
if (!wasActivatedByTap && isTapSupported) { if (!wasActivatedByTap && isTapSupported) {
maybeShow(FeatureConstants.CONTEXTUAL_SEARCH_PROMOTE_TAP_FEATURE, profile); if (mIsShowing
&& mFeatureName.equals(
FeatureConstants.CONTEXTUAL_SEARCH_PROMOTE_TAP_FEATURE)) {
dismiss(profile);
} else {
maybeShow(FeatureConstants.CONTEXTUAL_SEARCH_PROMOTE_TAP_FEATURE, profile);
}
} }
} }
......
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