1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.biometrics.fingerprint.feature; 18 19 import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.SFPS_STAGE_CENTER; 20 import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.SFPS_STAGE_FINGERTIP; 21 import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.SFPS_STAGE_LEFT_EDGE; 22 import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.SFPS_STAGE_NO_ANIMATION; 23 import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.SFPS_STAGE_RIGHT_EDGE; 24 import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.STAGE_UNKNOWN; 25 26 import android.animation.Animator; 27 import android.animation.ObjectAnimator; 28 import android.content.Context; 29 import android.hardware.fingerprint.FingerprintManager; 30 import android.view.View; 31 import android.view.animation.AccelerateInterpolator; 32 33 import androidx.annotation.NonNull; 34 import androidx.annotation.Nullable; 35 36 import com.android.internal.annotations.VisibleForTesting; 37 import com.android.settings.R; 38 39 import java.util.function.Function; 40 41 public class SfpsEnrollmentFeatureImpl implements SfpsEnrollmentFeature { 42 @VisibleForTesting 43 public static final int HELP_ANIMATOR_DURATION = 550; 44 45 @Nullable 46 private FingerprintManager mFingerprintManager = null; 47 48 @Override getCurrentSfpsEnrollStage(int progressSteps, Function<Integer, Integer> mapper)49 public int getCurrentSfpsEnrollStage(int progressSteps, Function<Integer, Integer> mapper) { 50 if (mapper == null) { 51 return STAGE_UNKNOWN; 52 } 53 if (progressSteps < mapper.apply(0)) { 54 return SFPS_STAGE_NO_ANIMATION; 55 } else if (progressSteps < mapper.apply(1)) { 56 return SFPS_STAGE_CENTER; 57 } else if (progressSteps < mapper.apply(2)) { 58 return SFPS_STAGE_FINGERTIP; 59 } else if (progressSteps < mapper.apply(3)) { 60 return SFPS_STAGE_LEFT_EDGE; 61 } else { 62 return SFPS_STAGE_RIGHT_EDGE; 63 } 64 } 65 66 @Override getFeaturedStageHeaderResource(int stage)67 public int getFeaturedStageHeaderResource(int stage) { 68 return switch (stage) { 69 case SFPS_STAGE_NO_ANIMATION 70 -> R.string.security_settings_fingerprint_enroll_repeat_title; 71 case SFPS_STAGE_CENTER -> R.string.security_settings_sfps_enroll_finger_center_title; 72 case SFPS_STAGE_FINGERTIP -> R.string.security_settings_sfps_enroll_fingertip_title; 73 case SFPS_STAGE_LEFT_EDGE -> R.string.security_settings_sfps_enroll_left_edge_title; 74 case SFPS_STAGE_RIGHT_EDGE -> R.string.security_settings_sfps_enroll_right_edge_title; 75 default -> throw new IllegalArgumentException("Invalid stage: " + stage); 76 }; 77 } 78 79 @Override getSfpsEnrollLottiePerStage(int stage)80 public int getSfpsEnrollLottiePerStage(int stage) { 81 return switch (stage) { 82 case SFPS_STAGE_NO_ANIMATION -> R.raw.sfps_lottie_no_animation; 83 case SFPS_STAGE_CENTER -> R.raw.sfps_lottie_pad_center; 84 case SFPS_STAGE_FINGERTIP -> R.raw.sfps_lottie_tip; 85 case SFPS_STAGE_LEFT_EDGE -> R.raw.sfps_lottie_left_edge; 86 case SFPS_STAGE_RIGHT_EDGE -> R.raw.sfps_lottie_right_edge; 87 default -> throw new IllegalArgumentException("Invalid stage: " + stage); 88 }; 89 } 90 91 @Override 92 public float getEnrollStageThreshold(@NonNull Context context, int index) { 93 if (mFingerprintManager == null) { 94 mFingerprintManager = context.getSystemService(FingerprintManager.class); 95 } 96 return mFingerprintManager.getEnrollStageThreshold(index); 97 } 98 99 @Override 100 public Animator getHelpAnimator(@NonNull View target) { 101 final float translationX = 40; 102 final ObjectAnimator help = ObjectAnimator.ofFloat(target, 103 "translationX" /* propertyName */, 104 0, translationX, -1 * translationX, translationX, 0f); 105 help.setInterpolator(new AccelerateInterpolator()); 106 help.setDuration(HELP_ANIMATOR_DURATION); 107 help.setAutoCancel(false); 108 return help; 109 } 110 } 111