diff --git a/packages/SystemUI/src/com/android/systemui/shade/DebugDrawable.java b/packages/SystemUI/src/com/android/systemui/shade/DebugDrawable.java new file mode 100644 index 0000000000000..ae303eb6d2039 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/shade/DebugDrawable.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.shade; + +import android.annotation.NonNull; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.ColorFilter; +import android.graphics.Paint; +import android.graphics.PixelFormat; +import android.graphics.drawable.Drawable; + +import com.android.keyguard.LockIconViewController; +import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController; + +import java.util.HashSet; +import java.util.Set; + +/** + * Drawable for NotificationPanelViewController. + */ +public class DebugDrawable extends Drawable { + + private final NotificationPanelViewController mNotificationPanelViewController; + private final NotificationPanelView mView; + private final NotificationStackScrollLayoutController mNotificationStackScrollLayoutController; + private final LockIconViewController mLockIconViewController; + private final Set mDebugTextUsedYPositions; + private final Paint mDebugPaint; + + public DebugDrawable( + NotificationPanelViewController notificationPanelViewController, + NotificationPanelView notificationPanelView, + NotificationStackScrollLayoutController notificationStackScrollLayoutController, + LockIconViewController lockIconViewController + ) { + mNotificationPanelViewController = notificationPanelViewController; + mView = notificationPanelView; + mNotificationStackScrollLayoutController = notificationStackScrollLayoutController; + mLockIconViewController = lockIconViewController; + mDebugTextUsedYPositions = new HashSet<>(); + mDebugPaint = new Paint(); + } + + @Override + public void draw(@androidx.annotation.NonNull @NonNull Canvas canvas) { + mDebugTextUsedYPositions.clear(); + + mDebugPaint.setColor(Color.RED); + mDebugPaint.setStrokeWidth(2); + mDebugPaint.setStyle(Paint.Style.STROKE); + mDebugPaint.setTextSize(24); + String headerDebugInfo = mNotificationPanelViewController.getHeaderDebugInfo(); + if (headerDebugInfo != null) canvas.drawText(headerDebugInfo, 50, 100, mDebugPaint); + + drawDebugInfo(canvas, mNotificationPanelViewController.getMaxPanelHeight(), + Color.RED, "getMaxPanelHeight()"); + drawDebugInfo(canvas, (int) mNotificationPanelViewController.getExpandedHeight(), + Color.BLUE, "getExpandedHeight()"); + drawDebugInfo(canvas, mNotificationPanelViewController.calculatePanelHeightQsExpanded(), + Color.GREEN, "calculatePanelHeightQsExpanded()"); + drawDebugInfo(canvas, mNotificationPanelViewController.calculatePanelHeightQsExpanded(), + Color.YELLOW, "calculatePanelHeightShade()"); + drawDebugInfo(canvas, + (int) mNotificationPanelViewController.calculateNotificationsTopPadding(), + Color.MAGENTA, "calculateNotificationsTopPadding()"); + drawDebugInfo(canvas, mNotificationPanelViewController.getClockPositionResult().clockY, + Color.GRAY, "mClockPositionResult.clockY"); + drawDebugInfo(canvas, (int) mLockIconViewController.getTop(), Color.GRAY, + "mLockIconViewController.getTop()"); + + if (mNotificationPanelViewController.getKeyguardShowing()) { + // Notifications have the space between those two lines. + drawDebugInfo(canvas, + mNotificationStackScrollLayoutController.getTop() + + (int) mNotificationPanelViewController + .getKeyguardNotificationTopPadding(), + Color.RED, "NSSL.getTop() + mKeyguardNotificationTopPadding"); + + drawDebugInfo(canvas, mNotificationStackScrollLayoutController.getBottom() + - (int) mNotificationPanelViewController + .getKeyguardNotificationBottomPadding(), + Color.RED, "NSSL.getBottom() - mKeyguardNotificationBottomPadding"); + } + + mDebugPaint.setColor(Color.CYAN); + canvas.drawLine(0, + mNotificationPanelViewController.getClockPositionResult().stackScrollerPadding, + mView.getWidth(), mNotificationStackScrollLayoutController.getTopPadding(), + mDebugPaint); + } + + private void drawDebugInfo(Canvas canvas, int y, int color, String label) { + mDebugPaint.setColor(color); + canvas.drawLine(/* startX= */ 0, /* startY= */ y, /* stopX= */ mView.getWidth(), + /* stopY= */ y, mDebugPaint); + canvas.drawText(label + " = " + y + "px", /* x= */ 0, + /* y= */ computeDebugYTextPosition(y), mDebugPaint); + } + + private int computeDebugYTextPosition(int lineY) { + if (lineY - mDebugPaint.getTextSize() < 0) { + // Avoiding drawing out of bounds + lineY += mDebugPaint.getTextSize(); + } + int textY = lineY; + while (mDebugTextUsedYPositions.contains(textY)) { + textY = (int) (textY + mDebugPaint.getTextSize()); + } + mDebugTextUsedYPositions.add(textY); + return textY; + } + + @Override + public void setAlpha(int alpha) { + + } + + @Override + public void setColorFilter(ColorFilter colorFilter) { + + } + + @Override + public int getOpacity() { + return PixelFormat.UNKNOWN; + } +} diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java index cc6c703757264..b8c4b3e36218f 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java @@ -56,15 +56,10 @@ import android.app.StatusBarManager; import android.content.ContentResolver; import android.content.res.Resources; import android.database.ContentObserver; -import android.graphics.Canvas; import android.graphics.Color; -import android.graphics.ColorFilter; import android.graphics.Insets; -import android.graphics.Paint; -import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.Region; -import android.graphics.drawable.Drawable; import android.hardware.biometrics.SensorLocationInternal; import android.hardware.fingerprint.FingerprintSensorPropertiesInternal; import android.os.Bundle; @@ -229,10 +224,8 @@ import com.android.wm.shell.animation.FlingAnimationUtils; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Optional; -import java.util.Set; import java.util.function.Consumer; import javax.inject.Inject; @@ -899,7 +892,8 @@ public final class NotificationPanelViewController { mView.setOnApplyWindowInsetsListener((v, insets) -> onApplyShadeWindowInsets(insets)); if (DEBUG_DRAWABLE) { - mView.getOverlay().add(new DebugDrawable()); + mView.getOverlay().add(new DebugDrawable(this, mView, + mNotificationStackScrollLayoutController, mLockIconViewController)); } mKeyguardUnfoldTransition = unfoldComponent.map( @@ -1512,6 +1506,10 @@ public final class NotificationPanelViewController { updateClock(); } + public KeyguardClockPositionAlgorithm.Result getClockPositionResult() { + return mClockPositionResult; + } + @ClockSize private int computeDesiredClockSize() { if (mSplitShadeEnabled) { @@ -2976,7 +2974,7 @@ public final class NotificationPanelViewController { } } - private float calculateNotificationsTopPadding() { + float calculateNotificationsTopPadding() { if (mSplitShadeEnabled) { return mKeyguardShowing ? getKeyguardNotificationStaticPadding() : 0; } @@ -3010,6 +3008,18 @@ public final class NotificationPanelViewController { } } + public boolean getKeyguardShowing() { + return mKeyguardShowing; + } + + public float getKeyguardNotificationTopPadding() { + return mKeyguardNotificationTopPadding; + } + + public float getKeyguardNotificationBottomPadding() { + return mKeyguardNotificationBottomPadding; + } + /** Returns the topPadding of notifications when on keyguard not respecting QS expansion. */ private int getKeyguardNotificationStaticPadding() { if (!mKeyguardShowing) { @@ -3279,7 +3289,6 @@ public final class NotificationPanelViewController { return !mSplitShadeEnabled && (isInSettings() || mIsPanelCollapseOnQQS); } - @VisibleForTesting int getMaxPanelHeight() { int min = mStatusBarMinHeight; if (!(mBarState == KEYGUARD) @@ -3405,7 +3414,7 @@ public final class NotificationPanelViewController { } } - private int calculatePanelHeightQsExpanded() { + int calculatePanelHeightQsExpanded() { float notificationHeight = mNotificationStackScrollLayoutController.getHeight() @@ -4369,6 +4378,10 @@ public final class NotificationPanelViewController { if (DEBUG_DRAWABLE) mHeaderDebugInfo = text; } + public String getHeaderDebugInfo() { + return mHeaderDebugInfo; + } + public void onThemeChanged() { mConfigurationListener.onThemeChanged(); } @@ -4818,7 +4831,6 @@ public final class NotificationPanelViewController { setExpandedHeight(getMaxPanelTransitionDistance() * frac); } - @VisibleForTesting float getExpandedHeight() { return mExpandedHeight; } @@ -5520,89 +5532,6 @@ public final class NotificationPanelViewController { } } - private final class DebugDrawable extends Drawable { - private final Set mDebugTextUsedYPositions = new HashSet<>(); - private final Paint mDebugPaint = new Paint(); - - @Override - public void draw(@NonNull Canvas canvas) { - mDebugTextUsedYPositions.clear(); - - mDebugPaint.setColor(Color.RED); - mDebugPaint.setStrokeWidth(2); - mDebugPaint.setStyle(Paint.Style.STROKE); - mDebugPaint.setTextSize(24); - if (mHeaderDebugInfo != null) canvas.drawText(mHeaderDebugInfo, 50, 100, mDebugPaint); - - drawDebugInfo(canvas, getMaxPanelHeight(), Color.RED, "getMaxPanelHeight()"); - drawDebugInfo(canvas, (int) getExpandedHeight(), Color.BLUE, "getExpandedHeight()"); - drawDebugInfo(canvas, calculatePanelHeightQsExpanded(), Color.GREEN, - "calculatePanelHeightQsExpanded()"); - drawDebugInfo(canvas, calculatePanelHeightShade(), Color.YELLOW, - "calculatePanelHeightShade()"); - drawDebugInfo(canvas, (int) calculateNotificationsTopPadding(), Color.MAGENTA, - "calculateNotificationsTopPadding()"); - drawDebugInfo(canvas, mClockPositionResult.clockY, Color.GRAY, - "mClockPositionResult.clockY"); - drawDebugInfo(canvas, (int) mLockIconViewController.getTop(), Color.GRAY, - "mLockIconViewController.getTop()"); - - if (mKeyguardShowing) { - // Notifications have the space between those two lines. - drawDebugInfo(canvas, - mNotificationStackScrollLayoutController.getTop() + - (int) mKeyguardNotificationTopPadding, - Color.RED, - "NSSL.getTop() + mKeyguardNotificationTopPadding"); - - drawDebugInfo(canvas, mNotificationStackScrollLayoutController.getBottom() - - (int) mKeyguardNotificationBottomPadding, - Color.RED, - "NSSL.getBottom() - mKeyguardNotificationBottomPadding"); - } - - mDebugPaint.setColor(Color.CYAN); - canvas.drawLine(0, mClockPositionResult.stackScrollerPadding, mView.getWidth(), - mNotificationStackScrollLayoutController.getTopPadding(), mDebugPaint); - } - - private void drawDebugInfo(Canvas canvas, int y, int color, String label) { - mDebugPaint.setColor(color); - canvas.drawLine(/* startX= */ 0, /* startY= */ y, /* stopX= */ mView.getWidth(), - /* stopY= */ y, mDebugPaint); - canvas.drawText(label + " = " + y + "px", /* x= */ 0, - /* y= */ computeDebugYTextPosition(y), mDebugPaint); - } - - private int computeDebugYTextPosition(int lineY) { - if (lineY - mDebugPaint.getTextSize() < 0) { - // Avoiding drawing out of bounds - lineY += mDebugPaint.getTextSize(); - } - int textY = lineY; - while (mDebugTextUsedYPositions.contains(textY)) { - textY = (int) (textY + mDebugPaint.getTextSize()); - } - mDebugTextUsedYPositions.add(textY); - return textY; - } - - @Override - public void setAlpha(int alpha) { - - } - - @Override - public void setColorFilter(ColorFilter colorFilter) { - - } - - @Override - public int getOpacity() { - return PixelFormat.UNKNOWN; - } - } - @NonNull private WindowInsets onApplyShadeWindowInsets(WindowInsets insets) { // the same types of insets that are handled in NotificationShadeWindowView