Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationMenuRow.java +18 −1 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.systemui.statusbar.notification.row; package com.android.systemui.statusbar.notification.row; import static android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE; import static android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE; import static android.view.HapticFeedbackConstants.CLOCK_TICK; import static com.android.systemui.SwipeHelper.SWIPED_FAR_ENOUGH_SIZE_FRACTION; import static com.android.systemui.SwipeHelper.SWIPED_FAR_ENOUGH_SIZE_FRACTION; Loading Loading @@ -113,6 +114,8 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl private boolean mIsUserTouching; private boolean mIsUserTouching; private boolean mSnappingToDismiss; private final PeopleNotificationIdentifier mPeopleNotificationIdentifier; private final PeopleNotificationIdentifier mPeopleNotificationIdentifier; public NotificationMenuRow(Context context, public NotificationMenuRow(Context context, Loading Loading @@ -175,6 +178,11 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl return mSnapping; return mSnapping; } } @VisibleForTesting protected boolean isSnappingToDismiss() { return mSnappingToDismiss; } @Override @Override public void setMenuClickListener(OnMenuEventListener listener) { public void setMenuClickListener(OnMenuEventListener listener) { mMenuListener = listener; mMenuListener = listener; Loading Loading @@ -346,6 +354,14 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl mCheckForDrag = new CheckForDrag(); mCheckForDrag = new CheckForDrag(); mHandler.postDelayed(mCheckForDrag, SHOW_MENU_DELAY); mHandler.postDelayed(mCheckForDrag, SHOW_MENU_DELAY); } } if (canBeDismissed()) { final float dismissThreshold = getDismissThreshold(); final boolean snappingToDismiss = delta < -dismissThreshold || delta > dismissThreshold; if (mSnappingToDismiss != snappingToDismiss) { getMenuView().performHapticFeedback(CLOCK_TICK); } mSnappingToDismiss = snappingToDismiss; } } } @VisibleForTesting @VisibleForTesting Loading @@ -362,6 +378,7 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl @Override @Override public void onTouchStart() { public void onTouchStart() { beginDrag(); beginDrag(); mSnappingToDismiss = false; } } @Override @Override Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java +62 −1 Original line number Original line Diff line number Diff line Loading @@ -14,8 +14,9 @@ package com.android.systemui.statusbar.notification.row; package com.android.systemui.statusbar.notification.row; import static android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE; import static android.provider.Settings.Global.SHOW_NEW_NOTIF_DISMISS; import static android.provider.Settings.Global.SHOW_NEW_NOTIF_DISMISS; import static android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE; import static android.view.HapticFeedbackConstants.CLOCK_TICK; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertFalse; Loading @@ -33,6 +34,7 @@ import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.testing.TestableLooper.RunWithLooper; import android.testing.ViewUtils; import android.testing.ViewUtils; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup; import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest; Loading @@ -54,12 +56,14 @@ import org.mockito.Mockito; public class NotificationMenuRowTest extends LeakCheckedTest { public class NotificationMenuRowTest extends LeakCheckedTest { private ExpandableNotificationRow mRow; private ExpandableNotificationRow mRow; private View mView; private PeopleNotificationIdentifier mPeopleNotificationIdentifier; private PeopleNotificationIdentifier mPeopleNotificationIdentifier; @Before @Before public void setup() { public void setup() { injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); mRow = mock(ExpandableNotificationRow.class); mRow = mock(ExpandableNotificationRow.class); mView = mock(View.class); mPeopleNotificationIdentifier = mock(PeopleNotificationIdentifier.class); mPeopleNotificationIdentifier = mock(PeopleNotificationIdentifier.class); NotificationEntry entry = new NotificationEntryBuilder().build(); NotificationEntry entry = new NotificationEntryBuilder().build(); when(mRow.getEntry()).thenReturn(entry); when(mRow.getEntry()).thenReturn(entry); Loading Loading @@ -409,4 +413,61 @@ public class NotificationMenuRowTest extends LeakCheckedTest { row.setMenuAlpha(0.5f); row.setMenuAlpha(0.5f); assertTrue("when alpha is .5, menu is visible", row.isMenuVisible()); assertTrue("when alpha is .5, menu is visible", row.isMenuVisible()); } } @Test public void testOnTouchMove() { NotificationMenuRow row = Mockito.spy( new NotificationMenuRow(mContext, mPeopleNotificationIdentifier)); row.createMenu(mRow, null); doReturn(50f).when(row).getDismissThreshold(); doReturn(true).when(row).canBeDismissed(); doReturn(mView).when(row).getMenuView(); row.onTouchMove(30f); assertFalse("When moving not farther than threshold, menu is not snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(0)).performHapticFeedback(CLOCK_TICK); row.onTouchMove(60f); assertTrue("When moving farther than threshold, menu is snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(1)).performHapticFeedback(CLOCK_TICK); row.onTouchMove(70f); assertTrue("When moving farther than threshold, menu is snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(1)).performHapticFeedback(CLOCK_TICK); row.onTouchMove(30f); assertFalse("When moving not farther than threshold, menu is not snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(2)).performHapticFeedback(CLOCK_TICK); row.onTouchMove(-30f); assertFalse("When moving not farther than threshold, menu is not snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(2)).performHapticFeedback(CLOCK_TICK); row.onTouchMove(-60f); assertTrue("When moving farther than threshold, menu is snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(3)).performHapticFeedback(CLOCK_TICK); row.onTouchMove(-70f); assertTrue("When moving farther than threshold, menu is snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(3)).performHapticFeedback(CLOCK_TICK); row.onTouchMove(-30f); assertFalse("When moving not farther than threshold, menu is not snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(4)).performHapticFeedback(CLOCK_TICK); } } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationMenuRow.java +18 −1 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.systemui.statusbar.notification.row; package com.android.systemui.statusbar.notification.row; import static android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE; import static android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE; import static android.view.HapticFeedbackConstants.CLOCK_TICK; import static com.android.systemui.SwipeHelper.SWIPED_FAR_ENOUGH_SIZE_FRACTION; import static com.android.systemui.SwipeHelper.SWIPED_FAR_ENOUGH_SIZE_FRACTION; Loading Loading @@ -113,6 +114,8 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl private boolean mIsUserTouching; private boolean mIsUserTouching; private boolean mSnappingToDismiss; private final PeopleNotificationIdentifier mPeopleNotificationIdentifier; private final PeopleNotificationIdentifier mPeopleNotificationIdentifier; public NotificationMenuRow(Context context, public NotificationMenuRow(Context context, Loading Loading @@ -175,6 +178,11 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl return mSnapping; return mSnapping; } } @VisibleForTesting protected boolean isSnappingToDismiss() { return mSnappingToDismiss; } @Override @Override public void setMenuClickListener(OnMenuEventListener listener) { public void setMenuClickListener(OnMenuEventListener listener) { mMenuListener = listener; mMenuListener = listener; Loading Loading @@ -346,6 +354,14 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl mCheckForDrag = new CheckForDrag(); mCheckForDrag = new CheckForDrag(); mHandler.postDelayed(mCheckForDrag, SHOW_MENU_DELAY); mHandler.postDelayed(mCheckForDrag, SHOW_MENU_DELAY); } } if (canBeDismissed()) { final float dismissThreshold = getDismissThreshold(); final boolean snappingToDismiss = delta < -dismissThreshold || delta > dismissThreshold; if (mSnappingToDismiss != snappingToDismiss) { getMenuView().performHapticFeedback(CLOCK_TICK); } mSnappingToDismiss = snappingToDismiss; } } } @VisibleForTesting @VisibleForTesting Loading @@ -362,6 +378,7 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl @Override @Override public void onTouchStart() { public void onTouchStart() { beginDrag(); beginDrag(); mSnappingToDismiss = false; } } @Override @Override Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java +62 −1 Original line number Original line Diff line number Diff line Loading @@ -14,8 +14,9 @@ package com.android.systemui.statusbar.notification.row; package com.android.systemui.statusbar.notification.row; import static android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE; import static android.provider.Settings.Global.SHOW_NEW_NOTIF_DISMISS; import static android.provider.Settings.Global.SHOW_NEW_NOTIF_DISMISS; import static android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE; import static android.view.HapticFeedbackConstants.CLOCK_TICK; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertFalse; Loading @@ -33,6 +34,7 @@ import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.testing.TestableLooper.RunWithLooper; import android.testing.ViewUtils; import android.testing.ViewUtils; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup; import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest; Loading @@ -54,12 +56,14 @@ import org.mockito.Mockito; public class NotificationMenuRowTest extends LeakCheckedTest { public class NotificationMenuRowTest extends LeakCheckedTest { private ExpandableNotificationRow mRow; private ExpandableNotificationRow mRow; private View mView; private PeopleNotificationIdentifier mPeopleNotificationIdentifier; private PeopleNotificationIdentifier mPeopleNotificationIdentifier; @Before @Before public void setup() { public void setup() { injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); mRow = mock(ExpandableNotificationRow.class); mRow = mock(ExpandableNotificationRow.class); mView = mock(View.class); mPeopleNotificationIdentifier = mock(PeopleNotificationIdentifier.class); mPeopleNotificationIdentifier = mock(PeopleNotificationIdentifier.class); NotificationEntry entry = new NotificationEntryBuilder().build(); NotificationEntry entry = new NotificationEntryBuilder().build(); when(mRow.getEntry()).thenReturn(entry); when(mRow.getEntry()).thenReturn(entry); Loading Loading @@ -409,4 +413,61 @@ public class NotificationMenuRowTest extends LeakCheckedTest { row.setMenuAlpha(0.5f); row.setMenuAlpha(0.5f); assertTrue("when alpha is .5, menu is visible", row.isMenuVisible()); assertTrue("when alpha is .5, menu is visible", row.isMenuVisible()); } } @Test public void testOnTouchMove() { NotificationMenuRow row = Mockito.spy( new NotificationMenuRow(mContext, mPeopleNotificationIdentifier)); row.createMenu(mRow, null); doReturn(50f).when(row).getDismissThreshold(); doReturn(true).when(row).canBeDismissed(); doReturn(mView).when(row).getMenuView(); row.onTouchMove(30f); assertFalse("When moving not farther than threshold, menu is not snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(0)).performHapticFeedback(CLOCK_TICK); row.onTouchMove(60f); assertTrue("When moving farther than threshold, menu is snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(1)).performHapticFeedback(CLOCK_TICK); row.onTouchMove(70f); assertTrue("When moving farther than threshold, menu is snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(1)).performHapticFeedback(CLOCK_TICK); row.onTouchMove(30f); assertFalse("When moving not farther than threshold, menu is not snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(2)).performHapticFeedback(CLOCK_TICK); row.onTouchMove(-30f); assertFalse("When moving not farther than threshold, menu is not snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(2)).performHapticFeedback(CLOCK_TICK); row.onTouchMove(-60f); assertTrue("When moving farther than threshold, menu is snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(3)).performHapticFeedback(CLOCK_TICK); row.onTouchMove(-70f); assertTrue("When moving farther than threshold, menu is snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(3)).performHapticFeedback(CLOCK_TICK); row.onTouchMove(-30f); assertFalse("When moving not farther than threshold, menu is not snapping to dismiss", row.isSnappingToDismiss()); verify(mView, times(4)).performHapticFeedback(CLOCK_TICK); } } }