package com.kofax.kmc.kui.uicontrols; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Rect; import android.util.AttributeSet; import android.util.Base64; import android.widget.RelativeLayout; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.kofax.kmc.ken.engines.data.BarCodeDataFormat; import com.kofax.kmc.ken.engines.data.BarCodeDirection; import com.kofax.kmc.ken.engines.data.BarCodeResult; import com.kofax.kmc.ken.engines.data.BarCodeType; import com.kofax.kmc.ken.engines.data.BoundingTetragon; import com.kofax.kmc.ken.engines.data.Image; import com.kofax.kmc.kui.uicontrols.data.GpsUsageLimits; import com.kofax.kmc.kui.uicontrols.data.GuidingLine; import com.kofax.kmc.kui.uicontrols.data.SearchDirection; import com.kofax.kmc.kui.uicontrols.data.Symbology; import com.kofax.kmc.kut.utilities.Licensing; import com.kofax.kmc.kut.utilities.error.ErrorInfo; import com.kofax.kmc.kut.utilities.error.KmcException; import com.kofax.kmc.kut.utilities.error.KmcRuntimeException; import com.kofax.mobile.sdk._internal.camera.l; import com.kofax.mobile.sdk._internal.dagger.Injector; import com.kofax.mobile.sdk._internal.impl.event.GPSEnabledEvent; import com.kofax.mobile.sdk._internal.impl.event.LevelChangedEvent; import com.kofax.mobile.sdk._internal.impl.event.LocationEvent; import com.kofax.mobile.sdk._internal.impl.event.PreviewImageReadyBusEvent; import com.kofax.mobile.sdk._internal.impl.view.v; import com.kofax.mobile.sdk._internal.k; import com.manateeworks.kfx.BarcodeScanner; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import net.sf.scuba.smartcards.ISO7816; import o.InterfaceC13006fNs; import o.InterfaceC13391fZD; /* loaded from: classes3.dex */ public class BarCodeCaptureView extends ImageCaptureView { private static final String TAG = "BarCodeCaptureView"; private static final Rect jD = new Rect(0, 0, 100, 100); private static final int jE = 1; private static final int jF = 2; private static final int jG = 4; private static final int jH = 8; @InterfaceC13391fZD l jI; private boolean jJ; private v jK; private final List jL; private boolean jM; private int jN; private float jO; private float jP; private float jQ; private float jR; private boolean jS; private Symbology[] jT; private SearchDirection[] jU; public BarCodeCaptureView(Context context) { this(context, null, 0); } public BarCodeCaptureView(Context context, AttributeSet attributeSet) { this(context, attributeSet, 0); } public BarCodeCaptureView(Context context, AttributeSet attributeSet, int i) { this(context, attributeSet, i, null); } /* JADX INFO: Access modifiers changed from: package-private */ @InterfaceC13391fZD public BarCodeCaptureView(Context context, v vVar) { this(context, null, 0, vVar); } private BarCodeCaptureView(Context context, AttributeSet attributeSet, int i, v vVar) { super(context, attributeSet, i); this.jL = new CopyOnWriteArrayList(); this.jM = false; this.jS = false; this.jT = new Symbology[0]; this.jU = new SearchDirection[]{SearchDirection.HORIZONTAL, SearchDirection.VERTICAL}; if (isInEditMode()) { return; } this.jK = vVar == null ? Injector.getInjector(context.getApplicationContext()).getGuideLineRenderer() : vVar; this.jJ = getResources().getConfiguration().orientation == 1; aj(); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-2, -2); layoutParams.addRule(13); this.jK.setLayoutParams(layoutParams); addView(this.jK); this._bus.register(this); } @Override // com.kofax.kmc.kui.uicontrols.ImageCaptureView void ai() { Injector.getInjector(getContext()).injectMembers(this); } public GuidingLine getGuidingLine() { return this.jK.getGuidingLine(); } public void setGuidingLine(GuidingLine guidingLine) { this.jK.setGuidingLine(guidingLine); } public void setSymbologies(Symbology[] symbologyArr) { this.jT = symbologyArr; ak(); } public void setSearchDirection(SearchDirection[] searchDirectionArr) { this.jU = searchDirectionArr; al(); } public void addBarCodeFoundEventListener(BarCodeFoundListener barCodeFoundListener) { if (this.jL.contains(barCodeFoundListener)) { return; } this.jL.add(barCodeFoundListener); } public void removeBarCodeFoundEventListener(BarCodeFoundListener barCodeFoundListener) { this.jL.remove(barCodeFoundListener); } @Override // com.kofax.kmc.kui.uicontrols.ImageCaptureView protected void checkLicense() { if (!Licensing.isSdkLicensed(Licensing.LicenseType.BARCODE_CAPTURE)) { throw new KmcRuntimeException(ErrorInfo.KMC_UT_LICENSE_BARCODE_CAPTURE); } } private void aj() { BarcodeScanner.registerCode(64, "Kofax.Android.PDF.UDL", "5A52C54FD2EEB8A9DC6599740ABB69E6B397378ADBE1CE342517D4700C9F56AD"); BarcodeScanner.registerCode(8, "Kofax.Android.C39.UDL", "2DBAB7E1F20796746AFA20069DE9F5B7C2D5CAA2F63A86BB6B89634D6C4336DD"); BarcodeScanner.registerCode(1, "Kofax.Android.QR.UDL", "5C44241E3E38A6E3BFBA3FB5949112DA91544173A67BFA58B622123B0C5341BC"); BarcodeScanner.registerCode(512, "Kofax.Android.C93.UDL", "076F86B485C8E77B90FC504C5CBE62C710B1D4EACB687C4211B688AE073E85A0"); BarcodeScanner.registerCode(1024, "Kofax.Android.CB.UDL", "722D1BF70863DBF0D933606DC43A259E2B0DFE7BE1DEAF3F7A5599CEBF076BC3"); BarcodeScanner.registerCode(2, "Kofax.Android.DM.UDL", "2CA472C41CEF35CFDC61211A06C1AEF49AD8D4405B07598C6008F4287D34ACFA"); BarcodeScanner.registerCode(16, "Kofax.Android.EANUPC.UDL", "295D23C3BCCF2A8C4E684BE761DFA13C44F30E15A707430D645BC4584083491B"); BarcodeScanner.registerCode(32, "Kofax.Android.C128.UDL", "5C62C3BE32CA208BD81CAE8F4390CEA5B3E36DD5BCA6379291B4A0F398A5F437"); BarcodeScanner.registerCode(256, "Kofax.Android.C25.UDL", "9A5282B31BBFF5DDA1B564105401D219B8C5A5832EE7897D42E2B1C83F487B59"); BarcodeScanner.registerCode(128, "Kofax.Android.AZTEC.UDL", "5C6F013332805C58FA52848F854B6DD4B593CE2A91AF0CAAE252E0D8C50B9A9B"); ak(); al(); BarcodeScanner.setFlags(512, 8); BarcodeScanner.setFlags(256, 1); BarcodeScanner.setLevel(2); } private void ak() { int i = 0; for (Symbology symbology : this.jT) { int a2 = a(symbology); BarcodeScanner.setScanningRect(a2, jD); i |= a2; } BarcodeScanner.setActiveCodes(i); } private void al() { int a2 = a(this.jU); int i = ((a2 & 1) == 0 && (a2 & 2) == 0) ? 0 : this.jJ ? 2 : 1; if ((a2 & 8) != 0 || (a2 & 4) != 0) { i |= this.jJ ? 1 : 2; } BarcodeScanner.setDirection(i); } private int a(SearchDirection[] searchDirectionArr) { int i = 0; for (SearchDirection searchDirection : searchDirectionArr) { i |= searchDirection.getValue(); } return i; } private int a(Symbology symbology) { if (symbology == Symbology.AZTEC) { return 128; } if (symbology == Symbology.CODABAR) { return 1024; } if (symbology == Symbology.CODE128) { return 32; } if (symbology == Symbology.CODE25) { return 256; } if (symbology == Symbology.CODE39) { return 8; } if (symbology == Symbology.CODE93) { return 512; } if (symbology == Symbology.DATAMATRIX) { return 2; } if (symbology == Symbology.EAN || symbology == Symbology.UPC) { return 16; } if (symbology == Symbology.PDF417) { return 64; } return symbology == Symbology.QR ? 1 : 0; } private void a(BarCodeResult barCodeResult, Image image) { if (this.jS && GpsUsageLimits.ALWAYS_USE_IF_ENABLED.equals(getGpsUsage())) { try { Image.FriendI friendI = new Image.FriendI(image, "com.kofax.kmc.kui.uicontrols"); friendI.setImageLatitude(Float.valueOf(this.jQ)); friendI.setImageLongitude(Float.valueOf(this.jR)); } catch (KmcException unused) { } } try { Image.FriendI friendI2 = new Image.FriendI(image, "com.kofax.kmc.kui.uicontrols"); friendI2.setImagePitch(Float.valueOf(this.jO)); friendI2.setImageRoll(Float.valueOf(this.jP)); } catch (KmcException unused2) { } Iterator it = this.jL.iterator(); while (it.hasNext()) { it.next().barCodeFound(new BarCodeFoundEvent(this, barCodeResult, image)); } } private void a(b bVar) { Bitmap imageDataToBitmap = this.jI.imageDataToBitmap(bVar.jW.data, bVar.jW.format, bVar.width, bVar.height, this.jN); BarCodeResult barCodeResult = new BarCodeResult(); barCodeResult.setType(d(bVar.type)); barCodeResult.setBoundingBox(calculateBound(bVar.jY, this.jN, bVar.width, bVar.height)); barCodeResult.setDirection(l(barCodeResult.getBoundingBox())); if (a(bVar.jX)) { barCodeResult.setDataFormat(BarCodeDataFormat.ASCII); barCodeResult.setValue(new String(bVar.jX)); } else { barCodeResult.setDataFormat(BarCodeDataFormat.BASE_64); barCodeResult.setValue(Base64.encodeToString(bVar.jX, 0)); } String str = TAG; StringBuilder sb = new StringBuilder("handleDecodeSuccess: "); sb.append(barCodeResult.getType()); k.b(str, sb.toString()); StringBuilder sb2 = new StringBuilder(" Direction: "); sb2.append(barCodeResult.getDirection()); k.b(str, sb2.toString()); if (barCodeResult.getBoundingBox() != null) { StringBuilder sb3 = new StringBuilder(" Bound: TL="); sb3.append(barCodeResult.getBoundingBox().getTopLeft()); sb3.append(" TR="); sb3.append(barCodeResult.getBoundingBox().getTopRight()); sb3.append(" BL="); sb3.append(barCodeResult.getBoundingBox().getBottomLeft()); sb3.append(" BR="); sb3.append(barCodeResult.getBoundingBox().getBottomRight()); k.b(str, sb3.toString()); } StringBuilder sb4 = new StringBuilder(" Format: "); sb4.append(barCodeResult.getDataFormat()); k.b(str, sb4.toString()); StringBuilder sb5 = new StringBuilder(" Message: "); sb5.append(barCodeResult.getValue()); k.b(str, sb5.toString()); ArrayList arrayList = new ArrayList(); arrayList.add(barCodeResult); Image image = new Image(imageDataToBitmap); image.setImageBarCodes(arrayList); a(barCodeResult, image); } private boolean a(byte[] bArr) { for (byte b2 : bArr) { if (b2 < 32 || b2 >= Byte.MAX_VALUE) { return false; } } return true; } private BarCodeType d(int i) { if (i == 1) { return BarCodeType.DATAMATRIX; } if (i == 2) { return BarCodeType.CODE39; } switch (i) { case 7: case 8: return BarCodeType.EAN; case 9: case 10: return BarCodeType.UPC; case 11: return BarCodeType.CODE128; case 12: return BarCodeType.PDF417; case 13: return BarCodeType.QR; case 14: return BarCodeType.AZTEC; case 15: case 16: return BarCodeType.CODE25; case 17: return BarCodeType.CODE93; case 18: return BarCodeType.CODABAR; default: return BarCodeType.UNKNOWN; } } private boolean b(float[] fArr) { if (fArr == null) { return true; } int i = 0; for (float f : fArr) { if (f == BitmapDescriptorFactory.HUE_RED) { i++; } } return i == fArr.length; } private BarCodeDirection l(BoundingTetragon boundingTetragon) { if (boundingTetragon == null) { return BarCodeDirection.UNKNOWN; } float f = boundingTetragon.getTopRight().x - boundingTetragon.getTopLeft().x; float f2 = boundingTetragon.getTopRight().y - boundingTetragon.getTopLeft().y; double sqrt = Math.sqrt((f * f) + (f2 * f2)); double atan2 = Math.atan2(f2 / sqrt, f / sqrt); String str = TAG; StringBuilder sb = new StringBuilder("Angle: "); sb.append((180.0d * atan2) / 3.141592653589793d); k.b(str, sb.toString()); if (b(getSearchDirection())) { if (atan2 <= -1.5707963267948966d) { return BarCodeDirection.RIGHT_LEFT; } if (atan2 > -1.5707963267948966d && atan2 <= 1.5707963267948966d) { return BarCodeDirection.LEFT_RIGHT; } if (atan2 > 1.5707963267948966d) { return BarCodeDirection.RIGHT_LEFT; } } else if (c(getSearchDirection())) { if ((atan2 > -3.141592653589793d && atan2 <= 0.0d) || (atan2 > 3.141592653589793d && atan2 < 6.283185307179586d)) { return BarCodeDirection.BOTTOM_UP; } if ((atan2 > 0.0d && atan2 <= 3.141592653589793d) || (atan2 < -3.141592653589793d && atan2 > -6.283185307179586d)) { return BarCodeDirection.TOP_DOWN; } } else { if (atan2 <= -2.356194490192345d) { return BarCodeDirection.RIGHT_LEFT; } if (atan2 > -2.356194490192345d && atan2 <= -0.7853981633974483d) { return BarCodeDirection.BOTTOM_UP; } if (atan2 > -0.7853981633974483d && atan2 <= 0.7853981633974483d) { return BarCodeDirection.LEFT_RIGHT; } if (atan2 > 0.7853981633974483d && atan2 <= 2.356194490192345d) { return BarCodeDirection.TOP_DOWN; } if (atan2 > 2.356194490192345d) { return BarCodeDirection.RIGHT_LEFT; } } return BarCodeDirection.UNKNOWN; } private boolean b(SearchDirection[] searchDirectionArr) { return a(SearchDirection.HORIZONTAL, SearchDirection.VERTICAL, searchDirectionArr); } private boolean c(SearchDirection[] searchDirectionArr) { return a(SearchDirection.VERTICAL, SearchDirection.HORIZONTAL, searchDirectionArr); } private boolean a(SearchDirection searchDirection, SearchDirection searchDirection2, SearchDirection[] searchDirectionArr) { if (searchDirectionArr == null || searchDirectionArr.length == 0) { return false; } boolean z = false; for (SearchDirection searchDirection3 : searchDirectionArr) { if (searchDirection3 == SearchDirection.ALL || searchDirection3 == searchDirection2) { return false; } if (searchDirection3 == searchDirection) { z = true; } } return z; } public BoundingTetragon calculateBound(float[] fArr, int i, int i2, int i3) { int i4 = i; if (b(fArr) || fArr.length != 8) { return null; } if (i4 < 0) { i4 += 360; } if (i4 == 0) { return new BoundingTetragon((int) fArr[0], (int) fArr[1], (int) fArr[2], (int) fArr[3], (int) fArr[6], (int) fArr[7], (int) fArr[4], (int) fArr[5]); } if (i4 == 90) { return new BoundingTetragon(i3 - ((int) fArr[1]), (int) fArr[0], i3 - ((int) fArr[3]), (int) fArr[2], i3 - ((int) fArr[7]), (int) fArr[6], i3 - ((int) fArr[5]), (int) fArr[4]); } if (i4 == 180) { return new BoundingTetragon(i2 - ((int) fArr[0]), i3 - ((int) fArr[1]), i2 - ((int) fArr[2]), i3 - ((int) fArr[3]), i2 - ((int) fArr[6]), i3 - ((int) fArr[7]), i2 - ((int) fArr[4]), i3 - ((int) fArr[5])); } if (i4 != 270) { return null; } return new BoundingTetragon((int) fArr[1], i2 - ((int) fArr[0]), (int) fArr[3], i2 - ((int) fArr[2]), (int) fArr[7], i2 - ((int) fArr[6]), (int) fArr[5], i2 - ((int) fArr[4])); } @InterfaceC13006fNs public void onLevelnessChanged(LevelChangedEvent levelChangedEvent) { this.jO = levelChangedEvent.pitch; this.jP = levelChangedEvent.roll; } @InterfaceC13006fNs public void onPreviewFrame(PreviewImageReadyBusEvent previewImageReadyBusEvent) { if (this.jM) { byte[] bArr = previewImageReadyBusEvent.imageData; int i = previewImageReadyBusEvent.width; int i2 = previewImageReadyBusEvent.height; this.jN = previewImageReadyBusEvent.rotation; byte[] scanGrayscaleImage = BarcodeScanner.scanGrayscaleImage(bArr, i, i2); if (scanGrayscaleImage == null || scanGrayscaleImage.length < 4) { return; } for (byte b2 : scanGrayscaleImage) { } b bVar = new b(); bVar.type = BarcodeScanner.getLastType(); bVar.width = i; bVar.height = i2; bVar.jX = scanGrayscaleImage; bVar.jW = new a(this, bArr, 17); bVar.jY = BarcodeScanner.getBarcodeLocation(); if (b(bVar)) { k.b("BarCodeCaptureHandler", "Decode Succeeded: ".concat(new String(bVar.jX))); this.jM = false; a(bVar); } } } @InterfaceC13006fNs public void onLocationEvent(LocationEvent locationEvent) { this.jQ = (float) locationEvent.latitude; this.jR = (float) locationEvent.longitude; } @InterfaceC13006fNs public void onLocationEnableEvent(GPSEnabledEvent gPSEnabledEvent) { this.jS = gPSEnabledEvent.gpsEnabled; } private boolean b(b bVar) { BarCodeType d = d(bVar.type); List asList = Arrays.asList(getSymbologies()); if (d == BarCodeType.EAN && !asList.contains(Symbology.EAN)) { return false; } if (d == BarCodeType.UPC && !asList.contains(Symbology.UPC)) { if (bVar.type != 9) { return false; } bVar.type = 7; byte[] bArr = new byte[bVar.jX.length + 1]; bArr[0] = ISO7816.INS_DECREASE; System.arraycopy(bVar.jX, 0, bArr, 1, bVar.jX.length); bVar.jX = bArr; } return true; } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public static class b { int height; a jW; byte[] jX; float[] jY; int type; int width; b() { } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public class a { public byte[] data; public int format; final BarCodeCaptureView jV; public a(BarCodeCaptureView barCodeCaptureView, byte[] bArr, int i) { this.jV = barCodeCaptureView; this.data = bArr; this.format = i; } } public void readBarcode() { this.jM = true; } public Symbology[] getSymbologies() { return this.jT; } public SearchDirection[] getSearchDirection() { return this.jU; } }