Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,389 @@
package com.bottle.hp.album.capture;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.baidu.cloud.media.player.IMediaPlayer;
import com.bottle.hp.album.R$id;
import com.bottle.hp.album.R$layout;
import com.bottle.hp.album.R$mipmap;
import java.lang.ref.WeakReference;
/* loaded from: classes.dex */
public class MediaPlayerActivity extends AppCompatActivity implements SurfaceHolder.Callback, MediaPlayer.OnCompletionListener, MediaPlayer.OnBufferingUpdateListener, MediaPlayer.OnErrorListener, MediaPlayer.OnPreparedListener, MediaPlayer.OnInfoListener, View.OnClickListener {
private ImageView b;
private ImageView c;
private SurfaceView d;
private ImageView e;
private TextView f;
private ImageView g;
private ProgressBar h;
private View i;
private TextView j;
private MediaPlayer k;
private SurfaceHolder l;
private String m;
private boolean n;
private Handler x;
private final String a = MediaPlayerActivity.class.getSimpleName();
private int o = 0;
private int p = 0;
private boolean q = false;
private boolean r = false;
private boolean s = false;
private boolean t = false;
private boolean u = false;
private Runnable v = new Runnable() { // from class: com.bottle.hp.album.capture.MediaPlayerActivity.2
@Override // java.lang.Runnable
public void run() {
if (MediaPlayerActivity.this.r) {
try {
MediaPlayerActivity.this.p = MediaPlayerActivity.this.k.getCurrentPosition();
MediaPlayerActivity.this.a(1, null, MediaPlayerActivity.this.p, 0);
MediaPlayerActivity.this.x.postDelayed(MediaPlayerActivity.this.v, 1000L);
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
private static class StaticHandler extends Handler {
private WeakReference<MediaPlayerActivity> a;
public StaticHandler(MediaPlayerActivity mediaPlayerActivity) {
this.a = new WeakReference<>(mediaPlayerActivity);
}
public WeakReference<MediaPlayerActivity> a() {
return this.a;
}
@Override // android.os.Handler
public void handleMessage(Message message) {
if (message.what == 1 && a().get() != null) {
a().get().l(message.arg1);
}
}
}
private void D0() {
this.k = new MediaPlayer();
this.k.setOnCompletionListener(this);
this.k.setOnBufferingUpdateListener(this);
this.k.setOnErrorListener(this);
this.k.setOnPreparedListener(this);
this.k.setOnInfoListener(this);
this.k.setAudioStreamType(3);
this.k.setDisplay(this.l);
try {
this.k.setDataSource(this.m);
this.k.prepareAsync();
} catch (Exception e) {
e.printStackTrace();
}
}
private void E0() {
try {
if (this.k != null) {
this.k.pause();
this.r = false;
this.c.setVisibility(0);
this.e.setImageResource(R$mipmap.video_start);
}
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
private void F0() {
this.r = false;
if (this.k != null) {
new Thread(new Runnable() { // from class: com.bottle.hp.album.capture.MediaPlayerActivity.1
@Override // java.lang.Runnable
public void run() {
MediaPlayerActivity.this.k.release();
}
}).start();
}
}
private void G0() {
try {
if (this.t) {
this.t = false;
this.k.seekTo(this.p);
this.g.setVisibility(8);
}
if (!this.s) {
this.k.start();
}
this.r = true;
this.x.postDelayed(this.v, 200L);
this.c.setVisibility(8);
this.e.setImageResource(R$mipmap.video_stop);
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
private void c(View view) {
}
private void initData() {
try {
Intent intent = getIntent();
this.m = intent.getStringExtra("uri");
this.n = intent.getBooleanExtra("auto_close", false);
} catch (Exception e) {
e.printStackTrace();
}
}
/* JADX INFO: Access modifiers changed from: private */
public void l(int i) {
this.h.setProgress(i);
int i2 = this.o - i;
this.f.setText(String.format("%02d:%02d", Integer.valueOf(i2 / 1000000), Integer.valueOf(i2 / 1000)));
}
public void initView() {
this.b = (ImageView) findViewById(R$id.activity_media_player_img_back);
this.b.setOnClickListener(this);
this.c = (ImageView) findViewById(R$id.activity_media_player_img_play);
this.c.setOnClickListener(this);
this.e = (ImageView) findViewById(R$id.activity_media_player_img_start);
this.e.setOnClickListener(this);
this.d = (SurfaceView) findViewById(R$id.activity_media_player_surface);
this.f = (TextView) findViewById(R$id.activity_media_player_tv_reset);
this.f.setOnClickListener(this);
this.g = (ImageView) findViewById(R$id.activity_media_player_img_snagshot);
this.h = (ProgressBar) findViewById(R$id.activity_media_player_pb);
this.i = findViewById(R$id.rl_error);
this.j = (TextView) findViewById(R$id.tv_retry);
this.j.setOnClickListener(this);
this.l = this.d.getHolder();
this.l.addCallback(this);
this.l.setFixedSize(320, 220);
}
@Override // android.media.MediaPlayer.OnBufferingUpdateListener
public void onBufferingUpdate(MediaPlayer mediaPlayer, int i) {
}
@Override // android.view.View.OnClickListener
public void onClick(View view) {
int id = view.getId();
if (id == R$id.activity_media_player_img_back) {
a(view);
return;
}
if (id == R$id.tv_retry) {
d(view);
return;
}
if (id == R$id.activity_media_player_img_start) {
e(view);
} else if (id == R$id.activity_media_player_img_play) {
b(view);
} else if (id == R$id.activity_media_player_tv_reset) {
c(view);
}
}
@Override // android.media.MediaPlayer.OnCompletionListener
public void onCompletion(MediaPlayer mediaPlayer) {
this.r = false;
this.p = this.o;
this.e.setImageResource(R$mipmap.video_start);
a(1, null, this.o, 0);
if (this.u) {
this.u = false;
} else {
this.c.setVisibility(0);
}
try {
if (this.n) {
finish();
}
} catch (Exception e) {
e.printStackTrace();
}
}
@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_media_player);
this.x = new StaticHandler(this);
initView();
initData();
if (bundle != null) {
this.p = bundle.getInt("currentPosition");
this.s = bundle.getBoolean("isPause");
}
}
@Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
protected void onDestroy() {
this.x.removeCallbacksAndMessages(null);
super.onDestroy();
}
@Override // android.media.MediaPlayer.OnErrorListener
public boolean onError(MediaPlayer mediaPlayer, int i, int i2) {
Log.e(this.a, "onError:" + i + "-" + i2);
this.i.setVisibility(0);
this.u = true;
this.k.reset();
return false;
}
@Override // android.media.MediaPlayer.OnInfoListener
public boolean onInfo(MediaPlayer mediaPlayer, int i, int i2) {
Log.e(this.a, "onInfo:" + i + "-" + i2);
if (i == -1004) {
Log.e(this.a, "media error io");
return false;
}
if (i == -110) {
Log.e(this.a, "media error timeout");
return false;
}
if (i == 1) {
Log.i(this.a, "media info unknown");
return false;
}
switch (i) {
case IMediaPlayer.MEDIA_INFO_VIDEO_TRACK_LAGGING /* 700 */:
Log.i(this.a, "media info video track lagging");
break;
case IMediaPlayer.MEDIA_INFO_BUFFERING_START /* 701 */:
Log.i(this.a, "media info video buffering start");
break;
case IMediaPlayer.MEDIA_INFO_BUFFERING_END /* 702 */:
Log.i(this.a, "media info buffering end");
break;
default:
switch (i) {
case 800:
Log.i(this.a, "media info bad interleaving");
break;
case IMediaPlayer.MEDIA_INFO_NOT_SEEKABLE /* 801 */:
Log.i(this.a, "media info not seekable");
break;
case IMediaPlayer.MEDIA_INFO_METADATA_UPDATE /* 802 */:
Log.i(this.a, "media info metadata update");
break;
}
}
return false;
}
@Override // androidx.appcompat.app.AppCompatActivity, android.app.Activity, android.view.KeyEvent.Callback
public boolean onKeyDown(int i, KeyEvent keyEvent) {
if (i != 4) {
return super.onKeyDown(i, keyEvent);
}
F0();
finish();
return true;
}
@Override // androidx.fragment.app.FragmentActivity, android.app.Activity
protected void onPause() {
E0();
super.onPause();
}
@Override // android.media.MediaPlayer.OnPreparedListener
public void onPrepared(MediaPlayer mediaPlayer) {
try {
this.o = this.k.getDuration();
this.h.setMax(this.o);
this.q = true;
this.r = true;
G0();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override // androidx.fragment.app.FragmentActivity, android.app.Activity
protected void onResume() {
this.t = true;
super.onResume();
}
@Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, androidx.core.app.ComponentActivity, android.app.Activity
protected void onSaveInstanceState(Bundle bundle) {
bundle.putInt("currentPosition", this.p);
bundle.putBoolean("isPause", this.s);
super.onSaveInstanceState(bundle);
}
@Override // android.view.SurfaceHolder.Callback
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
}
@Override // android.view.SurfaceHolder.Callback
public void surfaceCreated(SurfaceHolder surfaceHolder) {
D0();
}
@Override // android.view.SurfaceHolder.Callback
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
}
private void d(View view) {
this.i.setVisibility(8);
try {
this.k.reset();
this.k.setDataSource(this.m);
this.k.prepareAsync();
} catch (Exception e) {
e.printStackTrace();
}
}
private void e(View view) {
MediaPlayer mediaPlayer = this.k;
if (mediaPlayer != null && this.q) {
if (mediaPlayer.isPlaying()) {
this.s = true;
E0();
} else {
this.s = false;
G0();
}
}
}
private void a(View view) {
F0();
finish();
}
private void b(View view) {
e((View) null);
}
protected void a(int i, Object obj, int i2, int i3) {
Handler handler = this.x;
if (handler != null) {
handler.sendMessage(handler.obtainMessage(i, i2, i3, obj));
}
}
}

View File

@@ -0,0 +1,140 @@
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();
}
}

View File

@@ -0,0 +1,624 @@
package com.bottle.hp.album.capture;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.hardware.Camera;
import android.net.Uri;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.OrientationEventListener;
import android.view.View;
import android.view.WindowManager;
import com.bottle.hp.album.BaseActivity;
import com.bottle.hp.album.R$id;
import com.bottle.hp.album.R$layout;
import com.bottle.hp.album.R$string;
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.configuration.CaptureConfiguration;
import com.bottle.hp.album.capture.configuration.PredefinedCaptureConfigurations$CaptureQuality;
import com.bottle.hp.album.capture.configuration.PredefinedCaptureConfigurations$CaptureResolution;
import com.bottle.hp.album.capture.preview.CapturePreviewInterface;
import com.bottle.hp.album.capture.recorder.AlreadyUsedException;
import com.bottle.hp.album.capture.recorder.VideoRecorder;
import com.bottle.hp.album.capture.recorder.VideoRecorderInterface;
import com.bottle.hp.album.capture.view.VideoCaptureView;
import com.ubtech.permission.JimuPermissionRequest;
import com.ubtrobot.log.ALog;
import com.yanzhenjie.permission.Permission$Group;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
/* loaded from: classes.dex */
public class VideoCaptureActivity extends BaseActivity implements Camera.PictureCallback, CapturePreviewInterface, VideoCaptureView.IVideoCaptureUIListener, VideoRecorderInterface, View.OnClickListener, Camera.PreviewCallback {
private static int y = 20000;
private VideoCaptureView d;
private CameraWrapper e;
private String g;
private Timer l;
private CaptureConfiguration p;
private VideoRecorder q;
private AlbumOrientationEventListener s;
private int t;
private TimeCounter u;
private final String c = VideoCaptureActivity.class.getSimpleName();
private int f = 5;
private boolean h = false;
private long i = 0;
private boolean j = false;
private long k = 0;
private Handler m = new Handler();
private boolean n = false;
private VideoFile o = null;
private int r = 0;
private int v = 100;
private boolean x = false;
private class AlbumOrientationEventListener extends OrientationEventListener {
public AlbumOrientationEventListener(Context context, int i) {
super(context, i);
}
@Override // android.view.OrientationEventListener
public void onOrientationChanged(int i) {
int i2;
if (i == -1 || (i2 = (((i + 45) / 90) * 90) % 360) == VideoCaptureActivity.this.t) {
return;
}
VideoCaptureActivity.this.t = i2;
ALog.a(VideoCaptureActivity.this.c).d("角度" + VideoCaptureActivity.this.t);
VideoCaptureActivity videoCaptureActivity = VideoCaptureActivity.this;
videoCaptureActivity.l(videoCaptureActivity.t);
}
}
private class StartRecordTask extends TimerTask {
private StartRecordTask() {
}
@Override // java.util.TimerTask, java.lang.Runnable
public void run() {
try {
VideoCaptureActivity.this.x = false;
VideoCaptureActivity.this.q.f();
VideoCaptureActivity.this.m.postDelayed(new Runnable() { // from class: com.bottle.hp.album.capture.VideoCaptureActivity.StartRecordTask.1
@Override // java.lang.Runnable
public void run() {
if (VideoCaptureActivity.this.e.c() == null) {
VideoCaptureActivity.this.b(R$string.tips_ask_camera_permission, 2);
} else {
VideoCaptureActivity.this.d.d();
}
}
}, 10L);
} catch (AlreadyUsedException unused) {
ALog.a(VideoCaptureActivity.this.c).d("Cannot toggle recording after cleaning up all resources");
}
}
}
private class TimeCounter extends CountDownTimer {
private long a;
public TimeCounter(long j, long j2) {
super(j, j2);
this.a = 0L;
}
public long a() {
return this.a;
}
@Override // android.os.CountDownTimer
public void onFinish() {
VideoCaptureActivity.this.d.a(100);
}
@Override // android.os.CountDownTimer
public void onTick(long j) {
int i = (int) (VideoCaptureActivity.y - j);
this.a = i;
VideoCaptureActivity.this.d.a((i * 100) / VideoCaptureActivity.y);
}
}
private void G0() {
TimeCounter timeCounter = this.u;
if (timeCounter != null) {
timeCounter.cancel();
}
}
private File H0() {
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath() + File.separator + "Jimu");
if (!file.exists()) {
file.mkdirs();
}
this.g = file.getAbsolutePath() + File.separator + Utils.a() + ".png";
return new File(this.g);
}
/* JADX INFO: Access modifiers changed from: private */
public void I0() {
try {
if (this.q != null) {
this.d.getPreviewSurfaceHolder().removeCallback(this.q.b());
this.q.d();
}
this.e = new CameraWrapper(new NativeCamera(), ((WindowManager) getSystemService("window")).getDefaultDisplay().getRotation(), this.r, this);
this.o = a((Bundle) null);
this.q = new VideoRecorder(this, this.p, this.o, this.e, this.d.getPreviewSurfaceHolder());
} catch (Exception e) {
e.printStackTrace();
Log.e(this.c, e.getMessage());
}
}
private void J0() {
if (System.currentTimeMillis() - this.k < 1000) {
return;
}
if (this.e.c() != null) {
try {
this.e.a((Camera.ShutterCallback) null, (Camera.PictureCallback) null, this);
} catch (RuntimeException e) {
e.printStackTrace();
Log.e(this.c, "拍照失败:" + e.getMessage());
b(R$string.tips_ask_camera_permission, 2);
}
} else {
Log.e(this.c, "camera 对象为空");
b(R$string.tips_ask_camera_permission, 2);
}
this.k = System.currentTimeMillis();
}
private boolean K0() {
TimeCounter timeCounter = this.u;
if (timeCounter == null || timeCounter.a() >= 1500) {
return false;
}
J0();
VideoFile videoFile = this.o;
if (videoFile != null && videoFile.a().exists()) {
this.o.a().delete();
sendBroadcast(new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE", Uri.fromFile(this.o.a())));
}
return true;
}
private void initView() {
this.d = (VideoCaptureView) findViewById(R$id.videoCaptureView);
this.d.setUIListener(this);
}
@Override // com.bottle.hp.album.capture.view.VideoCaptureView.IVideoCaptureUIListener
public void B0() {
if (this.r == 0) {
this.r = 1;
} else {
this.r = 0;
}
I0();
}
protected CaptureConfiguration E0() {
CaptureConfiguration captureConfiguration = (CaptureConfiguration) getIntent().getParcelableExtra("com.bottle.extracaptureconfiguration");
if (captureConfiguration != null) {
return captureConfiguration;
}
CaptureConfiguration captureConfiguration2 = new CaptureConfiguration();
ALog.a(this.c).d("No captureconfiguration passed - using default configuration");
return captureConfiguration2;
}
@Override // com.bottle.hp.album.capture.recorder.VideoRecorderInterface
public void f0() {
if (!this.j) {
this.m.post(new Runnable() { // from class: com.bottle.hp.album.capture.VideoCaptureActivity.3
@Override // java.lang.Runnable
public void run() {
VideoCaptureActivity.this.q.a("user cancel");
}
});
return;
}
this.g = null;
ALog.a(this.c).d("开始录制");
this.m.postDelayed(new Runnable() { // from class: com.bottle.hp.album.capture.VideoCaptureActivity.4
@Override // java.lang.Runnable
public void run() {
VideoCaptureActivity videoCaptureActivity = VideoCaptureActivity.this;
videoCaptureActivity.u = videoCaptureActivity.new TimeCounter(VideoCaptureActivity.y, VideoCaptureActivity.this.v);
VideoCaptureActivity.this.u.start();
}
}, 300L);
}
@Override // com.bottle.hp.album.capture.view.VideoCaptureView.IVideoCaptureUIListener
public void h0() {
this.j = true;
if (this.f == 1) {
return;
}
this.i = System.currentTimeMillis();
this.l = new Timer();
this.l.schedule(new StartRecordTask(), 300L);
}
@Override // com.bottle.hp.album.capture.recorder.VideoRecorderInterface
public boolean j0() {
return JimuPermissionRequest.b(this, Permission$Group.c);
}
@Override // com.bottle.hp.album.capture.recorder.VideoRecorderInterface
public void l(String str) {
ALog.a(this.c).d("停止录制");
G0();
if (this.x) {
this.g = "";
} else {
if (K0()) {
return;
}
onCancel();
}
}
@Override // com.bottle.hp.album.capture.recorder.VideoRecorderInterface
public void m(String str) {
ALog.a(this.c).d("录制失败");
G0();
setResult(0);
finish();
}
@Override // androidx.fragment.app.FragmentActivity, android.app.Activity
public void onActivityResult(int i, int i2, Intent intent) {
super.onActivityResult(i, i2, intent);
if (101 == i) {
if (i2 == -1) {
x0();
} else {
onCancel();
}
}
}
@Override // com.bottle.hp.album.capture.view.VideoCaptureView.IVideoCaptureUIListener
public void onCancel() {
VideoFile videoFile = this.o;
if (videoFile != null && videoFile.a().exists()) {
this.o.a().delete();
sendBroadcast(new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE", Uri.fromFile(this.o.a())));
}
if (!TextUtils.isEmpty(this.g)) {
File file = new File(this.g);
if (file.exists()) {
file.delete();
sendBroadcast(new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE", Uri.fromFile(file)));
}
}
this.m.postDelayed(new Runnable() { // from class: com.bottle.hp.album.capture.VideoCaptureActivity.1
@Override // java.lang.Runnable
public void run() {
VideoCaptureActivity.this.I0();
}
}, 10L);
this.m.postDelayed(new Runnable() { // from class: com.bottle.hp.album.capture.VideoCaptureActivity.2
@Override // java.lang.Runnable
public void run() {
VideoCaptureActivity.this.d.b();
}
}, 500L);
}
@Override // android.view.View.OnClickListener
public void onClick(View view) {
}
@Override // com.bottle.hp.album.BaseActivity, 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_video_capture);
c(bundle);
initView();
this.s = new AlbumOrientationEventListener(this, 3);
if (this.s.canDetectOrientation()) {
this.s.enable();
} else {
Log.e(this.c, "Can't Detect Orientation");
}
this.f = getIntent().getIntExtra("recordType", 5);
int i = this.f;
if (i == 1) {
this.d.c();
} else if (i == 2) {
this.d.e();
} else {
this.d.a();
}
}
@Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
protected void onDestroy() {
Handler handler = this.m;
if (handler != null) {
handler.removeCallbacksAndMessages(null);
}
super.onDestroy();
VideoRecorder videoRecorder = this.q;
if (videoRecorder != null) {
videoRecorder.d();
}
this.s.disable();
}
@Override // androidx.appcompat.app.AppCompatActivity, android.app.Activity, android.view.KeyEvent.Callback
public boolean onKeyDown(int i, KeyEvent keyEvent) {
if (this.j) {
return true;
}
if (i != 4) {
return super.onKeyDown(i, keyEvent);
}
setResult(0);
finish();
return true;
}
@Override // androidx.fragment.app.FragmentActivity, android.app.Activity
public void onPause() {
super.onPause();
}
@Override // android.hardware.Camera.PictureCallback
public void onPictureTaken(byte[] bArr, Camera camera) {
a(bArr);
}
@Override // android.hardware.Camera.PreviewCallback
public void onPreviewFrame(byte[] bArr, Camera camera) {
if (bArr == null || bArr.length == 0) {
}
}
@Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, androidx.core.app.ComponentActivity, android.app.Activity
public void onSaveInstanceState(Bundle bundle) {
bundle.putBoolean("com.bottle.savedrecordedboolean", this.n);
bundle.putString("com.bottle.savedoutputfilename", this.o.b());
super.onSaveInstanceState(bundle);
}
@Override // android.app.Activity, android.view.Window.Callback
public void onWindowFocusChanged(boolean z) {
super.onWindowFocusChanged(z);
if (this.h) {
return;
}
this.h = true;
I0();
}
@Override // com.bottle.hp.album.capture.view.VideoCaptureView.IVideoCaptureUIListener
public void r0() {
this.j = false;
if (this.f == 1) {
J0();
return;
}
this.l.cancel();
if (System.currentTimeMillis() - this.i >= 300) {
this.q.a("stop recoding");
} else if (this.f == 5) {
J0();
}
}
@Override // com.bottle.hp.album.capture.view.VideoCaptureView.IVideoCaptureUIListener
public void t0() {
Log.e("TestLog", "播放视频onPlayVideo");
VideoPreviewActivity.a(this, 1001, this.o.b());
}
@Override // com.bottle.hp.album.capture.recorder.VideoRecorderInterface
public void u0() {
sendBroadcast(new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE", Uri.fromFile(this.o.a())));
ALog.a(this.c).d("录制成功");
this.x = true;
if (this.u.a() < 1500) {
this.x = false;
} else {
this.m.post(new Runnable() { // from class: com.bottle.hp.album.capture.VideoCaptureActivity.5
@Override // java.lang.Runnable
public void run() {
VideoCaptureActivity videoCaptureActivity = VideoCaptureActivity.this;
VideoPreviewActivity.a(videoCaptureActivity, 101, videoCaptureActivity.o.b());
try {
VideoCaptureActivity.this.e.j();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
@Override // com.bottle.hp.album.capture.view.VideoCaptureView.IVideoCaptureUIListener
public void x0() {
Intent intent = new Intent();
if (TextUtils.isEmpty(this.g)) {
intent.putExtra("data", this.o.b());
intent.putExtra("data_type", 1);
} else {
intent.putExtra("data", this.g);
intent.putExtra("data_type", 0);
}
setResult(-1, intent);
finish();
}
@Override // com.bottle.hp.album.capture.view.VideoCaptureView.IVideoCaptureUIListener
public void y0() {
if (this.j) {
return;
}
setResult(0);
finish();
}
public static CaptureConfiguration c(int i, int i2) {
PredefinedCaptureConfigurations$CaptureResolution predefinedCaptureConfigurations$CaptureResolution = PredefinedCaptureConfigurations$CaptureResolution.RES_720P;
PredefinedCaptureConfigurations$CaptureQuality predefinedCaptureConfigurations$CaptureQuality = PredefinedCaptureConfigurations$CaptureQuality.LOW;
if (i2 != 1) {
if (i2 == 2) {
predefinedCaptureConfigurations$CaptureQuality = PredefinedCaptureConfigurations$CaptureQuality.MEDIUM;
} else if (i2 == 3) {
predefinedCaptureConfigurations$CaptureQuality = PredefinedCaptureConfigurations$CaptureQuality.HIGH;
}
}
return new CaptureConfiguration(predefinedCaptureConfigurations$CaptureResolution, predefinedCaptureConfigurations$CaptureQuality, i, -1);
}
@Override // com.bottle.hp.album.capture.preview.CapturePreviewInterface
public void i() {
finish();
}
private boolean b(Bundle bundle) {
if (bundle == null) {
return false;
}
return bundle.getBoolean("com.bottle.savedrecordedboolean", false);
}
public static void a(Activity activity, int i, int i2) {
Intent intent = new Intent(activity, (Class<?>) VideoCaptureActivity.class);
intent.putExtra("com.bottle.extracaptureconfiguration", c(y / 1000, 1));
intent.putExtra("com.bottle.extraoutputfilename", "");
intent.putExtra("recordType", i2);
activity.startActivityForResult(intent, i);
}
private void c(Bundle bundle) {
this.p = E0();
this.n = b(bundle);
this.o = a(bundle);
}
/* JADX INFO: Access modifiers changed from: private */
public void l(int i) {
int i2;
CameraWrapper cameraWrapper = this.e;
if (cameraWrapper == null || cameraWrapper.c() == null) {
return;
}
try {
Camera.Parameters parameters = this.e.c().getParameters();
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(this.r, cameraInfo);
int i3 = ((i + 45) / 90) * 90;
if (cameraInfo.facing == 1) {
i2 = ((cameraInfo.orientation - i3) + 360) % 360;
} else {
i2 = (cameraInfo.orientation + i3) % 360;
}
parameters.setRotation(i2);
this.e.c().setParameters(parameters);
} catch (RuntimeException e) {
e.printStackTrace();
Log.e(this.c, e.getMessage());
}
}
/* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:45:0x002e -> B:9:0x0079). Please report as a decompilation issue!!! */
private void a(byte[] bArr) {
FileOutputStream fileOutputStream = null;
try {
} catch (Exception e) {
e.printStackTrace();
}
try {
try {
File H0 = H0();
FileOutputStream fileOutputStream2 = new FileOutputStream(H0);
try {
fileOutputStream2.write(bArr);
a(H0);
fileOutputStream2.close();
} catch (FileNotFoundException e2) {
e = e2;
fileOutputStream = fileOutputStream2;
e.printStackTrace();
Log.e(this.c, "File not found: " + e.getMessage());
if (fileOutputStream != null) {
fileOutputStream.close();
}
} catch (IOException e3) {
e = e3;
fileOutputStream = fileOutputStream2;
e.printStackTrace();
Log.e(this.c, "Error accessing file: " + e.getMessage());
if (fileOutputStream != null) {
fileOutputStream.close();
}
} catch (Exception e4) {
e = e4;
fileOutputStream = fileOutputStream2;
e.printStackTrace();
if (fileOutputStream != null) {
fileOutputStream.close();
}
} catch (Throwable th) {
th = th;
fileOutputStream = fileOutputStream2;
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (Exception e5) {
e5.printStackTrace();
}
}
throw th;
}
} catch (FileNotFoundException e6) {
e = e6;
} catch (IOException e7) {
e = e7;
} catch (Exception e8) {
e = e8;
}
} catch (Throwable th2) {
th = th2;
}
}
private void a(File file) {
try {
sendBroadcast(new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE", Uri.fromFile(file)));
this.e.j();
this.d.a(file.getAbsolutePath(), 0);
} catch (Exception e) {
e.printStackTrace();
Log.e(this.c, e.getMessage());
}
}
protected VideoFile a(Bundle bundle) {
if (bundle != null) {
return new VideoFile(bundle.getString("com.bottle.savedoutputfilename"));
}
return new VideoFile(getIntent().getStringExtra("com.bottle.extraoutputfilename"));
}
}

View File

@@ -0,0 +1,56 @@
package com.bottle.hp.album.capture;
import android.os.Environment;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/* loaded from: classes.dex */
public class VideoFile {
private final String a;
private Date b;
public VideoFile(String str) {
this.a = str;
}
private String c() {
if (e()) {
return this.a;
}
return "video_" + new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(d()) + ".mp4";
}
private Date d() {
if (this.b == null) {
this.b = new Date();
}
return this.b;
}
private boolean e() {
if (this.a == null) {
return false;
}
return !r0.isEmpty();
}
public File a() {
String c = c();
if (c.contains("/")) {
return new File(c);
}
File externalStoragePublicDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);
externalStoragePublicDirectory.mkdirs();
return new File(externalStoragePublicDirectory, c());
}
public String b() {
return a().getAbsolutePath();
}
public static String a(String str) {
return str + File.separator + "video_" + new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date()) + ".mp4";
}
}

View File

@@ -0,0 +1,385 @@
package com.bottle.hp.album.capture;
import android.app.Fragment;
import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.VideoView;
import com.bottle.hp.album.R$id;
import com.bottle.hp.album.R$layout;
import com.bottle.hp.album.Utils;
import com.ubt.jimu.base.mvp.SingleClickListener;
import com.ubtrobot.log.ALog;
import java.lang.ref.WeakReference;
import java.util.Timer;
import java.util.TimerTask;
/* loaded from: classes.dex */
public class VideoPlayFragment extends Fragment implements MediaPlayer.OnCompletionListener, View.OnClickListener, View.OnTouchListener, MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener, MediaPlayer.OnInfoListener {
private static StaticHandler s;
private Uri b;
private VideoView h;
private ImageView i;
private ProgressBar j;
private TextView k;
private TextView l;
private RelativeLayout m;
private int o;
private IPlayListener p;
private Timer q;
private MediaPlayer.OnPreparedListener r;
private final String a = VideoPlayFragment.class.getSimpleName();
private boolean c = false;
private boolean d = true;
private boolean e = false;
private boolean f = false;
private ImageView.ScaleType g = ImageView.ScaleType.FIT_CENTER;
private long n = 0;
public interface IPlayListener {
void b(String str);
void m0();
void onFinished();
boolean onInfo(MediaPlayer mediaPlayer, int i, int i2);
void onProgress(int i, int i2, int i3);
void v0();
}
private class ProgressTimerTask extends TimerTask {
private ProgressTimerTask() {
}
@Override // java.util.TimerTask, java.lang.Runnable
public void run() {
if (VideoPlayFragment.this.f) {
return;
}
int currentPosition = VideoPlayFragment.this.h.getCurrentPosition();
int duration = VideoPlayFragment.this.h.getDuration();
if (duration <= 0) {
return;
}
int i = (currentPosition * 100) / duration;
VideoPlayFragment.this.o = currentPosition;
VideoPlayFragment.s.sendMessage(VideoPlayFragment.s.obtainMessage(101, i, VideoPlayFragment.this.o, null));
if (VideoPlayFragment.this.p != null) {
VideoPlayFragment.this.p.onProgress(currentPosition, duration, i);
}
}
}
public static class StaticHandler extends Handler {
private final WeakReference<VideoPlayFragment> a;
public StaticHandler(VideoPlayFragment videoPlayFragment) {
this.a = new WeakReference<>(videoPlayFragment);
}
public WeakReference<VideoPlayFragment> a() {
return this.a;
}
}
/* JADX WARN: Multi-variable type inference failed */
@Override // android.app.Fragment
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof IPlayListener) {
this.p = (IPlayListener) context;
}
}
@Override // android.view.View.OnClickListener
public void onClick(View view) {
int id = view.getId();
if (id == R$id.imgPlay) {
b();
} else if (id == R$id.video_view) {
a();
}
}
@Override // android.media.MediaPlayer.OnCompletionListener
public void onCompletion(MediaPlayer mediaPlayer) {
this.f = true;
this.o = 0;
if (this.d) {
this.i.setVisibility(0);
}
Timer timer = this.q;
if (timer != null) {
timer.cancel();
this.q = null;
}
StaticHandler staticHandler = s;
staticHandler.sendMessage(staticHandler.obtainMessage(101, 100, this.h.getDuration(), null));
IPlayListener iPlayListener = this.p;
if (iPlayListener != null) {
iPlayListener.onFinished();
this.p.onProgress(this.h.getCurrentPosition(), this.h.getDuration(), 100);
}
}
@Override // android.app.Fragment
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
s = new StaticHandler(this, this) { // from class: com.bottle.hp.album.capture.VideoPlayFragment.1
@Override // android.os.Handler
public void handleMessage(Message message) {
if (message.what != 101 || a() == null || a().get() == null) {
return;
}
a().get().a(message.arg1);
}
};
new Thread();
if (getArguments() != null) {
this.b = (Uri) getArguments().getParcelable("url");
this.c = getArguments().getBoolean("auto");
this.d = getArguments().getBoolean("show_ui", true);
}
}
@Override // android.app.Fragment
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
View inflate = layoutInflater.inflate(R$layout.video_play_fragment, (ViewGroup) null, false);
this.k = (TextView) inflate.findViewById(R$id.tvCurrent);
this.l = (TextView) inflate.findViewById(R$id.tvDuration);
this.m = (RelativeLayout) inflate.findViewById(R$id.rlProgress);
this.h = (VideoView) inflate.findViewById(R$id.video_view);
this.h.setOnCompletionListener(this);
this.h.setOnTouchListener(this);
this.h.setOnPreparedListener(this);
this.h.setOnErrorListener(this);
if (Build.VERSION.SDK_INT >= 17) {
this.h.setOnInfoListener(this);
}
this.i = (ImageView) inflate.findViewById(R$id.imgPlay);
this.i.setOnClickListener(this);
this.j = (ProgressBar) inflate.findViewById(R$id.progressBar);
if (!this.d) {
this.m.setVisibility(4);
this.i.setVisibility(8);
}
try {
if (this.b != null) {
this.h.setVideoURI(this.b);
}
} catch (Exception e) {
e.printStackTrace();
a(e.getMessage());
}
if (this.c) {
b();
}
return inflate;
}
@Override // android.app.Fragment
public void onDestroy() {
super.onDestroy();
s.removeCallbacksAndMessages(null);
}
@Override // android.app.Fragment
public void onDetach() {
super.onDetach();
Timer timer = this.q;
if (timer != null) {
timer.cancel();
}
}
@Override // android.media.MediaPlayer.OnErrorListener
public boolean onError(MediaPlayer mediaPlayer, int i, int i2) {
a("msg:" + i2);
return true;
}
@Override // android.media.MediaPlayer.OnInfoListener
public boolean onInfo(MediaPlayer mediaPlayer, int i, int i2) {
ALog.a(this.a).d("what:" + i + " extra " + i2);
IPlayListener iPlayListener = this.p;
if (iPlayListener == null) {
return false;
}
iPlayListener.onInfo(mediaPlayer, i, i2);
return false;
}
@Override // android.app.Fragment
public void onPause() {
super.onPause();
this.e = true;
}
@Override // android.media.MediaPlayer.OnPreparedListener
public void onPrepared(MediaPlayer mediaPlayer) {
int b = Utils.b(getActivity());
int a = Utils.a(getActivity());
int videoWidth = mediaPlayer.getVideoWidth();
int videoHeight = mediaPlayer.getVideoHeight();
if (ImageView.ScaleType.FIT_CENTER == this.g) {
if (b > a) {
b = (videoWidth * a) / videoHeight;
} else {
a = (videoHeight * b) / videoWidth;
}
} else if (b <= a) {
a = (videoHeight * b) / videoWidth;
} else if (videoWidth > videoHeight) {
a = (videoHeight * b) / videoWidth;
} else {
b = (videoWidth * a) / videoHeight;
}
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(b, a);
layoutParams.gravity = 17;
this.h.setLayoutParams(layoutParams);
MediaPlayer.OnPreparedListener onPreparedListener = this.r;
if (onPreparedListener != null) {
onPreparedListener.onPrepared(mediaPlayer);
}
}
@Override // android.view.View.OnTouchListener
public boolean onTouch(View view, MotionEvent motionEvent) {
int action = motionEvent.getAction();
if (action == 0) {
this.n = System.currentTimeMillis();
ALog.a(this.a).d("action down");
return true;
}
if (action == 1) {
e();
return true;
}
if (action != 2) {
return false;
}
ALog.a(this.a).d("action move");
return false;
}
private void e() {
if (System.currentTimeMillis() - this.n > 500) {
return;
}
if (this.h.isPlaying()) {
a();
} else {
b();
}
ALog.a(this.a).d("action up");
}
public void c() {
a(this.o, true);
}
public static VideoPlayFragment a(Uri uri, boolean z, boolean z2) {
VideoPlayFragment videoPlayFragment = new VideoPlayFragment();
Bundle bundle = new Bundle();
bundle.putParcelable("url", uri);
bundle.putBoolean("auto", z);
bundle.putBoolean("show_ui", z2);
videoPlayFragment.setArguments(bundle);
return videoPlayFragment;
}
public void b() {
if (this.e) {
a(this.o, true);
} else {
a(this.o, false);
}
this.e = false;
}
/* JADX INFO: Access modifiers changed from: private */
public void a(int i) {
this.j.setProgress(i);
this.k.setText(Utils.a(this.h.getCurrentPosition()));
this.l.setText(Utils.a(this.h.getDuration() + SingleClickListener.FAST_CLICK_DELAY_TIME));
if (i == 100) {
this.k.setText(Utils.a(this.h.getDuration() + SingleClickListener.FAST_CLICK_DELAY_TIME));
}
}
private void a(int i, boolean z) {
if (z && !this.f) {
this.h.seekTo(i);
}
this.f = false;
this.h.start();
this.q = new Timer();
this.q.schedule(new ProgressTimerTask(), 10L, 300L);
this.i.setVisibility(8);
IPlayListener iPlayListener = this.p;
if (iPlayListener != null) {
iPlayListener.v0();
}
}
private void a(String str) {
this.i.post(new Runnable() { // from class: com.bottle.hp.album.capture.VideoPlayFragment.2
@Override // java.lang.Runnable
public void run() {
VideoPlayFragment.this.i.setVisibility(4);
}
});
IPlayListener iPlayListener = this.p;
if (iPlayListener != null) {
iPlayListener.b(str);
}
}
public void a(Uri uri) {
if (uri == null) {
a("播放地址为null");
return;
}
Uri uri2 = this.b;
if (uri2 == null || !uri2.equals(uri)) {
this.b = uri;
this.h.setVideoURI(uri);
this.o = 0;
this.l.setText(Utils.a(this.h.getDuration() + SingleClickListener.FAST_CLICK_DELAY_TIME));
this.k.setText(Utils.a(0L));
}
}
public void a() {
this.o = this.h.getCurrentPosition();
if (this.d) {
this.i.setVisibility(0);
}
this.h.pause();
Timer timer = this.q;
if (timer != null) {
timer.cancel();
this.q = null;
}
IPlayListener iPlayListener = this.p;
if (iPlayListener != null) {
iPlayListener.m0();
}
}
}

View File

@@ -0,0 +1,141 @@
package com.bottle.hp.album.capture;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.bottle.hp.album.BaseActivity;
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.VideoPlayFragment;
import com.ubtrobot.log.ALog;
import java.io.File;
/* loaded from: classes.dex */
public class VideoPreviewActivity extends BaseActivity implements View.OnClickListener, VideoPlayFragment.IPlayListener {
private static final String i = VideoPreviewActivity.class.getSimpleName();
private VideoPlayFragment c;
private FrameLayout d;
private ImageView e;
private ImageView f;
private String g;
private boolean h = true;
private void c(int i2, String str) {
Intent intent = new Intent();
intent.putExtra("url", str);
setResult(i2, intent);
this.c.a();
finish();
}
@Override // com.bottle.hp.album.capture.VideoPlayFragment.IPlayListener
public void b(String str) {
long j;
Log.e(i, str);
File file = new File(this.g);
try {
j = Utils.a(file);
} catch (Exception e) {
e.printStackTrace();
Log.e(i, e.getMessage());
j = 0;
}
if (!file.exists() || j == 0) {
this.f.setEnabled(false);
}
}
@Override // com.bottle.hp.album.capture.VideoPlayFragment.IPlayListener
public void m0() {
}
@Override // android.view.View.OnClickListener
public void onClick(View view) {
if (R$id.imgCancel == view.getId()) {
c(0, this.g);
} else if (R$id.imgAccept == view.getId()) {
c(-1, this.g);
} else {
ALog.a(i).d("click");
}
}
@Override // com.bottle.hp.album.BaseActivity, 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_video_preview);
this.d = (FrameLayout) findViewById(R$id.flVideoViewContainer);
this.e = (ImageView) findViewById(R$id.imgCancel);
this.f = (ImageView) findViewById(R$id.imgAccept);
this.e.setOnClickListener(this);
this.f.setOnClickListener(this);
this.g = getIntent().getStringExtra("url");
this.c = VideoPlayFragment.a(Uri.parse(this.g), true, true);
getFragmentManager().beginTransaction().replace(R$id.flVideoViewContainer, this.c).commit();
}
@Override // com.bottle.hp.album.capture.VideoPlayFragment.IPlayListener
public void onFinished() {
}
@Override // com.bottle.hp.album.capture.VideoPlayFragment.IPlayListener
public boolean onInfo(MediaPlayer mediaPlayer, int i2, int i3) {
return false;
}
@Override // androidx.appcompat.app.AppCompatActivity, android.app.Activity, android.view.KeyEvent.Callback
public boolean onKeyDown(int i2, KeyEvent keyEvent) {
if (i2 != 4) {
return super.onKeyDown(i2, keyEvent);
}
c(0, this.g);
return true;
}
@Override // androidx.fragment.app.FragmentActivity, android.app.Activity
public void onPause() {
super.onPause();
VideoPlayFragment videoPlayFragment = this.c;
if (videoPlayFragment != null) {
videoPlayFragment.a();
}
}
@Override // com.bottle.hp.album.capture.VideoPlayFragment.IPlayListener
public void onProgress(int i2, int i3, int i4) {
Log.e(i, "progress:" + i4);
}
@Override // androidx.fragment.app.FragmentActivity, android.app.Activity
public void onResume() {
super.onResume();
if (this.h) {
this.h = false;
} else {
this.d.post(new Runnable() { // from class: com.bottle.hp.album.capture.VideoPreviewActivity.1
@Override // java.lang.Runnable
public void run() {
VideoPreviewActivity.this.c.c();
}
});
}
}
@Override // com.bottle.hp.album.capture.VideoPlayFragment.IPlayListener
public void v0() {
}
public static void a(Activity activity, int i2, String str) {
Intent intent = new Intent(activity, (Class<?>) VideoPreviewActivity.class);
intent.putExtra("url", str);
activity.startActivityForResult(intent, i2);
}
}

View File

@@ -0,0 +1,20 @@
package com.bottle.hp.album.capture.camera;
/* loaded from: classes.dex */
public class CameraSize {
private final int a;
private final int b;
public CameraSize(int i, int i2) {
this.a = i;
this.b = i2;
}
public int a() {
return this.b;
}
public int b() {
return this.a;
}
}

View File

@@ -0,0 +1,216 @@
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);
}
}

View File

@@ -0,0 +1,77 @@
package com.bottle.hp.album.capture.camera;
import android.hardware.Camera;
import android.view.SurfaceHolder;
import java.io.IOException;
/* loaded from: classes.dex */
public class NativeCamera {
private Camera a = null;
private Camera.Parameters b = null;
private int i() {
int numberOfCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numberOfCameras; i++) {
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(i, cameraInfo);
if (cameraInfo.facing == 0) {
return i;
}
}
return -1;
}
public void a(int i) throws RuntimeException {
this.a = Camera.open(i);
}
public void b(int i) {
this.a.setDisplayOrientation(i);
}
public Camera c() {
return this.a;
}
public Camera.Parameters d() {
if (this.b == null) {
this.b = this.a.getParameters();
}
return this.b;
}
public void e() {
this.a.release();
}
public void f() {
this.a.startPreview();
}
public void g() {
this.a.stopPreview();
}
public void h() {
this.a.unlock();
}
public void a(SurfaceHolder surfaceHolder) throws IOException {
this.a.setPreviewDisplay(surfaceHolder);
}
public int b() {
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(i(), cameraInfo);
return cameraInfo.orientation;
}
public void a() {
this.a.setPreviewCallback(null);
}
public void a(Camera.Parameters parameters) {
this.b = parameters;
this.a.setParameters(parameters);
}
}

View File

@@ -0,0 +1,38 @@
package com.bottle.hp.album.capture.camera;
import android.util.Log;
/* loaded from: classes.dex */
public class OpenCameraException extends Exception {
private static final String LOG_PREFIX = "Unable to open camera - ";
private static final long serialVersionUID = -7340415176385044242L;
private final String TAG;
private final OpenType mType;
public enum OpenType {
INUSE("Camera disabled or in use by other process"),
NOCAMERA("Device does not have camera");
private String mMessage;
OpenType(String str) {
this.mMessage = str;
}
public String getMessage() {
return this.mMessage;
}
}
public OpenCameraException(OpenType openType) {
super(openType.getMessage());
this.TAG = OpenCameraException.class.getSimpleName();
this.mType = openType;
}
@Override // java.lang.Throwable
public void printStackTrace() {
Log.e(this.TAG, LOG_PREFIX + this.mType.getMessage());
super.printStackTrace();
}
}

View File

@@ -0,0 +1,17 @@
package com.bottle.hp.album.capture.camera;
import android.util.Log;
/* loaded from: classes.dex */
public class PrepareCameraException extends Exception {
private static final String LOG_PREFIX = "Unable to unlock camera - ";
private static final String MESSAGE = "Unable to use camera for recording";
private static final long serialVersionUID = 6305923762266448674L;
private final String TAG = PrepareCameraException.class.getSimpleName();
@Override // java.lang.Throwable
public String getMessage() {
Log.e(this.TAG, "Unable to unlock camera - Unable to use camera for recording");
return MESSAGE;
}
}

View File

@@ -0,0 +1,12 @@
package com.bottle.hp.album.capture.camera;
/* loaded from: classes.dex */
public class RecordingSize {
public int a;
public int b;
public RecordingSize(int i, int i2) {
this.a = i;
this.b = i2;
}
}

View File

@@ -0,0 +1,174 @@
package com.bottle.hp.album.capture.configuration;
import android.os.Parcel;
import android.os.Parcelable;
/* loaded from: classes.dex */
public class CaptureConfiguration implements Parcelable {
public static final Parcelable.Creator<CaptureConfiguration> CREATOR = new Parcelable.Creator<CaptureConfiguration>() { // from class: com.bottle.hp.album.capture.configuration.CaptureConfiguration.1
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public CaptureConfiguration createFromParcel(Parcel parcel) {
return new CaptureConfiguration(parcel);
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public CaptureConfiguration[] newArray(int i) {
return new CaptureConfiguration[i];
}
};
private static final int MBYTE_TO_BYTE = 1048576;
private static final int MSEC_TO_SEC = 1000;
public static final int NO_DURATION_LIMIT = -1;
public static final int NO_FILESIZE_LIMIT = -1;
private int AUDIO_ENCODER;
private int AUDIO_SOURCE;
private int OUTPUT_FORMAT;
private int VIDEO_ENCODER;
private int VIDEO_SOURCE;
private int mBitrate;
private int mMaxDurationMs;
private int mMaxFilesizeBytes;
private int mVideoHeight;
private int mVideoWidth;
@Override // android.os.Parcelable
public int describeContents() {
return 0;
}
public int getAudioEncoder() {
return this.AUDIO_ENCODER;
}
public int getAudioSource() {
return this.AUDIO_SOURCE;
}
public int getMaxCaptureDuration() {
return this.mMaxDurationMs;
}
public int getMaxCaptureFileSize() {
return this.mMaxFilesizeBytes;
}
public int getOutputFormat() {
return this.OUTPUT_FORMAT;
}
public int getVideoBitrate() {
return this.mBitrate;
}
public int getVideoEncoder() {
return this.VIDEO_ENCODER;
}
public int getVideoHeight() {
return this.mVideoHeight;
}
public int getVideoSource() {
return this.VIDEO_SOURCE;
}
public int getVideoWidth() {
return this.mVideoWidth;
}
@Override // android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
parcel.writeInt(this.mVideoWidth);
parcel.writeInt(this.mVideoHeight);
parcel.writeInt(this.mBitrate);
parcel.writeInt(this.mMaxDurationMs);
parcel.writeInt(this.mMaxFilesizeBytes);
parcel.writeInt(this.OUTPUT_FORMAT);
parcel.writeInt(this.AUDIO_SOURCE);
parcel.writeInt(this.AUDIO_ENCODER);
parcel.writeInt(this.VIDEO_SOURCE);
parcel.writeInt(this.VIDEO_ENCODER);
}
public CaptureConfiguration() {
this.mVideoWidth = 1280;
this.mVideoHeight = 720;
this.mBitrate = 5000000;
this.mMaxDurationMs = -1;
this.mMaxFilesizeBytes = -1;
this.OUTPUT_FORMAT = 2;
this.AUDIO_SOURCE = 0;
this.AUDIO_ENCODER = 3;
this.VIDEO_SOURCE = 1;
this.VIDEO_ENCODER = 2;
}
public CaptureConfiguration(PredefinedCaptureConfigurations$CaptureResolution predefinedCaptureConfigurations$CaptureResolution, PredefinedCaptureConfigurations$CaptureQuality predefinedCaptureConfigurations$CaptureQuality) {
this.mVideoWidth = 1280;
this.mVideoHeight = 720;
this.mBitrate = 5000000;
this.mMaxDurationMs = -1;
this.mMaxFilesizeBytes = -1;
this.OUTPUT_FORMAT = 2;
this.AUDIO_SOURCE = 0;
this.AUDIO_ENCODER = 3;
this.VIDEO_SOURCE = 1;
this.VIDEO_ENCODER = 2;
this.mVideoWidth = predefinedCaptureConfigurations$CaptureResolution.width;
this.mVideoHeight = predefinedCaptureConfigurations$CaptureResolution.height;
this.mBitrate = predefinedCaptureConfigurations$CaptureResolution.getBitrate(predefinedCaptureConfigurations$CaptureQuality);
}
public CaptureConfiguration(PredefinedCaptureConfigurations$CaptureResolution predefinedCaptureConfigurations$CaptureResolution, PredefinedCaptureConfigurations$CaptureQuality predefinedCaptureConfigurations$CaptureQuality, int i, int i2) {
this(predefinedCaptureConfigurations$CaptureResolution, predefinedCaptureConfigurations$CaptureQuality);
this.mMaxDurationMs = i * MSEC_TO_SEC;
this.mMaxFilesizeBytes = i2 * MBYTE_TO_BYTE;
}
public CaptureConfiguration(int i, int i2, int i3) {
this.mVideoWidth = 1280;
this.mVideoHeight = 720;
this.mBitrate = 5000000;
this.mMaxDurationMs = -1;
this.mMaxFilesizeBytes = -1;
this.OUTPUT_FORMAT = 2;
this.AUDIO_SOURCE = 0;
this.AUDIO_ENCODER = 3;
this.VIDEO_SOURCE = 1;
this.VIDEO_ENCODER = 2;
this.mVideoWidth = i;
this.mVideoHeight = i2;
this.mBitrate = i3;
}
public CaptureConfiguration(int i, int i2, int i3, int i4, int i5) {
this(i, i2, i3);
this.mMaxDurationMs = i4 * MSEC_TO_SEC;
this.mMaxFilesizeBytes = i5 * MBYTE_TO_BYTE;
}
private CaptureConfiguration(Parcel parcel) {
this.mVideoWidth = 1280;
this.mVideoHeight = 720;
this.mBitrate = 5000000;
this.mMaxDurationMs = -1;
this.mMaxFilesizeBytes = -1;
this.OUTPUT_FORMAT = 2;
this.AUDIO_SOURCE = 0;
this.AUDIO_ENCODER = 3;
this.VIDEO_SOURCE = 1;
this.VIDEO_ENCODER = 2;
this.mVideoWidth = parcel.readInt();
this.mVideoHeight = parcel.readInt();
this.mBitrate = parcel.readInt();
this.mMaxDurationMs = parcel.readInt();
this.mMaxFilesizeBytes = parcel.readInt();
this.OUTPUT_FORMAT = parcel.readInt();
this.AUDIO_SOURCE = parcel.readInt();
this.AUDIO_ENCODER = parcel.readInt();
this.VIDEO_SOURCE = parcel.readInt();
this.VIDEO_ENCODER = parcel.readInt();
}
}

View File

@@ -0,0 +1,21 @@
package com.bottle.hp.album.capture.configuration;
/* loaded from: classes.dex */
/* synthetic */ class PredefinedCaptureConfigurations$1 {
static final /* synthetic */ int[] a = new int[PredefinedCaptureConfigurations$CaptureQuality.values().length];
static {
try {
a[PredefinedCaptureConfigurations$CaptureQuality.HIGH.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
a[PredefinedCaptureConfigurations$CaptureQuality.MEDIUM.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
a[PredefinedCaptureConfigurations$CaptureQuality.LOW.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
}
}

View File

@@ -0,0 +1,8 @@
package com.bottle.hp.album.capture.configuration;
/* loaded from: classes.dex */
public enum PredefinedCaptureConfigurations$CaptureQuality {
LOW,
MEDIUM,
HIGH
}

View File

@@ -0,0 +1,31 @@
package com.bottle.hp.album.capture.configuration;
/* loaded from: classes.dex */
public enum PredefinedCaptureConfigurations$CaptureResolution {
RES_360P(640, 360, 1000000, 700000, 300000),
RES_480P(640, 480, 2500000, 1750000, 750000),
RES_720P(1280, 720, 5000000, 3500000, 1500000),
RES_1080P(1920, 1080, 8000000, 5600000, 2400000),
RES_1440P(2560, 1440, 10000000, 7000000, 3000000),
RES_2160P(3840, 2160, 40000000, 28000000, 12000000);
public int height;
private final int highBitrate;
private final int lowBitrate;
private final int medBitrate;
public int width;
PredefinedCaptureConfigurations$CaptureResolution(int i, int i2, int i3, int i4, int i5) {
this.width = i;
this.height = i2;
this.highBitrate = i3;
this.medBitrate = i4;
this.lowBitrate = i5;
}
public int getBitrate(PredefinedCaptureConfigurations$CaptureQuality predefinedCaptureConfigurations$CaptureQuality) {
int i = this.highBitrate;
int i2 = PredefinedCaptureConfigurations$1.a[predefinedCaptureConfigurations$CaptureQuality.ordinal()];
return i2 != 1 ? i2 != 2 ? i2 != 3 ? i : this.lowBitrate : this.medBitrate : this.highBitrate;
}
}

View File

@@ -0,0 +1,91 @@
package com.bottle.hp.album.capture.preview;
import android.util.Log;
import android.view.SurfaceHolder;
import com.bottle.hp.album.capture.camera.CameraWrapper;
import com.ubtrobot.log.ALog;
import java.io.IOException;
/* loaded from: classes.dex */
public class CapturePreview implements SurfaceHolder.Callback {
private final String a = CapturePreview.class.getSimpleName();
private boolean b = true;
private final CapturePreviewInterface c;
public final CameraWrapper d;
public CapturePreview(CapturePreviewInterface capturePreviewInterface, CameraWrapper cameraWrapper, SurfaceHolder surfaceHolder) {
this.c = capturePreviewInterface;
this.d = cameraWrapper;
a(surfaceHolder);
}
private void a(SurfaceHolder surfaceHolder) {
surfaceHolder.addCallback(this);
surfaceHolder.setType(3);
a(surfaceHolder, 0, 0);
}
@Override // android.view.SurfaceHolder.Callback
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
a(surfaceHolder, i2, i3);
}
@Override // android.view.SurfaceHolder.Callback
public void surfaceCreated(SurfaceHolder surfaceHolder) {
}
@Override // android.view.SurfaceHolder.Callback
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
}
private void a(SurfaceHolder surfaceHolder, int i, int i2) {
if (this.b) {
try {
this.d.j();
} catch (Exception e) {
e.printStackTrace();
}
}
try {
this.d.a(i, i2);
try {
this.d.a();
} catch (RuntimeException e2) {
e2.printStackTrace();
ALog.a(this.a).d("AutoFocus not available for preview");
}
try {
this.d.a(surfaceHolder);
a(true);
} catch (IOException e3) {
e3.printStackTrace();
ALog.a(this.a).d("Failed to show preview - unable to connect camera to preview (IOException)");
this.c.i();
} catch (RuntimeException e4) {
e4.printStackTrace();
ALog.a(this.a).d("Failed to show preview - unable to start camera preview (RuntimeException)");
this.c.i();
}
} catch (RuntimeException e5) {
e5.printStackTrace();
Log.e(this.a, "Failed to show preview - invalid parameters set to camera preview");
this.c.i();
}
}
public void a() {
if (this.b) {
try {
this.d.j();
a(false);
} catch (Exception e) {
e.printStackTrace();
Log.e(this.a, "Failed to clean up preview resources");
}
}
}
protected void a(boolean z) {
this.b = z;
}
}

View File

@@ -0,0 +1,6 @@
package com.bottle.hp.album.capture.preview;
/* loaded from: classes.dex */
public interface CapturePreviewInterface {
void i();
}

View File

@@ -0,0 +1,5 @@
package com.bottle.hp.album.capture.recorder;
/* loaded from: classes.dex */
public class AlreadyUsedException extends Exception {
}

View File

@@ -0,0 +1,254 @@
package com.bottle.hp.album.capture.recorder;
import android.hardware.Camera;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.util.Log;
import android.view.SurfaceHolder;
import com.bottle.hp.album.capture.VideoFile;
import com.bottle.hp.album.capture.camera.CameraWrapper;
import com.bottle.hp.album.capture.camera.OpenCameraException;
import com.bottle.hp.album.capture.camera.PrepareCameraException;
import com.bottle.hp.album.capture.camera.RecordingSize;
import com.bottle.hp.album.capture.configuration.CaptureConfiguration;
import com.bottle.hp.album.capture.preview.CapturePreview;
import com.bottle.hp.album.capture.preview.CapturePreviewInterface;
import com.ubtrobot.log.ALog;
import java.io.IOException;
import java.util.Locale;
/* loaded from: classes.dex */
public class VideoRecorder implements MediaRecorder.OnInfoListener, CapturePreviewInterface {
private CameraWrapper b;
private CapturePreview c;
private final CaptureConfiguration d;
private final VideoFile e;
private MediaRecorder f;
private final VideoRecorderInterface h;
private final String a = VideoRecorder.class.getSimpleName();
private boolean g = false;
public VideoRecorder(VideoRecorderInterface videoRecorderInterface, CaptureConfiguration captureConfiguration, VideoFile videoFile, CameraWrapper cameraWrapper, SurfaceHolder surfaceHolder) {
this.d = captureConfiguration;
this.h = videoRecorderInterface;
this.e = videoFile;
this.b = cameraWrapper;
surfaceHolder.getSurface();
a(surfaceHolder);
}
private boolean g() {
if (this.b.b() == null) {
throw new UnsupportedOperationException("No quality level found");
}
try {
this.b.h();
a(new MediaRecorder());
try {
a(a(), this.b.c());
ALog.a(this.a).d("MediaRecorder successfully initialized");
return true;
} catch (IllegalArgumentException | IllegalStateException e) {
e.printStackTrace();
return false;
}
} catch (PrepareCameraException e2) {
e2.printStackTrace();
this.h.m("Unable to record video");
Log.e(this.a, "Failed to initialize recorder - " + e2.toString());
return false;
}
}
private boolean h() {
try {
a().prepare();
ALog.a(this.a).d("MediaRecorder successfully prepared");
return true;
} catch (IOException e) {
e.printStackTrace();
ALog.a(this.a).d("MediaRecorder preparation failed - " + e.toString());
return false;
} catch (IllegalStateException e2) {
e2.printStackTrace();
ALog.a(this.a).d("MediaRecorder preparation failed - " + e2.toString());
return false;
}
}
private void j() {
MediaRecorder a = a();
if (a != null) {
a.release();
a((MediaRecorder) null);
}
}
private boolean k() {
try {
a().start();
ALog.a(this.a).d("MediaRecorder successfully started");
return true;
} catch (IllegalStateException e) {
e.printStackTrace();
ALog.a(this.a).d("MediaRecorder start failed - " + e.toString());
return false;
} catch (RuntimeException e2) {
e2.printStackTrace();
ALog.a(this.a).d("MediaRecorder start failed - " + e2.toString());
this.h.m("Unable to record video with given settings");
return false;
}
}
protected void a(SurfaceHolder surfaceHolder) {
try {
this.b.g();
this.c = new CapturePreview(this, this.b, surfaceHolder);
} catch (OpenCameraException e) {
e.printStackTrace();
this.h.m(e.getMessage());
}
}
public CapturePreview b() {
return this.c;
}
public boolean c() {
return this.g;
}
public void d() {
CapturePreview capturePreview = this.c;
if (capturePreview != null) {
capturePreview.a();
}
CameraWrapper cameraWrapper = this.b;
if (cameraWrapper != null) {
cameraWrapper.i();
this.b = null;
}
j();
ALog.a(this.a).d("Released all resources");
}
protected void e() {
this.g = false;
if (g() && h() && k()) {
this.g = true;
this.h.f0();
ALog.a(this.a).d("Successfully started recording - outputfile: " + this.e.b());
}
}
public void f() throws AlreadyUsedException {
if (this.b == null) {
throw new AlreadyUsedException();
}
if (c()) {
a((String) null);
return;
}
try {
e();
} catch (UnsupportedOperationException e) {
throw e;
}
}
@Override // com.bottle.hp.album.capture.preview.CapturePreviewInterface
public void i() {
this.h.m("Unable to show camera preview");
}
@Override // android.media.MediaRecorder.OnInfoListener
public void onInfo(MediaRecorder mediaRecorder, int i, int i2) {
Locale locale = Locale.getDefault();
if (i != 1) {
if (i == 800) {
ALog.a(this.a).d("MediaRecorder max duration reached");
a(locale.getLanguage().equals("zh") ? "录制时间达到最长时间限制,停止录制。" : "Capture stopped - Max duration reached");
} else {
if (i != 801) {
return;
}
ALog.a(this.a).d("MediaRecorder max filesize reached");
a(locale.equals(Locale.CHINESE) ? "录制时间达到最长时间限制,停止录制。" : "Capture stopped - Max duration reached");
}
}
}
public void a(String str) {
if (c()) {
try {
a().stop();
this.h.u0();
ALog.a(this.a).d("Successfully stopped recording - outputfile: " + this.e.b());
} catch (RuntimeException unused) {
ALog.a(this.a).d("Failed to stop recording");
}
this.g = false;
this.h.l(str);
}
}
protected void a(MediaRecorder mediaRecorder, Camera camera) throws IllegalStateException, IllegalArgumentException {
mediaRecorder.setCamera(camera);
mediaRecorder.setVideoSource(this.d.getVideoSource());
if (this.h.j0()) {
try {
mediaRecorder.setAudioSource(this.d.getAudioSource());
} catch (Throwable th) {
th.printStackTrace();
}
}
CamcorderProfile b = this.b.b();
if (b != null) {
b.fileFormat = this.d.getOutputFormat();
RecordingSize b2 = this.b.b(this.d.getVideoWidth(), this.d.getVideoHeight());
b.videoFrameWidth = b2.a;
b.videoFrameHeight = b2.b;
b.videoBitRate = this.d.getVideoBitrate();
b.audioCodec = this.d.getAudioEncoder();
b.videoCodec = this.d.getVideoEncoder();
a(mediaRecorder, b);
mediaRecorder.setMaxDuration(this.d.getMaxCaptureDuration());
mediaRecorder.setOutputFile(this.e.b());
mediaRecorder.setOrientationHint(this.b.e());
try {
mediaRecorder.setMaxFileSize(this.d.getMaxCaptureFileSize());
} catch (IllegalArgumentException unused) {
Log.e(this.a, "Failed to set max filesize - illegal argument: " + this.d.getMaxCaptureFileSize());
} catch (RuntimeException unused2) {
Log.e(this.a, "Failed to set max filesize - runtime exception");
}
mediaRecorder.setOnInfoListener(this);
return;
}
throw new UnsupportedOperationException("No quality level found");
}
private void a(MediaRecorder mediaRecorder, CamcorderProfile camcorderProfile) {
mediaRecorder.setOutputFormat(camcorderProfile.fileFormat);
mediaRecorder.setVideoFrameRate(camcorderProfile.videoFrameRate);
mediaRecorder.setVideoSize(camcorderProfile.videoFrameWidth, camcorderProfile.videoFrameHeight);
mediaRecorder.setVideoEncodingBitRate(camcorderProfile.videoBitRate);
mediaRecorder.setVideoEncoder(camcorderProfile.videoCodec);
int i = camcorderProfile.quality;
if ((i < 1000 || i > 1007) && this.h.j0()) {
mediaRecorder.setAudioEncodingBitRate(camcorderProfile.audioBitRate);
mediaRecorder.setAudioChannels(camcorderProfile.audioChannels);
mediaRecorder.setAudioSamplingRate(camcorderProfile.audioSampleRate);
mediaRecorder.setAudioEncoder(camcorderProfile.audioCodec);
}
}
protected void a(MediaRecorder mediaRecorder) {
this.f = mediaRecorder;
}
protected MediaRecorder a() {
return this.f;
}
}

View File

@@ -0,0 +1,14 @@
package com.bottle.hp.album.capture.recorder;
/* loaded from: classes.dex */
public interface VideoRecorderInterface {
void f0();
boolean j0();
void l(String str);
void m(String str);
void u0();
}

View File

@@ -0,0 +1,10 @@
package com.bottle.hp.album.capture.view;
/* loaded from: classes.dex */
public interface IPictureCaptureListener {
void a();
void b();
void onCancel();
}

View File

@@ -0,0 +1,102 @@
package com.bottle.hp.album.capture.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.bottle.hp.album.R$id;
import com.bottle.hp.album.R$layout;
import com.bumptech.glide.Glide;
/* loaded from: classes.dex */
public class PictureCaptureView extends FrameLayout implements View.OnClickListener {
private IPictureCaptureListener a;
private ImageView b;
private ImageView c;
private ImageView d;
private ImageView e;
private SurfaceView f;
public PictureCaptureView(Context context) {
super(context);
a(context);
}
public void a() {
this.b.setVisibility(0);
this.c.setVisibility(4);
this.d.setVisibility(4);
this.e.setVisibility(8);
}
public SurfaceHolder getPreviewSurfaceHolder() {
return this.f.getHolder();
}
@Override // android.view.View.OnClickListener
public void onClick(View view) {
IPictureCaptureListener iPictureCaptureListener;
int id = view.getId();
if (id == R$id.imgCapture) {
IPictureCaptureListener iPictureCaptureListener2 = this.a;
if (iPictureCaptureListener2 != null) {
iPictureCaptureListener2.b();
return;
}
return;
}
if (id == R$id.imgOK) {
IPictureCaptureListener iPictureCaptureListener3 = this.a;
if (iPictureCaptureListener3 != null) {
iPictureCaptureListener3.a();
return;
}
return;
}
if (id != R$id.imgCancel || (iPictureCaptureListener = this.a) == null) {
return;
}
iPictureCaptureListener.onCancel();
}
public void setPictureCaptureListener(IPictureCaptureListener iPictureCaptureListener) {
this.a = iPictureCaptureListener;
}
public PictureCaptureView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
a(context);
}
public PictureCaptureView(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
a(context);
}
public void a(String str) {
this.b.setVisibility(4);
this.c.setVisibility(0);
this.d.setVisibility(0);
this.e.setVisibility(0);
a(this.e, str);
}
private void a(Context context) {
View inflate = View.inflate(context, R$layout.view_picture_capture, this);
this.b = (ImageView) inflate.findViewById(R$id.imgCapture);
this.c = (ImageView) inflate.findViewById(R$id.imgOK);
this.d = (ImageView) inflate.findViewById(R$id.imgCancel);
this.e = (ImageView) inflate.findViewById(R$id.imgPreview);
this.b.setOnClickListener(this);
this.c.setOnClickListener(this);
this.d.setOnClickListener(this);
this.f = (SurfaceView) inflate.findViewById(R$id.surfaceView);
}
private void a(ImageView imageView, String str) {
Glide.e(getContext()).a(str).a(imageView);
}
}

View File

@@ -0,0 +1,214 @@
package com.bottle.hp.album.capture.view;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.bottle.hp.album.R$id;
import com.bottle.hp.album.R$layout;
import com.bottle.hp.album.R$mipmap;
import com.bottle.hp.album.R$string;
import com.bottle.hp.album.Utils;
import com.bumptech.glide.Glide;
import com.github.chrisbanes.photoview.PhotoView;
import com.ubtrobot.log.ALog;
/* loaded from: classes.dex */
public class VideoCaptureView extends FrameLayout implements View.OnClickListener, View.OnTouchListener {
private final String a;
private SurfaceView b;
private ImageView c;
private ImageView d;
private ProgressBar e;
private ImageView f;
private ImageView g;
private PhotoView h;
private ImageView i;
private TextView j;
private RelativeLayout k;
private ImageView l;
private IVideoCaptureUIListener m;
public interface IVideoCaptureUIListener {
void B0();
void h0();
void onCancel();
void r0();
void t0();
void x0();
void y0();
}
public VideoCaptureView(Context context) {
super(context);
this.a = VideoCaptureView.class.getSimpleName();
a(context);
}
private void a(Context context) {
View inflate = View.inflate(context, R$layout.view_video_capture, this);
this.b = (SurfaceView) inflate.findViewById(R$id.surfaceView);
this.c = (ImageView) inflate.findViewById(R$id.imgBack);
this.d = (ImageView) inflate.findViewById(R$id.imgChangeCamera);
this.e = (ProgressBar) inflate.findViewById(R$id.progressBar);
this.f = (ImageView) inflate.findViewById(R$id.imgCancel);
this.g = (ImageView) inflate.findViewById(R$id.imgAccept);
this.h = (PhotoView) inflate.findViewById(R$id.imgPreview);
this.i = (ImageView) inflate.findViewById(R$id.imgStartPlay);
this.j = (TextView) inflate.findViewById(R$id.tvTips);
this.k = (RelativeLayout) inflate.findViewById(R$id.rlBottom);
this.l = (ImageView) inflate.findViewById(R$id.imgCaptureBackground);
this.c.setOnClickListener(this);
this.d.setOnClickListener(this);
this.l.setOnClickListener(this);
this.c.setOnClickListener(this);
this.f.setOnClickListener(this);
this.g.setOnClickListener(this);
this.l.setOnTouchListener(this);
this.i.setOnClickListener(this);
}
private void f() {
this.i.setVisibility(8);
}
private void g() {
this.i.setVisibility(0);
}
public void b() {
this.l.setVisibility(0);
this.e.setVisibility(8);
this.l.setImageResource(R$mipmap.capture);
this.j.setVisibility(0);
this.h.setVisibility(4);
this.i.setVisibility(8);
this.c.setVisibility(0);
this.d.setVisibility(0);
this.k.setVisibility(8);
this.e.setProgress(0);
}
public void c() {
this.j.setText("");
}
public void d() {
this.j.setVisibility(8);
this.l.setImageResource(R$mipmap.capture_videotape);
this.e.setVisibility(0);
}
public void e() {
this.j.setText(getContext().getString(R$string.please_add_video));
}
public SurfaceHolder getPreviewSurfaceHolder() {
return this.b.getHolder();
}
@Override // android.view.View.OnClickListener
public void onClick(View view) {
int id = view.getId();
if (id == R$id.imgBack) {
this.m.y0();
return;
}
if (id == R$id.imgChangeCamera) {
this.m.B0();
return;
}
if (id == R$id.imgCancel) {
this.m.onCancel();
} else if (id == R$id.imgAccept) {
this.m.x0();
} else if (id == R$id.imgStartPlay) {
this.m.t0();
}
}
@Override // android.view.View.OnTouchListener
public boolean onTouch(View view, MotionEvent motionEvent) {
ImageView imageView = this.l;
if (imageView == null || !imageView.equals(view) || motionEvent == null || this.m == null) {
return false;
}
int action = motionEvent.getAction();
if (action == 0) {
ALog.a(this.a).d("action down");
this.m.h0();
return true;
}
if (action != 1) {
if (action == 2) {
ALog.a(this.a).d("action move");
}
return false;
}
ALog.a(this.a).d("action up");
this.m.r0();
return true;
}
public void setUIListener(IVideoCaptureUIListener iVideoCaptureUIListener) {
this.m = iVideoCaptureUIListener;
}
public VideoCaptureView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
this.a = VideoCaptureView.class.getSimpleName();
a(context);
}
public VideoCaptureView(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
this.a = VideoCaptureView.class.getSimpleName();
a(context);
}
private void a(ImageView imageView, String str) {
Glide.e(getContext()).a(str).a(imageView);
}
public void a(String str, int i) {
this.j.setVisibility(8);
this.c.setVisibility(8);
this.d.setVisibility(8);
this.l.setVisibility(8);
this.e.setVisibility(8);
this.e.setProgress(0);
this.k.setVisibility(0);
this.h.setVisibility(0);
if (1 == i) {
Bitmap a = Utils.a(str);
this.h.setScaleType(ImageView.ScaleType.CENTER_CROP);
this.h.setImageBitmap(a);
g();
return;
}
a(this.h, str);
f();
}
public void a(int i) {
this.e.setProgress(i);
}
public void a() {
this.j.setText(getContext().getString(R$string.tips_photo_or_video));
}
}