Merge "Add progressbar to UdfpsView" into sc-dev

This commit is contained in:
Kevin Chyn
2021-02-06 05:08:45 +00:00
committed by Android (Google) Code Review
10 changed files with 206 additions and 25 deletions

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2021 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.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape
android:innerRadiusRatio="2.2"
android:shape="ring"
android:thickness="@dimen/udfps_enroll_progress_thickness"
android:useLevel="false"
android:tint="?android:colorControlNormal">
<solid android:color="@*android:color/white_disabled_material" />
</shape>
</item>
<item android:id="@android:id/progress">
<rotate
android:fromDegrees="270"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="270">
<shape
android:innerRadiusRatio="2.2"
android:shape="ring"
android:thickness="@dimen/udfps_enroll_progress_thickness"
android:tint="?android:attr/colorControlActivated">
<solid android:color="@android:color/white" />
</shape>
</rotate>
</item>
</layer-list>

View File

@@ -20,4 +20,17 @@
android:id="@+id/udfps_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
systemui:sensorTouchAreaCoefficient="0.5"/>
systemui:sensorTouchAreaCoefficient="0.5">
<!-- Enrollment progress bar-->
<com.android.systemui.biometrics.UdfpsProgressBar
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:max="100"
android:padding="@dimen/udfps_enroll_progress_thickness"
android:progress="0"
android:layout_gravity="center"
android:visibility="gone"/>
</com.android.systemui.biometrics.UdfpsView>

View File

@@ -1117,6 +1117,9 @@
<!-- Y translation for credential contents when animating in -->
<dimen name="biometric_dialog_credential_translation_offset">60dp</dimen>
<!-- UDFPS enrollment progress bar thickness -->
<dimen name="udfps_enroll_progress_thickness">12dp</dimen>
<!-- Wireless Charging Animation values -->
<dimen name="wireless_charging_dots_radius_start">0dp</dimen>
<dimen name="wireless_charging_dots_radius_end">4dp</dimen>

View File

@@ -765,4 +765,12 @@
<item name="android:textSize">14sp</item>
<item name="android:fontFamily">@*android:string/config_headlineFontFamily</item>
</style>
<style name="UdfpsProgressBarStyle"
parent="android:style/Widget.Material.ProgressBar.Horizontal">
<item name="android:indeterminate">false</item>
<item name="android:max">10000</item>
<item name="android:mirrorForRtl">false</item>
<item name="android:progressDrawable">@drawable/udfps_progress_bar</item>
</style>
</resources>

View File

