OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.widget.bottomsheet; | 5 package org.chromium.chrome.browser.widget.bottomsheet; |
6 | 6 |
7 import android.animation.Animator; | 7 import android.animation.Animator; |
8 import android.animation.AnimatorListenerAdapter; | 8 import android.animation.AnimatorListenerAdapter; |
9 import android.animation.ValueAnimator; | 9 import android.animation.ValueAnimator; |
10 import android.content.Context; | 10 import android.content.Context; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 | 175 |
176 /** | 176 /** |
177 * @return The vertical scroll offset of the content view. | 177 * @return The vertical scroll offset of the content view. |
178 */ | 178 */ |
179 int getVerticalScrollOffset(); | 179 int getVerticalScrollOffset(); |
180 | 180 |
181 /** | 181 /** |
182 * Called to destroy the BottomSheetContent when it is no longer in use. | 182 * Called to destroy the BottomSheetContent when it is no longer in use. |
183 */ | 183 */ |
184 void destroy(); | 184 void destroy(); |
185 | |
186 /** | |
187 * @return The String to use when recording user metrics related to this content. | |
188 */ | |
189 String getMetricsName(); | |
185 } | 190 } |
186 | 191 |
187 /** | 192 /** |
188 * This class is responsible for detecting swipe and scroll events on the bo ttom sheet or | 193 * This class is responsible for detecting swipe and scroll events on the bo ttom sheet or |
189 * ignoring them when appropriate. | 194 * ignoring them when appropriate. |
190 */ | 195 */ |
191 private class BottomSheetSwipeDetector extends GestureDetector.SimpleOnGestu reListener { | 196 private class BottomSheetSwipeDetector extends GestureDetector.SimpleOnGestu reListener { |
192 @Override | 197 @Override |
193 public boolean onDown(MotionEvent e) { | 198 public boolean onDown(MotionEvent e) { |
194 return true; | 199 return true; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 * @param context An Android context. | 269 * @param context An Android context. |
265 * @param atts The XML attributes. | 270 * @param atts The XML attributes. |
266 */ | 271 */ |
267 public BottomSheet(Context context, AttributeSet atts) { | 272 public BottomSheet(Context context, AttributeSet atts) { |
268 super(context, atts); | 273 super(context, atts); |
269 | 274 |
270 mVelocityTracker = VelocityTracker.obtain(); | 275 mVelocityTracker = VelocityTracker.obtain(); |
271 | 276 |
272 mGestureDetector = new GestureDetector(context, new BottomSheetSwipeDete ctor()); | 277 mGestureDetector = new GestureDetector(context, new BottomSheetSwipeDete ctor()); |
273 mGestureDetector.setIsLongpressEnabled(false); | 278 mGestureDetector.setIsLongpressEnabled(false); |
279 | |
280 new BottomSheetMetrics(this); | |
274 } | 281 } |
275 | 282 |
276 @Override | 283 @Override |
277 public boolean onInterceptTouchEvent(MotionEvent e) { | 284 public boolean onInterceptTouchEvent(MotionEvent e) { |
278 if (!canMoveSheet()) return false; | 285 if (!canMoveSheet()) return false; |
279 | 286 |
280 // The incoming motion event may have been adjusted by the view sending it down. Create a | 287 // The incoming motion event may have been adjusted by the view sending it down. Create a |
281 // motion event with the raw (x, y) coordinates of the original so the g esture detector | 288 // motion event with the raw (x, y) coordinates of the original so the g esture detector |
282 // functions properly. | 289 // functions properly. |
283 mGestureDetector.onTouchEvent(createRawMotionEvent(e)); | 290 mGestureDetector.onTouchEvent(createRawMotionEvent(e)); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
498 mLastToolbarView = null; | 505 mLastToolbarView = null; |
499 } | 506 } |
500 | 507 |
501 if (mSheetContent.getToolbarView() != null) { | 508 if (mSheetContent.getToolbarView() != null) { |
502 mLastToolbarView = mSheetContent.getToolbarView(); | 509 mLastToolbarView = mSheetContent.getToolbarView(); |
503 mToolbarHolder.addView(mSheetContent.getToolbarView()); | 510 mToolbarHolder.addView(mSheetContent.getToolbarView()); |
504 mDefaultToolbarView.setVisibility(View.GONE); | 511 mDefaultToolbarView.setVisibility(View.GONE); |
505 } else { | 512 } else { |
506 mDefaultToolbarView.setVisibility(View.VISIBLE); | 513 mDefaultToolbarView.setVisibility(View.VISIBLE); |
507 } | 514 } |
515 | |
516 | |
517 for (BottomSheetObserver o : mObservers) { | |
518 o.onSheetContentChanged(mSheetContent); | |
519 } | |
508 } | 520 } |
509 | 521 |
510 /** | 522 /** |
511 * Determines if a touch event is inside the toolbar. This assumes the toolb ar is the full | 523 * Determines if a touch event is inside the toolbar. This assumes the toolb ar is the full |
512 * width of the screen and that the toolbar is at the top of the bottom shee t. | 524 * width of the screen and that the toolbar is at the top of the bottom shee t. |
513 * @param e The motion event to test. | 525 * @param e The motion event to test. |
514 * @return True if the event occured in the toolbar region. | 526 * @return True if the event occured in the toolbar region. |
515 */ | 527 */ |
516 private boolean isTouchEventInToolbar(MotionEvent e) { | 528 private boolean isTouchEventInToolbar(MotionEvent e) { |
517 if (mControlContainer == null) return false; | 529 if (mControlContainer == null) return false; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
721 } | 733 } |
722 } | 734 } |
723 | 735 |
724 /** | 736 /** |
725 * Moves the sheet to the provided state. | 737 * Moves the sheet to the provided state. |
726 * @param state The state to move the panel to. | 738 * @param state The state to move the panel to. |
727 * @param animate If true, the sheet will animate to the provided state, oth erwise it will | 739 * @param animate If true, the sheet will animate to the provided state, oth erwise it will |
728 * move there instantly. | 740 * move there instantly. |
729 */ | 741 */ |
730 public void setSheetState(@SheetState int state, boolean animate) { | 742 public void setSheetState(@SheetState int state, boolean animate) { |
743 boolean stateChanged = state != mCurrentState; | |
731 mCurrentState = state; | 744 mCurrentState = state; |
732 | 745 |
733 if (animate) { | 746 if (animate) { |
734 createSettleAnimation(state); | 747 createSettleAnimation(state); |
735 } else { | 748 } else { |
736 setSheetOffsetFromBottom(getSheetHeightForState(state)); | 749 setSheetOffsetFromBottom(getSheetHeightForState(state)); |
737 } | 750 } |
751 | |
752 if (!stateChanged) return; | |
753 for (BottomSheetObserver o : mObservers) { | |
754 o.onSheetStateChanged(mCurrentState); | |
mdjones
2017/03/17 18:17:26
Admittedly the sheet state concept in this class i
Theresa
2017/03/17 20:26:30
As discussed offline, waiting until onAnimationEnd
| |
755 } | |
738 } | 756 } |
739 | 757 |
740 /** | 758 /** |
741 * @return The current state of the bottom sheet. If the sheet is animating, this will be the | 759 * @return The current state of the bottom sheet. If the sheet is animating, this will be the |
742 * state the sheet is animating to. | 760 * state the sheet is animating to. |
743 */ | 761 */ |
744 public int getSheetState() { | 762 public int getSheetState() { |
745 return mCurrentState; | 763 return mCurrentState; |
746 } | 764 } |
747 | 765 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
826 @Override | 844 @Override |
827 public void onFadingViewVisibilityChanged(boolean visible) {} | 845 public void onFadingViewVisibilityChanged(boolean visible) {} |
828 | 846 |
829 private boolean canMoveSheet() { | 847 private boolean canMoveSheet() { |
830 boolean isInOverviewMode = mTabModelSelector != null | 848 boolean isInOverviewMode = mTabModelSelector != null |
831 && (mTabModelSelector.getCurrentTab() == null | 849 && (mTabModelSelector.getCurrentTab() == null |
832 || mTabModelSelector.getCurrentTab().getActivity().is InOverviewMode()); | 850 || mTabModelSelector.getCurrentTab().getActivity().is InOverviewMode()); |
833 return !isToolbarAndroidViewHidden() && !isInOverviewMode; | 851 return !isToolbarAndroidViewHidden() && !isInOverviewMode; |
834 } | 852 } |
835 } | 853 } |
OLD | NEW |