Animate last section of progress when ACQUIRED_GOOD

Bug: 187460696
Test: manual
Change-Id: Ie6aed9d737c470414a827503ddd88c1fbed2d345
This commit is contained in:
Kevin Chyn
2021-06-07 13:11:06 -07:00
parent 2e813eb8a9
commit 26c699989e
6 changed files with 74 additions and 6 deletions

View File

@@ -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");
}
});
}

View File

@@ -146,6 +146,10 @@ public class UdfpsEnrollDrawable extends UdfpsDrawable {
}
}
void onLastStepAcquired() {
mProgressDrawable.onLastStepAcquired();
}
@Override
public void draw(@NonNull Canvas canvas) {
mProgressDrawable.draw(canvas);

View File

@@ -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();
}
}
}

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -32,7 +32,17 @@ public class UdfpsEnrollViewController extends UdfpsAnimationViewController<Udfp
private final int mEnrollProgressBarRadius;
@NonNull private final UdfpsEnrollHelper mEnrollHelper;
@NonNull private final UdfpsEnrollHelper.Listener mEnrollHelperListener =
mView::onEnrollmentProgress;
new UdfpsEnrollHelper.Listener() {
@Override
public void onEnrollmentProgress(int remaining, int totalSteps) {
mView.onEnrollmentProgress(remaining, totalSteps);
}
@Override
public void onLastStepAcquired() {
mView.onLastStepAcquired();
}
};
protected UdfpsEnrollViewController(
@NonNull UdfpsEnrollView view,