@@ -38,6 +38,7 @@ public class UdfpsAnimationEnroll extends UdfpsAnimation {
private static final String TAG = "UdfpsAnimationEnroll";
private static final float SHADOW_RADIUS = 5.f;
private static final float PROGRESS_BAR_RADIUS = 140.f;
@Nullable private RectF mSensorRect;
@NonNull private final Paint mSensorPaint;
@@ -81,12 +82,12 @@ public class UdfpsAnimationEnroll extends UdfpsAnimation {
@Override
public int getPaddingX() {
return (int) Math.ceil(SHADOW_RADIUS);
return (int) Math.ceil(PROGRESS_BAR_RADIUS);
}
@Override
public int getPaddingY() {
return (int) Math.ceil(SHADOW_RADIUS);
return (int) Math.ceil(PROGRESS_BAR_RADIUS);
}
@Override
@@ -104,12 +105,4 @@ public class UdfpsAnimationEnroll extends UdfpsAnimation {
public int getOpacity() {
return 0;
}
public void onEnrollmentProgress(int remaining) {
Log.d(TAG, "Remaining: " + remaining);
}
public void onEnrollmentHelp() {
Log.d(TAG, "onEnrollmentHelp");
}
}

View File

@@ -103,18 +103,6 @@ public class UdfpsAnimationView extends View implements DozeReceiver,
postInvalidate();
}
void onEnrollmentProgress(int remaining) {
if (mUdfpsAnimation instanceof UdfpsAnimationEnroll) {
((UdfpsAnimationEnroll) mUdfpsAnimation).onEnrollmentProgress(remaining);
}
}
void onEnrollmentHelp() {
if (mUdfpsAnimation instanceof UdfpsAnimationEnroll) {
((UdfpsAnimationEnroll) mUdfpsAnimation).onEnrollmentHelp();
}
}
public int getPaddingX() {
if (mUdfpsAnimation == null) {
return 0;

View File

@@ -84,6 +84,7 @@ public class UdfpsController implements DozeReceiver, HbmCallback {
private boolean mIsOverlayRequested;
// Reason the overlay has been requested. See IUdfpsOverlayController for definitions.
private int mRequestReason;
@Nullable UdfpsEnrollHelper mEnrollHelper;
// The fingerprint AOD trigger doesn't provide an ACTION_UP/ACTION_CANCEL event to tell us when
// to turn off high brightness mode. To get around this limitation, the state of the AOD
@@ -95,6 +96,9 @@ public class UdfpsController implements DozeReceiver, HbmCallback {
public class UdfpsOverlayController extends IUdfpsOverlayController.Stub {
@Override
public void showUdfpsOverlay(int sensorId, int reason) {
if (reason == IUdfpsOverlayController.REASON_ENROLL) {
mEnrollHelper = new UdfpsEnrollHelper();
}
UdfpsController.this.showOverlay(reason);
}
@@ -297,6 +301,7 @@ public class UdfpsController implements DozeReceiver, HbmCallback {
Log.v(TAG, "showUdfpsOverlay | adding window");
final UdfpsAnimation animation = getUdfpsAnimationForReason(reason);
mView.setUdfpsAnimation(animation);
mView.setEnrollHelper(mEnrollHelper);
mWindowManager.addView(mView, computeLayoutParams(animation));
mView.setOnTouchListener(mOnTouchListener);
mIsOverlayShowing = true;

View File

@@ -0,0 +1,48 @@
/*
* Copyright (C) 2021 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.
*/
package com.android.systemui.biometrics;
import androidx.annotation.NonNull;
/**
* Helps keep track of enrollment state and animates the progress bar accordingly.
*/
public class UdfpsEnrollHelper {
private static final String TAG = "UdfpsEnrollHelper";
private int mTotalSteps = -1;
private int mCurrentProgress = 0;
void onEnrollmentProgress(int remaining, @NonNull UdfpsProgressBar progressBar) {
if (mTotalSteps == -1) {
mTotalSteps = remaining;
}
mCurrentProgress = progressBar.getMax() * Math.max(0, mTotalSteps + 1 - remaining)
/ (mTotalSteps + 1);
progressBar.setProgress(mCurrentProgress, true /* animate */);
}
void updateProgress(@NonNull UdfpsProgressBar progressBar) {
progressBar.setProgress(mCurrentProgress);
}
void onEnrollmentHelp() {
}
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright (C) 2021 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.
*/
package com.android.systemui.biometrics;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ProgressBar;
import com.android.systemui.R;
/**
* A (determinate) progress bar in the form of a ring. The progress bar goes clockwise starting
* from the 12 o'clock position. This view maintain equal width and height using a strategy similar
* to "centerInside" for ImageView.
*/
public class UdfpsProgressBar extends ProgressBar {
public UdfpsProgressBar(Context context) {
this(context, null);
}
public UdfpsProgressBar(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public UdfpsProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, R.style.UdfpsProgressBarStyle);
}
public UdfpsProgressBar(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final int measuredHeight = getMeasuredHeight();
final int measuredWidth = getMeasuredWidth();
final int length = Math.min(measuredHeight, measuredWidth);
setMeasuredDimension(length, length);
}
}

View File

@@ -56,6 +56,8 @@ public class UdfpsView extends FrameLayout implements DozeReceiver, UdfpsIllumin
@NonNull private final RectF mSensorRect;
@NonNull private final Paint mDebugTextPaint;
@Nullable private UdfpsProgressBar mProgressBar;
// Used to obtain the sensor location.
@NonNull private FingerprintSensorPropertiesInternal mSensorProps;
@@ -64,6 +66,7 @@ public class UdfpsView extends FrameLayout implements DozeReceiver, UdfpsIllumin
private boolean mIlluminationRequested;
private int mStatusBarState;
private boolean mNotificationShadeExpanded;
@Nullable private UdfpsEnrollHelper mEnrollHelper;
public UdfpsView(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -110,6 +113,18 @@ public class UdfpsView extends FrameLayout implements DozeReceiver, UdfpsIllumin
void setUdfpsAnimation(@Nullable UdfpsAnimation animation) {
mAnimationView.setAnimation(animation);
if (animation instanceof UdfpsAnimationEnroll) {
mProgressBar.setVisibility(View.VISIBLE);
} else {
mProgressBar.setVisibility(View.GONE);
}
}
void setEnrollHelper(@Nullable UdfpsEnrollHelper enrollHelper) {
mEnrollHelper = enrollHelper;
if (mEnrollHelper != null) {
mEnrollHelper.updateProgress(mProgressBar);
}
}
@Override
@@ -137,6 +152,11 @@ public class UdfpsView extends FrameLayout implements DozeReceiver, UdfpsIllumin
mAnimationView.onExpansionChanged(expansion, expanded);
}
@Override
protected void onFinishInflate() {
mProgressBar = findViewById(R.id.progress_bar);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
@@ -233,10 +253,10 @@ public class UdfpsView extends FrameLayout implements DozeReceiver, UdfpsIllumin
}
void onEnrollmentProgress(int remaining) {
mAnimationView.onEnrollmentProgress(remaining);
mEnrollHelper.onEnrollmentProgress(remaining, mProgressBar);
}
void onEnrollmentHelp() {
mAnimationView.onEnrollmentHelp();
}
}