diff options
| author | 2021-10-06 17:51:27 +0000 | |
|---|---|---|
| committer | 2021-10-06 17:51:27 +0000 | |
| commit | 4617507f9170af61d2cfda7f971aa03babbcae97 (patch) | |
| tree | 9c32217e19d3567b73fc0c1a9d40a2285fd4fc85 | |
| parent | 385e707260ce1089557b4ba07ea4c163fffea9e3 (diff) | |
| parent | 4cbf1b636c270657e8cc8175b503a09b517ea50c (diff) | |
Merge changes If31a0d78,I3e327a83,I41e1854e into sc-v2-dev
* changes:
[Status Bar Refactor] Remove some indirection about minFraction between NotificationPanelViewController and PanelBar.
[Status Bar Refactor] Remove PanelBar#onPanelFullyOpened and instead handle that logic in the listener callback.
[Status Bar Refactor] Add a PanelStateChangeListener interface and use it in PanelBar#go.
7 files changed, 118 insertions, 64 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java index ab0499bc0dde..90e554041dbc 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java @@ -34,6 +34,9 @@ import static com.android.systemui.statusbar.StatusBarState.KEYGUARD; import static com.android.systemui.statusbar.StatusBarState.SHADE; import static com.android.systemui.statusbar.StatusBarState.SHADE_LOCKED; import static com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout.ROWS_ALL; +import static com.android.systemui.statusbar.phone.PanelBar.STATE_CLOSED; +import static com.android.systemui.statusbar.phone.PanelBar.STATE_OPEN; +import static com.android.systemui.statusbar.phone.PanelBar.STATE_OPENING; import static java.lang.Float.isNaN; @@ -57,7 +60,6 @@ import android.graphics.PointF; import android.graphics.Rect; import android.graphics.Region; import android.graphics.drawable.Drawable; -import android.hardware.biometrics.BiometricSourceType; import android.hardware.biometrics.SensorLocationInternal; import android.hardware.fingerprint.FingerprintSensorPropertiesInternal; import android.os.Bundle; @@ -80,6 +82,7 @@ import android.view.ViewPropertyAnimator; import android.view.ViewStub; import android.view.ViewTreeObserver; import android.view.WindowInsets; +import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityNodeInfo; import android.widget.FrameLayout; @@ -1802,15 +1805,6 @@ public class NotificationPanelViewController extends PanelViewController { return !mQsTouchAboveFalsingThreshold; } - /** - * Percentage of panel expansion offset, caused by pulling down on a heads-up. - */ - @Override - public void setMinFraction(float minFraction) { - mMinFraction = minFraction; - mDepthController.setPanelPullDownMinFraction(mMinFraction); - } - private float computeQsExpansionFraction() { if (mQSAnimatingHiddenFromCollapsed) { // When hiding QS from collapsed state, the expansion can sometimes temporarily @@ -2232,12 +2226,6 @@ public class NotificationPanelViewController extends PanelViewController { updateQSExpansionEnabledAmbient(); } - @Override - public void setIsShadeOpening(boolean opening) { - mAmbientState.setIsShadeOpening(opening); - updateQSExpansionEnabledAmbient(); - } - private void updateQSExpansionEnabledAmbient() { final float scrollRangeToTop = mAmbientState.getTopPadding() - mQuickQsOffsetHeight; mQsExpansionEnabledAmbient = mShouldUseSplitNotificationShade @@ -3344,8 +3332,14 @@ public class NotificationPanelViewController extends PanelViewController { return mBarState == KEYGUARD; } + /** + * Sets the minimum fraction for the panel expansion offset. This may be non-zero in certain + * cases, such as if there's a heads-up notification. + */ public void setPanelScrimMinFraction(float minFraction) { mBar.onPanelMinFractionChanged(minFraction); + mMinFraction = minFraction; + mDepthController.setPanelPullDownMinFraction(mMinFraction); } public void clearNotificationEffects() { @@ -4633,4 +4627,26 @@ public class NotificationPanelViewController extends PanelViewController { return insets; } } + + private final PanelBar.PanelStateChangeListener mPanelStateChangeListener = + new PanelBar.PanelStateChangeListener() { + + @PanelBar.PanelState + private int mCurrentState = STATE_CLOSED; + + @Override + public void onStateChanged(@PanelBar.PanelState int state) { + mAmbientState.setIsShadeOpening(state == STATE_OPENING); + updateQSExpansionEnabledAmbient(); + + if (state == STATE_OPEN && mCurrentState != state) { + mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); + } + mCurrentState = state; + } + }; + + public PanelBar.PanelStateChangeListener getPanelStateChangeListener() { + return mPanelStateChangeListener; + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelBar.java index 247ede91eeb3..1f1090d7168b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelBar.java @@ -17,8 +17,9 @@ package com.android.systemui.statusbar.phone; import static java.lang.Float.isNaN; +import static java.lang.annotation.RetentionPolicy.SOURCE; -import android.annotation.CallSuper; +import android.annotation.IntDef; import android.content.Context; import android.os.Bundle; import android.os.Parcelable; @@ -27,6 +28,10 @@ import android.util.Log; import android.view.MotionEvent; import android.widget.FrameLayout; +import androidx.annotation.Nullable; + +import java.lang.annotation.Retention; + public abstract class PanelBar extends FrameLayout { public static final boolean DEBUG = false; public static final String TAG = PanelBar.class.getSimpleName(); @@ -40,26 +45,27 @@ public abstract class PanelBar extends FrameLayout { Log.v(TAG, String.format(fmt, args)); } + /** Enum for the current state of the panel. */ + @Retention(SOURCE) + @IntDef({STATE_CLOSED, STATE_OPENING, STATE_OPEN}) + @interface PanelState {} public static final int STATE_CLOSED = 0; public static final int STATE_OPENING = 1; public static final int STATE_OPEN = 2; - PanelViewController mPanel; + private PanelViewController mPanel; + @Nullable private PanelStateChangeListener mPanelStateChangeListener; private int mState = STATE_CLOSED; private boolean mTracking; - public void go(int state) { + private void go(@PanelState int state) { if (DEBUG) LOG("go state: %d -> %d", mState, state); mState = state; - if (mPanel != null) { - mPanel.setIsShadeOpening(state == STATE_OPENING); + if (mPanelStateChangeListener != null) { + mPanelStateChangeListener.onStateChanged(state); } } - protected boolean isShadeOpening() { - return mState == STATE_OPENING; - } - @Override protected Parcelable onSaveInstanceState() { Bundle bundle = new Bundle(); @@ -97,6 +103,11 @@ public abstract class PanelBar extends FrameLayout { pv.setBar(this); } + /** Sets the listener that will be notified of panel state changes. */ + public void setPanelStateChangeListener(PanelStateChangeListener listener) { + mPanelStateChangeListener = listener; + } + public boolean panelEnabled() { return true; } @@ -137,10 +148,7 @@ public abstract class PanelBar extends FrameLayout { /** * Percentage of panel expansion offset, caused by pulling down on a heads-up. */ - @CallSuper - public void onPanelMinFractionChanged(float minFraction) { - mPanel.setMinFraction(minFraction); - } + abstract void onPanelMinFractionChanged(float minFraction); /** * @param frac the fraction from the expansion in [0, 1] @@ -166,7 +174,6 @@ public abstract class PanelBar extends FrameLayout { } if (fullyOpened && !mTracking) { go(STATE_OPEN); - onPanelFullyOpened(); } else if (fullyClosed && !mTracking && mState != STATE_CLOSED) { go(STATE_CLOSED); onPanelCollapsed(); @@ -207,10 +214,6 @@ public abstract class PanelBar extends FrameLayout { if (DEBUG) LOG("onPanelCollapsed"); } - public void onPanelFullyOpened() { - if (DEBUG) LOG("onPanelFullyOpened"); - } - public void onTrackingStarted() { mTracking = true; } @@ -226,4 +229,10 @@ public abstract class PanelBar extends FrameLayout { public void onClosingFinished() { } + + /** An interface that will be notified of panel state changes. */ + public interface PanelStateChangeListener { + /** Called when the state changes. */ + void onStateChanged(@PanelState int state); + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelViewController.java index b2155154d652..768567b8b474 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelViewController.java @@ -343,13 +343,6 @@ public abstract class PanelViewController { protected abstract float getOpeningHeight(); /** - * Minimum fraction from where expansion should start. This is set when pulling down on a - * heads-up notification. - * @param minFraction Fraction from 0 to 1. - */ - public abstract void setMinFraction(float minFraction); - - /** * @return whether the swiping direction is upwards and above a 45 degree angle compared to the * horizontal direction */ @@ -1171,11 +1164,6 @@ public abstract class PanelViewController { return new OnConfigurationChangedListener(); } - /** - * Set that the panel is currently opening and not fully opened or closed. - */ - public abstract void setIsShadeOpening(boolean opening); - public class TouchHandler implements View.OnTouchListener { public boolean onInterceptTouchEvent(MotionEvent event) { if (mInstantExpanding || !mNotificationsDragEnabled || mTouchDisabled || (mMotionAborted diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java index 9ab6cdd3053b..1cca4777da0a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java @@ -56,7 +56,6 @@ public class PhoneStatusBarView extends PanelBar { StatusBar mBar; - boolean mIsFullyOpenedPanel = false; private ScrimController mScrimController; private float mMinFraction; private Runnable mHideExpandedRunnable = new Runnable() { @@ -216,7 +215,6 @@ public class PhoneStatusBarView extends PanelBar { super.onPanelCollapsed(); // Close the status bar in the next frame so we can show the end of the animation. post(mHideExpandedRunnable); - mIsFullyOpenedPanel = false; } public void removePendingHideExpandedRunnables() { @@ -224,15 +222,6 @@ public class PhoneStatusBarView extends PanelBar { } @Override - public void onPanelFullyOpened() { - super.onPanelFullyOpened(); - if (!mIsFullyOpenedPanel) { - mPanel.getView().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); - } - mIsFullyOpenedPanel = true; - } - - @Override public boolean onTouchEvent(MotionEvent event) { boolean barConsumedEvent = mBar.interceptTouchEvent(event); @@ -283,7 +272,6 @@ public class PhoneStatusBarView extends PanelBar { if (isNaN(minFraction)) { throw new IllegalArgumentException("minFraction cannot be NaN"); } - super.onPanelMinFractionChanged(minFraction); if (mMinFraction != minFraction) { mMinFraction = minFraction; updateScrimFraction(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 2130e028e863..67b2ee5ba210 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -1161,6 +1161,8 @@ public class StatusBar extends SystemUI implements mStatusBarView = (PhoneStatusBarView) statusBarFragment.getView(); mStatusBarView.setBar(this); mStatusBarView.setPanel(mNotificationPanelViewController); + mStatusBarView.setPanelStateChangeListener( + mNotificationPanelViewController.getPanelStateChangeListener()); mStatusBarView.setScrimController(mScrimController); mStatusBarView.setExpansionChangedListeners(mExpansionChangedListeners); for (ExpansionChangedListener listener : mExpansionChangedListeners) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewControllerTest.java index 253077f4ab08..b18ea4bca681 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewControllerTest.java @@ -472,8 +472,8 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase { } @Test - public void testSetMinFraction() { - mNotificationPanelViewController.setMinFraction(0.5f); + public void testSetPanelScrimMinFraction() { + mNotificationPanelViewController.setPanelScrimMinFraction(0.5f); verify(mNotificationShadeDepthController).setPanelPullDownMinFraction(eq(0.5f)); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt index aee9f12c3844..ec7e07f905c6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt @@ -35,6 +35,8 @@ class PhoneStatusBarViewTest : SysuiTestCase() { private lateinit var panelView: ViewGroup @Mock private lateinit var scrimController: ScrimController + @Mock + private lateinit var statusBar: StatusBar private lateinit var view: PhoneStatusBarView @@ -48,6 +50,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() { view = PhoneStatusBarView(mContext, null) view.setPanel(panelViewController) view.setScrimController(scrimController) + view.setBar(statusBar) } @Test @@ -72,7 +75,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() { @Test fun panelExpansionChanged_fracZero_stateChangeListenerNotified() { - val listener = TestStateChangedListener() + val listener = TestExpansionStateChangedListener() view.setPanelExpansionStateChangedListener(listener) view.panelExpansionChanged(0f, false) @@ -82,7 +85,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() { @Test fun panelExpansionChanged_fracOne_stateChangeListenerNotified() { - val listener = TestStateChangedListener() + val listener = TestExpansionStateChangedListener() view.setPanelExpansionStateChangedListener(listener) view.panelExpansionChanged(1f, false) @@ -92,7 +95,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() { @Test fun panelExpansionChanged_fracHalf_stateChangeListenerNotNotified() { - val listener = TestStateChangedListener() + val listener = TestExpansionStateChangedListener() view.setPanelExpansionStateChangedListener(listener) view.panelExpansionChanged(0.5f, false) @@ -106,11 +109,59 @@ class PhoneStatusBarViewTest : SysuiTestCase() { // No assert needed, just testing no crash } - private class TestStateChangedListener : PhoneStatusBarView.PanelExpansionStateChangedListener { + @Test + fun panelStateChanged_toStateOpening_listenerNotified() { + val listener = TestStateChangedListener() + view.setPanelStateChangeListener(listener) + + view.panelExpansionChanged(0.5f, true) + + assertThat(listener.state).isEqualTo(PanelBar.STATE_OPENING) + } + + @Test + fun panelStateChanged_toStateOpen_listenerNotified() { + val listener = TestStateChangedListener() + view.setPanelStateChangeListener(listener) + + view.panelExpansionChanged(1f, true) + + assertThat(listener.state).isEqualTo(PanelBar.STATE_OPEN) + } + + @Test + fun panelStateChanged_toStateClosed_listenerNotified() { + val listener = TestStateChangedListener() + view.setPanelStateChangeListener(listener) + + // First, open the panel + view.panelExpansionChanged(1f, true) + + // Then, close it again + view.panelExpansionChanged(0f, false) + + assertThat(listener.state).isEqualTo(PanelBar.STATE_CLOSED) + } + + @Test + fun panelStateChanged_noListener_noCrash() { + view.panelExpansionChanged(1f, true) + // No assert needed, just testing no crash + } + + private class TestExpansionStateChangedListener + : PhoneStatusBarView.PanelExpansionStateChangedListener { var stateChangeCalled: Boolean = false override fun onPanelExpansionStateChanged() { stateChangeCalled = true } } + + private class TestStateChangedListener : PanelBar.PanelStateChangeListener { + var state: Int = 0 + override fun onStateChanged(state: Int) { + this.state = state + } + } } |