正在查看: Meine NEW v2.0.3616 应用的 CaptureManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Meine NEW v2.0.3616 应用的 CaptureManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.journeyapps.barcodescanner;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import b0.a;
import com.google.zxing.ResultMetadataType;
import com.google.zxing.ResultPoint;
import com.google.zxing.client.android.BeepManager;
import com.google.zxing.client.android.InactivityTimer;
import com.google.zxing.client.android.Intents;
import com.google.zxing.client.android.R;
import com.journeyapps.barcodescanner.CameraPreview;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class CaptureManager {
private static final String SAVED_ORIENTATION_LOCK = "SAVED_ORIENTATION_LOCK";
private static final String TAG = "CaptureManager";
private static int cameraPermissionReqCode = 250;
private Activity activity;
private boolean askedPermission;
private DecoratedBarcodeView barcodeView;
private BeepManager beepManager;
private Handler handler;
private InactivityTimer inactivityTimer;
private final CameraPreview.StateListener stateListener;
private int orientationLock = -1;
private boolean returnBarcodeImagePath = false;
private boolean destroyed = false;
private boolean finishWhenClosed = false;
private BarcodeCallback callback = new BarcodeCallback() {
@Override
public void barcodeResult(final BarcodeResult barcodeResult) {
CaptureManager.this.barcodeView.pause();
CaptureManager.this.beepManager.playBeepSoundAndVibrate();
CaptureManager.this.handler.post(new Runnable() {
@Override
public void run() {
CaptureManager.this.returnResult(barcodeResult);
}
});
}
@Override
public void possibleResultPoints(List<ResultPoint> list) {
}
};
public CaptureManager(Activity activity, DecoratedBarcodeView decoratedBarcodeView) {
CameraPreview.StateListener stateListener = new CameraPreview.StateListener() {
@Override
public void cameraClosed() {
if (CaptureManager.this.finishWhenClosed) {
String unused = CaptureManager.TAG;
CaptureManager.this.finish();
}
}
@Override
public void cameraError(Exception exc) {
CaptureManager.this.displayFrameworkBugMessageAndExit();
}
@Override
public void previewSized() {
}
@Override
public void previewStarted() {
}
@Override
public void previewStopped() {
}
};
this.stateListener = stateListener;
this.askedPermission = false;
this.activity = activity;
this.barcodeView = decoratedBarcodeView;
decoratedBarcodeView.getBarcodeView().addStateListener(stateListener);
this.handler = new Handler();
this.inactivityTimer = new InactivityTimer(activity, new Runnable() {
@Override
public void run() {
String unused = CaptureManager.TAG;
CaptureManager.this.finish();
}
});
this.beepManager = new BeepManager(activity);
}
public void finish() {
this.activity.finish();
}
private String getBarcodeImagePath(BarcodeResult barcodeResult) {
if (this.returnBarcodeImagePath) {
Bitmap bitmap = barcodeResult.getBitmap();
try {
File createTempFile = File.createTempFile("barcodeimage", ".jpg", this.activity.getCacheDir());
FileOutputStream fileOutputStream = new FileOutputStream(createTempFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
fileOutputStream.close();
return createTempFile.getAbsolutePath();
} catch (IOException e) {
Log.w(TAG, "Unable to create temporary file and store bitmap! " + e);
}
}
return null;
}
public static int getCameraPermissionReqCode() {
return cameraPermissionReqCode;
}
@TargetApi(23)
private void openCameraWithPermission() {
if (a.checkSelfPermission(this.activity, "android.permission.CAMERA") == 0) {
this.barcodeView.resume();
} else {
if (this.askedPermission) {
return;
}
a0.a.a(this.activity, new String[]{"android.permission.CAMERA"}, cameraPermissionReqCode);
this.askedPermission = true;
}
}
public static Intent resultIntent(BarcodeResult barcodeResult, String str) {
Intent intent = new Intent(Intents.Scan.ACTION);
intent.addFlags(524288);
intent.putExtra(Intents.Scan.RESULT, barcodeResult.toString());
intent.putExtra(Intents.Scan.RESULT_FORMAT, barcodeResult.getBarcodeFormat().toString());
byte[] rawBytes = barcodeResult.getRawBytes();
if (rawBytes != null && rawBytes.length > 0) {
intent.putExtra(Intents.Scan.RESULT_BYTES, rawBytes);
}
Map<ResultMetadataType, Object> resultMetadata = barcodeResult.getResultMetadata();
if (resultMetadata != null) {
ResultMetadataType resultMetadataType = ResultMetadataType.UPC_EAN_EXTENSION;
if (resultMetadata.containsKey(resultMetadataType)) {
intent.putExtra(Intents.Scan.RESULT_UPC_EAN_EXTENSION, resultMetadata.get(resultMetadataType).toString());
}
Number number = (Number) resultMetadata.get(ResultMetadataType.ORIENTATION);
if (number != null) {
intent.putExtra(Intents.Scan.RESULT_ORIENTATION, number.intValue());
}
String str2 = (String) resultMetadata.get(ResultMetadataType.ERROR_CORRECTION_LEVEL);
if (str2 != null) {
intent.putExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL, str2);
}
Iterable iterable = (Iterable) resultMetadata.get(ResultMetadataType.BYTE_SEGMENTS);
if (iterable != null) {
Iterator it = iterable.iterator();
int i = 0;
while (it.hasNext()) {
intent.putExtra(Intents.Scan.RESULT_BYTE_SEGMENTS_PREFIX + i, (byte[]) it.next());
i++;
}
}
}
if (str != null) {
intent.putExtra(Intents.Scan.RESULT_BARCODE_IMAGE_PATH, str);
}
return intent;
}
public static void setCameraPermissionReqCode(int i) {
cameraPermissionReqCode = i;
}
public void closeAndFinish() {
if (this.barcodeView.getBarcodeView().isCameraClosed()) {
finish();
} else {
this.finishWhenClosed = true;
}
this.barcodeView.pause();
this.inactivityTimer.cancel();
}
public void decode() {
this.barcodeView.decodeSingle(this.callback);
}
public void displayFrameworkBugMessageAndExit() {
if (this.activity.isFinishing() || this.destroyed || this.finishWhenClosed) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(this.activity);
builder.setTitle(this.activity.getString(R.string.zxing_app_name));
builder.setMessage(this.activity.getString(R.string.zxing_msg_camera_framework_bug));
builder.setPositiveButton(R.string.zxing_button_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
CaptureManager.this.finish();
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
CaptureManager.this.finish();
}
});
builder.show();
}
public void initializeFromIntent(Intent intent, Bundle bundle) {
this.activity.getWindow().addFlags(128);
if (bundle != null) {
this.orientationLock = bundle.getInt(SAVED_ORIENTATION_LOCK, -1);
}
if (intent != null) {
if (intent.getBooleanExtra(Intents.Scan.ORIENTATION_LOCKED, true)) {
lockOrientation();
}
if (Intents.Scan.ACTION.equals(intent.getAction())) {
this.barcodeView.initializeFromIntent(intent);
}
if (!intent.getBooleanExtra(Intents.Scan.BEEP_ENABLED, true)) {
this.beepManager.setBeepEnabled(false);
}
if (intent.hasExtra(Intents.Scan.TIMEOUT)) {
this.handler.postDelayed(new Runnable() {
@Override
public void run() {
CaptureManager.this.returnResultTimeout();
}
}, intent.getLongExtra(Intents.Scan.TIMEOUT, 0L));
}
if (intent.getBooleanExtra(Intents.Scan.BARCODE_IMAGE_ENABLED, false)) {
this.returnBarcodeImagePath = true;
}
}
}
public void lockOrientation() {
if (this.orientationLock == -1) {
int rotation = this.activity.getWindowManager().getDefaultDisplay().getRotation();
int i = this.activity.getResources().getConfiguration().orientation;
int i2 = 0;
if (i == 2) {
if (rotation != 0 && rotation != 1) {
i2 = 8;
}
} else if (i == 1) {
i2 = (rotation == 0 || rotation == 3) ? 1 : 9;
}
this.orientationLock = i2;
}
this.activity.setRequestedOrientation(this.orientationLock);
}
public void onDestroy() {
this.destroyed = true;
this.inactivityTimer.cancel();
this.handler.removeCallbacksAndMessages(null);
}
public void onPause() {
this.inactivityTimer.cancel();
this.barcodeView.pauseAndWait();
}
public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
if (i == cameraPermissionReqCode) {
if (iArr.length <= 0 || iArr[0] != 0) {
displayFrameworkBugMessageAndExit();
} else {
this.barcodeView.resume();
}
}
}
public void onResume() {
openCameraWithPermission();
this.inactivityTimer.start();
}
public void onSaveInstanceState(Bundle bundle) {
bundle.putInt(SAVED_ORIENTATION_LOCK, this.orientationLock);
}
public void returnResult(BarcodeResult barcodeResult) {
this.activity.setResult(-1, resultIntent(barcodeResult, getBarcodeImagePath(barcodeResult)));
closeAndFinish();
}
public void returnResultTimeout() {
Intent intent = new Intent(Intents.Scan.ACTION);
intent.putExtra(Intents.Scan.TIMEOUT, true);
this.activity.setResult(0, intent);
closeAndFinish();
}
}