Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheet.java

Issue 2754313002: [Home] Record some user actions for the Chrome Home BottomSheet (Closed)
Patch Set: Move early return to BottomSheet Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 144
145 /** 145 /**
146 * The default toolbar view. This is shown when the current bottom sheet con tent doesn't have 146 * The default toolbar view. This is shown when the current bottom sheet con tent doesn't have
147 * its own toolbar and when the bottom sheet is closed. 147 * its own toolbar and when the bottom sheet is closed.
148 */ 148 */
149 private View mDefaultToolbarView; 149 private View mDefaultToolbarView;
150 150
151 /** The last non-default toolbar view that was attached to mToolbarHolder. * / 151 /** The last non-default toolbar view that was attached to mToolbarHolder. * /
152 private View mLastToolbarView; 152 private View mLastToolbarView;
153 153
154 /** Whether the sheet is currently open. */
155 private boolean mIsSheetOpen;
156
154 /** 157 /**
155 * An interface defining content that can be displayed inside of the bottom sheet for Chrome 158 * An interface defining content that can be displayed inside of the bottom sheet for Chrome
156 * Home. 159 * Home.
157 */ 160 */
158 public interface BottomSheetContent { 161 public interface BottomSheetContent {
159 /** 162 /**
160 * Gets the {@link View} that holds the content to be displayed in the C hrome Home bottom 163 * Gets the {@link View} that holds the content to be displayed in the C hrome Home bottom
161 * sheet. 164 * sheet.
162 * @return The content view. 165 * @return The content view.
163 */ 166 */
(...skipping 11 matching lines...) Expand all
175 178
176 /** 179 /**
177 * @return The vertical scroll offset of the content view. 180 * @return The vertical scroll offset of the content view.
178 */ 181 */
179 int getVerticalScrollOffset(); 182 int getVerticalScrollOffset();
180 183
181 /** 184 /**
182 * Called to destroy the BottomSheetContent when it is no longer in use. 185 * Called to destroy the BottomSheetContent when it is no longer in use.
183 */ 186 */
184 void destroy(); 187 void destroy();
188
189 /**
190 * @return The {@link BottomSheetContentController.ContentType} for this content.
191 */
192 int getType();
185 } 193 }
186 194
187 /** 195 /**
188 * This class is responsible for detecting swipe and scroll events on the bo ttom sheet or 196 * This class is responsible for detecting swipe and scroll events on the bo ttom sheet or
189 * ignoring them when appropriate. 197 * ignoring them when appropriate.
190 */ 198 */
191 private class BottomSheetSwipeDetector extends GestureDetector.SimpleOnGestu reListener { 199 private class BottomSheetSwipeDetector extends GestureDetector.SimpleOnGestu reListener {
192 @Override 200 @Override
193 public boolean onDown(MotionEvent e) { 201 public boolean onDown(MotionEvent e) {
194 return true; 202 return true;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 * @param context An Android context. 272 * @param context An Android context.
265 * @param atts The XML attributes. 273 * @param atts The XML attributes.
266 */ 274 */
267 public BottomSheet(Context context, AttributeSet atts) { 275 public BottomSheet(Context context, AttributeSet atts) {
268 super(context, atts); 276 super(context, atts);
269 277
270 mVelocityTracker = VelocityTracker.obtain(); 278 mVelocityTracker = VelocityTracker.obtain();
271 279
272 mGestureDetector = new GestureDetector(context, new BottomSheetSwipeDete ctor()); 280 mGestureDetector = new GestureDetector(context, new BottomSheetSwipeDete ctor());
273 mGestureDetector.setIsLongpressEnabled(false); 281 mGestureDetector.setIsLongpressEnabled(false);
282
283 new BottomSheetMetrics(this);
274 } 284 }
275 285
276 @Override 286 @Override
277 public boolean onInterceptTouchEvent(MotionEvent e) { 287 public boolean onInterceptTouchEvent(MotionEvent e) {
278 if (!canMoveSheet()) return false; 288 if (!canMoveSheet()) return false;
279 289
280 // The incoming motion event may have been adjusted by the view sending it down. Create a 290 // 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 291 // motion event with the raw (x, y) coordinates of the original so the g esture detector
282 // functions properly. 292 // functions properly.
283 mGestureDetector.onTouchEvent(createRawMotionEvent(e)); 293 mGestureDetector.onTouchEvent(createRawMotionEvent(e));
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 mLastToolbarView = null; 508 mLastToolbarView = null;
499 } 509 }
500 510
501 if (mSheetContent.getToolbarView() != null) { 511 if (mSheetContent.getToolbarView() != null) {
502 mLastToolbarView = mSheetContent.getToolbarView(); 512 mLastToolbarView = mSheetContent.getToolbarView();
503 mToolbarHolder.addView(mSheetContent.getToolbarView()); 513 mToolbarHolder.addView(mSheetContent.getToolbarView());
504 mDefaultToolbarView.setVisibility(View.GONE); 514 mDefaultToolbarView.setVisibility(View.GONE);
505 } else { 515 } else {
506 mDefaultToolbarView.setVisibility(View.VISIBLE); 516 mDefaultToolbarView.setVisibility(View.VISIBLE);
507 } 517 }
518
519
gone 2017/03/20 20:29:31 nit: too many newlines
Theresa 2017/03/20 20:59:12 Done.
520 for (BottomSheetObserver o : mObservers) {
521 o.onSheetContentChanged(mSheetContent);
522 }
508 } 523 }
509 524
510 /** 525 /**
511 * Determines if a touch event is inside the toolbar. This assumes the toolb ar is the full 526 * 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. 527 * 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. 528 * @param e The motion event to test.
514 * @return True if the event occured in the toolbar region. 529 * @return True if the event occured in the toolbar region.
515 */ 530 */
516 private boolean isTouchEventInToolbar(MotionEvent e) { 531 private boolean isTouchEventInToolbar(MotionEvent e) {
517 if (mControlContainer == null) return false; 532 if (mControlContainer == null) return false;
518 533
519 mControlContainer.getLocationInWindow(mLocationArray); 534 mControlContainer.getLocationInWindow(mLocationArray);
520 535
521 return e.getRawY() < mLocationArray[1] + mToolbarHeight; 536 return e.getRawY() < mLocationArray[1] + mToolbarHeight;
522 } 537 }
523 538
524 /** 539 /**
525 * A notification that the sheet is exiting the peek state into one that sho ws content. 540 * A notification that the sheet is exiting the peek state into one that sho ws content.
526 */ 541 */
527 private void onSheetOpened() { 542 private void onSheetOpened() {
543 if (mIsSheetOpen) return;
544
545 mIsSheetOpen = true;
528 for (BottomSheetObserver o : mObservers) o.onSheetOpened(); 546 for (BottomSheetObserver o : mObservers) o.onSheetOpened();
529 } 547 }
530 548
531 /** 549 /**
532 * A notification that the sheet has returned to the peeking state. 550 * A notification that the sheet has returned to the peeking state.
533 */ 551 */
534 private void onSheetClosed() { 552 private void onSheetClosed() {
553 if (!mIsSheetOpen) return;
554
555 mIsSheetOpen = false;
535 for (BottomSheetObserver o : mObservers) o.onSheetClosed(); 556 for (BottomSheetObserver o : mObservers) o.onSheetClosed();
536 } 557 }
537 558
538 /** 559 /**
539 * Creates an unadjusted version of a MotionEvent. 560 * Creates an unadjusted version of a MotionEvent.
540 * @param e The original event. 561 * @param e The original event.
541 * @return The unadjusted version of the event. 562 * @return The unadjusted version of the event.
542 */ 563 */
543 private MotionEvent createRawMotionEvent(MotionEvent e) { 564 private MotionEvent createRawMotionEvent(MotionEvent e) {
544 MotionEvent rawEvent = MotionEvent.obtain(e); 565 MotionEvent rawEvent = MotionEvent.obtain(e);
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 } 742 }
722 } 743 }
723 744
724 /** 745 /**
725 * Moves the sheet to the provided state. 746 * Moves the sheet to the provided state.
726 * @param state The state to move the panel to. 747 * @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 748 * @param animate If true, the sheet will animate to the provided state, oth erwise it will
728 * move there instantly. 749 * move there instantly.
729 */ 750 */
730 public void setSheetState(@SheetState int state, boolean animate) { 751 public void setSheetState(@SheetState int state, boolean animate) {
752 boolean stateChanged = state != mCurrentState;
731 mCurrentState = state; 753 mCurrentState = state;
732 754
733 if (animate) { 755 if (animate) {
734 createSettleAnimation(state); 756 createSettleAnimation(state);
735 } else { 757 } else {
736 setSheetOffsetFromBottom(getSheetHeightForState(state)); 758 setSheetOffsetFromBottom(getSheetHeightForState(state));
737 } 759 }
760
761 if (!stateChanged) return;
gone 2017/03/20 20:29:31 Why is this check so far down? Seems like you wou
Theresa 2017/03/20 20:59:12 The sheet doesn't end up in the correct place if t
762
763 for (BottomSheetObserver o : mObservers) {
764 o.onSheetStateChanged(mCurrentState);
765 }
738 } 766 }
739 767
740 /** 768 /**
741 * @return The current state of the bottom sheet. If the sheet is animating, this will be the 769 * @return The current state of the bottom sheet. If the sheet is animating, this will be the
742 * state the sheet is animating to. 770 * state the sheet is animating to.
743 */ 771 */
744 public int getSheetState() { 772 public int getSheetState() {
745 return mCurrentState; 773 return mCurrentState;
746 } 774 }
747 775
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 @Override 854 @Override
827 public void onFadingViewVisibilityChanged(boolean visible) {} 855 public void onFadingViewVisibilityChanged(boolean visible) {}
828 856
829 private boolean canMoveSheet() { 857 private boolean canMoveSheet() {
830 boolean isInOverviewMode = mTabModelSelector != null 858 boolean isInOverviewMode = mTabModelSelector != null
831 && (mTabModelSelector.getCurrentTab() == null 859 && (mTabModelSelector.getCurrentTab() == null
832 || mTabModelSelector.getCurrentTab().getActivity().is InOverviewMode()); 860 || mTabModelSelector.getCurrentTab().getActivity().is InOverviewMode());
833 return !isToolbarAndroidViewHidden() && !isInOverviewMode; 861 return !isToolbarAndroidViewHidden() && !isInOverviewMode;
834 } 862 }
835 } 863 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698