Skip to content

Commit

Permalink
Merge pull request #8 from stone-ton/feat/16086/manual-capture
Browse files Browse the repository at this point in the history
feat: add timeout to force manual capture on error
  • Loading branch information
Kazzel authored Dec 17, 2021
2 parents 48b2d3c + cfebc7c commit 876b92f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.example.camerabioexample_android"
minSdkVersion 19
targetSdkVersion 28
versionCode 6
versionName "2.3.2"
versionCode 7
versionName "2.4.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class SelfieActivity extends Camera2Base implements ImageProcessor, Captu
"Gire um pouco a direita",
"Rosto não identificado",
"Rosto inclinado"} ;
private final String manualCaptureMessage = "Pressione o botão para tirar a foto";

private int erroIndex = -1;
private boolean faceOK = true;
Expand Down Expand Up @@ -137,6 +138,9 @@ public class SelfieActivity extends Camera2Base implements ImageProcessor, Captu
private Boolean autoCapture;
private Boolean countRegressive;

// contador de erro
private CountDownTimer errorCountDownTimer;
private Boolean forcedManualCapture = Boolean.FALSE;

private static CameraBioManager cameraBioManager;

Expand Down Expand Up @@ -354,7 +358,6 @@ else if (diffNose < noseRange || diffNose > maxDiffNose) {
}
else {
markRed();
takePictureImageButton.setEnabled(false);
}
// exibe as grides em tela (caso ativo)
if (showLines) {
Expand All @@ -368,20 +371,20 @@ else if (diffNose < noseRange || diffNose > maxDiffNose) {
else {
erroIndex = 7;
markRed();
takePictureImageButton.setEnabled(false);
}
}
else {
erroIndex = 7;
markRed();
takePictureImageButton.setEnabled(false);
}

runOnUiThread(new Runnable() {
@Override
public void run() {

if (erroIndex != -1) {
if (erroIndex != -1 && forcedManualCapture) {
showFastToast(manualCaptureMessage);
} else if (erroIndex != -1) {
showFastToast(mensagens[erroIndex]);
} else if (toast != null) {
toast.cancel();
Expand Down Expand Up @@ -439,6 +442,32 @@ public void onFinish() {
}
}

private void destroyErrorTimer () {
if (errorCountDownTimer != null) {
errorCountDownTimer.cancel();
errorCountDownTimer = null;
}
}

private void createErrorTimer () {
if (errorCountDownTimer == null && !forcedManualCapture) {
takePictureImageButton.setEnabled(false);
errorCountDownTimer = new CountDownTimer(5000, 1000) {

public void onTick(long millisUntilFinished) {}

public void onFinish() {
autoCapture = Boolean.FALSE;
forcedManualCapture = Boolean.TRUE;
takePictureImageButton.setEnabled(true);
markBlue();
}

};
errorCountDownTimer.start();
}
}

private void autoCapture () {

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

private void markBlue() {
destroyErrorTimer();

erroIndex =-1;

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

private void markRed() {
destroyTimer();
createErrorTimer();

if (!countDownCancelled[0]) {
if (!countDownCancelled[0] && !forcedManualCapture) {
int size = 18;
if (screenWidth > 1600) {
size = 34;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class SelfieActivity extends Camera2Base implements ImageProcessor, Captu
"Gire um pouco a direita",
"Rosto não identificado",
"Rosto inclinado"} ;
private final String manualCaptureMessage = "Pressione o botão para tirar a foto";

private int erroIndex = -1;
private boolean faceOK = true;
Expand Down Expand Up @@ -134,6 +135,9 @@ public class SelfieActivity extends Camera2Base implements ImageProcessor, Captu
private Boolean autoCapture;
private Boolean countRegressive;

// contador de erro
private CountDownTimer errorCountDownTimer;
private Boolean forcedManualCapture = Boolean.FALSE;

private static CameraBioManager cameraBioManager;

Expand Down Expand Up @@ -349,7 +353,6 @@ else if (diffNose < noseRange || diffNose > maxDiffNose) {
}
else {
markRed();
takePictureImageButton.setEnabled(false);
}
// exibe as grides em tela (caso ativo)
if (showLines) {
Expand All @@ -363,20 +366,20 @@ else if (diffNose < noseRange || diffNose > maxDiffNose) {
else {
erroIndex = 7;
markRed();
takePictureImageButton.setEnabled(false);
}
}
else {
erroIndex = 7;
markRed();
takePictureImageButton.setEnabled(false);
}

runOnUiThread(new Runnable() {
@Override
public void run() {

if (erroIndex != -1) {
if (erroIndex != -1 && forcedManualCapture) {
showFastToast(manualCaptureMessage);
} else if (erroIndex != -1) {
showFastToast(mensagens[erroIndex]);
} else if (toast != null) {
toast.cancel();
Expand Down Expand Up @@ -434,6 +437,32 @@ public void onFinish() {
}
}

private void destroyErrorTimer () {
if (errorCountDownTimer != null) {
errorCountDownTimer.cancel();
errorCountDownTimer = null;
}
}

private void createErrorTimer () {
if (errorCountDownTimer == null && !forcedManualCapture) {
takePictureImageButton.setEnabled(false);
errorCountDownTimer = new CountDownTimer(5000, 1000) {

public void onTick(long millisUntilFinished) {}

public void onFinish() {
autoCapture = Boolean.FALSE;
forcedManualCapture = Boolean.TRUE;
takePictureImageButton.setEnabled(true);
markBlue();
}

};
errorCountDownTimer.start();
}
}

private void autoCapture () {

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

private void markBlue() {
destroyErrorTimer();

erroIndex =-1;

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

private void markRed() {
destroyTimer();
createErrorTimer();

if (!countDownCancelled[0]) {
if (!countDownCancelled[0] && !forcedManualCapture) {
int size = 18;
if (screenWidth > 1600) {
size = 34;
Expand Down

0 comments on commit 876b92f

Please sign in to comment.