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

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

Issue 2862893002: 📰 Add visibility change triggers for bottom sheet content (Closed)
Patch Set: cleanup, support app switching Created 3 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.widget.bottomsheet;
6
7 /**
8 * Notifies of events dedicated to changes in visibility of a specific
9 * {@link BottomSheet.BottomSheetContent}.
10 */
11 public abstract class SheetContentStateChangeObserver extends EmptyBottomSheetOb server {
12 @BottomSheet.SheetState
13 private int mCurrentSheetState;
14 private boolean mCurrentVisibility;
15
16 private final BottomSheet.BottomSheetContent mContentObserved;
17 private final BottomSheet mBottomSheet;
18
19 /**
20 * @param bottomSheetContent BottomSheetContent to observe visibility for.
21 * @param bottomSheet The BottomSheet the observed content is registered wit h. Note: the
22 * constructor does not register the object as observer!
23 */
24 public SheetContentStateChangeObserver(
25 BottomSheet.BottomSheetContent bottomSheetContent, BottomSheet botto mSheet) {
26 mContentObserved = bottomSheetContent;
27 mBottomSheet = bottomSheet;
28
29 onStateChange();
30 }
31
32 /** Called when the observed content becomes visible. */
33 public abstract void onContentShown();
34
35 /** Called when the observed content becomes invisible. */
36 public abstract void onContentHidden();
37
38 /**
39 * Called when the bottom sheet stabilises with a new state or visibility.
40 * @param sheetState The new {@link BottomSheet.SheetState}, restricted to s table states:
41 * {@link BottomSheet#SHEET_STATE_FULL},{@link BottomSheet #SHEET_STATE_HALF}
42 * or {@link BottomSheet#SHEET_STATE_PEEK}
43 */
44 public abstract void onContentStateChanged(int sheetState);
Bernhard Bauer 2017/05/05 13:39:54 @BottomSheet.SheetState?
dgn 2017/05/09 16:55:51 Done.
45
46 @BottomSheet.SheetState
47 protected int getCurrentState() {
48 return mCurrentSheetState;
49 }
50
51 @Override
52 public void onSheetOpened() {
53 onStateChange();
54 }
55
56 @Override
57 public void onSheetClosed() {
58 onStateChange();
59 }
60
61 @Override
62 public void onSheetContentChanged(BottomSheet.BottomSheetContent newContent) {
63 onStateChange();
64 }
65
66 @Override
67 public void onSheetStateChanged(int newState) {
68 if (newState == BottomSheet.SHEET_STATE_SCROLLING) return; // Ignore int ermediate states.
Bernhard Bauer 2017/05/05 13:39:55 Don't you already have a seemingly more accurate c
dgn 2017/05/09 16:55:51 Done.
69 onStateChange();
70 }
71
72 private void onStateChange() {
73 @BottomSheet.SheetState
74 int newSheetState = mBottomSheet.getSheetState();
75 boolean newVisibility = mBottomSheet.isSheetOpen()
76 && mBottomSheet.getCurrentSheetContent() == mContentObserved;
77
78 if (newVisibility) {
79 mBottomSheet.getCurrentSheetContent();
Bernhard Bauer 2017/05/05 13:39:55 What's this for? Ensuring that the sheet content i
dgn 2017/05/09 16:55:51 oops ignore, that has nothing to do here.
80 }
81
82 if (newVisibility == mCurrentVisibility && mCurrentSheetState == newShee tState) return;
Bernhard Bauer 2017/05/05 13:39:55 The first part of this check is already in line 84
dgn 2017/05/09 16:55:51 Hum that's the kind of stuff that makes me think I
83
84 if (newVisibility != mCurrentVisibility) {
85 if (newVisibility) {
86 onContentShown();
87 } else {
88 onContentHidden();
89 }
90 mCurrentVisibility = newVisibility;
91 }
92
93 if (BottomSheet.isStateStable(newSheetState)) {
94 onContentStateChanged(newSheetState);
95 mCurrentSheetState = newSheetState;
96 }
97 }
98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698