This repository has been archived by the owner on Feb 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
/
MainActivity.java
executable file
·163 lines (136 loc) · 5.06 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package com.github.ajalt.reprint;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.TextView;
import com.github.ajalt.reprint.core.AuthenticationFailureReason;
import com.github.ajalt.reprint.core.AuthenticationListener;
import com.github.ajalt.reprint.core.Reprint;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
@SuppressLint("SetTextI18n")
public class MainActivity extends AppCompatActivity {
@BindView(R.id.fab)
FloatingActionButton fab;
@BindView(R.id.result)
TextView result;
@BindView(R.id.hardware_present)
TextView hardwarePresent;
@BindView(R.id.fingerprints_registered)
TextView fingerprintsRegistered;
@BindView(R.id.radio_callbacks)
CompoundButton radioCallbacks;
@BindView(R.id.radio_rxjava1)
CompoundButton radioRxJava1;
@BindView(R.id.radio_rxjava2)
CompoundButton radioRxJava2;
@BindView(R.id.toolbar)
Toolbar toolbar;
private boolean running;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
hardwarePresent.setText(String.valueOf(Reprint.isHardwarePresent()));
fingerprintsRegistered.setText(String.valueOf(Reprint.hasFingerprintRegistered()));
running = false;
}
@Override
protected void onPause() {
super.onPause();
cancel();
}
@OnClick(R.id.fab)
public void onFabClick() {
if (running) {
cancel();
} else {
start();
}
}
private void start() {
running = true;
result.setText("Listening");
fab.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_close_white_24dp));
if (radioCallbacks.isChecked()) {
startTraditional();
} else if (radioRxJava1.isChecked()) {
startRxJava1();
} else if (radioRxJava2.isChecked()) {
startRxJava2();
} else {
throw new IllegalStateException();
}
}
private void startTraditional() {
Reprint.authenticate(new AuthenticationListener() {
@Override
public void onSuccess(int moduleTag) {
showSuccess();
}
@Override
public void onFailure(AuthenticationFailureReason failureReason, boolean fatal,
CharSequence errorMessage, int moduleTag, int errorCode) {
showError(failureReason, fatal, errorMessage, errorCode);
}
});
}
private void startRxJava1() {
com.github.ajalt.reprint.rxjava.RxReprint.authenticate()
.subscribe(res -> {
switch (res.status) {
case SUCCESS:
showSuccess();
break;
case NONFATAL_FAILURE:
showError(res.failureReason, false, res.errorMessage, res.errorCode);
break;
case FATAL_FAILURE:
showError(res.failureReason, true, res.errorMessage, res.errorCode);
break;
}
});
}
private void startRxJava2() {
com.github.ajalt.reprint.rxjava2.RxReprint.authenticate()
.subscribe(res -> {
switch (res.status) {
case SUCCESS:
showSuccess();
break;
case NONFATAL_FAILURE:
showError(res.failureReason, false, res.errorMessage, res.errorCode);
break;
case FATAL_FAILURE:
showError(res.failureReason, true, res.errorMessage, res.errorCode);
break;
}
});
}
private void cancel() {
result.setText("Cancelled");
running = false;
fab.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_fingerprint_white_24dp));
Reprint.cancelAuthentication();
}
private void showSuccess() {
result.setText("Success");
fab.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_fingerprint_white_24dp));
running = false;
}
private void showError(AuthenticationFailureReason failureReason, boolean fatal,
CharSequence errorMessage, int errorCode) {
result.setText(errorMessage);
if (fatal) {
fab.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_fingerprint_white_24dp));
running = false;
}
}
}