217 lines
6.3 KiB
Java
217 lines
6.3 KiB
Java
package com.bottle.hp.album.capture.camera;
|
|
|
|
import android.annotation.TargetApi;
|
|
import android.content.Context;
|
|
import android.hardware.Camera;
|
|
import android.media.CamcorderProfile;
|
|
import android.os.Build;
|
|
import android.util.Log;
|
|
import android.view.SurfaceHolder;
|
|
import com.bottle.hp.album.Utils;
|
|
import com.bottle.hp.album.capture.camera.OpenCameraException;
|
|
import com.ubtrobot.log.ALog;
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class CameraWrapper {
|
|
private final int b;
|
|
private NativeCamera c;
|
|
private int e;
|
|
private Context f;
|
|
private final String a = CameraWrapper.class.getSimpleName();
|
|
private Camera.Parameters d = null;
|
|
|
|
public CameraWrapper(NativeCamera nativeCamera, int i, int i2, Context context) {
|
|
this.c = null;
|
|
this.c = nativeCamera;
|
|
this.b = i;
|
|
this.e = i2;
|
|
this.f = context;
|
|
}
|
|
|
|
private CamcorderProfile k() {
|
|
CamcorderProfile camcorderProfile = CamcorderProfile.get(1);
|
|
if (camcorderProfile != null) {
|
|
return camcorderProfile;
|
|
}
|
|
CamcorderProfile camcorderProfile2 = CamcorderProfile.get(0);
|
|
if (camcorderProfile2 != null) {
|
|
return camcorderProfile2;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void a(SurfaceHolder surfaceHolder) throws IOException {
|
|
this.c.a(surfaceHolder);
|
|
this.c.f();
|
|
}
|
|
|
|
public RecordingSize b(int i, int i2) {
|
|
CameraSize a = a(a(Build.VERSION.SDK_INT), i, i2);
|
|
if (a == null) {
|
|
ALog.a(this.a).d("Failed to find supported recording size - falling back to requested: " + i + "x" + i2);
|
|
return new RecordingSize(i, i2);
|
|
}
|
|
ALog.a(this.a).d("Recording size: " + a.b() + "x" + a.a());
|
|
return new RecordingSize(a.b(), a.a());
|
|
}
|
|
|
|
public Camera c() {
|
|
return this.c.c();
|
|
}
|
|
|
|
public int d() {
|
|
return 0;
|
|
}
|
|
|
|
public int e() {
|
|
return ((this.c.b() - (this.b * 90)) + 360) % 360;
|
|
}
|
|
|
|
public Camera.Size f() {
|
|
List<Camera.Size> supportedPictureSizes;
|
|
this.d = this.c.d();
|
|
Camera.Parameters parameters = this.d;
|
|
if (parameters == null || (supportedPictureSizes = parameters.getSupportedPictureSizes()) == null || supportedPictureSizes.size() == 0) {
|
|
return null;
|
|
}
|
|
int b = Utils.b(this.f);
|
|
int a = Utils.a(this.f);
|
|
if (a < b) {
|
|
b = a;
|
|
}
|
|
int i = 0;
|
|
while (true) {
|
|
if (i >= supportedPictureSizes.size()) {
|
|
i = -1;
|
|
break;
|
|
}
|
|
if (b == supportedPictureSizes.get(i).height) {
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
if (i == -1) {
|
|
i = supportedPictureSizes.size() / 2;
|
|
}
|
|
return supportedPictureSizes.get(i);
|
|
}
|
|
|
|
public void g() throws OpenCameraException {
|
|
try {
|
|
this.c.a(this.e);
|
|
if (this.c.c() == null) {
|
|
throw new OpenCameraException(OpenCameraException.OpenType.NOCAMERA);
|
|
}
|
|
} catch (RuntimeException e) {
|
|
e.printStackTrace();
|
|
throw new OpenCameraException(OpenCameraException.OpenType.INUSE);
|
|
}
|
|
}
|
|
|
|
public void h() throws PrepareCameraException {
|
|
try {
|
|
this.c.h();
|
|
} catch (RuntimeException e) {
|
|
e.printStackTrace();
|
|
throw new PrepareCameraException();
|
|
}
|
|
}
|
|
|
|
public void i() {
|
|
if (c() == null) {
|
|
return;
|
|
}
|
|
this.c.e();
|
|
}
|
|
|
|
public void j() throws Exception {
|
|
this.c.g();
|
|
this.c.a();
|
|
}
|
|
|
|
public void a(int i, int i2) {
|
|
if (i == 0) {
|
|
i = Utils.b(this.f);
|
|
}
|
|
if (i2 == 0) {
|
|
i2 = Utils.a(this.f);
|
|
}
|
|
Camera.Parameters d = this.c.d();
|
|
CameraSize a = a(d.getSupportedPreviewSizes(), i, i2);
|
|
Camera.Size f = f();
|
|
d.setPreviewSize(a.b(), a.a());
|
|
d.setPictureSize(f == null ? a.b() : f.width, f == null ? a.a() : f.height);
|
|
d.setPreviewFormat(17);
|
|
this.c.a(d);
|
|
this.c.b(d());
|
|
ALog.a(this.a).d("Preview size: " + a.b() + "x" + a.a());
|
|
}
|
|
|
|
public CamcorderProfile b() {
|
|
if (Build.VERSION.SDK_INT < 11) {
|
|
return k();
|
|
}
|
|
if (CamcorderProfile.hasProfile(5)) {
|
|
return CamcorderProfile.get(5);
|
|
}
|
|
if (CamcorderProfile.hasProfile(4)) {
|
|
return CamcorderProfile.get(4);
|
|
}
|
|
return k();
|
|
}
|
|
|
|
public void a() {
|
|
Camera.Parameters d = this.c.d();
|
|
d.setFocusMode("continuous-video");
|
|
this.c.a(d);
|
|
}
|
|
|
|
@TargetApi(11)
|
|
protected List<Camera.Size> a(int i) {
|
|
Camera.Parameters d = this.c.d();
|
|
if (i < 11) {
|
|
Log.e(this.a, "Using supportedPreviewSizes iso supportedVideoSizes due to API restriction");
|
|
return d.getSupportedPreviewSizes();
|
|
}
|
|
if (d.getSupportedVideoSizes() == null) {
|
|
Log.e(this.a, "Using supportedPreviewSizes because supportedVideoSizes is null");
|
|
return d.getSupportedPreviewSizes();
|
|
}
|
|
return d.getSupportedVideoSizes();
|
|
}
|
|
|
|
public CameraSize a(List<Camera.Size> list, int i, int i2) {
|
|
double d = i / i2;
|
|
Camera.Size size = null;
|
|
if (list == null) {
|
|
return null;
|
|
}
|
|
double d2 = Double.MAX_VALUE;
|
|
double d3 = Double.MAX_VALUE;
|
|
for (Camera.Size size2 : list) {
|
|
if (Math.abs((size2.width / size2.height) - d) <= 0.1d && Math.abs(size2.height - i2) < d3) {
|
|
d3 = Math.abs(size2.height - i2);
|
|
size = size2;
|
|
}
|
|
}
|
|
if (size == null) {
|
|
for (Camera.Size size3 : list) {
|
|
if (Math.abs(size3.height - i2) < d2) {
|
|
size = size3;
|
|
d2 = Math.abs(size3.height - i2);
|
|
}
|
|
}
|
|
}
|
|
if (size != null) {
|
|
return new CameraSize(size.width, size.height);
|
|
}
|
|
return new CameraSize(0, 0);
|
|
}
|
|
|
|
public void a(Camera.ShutterCallback shutterCallback, Camera.PictureCallback pictureCallback, Camera.PictureCallback pictureCallback2) {
|
|
c().takePicture(shutterCallback, pictureCallback, pictureCallback2);
|
|
}
|
|
}
|