what-the-bank/sources/com/kofax/kmc/kui/uicontrols/captureanimations/CaptureExperience.java

250 lines
9.7 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.kofax.kmc.kui.uicontrols.captureanimations;
import android.os.Handler;
import android.os.Looper;
import android.os.Vibrator;
import com.kofax.kmc.kui.uicontrols.AutoFocusResultEvent;
import com.kofax.kmc.kui.uicontrols.AutoFocusResultListener;
import com.kofax.kmc.kui.uicontrols.ImageCaptureView;
import com.kofax.kmc.kui.uicontrols.ImageCapturedEvent;
import com.kofax.kmc.kui.uicontrols.ImageCapturedListener;
import com.kofax.kmc.kui.uicontrols.LevelnessEvent;
import com.kofax.kmc.kui.uicontrols.LevelnessListener;
import com.kofax.kmc.kui.uicontrols.StabilityDelayEvent;
import com.kofax.kmc.kui.uicontrols.StabilityDelayListener;
import com.kofax.kmc.kut.utilities.error.ErrorInfo;
import com.kofax.kmc.kut.utilities.error.KmcRuntimeException;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
/* loaded from: classes3.dex */
public abstract class CaptureExperience implements AutoFocusResultListener, ImageCapturedListener, LevelnessListener, StabilityDelayListener {
protected float _aspectRatio;
protected boolean _continuousCapture;
protected ImageCaptureView _imageCaptureView;
protected final Object _lock;
protected boolean _sdkCaptureRequested;
protected Vibrator _vibrator;
private boolean ml;
private CaptureExperienceCriteriaHolder mm;
private int mn;
private int mo;
protected CaptureExperienceData _captureExperienceData = new CaptureExperienceData();
protected final Handler _uiHandler = new Handler(Looper.getMainLooper());
protected Set<ImageCapturedListener> _imageCapturedListeners = new LinkedHashSet();
protected boolean _vibrationEnabled = false;
abstract void b(CaptureExperienceData captureExperienceData);
protected abstract void removeAllViews();
/* JADX INFO: Access modifiers changed from: package-private */
public CaptureExperience(ImageCaptureView imageCaptureView) {
if (imageCaptureView == null) {
throw new KmcRuntimeException(ErrorInfo.KMC_GN_NULL_POINTER_EXCEPTION);
}
a((CaptureExperienceCriteriaHolder) null);
this._imageCaptureView = imageCaptureView;
this._lock = new Object();
addCameraEventListeners();
this._vibrator = (Vibrator) imageCaptureView.getContext().getSystemService("vibrator");
}
protected void addCameraEventListeners() {
this._imageCaptureView.addStabilityDelayListener(this);
this._imageCaptureView.addLevelnessListener(this);
this._imageCaptureView.addOnAutoFocusResultListener(this);
this._imageCaptureView.addOnImageCapturedListener(this);
}
protected void removeCameraEventListeners() {
this._imageCaptureView.removeStabilityDelayListener(this);
this._imageCaptureView.removeLevelnessListener(this);
this._imageCaptureView.removeOnAutoFocusResultListener(this);
this._imageCaptureView.removeOnImageCapturedListener(this);
}
void a(CaptureExperienceCriteriaHolder captureExperienceCriteriaHolder) {
if (captureExperienceCriteriaHolder == null) {
captureExperienceCriteriaHolder = new CaptureExperienceCriteriaHolder();
}
this.mm = captureExperienceCriteriaHolder;
}
final void a(CaptureExperienceData captureExperienceData) {
captureExperienceData.setSdkCaptureRequested(this._sdkCaptureRequested);
this._uiHandler.post(new Runnable(this, captureExperienceData) { // from class: com.kofax.kmc.kui.uicontrols.captureanimations.CaptureExperience.1
final CaptureExperienceData mp;
final CaptureExperience mq;
{
this.mq = this;
this.mp = captureExperienceData;
}
@Override // java.lang.Runnable
public void run() {
this.mq.b(this.mp);
}
});
synchronized (this._lock) {
if (this.ml && !this._sdkCaptureRequested && captureCriteriaMet(captureExperienceData)) {
captureExperienceData.setCriteriaMet(true);
captureExperienceData.setSdkCaptureRequested(true);
this._uiHandler.post(new Runnable(this, captureExperienceData) { // from class: com.kofax.kmc.kui.uicontrols.captureanimations.CaptureExperience.2
final CaptureExperienceData mp;
final CaptureExperience mq;
{
this.mq = this;
this.mp = captureExperienceData;
}
@Override // java.lang.Runnable
public void run() {
this.mq.b(this.mp);
}
});
this._sdkCaptureRequested = true;
this.ml = this._continuousCapture;
this._imageCaptureView.takePictureForCaptureExperience("com.kofax.kmc.kui.uicontrols.", this.mm.isRefocusBeforeCaptureEnabled());
}
}
}
protected boolean captureCriteriaMet(CaptureExperienceData captureExperienceData) {
if (!captureCriteriaMetInternal(captureExperienceData)) {
captureExperienceData.setCriteriaMet(false);
return false;
}
return c(captureExperienceData);
}
public void addOnImageCapturedListener(ImageCapturedListener imageCapturedListener) {
if (imageCapturedListener != null) {
this._imageCapturedListeners.add(imageCapturedListener);
}
}
public void removeOnImageCapturedListener(ImageCapturedListener imageCapturedListener) {
this._imageCapturedListeners.remove(imageCapturedListener);
}
public void takePicture() {
d(false);
}
public void takePictureContinually() {
d(true);
}
private void d(boolean z) {
CaptureExperienceData captureExperienceData = new CaptureExperienceData();
this._captureExperienceData = captureExperienceData;
this._sdkCaptureRequested = false;
this.mn = 0;
b(captureExperienceData);
synchronized (this._lock) {
this._continuousCapture = z;
this.ml = true;
}
}
public void stopCapture() {
this._captureExperienceData = new CaptureExperienceData();
this.ml = false;
}
@Override // com.kofax.kmc.kui.uicontrols.ImageCapturedListener
public void onImageCaptured(ImageCapturedEvent imageCapturedEvent) {
CaptureExperienceData captureExperienceData = new CaptureExperienceData(this._captureExperienceData);
this._captureExperienceData = captureExperienceData;
this.mn = 0;
captureExperienceData.setDocumentDetectionGuidanceList(null);
a(this._captureExperienceData);
synchronized (this._lock) {
this._sdkCaptureRequested = false;
}
if (this._vibrationEnabled) {
try {
this._vibrator.vibrate(500L);
} catch (Exception unused) {
}
}
}
protected void invokeImageCapturedListeners(ImageCapturedEvent imageCapturedEvent) {
Iterator<ImageCapturedListener> it = this._imageCapturedListeners.iterator();
while (it.hasNext()) {
it.next().onImageCaptured(imageCapturedEvent);
}
}
@Override // com.kofax.kmc.kui.uicontrols.AutoFocusResultListener
public void onAutoFocus(AutoFocusResultEvent autoFocusResultEvent) {
this._captureExperienceData.setFocused(autoFocusResultEvent.getSuccess());
a(this._captureExperienceData);
}
@Override // com.kofax.kmc.kui.uicontrols.LevelnessListener
public void onLevelness(LevelnessEvent levelnessEvent) {
this._captureExperienceData.setPitch(Math.abs(levelnessEvent.getPitch()));
this._captureExperienceData.setRoll(Math.abs(levelnessEvent.getRoll()));
a(this._captureExperienceData);
}
@Override // com.kofax.kmc.kui.uicontrols.StabilityDelayListener
public void onStabilityDelay(StabilityDelayEvent stabilityDelayEvent) {
this._captureExperienceData.setStability(stabilityDelayEvent.getStability());
a(this._captureExperienceData);
}
boolean c(CaptureExperienceData captureExperienceData) {
if (!this.mm.isStabilityThresholdEnabled()) {
return true;
}
this.mn++;
int stability = this.mo + captureExperienceData.getStability();
this.mo = stability;
int i = this.mn;
if (i >= 6) {
int stabilityThreshold = (stability / i) - this.mm.getStabilityThreshold();
this.mo = 0;
this.mn = 0;
if (stabilityThreshold > 0) {
return true;
}
}
return false;
}
protected boolean captureCriteriaMetInternal(CaptureExperienceData captureExperienceData) {
if (this.mm.isFocusEnabled() && !captureExperienceData.isFocused()) {
return false;
}
if (!this.mm.isPitchThresholdEnabled() || this.mm.getPitchThreshold() == 45 || this.mm.getPitchThreshold() >= captureExperienceData.getPitch()) {
return !this.mm.isRollThresholdEnabled() || this.mm.getRollThreshold() == 45 || this.mm.getRollThreshold() >= captureExperienceData.getRoll();
}
return false;
}
public void destroy() {
removeCameraEventListeners();
removeAllViews();
CaptureExperienceData captureExperienceData = this._captureExperienceData;
if (captureExperienceData != null) {
captureExperienceData.setDocumentDetectionGuidanceList(null);
this._captureExperienceData = null;
}
}
public void setVibrationEnabled(boolean z) {
this._vibrationEnabled = z;
}
public boolean isVibrationEnabled() {
return this._vibrationEnabled;
}
}