Clean up interfaces for StackScrollLayout.

Test: Automated tests should pass.
Change-Id: Ibf2718bfaacff0adcfca7ef8ca2f3eb2b867debf
This commit is contained in:
Aaron Heuckroth
2018-10-01 16:31:08 -04:00
parent 294ade62bf
commit cd944dc665
10 changed files with 748 additions and 714 deletions

View File

@@ -87,6 +87,8 @@ public class SwipeHelper implements Gefingerpoken {
private Runnable mWatchLongPress;
private final long mLongPressTimeout;
protected boolean mSwipingInProgress;
final private int[] mTmpPos = new int[2];
private final int mFalsingThreshold;
private boolean mTouchAboveFalsingThreshold;
@@ -127,6 +129,10 @@ public class SwipeHelper implements Gefingerpoken {
mDisableHwLayers = disableHwLayers;
}
public boolean isSwipingInProgress() {
return mSwipingInProgress;
}
private float getPos(MotionEvent ev) {
return mSwipeDirection == X ? ev.getX() : ev.getY();
}
@@ -318,6 +324,7 @@ public class SwipeHelper implements Gefingerpoken {
if (Math.abs(delta) > mPagingTouchSlop
&& Math.abs(delta) > Math.abs(deltaPerpendicular)) {
if (mCallback.canChildBeDragged(mCurrView)) {
mSwipingInProgress = true;
mCallback.onBeginDrag(mCurrView);
mDragging = true;
mInitialTouchPos = getPos(ev);
@@ -437,6 +444,7 @@ public class SwipeHelper implements Gefingerpoken {
wasRemoved = row.isRemoved();
}
if (!mCancelled || wasRemoved) {
mSwipingInProgress = false;
mCallback.onChildDismissed(animView);
}
if (endAction != null) {
@@ -626,6 +634,7 @@ public class SwipeHelper implements Gefingerpoken {
!swipedFastEnough() /* useAccelerateInterpolator */);
} else {
// snappity
mSwipingInProgress = false;
mCallback.onDragCancelled(mCurrView);
snapChild(mCurrView, 0 /* leftTarget */, velocity);
}

View File

@@ -24,7 +24,10 @@ import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
public interface VisibilityLocationProvider {
/**
* @return whether the view is in a visible location right now.
* Returns whether an ExpandableNotificationRow is in a visible location or not.
*
* @param row
* @return true if row is in a visible location
*/
boolean isInVisibleLocation(ExpandableNotificationRow row);
}

View File

@@ -22,6 +22,7 @@ import android.view.View;
import android.view.ViewGroup;
import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper;
import com.android.systemui.statusbar.notification.VisibilityLocationProvider;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.ExpandableView;
import com.android.systemui.statusbar.notification.NotificationData;
@@ -31,7 +32,8 @@ import com.android.systemui.statusbar.notification.logging.NotificationLogger;
* Interface representing the entity that contains notifications. It can have
* notification views added and removed from it, and will manage displaying them to the user.
*/
public interface NotificationListContainer {
public interface NotificationListContainer extends ExpandableView.OnHeightChangedListener,
VisibilityLocationProvider {
/**
* Called when a child is being transferred.
@@ -127,14 +129,6 @@ public interface NotificationListContainer {
*/
ViewGroup getViewParentForNotification(NotificationData.Entry entry);
/**
* Called when the height of an expandable view changes.
*
* @param view view whose height changed
* @param animate whether this change should be animated
*/
void onHeightChanged(ExpandableView view, boolean animate);
/**
* Resets the currently exposed menu view.
*
@@ -158,13 +152,6 @@ public interface NotificationListContainer {
*/
void cleanUpViewState(View view);
/**
* Returns whether an ExpandableNotificationRow is in a visible location or not.
*
* @param row
* @return true if row is in a visible location
*/
boolean isInVisibleLocation(ExpandableNotificationRow row);
/**
* Sets a listener to listen for changes in notification locations.

View File

@@ -31,11 +31,9 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.SwipeHelper;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper;
import com.android.systemui.statusbar.notification.ShadeViewRefactor;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.ExpandableView;
@ShadeViewRefactor(ShadeViewRefactor.RefactorComponent.INPUT)
class NotificationSwipeHelper extends SwipeHelper
implements NotificationSwipeActionHelper {
@VisibleForTesting
@@ -229,6 +227,7 @@ class NotificationSwipeHelper extends SwipeHelper
if (mCallback.isExpanded()) {
// We don't want to quick-dismiss when it's a heads up as this might lead to closing
// of the panel early.
mSwipingInProgress = false;
mCallback.handleChildViewDismissed(view);
}
mCallback.onDismiss();
@@ -248,6 +247,7 @@ class NotificationSwipeHelper extends SwipeHelper
@Override
public void snapChild(final View animView, final float targetLeft, float velocity) {
superSnapChild(animView, targetLeft, velocity);
mSwipingInProgress = false;
mCallback.onDragCancelled(animView);
if (targetLeft == 0) {
handleMenuCoveredOrDismissed();
@@ -354,6 +354,7 @@ class NotificationSwipeHelper extends SwipeHelper
public void onMenuShown(View animView) {
setExposedMenuView(getTranslatingParentView());
mSwipingInProgress = false;
mCallback.onDragCancelled(animView);
Handler handler = getHandler();

View File

@@ -32,7 +32,7 @@ import com.android.systemui.statusbar.notification.stack.NotificationStackScroll
public class HeadsUpTouchHelper implements Gefingerpoken {
private HeadsUpManagerPhone mHeadsUpManager;
private NotificationStackScrollLayout mStackScroller;
private Callback mCallback;
private int mTrackingPointer;
private float mTouchSlop;
private float mInitialTouchX;
@@ -44,12 +44,12 @@ public class HeadsUpTouchHelper implements Gefingerpoken {
private ExpandableNotificationRow mPickedChild;
public HeadsUpTouchHelper(HeadsUpManagerPhone headsUpManager,
NotificationStackScrollLayout stackScroller,
Callback callback,
NotificationPanelView notificationPanelView) {
mHeadsUpManager = headsUpManager;
mStackScroller = stackScroller;
mCallback = callback;
mPanel = notificationPanelView;
Context context = stackScroller.getContext();
Context context = mCallback.getContext();
final ViewConfiguration configuration = ViewConfiguration.get(context);
mTouchSlop = configuration.getScaledTouchSlop();
}
@@ -75,13 +75,13 @@ public class HeadsUpTouchHelper implements Gefingerpoken {
mInitialTouchY = y;
mInitialTouchX = x;
setTrackingHeadsUp(false);
ExpandableView child = mStackScroller.getChildAtRawPosition(x, y);
ExpandableView child = mCallback.getChildAtRawPosition(x, y);
mTouchingHeadsUpView = false;
if (child instanceof ExpandableNotificationRow) {
mPickedChild = (ExpandableNotificationRow) child;
mTouchingHeadsUpView = !mStackScroller.isExpanded()
mTouchingHeadsUpView = !mCallback.isExpanded()
&& mPickedChild.isHeadsUp() && mPickedChild.isPinned();
} else if (child == null && !mStackScroller.isExpanded()) {
} else if (child == null && !mCallback.isExpanded()) {
// We might touch above the visible heads up child, but then we still would
// like to capture it.
NotificationData.Entry topEntry = mHeadsUpManager.getTopEntry();
@@ -174,4 +174,10 @@ public class HeadsUpTouchHelper implements Gefingerpoken {
mPickedChild = null;
mTouchingHeadsUpView = false;
}
public interface Callback {
ExpandableView getChildAtRawPosition(float touchX, float touchY);
boolean isExpanded();
Context getContext();
}
}

View File

@@ -2521,8 +2521,8 @@ public class NotificationPanelView extends PanelView implements
@Override
public void setHeadsUpManager(HeadsUpManagerPhone headsUpManager) {
super.setHeadsUpManager(headsUpManager);
mHeadsUpTouchHelper = new HeadsUpTouchHelper(headsUpManager, mNotificationStackScroller,
this);
mHeadsUpTouchHelper = new HeadsUpTouchHelper(headsUpManager,
mNotificationStackScroller.getHeadsUpCallback(), this);
}
public void setTrackedHeadsUp(ExpandableNotificationRow pickedChild) {

View File

@@ -58,6 +58,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.view.FloatingActionMode;
import com.android.internal.widget.FloatingToolbar;
import com.android.systemui.Dependency;
import com.android.systemui.ExpandHelper;
import com.android.systemui.R;
import com.android.systemui.classifier.FalsingManager;
import com.android.systemui.statusbar.DragDownHelper;
@@ -182,6 +183,11 @@ public class StatusBarWindowView extends FrameLayout {
}
}
@VisibleForTesting
protected NotificationStackScrollLayout getStackScrollLayout() {
return mStackScrollLayout;
}
@Override
public FrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs) {
return new LayoutParams(getContext(), attrs);
@@ -215,8 +221,11 @@ public class StatusBarWindowView extends FrameLayout {
public void setService(StatusBar service) {
mService = service;
setDragDownHelper(new DragDownHelper(getContext(), this, mStackScrollLayout,
mStackScrollLayout));
NotificationStackScrollLayout stackScrollLayout = getStackScrollLayout();
ExpandHelper.Callback expandHelperCallback = stackScrollLayout.getExpandHelperCallback();
DragDownHelper.DragDownCallback dragDownCallback = stackScrollLayout.getDragDownCallback();
setDragDownHelper(new DragDownHelper(getContext(), this, expandHelperCallback,
dragDownCallback));
}
@VisibleForTesting
@@ -309,7 +318,7 @@ public class StatusBarWindowView extends FrameLayout {
}
}
if (isDown) {
mStackScrollLayout.closeControlsIfOutsideTouch(ev);
getStackScrollLayout().closeControlsIfOutsideTouch(ev);
}
if (mService.isDozing()) {
mService.mDozeScrimController.extendPulse();
@@ -331,13 +340,14 @@ public class StatusBarWindowView extends FrameLayout {
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mService.isDozing() && !mStackScrollLayout.hasPulsingNotifications()) {
NotificationStackScrollLayout stackScrollLayout = getStackScrollLayout();
if (mService.isDozing() && !stackScrollLayout.hasPulsingNotifications()) {
// Capture all touch events in always-on.
return true;
}
boolean intercept = false;
if (mNotificationPanel.isFullyExpanded()
&& mStackScrollLayout.getVisibility() == View.VISIBLE
&& stackScrollLayout.getVisibility() == View.VISIBLE
&& mStatusBarStateController.getState() == StatusBarState.KEYGUARD
&& !mService.isBouncerShowing()
&& !mService.isDozing()) {
@@ -349,7 +359,7 @@ public class StatusBarWindowView extends FrameLayout {
if (intercept) {
MotionEvent cancellation = MotionEvent.obtain(ev);
cancellation.setAction(MotionEvent.ACTION_CANCEL);
mStackScrollLayout.onInterceptTouchEvent(cancellation);
stackScrollLayout.onInterceptTouchEvent(cancellation);
mNotificationPanel.onInterceptTouchEvent(cancellation);
cancellation.recycle();
}
@@ -391,8 +401,9 @@ public class StatusBarWindowView extends FrameLayout {
}
public void cancelExpandHelper() {
if (mStackScrollLayout != null) {
mStackScrollLayout.cancelExpandHelper();
NotificationStackScrollLayout stackScrollLayout = getStackScrollLayout();
if (stackScrollLayout != null) {
stackScrollLayout.cancelExpandHelper();
}
}

View File

@@ -217,6 +217,9 @@ public class NotificationViewHierarchyManagerTest extends SysuiTestCase {
@Override
public void generateChildOrderChangedEvent() {}
@Override
public void onReset(ExpandableView view) {}
@Override
public int getContainerChildCount() {
return mRows.size();

View File

@@ -17,11 +17,11 @@
package com.android.systemui.statusbar.phone;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.os.SystemClock;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.MotionEvent;
@@ -31,6 +31,7 @@ import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.DragDownHelper;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
import org.junit.Before;
import org.junit.Test;
@@ -43,11 +44,14 @@ public class StatusBarWindowViewTest extends SysuiTestCase {
private StatusBarWindowView mView;
private StatusBar mStatusBar;
private DragDownHelper mDragDownHelper;
private NotificationStackScrollLayout mStackScrollLayout;
@Before
public void setUp() {
mDependency.injectMockDependency(StatusBarStateController.class);
mView = new StatusBarWindowView(getContext(), null);
mView = spy(new StatusBarWindowView(getContext(), null));
mStackScrollLayout = mock(NotificationStackScrollLayout.class);
when(mView.getStackScrollLayout()).thenReturn(mStackScrollLayout);
mStatusBar = mock(StatusBar.class);
mView.setService(mStatusBar);
mDragDownHelper = mock(DragDownHelper.class);