Alan Viverette | 3da604b | 2020-06-10 18:34:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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.systemui.biometrics; |
| 18 | |
| 19 | |
| 20 | import android.content.Context; |
| 21 | import android.graphics.drawable.AnimatedVectorDrawable; |
| 22 | import android.graphics.drawable.Drawable; |
| 23 | import android.util.AttributeSet; |
| 24 | import android.util.Log; |
| 25 | |
| 26 | import com.android.systemui.R; |
| 27 | |
| 28 | public class AuthBiometricFingerprintView extends AuthBiometricView { |
| 29 | |
| 30 | private static final String TAG = "BiometricPrompt/AuthBiometricFingerprintView"; |
| 31 | |
| 32 | public AuthBiometricFingerprintView(Context context) { |
| 33 | this(context, null); |
| 34 | } |
| 35 | |
| 36 | public AuthBiometricFingerprintView(Context context, AttributeSet attrs) { |
| 37 | super(context, attrs); |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | protected int getDelayAfterAuthenticatedDurationMs() { |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | protected int getStateForAfterError() { |
| 47 | return STATE_AUTHENTICATING; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | protected void handleResetAfterError() { |
| 52 | showTouchSensorString(); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | protected void handleResetAfterHelp() { |
| 57 | showTouchSensorString(); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | protected boolean supportsSmallDialog() { |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public void updateState(@BiometricState int newState) { |
| 67 | updateIcon(mState, newState); |
| 68 | |
| 69 | // Do this last since the state variable gets updated. |
| 70 | super.updateState(newState); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | void onAttachedToWindowInternal() { |
| 75 | super.onAttachedToWindowInternal(); |
| 76 | showTouchSensorString(); |
| 77 | } |
| 78 | |
| 79 | private void showTouchSensorString() { |
| 80 | mIndicatorView.setText(R.string.fingerprint_dialog_touch_sensor); |
| 81 | mIndicatorView.setTextColor(R.color.biometric_dialog_gray); |
| 82 | } |
| 83 | |
| 84 | private void updateIcon(int lastState, int newState) { |
| 85 | final Drawable icon = getAnimationForTransition(lastState, newState); |
| 86 | if (icon == null) { |
| 87 | Log.e(TAG, "Animation not found, " + lastState + " -> " + newState); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | final AnimatedVectorDrawable animation = icon instanceof AnimatedVectorDrawable |
| 92 | ? (AnimatedVectorDrawable) icon |
| 93 | : null; |
| 94 | |
| 95 | mIconView.setImageDrawable(icon); |
| 96 | |
| 97 | if (animation != null && shouldAnimateForTransition(lastState, newState)) { |
| 98 | animation.forceAnimationOnUI(); |
| 99 | animation.start(); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | private boolean shouldAnimateForTransition(int oldState, int newState) { |
| 104 | switch (newState) { |
| 105 | case STATE_HELP: |
| 106 | case STATE_ERROR: |
| 107 | return true; |
| 108 | case STATE_AUTHENTICATING_ANIMATING_IN: |
| 109 | case STATE_AUTHENTICATING: |
| 110 | if (oldState == STATE_ERROR || oldState == STATE_HELP) { |
| 111 | return true; |
| 112 | } else { |
| 113 | return false; |
| 114 | } |
| 115 | case STATE_AUTHENTICATED: |
| 116 | return false; |
| 117 | default: |
| 118 | return false; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | private Drawable getAnimationForTransition(int oldState, int newState) { |
| 123 | int iconRes; |
| 124 | |
| 125 | switch (newState) { |
| 126 | case STATE_HELP: |
| 127 | case STATE_ERROR: |
| 128 | iconRes = R.drawable.fingerprint_dialog_fp_to_error; |
| 129 | break; |
| 130 | case STATE_AUTHENTICATING_ANIMATING_IN: |
| 131 | case STATE_AUTHENTICATING: |
| 132 | if (oldState == STATE_ERROR || oldState == STATE_HELP) { |
| 133 | iconRes = R.drawable.fingerprint_dialog_error_to_fp; |
| 134 | } else { |
| 135 | iconRes = R.drawable.fingerprint_dialog_fp_to_error; |
| 136 | } |
| 137 | break; |
| 138 | case STATE_AUTHENTICATED: |
| 139 | iconRes = R.drawable.fingerprint_dialog_fp_to_error; |
| 140 | break; |
| 141 | default: |
| 142 | return null; |
| 143 | } |
| 144 | |
| 145 | return mContext.getDrawable(iconRes); |
| 146 | } |
| 147 | } |