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

107 lines
3.2 KiB
Java

package com.google.zxing.client.android.camera;
import android.content.Context;
import android.content.SharedPreferences;
import android.hardware.Camera;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.util.Log;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.RejectedExecutionException;
/* loaded from: classes.dex */
final class AutoFocusManager implements Camera.AutoFocusCallback {
private static final String f = AutoFocusManager.class.getSimpleName();
private static final Collection<String> g = new ArrayList(2);
private boolean a;
private boolean b;
private final boolean c;
private final Camera d;
private AsyncTask<?, ?, ?> e;
private final class AutoFocusTask extends AsyncTask<Object, Object, Object> {
private AutoFocusTask() {
}
@Override // android.os.AsyncTask
protected Object doInBackground(Object... objArr) {
try {
Thread.sleep(2000L);
} catch (InterruptedException unused) {
Thread.currentThread().interrupt();
}
AutoFocusManager.this.a();
return null;
}
}
static {
g.add("auto");
g.add("macro");
}
AutoFocusManager(Context context, Camera camera) {
this.d = camera;
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
String focusMode = camera.getParameters().getFocusMode();
this.c = defaultSharedPreferences.getBoolean("preferences_auto_focus", true) && g.contains(focusMode);
Log.i(f, "Current focus mode '" + focusMode + "'; use auto focus? " + this.c);
a();
}
private synchronized void c() {
if (!this.a && this.e == null) {
AutoFocusTask autoFocusTask = new AutoFocusTask();
try {
autoFocusTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Object[0]);
this.e = autoFocusTask;
} catch (RejectedExecutionException e) {
Log.w(f, "Could not request auto focus", e);
}
}
}
private synchronized void d() {
if (this.e != null) {
if (this.e.getStatus() != AsyncTask.Status.FINISHED) {
this.e.cancel(true);
}
this.e = null;
}
}
synchronized void a() {
if (this.c) {
this.e = null;
if (!this.a && !this.b) {
try {
this.d.autoFocus(this);
this.b = true;
} catch (RuntimeException e) {
Log.w(f, "Unexpected exception while focusing", e);
c();
}
}
}
}
synchronized void b() {
this.a = true;
if (this.c) {
d();
try {
this.d.cancelAutoFocus();
} catch (RuntimeException e) {
Log.w(f, "Unexpected exception while cancelling focusing", e);
}
}
}
@Override // android.hardware.Camera.AutoFocusCallback
public synchronized void onAutoFocus(boolean z, Camera camera) {
this.b = false;
c();
}
}