From 76ca5b9d43e7071d024c9e091c99b06a69a6fc75 Mon Sep 17 00:00:00 2001 From: Michal Brzezinski Date: Thu, 18 Apr 2024 11:47:37 +0100 Subject: Fixing radius of notification focus overlay Focus overlay doesn't fully cover corners of notification background it's is peeking from beneath. It's caused by using stroke instead of filling with color - notification background drawable is layer drawable with all shapes being the same but when shape (as Path object) is drawn using stroke, stroke is centered on the path. That means drawable is bigger by stroke width / 2 and when it's fitted inside NotificationBackgroundView it needs to be scaled down. That changes radius shape and radius needs to be decreased to account for that. Fixes: 329250144 Flag: None Test: focus on notification and see notification background corners are not going outside of focus overaly Change-Id: Ib8948bc9559bf2598af63185bcd14f073e39bfa7 --- .../res/drawable/notification_material_bg.xml | 5 +++-- packages/SystemUI/res/values/dimens.xml | 3 +++ .../row/NotificationBackgroundView.java | 25 ++++++++++++++++++---- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/res/drawable/notification_material_bg.xml b/packages/SystemUI/res/drawable/notification_material_bg.xml index 587a5a05458f..715be074eaa8 100644 --- a/packages/SystemUI/res/drawable/notification_material_bg.xml +++ b/packages/SystemUI/res/drawable/notification_material_bg.xml @@ -28,9 +28,10 @@ - + - + \ No newline at end of file diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 26fa2b136ed4..07604d5d0ebd 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -310,6 +310,9 @@ 28dp + + 3dp + 48dp diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationBackgroundView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationBackgroundView.java index ed3a38d3305b..d0db5145e0ff 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationBackgroundView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationBackgroundView.java @@ -53,6 +53,8 @@ public class NotificationBackgroundView extends View implements Dumpable { private int mTintColor; @Nullable private Integer mRippleColor; private final float[] mCornerRadii = new float[8]; + private final float[] mFocusOverlayCornerRadii = new float[8]; + private float mFocusOverlayStroke = 0; private boolean mBottomIsRounded; private boolean mBottomAmountClips = true; private int mActualHeight = -1; @@ -74,6 +76,7 @@ public class NotificationBackgroundView extends View implements Dumpable { R.color.notification_state_color_dark); mNormalColor = Utils.getColorAttrDefaultColor(mContext, com.android.internal.R.attr.materialColorSurfaceContainerHigh); + mFocusOverlayStroke = getResources().getDimension(R.dimen.notification_focus_stroke_width); } @Override @@ -290,14 +293,28 @@ public class NotificationBackgroundView extends View implements Dumpable { if (mDontModifyCorners) { return; } - if (mBackground instanceof LayerDrawable) { - int numberOfLayers = ((LayerDrawable) mBackground).getNumberOfLayers(); + if (mBackground instanceof LayerDrawable layerDrawable) { + int numberOfLayers = layerDrawable.getNumberOfLayers(); for (int i = 0; i < numberOfLayers; i++) { - GradientDrawable gradientDrawable = - (GradientDrawable) ((LayerDrawable) mBackground).getDrawable(i); + GradientDrawable gradientDrawable = (GradientDrawable) layerDrawable.getDrawable(i); gradientDrawable.setCornerRadii(mCornerRadii); } + updateFocusOverlayRadii(layerDrawable); + } + } + + private void updateFocusOverlayRadii(LayerDrawable background) { + GradientDrawable overlay = + (GradientDrawable) background.findDrawableByLayerId( + R.id.notification_focus_overlay); + for (int i = 0; i < mCornerRadii.length; i++) { + // in theory subtracting mFocusOverlayStroke/2 should be enough but notification + // background is still peeking a bit from below - probably due to antialiasing or + // overlay uneven scaling. So let's subtract full mFocusOverlayStroke to make sure the + // radius is a bit smaller and covers background corners fully + mFocusOverlayCornerRadii[i] = Math.max(0, mCornerRadii[i] - mFocusOverlayStroke); } + overlay.setCornerRadii(mFocusOverlayCornerRadii); } /** Set the current expand animation size. */ -- cgit v1.2.3-59-g8ed1b