Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Commit 876b92f

Browse files
authored
Merge pull request #8 from stone-ton/feat/16086/manual-capture
feat: add timeout to force manual capture on error
2 parents 48b2d3c + cfebc7c commit 876b92f

File tree

3 files changed

+74
-12
lines changed

3 files changed

+74
-12
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
applicationId "com.example.camerabioexample_android"
77
minSdkVersion 19
88
targetSdkVersion 28
9-
versionCode 6
10-
versionName "2.3.2"
9+
versionCode 7
10+
versionName "2.4.0"
1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1212
vectorDrawables.useSupportLibrary = true
1313
}

app/src/main/java/com/example/camerabioexample_android/camerabiomanager/SelfieActivity.java

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class SelfieActivity extends Camera2Base implements ImageProcessor, Captu
5959
"Gire um pouco a direita",
6060
"Rosto não identificado",
6161
"Rosto inclinado"} ;
62+
private final String manualCaptureMessage = "Pressione o botão para tirar a foto";
6263

6364
private int erroIndex = -1;
6465
private boolean faceOK = true;
@@ -137,6 +138,9 @@ public class SelfieActivity extends Camera2Base implements ImageProcessor, Captu
137138
private Boolean autoCapture;
138139
private Boolean countRegressive;
139140

141+
// contador de erro
142+
private CountDownTimer errorCountDownTimer;
143+
private Boolean forcedManualCapture = Boolean.FALSE;
140144

141145
private static CameraBioManager cameraBioManager;
142146

