234 lines
9.8 KiB
Java
234 lines
9.8 KiB
Java
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();
|
|
}
|
|
}
|