blob: 38a69a90f0bb550a1bf61be3ac178a7c9e7fc39b [file] [log] [blame]
Kevin Chyn0be1f332018-09-18 18:15:16 -07001/*
2 * Copyright (C) 2018 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
17package com.android.systemui.biometrics;
18
19import android.content.Context;
20import android.graphics.drawable.AnimatedVectorDrawable;
21import android.graphics.drawable.Drawable;
22import android.util.Log;
23import android.widget.ImageView;
24
25import com.android.systemui.R;
26
27/**
28 * This class loads the view for the system-provided dialog. The view consists of:
29 * Application Icon, Title, Subtitle, Description, Fingerprint Icon, Error/Help message area,
30 * and positive/negative buttons.
31 */
32public class FingerprintDialogView extends BiometricDialogView {
33 private static final String TAG = "FingerprintDialogView";
34
35 @Override
Kevin Chyn6cf54e82018-09-18 19:13:27 -070036 protected int getHintStringResourceId() {
Kevin Chyn0be1f332018-09-18 18:15:16 -070037 return R.string.fingerprint_dialog_touch_sensor;
38 }
39
40 @Override
Kevin Chyn6cf54e82018-09-18 19:13:27 -070041 protected int getAuthenticatedAccessibilityResourceId() {
42 return com.android.internal.R.string.fingerprint_authenticated;
43 }
44
45 @Override
46 protected int getIconDescriptionResourceId() {
47 return R.string.accessibility_fingerprint_dialog_fingerprint_icon;
Kevin Chyn0be1f332018-09-18 18:15:16 -070048 }
49
50 @Override
51 protected void updateIcon(int lastState, int newState) {
52 Drawable icon = getAnimationForTransition(lastState, newState);
53
54 if (icon == null) {
55 Log.e(TAG, "Animation not found");
56 return;
57 }
58
59 final AnimatedVectorDrawable animation = icon instanceof AnimatedVectorDrawable
60 ? (AnimatedVectorDrawable) icon
61 : null;
62
Kevin Chyn6cf54e82018-09-18 19:13:27 -070063 final ImageView fingerprintIcon = getLayout().findViewById(R.id.biometric_icon);
64 fingerprintIcon.setImageDrawable(icon);
Kevin Chyn0be1f332018-09-18 18:15:16 -070065
66 if (animation != null && shouldAnimateForTransition(lastState, newState)) {
67 animation.forceAnimationOnUI();
68 animation.start();
69 }
70 }
71
72 public FingerprintDialogView(Context context,
73 DialogViewCallback callback) {
74 super(context, callback);
75 }
76
77 private boolean shouldAnimateForTransition(int oldState, int newState) {
78 if (oldState == STATE_NONE && newState == STATE_AUTHENTICATING) {
79 return false;
80 } else if (oldState == STATE_AUTHENTICATING && newState == STATE_ERROR) {
81 return true;
82 } else if (oldState == STATE_ERROR && newState == STATE_AUTHENTICATING) {
83 return true;
84 } else if (oldState == STATE_AUTHENTICATING && newState == STATE_AUTHENTICATED) {
85 // TODO(b/77328470): add animation when fingerprint is authenticated
86 return false;
87 }
88 return false;
89 }
90
91 private Drawable getAnimationForTransition(int oldState, int newState) {
92 int iconRes;
93 if (oldState == STATE_NONE && newState == STATE_AUTHENTICATING) {
94 iconRes = R.drawable.fingerprint_dialog_fp_to_error;
95 } else if (oldState == STATE_AUTHENTICATING && newState == STATE_ERROR) {
96 iconRes = R.drawable.fingerprint_dialog_fp_to_error;
97 } else if (oldState == STATE_ERROR && newState == STATE_AUTHENTICATING) {
98 iconRes = R.drawable.fingerprint_dialog_error_to_fp;
99 } else if (oldState == STATE_AUTHENTICATING && newState == STATE_AUTHENTICATED) {
100 // TODO(b/77328470): add animation when fingerprint is authenticated
101 iconRes = R.drawable.fingerprint_dialog_error_to_fp;
102 } else {
103 return null;
104 }
105 return mContext.getDrawable(iconRes);
106 }
107}