Commit 52fe73d0 authored by bttk's avatar bttk Committed by Commit Bot

[ToolbarMVC] Add nested LocationBar interfaces for phone and tablet

Making Toolbar interact with LocationBar only through those interfaces
uncovered which LocationBar* and View methods are used.
Next these interfaces can be replaced by Coordinator objects.

Bug: 1133482
Change-Id: Iececeed429fee66f7adbeb515a328403ef1b1aab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2444470Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarBrandon Wylie <wylieb@chromium.org>
Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Commit-Queue: who/bttk <bttk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814529}
parent b7edca7e
......@@ -12,6 +12,7 @@ import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.TouchDelegate;
import android.view.View;
import android.widget.FrameLayout;
import org.chromium.base.TraceEvent;
import org.chromium.chrome.R;
......@@ -23,7 +24,7 @@ import java.util.List;
/**
* A location bar implementation specific for smaller/phone screens.
*/
public class LocationBarPhone extends LocationBarLayout {
public class LocationBarPhone extends LocationBarLayout implements LocationBar.Phone {
private static final int ACTION_BUTTON_TOUCH_OVERFLOW_LEFT = 15;
private View mFirstVisibleFocusedView;
......@@ -94,6 +95,7 @@ public class LocationBarPhone extends LocationBarLayout {
* @return Width of child views before the first view that would be visible when location bar is
* focused. The first visible, focused view should be either url bar or status icon.
*/
@Override
public int getOffsetOfFirstVisibleFocusedView() {
int visibleWidth = 0;
for (int i = 0; i < getChildCount(); i++) {
......@@ -112,6 +114,7 @@ public class LocationBarPhone extends LocationBarLayout {
* @param durationMs Duration of fade animation in milliseconds.
* @param targetAlpha Target alpha value.
*/
@Override
public void populateFadeAnimations(
List<Animator> animators, long startDelayMs, long durationMs, float targetAlpha) {
for (int i = 0; i < getChildCount(); i++) {
......@@ -133,6 +136,7 @@ public class LocationBarPhone extends LocationBarLayout {
* animation starting and the unfocus animation starting.
* @return The offset for the location bar when showing the dse icon.
*/
@Override
public int getLocationBarOffsetForFocusAnimation(boolean hasFocus) {
if (mStatusCoordinator == null) return 0;
......@@ -166,6 +170,7 @@ public class LocationBarPhone extends LocationBarLayout {
* animation starting and the unfocus animation starting.
* @return The X translation for the URL bar, used in the toolbar animation.
*/
@Override
public float getUrlBarTranslationXForToolbarAnimation(
float urlExpansionPercent, boolean hasFocus) {
// This will be called before status view is ready.
......@@ -277,6 +282,11 @@ public class LocationBarPhone extends LocationBarLayout {
mStatusCoordinator.onUrlAnimationFinished(hasFocus);
}
@Override
public FrameLayout.LayoutParams getFrameLayoutParams() {
return (FrameLayout.LayoutParams) getLayoutParams();
}
@Override
protected void updateButtonVisibility() {
super.updateButtonVisibility();
......@@ -328,6 +338,11 @@ public class LocationBarPhone extends LocationBarLayout {
}
}
@Override
public View getViewForDrawing() {
return this;
}
/** Update the status visibility according to the current state held in LocationBar. */
private void updateStatusVisibility() {
boolean incognito = getToolbarDataProvider().isIncognito();
......
......@@ -29,7 +29,7 @@ import java.util.List;
/**
* Location bar for tablet form factors.
*/
public class LocationBarTablet extends LocationBarLayout {
public class LocationBarTablet extends LocationBarLayout implements LocationBar.Tablet {
private static final long MAX_NTP_KEYBOARD_FOCUS_DURATION_MS = 200;
private static final int ICON_FADE_ANIMATION_DURATION_MS = 150;
......@@ -187,6 +187,7 @@ public class LocationBarTablet extends LocationBarLayout {
* @param shouldShowButtons Whether buttons should be displayed in the URL bar when it's not
* focused.
*/
@Override
public void setShouldShowButtonsWhenUnfocused(boolean shouldShowButtons) {
mShouldShowButtonsWhenUnfocused = shouldShowButtons;
updateButtonVisibility();
......@@ -267,6 +268,7 @@ public class LocationBarTablet extends LocationBarLayout {
* @return An animator to run for the given view when showing buttons in the unfocused location
* bar. This should also be used to create animators for showing toolbar buttons.
*/
@Override
public ObjectAnimator createShowButtonAnimator(View button) {
if (button.getVisibility() != View.VISIBLE) {
button.setAlpha(0.f);
......@@ -283,6 +285,7 @@ public class LocationBarTablet extends LocationBarLayout {
* @return An animator to run for the given view when hiding buttons in the unfocused location
* bar. This should also be used to create animators for hiding toolbar buttons.
*/
@Override
public ObjectAnimator createHideButtonAnimator(View button) {
ObjectAnimator buttonAnimator = ObjectAnimator.ofFloat(button, View.ALPHA, 0.f);
buttonAnimator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
......@@ -299,6 +302,7 @@ public class LocationBarTablet extends LocationBarLayout {
* the beginning and end of the animation.
* @return An ArrayList of animators to run.
*/
@Override
public List<Animator> getShowButtonsWhenUnfocusedAnimators(int toolbarStartPaddingDifference) {
mToolbarStartPaddingDifference = toolbarStartPaddingDifference;
......@@ -353,6 +357,7 @@ public class LocationBarTablet extends LocationBarLayout {
* the beginning and end of the animation.
* @return An ArrayList of animators to run.
*/
@Override
public List<Animator> getHideButtonsWhenUnfocusedAnimators(int toolbarStartPaddingDifference) {
mToolbarStartPaddingDifference = toolbarStartPaddingDifference;
......
......@@ -32,7 +32,6 @@ import org.chromium.chrome.browser.download.DownloadUtils;
import org.chromium.chrome.browser.homepage.HomepageManager;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.omnibox.LocationBar;
import org.chromium.chrome.browser.omnibox.LocationBarTablet;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.profiles.Profile;
......@@ -85,7 +84,8 @@ public class ToolbarTablet extends ToolbarLayout
private NavigationPopup mNavigationPopup;
private Boolean mIsIncognito;
private LocationBarTablet mLocationBar;
private LocationBar mLocationBar;
private LocationBar.Tablet mLocationBarTablet;
private final int mStartPaddingWithButtons;
private final int mStartPaddingWithoutButtons;
......@@ -110,7 +110,8 @@ public class ToolbarTablet extends ToolbarLayout
@Override
public void onFinishInflate() {
super.onFinishInflate();
mLocationBar = (LocationBarTablet) findViewById(R.id.location_bar);
mLocationBar = (LocationBar) findViewById(R.id.location_bar);
mLocationBarTablet = (LocationBar.Tablet) mLocationBar;
mHomeButton = findViewById(R.id.home_button);
mBackButton = findViewById(R.id.back_button);
......@@ -391,7 +392,7 @@ public class ToolbarTablet extends ToolbarLayout
setBackgroundColor(color);
final int textBoxColor = ToolbarColors.getTextBoxColorForToolbarBackgroundInNonNativePage(
getResources(), color, isIncognito());
mLocationBar.getBackground().setColorFilter(textBoxColor, PorterDuff.Mode.SRC_IN);
mLocationBarTablet.getBackground().setColorFilter(textBoxColor, PorterDuff.Mode.SRC_IN);
mLocationBar.updateVisualsForState();
}
......@@ -428,7 +429,7 @@ public class ToolbarTablet extends ToolbarLayout
@Override
void updateButtonVisibility() {
mLocationBar.updateButtonVisibility();
mLocationBarTablet.updateButtonVisibility();
}
@Override
......@@ -616,7 +617,7 @@ public class ToolbarTablet extends ToolbarLayout
for (ImageButton button : mToolbarButtons) {
button.setVisibility(visible ? View.VISIBLE : View.GONE);
}
mLocationBar.setShouldShowButtonsWhenUnfocused(visible);
mLocationBarTablet.setShouldShowButtonsWhenUnfocused(visible);
setStartPaddingBasedOnButtonVisibility(visible);
}
}
......@@ -657,11 +658,11 @@ public class ToolbarTablet extends ToolbarLayout
// Create animators for all of the toolbar buttons.
for (ImageButton button : mToolbarButtons) {
animators.add(mLocationBar.createShowButtonAnimator(button));
animators.add(mLocationBarTablet.createShowButtonAnimator(button));
}
// Add animators for location bar.
animators.addAll(mLocationBar.getShowButtonsWhenUnfocusedAnimators(
animators.addAll(mLocationBarTablet.getShowButtonsWhenUnfocusedAnimators(
getStartPaddingDifferenceForButtonVisibilityAnimation()));
AnimatorSet set = new AnimatorSet();
......@@ -692,11 +693,11 @@ public class ToolbarTablet extends ToolbarLayout
// Create animators for all of the toolbar buttons.
for (ImageButton button : mToolbarButtons) {
animators.add(mLocationBar.createHideButtonAnimator(button));
animators.add(mLocationBarTablet.createHideButtonAnimator(button));
}
// Add animators for location bar.
animators.addAll(mLocationBar.getHideButtonsWhenUnfocusedAnimators(
animators.addAll(mLocationBarTablet.getHideButtonsWhenUnfocusedAnimators(
getStartPaddingDifferenceForButtonVisibilityAnimation()));
AnimatorSet set = new AnimatorSet();
......
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