camera2 implementation (WIP)
This commit is contained in:
parent
990e071c65
commit
c34e197bf3
2 changed files with 17 additions and 43 deletions
|
@ -1,6 +1,6 @@
|
|||
package com.example.cameraxtestappjava;
|
||||
|
||||
import static com.example.cameraxtestappjava.camera.SegPassCamera.REQUEST_CAMERA_PERMISSION;
|
||||
import static com.example.cameraxtestappjava.camera.SegpassCamera.REQUEST_CAMERA_PERMISSION;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
|
@ -21,30 +21,18 @@ import androidx.core.view.ViewCompat;
|
|||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import com.example.cameraxtestappjava.camera.CustomCamera;
|
||||
import com.example.cameraxtestappjava.camera.SegPassCamera;
|
||||
import com.example.cameraxtestappjava.camera.SegpassCamera;
|
||||
import com.example.cameraxtestappjava.camera.CustomCameraCallback;
|
||||
import com.example.cameraxtestappjava.databinding.ActivityMainBinding;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
// binding
|
||||
ActivityMainBinding binding;
|
||||
CustomCamera mCamera;
|
||||
|
||||
// Camera2
|
||||
private static final String TAG = "AndroidCameraApi";
|
||||
private ImageButton mTakePictureButton;
|
||||
private TextureView mTextureView;
|
||||
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);
|
||||
}
|
||||
|
||||
SegPassCamera mCustomCamera2;
|
||||
private static final String TAG = "MainActivity";
|
||||
SegpassCamera mSegpassCamera;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -63,32 +51,18 @@ public class MainActivity extends AppCompatActivity {
|
|||
});
|
||||
}
|
||||
|
||||
private void setListeners() {
|
||||
binding.cvCustomCamera.btnTakePicture.setOnClickListener(v -> mCamera.capturePhoto(new CustomCameraCallback() {
|
||||
@Override
|
||||
public void onPictureTakenSuccess(String message) {
|
||||
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPictureTakenFailError(String error) {
|
||||
Toast.makeText(MainActivity.this, error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
// Camera 2
|
||||
private void setUpCamera2() {
|
||||
|
||||
// Initialize visual elements in host app
|
||||
mTextureView = binding.c2Camera.tvCameraTextureView;
|
||||
mTakePictureButton = binding.c2Camera.btnTakepicture;
|
||||
TextureView mTextureView = binding.c2Camera.tvCameraTextureView;
|
||||
ImageButton mTakePictureButton = binding.c2Camera.btnTakepicture;
|
||||
|
||||
// Initialized CustomCamera2 in host app
|
||||
mCustomCamera2 = new SegPassCamera(this, mTextureView);
|
||||
mCustomCamera2.init(); // Do not skip this!!!
|
||||
mSegpassCamera = new SegpassCamera(this, mTextureView);
|
||||
mSegpassCamera.init(); // Do not skip this!!!
|
||||
|
||||
mTakePictureButton.setOnClickListener(v -> mCustomCamera2.takePicture(new CustomCameraCallback() {
|
||||
mTakePictureButton.setOnClickListener(v -> mSegpassCamera.takePicture(new CustomCameraCallback() {
|
||||
@Override
|
||||
public void onPictureTakenSuccess(String message) {
|
||||
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
|
||||
|
@ -118,20 +92,20 @@ public class MainActivity extends AppCompatActivity {
|
|||
protected void onResume() {
|
||||
super.onResume();
|
||||
Log.d(TAG, "onResume");
|
||||
mCustomCamera2.resumeCamera();
|
||||
mSegpassCamera.resumeCamera();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
Log.d(TAG, "onPause");
|
||||
mCustomCamera2.pauseCamera();
|
||||
mSegpassCamera.pauseCamera();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
Log.d(TAG, "onPause");
|
||||
mCustomCamera2.destroyCamera();
|
||||
mSegpassCamera.destroyCamera();
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
|
@ -42,8 +42,8 @@ import java.util.Collections;
|
|||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class SegPassCamera {
|
||||
private static final String TAG = "CustomCamera2";
|
||||
public class SegpassCamera {
|
||||
private static final String TAG = "SegpassCamera";
|
||||
|
||||
Context mContext;
|
||||
AppCompatActivity mActivity;
|
||||
|
@ -83,12 +83,12 @@ public class SegPassCamera {
|
|||
}
|
||||
}
|
||||
|
||||
public SegPassCamera(Context context, TextureView textureView) {
|
||||
public SegpassCamera(Context context, TextureView textureView) {
|
||||
mContext = context;
|
||||
mTextureView = textureView;
|
||||
}
|
||||
|
||||
public SegPassCamera(AppCompatActivity activity, TextureView textureView) {
|
||||
public SegpassCamera(AppCompatActivity activity, TextureView textureView) {
|
||||
mActivity = activity;
|
||||
mTextureView = textureView;
|
||||
}
|
Loading…
Reference in a new issue