164 lines
6.5 KiB
Java
164 lines
6.5 KiB
Java
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);
|
|
}
|
|
}
|