Merge "Remove obsolete shadow logic from StackScrollAlgorithm updateChildZValue" into tm-qpr-dev am: be2f4b96ab

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

Change-Id: I05240e9aac87beda26480b7c1abf3a9009f86176
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Yining Liu
2022-12-14 18:53:57 +00:00
committed by Automerger Merge Worker
2 changed files with 26 additions and 40 deletions

View File

@@ -871,8 +871,7 @@ public class StackScrollAlgorithm {
} }
for (int i = childCount - 1; i >= 0; i--) { for (int i = childCount - 1; i >= 0; i--) {
childrenOnTop = updateChildZValue(i, childrenOnTop, updateChildZValue(i, algorithmState, ambientState, i == topHunIndex);
algorithmState, ambientState, i == topHunIndex);
} }
} }
@@ -882,15 +881,11 @@ public class StackScrollAlgorithm {
* *
* @param isTopHun Whether the child is a top HUN. A top HUN means a HUN that shows on the * @param isTopHun Whether the child is a top HUN. A top HUN means a HUN that shows on the
* vertically top of screen. Top HUNs should have drop shadows * vertically top of screen. Top HUNs should have drop shadows
* @param childrenOnTop It is greater than 0 when there's an existing HUN that is elevated
* @return childrenOnTop The decimal part represents the fraction of the elevated HUN's height
* that overlaps with QQS Panel. The integer part represents the count of
* previous HUNs whose Z positions are greater than 0.
*/ */
protected float updateChildZValue(int i, float childrenOnTop, protected void updateChildZValue(int i,
StackScrollAlgorithmState algorithmState, StackScrollAlgorithmState algorithmState,
AmbientState ambientState, AmbientState ambientState,
boolean isTopHun) { boolean isTopHun) {
ExpandableView child = algorithmState.visibleChildren.get(i); ExpandableView child = algorithmState.visibleChildren.get(i);
ExpandableViewState childViewState = child.getViewState(); ExpandableViewState childViewState = child.getViewState();
float baseZ = ambientState.getBaseZHeight(); float baseZ = ambientState.getBaseZHeight();
@@ -904,22 +899,16 @@ public class StackScrollAlgorithm {
// Handles HUN shadow when Shade is opened, and AmbientState.mScrollY > 0 // Handles HUN shadow when Shade is opened, and AmbientState.mScrollY > 0
// Calculate the HUN's z-value based on its overlapping fraction with QQS Panel. // Calculate the HUN's z-value based on its overlapping fraction with QQS Panel.
// When scrolling down shade to make HUN back to in-position in Notification Panel, // When scrolling down shade to make HUN back to in-position in Notification Panel,
// The over-lapping fraction goes to 0, and shadows hides gradually. // the overlapFraction goes to 0, and the pinned HUN's shadows hides gradually.
if (childrenOnTop != 0.0f) { float overlap = ambientState.getTopPadding()
// To elevate the later HUN over previous HUN + ambientState.getStackTranslation() - childViewState.getYTranslation();
childrenOnTop++;
} else { if (childViewState.height > 0) { // To avoid 0/0 problems
float overlap = ambientState.getTopPadding() // To prevent over-shadow
+ ambientState.getStackTranslation() - childViewState.getYTranslation(); float overlapFraction = MathUtils.saturate(overlap / childViewState.height);
// To prevent over-shadow during HUN entry childViewState.setZTranslation(baseZ
childrenOnTop += Math.min( + overlapFraction * mPinnedZTranslationExtra);
1.0f,
overlap / childViewState.height
);
MathUtils.saturate(childrenOnTop);
} }
childViewState.setZTranslation(baseZ
+ childrenOnTop * mPinnedZTranslationExtra);
} else if (isTopHun) { } else if (isTopHun) {
// In case this is a new view that has never been measured before, we don't want to // In case this is a new view that has never been measured before, we don't want to
// elevate if we are currently expanded more than the notification // elevate if we are currently expanded more than the notification
@@ -947,15 +936,14 @@ public class StackScrollAlgorithm {
} }
// Handles HUN shadow when shade is closed. // Handles HUN shadow when shade is closed.
// While HUN is showing and Shade is closed: headerVisibleAmount stays 0, shadow stays. // While shade is closed, and during HUN's entry: headerVisibleAmount stays 0, shadow stays.
// While shade is closed, and HUN is showing: headerVisibleAmount stays 0, shadow stays.
// During HUN-to-Shade (eg. dragging down HUN to open Shade): headerVisibleAmount goes // During HUN-to-Shade (eg. dragging down HUN to open Shade): headerVisibleAmount goes
// gradually from 0 to 1, shadow hides gradually. // gradually from 0 to 1, shadow hides gradually.
// Header visibility is a deprecated concept, we are using headerVisibleAmount only because // Header visibility is a deprecated concept, we are using headerVisibleAmount only because
// this value nicely goes from 0 to 1 during the HUN-to-Shade process. // this value nicely goes from 0 to 1 during the HUN-to-Shade process.
childViewState.setZTranslation(childViewState.getZTranslation() childViewState.setZTranslation(childViewState.getZTranslation()
+ (1.0f - child.getHeaderVisibleAmount()) * mPinnedZTranslationExtra); + (1.0f - child.getHeaderVisibleAmount()) * mPinnedZTranslationExtra);
return childrenOnTop;
} }
public void setIsExpanded(boolean isExpanded) { public void setIsExpanded(boolean isExpanded) {

View File

@@ -518,7 +518,7 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
val childHunView = createHunViewMock( val childHunView = createHunViewMock(
isShadeOpen = true, isShadeOpen = true,
fullyVisible = false, fullyVisible = false,
headerVisibleAmount = 1f headerVisibleAmount = 1f,
) )
val algorithmState = StackScrollAlgorithm.StackScrollAlgorithmState() val algorithmState = StackScrollAlgorithm.StackScrollAlgorithmState()
algorithmState.visibleChildren.add(childHunView) algorithmState.visibleChildren.add(childHunView)
@@ -526,7 +526,6 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
// When: updateChildZValue() is called for the top HUN // When: updateChildZValue() is called for the top HUN
stackScrollAlgorithm.updateChildZValue( stackScrollAlgorithm.updateChildZValue(
/* i= */ 0, /* i= */ 0,
/* childrenOnTop= */ 0.0f,
/* StackScrollAlgorithmState= */ algorithmState, /* StackScrollAlgorithmState= */ algorithmState,
/* ambientState= */ ambientState, /* ambientState= */ ambientState,
/* shouldElevateHun= */ true /* shouldElevateHun= */ true
@@ -546,7 +545,7 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
val childHunView = createHunViewMock( val childHunView = createHunViewMock(
isShadeOpen = true, isShadeOpen = true,
fullyVisible = false, fullyVisible = false,
headerVisibleAmount = 1f headerVisibleAmount = 1f,
) )
// Use half of the HUN's height as overlap // Use half of the HUN's height as overlap
childHunView.viewState.yTranslation = (childHunView.viewState.height + 1 shr 1).toFloat() childHunView.viewState.yTranslation = (childHunView.viewState.height + 1 shr 1).toFloat()
@@ -556,7 +555,6 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
// When: updateChildZValue() is called for the top HUN // When: updateChildZValue() is called for the top HUN
stackScrollAlgorithm.updateChildZValue( stackScrollAlgorithm.updateChildZValue(
/* i= */ 0, /* i= */ 0,
/* childrenOnTop= */ 0.0f,
/* StackScrollAlgorithmState= */ algorithmState, /* StackScrollAlgorithmState= */ algorithmState,
/* ambientState= */ ambientState, /* ambientState= */ ambientState,
/* shouldElevateHun= */ true /* shouldElevateHun= */ true
@@ -580,7 +578,7 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
val childHunView = createHunViewMock( val childHunView = createHunViewMock(
isShadeOpen = true, isShadeOpen = true,
fullyVisible = true, fullyVisible = true,
headerVisibleAmount = 1f headerVisibleAmount = 1f,
) )
// HUN doesn't overlap with QQS Panel // HUN doesn't overlap with QQS Panel
childHunView.viewState.yTranslation = ambientState.topPadding + childHunView.viewState.yTranslation = ambientState.topPadding +
@@ -591,7 +589,6 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
// When: updateChildZValue() is called for the top HUN // When: updateChildZValue() is called for the top HUN
stackScrollAlgorithm.updateChildZValue( stackScrollAlgorithm.updateChildZValue(
/* i= */ 0, /* i= */ 0,
/* childrenOnTop= */ 0.0f,
/* StackScrollAlgorithmState= */ algorithmState, /* StackScrollAlgorithmState= */ algorithmState,
/* ambientState= */ ambientState, /* ambientState= */ ambientState,
/* shouldElevateHun= */ true /* shouldElevateHun= */ true
@@ -611,7 +608,7 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
val childHunView = createHunViewMock( val childHunView = createHunViewMock(
isShadeOpen = false, isShadeOpen = false,
fullyVisible = false, fullyVisible = false,
headerVisibleAmount = 0f headerVisibleAmount = 0f,
) )
childHunView.viewState.yTranslation = 0f childHunView.viewState.yTranslation = 0f
// Shade is closed, thus childHunView's headerVisibleAmount is 0 // Shade is closed, thus childHunView's headerVisibleAmount is 0
@@ -622,7 +619,6 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
// When: updateChildZValue() is called for the top HUN // When: updateChildZValue() is called for the top HUN
stackScrollAlgorithm.updateChildZValue( stackScrollAlgorithm.updateChildZValue(
/* i= */ 0, /* i= */ 0,
/* childrenOnTop= */ 0.0f,
/* StackScrollAlgorithmState= */ algorithmState, /* StackScrollAlgorithmState= */ algorithmState,
/* ambientState= */ ambientState, /* ambientState= */ ambientState,
/* shouldElevateHun= */ true /* shouldElevateHun= */ true
@@ -642,7 +638,7 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
val childHunView = createHunViewMock( val childHunView = createHunViewMock(
isShadeOpen = false, isShadeOpen = false,
fullyVisible = false, fullyVisible = false,
headerVisibleAmount = 0.5f headerVisibleAmount = 0.5f,
) )
childHunView.viewState.yTranslation = 0f childHunView.viewState.yTranslation = 0f
// Shade is being opened, thus childHunView's headerVisibleAmount is between 0 and 1 // Shade is being opened, thus childHunView's headerVisibleAmount is between 0 and 1
@@ -654,7 +650,6 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
// When: updateChildZValue() is called for the top HUN // When: updateChildZValue() is called for the top HUN
stackScrollAlgorithm.updateChildZValue( stackScrollAlgorithm.updateChildZValue(
/* i= */ 0, /* i= */ 0,
/* childrenOnTop= */ 0.0f,
/* StackScrollAlgorithmState= */ algorithmState, /* StackScrollAlgorithmState= */ algorithmState,
/* ambientState= */ ambientState, /* ambientState= */ ambientState,
/* shouldElevateHun= */ true /* shouldElevateHun= */ true
@@ -669,7 +664,7 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
private fun createHunViewMock( private fun createHunViewMock(
isShadeOpen: Boolean, isShadeOpen: Boolean,
fullyVisible: Boolean, fullyVisible: Boolean,
headerVisibleAmount: Float headerVisibleAmount: Float,
) = ) =
mock<ExpandableNotificationRow>().apply { mock<ExpandableNotificationRow>().apply {
val childViewStateMock = createHunChildViewState(isShadeOpen, fullyVisible) val childViewStateMock = createHunChildViewState(isShadeOpen, fullyVisible)
@@ -680,7 +675,10 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
} }
private fun createHunChildViewState(isShadeOpen: Boolean, fullyVisible: Boolean) = private fun createHunChildViewState(
isShadeOpen: Boolean,
fullyVisible: Boolean,
) =
ExpandableViewState().apply { ExpandableViewState().apply {
// Mock the HUN's height with ambientState.topPadding + // Mock the HUN's height with ambientState.topPadding +
// ambientState.stackTranslation // ambientState.stackTranslation