Merge "[Status Bar Refactor] Remove final StatusBar references from PhoneStatusBarView." into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
894c6a62ac
@@ -3791,45 +3791,6 @@ public class NotificationPanelViewController extends PanelViewController {
|
|||||||
|
|
||||||
private long mLastTouchDownTime = -1L;
|
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
|
@Override
|
||||||
public boolean onInterceptTouchEvent(MotionEvent event) {
|
public boolean onInterceptTouchEvent(MotionEvent event) {
|
||||||
if (mBlockTouches || mQs.disallowPanelTouches()) {
|
if (mBlockTouches || mQs.disallowPanelTouches()) {
|
||||||
@@ -3941,6 +3902,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
|
@Override
|
||||||
protected PanelViewController.OnConfigurationChangedListener
|
protected PanelViewController.OnConfigurationChangedListener
|
||||||
createOnConfigurationChangedListener() {
|
createOnConfigurationChangedListener() {
|
||||||
@@ -4700,6 +4710,6 @@ public class NotificationPanelViewController extends PanelViewController {
|
|||||||
|
|
||||||
/** Returns the handler that the status bar should forward touches to. */
|
/** Returns the handler that the status bar should forward touches to. */
|
||||||
public PhoneStatusBarView.TouchEventHandler getStatusBarTouchEventHandler() {
|
public PhoneStatusBarView.TouchEventHandler getStatusBarTouchEventHandler() {
|
||||||
return getTouchHandler()::onTouchForwardedFromStatusBar;
|
return mStatusBarViewTouchEventHandler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -292,10 +292,6 @@ public abstract class PanelViewController {
|
|||||||
: mTouchSlop;
|
: mTouchSlop;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TouchHandler getTouchHandler() {
|
|
||||||
return mTouchHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addMovement(MotionEvent event) {
|
private void addMovement(MotionEvent event) {
|
||||||
// Add movement to velocity tracker using raw screen X and Y coordinates instead
|
// 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.
|
// 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();
|
return new OnConfigurationChangedListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class TouchHandler implements View.OnTouchListener {
|
public 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 boolean onInterceptTouchEvent(MotionEvent event) {
|
public boolean onInterceptTouchEvent(MotionEvent event) {
|
||||||
if (mInstantExpanding || !mNotificationsDragEnabled || mTouchDisabled || (mMotionAborted
|
if (mInstantExpanding || !mNotificationsDragEnabled || mTouchDisabled || (mMotionAborted
|
||||||
|
|||||||
@@ -50,9 +50,6 @@ public class PhoneStatusBarView extends FrameLayout {
|
|||||||
private static final String TAG = "PhoneStatusBarView";
|
private static final String TAG = "PhoneStatusBarView";
|
||||||
private final StatusBarContentInsetsProvider mContentInsetsProvider;
|
private final StatusBarContentInsetsProvider mContentInsetsProvider;
|
||||||
|
|
||||||
StatusBar mBar;
|
|
||||||
|
|
||||||
private ScrimController mScrimController;
|
|
||||||
private DarkReceiver mBattery;
|
private DarkReceiver mBattery;
|
||||||
private DarkReceiver mClock;
|
private DarkReceiver mClock;
|
||||||
private int mRotationOrientation = -1;
|
private int mRotationOrientation = -1;
|
||||||
@@ -76,18 +73,10 @@ public class PhoneStatusBarView extends FrameLayout {
|
|||||||
mContentInsetsProvider = Dependency.get(StatusBarContentInsetsProvider.class);
|
mContentInsetsProvider = Dependency.get(StatusBarContentInsetsProvider.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBar(StatusBar bar) {
|
|
||||||
mBar = bar;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setTouchEventHandler(TouchEventHandler handler) {
|
void setTouchEventHandler(TouchEventHandler handler) {
|
||||||
mTouchEventHandler = handler;
|
mTouchEventHandler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScrimController(ScrimController scrimController) {
|
|
||||||
mScrimController = scrimController;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFinishInflate() {
|
public void onFinishInflate() {
|
||||||
mBattery = findViewById(R.id.battery);
|
mBattery = findViewById(R.id.battery);
|
||||||
@@ -174,7 +163,6 @@ public class PhoneStatusBarView extends FrameLayout {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
mBar.onTouchEvent(event);
|
|
||||||
if (mTouchEventHandler == null) {
|
if (mTouchEventHandler == null) {
|
||||||
Log.w(
|
Log.w(
|
||||||
TAG,
|
TAG,
|
||||||
@@ -191,7 +179,7 @@ public class PhoneStatusBarView extends FrameLayout {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onInterceptTouchEvent(MotionEvent event) {
|
public boolean onInterceptTouchEvent(MotionEvent event) {
|
||||||
mBar.onTouchEvent(event);
|
mTouchEventHandler.onInterceptTouchEvent(event);
|
||||||
return super.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
|
* Touches that occur on the status bar view may have ramifications for the notification
|
||||||
* value from the handler will be returned from {@link this#onTouchEvent}.
|
* 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 {
|
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);
|
boolean handleTouchEvent(MotionEvent event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1141,8 +1141,6 @@ public class StatusBar extends SystemUI implements
|
|||||||
|
|
||||||
PhoneStatusBarView oldStatusBarView = mStatusBarView;
|
PhoneStatusBarView oldStatusBarView = mStatusBarView;
|
||||||
mStatusBarView = (PhoneStatusBarView) statusBarFragment.getView();
|
mStatusBarView = (PhoneStatusBarView) statusBarFragment.getView();
|
||||||
mStatusBarView.setBar(this);
|
|
||||||
mStatusBarView.setScrimController(mScrimController);
|
|
||||||
|
|
||||||
mPhoneStatusBarViewController = mPhoneStatusBarViewControllerFactory
|
mPhoneStatusBarViewController = mPhoneStatusBarViewControllerFactory
|
||||||
.create(mStatusBarView, mNotificationPanelViewController
|
.create(mStatusBarView, mNotificationPanelViewController
|
||||||
|
|||||||
@@ -523,46 +523,50 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onTouchForwardedFromStatusBar_panelsNotEnabled_returnsFalseAndNoViewEvent() {
|
public void handleTouchEventFromStatusBar_panelsNotEnabled_returnsFalseAndNoViewEvent() {
|
||||||
when(mCommandQueue.panelsEnabled()).thenReturn(false);
|
when(mCommandQueue.panelsEnabled()).thenReturn(false);
|
||||||
|
|
||||||
boolean returnVal = mTouchHandler.onTouchForwardedFromStatusBar(
|
boolean returnVal = mNotificationPanelViewController
|
||||||
MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0));
|
.getStatusBarTouchEventHandler()
|
||||||
|
.handleTouchEvent(
|
||||||
|
MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0));
|
||||||
|
|
||||||
assertThat(returnVal).isFalse();
|
assertThat(returnVal).isFalse();
|
||||||
verify(mView, never()).dispatchTouchEvent(any());
|
verify(mView, never()).dispatchTouchEvent(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onTouchForwardedFromStatusBar_viewNotEnabled_returnsTrueAndNoViewEvent() {
|
public void handleTouchEventFromStatusBar_viewNotEnabled_returnsTrueAndNoViewEvent() {
|
||||||
when(mCommandQueue.panelsEnabled()).thenReturn(true);
|
when(mCommandQueue.panelsEnabled()).thenReturn(true);
|
||||||
when(mView.isEnabled()).thenReturn(false);
|
when(mView.isEnabled()).thenReturn(false);
|
||||||
|
|
||||||
boolean returnVal = mTouchHandler.onTouchForwardedFromStatusBar(
|
boolean returnVal = mNotificationPanelViewController
|
||||||
MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0));
|
.getStatusBarTouchEventHandler()
|
||||||
|
.handleTouchEvent(
|
||||||
|
MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0));
|
||||||
|
|
||||||
assertThat(returnVal).isTrue();
|
assertThat(returnVal).isTrue();
|
||||||
verify(mView, never()).dispatchTouchEvent(any());
|
verify(mView, never()).dispatchTouchEvent(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onTouchForwardedFromStatusBar_viewNotEnabledButIsMoveEvent_viewReceivesEvent() {
|
public void handleTouchEventFromStatusBar_viewNotEnabledButIsMoveEvent_viewReceivesEvent() {
|
||||||
when(mCommandQueue.panelsEnabled()).thenReturn(true);
|
when(mCommandQueue.panelsEnabled()).thenReturn(true);
|
||||||
when(mView.isEnabled()).thenReturn(false);
|
when(mView.isEnabled()).thenReturn(false);
|
||||||
MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_MOVE, 0f, 0f, 0);
|
MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_MOVE, 0f, 0f, 0);
|
||||||
|
|
||||||
mTouchHandler.onTouchForwardedFromStatusBar(event);
|
mNotificationPanelViewController.getStatusBarTouchEventHandler().handleTouchEvent(event);
|
||||||
|
|
||||||
verify(mView).dispatchTouchEvent(event);
|
verify(mView).dispatchTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onTouchForwardedFromStatusBar_panelAndViewEnabled_viewReceivesEvent() {
|
public void handleTouchEventFromStatusBar_panelAndViewEnabled_viewReceivesEvent() {
|
||||||
when(mCommandQueue.panelsEnabled()).thenReturn(true);
|
when(mCommandQueue.panelsEnabled()).thenReturn(true);
|
||||||
when(mView.isEnabled()).thenReturn(true);
|
when(mView.isEnabled()).thenReturn(true);
|
||||||
MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0);
|
MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0);
|
||||||
|
|
||||||
mTouchHandler.onTouchForwardedFromStatusBar(event);
|
mNotificationPanelViewController.getStatusBarTouchEventHandler().handleTouchEvent(event);
|
||||||
|
|
||||||
verify(mView).dispatchTouchEvent(event);
|
verify(mView).dispatchTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,8 +52,6 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
|
|||||||
@Mock
|
@Mock
|
||||||
private lateinit var panelView: ViewGroup
|
private lateinit var panelView: ViewGroup
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var scrimController: ScrimController
|
|
||||||
@Mock
|
|
||||||
private lateinit var moveFromCenterAnimation: StatusBarMoveFromCenterAnimationController
|
private lateinit var moveFromCenterAnimation: StatusBarMoveFromCenterAnimationController
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var sysuiUnfoldComponent: SysUIUnfoldComponent
|
private lateinit var sysuiUnfoldComponent: SysUIUnfoldComponent
|
||||||
@@ -76,8 +74,6 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
|
|||||||
val parent = FrameLayout(mContext) // add parent to keep layout params
|
val parent = FrameLayout(mContext) // add parent to keep layout params
|
||||||
view = LayoutInflater.from(mContext)
|
view = LayoutInflater.from(mContext)
|
||||||
.inflate(R.layout.status_bar, parent, false) as PhoneStatusBarView
|
.inflate(R.layout.status_bar, parent, false) as PhoneStatusBarView
|
||||||
view.setScrimController(scrimController)
|
|
||||||
view.setBar(mock(StatusBar::class.java))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
controller = createController(view)
|
controller = createController(view)
|
||||||
@@ -85,10 +81,13 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun constructor_setsTouchHandlerOnView() {
|
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)
|
val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)
|
||||||
|
|
||||||
|
view.onInterceptTouchEvent(interceptEvent)
|
||||||
view.onTouchEvent(event)
|
view.onTouchEvent(event)
|
||||||
|
|
||||||
|
assertThat(touchEventHandler.lastInterceptEvent).isEqualTo(interceptEvent)
|
||||||
assertThat(touchEventHandler.lastEvent).isEqualTo(event)
|
assertThat(touchEventHandler.lastEvent).isEqualTo(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +127,11 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
|
|||||||
|
|
||||||
private class TestTouchEventHandler : PhoneStatusBarView.TouchEventHandler {
|
private class TestTouchEventHandler : PhoneStatusBarView.TouchEventHandler {
|
||||||
var lastEvent: MotionEvent? = null
|
var lastEvent: MotionEvent? = null
|
||||||
|
var lastInterceptEvent: MotionEvent? = null
|
||||||
|
|
||||||
|
override fun onInterceptTouchEvent(event: MotionEvent?) {
|
||||||
|
lastInterceptEvent = event
|
||||||
|
}
|
||||||
override fun handleTouchEvent(event: MotionEvent?): Boolean {
|
override fun handleTouchEvent(event: MotionEvent?): Boolean {
|
||||||
lastEvent = event
|
lastEvent = event
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -34,10 +34,6 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
|||||||
private lateinit var panelViewController: PanelViewController
|
private lateinit var panelViewController: PanelViewController
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var panelView: ViewGroup
|
private lateinit var panelView: ViewGroup
|
||||||
@Mock
|
|
||||||
private lateinit var scrimController: ScrimController
|
|
||||||
@Mock
|
|
||||||
private lateinit var statusBar: StatusBar
|
|
||||||
|
|
||||||
private lateinit var view: PhoneStatusBarView
|
private lateinit var view: PhoneStatusBarView
|
||||||
|
|
||||||
@@ -49,8 +45,6 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
|||||||
`when`(panelViewController.view).thenReturn(panelView)
|
`when`(panelViewController.view).thenReturn(panelView)
|
||||||
|
|
||||||
view = PhoneStatusBarView(mContext, null)
|
view = PhoneStatusBarView(mContext, null)
|
||||||
view.setScrimController(scrimController)
|
|
||||||
view.setBar(statusBar)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -64,13 +58,24 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
|||||||
assertThat(handler.lastEvent).isEqualTo(event)
|
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
|
@Test
|
||||||
fun onTouchEvent_listenerReturnsTrue_viewReturnsTrue() {
|
fun onTouchEvent_listenerReturnsTrue_viewReturnsTrue() {
|
||||||
val handler = TestTouchEventHandler()
|
val handler = TestTouchEventHandler()
|
||||||
view.setTouchEventHandler(handler)
|
view.setTouchEventHandler(handler)
|
||||||
val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)
|
val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)
|
||||||
|
|
||||||
handler.returnValue = true
|
handler.handleTouchReturnValue = true
|
||||||
|
|
||||||
assertThat(view.onTouchEvent(event)).isTrue()
|
assertThat(view.onTouchEvent(event)).isTrue()
|
||||||
}
|
}
|
||||||
@@ -81,7 +86,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
|||||||
view.setTouchEventHandler(handler)
|
view.setTouchEventHandler(handler)
|
||||||
val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)
|
val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)
|
||||||
|
|
||||||
handler.returnValue = false
|
handler.handleTouchReturnValue = false
|
||||||
|
|
||||||
assertThat(view.onTouchEvent(event)).isFalse()
|
assertThat(view.onTouchEvent(event)).isFalse()
|
||||||
}
|
}
|
||||||
@@ -93,11 +98,17 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class TestTouchEventHandler : PhoneStatusBarView.TouchEventHandler {
|
private class TestTouchEventHandler : PhoneStatusBarView.TouchEventHandler {
|
||||||
|
var lastInterceptEvent: MotionEvent? = null
|
||||||
var lastEvent: 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 {
|
override fun handleTouchEvent(event: MotionEvent?): Boolean {
|
||||||
lastEvent = event
|
lastEvent = event
|
||||||
return returnValue
|
return handleTouchReturnValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user