Commit 71bdacf2 authored by Theresa's avatar Theresa Committed by Commit Bot

[EoC] Add animation for button appearance/disappearance

Add an animtion for the button appearing and disappearing. Also animate
the button when the URL is focused/unfocused.

BUG=889536

Change-Id: I7ca53c2e41da3bedab5b07a133ab4475887c3e17
Reviewed-on: https://chromium-review.googlesource.com/1246944
Commit-Queue: Theresa <twellington@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595182}
parent b6709dfe
......@@ -267,6 +267,7 @@
<dimen name="tablet_toolbar_start_padding">4dp</dimen>
<dimen name="tablet_toolbar_end_padding">6dp</dimen>
<dimen name="location_bar_status_separator_width">1dp</dimen>
<dimen name="toolbar_optional_button_animation_translation">10dp</dimen>
<!-- Modern toolbar dimensions -->
<dimen name="modern_toolbar_background_size">40dp</dimen>
......
......@@ -25,6 +25,7 @@ import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager.Fullscreen
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.toolbar.ToolbarManager;
import org.chromium.chrome.browser.toolbar.ToolbarPhone;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.chrome.browser.util.MathUtils;
import org.chromium.chrome.browser.widget.ListMenuButton;
......@@ -289,7 +290,8 @@ class ContextualSuggestionsMediator
reportEvent(ContextualSuggestionsEvent.UI_BUTTON_SHOWN);
TrackerFactory.getTrackerForProfile(mProfile).notifyEvent(
EventConstants.CONTEXTUAL_SUGGESTIONS_BUTTON_SHOWN);
maybeShowHelpBubble();
mHandler.postDelayed(() -> maybeShowHelpBubble(),
ToolbarPhone.LOC_BAR_WIDTH_CHANGE_ANIMATION_DURATION_MS);
}
@Override
......@@ -433,13 +435,19 @@ class ContextualSuggestionsMediator
}
private void maybeShowHelpBubble() {
View anchorView =
mIphParentView.getRootView().findViewById(R.id.experimental_toolbar_button);
if (mToolbarManager.isUrlBarFocused() || anchorView == null
|| anchorView.getVisibility() != View.VISIBLE) {
return;
}
Tracker tracker = TrackerFactory.getTrackerForProfile(mProfile);
if (!tracker.shouldTriggerHelpUI(FeatureConstants.CONTEXTUAL_SUGGESTIONS_FEATURE)) {
return;
}
ViewRectProvider rectProvider = new ViewRectProvider(
mIphParentView.getRootView().findViewById(R.id.experimental_toolbar_button));
ViewRectProvider rectProvider = new ViewRectProvider(anchorView);
rectProvider.setInsetPx(0, 0, 0,
mIphParentView.getResources().getDimensionPixelOffset(
R.dimen.text_bubble_menu_anchor_y_inset));
......
......@@ -63,7 +63,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
/**
* The ImageButton view that represents the menu button.
*/
private TintedImageButton mMenuButton;
protected TintedImageButton mMenuButton;
private ImageView mMenuBadge;
private View mMenuButtonWrapper;
private AppMenuButtonHelper mAppMenuButtonHelper;
......
......@@ -667,6 +667,13 @@ public class ToolbarManager implements ToolbarTabController, UrlFocusChangeListe
mLoadProgressSimulator = new LoadProgressSimulator(this);
}
/**
* @return Whether the UrlBar currently has focus.
*/
public boolean isUrlBarFocused() {
return getToolbarLayout().getLocationBar().isUrlBarFocused();
}
/**
* @param reason A {@link OmniboxFocusReason} that the omnibox was focused.
*/
......
......@@ -528,7 +528,10 @@ public class ContextualSuggestionsTest {
"Toolbar button should be visible", View.VISIBLE, toolbarButton.getVisibility());
// Simulate suggestions being cleared.
ThreadUtils.runOnUiThreadBlocking(() -> mMediator.clearState());
ThreadUtils.runOnUiThreadBlocking(() -> {
mMediator.clearState();
getToolbarPhone().endExperimentalButtonAnimationForTesting();
});
assertEquals("Toolbar button should be gone", View.GONE, toolbarButton.getVisibility());
assertEquals("Suggestions should be cleared", 0, mModel.getClusterList().getItemCount());
......@@ -598,10 +601,8 @@ public class ContextualSuggestionsTest {
}
private View getToolbarButton(ChromeActivity activity) throws ExecutionException {
return ThreadUtils.runOnUiThreadBlocking(() -> {
return ((ToolbarPhone) activity.getToolbarManager().getToolbarLayout())
.getExperimentalButtonForTesting();
});
return ThreadUtils.runOnUiThreadBlocking(
() -> { return getToolbarPhone(activity).getExperimentalButtonForTesting(); });
}
private void clickToolbarButton() throws ExecutionException {
......@@ -641,6 +642,9 @@ public class ContextualSuggestionsTest {
CriteriaHelper.pollUiThread(() -> {
return mActivityTestRule.getActivity().getActivityTab().getUrl().equals(expectedUrl);
});
ThreadUtils.runOnUiThreadBlocking(
() -> getToolbarPhone().endExperimentalButtonAnimationForTesting());
}
private void dismissHelpBubble() {
......@@ -650,4 +654,12 @@ public class ContextualSuggestionsTest {
}
});
}
private ToolbarPhone getToolbarPhone() {
return getToolbarPhone(mActivityTestRule.getActivity());
}
private ToolbarPhone getToolbarPhone(ChromeActivity activity) {
return (ToolbarPhone) activity.getToolbarManager().getToolbarLayout();
}
}
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