[Status Bar Refactor] Remove final StatusBar references from
PhoneStatusBarView. The references are moved into NotificationPanelViewController, which admittedly isn't *that* much better of a location but it's better for it to be in a controller instead of a view, and NPVC already has 40+ references to StatusBar. Fixes: 199733640 Test: manual (verified StatusBar's callback still triggers) Test: atest SystemUITests Change-Id: I05a4f0ed52c02f0caff621f64d188189cceb48d0
This commit is contained in:
@@ -3789,45 +3789,6 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
|
||||
private long mLastTouchDownTime = -1L;
|
||||
|
||||
@Override
|
||||
public boolean onTouchForwardedFromStatusBar(MotionEvent event) {
|
||||
// TODO(b/202981994): Move the touch debugging in this method to a central location.
|
||||
// (Right now, it's split between StatusBar and here.)
|
||||
|
||||
// If panels aren't enabled, ignore the gesture and don't pass it down to the
|
||||
// panel view.
|
||||
if (!mCommandQueue.panelsEnabled()) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
Log.v(
|
||||
TAG,
|
||||
String.format(
|
||||
"onTouchForwardedFromStatusBar: "
|
||||
+ "panel disabled, ignoring touch at (%d,%d)",
|
||||
(int) event.getX(),
|
||||
(int) event.getY()
|
||||
)
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the view that would receive the touch is disabled, just have status bar eat
|
||||
// the gesture.
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN && !mView.isEnabled()) {
|
||||
Log.v(TAG,
|
||||
String.format(
|
||||
"onTouchForwardedFromStatusBar: "
|
||||
+ "panel view disabled, eating touch at (%d,%d)",
|
||||
(int) event.getX(),
|
||||
(int) event.getY()
|
||||
)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
return mView.dispatchTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent event) {
|
||||
if (mBlockTouches || mQs.disallowPanelTouches()) {
|
||||
@@ -3939,6 +3900,55 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
};
|
||||
}
|
||||
|
||||
private final PhoneStatusBarView.TouchEventHandler mStatusBarViewTouchEventHandler =
|
||||
new PhoneStatusBarView.TouchEventHandler() {
|
||||
@Override
|
||||
public void onInterceptTouchEvent(MotionEvent event) {
|
||||
mStatusBar.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleTouchEvent(MotionEvent event) {
|
||||
mStatusBar.onTouchEvent(event);
|
||||
|
||||
// TODO(b/202981994): Move the touch debugging in this method to a central
|
||||
// location. (Right now, it's split between StatusBar and here.)
|
||||
|
||||
// If panels aren't enabled, ignore the gesture and don't pass it down to the
|
||||
// panel view.
|
||||
if (!mCommandQueue.panelsEnabled()) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
Log.v(
|
||||
TAG,
|
||||
String.format(
|
||||
"onTouchForwardedFromStatusBar: "
|
||||
+ "panel disabled, ignoring touch at (%d,%d)",
|
||||
(int) event.getX(),
|
||||
(int) event.getY()
|
||||
)
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the view that would receive the touch is disabled, just have status bar
|
||||
// eat the gesture.
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN && !mView.isEnabled()) {
|
||||
Log.v(TAG,
|
||||
String.format(
|
||||
"onTouchForwardedFromStatusBar: "
|
||||
+ "panel view disabled, eating touch at (%d,%d)",
|
||||
(int) event.getX(),
|
||||
(int) event.getY()
|
||||
)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
return mView.dispatchTouchEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected PanelViewController.OnConfigurationChangedListener
|
||||
createOnConfigurationChangedListener() {
|
||||
@@ -4698,6 +4708,6 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
|
||||
/** Returns the handler that the status bar should forward touches to. */
|
||||
public PhoneStatusBarView.TouchEventHandler getStatusBarTouchEventHandler() {
|
||||
return getTouchHandler()::onTouchForwardedFromStatusBar;
|
||||
return mStatusBarViewTouchEventHandler;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,10 +292,6 @@ public abstract class PanelViewController {
|
||||
: mTouchSlop;
|
||||
}
|
||||
|
||||
protected TouchHandler getTouchHandler() {
|
||||
return mTouchHandler;
|
||||
}
|
||||
|
||||
private void addMovement(MotionEvent event) {
|
||||
// Add movement to velocity tracker using raw screen X and Y coordinates instead
|
||||
// of window coordinates because the window frame may be moving at the same time.
|
||||
@@ -1161,17 +1157,7 @@ public abstract class PanelViewController {
|
||||
return new OnConfigurationChangedListener();
|
||||
}
|
||||
|
||||
public abstract class TouchHandler implements View.OnTouchListener {
|
||||
/**
|
||||
* Method called when a touch has occurred on {@link PhoneStatusBarView}.
|
||||
*
|
||||
* Touches that occur on the status bar view may have ramifications for the notification
|
||||
* panel (e.g. a touch that pulls down the shade could start on the status bar), so we need
|
||||
* to notify the panel controller when these touches occur.
|
||||
*
|
||||
* Returns true if the event was handled and false otherwise.
|
||||
*/
|
||||
public abstract boolean onTouchForwardedFromStatusBar(MotionEvent event);
|
||||
public class TouchHandler implements View.OnTouchListener {
|
||||
|
||||
public boolean onInterceptTouchEvent(MotionEvent event) {
|
||||
if (mInstantExpanding || !mNotificationsDragEnabled || mTouchDisabled || (mMotionAborted
|
||||
|
||||
@@ -50,9 +50,6 @@ public class PhoneStatusBarView extends FrameLayout {
|
||||
private static final String TAG = "PhoneStatusBarView";
|
||||
private final StatusBarContentInsetsProvider mContentInsetsProvider;
|
||||
|
||||
StatusBar mBar;
|
||||
|
||||
private ScrimController mScrimController;
|
||||
private DarkReceiver mBattery;
|
||||
private DarkReceiver mClock;
|
||||
private int mRotationOrientation = -1;
|
||||
@@ -76,18 +73,10 @@ public class PhoneStatusBarView extends FrameLayout {
|
||||
mContentInsetsProvider = Dependency.get(StatusBarContentInsetsProvider.class);
|
||||
}
|
||||
|
||||
public void setBar(StatusBar bar) {
|
||||
mBar = bar;
|
||||
}
|
||||
|
||||
void setTouchEventHandler(TouchEventHandler handler) {
|
||||
mTouchEventHandler = handler;
|
||||
}
|
||||
|
||||
public void setScrimController(ScrimController scrimController) {
|
||||
mScrimController = scrimController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinishInflate() {
|
||||
mBattery = findViewById(R.id.battery);
|
||||
@@ -174,7 +163,6 @@ public class PhoneStatusBarView extends FrameLayout {
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
mBar.onTouchEvent(event);
|
||||
if (mTouchEventHandler == null) {
|
||||
Log.w(
|
||||
TAG,
|
||||
@@ -191,7 +179,7 @@ public class PhoneStatusBarView extends FrameLayout {
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent event) {
|
||||
mBar.onTouchEvent(event);
|
||||
mTouchEventHandler.onInterceptTouchEvent(event);
|
||||
return super.onInterceptTouchEvent(event);
|
||||
}
|
||||
|
||||
@@ -275,13 +263,26 @@ public class PhoneStatusBarView extends FrameLayout {
|
||||
}
|
||||
|
||||
/**
|
||||
* A handler repsonsible for all touch event handling on the status bar.
|
||||
* A handler responsible for all touch event handling on the status bar.
|
||||
*
|
||||
* The handler will be notified each time {@link this#onTouchEvent} is called, and the return
|
||||
* value from the handler will be returned from {@link this#onTouchEvent}.
|
||||
* Touches that occur on the status bar view may have ramifications for the notification
|
||||
* panel (e.g. a touch that pulls down the shade could start on the status bar), so this
|
||||
* interface provides a way to notify the panel controller when these touches occur.
|
||||
*
|
||||
* The handler will be notified each time {@link PhoneStatusBarView#onTouchEvent} and
|
||||
* {@link PhoneStatusBarView#onInterceptTouchEvent} are called.
|
||||
**/
|
||||
public interface TouchEventHandler {
|
||||
/** Called each time {@link this#onTouchEvent} is called. */
|
||||
/** Called each time {@link PhoneStatusBarView#onInterceptTouchEvent} is called. */
|
||||
void onInterceptTouchEvent(MotionEvent event);
|
||||
|
||||
/**
|
||||
* Called each time {@link PhoneStatusBarView#onTouchEvent} is called.
|
||||
*
|
||||
* Should return true if the touch was handled by this handler and false otherwise. The
|
||||
* return value from the handler will be returned from
|
||||
* {@link PhoneStatusBarView#onTouchEvent}.
|
||||
*/
|
||||
boolean handleTouchEvent(MotionEvent event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1142,8 +1142,6 @@ public class StatusBar extends SystemUI implements
|
||||
|
||||
PhoneStatusBarView oldStatusBarView = mStatusBarView;
|
||||
mStatusBarView = (PhoneStatusBarView) statusBarFragment.getView();
|
||||
mStatusBarView.setBar(this);
|
||||
mStatusBarView.setScrimController(mScrimController);
|
||||
|
||||
mPhoneStatusBarViewController = mPhoneStatusBarViewControllerFactory
|
||||
.create(mStatusBarView, mNotificationPanelViewController
|
||||
|
||||
@@ -523,46 +523,50 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onTouchForwardedFromStatusBar_panelsNotEnabled_returnsFalseAndNoViewEvent() {
|
||||
public void handleTouchEventFromStatusBar_panelsNotEnabled_returnsFalseAndNoViewEvent() {
|
||||
when(mCommandQueue.panelsEnabled()).thenReturn(false);
|
||||
|
||||
boolean returnVal = mTouchHandler.onTouchForwardedFromStatusBar(
|
||||
MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0));
|
||||
boolean returnVal = mNotificationPanelViewController
|
||||
.getStatusBarTouchEventHandler()
|
||||
.handleTouchEvent(
|
||||
MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0));
|
||||
|
||||
assertThat(returnVal).isFalse();
|
||||
verify(mView, never()).dispatchTouchEvent(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onTouchForwardedFromStatusBar_viewNotEnabled_returnsTrueAndNoViewEvent() {
|
||||
public void handleTouchEventFromStatusBar_viewNotEnabled_returnsTrueAndNoViewEvent() {
|
||||
when(mCommandQueue.panelsEnabled()).thenReturn(true);
|
||||
when(mView.isEnabled()).thenReturn(false);
|
||||
|
||||
boolean returnVal = mTouchHandler.onTouchForwardedFromStatusBar(
|
||||
MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0));
|
||||
boolean returnVal = mNotificationPanelViewController
|
||||
.getStatusBarTouchEventHandler()
|
||||
.handleTouchEvent(
|
||||
MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0));
|
||||
|
||||
assertThat(returnVal).isTrue();
|
||||
verify(mView, never()).dispatchTouchEvent(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onTouchForwardedFromStatusBar_viewNotEnabledButIsMoveEvent_viewReceivesEvent() {
|
||||
public void handleTouchEventFromStatusBar_viewNotEnabledButIsMoveEvent_viewReceivesEvent() {
|
||||
when(mCommandQueue.panelsEnabled()).thenReturn(true);
|
||||
when(mView.isEnabled()).thenReturn(false);
|
||||
MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_MOVE, 0f, 0f, 0);
|
||||
|
||||
mTouchHandler.onTouchForwardedFromStatusBar(event);
|
||||
mNotificationPanelViewController.getStatusBarTouchEventHandler().handleTouchEvent(event);
|
||||
|
||||
verify(mView).dispatchTouchEvent(event);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onTouchForwardedFromStatusBar_panelAndViewEnabled_viewReceivesEvent() {
|
||||
public void handleTouchEventFromStatusBar_panelAndViewEnabled_viewReceivesEvent() {
|
||||
when(mCommandQueue.panelsEnabled()).thenReturn(true);
|
||||
when(mView.isEnabled()).thenReturn(true);
|
||||
MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0);
|
||||
|
||||
mTouchHandler.onTouchForwardedFromStatusBar(event);
|
||||
mNotificationPanelViewController.getStatusBarTouchEventHandler().handleTouchEvent(event);
|
||||
|
||||
verify(mView).dispatchTouchEvent(event);
|
||||
}
|
||||
|
||||
@@ -52,8 +52,6 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
|
||||
@Mock
|
||||
private lateinit var panelView: ViewGroup
|
||||
@Mock
|
||||
private lateinit var scrimController: ScrimController
|
||||
@Mock
|
||||
private lateinit var moveFromCenterAnimation: StatusBarMoveFromCenterAnimationController
|
||||
@Mock
|
||||
private lateinit var sysuiUnfoldComponent: SysUIUnfoldComponent
|
||||
@@ -76,8 +74,6 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
|
||||
val parent = FrameLayout(mContext) // add parent to keep layout params
|
||||
view = LayoutInflater.from(mContext)
|
||||
.inflate(R.layout.status_bar, parent, false) as PhoneStatusBarView
|
||||
view.setScrimController(scrimController)
|
||||
view.setBar(mock(StatusBar::class.java))
|
||||
}
|
||||
|
||||
controller = createController(view)
|
||||
@@ -85,10 +81,13 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
|
||||
|
||||
@Test
|
||||
fun constructor_setsTouchHandlerOnView() {
|
||||
val interceptEvent = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_MOVE, 10f, 10f, 0)
|
||||
val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)
|
||||
|
||||
view.onInterceptTouchEvent(interceptEvent)
|
||||
view.onTouchEvent(event)
|
||||
|
||||
assertThat(touchEventHandler.lastInterceptEvent).isEqualTo(interceptEvent)
|
||||
assertThat(touchEventHandler.lastEvent).isEqualTo(event)
|
||||
}
|
||||
|
||||
@@ -128,6 +127,11 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
|
||||
|
||||
private class TestTouchEventHandler : PhoneStatusBarView.TouchEventHandler {
|
||||
var lastEvent: MotionEvent? = null
|
||||
var lastInterceptEvent: MotionEvent? = null
|
||||
|
||||
override fun onInterceptTouchEvent(event: MotionEvent?) {
|
||||
lastInterceptEvent = event
|
||||
}
|
||||
override fun handleTouchEvent(event: MotionEvent?): Boolean {
|
||||
lastEvent = event
|
||||
return false
|
||||
|
||||
@@ -34,10 +34,6 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
||||
private lateinit var panelViewController: PanelViewController
|
||||
@Mock
|
||||
private lateinit var panelView: ViewGroup
|
||||
@Mock
|
||||
private lateinit var scrimController: ScrimController
|
||||
@Mock
|
||||
private lateinit var statusBar: StatusBar
|
||||
|
||||
private lateinit var view: PhoneStatusBarView
|
||||
|
||||
@@ -49,8 +45,6 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
||||
`when`(panelViewController.view).thenReturn(panelView)
|
||||
|
||||
view = PhoneStatusBarView(mContext, null)
|
||||
view.setScrimController(scrimController)
|
||||
view.setBar(statusBar)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,13 +58,24 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
||||
assertThat(handler.lastEvent).isEqualTo(event)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onInterceptTouchEvent_listenerNotified() {
|
||||
val handler = TestTouchEventHandler()
|
||||
view.setTouchEventHandler(handler)
|
||||
|
||||
val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)
|
||||
view.onInterceptTouchEvent(event)
|
||||
|
||||
assertThat(handler.lastInterceptEvent).isEqualTo(event)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onTouchEvent_listenerReturnsTrue_viewReturnsTrue() {
|
||||
val handler = TestTouchEventHandler()
|
||||
view.setTouchEventHandler(handler)
|
||||
val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)
|
||||
|
||||
handler.returnValue = true
|
||||
handler.handleTouchReturnValue = true
|
||||
|
||||
assertThat(view.onTouchEvent(event)).isTrue()
|
||||
}
|
||||
@@ -81,7 +86,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
||||
view.setTouchEventHandler(handler)
|
||||
val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)
|
||||
|
||||
handler.returnValue = false
|
||||
handler.handleTouchReturnValue = false
|
||||
|
||||
assertThat(view.onTouchEvent(event)).isFalse()
|
||||
}
|
||||
@@ -93,11 +98,17 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
||||
}
|
||||
|
||||
private class TestTouchEventHandler : PhoneStatusBarView.TouchEventHandler {
|
||||
var lastInterceptEvent: MotionEvent? = null
|
||||
var lastEvent: MotionEvent? = null
|
||||
var returnValue: Boolean = false
|
||||
var handleTouchReturnValue: Boolean = false
|
||||
|
||||
override fun onInterceptTouchEvent(event: MotionEvent?) {
|
||||
lastInterceptEvent = event
|
||||
}
|
||||
|
||||
override fun handleTouchEvent(event: MotionEvent?): Boolean {
|
||||
lastEvent = event
|
||||
return returnValue
|
||||
return handleTouchReturnValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user