Merge "Update the fingerprint enrollment color when device dark/light theme color changes"

This commit is contained in:
Jason Chang
2022-11-29 00:33:43 +00:00
committed by Android (Google) Code Review
8 changed files with 143 additions and 22 deletions

View File

@@ -78,9 +78,6 @@
<color name="biometric_dialog_accent">@color/material_dynamic_primary70</color>
<color name="biometric_dialog_error">#fff28b82</color> <!-- red 300 -->
<!-- UDFPS colors -->
<color name="udfps_enroll_icon">#7DA7F1</color>
<color name="GM2_green_500">#FF41Af6A</color>
<color name="GM2_blue_500">#5195EA</color>
<color name="GM2_red_500">#E25142</color>
@@ -103,4 +100,13 @@
<color name="accessibility_floating_menu_message_text">@*android:color/primary_text_default_material_dark</color>
<color name="people_tile_background">@color/material_dynamic_secondary20</color>
<!-- UDFPS colors -->
<color name="udfps_enroll_icon">#7DA7F1</color>
<color name="udfps_moving_target_fill">#475670</color>
<!-- 50% of udfps_moving_target_fill-->
<color name="udfps_moving_target_fill_error">#80475670</color>
<color name="udfps_enroll_progress">#7DA7F1</color>
<color name="udfps_enroll_progress_help">#607DA7F1</color>
<color name="udfps_enroll_progress_help_with_talkback">#FFEE675C</color>
</resources>

View File

@@ -209,5 +209,15 @@
<attr name="permissionGrantButtonTopStyle" format="reference"/>
<attr name="permissionGrantButtonBottomStyle" format="reference"/>
</declare-styleable>
<declare-styleable name="BiometricsEnrollView">
<attr name="biometricsEnrollStyle" format="reference" />
<attr name="biometricsEnrollIcon" format="reference|color" />
<attr name="biometricsMovingTargetFill" format="reference|color" />
<attr name="biometricsMovingTargetFillError" format="reference|color" />
<attr name="biometricsEnrollProgress" format="reference|color" />
<attr name="biometricsEnrollProgressHelp" format="reference|color" />
<attr name="biometricsEnrollProgressHelpWithTalkback" format="reference|color" />
</declare-styleable>
</resources>

View File

@@ -134,12 +134,12 @@
<color name="biometric_dialog_error">#ffd93025</color> <!-- red 600 -->
<!-- UDFPS colors -->
<color name="udfps_enroll_icon">#7DA7F1</color>
<color name="udfps_moving_target_fill">#475670</color>
<color name="udfps_enroll_icon">#699FF3</color>
<color name="udfps_moving_target_fill">#C2D7F7</color>
<!-- 50% of udfps_moving_target_fill-->
<color name="udfps_moving_target_fill_error">#80475670</color>
<color name="udfps_enroll_progress">#7DA7F1</color>
<color name="udfps_enroll_progress_help">#607DA7F1</color>
<color name="udfps_moving_target_fill_error">#80C2D7F7</color>
<color name="udfps_enroll_progress">#699FF3</color>
<color name="udfps_enroll_progress_help">#70699FF3</color>
<color name="udfps_enroll_progress_help_with_talkback">#FFEE675C</color>
<!-- Floating overlay actions -->

View File

@@ -314,6 +314,10 @@
<!-- Needed for MediaRoute chooser dialog -->
<item name="*android:isLightTheme">false</item>
<!-- Biometrics enroll color style -->
<item name="biometricsEnrollStyle">@style/BiometricsEnrollStyle</item>
</style>
<style name="Theme.SystemUI.LightWallpaper">
@@ -1281,7 +1285,6 @@
<item name="android:textSize">@dimen/broadcast_dialog_btn_text_size</item>
</style>
<!-- The style for log access consent dialog -->
<style name="LogAccessDialogTheme" parent="@style/Theme.SystemUI.Dialog.Alert">
<item name="permissionGrantButtonTopStyle">@style/PermissionGrantButtonTop</item>
@@ -1321,4 +1324,13 @@
<item name="android:layout_marginBottom">2dp</item>
<item name="android:background">@drawable/grant_permissions_buttons_bottom</item>
</style>
<style name="BiometricsEnrollStyle">
<item name="biometricsEnrollIcon">@color/udfps_enroll_icon</item>
<item name="biometricsMovingTargetFill">@color/udfps_moving_target_fill</item>
<item name="biometricsMovingTargetFillError">@color/udfps_moving_target_fill_error</item>
<item name="biometricsEnrollProgress">@color/udfps_enroll_progress</item>
<item name="biometricsEnrollProgressHelp">@color/udfps_enroll_progress_help</item>
<item name="biometricsEnrollProgressHelpWithTalkback">@color/udfps_enroll_progress_help_with_talkback</item>
</style>
</resources>

