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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheet.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 side-by-side diff with in-line comments
Download patch
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 48602af38b47d2ece5e6084edd9c66138dda557a..d56158733ce8361e69ffcb213a79f9d5866e06d0 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
@@ -9,6 +9,7 @@
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
+import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
@@ -27,11 +28,15 @@
import android.view.animation.Interpolator;
import android.widget.FrameLayout;
+import org.chromium.base.ActivityState;
+import org.chromium.base.ActivityState.ActivityStateEnum;
import org.chromium.base.ApiCompatibilityUtils;
+import org.chromium.base.ApplicationStatus;
import org.chromium.base.ContextUtils;
import org.chromium.base.ObserverList;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
+import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.NativePageHost;
import org.chromium.chrome.browser.TabLoadStatus;
import org.chromium.chrome.browser.firstrun.FirstRunStatus;
@@ -353,6 +358,20 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
}
}
+ /** Returns whether the bottom sheet is in a stable state, not transitioning or animating. */
mdjones 2017/05/05 15:52:00 Full javadoc please.
dgn 2017/05/09 16:55:51 Done.
+ public static boolean isStateStable(@SheetState int sheetState) {
+ switch (sheetState) {
+ case SHEET_STATE_PEEK:
+ case SHEET_STATE_HALF:
+ case SHEET_STATE_FULL:
+ return true;
+ case SHEET_STATE_NONE:
mdjones 2017/05/05 15:52:00 SHEET_STATE_NONE is a private member that is used
dgn 2017/05/09 16:55:51 Added an assert here, as otherwise the linter comp
+ case SHEET_STATE_SCROLLING:
+ default:
+ return false;
+ }
+ }
+
/**
* Constructor for inflation from XML.
* @param context An Android context.
@@ -518,8 +537,9 @@ private boolean isToolbarAndroidViewHidden() {
* calculations in this class.
* @param root The container of the bottom sheet.
* @param controlContainer The container for the toolbar.
+ * @param chromeActivity The activity in which this bottom bar is contained.
*/
- public void init(View root, View controlContainer) {
+ public void init(View root, View controlContainer, final ChromeActivity chromeActivity) {
mControlContainer = controlContainer;
mToolbarHeight = mControlContainer.getHeight();
@@ -569,6 +589,29 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom,
}
});
+ ApplicationStatus.registerStateListenerForActivity(
mdjones 2017/05/05 15:52:00 I'd rather see this logic attached to the Suggesti
dgn 2017/05/09 16:55:51 Done.
+ new ApplicationStatus.ActivityStateListener() {
+ @Override
+ public void onActivityStateChange(
+ Activity activity, @ActivityStateEnum int newState) {
+ assert chromeActivity == activity;
+
+ if (newState == ActivityState.DESTROYED) {
+ ApplicationStatus.unregisterActivityStateListener(this);
+ return;
+ }
+
+ if (!mIsSheetOpen) return;
+
+ if (newState == ActivityState.RESUMED) {
+ onSheetForegrounded();
+ } else if (newState == ActivityState.PAUSED) {
+ onSheetBackgrounded();
+ }
+ }
+ },
+ chromeActivity);
+
mPlaceholder = new View(getContext());
LayoutParams placeHolderParams =
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
@@ -789,6 +832,20 @@ private void onSheetClosed() {
}
/**
+ * A notification that the sheet was revealed by putting the app in the foreground.
+ */
+ private void onSheetForegrounded() {
+ for (BottomSheetObserver o : mObservers) o.onSheetForegrounded();
+ }
+
+ /**
+ * A notification that the sheet was hidden by putting the app in the background.
+ */
+ private void onSheetBackgrounded() {
+ for (BottomSheetObserver o : mObservers) o.onSheetBackgrounded();
+ }
+
+ /**
* Creates an unadjusted version of a MotionEvent.
* @param e The original event.
* @return The unadjusted version of the event.

Powered by Google App Engine
This is Rietveld 408576698