Commit 43092e12 authored by Matt Jones's avatar Matt Jones Committed by Commit Bot

Make BottomSheet package protected

This patch makes the BottomSheet class protected. Accessors of the
view have been restricted to test methods. Most of the initialization
logic has been moved back into to BottomSheetController class with the
exception of the creation of the view and snackbar manager.

Bug: 986310, 1002277
Change-Id: I5e9cb255f89cd66add8fee93111cf09940be8452
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1910288
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715848}
parent a1b88bfa
......@@ -36,12 +36,12 @@ import org.chromium.base.Supplier;
import org.chromium.base.ThreadUtils;
import org.chromium.chrome.autofill_assistant.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManager;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule;
import org.chromium.chrome.browser.customtabs.CustomTabsTestUtils;
import org.chromium.chrome.browser.image_fetcher.ImageFetcher;
import org.chromium.chrome.browser.image_fetcher.ImageFetcherConfig;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.test.util.Criteria;
......@@ -211,23 +211,21 @@ class AutofillAssistantUiTestUtil {
static BottomSheetController createBottomSheetController(ChromeActivity activity) {
// Copied from {@link ChromeActivity#initializeBottomSheet}.
Supplier<BottomSheet> sheetSupplier = () -> {
Supplier<View> sheetSupplier = () -> {
ViewGroup coordinator = activity.findViewById(R.id.coordinator);
LayoutInflater.from(activity).inflate(R.layout.bottom_sheet, coordinator);
BottomSheet bottomSheet = coordinator.findViewById(R.id.bottom_sheet);
bottomSheet.init(coordinator, activity.getActivityTabProvider(), activity.getWindow(),
activity.getWindowAndroid().getKeyboardDelegate());
View bottomSheet = coordinator.findViewById(R.id.bottom_sheet);
return bottomSheet;
};
Supplier<OverlayPanelManager> panelManagerProvider = () -> {
return activity.getCompositorViewHolder().getLayoutManager().getOverlayPanelManager();
};
return new BottomSheetController(activity.getLifecycleDispatcher(),
activity.getActivityTabProvider(), activity.getScrim(), sheetSupplier,
()
-> activity.getCompositorViewHolder()
.getLayoutManager()
.getOverlayPanelManager(),
activity.getFullscreenManager());
panelManagerProvider, activity.getFullscreenManager(), activity.getWindow(),
activity.getWindowAndroid().getKeyboardDelegate());
}
/**
......
......@@ -161,7 +161,6 @@ import org.chromium.chrome.browser.vr.ArDelegateProvider;
import org.chromium.chrome.browser.vr.VrModuleProvider;
import org.chromium.chrome.browser.webapps.addtohomescreen.AddToHomescreenManager;
import org.chromium.chrome.browser.widget.ScrimView;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContent;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;
......@@ -1427,16 +1426,15 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
}
/**
* Initializes the {@link BottomSheetController}. The {@link BottomSheet} is only initialized
* after content is requested for the first time.
* Initializes the {@link BottomSheetController}. The bottom sheet is only initialized after
* content is requested for the first time.
*/
protected void initializeBottomSheetController() {
Supplier<BottomSheet> sheetSupplier = () -> {
Supplier<View> sheetViewSupplier = () -> {
ViewGroup coordinator = findViewById(R.id.coordinator);
getLayoutInflater().inflate(R.layout.bottom_sheet, coordinator);
BottomSheet sheet = coordinator.findViewById(R.id.bottom_sheet);
sheet.init(coordinator, getActivityTabProvider(), getWindow(),
getWindowAndroid().getKeyboardDelegate());
View sheet = coordinator.findViewById(R.id.bottom_sheet);
mBottomSheetSnackbarManager = new SnackbarManager(
this, sheet.findViewById(R.id.bottom_sheet_snackbar_container));
......@@ -1446,9 +1444,10 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
Supplier<OverlayPanelManager> panelManagerSupplier =
() -> getCompositorViewHolder().getLayoutManager().getOverlayPanelManager();
mBottomSheetController =
new BottomSheetController(getLifecycleDispatcher(), mActivityTabProvider,
mScrimView, sheetSupplier, panelManagerSupplier, getFullscreenManager());
mBottomSheetController = new BottomSheetController(getLifecycleDispatcher(),
mActivityTabProvider, mScrimView, sheetViewSupplier, panelManagerSupplier,
getFullscreenManager(), getWindow(), getWindowAndroid().getKeyboardDelegate());
((BottomContainer) findViewById(R.id.bottom_container))
.setBottomSheetController(mBottomSheetController);
......
......@@ -23,8 +23,8 @@ import org.chromium.chrome.browser.thinwebview.ThinWebView;
import org.chromium.chrome.browser.thinwebview.ThinWebViewFactory;
import org.chromium.chrome.browser.ui.widget.FadingShadow;
import org.chromium.chrome.browser.ui.widget.FadingShadowView;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContent;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.components.embedder_support.view.ContentView;
import org.chromium.components.url_formatter.UrlFormatter;
import org.chromium.content_public.browser.RenderCoordinates;
......@@ -143,7 +143,7 @@ public class EphemeralTabSheetContent implements BottomSheetContent {
TransitionDrawable transitionDrawable = ApiCompatibilityUtils.createTransitionDrawable(
new Drawable[] {mCurrentFavicon, favicon});
transitionDrawable.setCrossFadeEnabled(true);
transitionDrawable.startTransition((int) BottomSheet.BASE_ANIMATION_DURATION_MS);
transitionDrawable.startTransition(BottomSheetController.BASE_ANIMATION_DURATION_MS);
presentedDrawable = transitionDrawable;
}
......
......@@ -52,15 +52,8 @@ import org.chromium.ui.KeyboardVisibilityDelegate;
* All the computation in this file is based off of the bottom of the screen instead of the top
* for simplicity. This means that the bottom of the screen is 0 on the Y axis.
*/
public class BottomSheet
extends FrameLayout implements BottomSheetSwipeDetector.SwipeableBottomSheet,
NativePageHost, View.OnLayoutChangeListener {
/**
* The base duration of the settling animation of the sheet. 218 ms is a spec for material
* design (this is the minimum time a user is guaranteed to pay attention to something).
*/
public static final long BASE_ANIMATION_DURATION_MS = 218;
class BottomSheet extends FrameLayout implements BottomSheetSwipeDetector.SwipeableBottomSheet,
NativePageHost, View.OnLayoutChangeListener {
/**
* The fraction of the way to the next state the sheet must be swiped to animate there when
* released. This is the value used when there are 3 active states. A smaller value here means
......@@ -275,13 +268,13 @@ public class BottomSheet
* Adds layout change listeners to the views that the bottom sheet depends on. Namely the
* heights of the root view and control container are important as they are used in many of the
* calculations in this class.
* @param root The container of the bottom sheet.
* @param tabProvider A means of accessing the active tab.
* @param window Android window for getting insets.
* @param keyboardDelegate Delegate for hiding the keyboard.
*/
public void init(View root, ActivityTabProvider tabProvider, Window window,
public void init(ActivityTabProvider tabProvider, Window window,
KeyboardVisibilityDelegate keyboardDelegate) {
View root = (View) getParent();
mTabSupplier = tabProvider;
mToolbarHolder =
......@@ -609,7 +602,7 @@ public class BottomSheet
mTargetState = targetState;
mSettleAnimator =
ValueAnimator.ofFloat(getCurrentOffsetPx(), getSheetHeightForState(targetState));
mSettleAnimator.setDuration(BASE_ANIMATION_DURATION_MS);
mSettleAnimator.setDuration(BottomSheetController.BASE_ANIMATION_DURATION_MS);
mSettleAnimator.setInterpolator(mInterpolator);
// When the animation is canceled or ends, reset the handle to null.
......@@ -650,7 +643,7 @@ public class BottomSheet
* Sets the sheet's offset relative to the bottom of the screen.
* @param offset The offset that the sheet should be.
*/
private void setSheetOffsetFromBottom(float offset, @StateChangeReason int reason) {
void setSheetOffsetFromBottom(float offset, @StateChangeReason int reason) {
mCurrentOffsetPx = offset;
// The browser controls offset is added here so that the sheet's toolbar behaves like the
......
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.widget.bottomsheet;
import android.view.View;
import android.view.Window;
import androidx.annotation.IntDef;
import androidx.annotation.VisibleForTesting;
......@@ -27,6 +28,7 @@ import org.chromium.chrome.browser.vr.VrModuleProvider;
import org.chromium.chrome.browser.widget.ScrimView;
import org.chromium.chrome.browser.widget.ScrimView.ScrimObserver;
import org.chromium.chrome.browser.widget.ScrimView.ScrimParams;
import org.chromium.ui.KeyboardVisibilityDelegate;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
......@@ -42,6 +44,12 @@ import java.util.PriorityQueue;
* content was actually shown (see full doc on method).
*/
public class BottomSheetController implements Destroyable {
/**
* The base duration of the settling animation of the sheet. 218 ms is a spec for material
* design (this is the minimum time a user is guaranteed to pay attention to something).
*/
public static final int BASE_ANIMATION_DURATION_MS = 218;
/** The different states that the bottom sheet can have. */
@IntDef({SheetState.NONE, SheetState.HIDDEN, SheetState.PEEK, SheetState.HALF, SheetState.FULL,
SheetState.SCROLLING})
......@@ -141,15 +149,16 @@ public class BottomSheetController implements Destroyable {
* @param lifecycleDispatcher The {@link ActivityLifecycleDispatcher} for the {@code activity}.
* @param activityTabProvider The provider of the activity's current tab.
* @param scrim The scrim that shows when the bottom sheet is opened.
* @param bottomSheetSupplier A mechanism for creating a {@link BottomSheet}.
* @param bottomSheetViewSupplier A mechanism for creating a {@link BottomSheet}.
* @param overlayManager A supplier of the manager for overlay panels to attach listeners to.
* This is a supplier to get around wating for native to be initialized.
* @param fullscreenManager A fullscreen manager for access to browser controls offsets.
*/
public BottomSheetController(final ActivityLifecycleDispatcher lifecycleDispatcher,
final ActivityTabProvider activityTabProvider, final ScrimView scrim,
Supplier<BottomSheet> bottomSheetSupplier, Supplier<OverlayPanelManager> overlayManager,
ChromeFullscreenManager fullscreenManager) {
Supplier<View> bottomSheetViewSupplier, Supplier<OverlayPanelManager> overlayManager,
ChromeFullscreenManager fullscreenManager, Window window,
KeyboardVisibilityDelegate keyboardDelegate) {
mTabProvider = activityTabProvider;
mOverlayPanelManager = overlayManager;
mFullscreenManager = fullscreenManager;
......@@ -215,7 +224,8 @@ public class BottomSheetController implements Destroyable {
mFullscreenManager.addListener(mFullscreenListener);
mSheetInitializer = () -> {
initializeSheet(lifecycleDispatcher, scrim, bottomSheetSupplier);
initializeSheet(
lifecycleDispatcher, scrim, bottomSheetViewSupplier, window, keyboardDelegate);
};
}
......@@ -223,11 +233,13 @@ public class BottomSheetController implements Destroyable {
* Do the actual initialization of the bottom sheet.
* @param lifecycleDispatcher A means of binding to the activity's lifecycle.
* @param scrim The scrim to show behind the sheet.
* @param bottomSheetSupplier A means of creating the bottom sheet.
* @param bottomSheetViewSupplier A means of creating the bottom sheet.
*/
private void initializeSheet(final ActivityLifecycleDispatcher lifecycleDispatcher,
final ScrimView scrim, Supplier<BottomSheet> bottomSheetSupplier) {
mBottomSheet = bottomSheetSupplier.get();
final ScrimView scrim, Supplier<View> bottomSheetViewSupplier, Window window,
KeyboardVisibilityDelegate keyboardDelegate) {
mBottomSheet = (BottomSheet) bottomSheetViewSupplier.get();
mBottomSheet.init(mTabProvider, window, keyboardDelegate);
// Initialize the queue with a comparator that checks content priority.
mContentQueue = new PriorityQueue<>(INITIAL_QUEUE_CAPACITY,
......@@ -500,6 +512,16 @@ public class BottomSheetController implements Destroyable {
return mBottomSheet;
}
/**
* This is the same as {@link BottomSheet#setSheetOffsetFromBottom(float, int)} but exclusively
* for testing.
* @param offset The offset to set the sheet to.
*/
@VisibleForTesting
public void setSheetOffsetFromBottomForTesting(float offset) {
mBottomSheet.setSheetOffsetFromBottom(offset, StateChangeReason.NONE);
}
/**
* Request that some content be shown in the bottom sheet.
* @param content The content to be shown in the bottom sheet.
......
......@@ -22,7 +22,6 @@ import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.util.MathUtils;
import org.chromium.chrome.test.BottomSheetTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.ui.test.util.UiRestriction;
......
......@@ -113,7 +113,7 @@ android_library("chrome_java_test_support") {
"javatests/src/org/chromium/chrome/browser/omnibox/suggestions/AutocompleteCoordinatorTestUtils.java",
"javatests/src/org/chromium/chrome/browser/tab/MockTab.java",
"javatests/src/org/chromium/chrome/browser/tab/TabTestUtils.java",
"javatests/src/org/chromium/chrome/test/BottomSheetTestRule.java",
"javatests/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetTestRule.java",
"javatests/src/org/chromium/chrome/test/ChromeActivityTestRule.java",
"javatests/src/org/chromium/chrome/test/ChromeBrowserTestRule.java",
"javatests/src/org/chromium/chrome/test/ChromeJUnit4ClassRunner.java",
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.test;
package org.chromium.chrome.browser.widget.bottomsheet;
import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
import static org.chromium.chrome.browser.ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE;
......@@ -12,11 +12,8 @@ import android.support.test.uiautomator.UiDevice;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContent;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController.StateChangeReason;
import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
/**
......@@ -138,7 +135,7 @@ public class BottomSheetTestRule extends ChromeTabbedActivityTestRule {
*/
public void setSheetOffsetFromBottom(float offset) {
TestThreadUtils.runOnUiThreadBlocking(
() -> getBottomSheet().setSheetOffsetFromBottomForTesting(offset));
() -> mSheetController.setSheetOffsetFromBottomForTesting(offset));
}
public BottomSheetContent getBottomSheetContent() {
......
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