@@ -354,7 +358,6 @@ else if (diffNose < noseRange || diffNose > maxDiffNose) {
354358
}
355359
else {
356360
markRed();
357-
takePictureImageButton.setEnabled(false);
358361
}
359362
// exibe as grides em tela (caso ativo)
360363
if (showLines) {
@@ -368,20 +371,20 @@ else if (diffNose < noseRange || diffNose > maxDiffNose) {
368371
else {
369372
erroIndex = 7;
370373
markRed();
371-
takePictureImageButton.setEnabled(false);
372374
}
373375
}
374376
else {
375377
erroIndex = 7;
376378
markRed();
377-
takePictureImageButton.setEnabled(false);
378379
}
379380

380381
runOnUiThread(new Runnable() {
381382
@Override
382383
public void run() {
383384

384-
if (erroIndex != -1) {
385+
if (erroIndex != -1 && forcedManualCapture) {
386+
showFastToast(manualCaptureMessage);
387+
} else if (erroIndex != -1) {
385388
showFastToast(mensagens[erroIndex]);
386389
} else if (toast != null) {
387390
toast.cancel();
@@ -439,6 +442,32 @@ public void onFinish() {
439442
}
440443
}
441444

445+
private void destroyErrorTimer () {
446+
if (errorCountDownTimer != null) {
447+
errorCountDownTimer.cancel();
448+
errorCountDownTimer = null;
449+
}
450+
}
451+
452+
private void createErrorTimer () {
453+
if (errorCountDownTimer == null && !forcedManualCapture) {
454+
takePictureImageButton.setEnabled(false);
455+
errorCountDownTimer = new CountDownTimer(5000, 1000) {
456+
457+
public void onTick(long millisUntilFinished) {}
458+
459+
public void onFinish() {
460+
autoCapture = Boolean.FALSE;
461+
forcedManualCapture = Boolean.TRUE;
462+
takePictureImageButton.setEnabled(true);
463+
markBlue();
464+
}
465+
466+
};
467+
errorCountDownTimer.start();
468+
}
469+
}
470+
442471
private void autoCapture () {
443472

444473
if(countDownTimer == null && isRequestImage == false) {
@@ -469,6 +498,7 @@ public static float convertDpToPixel(float dp, Context context){
469498
}
470499

471500
private void markBlue() {
501+
destroyErrorTimer();
472502

473503
erroIndex =-1;
474504

@@ -492,8 +522,9 @@ else if (autoCapture) {
492522

493523
private void markRed() {
494524
destroyTimer();
525+
createErrorTimer();
495526

496-
if (!countDownCancelled[0]) {
527+
if (!countDownCancelled[0] && !forcedManualCapture) {
497528
int size = 18;
498529
if (screenWidth > 1600) {
499530
size = 34;

camerabioandroid/src/main/java/com/example/camerabioandroid/camerabiomanager/SelfieActivity.java

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class SelfieActivity extends Camera2Base implements ImageProcessor, Captu
5656
"Gire um pouco a direita",
5757
"Rosto não identificado",
5858
"Rosto inclinado"} ;
59+
private final String manualCaptureMessage = "Pressione o botão para tirar a foto";
5960

6061
private int erroIndex = -1;
6162
private boolean faceOK = true;
@@ -134,6 +135,9 @@ public class SelfieActivity extends Camera2Base implements ImageProcessor, Captu
134135
private Boolean autoCapture;
135136
private Boolean countRegressive;
136137

138+
// contador de erro
139+
private CountDownTimer errorCountDownTimer;
140+
private Boolean forcedManualCapture = Boolean.FALSE;
137141

138142
private static CameraBioManager cameraBioManager;
139143

@@ -349,7 +353,6 @@ else if (diffNose < noseRange || diffNose > maxDiffNose) {
349353
}
350354
else {
351355
markRed();
352-
takePictureImageButton.setEnabled(false);
353356
}
354357
// exibe as grides em tela (caso ativo)
355358
if (showLines) {
@@ -363,20 +366,20 @@ else if (diffNose < noseRange || diffNose > maxDiffNose) {
363366
else {
364367
erroIndex = 7;
365368
markRed();
366-
takePictureImageButton.setEnabled(false);
367369
}
368370
}
369371
else {
370372
erroIndex = 7;
371373
markRed();
372-
takePictureImageButton.setEnabled(false);
373374
}
374375

375376
runOnUiThread(new Runnable() {
376377
@Override
377378
public void run() {
378379

379-
if (erroIndex != -1) {
380+
if (erroIndex != -1 && forcedManualCapture) {
381+
showFastToast(manualCaptureMessage);
382+
} else if (erroIndex != -1) {
380383
showFastToast(mensagens[erroIndex]);
381384
} else if (toast != null) {
382385
toast.cancel();
@@ -434,6 +437,32 @@ public void onFinish() {
434437
}
435438
}
436439

440+
private void destroyErrorTimer () {
441+
if (errorCountDownTimer != null) {
442+
errorCountDownTimer.cancel();
443+
errorCountDownTimer = null;
444+
}
445+
}
446+
447+
private void createErrorTimer () {
448+
if (errorCountDownTimer == null && !forcedManualCapture) {
449+
takePictureImageButton.setEnabled(false);
450+
errorCountDownTimer = new CountDownTimer(5000, 1000) {
451+
452+
public void onTick(long millisUntilFinished) {}
453+
454+
public void onFinish() {
455+
autoCapture = Boolean.FALSE;
456+
forcedManualCapture = Boolean.TRUE;
457+
takePictureImageButton.setEnabled(true);
458+
markBlue();
459+
}
460+
461+
};
462+
errorCountDownTimer.start();
463+
}
464+
}
465+
437466
private void autoCapture () {
438467

439468
if(countDownTimer == null && isRequestImage == false) {
@@ -464,6 +493,7 @@ public static float convertDpToPixel(float dp, Context context){
464493
}
465494

466495
private void markBlue() {
496+
destroyErrorTimer();
467497

468498
erroIndex =-1;
469499

@@ -487,8 +517,9 @@ else if (autoCapture) {
487517

488518
private void markRed() {
489519
destroyTimer();
520+
createErrorTimer();
490521

491-
if (!countDownCancelled[0]) {
522+
if (!countDownCancelled[0] && !forcedManualCapture) {
492523
int size = 18;
493524
if (screenWidth > 1600) {
494525
size = 34;

0 commit comments

Comments
 (0)