• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.shade;
18 
19 import android.annotation.NonNull;
20 import android.graphics.Canvas;
21 import android.graphics.Color;
22 import android.graphics.ColorFilter;
23 import android.graphics.Paint;
24 import android.graphics.PixelFormat;
25 import android.graphics.drawable.Drawable;
26 
27 import com.android.keyguard.LockIconViewController;
28 import com.android.systemui.scene.shared.flag.SceneContainerFlag;
29 import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController;
30 
31 import java.util.HashSet;
32 import java.util.Set;
33 
34 /**
35  * Drawable for NotificationPanelViewController.
36  */
37 public class DebugDrawable extends Drawable {
38 
39     private final NotificationPanelViewController mNotificationPanelViewController;
40     private final NotificationPanelView mView;
41     private final NotificationStackScrollLayoutController mNotificationStackScrollLayoutController;
42     private final LockIconViewController mLockIconViewController;
43     private final QuickSettingsController mQsController;
44     private final Set<Integer> mDebugTextUsedYPositions;
45     private final Paint mDebugPaint;
46 
DebugDrawable( NotificationPanelViewController notificationPanelViewController, NotificationPanelView notificationPanelView, NotificationStackScrollLayoutController notificationStackScrollLayoutController, LockIconViewController lockIconViewController, QuickSettingsController quickSettingsController )47     public DebugDrawable(
48             NotificationPanelViewController notificationPanelViewController,
49             NotificationPanelView notificationPanelView,
50             NotificationStackScrollLayoutController notificationStackScrollLayoutController,
51             LockIconViewController lockIconViewController,
52             QuickSettingsController quickSettingsController
53     ) {
54         mNotificationPanelViewController = notificationPanelViewController;
55         mView = notificationPanelView;
56         mNotificationStackScrollLayoutController = notificationStackScrollLayoutController;
57         mLockIconViewController = lockIconViewController;
58         mQsController = quickSettingsController;
59         mDebugTextUsedYPositions = new HashSet<>();
60         mDebugPaint = new Paint();
61     }
62 
63     @Override
draw(@ndroidx.annotation.NonNull @onNull Canvas canvas)64     public void draw(@androidx.annotation.NonNull @NonNull Canvas canvas) {
65         mDebugTextUsedYPositions.clear();
66 
67         mDebugPaint.setColor(Color.RED);
68         mDebugPaint.setStrokeWidth(2);
69         mDebugPaint.setStyle(Paint.Style.STROKE);
70         mDebugPaint.setTextSize(24);
71 
72         drawDebugInfo(canvas, mNotificationPanelViewController.getMaxPanelHeight(),
73                 Color.RED, "getMaxPanelHeight()");
74         drawDebugInfo(canvas, (int) mNotificationPanelViewController.getExpandedHeight(),
75                 Color.BLUE, "getExpandedHeight()");
76         drawDebugInfo(canvas, mQsController.calculatePanelHeightExpanded(
77                         mNotificationPanelViewController.getClockPositionResult()
78                                 .stackScrollerPadding),
79                 Color.GREEN, "calculatePanelHeightQsExpanded()");
80         drawDebugInfo(canvas, mQsController.calculatePanelHeightExpanded(
81                         mNotificationPanelViewController.getClockPositionResult()
82                                 .stackScrollerPadding),
83                 Color.YELLOW, "calculatePanelHeightShade()");
84         if (!SceneContainerFlag.isEnabled()) {
85             drawDebugInfo(canvas,
86                     (int) mQsController.calculateNotificationsTopPadding(
87                             mNotificationPanelViewController.isExpandingOrCollapsing(),
88                             mNotificationPanelViewController.getKeyguardNotificationStaticPadding(),
89                             mNotificationPanelViewController.getExpandedFraction()),
90                     Color.MAGENTA, "calculateNotificationsTopPadding()");
91         }
92         drawDebugInfo(canvas, mNotificationPanelViewController.getClockPositionResult().clockY,
93                 Color.GRAY, "mClockPositionResult.clockY");
94         drawDebugInfo(canvas, (int) mLockIconViewController.getTop(), Color.GRAY,
95                 "mLockIconViewController.getTop()");
96 
97         if (mNotificationPanelViewController.isKeyguardShowing()) {
98             // Notifications have the space between those two lines.
99             drawDebugInfo(canvas,
100                     mNotificationStackScrollLayoutController.getTop()
101                             + (int) mNotificationPanelViewController
102                             .getKeyguardNotificationTopPadding(),
103                     Color.RED, "NSSL.getTop() + mKeyguardNotificationTopPadding");
104 
105             drawDebugInfo(canvas, mNotificationStackScrollLayoutController.getBottom()
106                             - (int) mNotificationPanelViewController
107                             .getKeyguardNotificationBottomPadding(),
108                     Color.RED, "NSSL.getBottom() - mKeyguardNotificationBottomPadding");
109         }
110 
111         mDebugPaint.setColor(Color.CYAN);
112         canvas.drawLine(0,
113                 mNotificationPanelViewController.getClockPositionResult().stackScrollerPadding,
114                 mView.getWidth(), mNotificationStackScrollLayoutController.getTopPadding(),
115                 mDebugPaint);
116     }
117 
drawDebugInfo(Canvas canvas, int y, int color, String label)118     private void drawDebugInfo(Canvas canvas, int y, int color, String label) {
119         mDebugPaint.setColor(color);
120         canvas.drawLine(/* startX= */ 0, /* startY= */ y, /* stopX= */ mView.getWidth(),
121                 /* stopY= */ y, mDebugPaint);
122         canvas.drawText(label + " = " + y + "px", /* x= */ 0,
123                 /* y= */ computeDebugYTextPosition(y), mDebugPaint);
124     }
125 
computeDebugYTextPosition(int lineY)126     private int computeDebugYTextPosition(int lineY) {
127         if (lineY - mDebugPaint.getTextSize() < 0) {
128             // Avoiding drawing out of bounds
129             lineY += mDebugPaint.getTextSize();
130         }
131         int textY = lineY;
132         while (mDebugTextUsedYPositions.contains(textY)) {
133             textY = (int) (textY + mDebugPaint.getTextSize());
134         }
135         mDebugTextUsedYPositions.add(textY);
136         return textY;
137     }
138 
139     @Override
setAlpha(int alpha)140     public void setAlpha(int alpha) {
141 
142     }
143 
144     @Override
setColorFilter(ColorFilter colorFilter)145     public void setColorFilter(ColorFilter colorFilter) {
146 
147     }
148 
149     @Override
getOpacity()150     public int getOpacity() {
151         return PixelFormat.UNKNOWN;
152     }
153 }
154