jimu-decompiled/sources/com/google/zxing/client/android/CaptureActivity.java
2025-05-13 19:24:51 +02:00

584 lines
22 KiB
Java

package com.google.zxing.client.android;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;
import com.google.zxing.Result;
import com.google.zxing.ResultMetadataType;
import com.google.zxing.ResultPoint;
import com.google.zxing.client.android.camera.CameraManager;
import com.google.zxing.client.android.clipboard.ClipboardInterface;
import com.google.zxing.client.android.history.HistoryManager;
import com.google.zxing.client.android.result.ResultButtonListener;
import com.google.zxing.client.android.result.ResultHandler;
import com.google.zxing.client.android.result.ResultHandlerFactory;
import com.google.zxing.client.android.result.supplement.SupplementalInfoRetriever;
import com.ubtrobot.jimu.robotapi.PeripheralType;
import java.io.IOException;
import java.text.DateFormat;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.Map;
/* loaded from: classes.dex */
public final class CaptureActivity extends Activity implements SurfaceHolder.Callback, ICaptureView {
private static final String t = CaptureActivity.class.getSimpleName();
private static final String[] u = {"http://zxing.appspot.com/scan", "zxing://scan/"};
private static final Collection<ResultMetadataType> v = EnumSet.of(ResultMetadataType.ISSUE_NUMBER, ResultMetadataType.SUGGESTED_PRICE, ResultMetadataType.ERROR_CORRECTION_LEVEL, ResultMetadataType.POSSIBLE_COUNTRY);
private CameraManager a;
private CaptureActivityHandler b;
private Result c;
private ViewfinderView d;
private TextView e;
private View f;
private Result g;
private boolean h;
private boolean i;
private IntentSource j;
private String k;
private ScanFromWebPageManager l;
private Collection<BarcodeFormat> m;
private Map<DecodeHintType, ?> n;
private String o;
private HistoryManager p;
private InactivityTimer q;
private BeepManager r;
private AmbientLightManager s;
/* renamed from: com.google.zxing.client.android.CaptureActivity$1, reason: invalid class name */
static /* synthetic */ class AnonymousClass1 {
static final /* synthetic */ int[] a = new int[IntentSource.values().length];
static {
try {
a[IntentSource.NATIVE_APP_INTENT.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
a[IntentSource.PRODUCT_SEARCH_LINK.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
a[IntentSource.ZXING_LINK.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
try {
a[IntentSource.NONE.ordinal()] = 4;
} catch (NoSuchFieldError unused4) {
}
}
}
private static boolean a(String str) {
if (str == null) {
return false;
}
for (String str2 : u) {
if (str.startsWith(str2)) {
return true;
}
}
return false;
}
private int b() {
int rotation = getWindowManager().getDefaultDisplay().getRotation();
return getResources().getConfiguration().orientation == 2 ? (rotation == 0 || rotation == 1) ? 0 : 8 : (rotation == 0 || rotation == 3) ? 1 : 9;
}
private void c() {
this.f.setVisibility(8);
this.e.setText(R$string.msg_default_status);
this.e.setVisibility(0);
this.d.setVisibility(0);
this.g = null;
}
@Override // com.google.zxing.client.android.ICaptureView
public ViewfinderView J() {
return this.d;
}
@Override // com.google.zxing.client.android.ICaptureView
public CameraManager b0() {
return this.a;
}
@Override // com.google.zxing.client.android.ICaptureView
public Handler getHandler() {
return this.b;
}
@Override // android.app.Activity
public void onActivityResult(int i, int i2, Intent intent) {
int intExtra;
if (i2 != -1 || i != 47820 || this.p == null || (intExtra = intent.getIntExtra("ITEM_NUMBER", -1)) < 0) {
return;
}
a(null, this.p.a(intExtra).b());
}
@Override // android.app.Activity
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
getWindow().addFlags(PeripheralType.SERVO);
setContentView(R$layout.capture);
this.h = false;
this.q = new InactivityTimer(this);
this.r = new BeepManager(this);
this.s = new AmbientLightManager(this);
PreferenceManager.setDefaultValues(this, R$xml.preferences, false);
}
@Override // android.app.Activity
protected void onDestroy() {
this.q.d();
super.onDestroy();
}
@Override // android.app.Activity, android.view.KeyEvent.Callback
public boolean onKeyDown(int i, KeyEvent keyEvent) {
if (i != 4) {
if (i != 27 && i != 80) {
if (i == 24) {
this.a.a(true);
} else if (i == 25) {
this.a.a(false);
return true;
}
}
return true;
}
IntentSource intentSource = this.j;
if (intentSource == IntentSource.NATIVE_APP_INTENT) {
setResult(0);
finish();
return true;
}
if ((intentSource == IntentSource.NONE || intentSource == IntentSource.ZXING_LINK) && this.g != null) {
a(0L);
return true;
}
return super.onKeyDown(i, keyEvent);
}
@Override // android.app.Activity
protected void onPause() {
CaptureActivityHandler captureActivityHandler = this.b;
if (captureActivityHandler != null) {
captureActivityHandler.a();
this.b = null;
}
this.q.b();
this.s.a();
this.r.close();
this.a.a();
if (!this.h) {
((SurfaceView) findViewById(R$id.preview_view)).getHolder().removeCallback(this);
}
super.onPause();
}
@Override // android.app.Activity
protected void onResume() {
int intExtra;
super.onResume();
this.p = new HistoryManager(this);
this.p.e();
this.a = new CameraManager(getApplication());
this.d = (ViewfinderView) findViewById(R$id.viewfinder_view);
this.d.setCameraManager(this.a);
this.f = findViewById(R$id.result_view);
this.e = (TextView) findViewById(R$id.status_view);
this.b = null;
this.g = null;
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean z = true;
if (defaultSharedPreferences.getBoolean("preferences_orientation", true)) {
setRequestedOrientation(b());
} else {
Log.e("Test", "~~~~~~~~~~~~~~~~~~~~~~~setRequestedOrientation");
setRequestedOrientation(6);
}
c();
this.r.b();
this.s.a(this.a);
this.q.c();
Intent intent = getIntent();
if (!defaultSharedPreferences.getBoolean("preferences_copy_to_clipboard", true) || (intent != null && !intent.getBooleanExtra("SAVE_HISTORY", true))) {
z = false;
}
this.i = z;
this.j = IntentSource.NONE;
this.k = null;
this.l = null;
this.m = null;
this.o = null;
if (intent != null) {
String action = intent.getAction();
String dataString = intent.getDataString();
if ("com.google.zxing.client.android.SCAN".equals(action)) {
this.j = IntentSource.NATIVE_APP_INTENT;
this.m = DecodeFormatManager.a(intent);
this.n = DecodeHintManager.a(intent);
if (intent.hasExtra("SCAN_WIDTH") && intent.hasExtra("SCAN_HEIGHT")) {
int intExtra2 = intent.getIntExtra("SCAN_WIDTH", 0);
int intExtra3 = intent.getIntExtra("SCAN_HEIGHT", 0);
if (intExtra2 > 0 && intExtra3 > 0) {
this.a.a(intExtra2, intExtra3);
}
}
if (intent.hasExtra("SCAN_CAMERA_ID") && (intExtra = intent.getIntExtra("SCAN_CAMERA_ID", -1)) >= 0) {
this.a.a(intExtra);
}
String stringExtra = intent.getStringExtra("PROMPT_MESSAGE");
if (stringExtra != null) {
this.e.setText(stringExtra);
}
} else if (dataString != null && dataString.contains("http://www.google") && dataString.contains("/m/products/scan")) {
this.j = IntentSource.PRODUCT_SEARCH_LINK;
this.k = dataString;
this.m = DecodeFormatManager.b;
} else if (a(dataString)) {
this.j = IntentSource.ZXING_LINK;
this.k = dataString;
Uri parse = Uri.parse(dataString);
this.l = new ScanFromWebPageManager(parse);
this.m = DecodeFormatManager.a(parse);
this.n = DecodeHintManager.a(parse);
}
this.o = intent.getStringExtra("CHARACTER_SET");
}
SurfaceHolder holder = ((SurfaceView) findViewById(R$id.preview_view)).getHolder();
if (this.h) {
a(holder);
} else {
holder.addCallback(this);
}
}
@Override // android.view.SurfaceHolder.Callback
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
}
@Override // android.view.SurfaceHolder.Callback
public void surfaceCreated(SurfaceHolder surfaceHolder) {
if (surfaceHolder == null) {
Log.e(t, "*** WARNING *** surfaceCreated() gave us a null surface!");
}
if (this.h) {
return;
}
this.h = true;
a(surfaceHolder);
}
@Override // android.view.SurfaceHolder.Callback
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
this.h = false;
}
@Override // com.google.zxing.client.android.ICaptureView
public void w() {
this.d.a();
}
private void a(Bitmap bitmap, Result result) {
if (this.b == null) {
this.c = result;
return;
}
if (result != null) {
this.c = result;
}
Result result2 = this.c;
if (result2 != null) {
this.b.sendMessage(Message.obtain(this.b, R$id.decode_succeeded, result2));
}
this.c = null;
}
private void b(Result result, ResultHandler resultHandler, Bitmap bitmap) {
a(resultHandler);
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
if (resultHandler.d() != null && defaultSharedPreferences.getBoolean("preferences_auto_open_web", false)) {
resultHandler.b(resultHandler.d().intValue());
return;
}
this.e.setVisibility(8);
this.d.setVisibility(8);
this.f.setVisibility(0);
ImageView imageView = (ImageView) findViewById(R$id.barcode_image_view);
if (bitmap == null) {
imageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R$drawable.launcher_icon));
} else {
imageView.setImageBitmap(bitmap);
}
((TextView) findViewById(R$id.format_text_view)).setText(result.a().toString());
((TextView) findViewById(R$id.type_text_view)).setText(resultHandler.h().toString());
((TextView) findViewById(R$id.time_text_view)).setText(DateFormat.getDateTimeInstance(3, 3).format(Long.valueOf(result.f())));
TextView textView = (TextView) findViewById(R$id.meta_text_view);
View findViewById = findViewById(R$id.meta_text_view_label);
textView.setVisibility(8);
findViewById.setVisibility(8);
Map<ResultMetadataType, Object> c = result.c();
if (c != null) {
StringBuilder sb = new StringBuilder(20);
for (Map.Entry<ResultMetadataType, Object> entry : c.entrySet()) {
if (v.contains(entry.getKey())) {
sb.append(entry.getValue());
sb.append('\n');
}
}
if (sb.length() > 0) {
sb.setLength(sb.length() - 1);
textView.setText(sb);
textView.setVisibility(0);
findViewById.setVisibility(0);
}
}
CharSequence e = resultHandler.e();
TextView textView2 = (TextView) findViewById(R$id.contents_text_view);
textView2.setText(e);
textView2.setTextSize(2, Math.max(22, 32 - (e.length() / 4)));
TextView textView3 = (TextView) findViewById(R$id.contents_supplement_text_view);
textView3.setText("");
textView3.setOnClickListener(null);
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("preferences_supplemental", true)) {
SupplementalInfoRetriever.a(textView3, resultHandler.g(), this.p, this);
}
int c2 = resultHandler.c();
ViewGroup viewGroup = (ViewGroup) findViewById(R$id.result_button_view);
viewGroup.requestFocus();
for (int i = 0; i < 4; i++) {
TextView textView4 = (TextView) viewGroup.getChildAt(i);
if (i < c2) {
textView4.setVisibility(0);
textView4.setText(resultHandler.a(i));
textView4.setOnClickListener(new ResultButtonListener(resultHandler, i));
} else {
textView4.setVisibility(8);
}
}
}
@Override // com.google.zxing.client.android.ICaptureView
public void a(Result result, Bitmap bitmap, float f) {
this.q.a();
this.g = result;
ResultHandler a = ResultHandlerFactory.a(this, this, result);
boolean z = bitmap != null;
if (z) {
this.p.a(result, a);
this.r.a();
a(bitmap, f, result);
}
int i = AnonymousClass1.a[this.j.ordinal()];
if (i == 1 || i == 2) {
a(result, a, bitmap);
return;
}
if (i == 3) {
ScanFromWebPageManager scanFromWebPageManager = this.l;
if (scanFromWebPageManager != null && scanFromWebPageManager.a()) {
a(result, a, bitmap);
return;
} else {
b(result, a, bitmap);
return;
}
}
if (i != 4) {
return;
}
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
if (z && defaultSharedPreferences.getBoolean("preferences_bulk_mode", false)) {
Toast.makeText(getApplicationContext(), getResources().getString(R$string.msg_bulk_mode_scanned) + " (" + result.e() + ')', 0).show();
a(a);
a(1000L);
return;
}
b(result, a, bitmap);
}
private void a(Bitmap bitmap, float f, Result result) {
ResultPoint[] d = result.d();
if (d == null || d.length <= 0) {
return;
}
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColor(getResources().getColor(R$color.result_points));
if (d.length == 2) {
paint.setStrokeWidth(4.0f);
a(canvas, paint, d[0], d[1], f);
return;
}
if (d.length == 4 && (result.a() == BarcodeFormat.UPC_A || result.a() == BarcodeFormat.EAN_13)) {
a(canvas, paint, d[0], d[1], f);
a(canvas, paint, d[2], d[3], f);
return;
}
paint.setStrokeWidth(10.0f);
for (ResultPoint resultPoint : d) {
if (resultPoint != null) {
canvas.drawPoint(resultPoint.a() * f, resultPoint.b() * f, paint);
}
}
}
private static void a(Canvas canvas, Paint paint, ResultPoint resultPoint, ResultPoint resultPoint2, float f) {
if (resultPoint == null || resultPoint2 == null) {
return;
}
canvas.drawLine(f * resultPoint.a(), f * resultPoint.b(), f * resultPoint2.a(), f * resultPoint2.b(), paint);
}
private void a(Result result, ResultHandler resultHandler, Bitmap bitmap) {
ScanFromWebPageManager scanFromWebPageManager;
if (bitmap != null) {
this.d.a(bitmap);
}
long longExtra = getIntent() != null ? getIntent().getLongExtra("RESULT_DISPLAY_DURATION_MS", 1500L) : 1500L;
int i = 0;
if (longExtra > 0) {
String valueOf = String.valueOf(result);
if (valueOf.length() > 32) {
valueOf = valueOf.substring(0, 32) + " ...";
}
this.e.setText(getString(resultHandler.f()) + " : " + valueOf);
}
a(resultHandler);
int i2 = AnonymousClass1.a[this.j.ordinal()];
if (i2 != 1) {
if (i2 != 2) {
if (i2 == 3 && (scanFromWebPageManager = this.l) != null && scanFromWebPageManager.a()) {
Object a = this.l.a(result, resultHandler);
this.l = null;
a(R$id.launch_product_query, a, longExtra);
return;
}
return;
}
a(R$id.launch_product_query, this.k.substring(0, this.k.lastIndexOf("/scan")) + "?q=" + ((Object) resultHandler.e()) + "&source=zxing", longExtra);
return;
}
Intent intent = new Intent(getIntent().getAction());
intent.addFlags(524288);
intent.putExtra("SCAN_RESULT", result.toString());
intent.putExtra("SCAN_RESULT_FORMAT", result.a().toString());
byte[] b = result.b();
if (b != null && b.length > 0) {
intent.putExtra("SCAN_RESULT_BYTES", b);
}
Map<ResultMetadataType, Object> c = result.c();
if (c != null) {
if (c.containsKey(ResultMetadataType.UPC_EAN_EXTENSION)) {
intent.putExtra("SCAN_RESULT_UPC_EAN_EXTENSION", c.get(ResultMetadataType.UPC_EAN_EXTENSION).toString());
}
Number number = (Number) c.get(ResultMetadataType.ORIENTATION);
if (number != null) {
intent.putExtra("SCAN_RESULT_ORIENTATION", number.intValue());
}
String str = (String) c.get(ResultMetadataType.ERROR_CORRECTION_LEVEL);
if (str != null) {
intent.putExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL", str);
}
Iterable iterable = (Iterable) c.get(ResultMetadataType.BYTE_SEGMENTS);
if (iterable != null) {
Iterator it = iterable.iterator();
while (it.hasNext()) {
intent.putExtra("SCAN_RESULT_BYTE_SEGMENTS_" + i, (byte[]) it.next());
i++;
}
}
}
a(R$id.return_scan_result, intent, longExtra);
}
private void a(ResultHandler resultHandler) {
if (!this.i || resultHandler.a()) {
return;
}
ClipboardInterface.a(resultHandler.e(), this);
}
private void a(int i, Object obj, long j) {
CaptureActivityHandler captureActivityHandler = this.b;
if (captureActivityHandler != null) {
Message obtain = Message.obtain(captureActivityHandler, i, obj);
if (j > 0) {
this.b.sendMessageDelayed(obtain, j);
} else {
this.b.sendMessage(obtain);
}
}
}
private void a(SurfaceHolder surfaceHolder) {
if (surfaceHolder != null) {
if (this.a.f()) {
Log.w(t, "initCamera() while already open -- late SurfaceView callback?");
return;
}
try {
this.a.a(surfaceHolder);
if (this.b == null) {
this.b = new CaptureActivityHandler(this, this, this.m, this.n, this.o, this.a);
}
a(null, null);
return;
} catch (IOException e) {
Log.w(t, e);
a();
return;
} catch (RuntimeException e2) {
Log.w(t, "Unexpected error initializing camera", e2);
a();
return;
}
}
throw new IllegalStateException("No SurfaceHolder provided");
}
private void a() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R$string.scan_name));
builder.setMessage(getString(R$string.msg_camera_framework_bug));
builder.setPositiveButton(R$string.button_ok, new FinishListener(this));
builder.setOnCancelListener(new FinishListener(this));
builder.show();
}
@Override // com.google.zxing.client.android.ICaptureView
public void a(long j) {
CaptureActivityHandler captureActivityHandler = this.b;
if (captureActivityHandler != null) {
captureActivityHandler.sendEmptyMessageDelayed(R$id.restart_preview, j);
}
c();
}
}