diff options
author | 2021-02-06 05:08:45 +0000 | |
---|---|---|
committer | 2021-02-06 05:08:45 +0000 | |
commit | 5423a75e17e25c98dc16faa4d0723cfe7ee786e6 (patch) | |
tree | db5f298ba428651c978b163bda1fc0dc6841866a | |
parent | ec1a3f05279049372d8d42a8ddcbe444298affea (diff) | |
parent | 8c4397fedfa752a79273fad42375fb90833221e1 (diff) |
Merge "Add progressbar to UdfpsView" into sc-dev
10 files changed, 206 insertions, 25 deletions
diff --git a/packages/SystemUI/res/drawable/udfps_progress_bar.xml b/packages/SystemUI/res/drawable/udfps_progress_bar.xml new file mode 100644 index 000000000000..e5389f3b99ef --- /dev/null +++ b/packages/SystemUI/res/drawable/udfps_progress_bar.xml @@ -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>
\ No newline at end of file diff --git a/packages/SystemUI/res/layout/udfps_view.xml b/packages/SystemUI/res/layout/udfps_view.xml index c0788051efed..6ae306e17209 100644 --- a/packages/SystemUI/res/layout/udfps_view.xml +++ b/packages/SystemUI/res/layout/udfps_view.xml @@ -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> diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 3f1441ac9310..afa98b56a13c 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -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> diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml index 8a84e3e1c882..7c72548a7252 100644 --- a/packages/SystemUI/res/values/styles.xml +++ b/packages/SystemUI/res/values/styles.xml @@ -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> diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationEnroll.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationEnroll.java index e07c84034b31..5290986b2a1c 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationEnroll.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationEnroll.java @@ -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"); - } } diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationView.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationView.java index 4e3419e1fab3..41ea4d66f575 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationView.java @@ -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; diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java index c088400f4057..edf046864a7c 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java @@ -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; diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsEnrollHelper.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsEnrollHelper.java new file mode 100644 index 000000000000..ac6a2121eaae --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsEnrollHelper.java @@ -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() { + + } +} diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsProgressBar.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsProgressBar.java new file mode 100644 index 000000000000..84e2fab7bf6b --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsProgressBar.java @@ -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); + } +}
\ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java index 7e378d3c568e..b21e1b5ebb15 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsView.java @@ -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 @@ -138,6 +153,11 @@ public class UdfpsView extends FrameLayout implements DozeReceiver, UdfpsIllumin } @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); mSensorRect.set(0 + mAnimationView.getPaddingX(), @@ -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(); + } } |