Merge "Improving scrim debugging"

This commit is contained in:
Michał Brzeziński
2022-02-08 11:50:58 +00:00
committed by Android (Google) Code Review
2 changed files with 25 additions and 10 deletions

View File

@@ -79,6 +79,13 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, Dump
static final String TAG = "ScrimController";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
// debug mode colors scrims with below debug colors, irrespectively of which state they're in
public static final boolean DEBUG_MODE = false;
public static final int DEBUG_NOTIFICATIONS_TINT = Color.RED;
public static final int DEBUG_FRONT_TINT = Color.GREEN;
public static final int DEBUG_BEHIND_TINT = Color.BLUE;
/**
* General scrim animation duration.
*/
@@ -994,6 +1001,9 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, Dump
alpha = Math.max(0, Math.min(1.0f, alpha));
if (scrim instanceof ScrimView) {
ScrimView scrimView = (ScrimView) scrim;
if (DEBUG_MODE) {
tint = getDebugScrimTint(scrimView);
}
Trace.traceCounter(Trace.TRACE_TAG_APP, getScrimName(scrimView) + "_alpha",
(int) (alpha * 255));
@@ -1008,6 +1018,13 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, Dump
dispatchScrimsVisible();
}
private int getDebugScrimTint(ScrimView scrim) {
if (scrim == mScrimBehind) return DEBUG_BEHIND_TINT;
if (scrim == mScrimInFront) return DEBUG_FRONT_TINT;
if (scrim == mNotificationsScrim) return DEBUG_NOTIFICATIONS_TINT;
throw new RuntimeException("scrim can't be matched with known scrims");
}
private void startScrimAnimation(final View scrim, float current) {
ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
if (mAnimatorListener != null) {

View File

@@ -153,7 +153,7 @@ public enum ScrimState {
// to make sure correct color is returned before "prepare" is called
@Override
public int getBehindTint() {
return DEBUG_MODE ? DEBUG_BEHIND_TINT : Color.BLACK;
return Color.BLACK;
}
},
@@ -264,12 +264,6 @@ public enum ScrimState {
}
};
private static final boolean DEBUG_MODE = false;
private static final int DEBUG_NOTIFICATIONS_TINT = Color.RED;
private static final int DEBUG_FRONT_TINT = Color.GREEN;
private static final int DEBUG_BEHIND_TINT = Color.BLUE;
boolean mBlankScreen = false;
long mAnimationDuration = ScrimController.ANIMATION_DURATION;
int mFrontTint = Color.TRANSPARENT;
@@ -329,15 +323,15 @@ public enum ScrimState {
}
public int getFrontTint() {
return DEBUG_MODE ? DEBUG_FRONT_TINT : mFrontTint;
return mFrontTint;
}
public int getBehindTint() {
return DEBUG_MODE ? DEBUG_BEHIND_TINT : mBehindTint;
return mBehindTint;
}
public int getNotifTint() {
return DEBUG_MODE ? DEBUG_NOTIFICATIONS_TINT : mNotifTint;
return mNotifTint;
}
public long getAnimationDuration() {
@@ -349,6 +343,10 @@ public enum ScrimState {
}
public void updateScrimColor(ScrimView scrim, float alpha, int tint) {
if (ScrimController.DEBUG_MODE) {
tint = scrim == mScrimInFront ? ScrimController.DEBUG_FRONT_TINT
: ScrimController.DEBUG_BEHIND_TINT;
}
Trace.traceCounter(Trace.TRACE_TAG_APP,
scrim == mScrimInFront ? "front_scrim_alpha" : "back_scrim_alpha",
(int) (alpha * 255));