141 lines
6.4 KiB
Java
141 lines
6.4 KiB
Java
package com.bottle.hp.album.capture;
|
|
|
|
import android.content.Intent;
|
|
import android.hardware.Camera;
|
|
import android.os.Bundle;
|
|
import android.os.Environment;
|
|
import android.text.TextUtils;
|
|
import android.view.View;
|
|
import android.view.WindowManager;
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
import com.bottle.hp.album.R$id;
|
|
import com.bottle.hp.album.R$layout;
|
|
import com.bottle.hp.album.Utils;
|
|
import com.bottle.hp.album.capture.camera.CameraWrapper;
|
|
import com.bottle.hp.album.capture.camera.NativeCamera;
|
|
import com.bottle.hp.album.capture.preview.CapturePreview;
|
|
import com.bottle.hp.album.capture.preview.CapturePreviewInterface;
|
|
import com.bottle.hp.album.capture.view.IPictureCaptureListener;
|
|
import com.bottle.hp.album.capture.view.PictureCaptureView;
|
|
import com.ubtrobot.log.ALog;
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class PictureCaptureActivity extends AppCompatActivity implements View.OnClickListener {
|
|
private String b;
|
|
private PictureCaptureView c;
|
|
private CameraWrapper d;
|
|
private final String a = PictureCaptureActivity.class.getSimpleName();
|
|
private Camera.PictureCallback e = new Camera.PictureCallback() { // from class: com.bottle.hp.album.capture.PictureCaptureActivity.3
|
|
@Override // android.hardware.Camera.PictureCallback
|
|
public void onPictureTaken(byte[] bArr, Camera camera) {
|
|
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath() + File.separator + "Jimu");
|
|
if (!file.exists()) {
|
|
file.mkdirs();
|
|
}
|
|
PictureCaptureActivity.this.b = file.getAbsolutePath() + File.separator + Utils.a() + ".png";
|
|
File file2 = new File(PictureCaptureActivity.this.b);
|
|
FileOutputStream fileOutputStream = null;
|
|
try {
|
|
try {
|
|
try {
|
|
FileOutputStream fileOutputStream2 = new FileOutputStream(file2);
|
|
try {
|
|
fileOutputStream2.write(bArr);
|
|
PictureCaptureActivity.this.c.a(file2.getAbsolutePath());
|
|
fileOutputStream2.close();
|
|
} catch (FileNotFoundException e) {
|
|
e = e;
|
|
fileOutputStream = fileOutputStream2;
|
|
ALog.a(PictureCaptureActivity.this.a).d("File not found: " + e.getMessage());
|
|
if (fileOutputStream != null) {
|
|
fileOutputStream.close();
|
|
}
|
|
} catch (IOException e2) {
|
|
e = e2;
|
|
fileOutputStream = fileOutputStream2;
|
|
ALog.a(PictureCaptureActivity.this.a).d("Error accessing file: " + e.getMessage());
|
|
if (fileOutputStream != null) {
|
|
fileOutputStream.close();
|
|
}
|
|
} catch (Throwable th) {
|
|
th = th;
|
|
fileOutputStream = fileOutputStream2;
|
|
if (fileOutputStream != null) {
|
|
try {
|
|
fileOutputStream.close();
|
|
} catch (Exception e3) {
|
|
e3.printStackTrace();
|
|
}
|
|
}
|
|
throw th;
|
|
}
|
|
} catch (FileNotFoundException e4) {
|
|
e = e4;
|
|
} catch (IOException e5) {
|
|
e = e5;
|
|
}
|
|
} catch (Exception e6) {
|
|
e6.printStackTrace();
|
|
}
|
|
} catch (Throwable th2) {
|
|
th = th2;
|
|
}
|
|
}
|
|
};
|
|
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
}
|
|
|
|
@Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, androidx.core.app.ComponentActivity, android.app.Activity
|
|
protected void onCreate(Bundle bundle) {
|
|
super.onCreate(bundle);
|
|
setContentView(R$layout.activity_picture_capture);
|
|
this.c = (PictureCaptureView) findViewById(R$id.pictureCaptureView);
|
|
this.c.setPictureCaptureListener(new IPictureCaptureListener() { // from class: com.bottle.hp.album.capture.PictureCaptureActivity.1
|
|
@Override // com.bottle.hp.album.capture.view.IPictureCaptureListener
|
|
public void a() {
|
|
Intent intent = new Intent();
|
|
intent.putExtra("data", PictureCaptureActivity.this.b);
|
|
PictureCaptureActivity.this.setResult(-1, intent);
|
|
PictureCaptureActivity.this.finish();
|
|
}
|
|
|
|
@Override // com.bottle.hp.album.capture.view.IPictureCaptureListener
|
|
public void b() {
|
|
PictureCaptureActivity.this.d.a((Camera.ShutterCallback) null, (Camera.PictureCallback) null, PictureCaptureActivity.this.e);
|
|
}
|
|
|
|
@Override // com.bottle.hp.album.capture.view.IPictureCaptureListener
|
|
public void onCancel() {
|
|
if (!TextUtils.isEmpty(PictureCaptureActivity.this.b)) {
|
|
new File(PictureCaptureActivity.this.b).delete();
|
|
PictureCaptureActivity.this.b = "";
|
|
}
|
|
PictureCaptureActivity.this.c.a();
|
|
}
|
|
});
|
|
try {
|
|
this.d = new CameraWrapper(new NativeCamera(), ((WindowManager) getSystemService("window")).getDefaultDisplay().getRotation(), 0, this);
|
|
this.d.g();
|
|
new CapturePreview(new CapturePreviewInterface() { // from class: com.bottle.hp.album.capture.PictureCaptureActivity.2
|
|
@Override // com.bottle.hp.album.capture.preview.CapturePreviewInterface
|
|
public void i() {
|
|
PictureCaptureActivity.this.finish();
|
|
}
|
|
}, this.d, this.c.getPreviewSurfaceHolder());
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentActivity, android.app.Activity
|
|
protected void onPause() {
|
|
super.onPause();
|
|
}
|
|
}
|