Merge "Center EmptyShadeView vertically and horizontally." into sc-v2-dev

This commit is contained in:
Christian Göllner
2021-12-10 09:39:01 +00:00
committed by Android (Google) Code Review
5 changed files with 42 additions and 5 deletions

View File

@@ -26,8 +26,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minHeight="64dp" android:minHeight="64dp"
android:paddingTop="12dp"
android:textAppearance="?android:attr/textAppearanceButton" android:textAppearance="?android:attr/textAppearanceButton"
android:gravity="top|center_horizontal" android:gravity="center"
android:text="@string/empty_shade_text"/> android:text="@string/empty_shade_text"/>
</com.android.systemui.statusbar.EmptyShadeView> </com.android.systemui.statusbar.EmptyShadeView>

View File

@@ -59,6 +59,7 @@ public class AmbientState {
private float mMaxHeadsUpTranslation; private float mMaxHeadsUpTranslation;
private boolean mDismissAllInProgress; private boolean mDismissAllInProgress;
private int mLayoutMinHeight; private int mLayoutMinHeight;
private int mLayoutMaxHeight;
private NotificationShelf mShelf; private NotificationShelf mShelf;
private int mZDistanceBetweenElements; private int mZDistanceBetweenElements;
private int mBaseZHeight; private int mBaseZHeight;
@@ -326,6 +327,14 @@ public class AmbientState {
mLayoutHeight = layoutHeight; mLayoutHeight = layoutHeight;
} }
public void setLayoutMaxHeight(int maxLayoutHeight) {
mLayoutMaxHeight = maxLayoutHeight;
}
public int getLayoutMaxHeight() {
return mLayoutMaxHeight;
}
public float getTopPadding() { public float getTopPadding() {
return mTopPadding; return mTopPadding;
} }

View File

@@ -1110,6 +1110,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
@ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM) @ShadeViewRefactor(RefactorComponent.LAYOUT_ALGORITHM)
private void updateAlgorithmHeightAndPadding() { private void updateAlgorithmHeightAndPadding() {
mAmbientState.setLayoutHeight(getLayoutHeight()); mAmbientState.setLayoutHeight(getLayoutHeight());
mAmbientState.setLayoutMaxHeight(mMaxLayoutHeight);
updateAlgorithmLayoutMinHeight(); updateAlgorithmLayoutMinHeight();
mAmbientState.setTopPadding(mTopPadding); mAmbientState.setTopPadding(mTopPadding);
} }

View File

@@ -29,6 +29,7 @@ import androidx.annotation.VisibleForTesting;
import com.android.internal.policy.SystemBarUtils; import com.android.internal.policy.SystemBarUtils;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.animation.ShadeInterpolation; import com.android.systemui.animation.ShadeInterpolation;
import com.android.systemui.statusbar.EmptyShadeView;
import com.android.systemui.statusbar.NotificationShelf; import com.android.systemui.statusbar.NotificationShelf;
import com.android.systemui.statusbar.notification.row.ActivatableNotificationView; import com.android.systemui.statusbar.notification.row.ActivatableNotificationView;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
@@ -60,6 +61,7 @@ public class StackScrollAlgorithm {
@VisibleForTesting float mHeadsUpInset; @VisibleForTesting float mHeadsUpInset;
private int mPinnedZTranslationExtra; private int mPinnedZTranslationExtra;
private float mNotificationScrimPadding; private float mNotificationScrimPadding;
private int mCloseHandleUnderlapHeight;
public StackScrollAlgorithm( public StackScrollAlgorithm(
Context context, Context context,
@@ -85,6 +87,7 @@ public class StackScrollAlgorithm {
R.dimen.heads_up_pinned_elevation); R.dimen.heads_up_pinned_elevation);
mGapHeight = res.getDimensionPixelSize(R.dimen.notification_section_divider_height); mGapHeight = res.getDimensionPixelSize(R.dimen.notification_section_divider_height);
mNotificationScrimPadding = res.getDimensionPixelSize(R.dimen.notification_side_paddings); mNotificationScrimPadding = res.getDimensionPixelSize(R.dimen.notification_side_paddings);
mCloseHandleUnderlapHeight = res.getDimensionPixelSize(R.dimen.close_handle_underlap);
} }
/** /**
@@ -459,13 +462,17 @@ public class StackScrollAlgorithm {
&& !hasOngoingNotifs(algorithmState)); && !hasOngoingNotifs(algorithmState));
} }
} else { } else {
if (view != ambientState.getTrackedHeadsUpRow()) { if (view instanceof EmptyShadeView) {
float fullHeight = ambientState.getLayoutMaxHeight() + mCloseHandleUnderlapHeight
- ambientState.getStackY();
viewState.yTranslation = (fullHeight - getMaxAllowedChildHeight(view)) / 2f;
} else if (view != ambientState.getTrackedHeadsUpRow()) {
if (ambientState.isExpansionChanging()) { if (ambientState.isExpansionChanging()) {
// We later update shelf state, then hide views below the shelf. // We later update shelf state, then hide views below the shelf.
viewState.hidden = false; viewState.hidden = false;
viewState.inShelf = algorithmState.firstViewInShelf != null viewState.inShelf = algorithmState.firstViewInShelf != null
&& i >= algorithmState.visibleChildren.indexOf( && i >= algorithmState.visibleChildren.indexOf(
algorithmState.firstViewInShelf); algorithmState.firstViewInShelf);
} else if (ambientState.getShelf() != null) { } else if (ambientState.getShelf() != null) {
// When pulsing (incoming notification on AOD), innerHeight is 0; clamp all // When pulsing (incoming notification on AOD), innerHeight is 0; clamp all
// to shelf start, thereby hiding all notifications (except the first one, which // to shelf start, thereby hiding all notifications (except the first one, which

View File

@@ -4,6 +4,7 @@ import android.widget.FrameLayout
import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest
import com.android.systemui.R import com.android.systemui.R
import com.android.systemui.SysuiTestCase import com.android.systemui.SysuiTestCase
import com.android.systemui.statusbar.EmptyShadeView
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm.BypassController import com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm.BypassController
import com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm.SectionProvider import com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm.SectionProvider
@@ -55,4 +56,24 @@ class StackScrollAlgorithmTest : SysuiTestCase() {
// top margin presence should decrease heads up translation up to minHeadsUpTranslation // top margin presence should decrease heads up translation up to minHeadsUpTranslation
assertThat(expandableViewState.yTranslation).isEqualTo(minHeadsUpTranslation) assertThat(expandableViewState.yTranslation).isEqualTo(minHeadsUpTranslation)
} }
}
@Test
fun resetViewStates_childIsEmptyShadeView_viewIsCenteredVertically() {
stackScrollAlgorithm.initView(context)
val emptyShadeView = EmptyShadeView(context, /* attrs= */ null).apply {
layout(/* l= */ 0, /* t= */ 0, /* r= */ 100, /* b= */ 100)
}
hostView.removeAllViews()
hostView.addView(emptyShadeView)
ambientState.layoutMaxHeight = 1280
stackScrollAlgorithm.resetViewStates(ambientState, /* speedBumpIndex= */ 0)
val closeHandleUnderlapHeight =
context.resources.getDimensionPixelSize(R.dimen.close_handle_underlap)
val fullHeight =
ambientState.layoutMaxHeight + closeHandleUnderlapHeight - ambientState.stackY
val centeredY = ambientState.stackY + fullHeight / 2f - emptyShadeView.height / 2f
assertThat(emptyShadeView.viewState?.yTranslation).isEqualTo(centeredY)
}
}