Merge "Fix UDFPS enrollment shadow" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-02-03 05:44:57 +00:00
committed by Android (Google) Code Review
4 changed files with 40 additions and 8 deletions

View File

@@ -52,4 +52,18 @@ public abstract class UdfpsAnimation extends Drawable {
public void setAlpha(int alpha) { public void setAlpha(int alpha) {
mFingerprintDrawable.setAlpha(alpha); mFingerprintDrawable.setAlpha(alpha);
} }
/**
* @return The amount of padding that's needed on each side of the sensor, in pixels.
*/
public int getPaddingX() {
return 0;
}
/**
* @return The amount of padding that's needed on each side of the sensor, in pixels.
*/
public int getPaddingY() {
return 0;
}
} }

View File

@@ -70,6 +70,9 @@ public class UdfpsAnimationEnroll extends UdfpsAnimation {
@Override @Override
public void draw(@NonNull Canvas canvas) { public void draw(@NonNull Canvas canvas) {
canvas.save();
canvas.translate(getPaddingX(), getPaddingY());
final boolean isNightMode = (mContext.getResources().getConfiguration().uiMode final boolean isNightMode = (mContext.getResources().getConfiguration().uiMode
& Configuration.UI_MODE_NIGHT_YES) != 0; & Configuration.UI_MODE_NIGHT_YES) != 0;
if (!isNightMode) { if (!isNightMode) {
@@ -78,6 +81,18 @@ public class UdfpsAnimationEnroll extends UdfpsAnimation {
} }
} }
mFingerprintDrawable.draw(canvas); mFingerprintDrawable.draw(canvas);
canvas.restore();
}
@Override
public int getPaddingX() {
return (int) Math.ceil(SHADOW_RADIUS);
}
@Override
public int getPaddingY() {
return (int) Math.ceil(SHADOW_RADIUS);
} }
@Override @Override

View File

@@ -242,12 +242,15 @@ public class UdfpsController implements DozeReceiver, HbmCallback {
} }
} }
private WindowManager.LayoutParams computeLayoutParams() { private WindowManager.LayoutParams computeLayoutParams(@Nullable UdfpsAnimation animation) {
final int paddingX = animation != null ? animation.getPaddingX() : 0;
final int paddingY = animation != null ? animation.getPaddingY() : 0;
// Default dimensions assume portrait mode. // Default dimensions assume portrait mode.
mCoreLayoutParams.x = mSensorProps.sensorLocationX - mSensorProps.sensorRadius; mCoreLayoutParams.x = mSensorProps.sensorLocationX - mSensorProps.sensorRadius - paddingX;
mCoreLayoutParams.y = mSensorProps.sensorLocationY - mSensorProps.sensorRadius; mCoreLayoutParams.y = mSensorProps.sensorLocationY - mSensorProps.sensorRadius - paddingY;
mCoreLayoutParams.height = 2 * mSensorProps.sensorRadius; mCoreLayoutParams.height = 2 * mSensorProps.sensorRadius + 2 * paddingX;
mCoreLayoutParams.width = 2 * mSensorProps.sensorRadius; mCoreLayoutParams.width = 2 * mSensorProps.sensorRadius + 2 * paddingY;
Point p = new Point(); Point p = new Point();
// Gets the size based on the current rotation of the display. // Gets the size based on the current rotation of the display.
@@ -289,8 +292,9 @@ public class UdfpsController implements DozeReceiver, HbmCallback {
if (!mIsOverlayShowing) { if (!mIsOverlayShowing) {
try { try {
Log.v(TAG, "showUdfpsOverlay | adding window"); Log.v(TAG, "showUdfpsOverlay | adding window");
mView.setUdfpsAnimation(getUdfpsAnimationForReason(reason)); final UdfpsAnimation animation = getUdfpsAnimationForReason(reason);
mWindowManager.addView(mView, computeLayoutParams()); mView.setUdfpsAnimation(animation);
mWindowManager.addView(mView, computeLayoutParams(animation));
mView.setOnTouchListener(mOnTouchListener); mView.setOnTouchListener(mOnTouchListener);
mIsOverlayShowing = true; mIsOverlayShowing = true;
} catch (RuntimeException e) { } catch (RuntimeException e) {

View File

@@ -56,7 +56,6 @@ public class UdfpsView extends FrameLayout implements DozeReceiver, UdfpsIllumin
@NonNull private final RectF mSensorRect; @NonNull private final RectF mSensorRect;
@NonNull private final Paint mDebugTextPaint; @NonNull private final Paint mDebugTextPaint;
// Used to obtain the sensor location. // Used to obtain the sensor location.
@NonNull private FingerprintSensorPropertiesInternal mSensorProps; @NonNull private FingerprintSensorPropertiesInternal mSensorProps;