Merge "Animate UDFPS enroll affordance" into sc-dev
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.systemui.biometrics;
|
package com.android.systemui.biometrics;
|
||||||
|
|
||||||
|
import android.animation.AnimatorSet;
|
||||||
|
import android.animation.ValueAnimator;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
@@ -24,6 +26,9 @@ import android.graphics.PointF;
|
|||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -38,17 +43,33 @@ public class UdfpsEnrollDrawable extends UdfpsDrawable {
|
|||||||
|
|
||||||
static final float PROGRESS_BAR_RADIUS = 360.f;
|
static final float PROGRESS_BAR_RADIUS = 360.f;
|
||||||
|
|
||||||
|
private static final long ANIM_DURATION = 800;
|
||||||
|
// 1 + SCALE_MAX is the maximum that the moving target will animate to
|
||||||
|
private static final float SCALE_MAX = 0.25f;
|
||||||
|
|
||||||
@NonNull private final Drawable mMovingTargetFpIcon;
|
@NonNull private final Drawable mMovingTargetFpIcon;
|
||||||
@NonNull private final Paint mSensorOutlinePaint;
|
@NonNull private final Paint mSensorOutlinePaint;
|
||||||
@NonNull private final Paint mBlueFill;
|
@NonNull private final Paint mBlueFill;
|
||||||
@NonNull private final Paint mBlueStroke;
|
@NonNull private final Paint mBlueStroke;
|
||||||
|
@NonNull private final Handler mHandler;
|
||||||
|
|
||||||
@Nullable private RectF mSensorRect;
|
@Nullable private RectF mSensorRect;
|
||||||
@Nullable private UdfpsEnrollHelper mEnrollHelper;
|
@Nullable private UdfpsEnrollHelper mEnrollHelper;
|
||||||
|
|
||||||
|
// Moving target animator set
|
||||||
|
@Nullable AnimatorSet mAnimatorSet;
|
||||||
|
// Moving target location
|
||||||
|
float mCurrentX;
|
||||||
|
float mCurrentY;
|
||||||
|
// Moving target size
|
||||||
|
float mCurrentScale = 1.f;
|
||||||
|
|
||||||
|
|
||||||
UdfpsEnrollDrawable(@NonNull Context context) {
|
UdfpsEnrollDrawable(@NonNull Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
|
mHandler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
mSensorOutlinePaint = new Paint(0 /* flags */);
|
mSensorOutlinePaint = new Paint(0 /* flags */);
|
||||||
mSensorOutlinePaint.setAntiAlias(true);
|
mSensorOutlinePaint.setAntiAlias(true);
|
||||||
mSensorOutlinePaint.setColor(mContext.getColor(R.color.udfps_enroll_icon));
|
mSensorOutlinePaint.setColor(mContext.getColor(R.color.udfps_enroll_icon));
|
||||||
@@ -90,6 +111,46 @@ public class UdfpsEnrollDrawable extends UdfpsDrawable {
|
|||||||
invalidateSelf();
|
invalidateSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onEnrollmentProgress(int remaining, int totalSteps) {
|
||||||
|
if (mEnrollHelper.isCenterEnrollmentComplete()) {
|
||||||
|
mHandler.post(() -> {
|
||||||
|
if (mAnimatorSet != null && mAnimatorSet.isRunning()) {
|
||||||
|
mAnimatorSet.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
final PointF point = mEnrollHelper.getNextGuidedEnrollmentPoint();
|
||||||
|
|
||||||
|
final ValueAnimator x = ValueAnimator.ofFloat(mCurrentX, point.x);
|
||||||
|
x.addUpdateListener(animation -> {
|
||||||
|
mCurrentX = (float) animation.getAnimatedValue();
|
||||||
|
invalidateSelf();
|
||||||
|
});
|
||||||
|
|
||||||
|
final ValueAnimator y = ValueAnimator.ofFloat(mCurrentY, point.y);
|
||||||
|
y.addUpdateListener(animation -> {
|
||||||
|
mCurrentY = (float) animation.getAnimatedValue();
|
||||||
|
invalidateSelf();
|
||||||
|
});
|
||||||
|
|
||||||
|
final ValueAnimator scale = ValueAnimator.ofFloat(0, (float) Math.PI);
|
||||||
|
scale.setDuration(ANIM_DURATION);
|
||||||
|
scale.addUpdateListener(animation -> {
|
||||||
|
// Grow then shrink
|
||||||
|
mCurrentScale = 1 +
|
||||||
|
SCALE_MAX * (float) Math.sin((float) animation.getAnimatedValue());
|
||||||
|
invalidateSelf();
|
||||||
|
});
|
||||||
|
|
||||||
|
mAnimatorSet = new AnimatorSet();
|
||||||
|
|
||||||
|
mAnimatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||||
|
mAnimatorSet.setDuration(ANIM_DURATION);
|
||||||
|
mAnimatorSet.playTogether(x, y, scale);
|
||||||
|
mAnimatorSet.start();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(@NonNull Canvas canvas) {
|
public void draw(@NonNull Canvas canvas) {
|
||||||
if (isIlluminationShowing()) {
|
if (isIlluminationShowing()) {
|
||||||
@@ -98,13 +159,12 @@ public class UdfpsEnrollDrawable extends UdfpsDrawable {
|
|||||||
|
|
||||||
// Draw moving target
|
// Draw moving target
|
||||||
if (mEnrollHelper.isCenterEnrollmentComplete()) {
|
if (mEnrollHelper.isCenterEnrollmentComplete()) {
|
||||||
mFingerprintDrawable.setAlpha(mAlpha == 255 ? 64 : mAlpha);
|
|
||||||
mSensorOutlinePaint.setAlpha(mAlpha == 255 ? 64 : mAlpha);
|
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
final PointF point = mEnrollHelper.getNextGuidedEnrollmentPoint();
|
canvas.translate(mCurrentX, mCurrentY);
|
||||||
canvas.translate(point.x, point.y);
|
|
||||||
if (mSensorRect != null) {
|
if (mSensorRect != null) {
|
||||||
|
canvas.scale(mCurrentScale, mCurrentScale,
|
||||||
|
mSensorRect.centerX(), mSensorRect.centerY());
|
||||||
canvas.drawOval(mSensorRect, mBlueFill);
|
canvas.drawOval(mSensorRect, mBlueFill);
|
||||||
canvas.drawOval(mSensorRect, mBlueStroke);
|
canvas.drawOval(mSensorRect, mBlueStroke);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,4 +60,8 @@ public class UdfpsEnrollView extends UdfpsAnimationView {
|
|||||||
void setEnrollHelper(UdfpsEnrollHelper enrollHelper) {
|
void setEnrollHelper(UdfpsEnrollHelper enrollHelper) {
|
||||||
mFingerprintDrawable.setEnrollHelper(enrollHelper);
|
mFingerprintDrawable.setEnrollHelper(enrollHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onEnrollmentProgress(int remaining, int totalSteps) {
|
||||||
|
mFingerprintDrawable.onEnrollmentProgress(remaining, totalSteps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ public class UdfpsEnrollViewController extends UdfpsAnimationViewController<Udfp
|
|||||||
* Math.max(0, totalSteps + 1 - remaining) / (totalSteps + 1);
|
* Math.max(0, totalSteps + 1 - remaining) / (totalSteps + 1);
|
||||||
|
|
||||||
mProgressBar.setProgress(interpolatedProgress, true);
|
mProgressBar.setProgress(interpolatedProgress, true);
|
||||||
|
mView.onEnrollmentProgress(remaining, totalSteps);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user