Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheet.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheet.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheet.java |
| index a115135d59af7bc65267642ef4961de909061721..575a80d5496b18dfcf0dca75b35b7352a480beb1 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheet.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheet.java |
| @@ -53,12 +53,13 @@ import java.lang.annotation.RetentionPolicy; |
| public class BottomSheet |
| extends FrameLayout implements FadingBackgroundView.FadingViewObserver, NativePageHost { |
| /** The different states that the bottom sheet can have. */ |
| - @IntDef({SHEET_STATE_PEEK, SHEET_STATE_HALF, SHEET_STATE_FULL}) |
| + @IntDef({SHEET_STATE_PEEK, SHEET_STATE_HALF, SHEET_STATE_FULL, SHEET_STATE_SCROLLING}) |
| @Retention(RetentionPolicy.SOURCE) |
| public @interface SheetState {} |
| public static final int SHEET_STATE_PEEK = 0; |
| public static final int SHEET_STATE_HALF = 1; |
| public static final int SHEET_STATE_FULL = 2; |
| + public static final int SHEET_STATE_SCROLLING = 3; |
| /** |
| * The base duration of the settling animation of the sheet. 218 ms is a spec for material |
| @@ -113,9 +114,12 @@ public class BottomSheet |
| /** The height of the view that contains the bottom sheet. */ |
| private float mContainerHeight; |
| - /** The current sheet state. If the sheet is moving, this will be the target state. */ |
| + /** The current state that the sheet is in. */ |
| private int mCurrentState; |
| + /** The target sheet state. This is the state that the sheet is currently moving to. */ |
| + private int mTargetState; |
| + |
| /** Used for getting the current tab. */ |
| private TabModelSelector mTabModelSelector; |
| @@ -248,6 +252,7 @@ public class BottomSheet |
| float newOffset = getSheetOffsetFromBottom() + distanceY; |
| setSheetOffsetFromBottom(MathUtils.clamp(newOffset, getMinOffset(), getMaxOffset())); |
| + setInternalCurrentState(SHEET_STATE_SCROLLING); |
| mIsScrolling = true; |
| return true; |
| } |
| @@ -388,7 +393,7 @@ public class BottomSheet |
| updateSheetDimensions(); |
| cancelAnimation(); |
| - setSheetState(mCurrentState, false); |
| + setSheetState(mTargetState, false); |
| } |
| }); |
| @@ -406,7 +411,7 @@ public class BottomSheet |
| updateSheetDimensions(); |
| cancelAnimation(); |
| - setSheetState(mCurrentState, false); |
| + setSheetState(mTargetState, false); |
| } |
| }); |
| @@ -609,7 +614,7 @@ public class BottomSheet |
| * @param targetState The target state. |
| */ |
| private void createSettleAnimation(@SheetState int targetState) { |
| - mCurrentState = targetState; |
| + mTargetState = targetState; |
| mSettleAnimator = ValueAnimator.ofFloat( |
| getSheetOffsetFromBottom(), getSheetHeightForState(targetState)); |
| mSettleAnimator.setDuration(BASE_ANIMATION_DURATION_MS); |
| @@ -620,6 +625,7 @@ public class BottomSheet |
| @Override |
| public void onAnimationEnd(Animator animator) { |
| mSettleAnimator = null; |
| + setInternalCurrentState(mTargetState); |
| } |
| }); |
| @@ -631,6 +637,7 @@ public class BottomSheet |
| }); |
| mSettleAnimator.start(); |
| + setInternalCurrentState(SHEET_STATE_SCROLLING); |
| } |
| /** |
| @@ -745,24 +752,19 @@ public class BottomSheet |
| /** |
| * Moves the sheet to the provided state. |
| - * @param state The state to move the panel to. |
| + * @param state The state to move the panel to. This cannot be SHEET_STATE_SCROLLING. |
| * @param animate If true, the sheet will animate to the provided state, otherwise it will |
| * move there instantly. |
| */ |
| public void setSheetState(@SheetState int state, boolean animate) { |
| - boolean stateChanged = state != mCurrentState; |
| - mCurrentState = state; |
| + assert state != SHEET_STATE_SCROLLING; |
| + mTargetState = state; |
| if (animate) { |
| createSettleAnimation(state); |
| } else { |
| setSheetOffsetFromBottom(getSheetHeightForState(state)); |
| - } |
| - |
| - if (!stateChanged) return; |
| - |
| - for (BottomSheetObserver o : mObservers) { |
| - o.onSheetStateChanged(mCurrentState); |
| + setInternalCurrentState(mTargetState); |
| } |
| } |
| @@ -775,6 +777,22 @@ public class BottomSheet |
| } |
| /** |
| + * Set the current state of the bottom sheet. This is for internal use to notify observers of |
| + * state change events. |
| + * @param state The current state of the sheet. |
| + */ |
| + private void setInternalCurrentState(@SheetState int state) { |
| + boolean stateChanged = state != mCurrentState; |
| + mCurrentState = state; |
| + |
| + if (!stateChanged) return; |
|
Theresa
2017/03/21 23:07:01
This early return can move up:
if (state == mCurr
mdjones
2017/03/21 23:32:42
Done.
|
| + |
| + for (BottomSheetObserver o : mObservers) { |
| + o.onSheetStateChanged(mCurrentState); |
| + } |
| + } |
| + |
| + /** |
| * If the animation to settle the sheet in one of its states is running. |
| * @return True if the animation is running. |
| */ |