blob: 9033322069674e066d439f06dca7b7676cf172ad [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
36 protected int getLayoutResourceId() {
37 return R.layout.fingerprint_dialog;
38 }
39
40 @Override
41 protected int getHintStringResource() {
42 return R.string.fingerprint_dialog_touch_sensor;
43 }
44
45 @Override
46 protected float getAnimationTranslationOffset() {
47 return getResources()
48 .getDimension(R.dimen.fingerprint_dialog_animation_translation_offset);
49 }
50
51 @Override
52 protected void updateIcon(int lastState, int newState) {
53 Drawable icon = getAnimationForTransition(lastState, newState);
54
55 if (icon == null) {
56 Log.e(TAG, "Animation not found");
57 return;
58 }
59
60 final AnimatedVectorDrawable animation = icon instanceof AnimatedVectorDrawable
61 ? (AnimatedVectorDrawable) icon
62 : null;
63
64 final ImageView fingerprint_icon = getLayout().findViewById(R.id.fingerprint_icon);
65 fingerprint_icon.setImageDrawable(icon);
66
67 if (animation != null && shouldAnimateForTransition(lastState, newState)) {
68 animation.forceAnimationOnUI();
69 animation.start();
70 }
71 }
72
73 public FingerprintDialogView(Context context,
74 DialogViewCallback callback) {
75 super(context, callback);
76 }
77
78 private boolean shouldAnimateForTransition(int oldState, int newState) {
79 if (oldState == STATE_NONE && newState == STATE_AUTHENTICATING) {
80 return false;
81 } else if (oldState == STATE_AUTHENTICATING && newState == STATE_ERROR) {
82 return true;
83 } else if (oldState == STATE_ERROR && newState == STATE_AUTHENTICATING) {
84 return true;
85 } else if (oldState == STATE_AUTHENTICATING && newState == STATE_AUTHENTICATED) {
86 // TODO(b/77328470): add animation when fingerprint is authenticated
87 return false;
88 }
89 return false;
90 }
91
92 private Drawable getAnimationForTransition(int oldState, int newState) {
93 int iconRes;
94 if (oldState == STATE_NONE && newState == STATE_AUTHENTICATING) {
95 iconRes = R.drawable.fingerprint_dialog_fp_to_error;
96 } else if (oldState == STATE_AUTHENTICATING && newState == STATE_ERROR) {
97 iconRes = R.drawable.fingerprint_dialog_fp_to_error;
98 } else if (oldState == STATE_ERROR && newState == STATE_AUTHENTICATING) {
99 iconRes = R.drawable.fingerprint_dialog_error_to_fp;
100 } else if (oldState == STATE_AUTHENTICATING && newState == STATE_AUTHENTICATED) {
101 // TODO(b/77328470): add animation when fingerprint is authenticated
102 iconRes = R.drawable.fingerprint_dialog_error_to_fp;
103 } else {
104 return null;
105 }
106 return mContext.getDrawable(iconRes);
107 }
108}