Merge "Reset translation and fading of top-level notifs on collapse/hide/show" into udc-dev am: 4815a874a5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23642106

Change-Id: I04d8fae32a7e3a88bb1bdcf99b8041bb6a28e6d9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Julia Reynolds
2023-06-12 15:33:31 +00:00
committed by Automerger Merge Worker
3 changed files with 45 additions and 7 deletions

View File

@@ -34,6 +34,7 @@ import android.app.PendingIntent;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.RectF; import android.graphics.RectF;
import android.os.Handler; import android.os.Handler;
import android.os.Trace;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
@@ -277,9 +278,11 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {
// invalidate the view's own bounds all the way up the view hierarchy // invalidate the view's own bounds all the way up the view hierarchy
public static void invalidateGlobalRegion(View view) { public static void invalidateGlobalRegion(View view) {
Trace.beginSection("SwipeHelper.invalidateGlobalRegion");
invalidateGlobalRegion( invalidateGlobalRegion(
view, view,
new RectF(view.getLeft(), view.getTop(), view.getRight(), view.getBottom())); new RectF(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()));
Trace.endSection();
} }
// invalidate a rectangle relative to the view's coordinate system all the way up the view // invalidate a rectangle relative to the view's coordinate system all the way up the view
@@ -492,7 +495,7 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {
} }
if (!mCancelled || wasRemoved) { if (!mCancelled || wasRemoved) {
mCallback.onChildDismissed(animView); mCallback.onChildDismissed(animView);
resetSwipeOfView(animView); resetViewIfSwiping(animView);
} }
if (endAction != null) { if (endAction != null) {
endAction.accept(mCancelled); endAction.accept(mCancelled);
@@ -547,7 +550,7 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {
if (!cancelled) { if (!cancelled) {
updateSwipeProgressFromOffset(animView, canBeDismissed); updateSwipeProgressFromOffset(animView, canBeDismissed);
resetSwipeOfView(animView); resetViewIfSwiping(animView);
// Clear the snapped view after success, assuming it's not being swiped now // Clear the snapped view after success, assuming it's not being swiped now
if (animView == mTouchedView && !mIsSwiping) { if (animView == mTouchedView && !mIsSwiping) {
mTouchedView = null; mTouchedView = null;
@@ -811,7 +814,7 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {
return mIsSwiping ? mTouchedView : null; return mIsSwiping ? mTouchedView : null;
} }
protected void resetSwipeOfView(View view) { protected void resetViewIfSwiping(View view) {
if (getSwipedView() == view) { if (getSwipedView() == view) {
resetSwipeState(); resetSwipeState();
} }
@@ -825,6 +828,12 @@ public class SwipeHelper implements Gefingerpoken, Dumpable {
resetSwipeStates(/* resetAll= */ true); resetSwipeStates(/* resetAll= */ true);
} }
public void forceResetSwipeState(@NonNull View view) {
if (view.getTranslationX() == 0) return;
setTranslation(view, 0);
updateSwipeProgressFromOffset(view, /* dismissable= */ true, 0);
}
/** This method resets the swipe state, and if `resetAll` is true, also resets the snap state */ /** This method resets the swipe state, and if `resetAll` is true, also resets the snap state */
private void resetSwipeStates(boolean resetAll) { private void resetSwipeStates(boolean resetAll) {
final View touchedView = mTouchedView; final View touchedView = mTouchedView;

View File

@@ -4011,7 +4011,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
mCentralSurfaces.resetUserExpandedStates(); mCentralSurfaces.resetUserExpandedStates();
clearTemporaryViews(); clearTemporaryViews();
clearUserLockedViews(); clearUserLockedViews();
cancelActiveSwipe(); resetAllSwipeState();
} }
} }
@@ -4077,7 +4077,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
mGroupExpansionManager.collapseGroups(); mGroupExpansionManager.collapseGroups();
mExpandHelper.cancelImmediately(); mExpandHelper.cancelImmediately();
if (!mIsExpansionChanging) { if (!mIsExpansionChanging) {
cancelActiveSwipe(); resetAllSwipeState();
} }
finalizeClearAllAnimation(); finalizeClearAllAnimation();
} }
@@ -4406,7 +4406,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
boolean nowHiddenAtAll = mAmbientState.isHiddenAtAll(); boolean nowHiddenAtAll = mAmbientState.isHiddenAtAll();
if (nowFullyHidden != wasFullyHidden) { if (nowFullyHidden != wasFullyHidden) {
updateVisibility(); updateVisibility();
mSwipeHelper.resetTouchState(); resetAllSwipeState();
} }
if (!wasHiddenAtAll && nowHiddenAtAll) { if (!wasHiddenAtAll && nowHiddenAtAll) {
resetExposedMenuView(true /* animate */, true /* animate */); resetExposedMenuView(true /* animate */, true /* animate */);
@@ -5866,9 +5866,14 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
} }
} }
private void cancelActiveSwipe() { private void resetAllSwipeState() {
Trace.beginSection("NSSL.resetAllSwipeState()");
mSwipeHelper.resetTouchState(); mSwipeHelper.resetTouchState();
for (int i = 0; i < getChildCount(); i++) {
mSwipeHelper.forceResetSwipeState(getChildAt(i));
}
updateContinuousShadowDrawing(); updateContinuousShadowDrawing();
Trace.endSection();
} }
void updateContinuousShadowDrawing() { void updateContinuousShadowDrawing() {

View File

@@ -21,6 +21,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyFloat; import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
@@ -29,6 +30,7 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.animation.Animator; import android.animation.Animator;
@@ -669,6 +671,28 @@ public class NotificationSwipeHelperTest extends SysuiTestCase {
verify(mNotificationRow, never()).setContentAlpha(anyFloat()); verify(mNotificationRow, never()).setContentAlpha(anyFloat());
} }
@Test
public void testForceResetSwipeStateDoesNothingIfTranslationIsZero() {
doReturn(FAKE_ROW_WIDTH).when(mNotificationRow).getMeasuredWidth();
doReturn(0f).when(mNotificationRow).getTranslationX();
mSwipeHelper.forceResetSwipeState(mNotificationRow);
verify(mNotificationRow).getTranslationX();
verifyNoMoreInteractions(mNotificationRow);
}
@Test
public void testForceResetSwipeStateResetsTranslationAndAlpha() {
doReturn(FAKE_ROW_WIDTH).when(mNotificationRow).getMeasuredWidth();
doReturn(10f).when(mNotificationRow).getTranslationX();
mSwipeHelper.forceResetSwipeState(mNotificationRow);
verify(mNotificationRow).setTranslation(eq(0f));
verify(mNotificationRow).setContentAlpha(eq(1f));
}
@Test @Test
public void testContentAlphaRemainsUnchangedWhenFeatureFlagIsDisabled() { public void testContentAlphaRemainsUnchangedWhenFeatureFlagIsDisabled() {