Initial commit
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
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();
|
||||
}
|
||||
}
|
@@ -0,0 +1,163 @@
|
||||
package com.google.zxing.client.android.camera;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Point;
|
||||
import android.hardware.Camera;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
import com.google.zxing.client.android.camera.open.CameraFacing;
|
||||
import com.google.zxing.client.android.camera.open.OpenCamera;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class CameraConfigurationManager {
|
||||
private final Context a;
|
||||
private int b;
|
||||
private int c;
|
||||
private Point d;
|
||||
private Point e;
|
||||
private Point f;
|
||||
private Point g;
|
||||
|
||||
CameraConfigurationManager(Context context) {
|
||||
this.a = context;
|
||||
}
|
||||
|
||||
void a(OpenCamera openCamera) {
|
||||
int i;
|
||||
Camera.Parameters parameters = openCamera.a().getParameters();
|
||||
Display defaultDisplay = ((WindowManager) this.a.getSystemService("window")).getDefaultDisplay();
|
||||
int rotation = defaultDisplay.getRotation();
|
||||
if (rotation == 0) {
|
||||
i = 0;
|
||||
} else if (rotation == 1) {
|
||||
i = 90;
|
||||
} else if (rotation == 2) {
|
||||
i = 180;
|
||||
} else if (rotation == 3) {
|
||||
i = 270;
|
||||
} else {
|
||||
if (rotation % 90 != 0) {
|
||||
throw new IllegalArgumentException("Bad rotation: " + rotation);
|
||||
}
|
||||
i = (rotation + 360) % 360;
|
||||
}
|
||||
Log.i("CameraConfiguration", "Display at: " + i);
|
||||
int c = openCamera.c();
|
||||
Log.i("CameraConfiguration", "Camera at: " + c);
|
||||
if (openCamera.b() == CameraFacing.FRONT) {
|
||||
c = (360 - c) % 360;
|
||||
Log.i("CameraConfiguration", "Front camera overriden to: " + c);
|
||||
}
|
||||
this.c = ((c + 360) - i) % 360;
|
||||
Log.i("CameraConfiguration", "Final display orientation: " + this.c);
|
||||
if (openCamera.b() == CameraFacing.FRONT) {
|
||||
Log.i("CameraConfiguration", "Compensating rotation for front camera");
|
||||
this.b = (360 - this.c) % 360;
|
||||
} else {
|
||||
this.b = this.c;
|
||||
}
|
||||
Log.i("CameraConfiguration", "Clockwise rotation from display to camera: " + this.b);
|
||||
Point point = new Point();
|
||||
defaultDisplay.getSize(point);
|
||||
this.d = point;
|
||||
Log.i("CameraConfiguration", "Screen resolution in current orientation: " + this.d);
|
||||
this.e = CameraConfigurationUtils.a(parameters, this.d);
|
||||
Log.i("CameraConfiguration", "Camera resolution: " + this.e);
|
||||
this.f = CameraConfigurationUtils.a(parameters, this.d);
|
||||
Log.i("CameraConfiguration", "Best available preview size: " + this.f);
|
||||
Point point2 = this.d;
|
||||
boolean z = point2.x < point2.y;
|
||||
Point point3 = this.f;
|
||||
if (z == (point3.x < point3.y)) {
|
||||
this.g = this.f;
|
||||
} else {
|
||||
Point point4 = this.f;
|
||||
this.g = new Point(point4.y, point4.x);
|
||||
}
|
||||
Log.i("CameraConfiguration", "Preview size on screen: " + this.g);
|
||||
}
|
||||
|
||||
Point b() {
|
||||
return this.d;
|
||||
}
|
||||
|
||||
void a(OpenCamera openCamera, boolean z) {
|
||||
Camera a = openCamera.a();
|
||||
Camera.Parameters parameters = a.getParameters();
|
||||
if (parameters == null) {
|
||||
Log.w("CameraConfiguration", "Device error: no camera parameters are available. Proceeding without configuration.");
|
||||
return;
|
||||
}
|
||||
Log.i("CameraConfiguration", "Initial camera parameters: " + parameters.flatten());
|
||||
if (z) {
|
||||
Log.w("CameraConfiguration", "In camera config safe mode -- most settings will not be honored");
|
||||
}
|
||||
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.a);
|
||||
a(parameters, defaultSharedPreferences, z);
|
||||
CameraConfigurationUtils.a(parameters, defaultSharedPreferences.getBoolean("preferences_auto_focus", true), defaultSharedPreferences.getBoolean("preferences_disable_continuous_focus", true), z);
|
||||
if (!z) {
|
||||
if (defaultSharedPreferences.getBoolean("preferences_invert_scan", false)) {
|
||||
CameraConfigurationUtils.c(parameters);
|
||||
}
|
||||
if (!defaultSharedPreferences.getBoolean("preferences_disable_barcode_scene_mode", true)) {
|
||||
CameraConfigurationUtils.a(parameters);
|
||||
}
|
||||
if (!defaultSharedPreferences.getBoolean("preferences_disable_metering", true)) {
|
||||
CameraConfigurationUtils.e(parameters);
|
||||
CameraConfigurationUtils.b(parameters);
|
||||
CameraConfigurationUtils.d(parameters);
|
||||
}
|
||||
parameters.setRecordingHint(true);
|
||||
}
|
||||
Point point = this.f;
|
||||
parameters.setPreviewSize(point.x, point.y);
|
||||
a.setParameters(parameters);
|
||||
a.setDisplayOrientation(this.c);
|
||||
Camera.Size previewSize = a.getParameters().getPreviewSize();
|
||||
if (previewSize != null) {
|
||||
Point point2 = this.f;
|
||||
if (point2.x == previewSize.width && point2.y == previewSize.height) {
|
||||
return;
|
||||
}
|
||||
Log.w("CameraConfiguration", "Camera said it supported preview size " + this.f.x + 'x' + this.f.y + ", but after setting it, preview size is " + previewSize.width + 'x' + previewSize.height);
|
||||
Point point3 = this.f;
|
||||
point3.x = previewSize.width;
|
||||
point3.y = previewSize.height;
|
||||
}
|
||||
}
|
||||
|
||||
Point a() {
|
||||
return this.e;
|
||||
}
|
||||
|
||||
boolean a(Camera camera) {
|
||||
Camera.Parameters parameters;
|
||||
if (camera == null || (parameters = camera.getParameters()) == null) {
|
||||
return false;
|
||||
}
|
||||
String flashMode = parameters.getFlashMode();
|
||||
return "on".equals(flashMode) || "torch".equals(flashMode);
|
||||
}
|
||||
|
||||
void a(Camera camera, boolean z) {
|
||||
Camera.Parameters parameters = camera.getParameters();
|
||||
a(parameters, z, false);
|
||||
camera.setParameters(parameters);
|
||||
}
|
||||
|
||||
private void a(Camera.Parameters parameters, SharedPreferences sharedPreferences, boolean z) {
|
||||
a(parameters, FrontLightMode.readPref(sharedPreferences) == FrontLightMode.ON, z);
|
||||
}
|
||||
|
||||
private void a(Camera.Parameters parameters, boolean z, boolean z2) {
|
||||
CameraConfigurationUtils.b(parameters, z);
|
||||
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.a);
|
||||
if (z2 || defaultSharedPreferences.getBoolean("preferences_disable_exposure", true)) {
|
||||
return;
|
||||
}
|
||||
CameraConfigurationUtils.a(parameters, z);
|
||||
}
|
||||
}
|
@@ -0,0 +1,233 @@
|
||||
package com.google.zxing.client.android.camera;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.hardware.Camera;
|
||||
import android.util.Log;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@TargetApi(15)
|
||||
/* loaded from: classes.dex */
|
||||
public final class CameraConfigurationUtils {
|
||||
static {
|
||||
Pattern.compile(";");
|
||||
}
|
||||
|
||||
public static void a(Camera.Parameters parameters, boolean z, boolean z2, boolean z3) {
|
||||
List<String> supportedFocusModes = parameters.getSupportedFocusModes();
|
||||
String a = z ? (z3 || z2) ? a("focus mode", supportedFocusModes, "auto") : a("focus mode", supportedFocusModes, "continuous-picture", "continuous-video", "auto") : null;
|
||||
if (!z3 && a == null) {
|
||||
a = a("focus mode", supportedFocusModes, "macro", "edof");
|
||||
}
|
||||
if (a != null) {
|
||||
if (!a.equals(parameters.getFocusMode())) {
|
||||
parameters.setFocusMode(a);
|
||||
return;
|
||||
}
|
||||
Log.i("CameraConfiguration", "Focus mode already set to " + a);
|
||||
}
|
||||
}
|
||||
|
||||
public static void b(Camera.Parameters parameters, boolean z) {
|
||||
List<String> supportedFlashModes = parameters.getSupportedFlashModes();
|
||||
String a = z ? a("flash mode", supportedFlashModes, "torch", "on") : a("flash mode", supportedFlashModes, "off");
|
||||
if (a != null) {
|
||||
if (a.equals(parameters.getFlashMode())) {
|
||||
Log.i("CameraConfiguration", "Flash mode already set to " + a);
|
||||
return;
|
||||
}
|
||||
Log.i("CameraConfiguration", "Setting flash mode to " + a);
|
||||
parameters.setFlashMode(a);
|
||||
}
|
||||
}
|
||||
|
||||
public static void c(Camera.Parameters parameters) {
|
||||
if ("negative".equals(parameters.getColorEffect())) {
|
||||
Log.i("CameraConfiguration", "Negative effect already set");
|
||||
return;
|
||||
}
|
||||
String a = a("color effect", parameters.getSupportedColorEffects(), "negative");
|
||||
if (a != null) {
|
||||
parameters.setColorEffect(a);
|
||||
}
|
||||
}
|
||||
|
||||
public static void d(Camera.Parameters parameters) {
|
||||
if (parameters.getMaxNumMeteringAreas() <= 0) {
|
||||
Log.i("CameraConfiguration", "Device does not support metering areas");
|
||||
return;
|
||||
}
|
||||
Log.i("CameraConfiguration", "Old metering areas: " + parameters.getMeteringAreas());
|
||||
List<Camera.Area> a = a(400);
|
||||
Log.i("CameraConfiguration", "Setting metering area to : " + a(a));
|
||||
parameters.setMeteringAreas(a);
|
||||
}
|
||||
|
||||
public static void e(Camera.Parameters parameters) {
|
||||
if (!parameters.isVideoStabilizationSupported()) {
|
||||
Log.i("CameraConfiguration", "This device does not support video stabilization");
|
||||
} else if (parameters.getVideoStabilization()) {
|
||||
Log.i("CameraConfiguration", "Video stabilization already enabled");
|
||||
} else {
|
||||
Log.i("CameraConfiguration", "Enabling video stabilization...");
|
||||
parameters.setVideoStabilization(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void a(Camera.Parameters parameters, boolean z) {
|
||||
int minExposureCompensation = parameters.getMinExposureCompensation();
|
||||
int maxExposureCompensation = parameters.getMaxExposureCompensation();
|
||||
float exposureCompensationStep = parameters.getExposureCompensationStep();
|
||||
if (minExposureCompensation != 0 || maxExposureCompensation != 0) {
|
||||
if (exposureCompensationStep > 0.0f) {
|
||||
int round = Math.round((z ? 0.0f : 1.5f) / exposureCompensationStep);
|
||||
float f = exposureCompensationStep * round;
|
||||
int max = Math.max(Math.min(round, maxExposureCompensation), minExposureCompensation);
|
||||
if (parameters.getExposureCompensation() == max) {
|
||||
Log.i("CameraConfiguration", "Exposure compensation already set to " + max + " / " + f);
|
||||
return;
|
||||
}
|
||||
Log.i("CameraConfiguration", "Setting exposure compensation to " + max + " / " + f);
|
||||
parameters.setExposureCompensation(max);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Log.i("CameraConfiguration", "Camera does not support exposure compensation");
|
||||
}
|
||||
|
||||
public static void b(Camera.Parameters parameters) {
|
||||
if (parameters.getMaxNumFocusAreas() > 0) {
|
||||
Log.i("CameraConfiguration", "Old focus areas: " + a(parameters.getFocusAreas()));
|
||||
List<Camera.Area> a = a(400);
|
||||
Log.i("CameraConfiguration", "Setting focus area to : " + a(a));
|
||||
parameters.setFocusAreas(a);
|
||||
return;
|
||||
}
|
||||
Log.i("CameraConfiguration", "Device does not support focus areas");
|
||||
}
|
||||
|
||||
private static List<Camera.Area> a(int i) {
|
||||
int i2 = -i;
|
||||
return Collections.singletonList(new Camera.Area(new Rect(i2, i2, i, i), 1));
|
||||
}
|
||||
|
||||
public static void a(Camera.Parameters parameters) {
|
||||
if ("barcode".equals(parameters.getSceneMode())) {
|
||||
Log.i("CameraConfiguration", "Barcode scene mode already set");
|
||||
return;
|
||||
}
|
||||
String a = a("scene mode", parameters.getSupportedSceneModes(), "barcode");
|
||||
if (a != null) {
|
||||
parameters.setSceneMode(a);
|
||||
}
|
||||
}
|
||||
|
||||
public static Point a(Camera.Parameters parameters, Point point) {
|
||||
List<Camera.Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes();
|
||||
if (supportedPreviewSizes == null) {
|
||||
Log.w("CameraConfiguration", "Device returned no supported preview sizes; using default");
|
||||
Camera.Size previewSize = parameters.getPreviewSize();
|
||||
if (previewSize != null) {
|
||||
return new Point(previewSize.width, previewSize.height);
|
||||
}
|
||||
throw new IllegalStateException("Parameters contained no preview size!");
|
||||
}
|
||||
ArrayList<Camera.Size> arrayList = new ArrayList(supportedPreviewSizes);
|
||||
Collections.sort(arrayList, new Comparator<Camera.Size>() { // from class: com.google.zxing.client.android.camera.CameraConfigurationUtils.1
|
||||
@Override // java.util.Comparator
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public int compare(Camera.Size size, Camera.Size size2) {
|
||||
int i = size.height * size.width;
|
||||
int i2 = size2.height * size2.width;
|
||||
if (i2 < i) {
|
||||
return -1;
|
||||
}
|
||||
return i2 > i ? 1 : 0;
|
||||
}
|
||||
});
|
||||
if (Log.isLoggable("CameraConfiguration", 4)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Camera.Size size : arrayList) {
|
||||
sb.append(size.width);
|
||||
sb.append('x');
|
||||
sb.append(size.height);
|
||||
sb.append(' ');
|
||||
}
|
||||
Log.i("CameraConfiguration", "Supported preview sizes: " + ((Object) sb));
|
||||
}
|
||||
double d = point.x / point.y;
|
||||
Iterator it = arrayList.iterator();
|
||||
while (true) {
|
||||
if (it.hasNext()) {
|
||||
Camera.Size size2 = (Camera.Size) it.next();
|
||||
int i = size2.width;
|
||||
int i2 = size2.height;
|
||||
if (i * i2 < 153600) {
|
||||
it.remove();
|
||||
} else {
|
||||
boolean z = i < i2;
|
||||
int i3 = z ? i2 : i;
|
||||
int i4 = z ? i : i2;
|
||||
if (Math.abs((i3 / i4) - d) > 0.15d) {
|
||||
it.remove();
|
||||
} else if (i3 == point.x && i4 == point.y) {
|
||||
Point point2 = new Point(i, i2);
|
||||
Log.i("CameraConfiguration", "Found preview size exactly matching screen size: " + point2);
|
||||
return point2;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!arrayList.isEmpty()) {
|
||||
Camera.Size size3 = (Camera.Size) arrayList.get(0);
|
||||
Point point3 = new Point(size3.width, size3.height);
|
||||
Log.i("CameraConfiguration", "Using largest suitable preview size: " + point3);
|
||||
return point3;
|
||||
}
|
||||
Camera.Size previewSize2 = parameters.getPreviewSize();
|
||||
if (previewSize2 != null) {
|
||||
Point point4 = new Point(previewSize2.width, previewSize2.height);
|
||||
Log.i("CameraConfiguration", "No suitable preview sizes, using default: " + point4);
|
||||
return point4;
|
||||
}
|
||||
throw new IllegalStateException("Parameters contained no preview size!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String a(String str, Collection<String> collection, String... strArr) {
|
||||
Log.i("CameraConfiguration", "Requesting " + str + " value from among: " + Arrays.toString(strArr));
|
||||
Log.i("CameraConfiguration", "Supported " + str + " values: " + collection);
|
||||
if (collection != null) {
|
||||
for (String str2 : strArr) {
|
||||
if (collection.contains(str2)) {
|
||||
Log.i("CameraConfiguration", "Can set " + str + " to: " + str2);
|
||||
return str2;
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.i("CameraConfiguration", "No supported values match");
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String a(Iterable<Camera.Area> iterable) {
|
||||
if (iterable == null) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Camera.Area area : iterable) {
|
||||
sb.append(area.rect);
|
||||
sb.append(':');
|
||||
sb.append(area.weight);
|
||||
sb.append(' ');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@@ -0,0 +1,232 @@
|
||||
package com.google.zxing.client.android.camera;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.hardware.Camera;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceHolder;
|
||||
import com.google.zxing.PlanarYUVLuminanceSource;
|
||||
import com.google.zxing.client.android.camera.open.CameraFacing;
|
||||
import com.google.zxing.client.android.camera.open.OpenCamera;
|
||||
import com.google.zxing.client.android.camera.open.OpenCameraInterface;
|
||||
import java.io.IOException;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class CameraManager {
|
||||
private static final String m = "CameraManager";
|
||||
private final Context a;
|
||||
private final CameraConfigurationManager b;
|
||||
private OpenCamera c;
|
||||
private AutoFocusManager d;
|
||||
private Rect e;
|
||||
private Rect f;
|
||||
private boolean g;
|
||||
private boolean h;
|
||||
private int i = -1;
|
||||
private int j;
|
||||
private int k;
|
||||
private final PreviewCallback l;
|
||||
|
||||
public CameraManager(Context context) {
|
||||
this.a = context;
|
||||
this.b = new CameraConfigurationManager(context);
|
||||
this.l = new PreviewCallback(this.b);
|
||||
}
|
||||
|
||||
public synchronized void a(SurfaceHolder surfaceHolder) throws IOException {
|
||||
OpenCamera openCamera = this.c;
|
||||
if (openCamera == null) {
|
||||
openCamera = OpenCameraInterface.a(this.i);
|
||||
if (openCamera == null) {
|
||||
throw new IOException("Camera.open() failed to return object from driver");
|
||||
}
|
||||
this.c = openCamera;
|
||||
}
|
||||
if (!this.g) {
|
||||
this.g = true;
|
||||
this.b.a(openCamera);
|
||||
if (this.j > 0 && this.k > 0) {
|
||||
a(this.j, this.k);
|
||||
this.j = 0;
|
||||
this.k = 0;
|
||||
}
|
||||
}
|
||||
Camera a = openCamera.a();
|
||||
Camera.Parameters parameters = a.getParameters();
|
||||
String flatten = parameters == null ? null : parameters.flatten();
|
||||
try {
|
||||
this.b.a(openCamera, false);
|
||||
} catch (RuntimeException unused) {
|
||||
Log.w(m, "Camera rejected parameters. Setting only minimal safe-mode parameters");
|
||||
Log.i(m, "Resetting to saved camera params: " + flatten);
|
||||
if (flatten != null) {
|
||||
Camera.Parameters parameters2 = a.getParameters();
|
||||
parameters2.unflatten(flatten);
|
||||
try {
|
||||
a.setParameters(parameters2);
|
||||
this.b.a(openCamera, true);
|
||||
} catch (RuntimeException unused2) {
|
||||
Log.w(m, "Camera rejected even safe-mode parameters! No configuration");
|
||||
}
|
||||
}
|
||||
}
|
||||
a.setPreviewDisplay(surfaceHolder);
|
||||
}
|
||||
|
||||
public CameraFacing b() {
|
||||
OpenCamera openCamera = this.c;
|
||||
return openCamera != null ? openCamera.b() : CameraFacing.BACK;
|
||||
}
|
||||
|
||||
public synchronized Rect c() {
|
||||
if (this.e == null) {
|
||||
if (this.c == null) {
|
||||
return null;
|
||||
}
|
||||
Point b = this.b.b();
|
||||
if (b == null) {
|
||||
return null;
|
||||
}
|
||||
int a = a(b.x, 240, 1200);
|
||||
int a2 = a(b.y, 240, 675);
|
||||
int i = (b.x - a) / 2;
|
||||
int i2 = (b.y - a2) / 2;
|
||||
this.e = new Rect(i, i2, a + i, a2 + i2);
|
||||
Log.d(m, "Calculated framing rect: " + this.e);
|
||||
}
|
||||
return this.e;
|
||||
}
|
||||
|
||||
public synchronized Rect d() {
|
||||
if (this.f == null) {
|
||||
Rect c = c();
|
||||
if (c == null) {
|
||||
return null;
|
||||
}
|
||||
Rect rect = new Rect(c);
|
||||
Point a = this.b.a();
|
||||
Point b = this.b.b();
|
||||
if (a != null && b != null) {
|
||||
rect.left = (rect.left * a.x) / b.x;
|
||||
rect.right = (rect.right * a.x) / b.x;
|
||||
rect.top = (rect.top * a.y) / b.y;
|
||||
rect.bottom = (rect.bottom * a.y) / b.y;
|
||||
this.f = rect;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return this.f;
|
||||
}
|
||||
|
||||
public int e() {
|
||||
OpenCamera openCamera = this.c;
|
||||
if (openCamera != null) {
|
||||
return openCamera.c();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public synchronized boolean f() {
|
||||
return this.c != null;
|
||||
}
|
||||
|
||||
public synchronized void g() {
|
||||
OpenCamera openCamera = this.c;
|
||||
if (openCamera != null && !this.h) {
|
||||
openCamera.a().startPreview();
|
||||
this.h = true;
|
||||
this.d = new AutoFocusManager(this.a, openCamera.a());
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void h() {
|
||||
if (this.d != null) {
|
||||
this.d.b();
|
||||
this.d = null;
|
||||
}
|
||||
if (this.c != null && this.h) {
|
||||
this.c.a().stopPreview();
|
||||
this.l.a(null, 0);
|
||||
this.h = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void b(int i) {
|
||||
OpenCamera openCamera = this.c;
|
||||
if (openCamera != null) {
|
||||
openCamera.a().setDisplayOrientation(i);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void a() {
|
||||
if (this.c != null) {
|
||||
this.c.a().release();
|
||||
this.c = null;
|
||||
this.e = null;
|
||||
this.f = null;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void a(boolean z) {
|
||||
OpenCamera openCamera = this.c;
|
||||
if (openCamera != null && z != this.b.a(openCamera.a())) {
|
||||
boolean z2 = this.d != null;
|
||||
if (z2) {
|
||||
this.d.b();
|
||||
this.d = null;
|
||||
}
|
||||
this.b.a(openCamera.a(), z);
|
||||
if (z2) {
|
||||
this.d = new AutoFocusManager(this.a, openCamera.a());
|
||||
this.d.a();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void a(Handler handler, int i) {
|
||||
OpenCamera openCamera = this.c;
|
||||
if (openCamera != null && this.h) {
|
||||
this.l.a(handler, i);
|
||||
openCamera.a().setOneShotPreviewCallback(this.l);
|
||||
}
|
||||
}
|
||||
|
||||
private static int a(int i, int i2, int i3) {
|
||||
int i4 = (i * 9) / 20;
|
||||
return i4 < i2 ? i2 : i4 > i3 ? i3 : i4;
|
||||
}
|
||||
|
||||
public synchronized void a(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public synchronized void a(int i, int i2) {
|
||||
if (this.g) {
|
||||
Point b = this.b.b();
|
||||
if (i > b.x) {
|
||||
i = b.x;
|
||||
}
|
||||
if (i2 > b.y) {
|
||||
i2 = b.y;
|
||||
}
|
||||
int i3 = (b.x - i) / 2;
|
||||
int i4 = (b.y - i2) / 2;
|
||||
this.e = new Rect(i3, i4, i + i3, i2 + i4);
|
||||
Log.d(m, "Calculated manual framing rect: " + this.e);
|
||||
this.f = null;
|
||||
} else {
|
||||
this.j = i;
|
||||
this.k = i2;
|
||||
}
|
||||
}
|
||||
|
||||
public PlanarYUVLuminanceSource a(byte[] bArr, int i, int i2) {
|
||||
Rect d = d();
|
||||
if (d == null) {
|
||||
return null;
|
||||
}
|
||||
return new PlanarYUVLuminanceSource(bArr, i, i2, d.left, d.top, d.width(), d.height(), false);
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.google.zxing.client.android.camera;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public enum FrontLightMode {
|
||||
ON,
|
||||
AUTO,
|
||||
OFF;
|
||||
|
||||
private static FrontLightMode parse(String str) {
|
||||
return str == null ? OFF : valueOf(str);
|
||||
}
|
||||
|
||||
public static FrontLightMode readPref(SharedPreferences sharedPreferences) {
|
||||
return parse(sharedPreferences.getString("preferences_front_light_mode", OFF.toString()));
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package com.google.zxing.client.android.camera;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.hardware.Camera;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class PreviewCallback implements Camera.PreviewCallback {
|
||||
private static final String d = PreviewCallback.class.getSimpleName();
|
||||
private final CameraConfigurationManager a;
|
||||
private Handler b;
|
||||
private int c;
|
||||
|
||||
PreviewCallback(CameraConfigurationManager cameraConfigurationManager) {
|
||||
this.a = cameraConfigurationManager;
|
||||
}
|
||||
|
||||
void a(Handler handler, int i) {
|
||||
this.b = handler;
|
||||
this.c = i;
|
||||
}
|
||||
|
||||
@Override // android.hardware.Camera.PreviewCallback
|
||||
public void onPreviewFrame(byte[] bArr, Camera camera) {
|
||||
Point a = this.a.a();
|
||||
Handler handler = this.b;
|
||||
if (a == null || handler == null) {
|
||||
Log.d(d, "Got preview callback, but no handler or resolution available");
|
||||
} else {
|
||||
handler.obtainMessage(this.c, a.x, a.y, bArr).sendToTarget();
|
||||
this.b = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package com.google.zxing.client.android.camera.open;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public enum CameraFacing {
|
||||
BACK,
|
||||
FRONT
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package com.google.zxing.client.android.camera.open;
|
||||
|
||||
import android.hardware.Camera;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class OpenCamera {
|
||||
private final int a;
|
||||
private final Camera b;
|
||||
private final CameraFacing c;
|
||||
private final int d;
|
||||
|
||||
public OpenCamera(int i, Camera camera, CameraFacing cameraFacing, int i2) {
|
||||
this.a = i;
|
||||
this.b = camera;
|
||||
this.c = cameraFacing;
|
||||
this.d = i2;
|
||||
}
|
||||
|
||||
public Camera a() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
public CameraFacing b() {
|
||||
return this.c;
|
||||
}
|
||||
|
||||
public int c() {
|
||||
return this.d;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Camera #" + this.a + " : " + this.c + ',' + this.d;
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package com.google.zxing.client.android.camera.open;
|
||||
|
||||
import android.hardware.Camera;
|
||||
import android.util.Log;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class OpenCameraInterface {
|
||||
private static final String a = "com.google.zxing.client.android.camera.open.OpenCameraInterface";
|
||||
|
||||
public static OpenCamera a(int i) {
|
||||
int numberOfCameras = Camera.getNumberOfCameras();
|
||||
if (numberOfCameras == 0) {
|
||||
Log.w(a, "No cameras!");
|
||||
return null;
|
||||
}
|
||||
if (i >= numberOfCameras) {
|
||||
Log.w(a, "Requested camera does not exist: " + i);
|
||||
return null;
|
||||
}
|
||||
if (i <= -1) {
|
||||
i = 0;
|
||||
while (i < numberOfCameras) {
|
||||
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
|
||||
Camera.getCameraInfo(i, cameraInfo);
|
||||
if (CameraFacing.values()[cameraInfo.facing] == CameraFacing.BACK) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (i == numberOfCameras) {
|
||||
Log.i(a, "No camera facing " + CameraFacing.BACK + "; returning camera #0");
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
Log.i(a, "Opening camera #" + i);
|
||||
Camera.CameraInfo cameraInfo2 = new Camera.CameraInfo();
|
||||
Camera.getCameraInfo(i, cameraInfo2);
|
||||
Camera open = Camera.open(i);
|
||||
if (open == null) {
|
||||
return null;
|
||||
}
|
||||
return new OpenCamera(i, open, CameraFacing.values()[cameraInfo2.facing], cameraInfo2.orientation);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user