View File

@@ -20,6 +20,7 @@ import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
@@ -28,6 +29,7 @@ import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.animation.AccelerateDecelerateInterpolator;
import androidx.annotation.NonNull;
@@ -68,25 +70,29 @@ public class UdfpsEnrollDrawable extends UdfpsDrawable {
private boolean mShouldShowTipHint = false;
private boolean mShouldShowEdgeHint = false;
UdfpsEnrollDrawable(@NonNull Context context) {
private int mEnrollIcon;
private int mMovingTargetFill;
UdfpsEnrollDrawable(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context);
loadResources(context, attrs);
mSensorOutlinePaint = new Paint(0 /* flags */);
mSensorOutlinePaint.setAntiAlias(true);
mSensorOutlinePaint.setColor(context.getColor(R.color.udfps_moving_target_fill));
mSensorOutlinePaint.setColor(mMovingTargetFill);
mSensorOutlinePaint.setStyle(Paint.Style.FILL);
mBlueFill = new Paint(0 /* flags */);
mBlueFill.setAntiAlias(true);
mBlueFill.setColor(context.getColor(R.color.udfps_moving_target_fill));
mBlueFill.setColor(mMovingTargetFill);
mBlueFill.setStyle(Paint.Style.FILL);
mMovingTargetFpIcon = context.getResources()
.getDrawable(R.drawable.ic_kg_fingerprint, null);
mMovingTargetFpIcon.setTint(context.getColor(R.color.udfps_enroll_icon));
mMovingTargetFpIcon.setTint(mEnrollIcon);
mMovingTargetFpIcon.mutate();
getFingerprintDrawable().setTint(context.getColor(R.color.udfps_enroll_icon));
getFingerprintDrawable().setTint(mEnrollIcon);
mTargetAnimListener = new Animator.AnimatorListener() {
@Override
@@ -105,6 +111,16 @@ public class UdfpsEnrollDrawable extends UdfpsDrawable {
};
}
void loadResources(Context context, @Nullable AttributeSet attrs) {
final TypedArray ta = context.obtainStyledAttributes(attrs,
R.styleable.BiometricsEnrollView, R.attr.biometricsEnrollStyle,
R.style.BiometricsEnrollStyle);
mEnrollIcon = ta.getColor(R.styleable.BiometricsEnrollView_biometricsEnrollIcon, 0);
mMovingTargetFill = ta.getColor(
R.styleable.BiometricsEnrollView_biometricsMovingTargetFill, 0);
ta.recycle();
}
void setEnrollHelper(@NonNull UdfpsEnrollHelper helper) {
mEnrollHelper = helper;
}

View File

@@ -18,6 +18,7 @@ package com.android.systemui.biometrics;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
@@ -26,6 +27,7 @@ import android.os.Process;
import android.os.VibrationAttributes;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.util.AttributeSet;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
@@ -93,17 +95,25 @@ public class UdfpsEnrollProgressBarDrawable extends Drawable {
@Nullable private ValueAnimator mCheckmarkAnimator;
@NonNull private final ValueAnimator.AnimatorUpdateListener mCheckmarkUpdateListener;
public UdfpsEnrollProgressBarDrawable(@NonNull Context context) {
private int mMovingTargetFill;
private int mMovingTargetFillError;
private int mEnrollProgress;
private int mEnrollProgressHelp;
private int mEnrollProgressHelpWithTalkback;
public UdfpsEnrollProgressBarDrawable(@NonNull Context context, @Nullable AttributeSet attrs) {
mContext = context;
loadResources(context, attrs);
mStrokeWidthPx = Utils.dpToPixels(context, STROKE_WIDTH_DP);
mProgressColor = context.getColor(R.color.udfps_enroll_progress);
mProgressColor = mEnrollProgress;
final AccessibilityManager am = context.getSystemService(AccessibilityManager.class);
mIsAccessibilityEnabled = am.isTouchExplorationEnabled();
mOnFirstBucketFailedColor = context.getColor(R.color.udfps_moving_target_fill_error);
mOnFirstBucketFailedColor = mMovingTargetFillError;
if (!mIsAccessibilityEnabled) {
mHelpColor = context.getColor(R.color.udfps_enroll_progress_help);
mHelpColor = mEnrollProgressHelp;
} else {
mHelpColor = context.getColor(R.color.udfps_enroll_progress_help_with_talkback);
mHelpColor = mEnrollProgressHelpWithTalkback;
}
mCheckmarkDrawable = context.getDrawable(R.drawable.udfps_enroll_checkmark);
mCheckmarkDrawable.mutate();
@@ -111,7 +121,7 @@ public class UdfpsEnrollProgressBarDrawable extends Drawable {
mBackgroundPaint = new Paint();
mBackgroundPaint.setStrokeWidth(mStrokeWidthPx);
mBackgroundPaint.setColor(context.getColor(R.color.udfps_moving_target_fill));
mBackgroundPaint.setColor(mMovingTargetFill);
mBackgroundPaint.setAntiAlias(true);
mBackgroundPaint.setStyle(Paint.Style.STROKE);
mBackgroundPaint.setStrokeCap(Paint.Cap.ROUND);
@@ -147,6 +157,23 @@ public class UdfpsEnrollProgressBarDrawable extends Drawable {
};
}
void loadResources(Context context, @Nullable AttributeSet attrs) {
final TypedArray ta = context.obtainStyledAttributes(attrs,
R.styleable.BiometricsEnrollView, R.attr.biometricsEnrollStyle,
R.style.BiometricsEnrollStyle);
mMovingTargetFill = ta.getColor(
R.styleable.BiometricsEnrollView_biometricsMovingTargetFill, 0);
mMovingTargetFillError = ta.getColor(
R.styleable.BiometricsEnrollView_biometricsMovingTargetFillError, 0);
mEnrollProgress = ta.getColor(
R.styleable.BiometricsEnrollView_biometricsEnrollProgress, 0);
mEnrollProgressHelp = ta.getColor(
R.styleable.BiometricsEnrollView_biometricsEnrollProgressHelp, 0);
mEnrollProgressHelpWithTalkback = ta.getColor(
R.styleable.BiometricsEnrollView_biometricsEnrollProgressHelpWithTalkback, 0);
ta.recycle();
}
void onEnrollmentProgress(int remaining, int totalSteps) {
mAfterFirstTouch = true;
updateState(remaining, totalSteps, false /* showingHelp */);

View File

@@ -47,8 +47,8 @@ public class UdfpsEnrollView extends UdfpsAnimationView {
public UdfpsEnrollView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
mFingerprintDrawable = new UdfpsEnrollDrawable(mContext);
mFingerprintProgressDrawable = new UdfpsEnrollProgressBarDrawable(context);
mFingerprintDrawable = new UdfpsEnrollDrawable(mContext, attrs);
mFingerprintProgressDrawable = new UdfpsEnrollProgressBarDrawable(context, attrs);
mHandler = new Handler(Looper.getMainLooper());
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2022 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 static com.google.common.truth.Truth.assertThat;
import android.content.res.Configuration;
import android.graphics.Color;
import android.testing.AndroidTestingRunner;
import androidx.test.filters.SmallTest;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest
@RunWith(AndroidTestingRunner.class)
public class UdfpsEnrollViewTest extends SysuiTestCase {
private static String ENROLL_PROGRESS_COLOR_LIGHT = "#699FF3";
private static String ENROLL_PROGRESS_COLOR_DARK = "#7DA7F1";
@Test
public void fingerprintUdfpsEnroll_usesCorrectThemeCheckmarkFillColor() {
final Configuration config = mContext.getResources().getConfiguration();
final boolean isDarkThemeOn = (config.uiMode & Configuration.UI_MODE_NIGHT_MASK)
== Configuration.UI_MODE_NIGHT_YES;
final int currentColor = mContext.getColor(R.color.udfps_enroll_progress);
assertThat(currentColor).isEqualTo(Color.parseColor(isDarkThemeOn
? ENROLL_PROGRESS_COLOR_DARK : ENROLL_PROGRESS_COLOR_LIGHT));
}
}