From 8e595414b5dd3dfb9e396aa115a4e1ecd2fd3014 Mon Sep 17 00:00:00 2001 From: Beverly Date: Thu, 3 Feb 2022 21:30:26 +0000 Subject: [PATCH] Inflate UDFPS lottie views on a bg thread So the main thread won't be blocked if the inflation takes a while. Test: manual Fixes: 217192991 Change-Id: Iddf1e71faf6486fd9f936a7de5b619050a977c27 --- .../res/layout/udfps_keyguard_view.xml | 31 +-------- .../layout/udfps_keyguard_view_internal.xml | 56 ++++++++++++++++ .../biometrics/UdfpsKeyguardView.java | 65 ++++++++++++++----- 3 files changed, 105 insertions(+), 47 deletions(-) create mode 100644 packages/SystemUI/res/layout/udfps_keyguard_view_internal.xml diff --git a/packages/SystemUI/res/layout/udfps_keyguard_view.xml b/packages/SystemUI/res/layout/udfps_keyguard_view.xml index a9eb27ad3b029..ee4fbaadc5c8a 100644 --- a/packages/SystemUI/res/layout/udfps_keyguard_view.xml +++ b/packages/SystemUI/res/layout/udfps_keyguard_view.xml @@ -21,35 +21,6 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - + - - - - - - diff --git a/packages/SystemUI/res/layout/udfps_keyguard_view_internal.xml b/packages/SystemUI/res/layout/udfps_keyguard_view_internal.xml new file mode 100644 index 0000000000000..6d52a30be7b4d --- /dev/null +++ b/packages/SystemUI/res/layout/udfps_keyguard_view_internal.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardView.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardView.java index 9015396d26ab8..7204a15233b00 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardView.java @@ -29,9 +29,11 @@ import android.graphics.PorterDuffColorFilter; import android.util.AttributeSet; import android.util.MathUtils; import android.view.View; +import android.view.ViewGroup; import android.widget.ImageView; import androidx.annotation.Nullable; +import androidx.asynclayoutinflater.view.AsyncLayoutInflater; import com.android.settingslib.Utils; import com.android.systemui.R; @@ -66,6 +68,7 @@ public class UdfpsKeyguardView extends UdfpsAnimationView { private float mBurnInOffsetY; private float mBurnInProgress; private float mInterpolatedDarkAmount; + private boolean mFullyInflated; public UdfpsKeyguardView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); @@ -80,17 +83,11 @@ public class UdfpsKeyguardView extends UdfpsAnimationView { @Override protected void onFinishInflate() { super.onFinishInflate(); - mAodFp = findViewById(R.id.udfps_aod_fp); - mLockScreenFp = findViewById(R.id.udfps_lockscreen_fp); - mBgProtection = findViewById(R.id.udfps_keyguard_fp_bg); - updateColor(); - - // requires call to invalidate to update the color - mLockScreenFp.addValueCallback( - new KeyPath("**"), LottieProperty.COLOR_FILTER, - frameInfo -> new PorterDuffColorFilter(mTextColorPrimary, PorterDuff.Mode.SRC_ATOP) - ); + // inflate Lottie views on a background thread in case it takes a while to inflate + AsyncLayoutInflater inflater = new AsyncLayoutInflater(mContext); + inflater.inflate(R.layout.udfps_keyguard_view_internal, this, + mLayoutInflaterFinishListener); } @Override @@ -113,6 +110,10 @@ public class UdfpsKeyguardView extends UdfpsAnimationView { } private void updateBurnInOffsets() { + if (!mFullyInflated) { + return; + } + mBurnInOffsetX = MathUtils.lerp(0f, getBurnInOffset(mMaxBurnInOffsetX * 2, true /* xAxis */) - mMaxBurnInOffsetX, mInterpolatedDarkAmount); @@ -141,6 +142,10 @@ public class UdfpsKeyguardView extends UdfpsAnimationView { } void updateColor() { + if (!mFullyInflated) { + return; + } + mTextColorPrimary = Utils.getColorAttrDefaultColor(mContext, android.R.attr.textColorPrimary); mBgProtection.setImageDrawable(getContext().getDrawable(R.drawable.fingerprint_bg)); @@ -165,13 +170,16 @@ public class UdfpsKeyguardView extends UdfpsAnimationView { @Override protected int updateAlpha() { int alpha = super.updateAlpha(); - mLockScreenFp.setAlpha(alpha / 255f); - if (mInterpolatedDarkAmount != 0f) { - mBgProtection.setAlpha(1f - mInterpolatedDarkAmount); - } else { - mBgProtection.setAlpha(alpha / 255f); + if (mFullyInflated) { + mLockScreenFp.setAlpha(alpha / 255f); + if (mInterpolatedDarkAmount != 0f) { + mBgProtection.setAlpha(1f - mInterpolatedDarkAmount); + } else { + mBgProtection.setAlpha(alpha / 255f); + } } + return alpha; } @@ -193,8 +201,8 @@ public class UdfpsKeyguardView extends UdfpsAnimationView { * Animates in the bg protection circle behind the fp icon to highlight the icon. */ void animateInUdfpsBouncer(Runnable onEndAnimation) { - if (mBackgroundInAnimator.isRunning()) { - // already animating in + if (mBackgroundInAnimator.isRunning() || !mFullyInflated) { + // already animating in or not yet inflated return; } @@ -220,4 +228,27 @@ public class UdfpsKeyguardView extends UdfpsAnimationView { private boolean isShadeLocked() { return mStatusBarState == StatusBarState.SHADE_LOCKED; } + + private final AsyncLayoutInflater.OnInflateFinishedListener mLayoutInflaterFinishListener = + new AsyncLayoutInflater.OnInflateFinishedListener() { + @Override + public void onInflateFinished(View view, int resid, ViewGroup parent) { + mFullyInflated = true; + parent.addView(view); + mAodFp = findViewById(R.id.udfps_aod_fp); + mLockScreenFp = findViewById(R.id.udfps_lockscreen_fp); + mBgProtection = findViewById(R.id.udfps_keyguard_fp_bg); + + updateBurnInOffsets(); + updateColor(); + updateAlpha(); + + // requires call to invalidate to update the color + mLockScreenFp.addValueCallback( + new KeyPath("**"), LottieProperty.COLOR_FILTER, + frameInfo -> new PorterDuffColorFilter(mTextColorPrimary, + PorterDuff.Mode.SRC_ATOP) + ); + } + }; }