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.
This commit is contained in:
committed by
Android (Google) Code Review
commit
4617507f91
@@ -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;
|
||||||
import static com.android.systemui.statusbar.StatusBarState.SHADE_LOCKED;
|
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.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;
|
import static java.lang.Float.isNaN;
|
||||||
|
|
||||||
@@ -57,7 +60,6 @@ import android.graphics.PointF;
|
|||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.Region;
|
import android.graphics.Region;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.hardware.biometrics.BiometricSourceType;
|
|
||||||
import android.hardware.biometrics.SensorLocationInternal;
|
import android.hardware.biometrics.SensorLocationInternal;
|
||||||
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
|
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -80,6 +82,7 @@ import android.view.ViewPropertyAnimator;
|
|||||||
import android.view.ViewStub;
|
import android.view.ViewStub;
|
||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
import android.view.WindowInsets;
|
import android.view.WindowInsets;
|
||||||
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
import android.view.accessibility.AccessibilityManager;
|
import android.view.accessibility.AccessibilityManager;
|
||||||
import android.view.accessibility.AccessibilityNodeInfo;
|
import android.view.accessibility.AccessibilityNodeInfo;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
@@ -1802,15 +1805,6 @@ public class NotificationPanelViewController extends PanelViewController {
|
|||||||
return !mQsTouchAboveFalsingThreshold;
|
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() {
|
private float computeQsExpansionFraction() {
|
||||||
if (mQSAnimatingHiddenFromCollapsed) {
|
if (mQSAnimatingHiddenFromCollapsed) {
|
||||||
// When hiding QS from collapsed state, the expansion can sometimes temporarily
|
// When hiding QS from collapsed state, the expansion can sometimes temporarily
|
||||||
@@ -2232,12 +2226,6 @@ public class NotificationPanelViewController extends PanelViewController {
|
|||||||
updateQSExpansionEnabledAmbient();
|
updateQSExpansionEnabledAmbient();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setIsShadeOpening(boolean opening) {
|
|
||||||
mAmbientState.setIsShadeOpening(opening);
|
|
||||||
updateQSExpansionEnabledAmbient();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateQSExpansionEnabledAmbient() {
|
private void updateQSExpansionEnabledAmbient() {
|
||||||
final float scrollRangeToTop = mAmbientState.getTopPadding() - mQuickQsOffsetHeight;
|
final float scrollRangeToTop = mAmbientState.getTopPadding() - mQuickQsOffsetHeight;
|
||||||
mQsExpansionEnabledAmbient = mShouldUseSplitNotificationShade
|
mQsExpansionEnabledAmbient = mShouldUseSplitNotificationShade
|
||||||
@@ -3344,8 +3332,14 @@ public class NotificationPanelViewController extends PanelViewController {
|
|||||||
return mBarState == KEYGUARD;
|
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) {
|
public void setPanelScrimMinFraction(float minFraction) {
|
||||||
mBar.onPanelMinFractionChanged(minFraction);
|
mBar.onPanelMinFractionChanged(minFraction);
|
||||||
|
mMinFraction = minFraction;
|
||||||
|
mDepthController.setPanelPullDownMinFraction(mMinFraction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearNotificationEffects() {
|
public void clearNotificationEffects() {
|
||||||
@@ -4633,4 +4627,26 @@ public class NotificationPanelViewController extends PanelViewController {
|
|||||||
return insets;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,9 @@
|
|||||||
package com.android.systemui.statusbar.phone;
|
package com.android.systemui.statusbar.phone;
|
||||||
|
|
||||||
import static java.lang.Float.isNaN;
|
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.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -27,6 +28,10 @@ import android.util.Log;
|
|||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
|
||||||
public abstract class PanelBar extends FrameLayout {
|
public abstract class PanelBar extends FrameLayout {
|
||||||
public static final boolean DEBUG = false;
|
public static final boolean DEBUG = false;
|
||||||
public static final String TAG = PanelBar.class.getSimpleName();
|
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));
|
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_CLOSED = 0;
|
||||||
public static final int STATE_OPENING = 1;
|
public static final int STATE_OPENING = 1;
|
||||||
public static final int STATE_OPEN = 2;
|
public static final int STATE_OPEN = 2;
|
||||||
|
|
||||||
PanelViewController mPanel;
|
private PanelViewController mPanel;
|
||||||
|
@Nullable private PanelStateChangeListener mPanelStateChangeListener;
|
||||||
private int mState = STATE_CLOSED;
|
private int mState = STATE_CLOSED;
|
||||||
private boolean mTracking;
|
private boolean mTracking;
|
||||||
|
|
||||||
public void go(int state) {
|
private void go(@PanelState int state) {
|
||||||
if (DEBUG) LOG("go state: %d -> %d", mState, state);
|
if (DEBUG) LOG("go state: %d -> %d", mState, state);
|
||||||
mState = state;
|
mState = state;
|
||||||
if (mPanel != null) {
|
if (mPanelStateChangeListener != null) {
|
||||||
mPanel.setIsShadeOpening(state == STATE_OPENING);
|
mPanelStateChangeListener.onStateChanged(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isShadeOpening() {
|
|
||||||
return mState == STATE_OPENING;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Parcelable onSaveInstanceState() {
|
protected Parcelable onSaveInstanceState() {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
@@ -97,6 +103,11 @@ public abstract class PanelBar extends FrameLayout {
|
|||||||
pv.setBar(this);
|
pv.setBar(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sets the listener that will be notified of panel state changes. */
|
||||||
|
public void setPanelStateChangeListener(PanelStateChangeListener listener) {
|
||||||
|
mPanelStateChangeListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean panelEnabled() {
|
public boolean panelEnabled() {
|
||||||
return true;
|
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.
|
* Percentage of panel expansion offset, caused by pulling down on a heads-up.
|
||||||
*/
|
*/
|
||||||
@CallSuper
|
abstract void onPanelMinFractionChanged(float minFraction);
|
||||||
public void onPanelMinFractionChanged(float minFraction) {
|
|
||||||
mPanel.setMinFraction(minFraction);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param frac the fraction from the expansion in [0, 1]
|
* @param frac the fraction from the expansion in [0, 1]
|
||||||
@@ -166,7 +174,6 @@ public abstract class PanelBar extends FrameLayout {
|
|||||||
}
|
}
|
||||||
if (fullyOpened && !mTracking) {
|
if (fullyOpened && !mTracking) {
|
||||||
go(STATE_OPEN);
|
go(STATE_OPEN);
|
||||||
onPanelFullyOpened();
|
|
||||||
} else if (fullyClosed && !mTracking && mState != STATE_CLOSED) {
|
} else if (fullyClosed && !mTracking && mState != STATE_CLOSED) {
|
||||||
go(STATE_CLOSED);
|
go(STATE_CLOSED);
|
||||||
onPanelCollapsed();
|
onPanelCollapsed();
|
||||||
@@ -207,10 +214,6 @@ public abstract class PanelBar extends FrameLayout {
|
|||||||
if (DEBUG) LOG("onPanelCollapsed");
|
if (DEBUG) LOG("onPanelCollapsed");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPanelFullyOpened() {
|
|
||||||
if (DEBUG) LOG("onPanelFullyOpened");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onTrackingStarted() {
|
public void onTrackingStarted() {
|
||||||
mTracking = true;
|
mTracking = true;
|
||||||
}
|
}
|
||||||
@@ -226,4 +229,10 @@ public abstract class PanelBar extends FrameLayout {
|
|||||||
public void onClosingFinished() {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -342,13 +342,6 @@ public abstract class PanelViewController {
|
|||||||
|
|
||||||
protected abstract float getOpeningHeight();
|
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
|
* @return whether the swiping direction is upwards and above a 45 degree angle compared to the
|
||||||
* horizontal direction
|
* horizontal direction
|
||||||
@@ -1171,11 +1164,6 @@ public abstract class PanelViewController {
|
|||||||
return new OnConfigurationChangedListener();
|
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 class TouchHandler implements View.OnTouchListener {
|
||||||
public boolean onInterceptTouchEvent(MotionEvent event) {
|
public boolean onInterceptTouchEvent(MotionEvent event) {
|
||||||
if (mInstantExpanding || !mNotificationsDragEnabled || mTouchDisabled || (mMotionAborted
|
if (mInstantExpanding || !mNotificationsDragEnabled || mTouchDisabled || (mMotionAborted
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ public class PhoneStatusBarView extends PanelBar {
|
|||||||
|
|
||||||
StatusBar mBar;
|
StatusBar mBar;
|
||||||
|
|
||||||
boolean mIsFullyOpenedPanel = false;
|
|
||||||
private ScrimController mScrimController;
|
private ScrimController mScrimController;
|
||||||
private float mMinFraction;
|
private float mMinFraction;
|
||||||
private Runnable mHideExpandedRunnable = new Runnable() {
|
private Runnable mHideExpandedRunnable = new Runnable() {
|
||||||
@@ -216,22 +215,12 @@ public class PhoneStatusBarView extends PanelBar {
|
|||||||
super.onPanelCollapsed();
|
super.onPanelCollapsed();
|
||||||
// Close the status bar in the next frame so we can show the end of the animation.
|
// Close the status bar in the next frame so we can show the end of the animation.
|
||||||
post(mHideExpandedRunnable);
|
post(mHideExpandedRunnable);
|
||||||
mIsFullyOpenedPanel = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePendingHideExpandedRunnables() {
|
public void removePendingHideExpandedRunnables() {
|
||||||
removeCallbacks(mHideExpandedRunnable);
|
removeCallbacks(mHideExpandedRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPanelFullyOpened() {
|
|
||||||
super.onPanelFullyOpened();
|
|
||||||
if (!mIsFullyOpenedPanel) {
|
|
||||||
mPanel.getView().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
|
|
||||||
}
|
|
||||||
mIsFullyOpenedPanel = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
boolean barConsumedEvent = mBar.interceptTouchEvent(event);
|
boolean barConsumedEvent = mBar.interceptTouchEvent(event);
|
||||||
@@ -283,7 +272,6 @@ public class PhoneStatusBarView extends PanelBar {
|
|||||||
if (isNaN(minFraction)) {
|
if (isNaN(minFraction)) {
|
||||||
throw new IllegalArgumentException("minFraction cannot be NaN");
|
throw new IllegalArgumentException("minFraction cannot be NaN");
|
||||||
}
|
}
|
||||||
super.onPanelMinFractionChanged(minFraction);
|
|
||||||
if (mMinFraction != minFraction) {
|
if (mMinFraction != minFraction) {
|
||||||
mMinFraction = minFraction;
|
mMinFraction = minFraction;
|
||||||
updateScrimFraction();
|
updateScrimFraction();
|
||||||
|
|||||||
@@ -1161,6 +1161,8 @@ public class StatusBar extends SystemUI implements
|
|||||||
mStatusBarView = (PhoneStatusBarView) statusBarFragment.getView();
|
mStatusBarView = (PhoneStatusBarView) statusBarFragment.getView();
|
||||||
mStatusBarView.setBar(this);
|
mStatusBarView.setBar(this);
|
||||||
mStatusBarView.setPanel(mNotificationPanelViewController);
|
mStatusBarView.setPanel(mNotificationPanelViewController);
|
||||||
|
mStatusBarView.setPanelStateChangeListener(
|
||||||
|
mNotificationPanelViewController.getPanelStateChangeListener());
|
||||||
mStatusBarView.setScrimController(mScrimController);
|
mStatusBarView.setScrimController(mScrimController);
|
||||||
mStatusBarView.setExpansionChangedListeners(mExpansionChangedListeners);
|
mStatusBarView.setExpansionChangedListeners(mExpansionChangedListeners);
|
||||||
for (ExpansionChangedListener listener : mExpansionChangedListeners) {
|
for (ExpansionChangedListener listener : mExpansionChangedListeners) {
|
||||||
|
|||||||
@@ -472,8 +472,8 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetMinFraction() {
|
public void testSetPanelScrimMinFraction() {
|
||||||
mNotificationPanelViewController.setMinFraction(0.5f);
|
mNotificationPanelViewController.setPanelScrimMinFraction(0.5f);
|
||||||
verify(mNotificationShadeDepthController).setPanelPullDownMinFraction(eq(0.5f));
|
verify(mNotificationShadeDepthController).setPanelPullDownMinFraction(eq(0.5f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
|||||||
private lateinit var panelView: ViewGroup
|
private lateinit var panelView: ViewGroup
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var scrimController: ScrimController
|
private lateinit var scrimController: ScrimController
|
||||||
|
@Mock
|
||||||
|
private lateinit var statusBar: StatusBar
|
||||||
|
|
||||||
private lateinit var view: PhoneStatusBarView
|
private lateinit var view: PhoneStatusBarView
|
||||||
|
|
||||||
@@ -48,6 +50,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
|||||||
view = PhoneStatusBarView(mContext, null)
|
view = PhoneStatusBarView(mContext, null)
|
||||||
view.setPanel(panelViewController)
|
view.setPanel(panelViewController)
|
||||||
view.setScrimController(scrimController)
|
view.setScrimController(scrimController)
|
||||||
|
view.setBar(statusBar)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -72,7 +75,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun panelExpansionChanged_fracZero_stateChangeListenerNotified() {
|
fun panelExpansionChanged_fracZero_stateChangeListenerNotified() {
|
||||||
val listener = TestStateChangedListener()
|
val listener = TestExpansionStateChangedListener()
|
||||||
view.setPanelExpansionStateChangedListener(listener)
|
view.setPanelExpansionStateChangedListener(listener)
|
||||||
|
|
||||||
view.panelExpansionChanged(0f, false)
|
view.panelExpansionChanged(0f, false)
|
||||||
@@ -82,7 +85,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun panelExpansionChanged_fracOne_stateChangeListenerNotified() {
|
fun panelExpansionChanged_fracOne_stateChangeListenerNotified() {
|
||||||
val listener = TestStateChangedListener()
|
val listener = TestExpansionStateChangedListener()
|
||||||
view.setPanelExpansionStateChangedListener(listener)
|
view.setPanelExpansionStateChangedListener(listener)
|
||||||
|
|
||||||
view.panelExpansionChanged(1f, false)
|
view.panelExpansionChanged(1f, false)
|
||||||
@@ -92,7 +95,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun panelExpansionChanged_fracHalf_stateChangeListenerNotNotified() {
|
fun panelExpansionChanged_fracHalf_stateChangeListenerNotNotified() {
|
||||||
val listener = TestStateChangedListener()
|
val listener = TestExpansionStateChangedListener()
|
||||||
view.setPanelExpansionStateChangedListener(listener)
|
view.setPanelExpansionStateChangedListener(listener)
|
||||||
|
|
||||||
view.panelExpansionChanged(0.5f, false)
|
view.panelExpansionChanged(0.5f, false)
|
||||||
@@ -106,11 +109,59 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
|||||||
// No assert needed, just testing no crash
|
// 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
|
var stateChangeCalled: Boolean = false
|
||||||
|
|
||||||
override fun onPanelExpansionStateChanged() {
|
override fun onPanelExpansionStateChanged() {
|
||||||
stateChangeCalled = true
|
stateChangeCalled = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class TestStateChangedListener : PanelBar.PanelStateChangeListener {
|
||||||
|
var state: Int = 0
|
||||||
|
override fun onStateChanged(state: Int) {
|
||||||
|
this.state = state
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user