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

Commit 26c69998 authored by Kevin Chyn's avatar Kevin Chyn
Browse files

Animate last section of progress when ACQUIRED_GOOD

Bug: 187460696
Test: manual
Change-Id: Ie6aed9d737c470414a827503ddd88c1fbed2d345
parent 2e813eb8
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -211,6 +211,12 @@ public class UdfpsController implements DozeReceiver {
            }
        }

        void onAcquiredGood() {
            if (mEnrollHelper != null) {
                mEnrollHelper.animateIfLastStep();
            }
        }

        void onEnrollmentHelp() {
            if (mEnrollHelper != null) {
                mEnrollHelper.onEnrollmentHelp();
@@ -260,6 +266,11 @@ public class UdfpsController implements DozeReceiver {
                }
                mGoodCaptureReceived = true;
                mView.stopIllumination();
                if (mServerRequest != null) {
                    mServerRequest.onAcquiredGood();
                } else {
                    Log.e(TAG, "Null serverRequest when onAcquiredGood");
                }
            });
        }

+4 −0
Original line number Diff line number Diff line
@@ -146,6 +146,10 @@ public class UdfpsEnrollDrawable extends UdfpsDrawable {
        }
    }

    void onLastStepAcquired() {
        mProgressDrawable.onLastStepAcquired();
    }

    @Override
    public void draw(@NonNull Canvas canvas) {
        mProgressDrawable.draw(canvas);
+12 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ public class UdfpsEnrollHelper {

    interface Listener {
        void onEnrollmentProgress(int remaining, int totalSteps);
        void onLastStepAcquired();
    }

    @NonNull private final Context mContext;
@@ -178,4 +179,15 @@ public class UdfpsEnrollHelper {
                .get(index % mGuidedEnrollmentPoints.size());
        return new PointF(originalPoint.x * scale, originalPoint.y * scale);
    }

    void animateIfLastStep() {
        if (mListener == null) {
            Log.e(TAG, "animateIfLastStep, null listener");
            return;
        }

        if (mRemainingSteps <= 2 && mRemainingSteps >= 0) {
            mListener.onLastStepAcquired();
        }
    }
}
+31 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.util.TypedValue;

import androidx.annotation.NonNull;
@@ -46,6 +47,8 @@ public class UdfpsEnrollProgressBarDrawable extends Drawable {

    @Nullable private ValueAnimator mProgressAnimator;
    private float mProgress;
    private int mRotation; // After last step, rotate the progress bar once
    private boolean mLastStepAcquired;

    public UdfpsEnrollProgressBarDrawable(@NonNull Context context,
            @NonNull UdfpsEnrollDrawable parent) {
@@ -81,13 +84,34 @@ public class UdfpsEnrollProgressBarDrawable extends Drawable {
        // Add one so that the first steps actually changes progress, but also so that the last
        // step ends at 1.0
        final float progress = (totalSteps - remaining + 1) / (float) (totalSteps + 1);
        setEnrollmentProgress(progress);
    }

    private void setEnrollmentProgress(float progress) {
        if (mLastStepAcquired) {
            return;
        }

        long animationDuration = 150;

        if (progress == 1.f) {
            animationDuration = 400;
            final ValueAnimator rotationAnimator = ValueAnimator.ofInt(0, 400);
            rotationAnimator.setDuration(animationDuration);
            rotationAnimator.addUpdateListener(animation -> {
                Log.d(TAG, "Rotation: " + mRotation);
                mRotation = (int) animation.getAnimatedValue();
                mParent.invalidateSelf();
            });
            rotationAnimator.start();
        }

        if (mProgressAnimator != null && mProgressAnimator.isRunning()) {
            mProgressAnimator.cancel();
        }

        mProgressAnimator = ValueAnimator.ofFloat(mProgress, progress);
        mProgressAnimator.setDuration(150);
        mProgressAnimator.setDuration(animationDuration);
        mProgressAnimator.addUpdateListener(animation -> {
            mProgress = (float) animation.getAnimatedValue();
            // Use the parent to invalidate, since it's the one that's attached as the view's
@@ -99,12 +123,17 @@ public class UdfpsEnrollProgressBarDrawable extends Drawable {
        mProgressAnimator.start();
    }

    void onLastStepAcquired() {
        setEnrollmentProgress(1.f);
        mLastStepAcquired = true;
    }

    @Override
    public void draw(@NonNull Canvas canvas) {
        canvas.save();

        // Progress starts from the top, instead of the right
        canvas.rotate(-90, getBounds().centerX(), getBounds().centerY());
        canvas.rotate(-90 + mRotation, getBounds().centerX(), getBounds().centerY());

        // Progress bar "background track"
        final float halfPaddingPx = Utils.dpToPixels(mContext, PROGRESS_BAR_THICKNESS_DP) / 2;
+5 −3
Original line number Diff line number Diff line
@@ -63,8 +63,10 @@ public class UdfpsEnrollView extends UdfpsAnimationView {
    }

    void onEnrollmentProgress(int remaining, int totalSteps) {
        mHandler.post(() -> {
            mFingerprintDrawable.onEnrollmentProgress(remaining, totalSteps);
        });
        mHandler.post(() -> mFingerprintDrawable.onEnrollmentProgress(remaining, totalSteps));
    }

    void onLastStepAcquired() {
        mHandler.post(mFingerprintDrawable::onLastStepAcquired);
    }
}
Loading