control commit

This commit is contained in:
Captain Arepa 2024-05-27 08:17:07 -04:00
parent 2f449a55c8
commit 51bd224ce5
2 changed files with 19 additions and 19 deletions

View file

@ -1,6 +1,6 @@
package com.example.cameraxtestappjava; package com.example.cameraxtestappjava;
import static com.example.cameraxtestappjava.segpass.CustomCamera.REQUEST_CAMERA_PERMISSION; import static com.example.cameraxtestappjava.segpass.SegpassCamera.REQUEST_CAMERA_PERMISSION;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
@ -23,12 +23,12 @@ import com.example.cameraxtestappjava.segpass.camera.utils.SegpassCameraCallback
import com.example.cameraxtestappjava.segpass.camera.utils.SegpassCameraStateCallback; import com.example.cameraxtestappjava.segpass.camera.utils.SegpassCameraStateCallback;
import com.example.cameraxtestappjava.segpass.camera.utils.SegpassPermissionListener; import com.example.cameraxtestappjava.segpass.camera.utils.SegpassPermissionListener;
import com.example.cameraxtestappjava.databinding.ActivityCameraNewBinding; import com.example.cameraxtestappjava.databinding.ActivityCameraNewBinding;
import com.example.cameraxtestappjava.segpass.CustomCamera; import com.example.cameraxtestappjava.segpass.SegpassCamera;
public class CameraActivityNew extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback, SegpassCameraCallback, SegpassCameraStateCallback, SegpassPermissionListener { public class CameraActivityNew extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback, SegpassCameraCallback, SegpassCameraStateCallback, SegpassPermissionListener {
ActivityCameraNewBinding binding; ActivityCameraNewBinding binding;
CustomCamera mCustomCamera; SegpassCamera mSegpassCamera;
AutoFitTextureView mTextureView; AutoFitTextureView mTextureView;
@SuppressLint("SourceLockedOrientationActivity") @SuppressLint("SourceLockedOrientationActivity")
@ -41,8 +41,8 @@ public class CameraActivityNew extends AppCompatActivity implements ActivityComp
setContentView(binding.getRoot()); setContentView(binding.getRoot());
mTextureView = binding.inCamera2.tvCameraTextureView; mTextureView = binding.inCamera2.tvCameraTextureView;
mCustomCamera = new CustomCamera(this, mTextureView, this, this); mSegpassCamera = new SegpassCamera(this, mTextureView, this, this);
mCustomCamera.init(); mSegpassCamera.init();
setUpListeners(); setUpListeners();
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
@ -55,12 +55,12 @@ public class CameraActivityNew extends AppCompatActivity implements ActivityComp
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
mCustomCamera.resumeCamera(); mSegpassCamera.resumeCamera();
} }
@Override @Override
public void onPause() { public void onPause() {
mCustomCamera.pauseCamera(); mSegpassCamera.pauseCamera();
super.onPause(); super.onPause();
} }
@ -78,7 +78,7 @@ public class CameraActivityNew extends AppCompatActivity implements ActivityComp
private void setUpListeners() { private void setUpListeners() {
binding.inCamera2.btnTakepicture.setOnClickListener(v -> { binding.inCamera2.btnTakepicture.setOnClickListener(v -> {
mCustomCamera.takePicture(this); mSegpassCamera.takePicture(this);
}); });
} }
@ -88,12 +88,12 @@ public class CameraActivityNew extends AppCompatActivity implements ActivityComp
@Override @Override
public void onPictureTakenSuccess(String message) { public void onPictureTakenSuccess(String message) {
mCustomCamera.showToast(message); mSegpassCamera.showToast(message);
} }
@Override @Override
public void onPictureTakenFailError(String error) { public void onPictureTakenFailError(String error) {
mCustomCamera.showToast(error); mSegpassCamera.showToast(error);
} }
/** /**
@ -102,7 +102,7 @@ public class CameraActivityNew extends AppCompatActivity implements ActivityComp
@Override @Override
public void onCameraInitError(String errorMessage) { public void onCameraInitError(String errorMessage) {
mCustomCamera.showToast(errorMessage); mSegpassCamera.showToast(errorMessage);
} }
/** /**
@ -121,7 +121,7 @@ public class CameraActivityNew extends AppCompatActivity implements ActivityComp
@Override @Override
public void onPermissionDenied() { public void onPermissionDenied() {
mCustomCamera.showToast("No permissions granted, closing camera."); mSegpassCamera.showToast("No permissions granted, closing camera.");
finish(); finish();
} }
} }

View file

@ -51,7 +51,7 @@ import java.util.List;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class CustomCamera { public class SegpassCamera {
/** /**
* Tag for the {@link Log}. * Tag for the {@link Log}.
@ -163,7 +163,7 @@ public class CustomCamera {
* @param textureView: The View used to show the Camera preview. * @param textureView: The View used to show the Camera preview.
* @param listener: Custom listener to deal with camera and storage permissions. * @param listener: Custom listener to deal with camera and storage permissions.
*/ */
public CustomCamera(AppCompatActivity activity, AutoFitTextureView textureView, SegpassPermissionListener listener) { public SegpassCamera(AppCompatActivity activity, AutoFitTextureView textureView, SegpassPermissionListener listener) {
mActivity = activity; mActivity = activity;
mTextureView = textureView; mTextureView = textureView;
mPermissionListener = listener; mPermissionListener = listener;
@ -176,7 +176,7 @@ public class CustomCamera {
* @param listener: Custom listener to deal with camera and storage permissions. * @param listener: Custom listener to deal with camera and storage permissions.
* @param stateCallback: Custom listener to deal with camera states in case it's deemed necessary. * @param stateCallback: Custom listener to deal with camera states in case it's deemed necessary.
*/ */
public CustomCamera(AppCompatActivity activity, AutoFitTextureView textureView, SegpassPermissionListener listener, @Nullable SegpassCameraStateCallback stateCallback) { public SegpassCamera(AppCompatActivity activity, AutoFitTextureView textureView, SegpassPermissionListener listener, @Nullable SegpassCameraStateCallback stateCallback) {
mActivity = activity; mActivity = activity;
mTextureView = textureView; mTextureView = textureView;
mPermissionListener = listener; mPermissionListener = listener;
@ -376,7 +376,6 @@ public class CustomCamera {
* @param width The width of available size for camera preview * @param width The width of available size for camera preview
* @param height The height of available size for camera preview * @param height The height of available size for camera preview
*/ */
@SuppressWarnings("SuspiciousNameCombination")
private void setUpCameraOutputs(int width, int height) { private void setUpCameraOutputs(int width, int height) {
CameraManager manager = (CameraManager) mActivity.getSystemService(Context.CAMERA_SERVICE); CameraManager manager = (CameraManager) mActivity.getSystemService(Context.CAMERA_SERVICE);
try { try {
@ -478,7 +477,7 @@ public class CustomCamera {
} }
/** /**
* Opens the camera specified by {@link CustomCamera#mCameraId}. * Opens the camera specified by {@link SegpassCamera#mCameraId}.
*/ */
private void openCamera(int width, int height) { private void openCamera(int width, int height) {
// Check permissions // Check permissions
@ -669,7 +668,8 @@ public class CustomCamera {
// Pre-set file // Pre-set file
String fileName = "IMG_" + System.currentTimeMillis() + ".jpg"; String fileName = "IMG_" + System.currentTimeMillis() + ".jpg";
mFile = new File(mFileFolder + "/" + fileName); // Ver como hacer para guardar en la carpeta de la app String base64FileName = "IMG_" + System.currentTimeMillis() + "_64.txt";
mFile = new File(mFileFolder + "/" + base64FileName); // Ver como hacer para guardar en la carpeta de la app
mReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler); mReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);
final CameraCaptureSession.CaptureCallback captureListener = new CameraCaptureSession.CaptureCallback() { final CameraCaptureSession.CaptureCallback captureListener = new CameraCaptureSession.CaptureCallback() {
@ -712,7 +712,7 @@ public class CustomCamera {
} }
/** /**
* Creates the custom folder {@link CustomCamera#mFileFolder} where pictures are saved. * Creates the custom folder {@link SegpassCamera#mFileFolder} where pictures are saved.
*/ */
public void createFolder() { public void createFolder() {
PackageManager pm = mActivity.getPackageManager(); PackageManager pm = mActivity.getPackageManager();