camera2 implementation (WIP)
This commit is contained in:
parent
6b55d749e4
commit
9b4cfe97b6
3 changed files with 77 additions and 2 deletions
|
@ -165,7 +165,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
mMediaRecorder = new MediaRecorder();
|
mMediaRecorder = new MediaRecorder();
|
||||||
|
|
||||||
tv = findViewById(R.id.tv);
|
tv = findViewById(R.id.tv);
|
||||||
textureView = binding.c2Camera.texture;
|
textureView = binding.c2Camera.tvCameraTextureView;
|
||||||
textureView.setSurfaceTextureListener(textureListener);
|
textureView.setSurfaceTextureListener(textureListener);
|
||||||
|
|
||||||
takePictureButton = binding.c2Camera.btnTakepicture;
|
takePictureButton = binding.c2Camera.btnTakepicture;
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
package com.example.cameraxtestappjava.camera;
|
||||||
|
|
||||||
|
import android.hardware.camera2.CameraCaptureSession;
|
||||||
|
import android.hardware.camera2.CameraCharacteristics;
|
||||||
|
import android.hardware.camera2.CameraDevice;
|
||||||
|
import android.hardware.camera2.CameraManager;
|
||||||
|
import android.hardware.camera2.CaptureRequest;
|
||||||
|
import android.media.ImageReader;
|
||||||
|
import android.media.MediaRecorder;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.HandlerThread;
|
||||||
|
import android.util.Range;
|
||||||
|
import android.util.Size;
|
||||||
|
import android.util.SparseIntArray;
|
||||||
|
import android.view.Surface;
|
||||||
|
import android.view.TextureView;
|
||||||
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
public class CustomCamera2 {
|
||||||
|
private static final String TAG = "AndroidCameraApi";
|
||||||
|
private ImageButton takePictureButton;
|
||||||
|
private TextureView textureView;
|
||||||
|
private TextView tv;
|
||||||
|
private static final SparseIntArray ORIENTATIONS = new SparseIntArray();
|
||||||
|
|
||||||
|
static {
|
||||||
|
ORIENTATIONS.append(Surface.ROTATION_0, 90);
|
||||||
|
ORIENTATIONS.append(Surface.ROTATION_90, 0);
|
||||||
|
ORIENTATIONS.append(Surface.ROTATION_180, 270);
|
||||||
|
ORIENTATIONS.append(Surface.ROTATION_270, 180);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class CompareSizeByArea implements Comparator<Size> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(Size ths, Size rhs) {
|
||||||
|
return Long.signum((long) ths.getWidth() * ths.getHeight() /
|
||||||
|
(long) rhs.getWidth() * rhs.getHeight());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String cameraId;
|
||||||
|
private String mCameraId;
|
||||||
|
private String defaultCameraId = "0";
|
||||||
|
Range<Integer> fps = new Range<>(110, 120);
|
||||||
|
private Range<Integer>[] availableFpsRange;
|
||||||
|
private Size mPreviewSize;
|
||||||
|
private Size mVideoSize;
|
||||||
|
private int totalRotation;
|
||||||
|
protected CameraDevice cameraDevice;
|
||||||
|
|
||||||
|
protected String[] cameraIds;
|
||||||
|
protected CameraManager cameraManager;
|
||||||
|
protected CameraCharacteristics cameraCharacteristics;
|
||||||
|
protected CameraCaptureSession cameraCaptureSessions;
|
||||||
|
protected CaptureRequest captureRequest;
|
||||||
|
protected CaptureRequest.Builder mCaptureRequestBuilder;
|
||||||
|
private Size imageDimension;
|
||||||
|
private ImageReader imageReader;
|
||||||
|
private boolean isRecording = false;
|
||||||
|
private File file;
|
||||||
|
private File fileFolder;
|
||||||
|
File videoFile;
|
||||||
|
private static final int REQUEST_CAMERA_PERMISSION = 200;
|
||||||
|
private boolean mFlashSupported;
|
||||||
|
private Handler mBackgroundHandler;
|
||||||
|
private HandlerThread mBackgroundThread;
|
||||||
|
private MediaRecorder mMediaRecorder;
|
||||||
|
private TextureView mTextureView;
|
||||||
|
private CaptureRequest.Builder captureRequestBuilder;
|
||||||
|
}
|
|
@ -8,7 +8,7 @@
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<TextureView
|
<TextureView
|
||||||
android:id="@+id/texture"
|
android:id="@+id/tvCameraTextureView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_above="@+id/btn_takepicture"
|
android:layout_above="@+id/btn_takepicture"
|
||||||
|
|
Loading…
Reference in a new issue