Rabbit-R1/switch port/java/sources/com/journeyapps/barcodescanner/BarcodeView.java
2024-05-21 17:08:36 -04:00

211 lines
8.1 KiB
Java

package com.journeyapps.barcodescanner;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import com.google.zxing.DecodeHintType;
import com.google.zxing.ResultPoint;
import com.google.zxing.client.android.R;
import java.util.HashMap;
import java.util.List;
/* loaded from: classes3.dex */
public class BarcodeView extends CameraPreview {
private BarcodeCallback callback;
private DecodeMode decodeMode;
private DecoderFactory decoderFactory;
private DecoderThread decoderThread;
private final Handler.Callback resultCallback;
private Handler resultHandler;
/* JADX INFO: Access modifiers changed from: private */
/* loaded from: classes3.dex */
public enum DecodeMode {
NONE,
SINGLE,
CONTINUOUS
}
public DecoderFactory getDecoderFactory() {
return this.decoderFactory;
}
public BarcodeView(Context context) {
super(context);
this.decodeMode = DecodeMode.NONE;
this.callback = null;
this.resultCallback = new Handler.Callback() { // from class: com.journeyapps.barcodescanner.BarcodeView.1
@Override // android.os.Handler.Callback
public boolean handleMessage(Message message) {
if (message.what == R.id.zxing_decode_succeeded) {
BarcodeResult barcodeResult = (BarcodeResult) message.obj;
if (barcodeResult != null && BarcodeView.this.callback != null && BarcodeView.this.decodeMode != DecodeMode.NONE) {
BarcodeView.this.callback.barcodeResult(barcodeResult);
if (BarcodeView.this.decodeMode == DecodeMode.SINGLE) {
BarcodeView.this.stopDecoding();
}
}
return true;
}
if (message.what == R.id.zxing_decode_failed) {
return true;
}
if (message.what != R.id.zxing_possible_result_points) {
return false;
}
List<ResultPoint> list = (List) message.obj;
if (BarcodeView.this.callback != null && BarcodeView.this.decodeMode != DecodeMode.NONE) {
BarcodeView.this.callback.possibleResultPoints(list);
}
return true;
}
};
initialize();
}
public BarcodeView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
this.decodeMode = DecodeMode.NONE;
this.callback = null;
this.resultCallback = new Handler.Callback() { // from class: com.journeyapps.barcodescanner.BarcodeView.1
@Override // android.os.Handler.Callback
public boolean handleMessage(Message message) {
if (message.what == R.id.zxing_decode_succeeded) {
BarcodeResult barcodeResult = (BarcodeResult) message.obj;
if (barcodeResult != null && BarcodeView.this.callback != null && BarcodeView.this.decodeMode != DecodeMode.NONE) {
BarcodeView.this.callback.barcodeResult(barcodeResult);
if (BarcodeView.this.decodeMode == DecodeMode.SINGLE) {
BarcodeView.this.stopDecoding();
}
}
return true;
}
if (message.what == R.id.zxing_decode_failed) {
return true;
}
if (message.what != R.id.zxing_possible_result_points) {
return false;
}
List<ResultPoint> list = (List) message.obj;
if (BarcodeView.this.callback != null && BarcodeView.this.decodeMode != DecodeMode.NONE) {
BarcodeView.this.callback.possibleResultPoints(list);
}
return true;
}
};
initialize();
}
public BarcodeView(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
this.decodeMode = DecodeMode.NONE;
this.callback = null;
this.resultCallback = new Handler.Callback() { // from class: com.journeyapps.barcodescanner.BarcodeView.1
@Override // android.os.Handler.Callback
public boolean handleMessage(Message message) {
if (message.what == R.id.zxing_decode_succeeded) {
BarcodeResult barcodeResult = (BarcodeResult) message.obj;
if (barcodeResult != null && BarcodeView.this.callback != null && BarcodeView.this.decodeMode != DecodeMode.NONE) {
BarcodeView.this.callback.barcodeResult(barcodeResult);
if (BarcodeView.this.decodeMode == DecodeMode.SINGLE) {
BarcodeView.this.stopDecoding();
}
}
return true;
}
if (message.what == R.id.zxing_decode_failed) {
return true;
}
if (message.what != R.id.zxing_possible_result_points) {
return false;
}
List<ResultPoint> list = (List) message.obj;
if (BarcodeView.this.callback != null && BarcodeView.this.decodeMode != DecodeMode.NONE) {
BarcodeView.this.callback.possibleResultPoints(list);
}
return true;
}
};
initialize();
}
private void initialize() {
this.decoderFactory = new DefaultDecoderFactory();
this.resultHandler = new Handler(this.resultCallback);
}
public void setDecoderFactory(DecoderFactory decoderFactory) {
Util.validateMainThread();
this.decoderFactory = decoderFactory;
DecoderThread decoderThread = this.decoderThread;
if (decoderThread != null) {
decoderThread.setDecoder(createDecoder());
}
}
private Decoder createDecoder() {
if (this.decoderFactory == null) {
this.decoderFactory = createDefaultDecoderFactory();
}
DecoderResultPointCallback decoderResultPointCallback = new DecoderResultPointCallback();
HashMap hashMap = new HashMap();
hashMap.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, decoderResultPointCallback);
Decoder createDecoder = this.decoderFactory.createDecoder(hashMap);
decoderResultPointCallback.setDecoder(createDecoder);
return createDecoder;
}
public void decodeSingle(BarcodeCallback barcodeCallback) {
this.decodeMode = DecodeMode.SINGLE;
this.callback = barcodeCallback;
startDecoderThread();
}
public void decodeContinuous(BarcodeCallback barcodeCallback) {
this.decodeMode = DecodeMode.CONTINUOUS;
this.callback = barcodeCallback;
startDecoderThread();
}
public void stopDecoding() {
this.decodeMode = DecodeMode.NONE;
this.callback = null;
stopDecoderThread();
}
protected DecoderFactory createDefaultDecoderFactory() {
return new DefaultDecoderFactory();
}
private void startDecoderThread() {
stopDecoderThread();
if (this.decodeMode == DecodeMode.NONE || !isPreviewActive()) {
return;
}
DecoderThread decoderThread = new DecoderThread(getCameraInstance(), createDecoder(), this.resultHandler);
this.decoderThread = decoderThread;
decoderThread.setCropRect(getPreviewFramingRect());
this.decoderThread.start();
}
@Override // com.journeyapps.barcodescanner.CameraPreview
protected void previewStarted() {
super.previewStarted();
startDecoderThread();
}
private void stopDecoderThread() {
DecoderThread decoderThread = this.decoderThread;
if (decoderThread != null) {
decoderThread.stop();
this.decoderThread = null;
}
}
@Override // com.journeyapps.barcodescanner.CameraPreview
public void pause() {
stopDecoderThread();
super.pause();
}
}