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

680 lines
22 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.kofax.kmc.kui.uicontrols;
import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.RelativeLayout;
import com.kofax.R;
import com.kofax.kmc.kui.uicontrols.data.CameraType;
import com.kofax.kmc.kui.uicontrols.data.Flash;
import com.kofax.kmc.kui.uicontrols.data.GpsUsageLimits;
import com.kofax.kmc.kut.utilities.Licensing;
import com.kofax.kmc.kut.utilities.Size;
import com.kofax.kmc.kut.utilities.error.ErrorInfo;
import com.kofax.kmc.kut.utilities.error.IllegalArgumentException;
import com.kofax.kmc.kut.utilities.error.KmcRuntimeException;
import com.kofax.mobile.sdk._internal.IBus;
import com.kofax.mobile.sdk._internal.camera.ICameraDelegate;
import com.kofax.mobile.sdk._internal.camera.d;
import com.kofax.mobile.sdk._internal.camera.f;
import com.kofax.mobile.sdk._internal.camera.q;
import com.kofax.mobile.sdk._internal.dagger.Injector;
import com.kofax.mobile.sdk._internal.impl.camera.h;
import com.kofax.mobile.sdk._internal.impl.event.SetFocusAreasRequestBusEvent;
import com.kofax.mobile.sdk._internal.impl.event.SurfaceChangedEvent;
import com.kofax.mobile.sdk._internal.impl.event.UseVideoChangedEvent;
import com.kofax.mobile.sdk._internal.impl.event.ad;
import com.kofax.mobile.sdk._internal.impl.event.af;
import com.kofax.mobile.sdk._internal.impl.event.ah;
import com.kofax.mobile.sdk._internal.impl.event.ai;
import com.kofax.mobile.sdk._internal.impl.event.aj;
import com.kofax.mobile.sdk._internal.impl.event.ak;
import com.kofax.mobile.sdk._internal.impl.event.al;
import com.kofax.mobile.sdk._internal.impl.event.aq;
import com.kofax.mobile.sdk._internal.impl.event.as;
import com.kofax.mobile.sdk._internal.impl.event.av;
import com.kofax.mobile.sdk._internal.impl.event.aw;
import com.kofax.mobile.sdk._internal.impl.event.az;
import com.kofax.mobile.sdk._internal.impl.event.bb;
import com.kofax.mobile.sdk._internal.impl.event.bc;
import com.kofax.mobile.sdk._internal.impl.event.c;
import com.kofax.mobile.sdk._internal.impl.event.e;
import com.kofax.mobile.sdk._internal.impl.event.m;
import com.kofax.mobile.sdk._internal.impl.event.r;
import com.kofax.mobile.sdk._internal.impl.event.s;
import com.kofax.mobile.sdk._internal.impl.event.t;
import com.kofax.mobile.sdk._internal.impl.event.v;
import com.kofax.mobile.sdk._internal.impl.event.y;
import com.kofax.mobile.sdk._internal.k;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import o.InterfaceC13004fNq;
import o.InterfaceC13006fNs;
import o.InterfaceC13391fZD;
@com.kofax.mobile.sdk._internal.dagger.a
/* loaded from: classes3.dex */
public class ImageCaptureView extends RelativeLayout implements SurfaceHolder.Callback, f {
public static final int DEFAULT_LUMINANCE_THRESHOLD = 100;
public static final int DEFAULT_TORCH_DELAY = 3;
private static final String TAG = "ImageCaptureView";
@InterfaceC13391fZD
protected IBus _bus;
private Context _ctx;
private CameraType kA;
private Flash kB;
private ICameraDelegate kC;
private List<Rect> kD;
private GpsUsageLimits kE;
private boolean kF;
private boolean kG;
private boolean kH;
private final ViewTreeObserver.OnGlobalLayoutListener kI;
private final List<View> kl;
private final a km;
@InterfaceC13391fZD
com.kofax.mobile.sdk._internal.impl.event.a kn;
@InterfaceC13391fZD
h ko;
@InterfaceC13391fZD
q kp;
@InterfaceC13391fZD
SurfaceView kq;
private d kr;
private int ks;
private int kt;
private int ku;
private int kv;
private int kw;
private int kx;
private int ky;
private int kz;
private void setHolderPushBuffers(SurfaceHolder surfaceHolder) {
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public ViewGroup getViewGroup() {
return this;
}
@Override // android.view.SurfaceHolder.Callback
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
}
@InterfaceC13391fZD
public ImageCaptureView(Context context) {
this(context, null, 0);
}
public ImageCaptureView(Context context, AttributeSet attributeSet) {
this(context, attributeSet, 0);
}
public ImageCaptureView(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
this.kl = new ArrayList();
this.km = new a();
this.kr = null;
this.ks = 0;
this.kt = 0;
this.ky = 100;
this.kz = 3;
this.kA = CameraType.BACK_CAMERA;
this.kB = Flash.OFF;
this.kC = null;
this.kE = GpsUsageLimits.ALWAYS_USE_IF_ENABLED;
this.kI = new ViewTreeObserver.OnGlobalLayoutListener(this) { // from class: com.kofax.kmc.kui.uicontrols.ImageCaptureView.1
final ImageCaptureView kJ;
{
this.kJ = this;
}
@Override // android.view.ViewTreeObserver.OnGlobalLayoutListener
public void onGlobalLayout() {
boolean isShown = this.kJ.isShown();
if (isShown) {
if (!this.kJ.kG) {
this.kJ.kG = isShown;
ImageCaptureView imageCaptureView = this.kJ;
imageCaptureView.a(imageCaptureView.kq.getHolder());
}
} else if (this.kJ.kG) {
this.kJ.an();
}
this.kJ.kG = isShown;
}
};
this._ctx = context;
if (isInEditMode()) {
this.kn = null;
this.ko = null;
this.kq = null;
} else {
ai();
checkLicense();
this.ko.r(false);
setBackgroundColor(-16777216);
}
}
void ai() {
Injector.getInjector(getContext()).injectMembers(this);
}
public final int getImagePreviewWidth() {
Point jA = this.ko.jA();
if (jA == null) {
return 0;
}
return jA.x;
}
public final int getImagePreviewHeight() {
Point jA = this.ko.jA();
if (jA == null) {
return 0;
}
return jA.y;
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void setFlash(Flash flash) {
if (flash == null) {
throw new IllegalArgumentException("setFlash(Flash flash) method: 'flash' parameter is null.");
}
this.kB = flash;
if (isFlashSupported(flash)) {
this.ko.setFlash(flash);
this._bus.post(new y(this.kB));
}
}
public final boolean isFlashSupported(Flash flash) {
if (flash == null) {
throw new IllegalArgumentException("flash is null");
}
return this.ko.isFlashSupported(flash);
}
public final void setGpsUsage(GpsUsageLimits gpsUsageLimits) {
this.kE = gpsUsageLimits;
this._bus.post(new af(gpsUsageLimits));
}
public final void setImageResolution(Size size) {
setImageResolutionInternal(size);
}
private void setImageResolutionInternal(Size size) {
if (this.ko.a(size)) {
requestLayout();
if (this.kF) {
invalidate();
}
}
}
public final List<Size> getAllowableImageResolutions() {
return this.ko.jz();
}
public final void setFocusAreas(List<Rect> list) throws KmcRuntimeException {
this.kD = list;
this.ko.c(list, getWidth(), getHeight());
this.ko.jC();
}
public final int getMaxFocusAreas() {
d dVar = this.kr;
if (dVar == null) {
return 0;
}
try {
return dVar.getMaxNumFocusAreas();
} catch (Exception unused) {
return 0;
}
}
public final boolean getUseVideoFrame() {
return this.ko.jB();
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void setUseVideoFrame(boolean z) {
if (this.ko.r(z)) {
this._bus.post(new UseVideoChangedEvent(z));
}
}
public final void setDeviceDeclinationPitch(int i) {
if (-180 <= i && i <= 180) {
this.ks = i;
}
this._bus.post(new s(i));
}
public final void setDeviceDeclinationRoll(int i) {
if (-180 <= i && i <= 180) {
this.kt = i;
}
this._bus.post(new t(i));
}
public final void setLuminanceThreshold(int i) {
if (i <= 0) {
throw new IllegalArgumentException(this._ctx.getString(R.string.ICV_InvalidLuminanceThresholdParameter));
}
this.ky = i;
this._bus.post(new ak(i));
}
public final void setTorchDelay(int i) {
if (i <= 0) {
throw new IllegalArgumentException(this._ctx.getString(R.string.ICV_InvalidTorchDelayParameter));
}
this.kz = i;
this._bus.post(new bb(i));
}
public final void muteAutoTorch() {
this._bus.post(new al(true));
}
public final void unmuteAutoTorch() {
this._bus.post(new al(false));
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void forceTakePicture() {
forceTakePicture(false);
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void forceTakePicture(boolean z) {
ICameraDelegate iCameraDelegate = this.kC;
if (iCameraDelegate != null) {
iCameraDelegate.forceTakePicture(z);
} else {
this._bus.post(new ad(false, z));
}
}
public final void sessionCreate() {
synchronized (this) {
this._bus.post(new av());
}
}
public final void sessionDismiss() {
synchronized (this) {
this._bus.post(new aw());
}
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void takePictureForCaptureExperience(String str) {
takePictureForCaptureExperience(str, false);
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void takePictureForCaptureExperience(String str, boolean z) {
l(str);
this._bus.post(new ad(true, z));
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public void forceTakePictureForCaptureExperience(String str, boolean z) {
l(str);
this._bus.post(new ad(false, z));
}
private void l(String str) {
if (!str.startsWith("com.kofax.kmc.kui.uicontrols.")) {
throw new KmcRuntimeException(ErrorInfo.KMC_GN_UNSUPPORTED_OPERATION);
}
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void addOnAutoFocusResultListener(AutoFocusResultListener autoFocusResultListener) {
this.kn.a(new e(autoFocusResultListener));
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void removeOnAutoFocusResultListener(AutoFocusResultListener autoFocusResultListener) {
this.kn.a(autoFocusResultListener, AutoFocusResultListener.class);
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void addOnImageCapturedListener(ImageCapturedListener imageCapturedListener) {
this.kn.a(new ah(imageCapturedListener));
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void removeOnImageCapturedListener(ImageCapturedListener imageCapturedListener) {
this.kn.a(imageCapturedListener, ImageCapturedListener.class);
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void addStabilityDelayListener(StabilityDelayListener stabilityDelayListener) {
this.kn.a(new az(stabilityDelayListener));
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void removeStabilityDelayListener(StabilityDelayListener stabilityDelayListener) {
this.kn.a(stabilityDelayListener, StabilityDelayListener.class);
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void addLevelnessListener(LevelnessListener levelnessListener) {
this.kn.a(new ai(levelnessListener));
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void removeLevelnessListener(LevelnessListener levelnessListener) {
this.kn.a(levelnessListener, LevelnessListener.class);
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void addCameraInitializationListener(CameraInitializationListener cameraInitializationListener) {
this.kn.a(new com.kofax.mobile.sdk._internal.impl.event.f(cameraInitializationListener));
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void removeCameraInitializationListener(CameraInitializationListener cameraInitializationListener) {
this.kn.a(cameraInitializationListener, CameraInitializationListener.class);
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void addCameraInitializationFailedListener(CameraInitializationFailedListener cameraInitializationFailedListener) {
this.kn.a(new com.kofax.mobile.sdk._internal.impl.event.h(cameraInitializationFailedListener));
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void removeCameraInitializationFailedListener(CameraInitializationFailedListener cameraInitializationFailedListener) {
this.kn.a(cameraInitializationFailedListener, CameraInitializationFailedListener.class);
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void addPreviewCallbackListener(PreviewCallbackListener previewCallbackListener) {
this.kn.a(new as(previewCallbackListener));
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public final void removePreviewCallbackListener(PreviewCallbackListener previewCallbackListener) {
this.kn.a(previewCallbackListener, PreviewCallbackListener.class);
}
public final void addTorchLuminanceListener(TorchLuminanceListener torchLuminanceListener) {
this.kn.a(new bc(torchLuminanceListener));
}
public final void removeTorchLuminanceListener(TorchLuminanceListener torchLuminanceListener) {
this.kn.a(torchLuminanceListener, TorchLuminanceListener.class);
}
protected void checkLicense() {
if (!am() && !Licensing.isSdkLicensed(Licensing.LicenseType.IMAGE_CAPTURE)) {
throw new KmcRuntimeException(ErrorInfo.KMC_UT_LICENSE_IMAGE_CAPTURE);
}
}
private boolean am() {
String property = System.getProperty("os.name");
return property.equalsIgnoreCase("Mac OS X") || property.contains("Windows");
}
@Override // android.view.ViewGroup
public void removeAllViews() {
this.kl.clear();
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
this.kl.add(getChildAt(i));
}
for (View view : this.kl) {
if (view != this.kq) {
removeView(view);
}
}
}
@Override // android.widget.RelativeLayout, android.view.ViewGroup, android.view.View
protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
this.ku = i;
this.kv = i2;
this.kw = i3;
this.kx = i4;
if (!this.kF) {
super.onLayout(z, i, i2, i3, i4);
return;
}
try {
int childCount = getChildCount();
int abs = Math.abs(i3 - i);
int abs2 = Math.abs(i4 - i2);
int suggestedMinimumWidth = getSuggestedMinimumWidth();
int suggestedMinimumHeight = getSuggestedMinimumHeight();
Point h = this.ko.h(abs, abs2);
h.set(Math.max(h.x, suggestedMinimumWidth), Math.max(h.y, suggestedMinimumHeight));
int i5 = h.x;
int i6 = h.y;
int i7 = (abs - i5) / 2;
int i8 = (abs2 - i6) / 2;
this.kl.clear();
for (int i9 = 0; i9 < childCount; i9++) {
this.kl.add(getChildAt(i9));
}
Iterator<View> it = this.kl.iterator();
while (it.hasNext()) {
it.next().layout(i7, i8, i5 + i7, i6 + i8);
}
} catch (Exception unused) {
super.onLayout(z, i, i2, i3, i4);
}
}
@Override // android.view.ViewGroup, android.view.View
protected void onDetachedFromWindow() {
if (isInEditMode()) {
return;
}
super.onDetachedFromWindow();
getViewTreeObserver().removeOnGlobalLayoutListener(this.kI);
removeView(this.kq);
this.kq = null;
}
@Override // android.view.ViewGroup, android.view.View
protected void onAttachedToWindow() {
if (isInEditMode()) {
return;
}
super.onAttachedToWindow();
SurfaceView surfaceView = Injector.getInjector(getContext().getApplicationContext()).getSurfaceView();
this.kq = surfaceView;
addView(surfaceView, 0);
SurfaceHolder holder = this.kq.getHolder();
holder.addCallback(this);
setHolderPushBuffers(holder);
getViewTreeObserver().addOnGlobalLayoutListener(this.kI);
}
@Override // android.view.SurfaceHolder.Callback
public void surfaceCreated(SurfaceHolder surfaceHolder) {
this.kF = true;
a(surfaceHolder);
}
/* JADX INFO: Access modifiers changed from: private */
public void a(SurfaceHolder surfaceHolder) {
if (this.kF && !this.kH && this.kG) {
try {
this.ko.setCameraType(this.kA);
this.ko.open();
this.ko.a(surfaceHolder, getWidth(), getHeight());
this.ko.startPreview();
this.ko.a(this.kp);
requestLayout();
this._bus.register(this.km);
this._bus.post(new c());
this._bus.post(new SurfaceChangedEvent(true, this.kq));
this.kH = true;
} catch (RuntimeException e) {
k.e(e);
IBus iBus = this._bus;
String str = TAG;
aj.a aVar = aj.a.ERROR;
StringBuilder sb = new StringBuilder("Error starting camera preview: ");
sb.append(e.getMessage());
iBus.post(new aj(str, aVar, sb.toString(), e));
}
}
}
@Override // android.view.SurfaceHolder.Callback
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
this.kF = false;
an();
}
/* JADX INFO: Access modifiers changed from: private */
public void an() {
if (this.kH) {
try {
this.ko.close();
this._bus.post(new SurfaceChangedEvent(false, null));
this._bus.post(new r());
this._bus.unregister(this.km);
ICameraDelegate iCameraDelegate = this.kC;
if (iCameraDelegate != null) {
iCameraDelegate.onDetachFromWindow();
}
this.kH = false;
} catch (Exception e) {
k.e("Error", "exception", (Throwable) e);
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public class a {
final ImageCaptureView kJ;
private a(ImageCaptureView imageCaptureView) {
this.kJ = imageCaptureView;
}
@InterfaceC13006fNs
public void a(aq aqVar) {
if (this.kJ.kC != null) {
this.kJ.kC.onPictureTaken();
}
}
@InterfaceC13006fNs
public void a(SetFocusAreasRequestBusEvent setFocusAreasRequestBusEvent) {
if (this.kJ.kC != null) {
this.kJ.kC.onFocusAreasRequest(setFocusAreasRequestBusEvent.areas, setFocusAreasRequestBusEvent.width, setFocusAreasRequestBusEvent.height);
}
}
@InterfaceC13006fNs
public void onCameraParametersProduced(m mVar) {
this.kJ.kr = mVar.Iv;
}
@InterfaceC13006fNs
public void a(v vVar) {
ImageCaptureView imageCaptureView = this.kJ;
imageCaptureView.onLayout(true, imageCaptureView.ku, this.kJ.kv, this.kJ.kw, this.kJ.kx);
}
@InterfaceC13004fNq
public SurfaceChangedEvent ao() {
return new SurfaceChangedEvent(this.kJ.kF, this.kJ.kq);
}
@InterfaceC13004fNq
public s ap() {
return new s(this.kJ.ks);
}
@InterfaceC13004fNq
public t aq() {
return new t(this.kJ.kt);
}
@InterfaceC13004fNq
public af ar() {
return new af(this.kJ.kE);
}
@InterfaceC13004fNq
public UseVideoChangedEvent as() {
return new UseVideoChangedEvent(this.kJ.ko.jB());
}
@InterfaceC13004fNq
public ak at() {
return new ak(this.kJ.ky);
}
@InterfaceC13004fNq
public bb au() {
return new bb(this.kJ.kz);
}
}
public final void setCameraType(CameraType cameraType) {
this.kA = cameraType;
}
@Override // com.kofax.mobile.sdk._internal.camera.f
public void setCameraDelegate(ICameraDelegate iCameraDelegate) {
this.kC = iCameraDelegate;
}
public final int getTorchDelay() {
return this.kz;
}
public final int getLuminanceThreshold() {
return this.ky;
}
public final GpsUsageLimits getGpsUsage() {
return this.kE;
}
public final List<Rect> getFocusAreas() {
return this.kD;
}
public final Flash getFlash() {
return this.kB;
}
public final int getDeviceDeclinationRoll() {
return this.kt;
}
public final int getDeviceDeclinationPitch() {
return this.ks;
}
}