From 85232a91bf7928fc6ddd6b9115b3e62d2817c33f Mon Sep 17 00:00:00 2001 From: Pinyao Ting Date: Tue, 14 Dec 2021 04:36:01 +0000 Subject: [PATCH] Avoid drawing the first frame in launcher before animation completes Currently Launcher reports the drawing of the first frame before the fade-in animation runs to a completion. This CL pauses the pre-draw until the animation concludes so that the performance metrics matches what user actually sees. Bug: 210527498 Test: 1) reboot verify things works 2) sign in to second user, verify things works. Change-Id: I0146c0408005c3de75098b9401089ed2bcbcb6d6 --- src/com/android/launcher3/Launcher.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 801a31d1eb..7abdef866b 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -106,6 +106,7 @@ import android.view.Menu; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.view.WindowManager.LayoutParams; import android.view.accessibility.AccessibilityEvent; import android.view.animation.OvershootInterpolator; @@ -503,6 +504,23 @@ public class Launcher extends StatefulActivity implements Launche setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); setContentView(getRootView()); + getRootView().getViewTreeObserver().addOnPreDrawListener( + new ViewTreeObserver.OnPreDrawListener() { + @Override + public boolean onPreDraw() { + // Checks the status of fade in animation. + final AlphaProperty property = + mDragLayer.getAlphaProperty(ALPHA_INDEX_LAUNCHER_LOAD); + if (property.getValue() == 0) { + // Animation haven't started yet; suspend. + return false; + } else { + // The animation is started; start drawing. + getRootView().getViewTreeObserver().removeOnPreDrawListener(this); + return true; + } + } + }); getRootView().dispatchInsets(); // Listen for broadcasts