Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ebc3a62d authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge "Inflate UDFPS lottie views on a bg thread"

parents 7ad09828 8e595414
Loading
Loading
Loading
Loading
+1 −30
Original line number Diff line number Diff line
@@ -21,35 +21,6 @@
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Background protection -->
    <ImageView
        android:id="@+id/udfps_keyguard_fp_bg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/fingerprint_bg"/>

    <!-- Fingerprint -->
    <!-- AOD dashed fingerprint icon with moving dashes -->
    <com.airbnb.lottie.LottieAnimationView
        android:id="@+id/udfps_aod_fp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="@dimen/lock_icon_padding"
        android:layout_gravity="center"
        android:scaleType="centerCrop"
        app:lottie_autoPlay="false"
        app:lottie_loop="true"
        app:lottie_rawRes="@raw/udfps_aod_fp"/>
    <!-- Add fingerprint views here. See udfps_keyguard_view_internal.xml. -->

    <!-- LockScreen fingerprint icon from 0 stroke width to full width -->
    <com.airbnb.lottie.LottieAnimationView
        android:id="@+id/udfps_lockscreen_fp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="@dimen/lock_icon_padding"
        android:layout_gravity="center"
        android:scaleType="centerCrop"
        app:lottie_autoPlay="false"
        app:lottie_loop="false"
        app:lottie_rawRes="@raw/udfps_lockscreen_fp"/>
</com.android.systemui.biometrics.UdfpsKeyguardView>
+56 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ 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.
  -->

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/udfps_animation_view_internal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Background protection -->
    <ImageView
        android:id="@+id/udfps_keyguard_fp_bg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/fingerprint_bg"/>

    <!-- Fingerprint -->
    <!-- AOD dashed fingerprint icon with moving dashes -->
    <com.airbnb.lottie.LottieAnimationView
        android:id="@+id/udfps_aod_fp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="@dimen/lock_icon_padding"
        android:layout_gravity="center"
        android:scaleType="centerCrop"
        app:lottie_autoPlay="false"
        app:lottie_loop="true"
        app:lottie_rawRes="@raw/udfps_aod_fp"/>

    <!-- LockScreen fingerprint icon from 0 stroke width to full width -->
    <com.airbnb.lottie.LottieAnimationView
        android:id="@+id/udfps_lockscreen_fp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="@dimen/lock_icon_padding"
        android:layout_gravity="center"
        android:scaleType="centerCrop"
        app:lottie_autoPlay="false"
        app:lottie_loop="false"
        app:lottie_rawRes="@raw/udfps_lockscreen_fp"/>
</FrameLayout>
 No newline at end of file
+48 −17
Original line number Diff line number Diff line
@@ -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,12 +170,15 @@ public class UdfpsKeyguardView extends UdfpsAnimationView {
    @Override
    protected int updateAlpha() {
        int alpha = super.updateAlpha();
        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)
            );
        }
    };
}