Class CameraController
- java.lang.Object
-
- com.cmput301w23t09.qrhunter.scanqr.camera.CameraController
-
- Direct Known Subclasses:
CameraLocationPhotoController
,CameraScannerController
public abstract class CameraController extends java.lang.Object
Manages Camera preview and capture using Google's CameraX library https://developer.android.com/training/camerax (Used ChatGPT to convert Kotlin to Java)Extended in subclasses to add functionality, such as QRCode scanning and photo taking (location photos)
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String[]
CAMERA_PERMISSIONS
protected java.util.concurrent.ExecutorService
cameraExecutor
protected androidx.fragment.app.Fragment
fragment
protected androidx.camera.view.PreviewView
previewView
static int
REQUEST_CODE_PERMISSIONS
-
Constructor Summary
Constructors Constructor Description CameraController(androidx.fragment.app.Fragment fragment, androidx.camera.view.PreviewView previewView)
Creates a basic CameraController that displays its preview to a view.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
cameraPermissionsGranted()
Checks if all required permissions are grantedvoid
onDestroy()
Shut down the camera when it's no longer neededprotected abstract void
setupCamera(com.google.common.util.concurrent.ListenableFuture<androidx.camera.lifecycle.ProcessCameraProvider> cameraProviderFuture)
Adds in the camera's functionalityvoid
startCamera()
Starts the camera and binds it's preview to the PreviewView UI element.
-
-
-
Field Detail
-
cameraExecutor
protected java.util.concurrent.ExecutorService cameraExecutor
-
fragment
protected androidx.fragment.app.Fragment fragment
-
previewView
protected androidx.camera.view.PreviewView previewView
-
REQUEST_CODE_PERMISSIONS
public static final int REQUEST_CODE_PERMISSIONS
- See Also:
- Constant Field Values
-
CAMERA_PERMISSIONS
public static final java.lang.String[] CAMERA_PERMISSIONS
-
-
Constructor Detail
-
CameraController
public CameraController(androidx.fragment.app.Fragment fragment, androidx.camera.view.PreviewView previewView)
Creates a basic CameraController that displays its preview to a view.- Parameters:
fragment
- The fragment that uses the camera.previewView
- The UI element in fragment to show camera preview on.
-
-
Method Detail
-
startCamera
public void startCamera()
Starts the camera and binds it's preview to the PreviewView UI element.
-
setupCamera
protected abstract void setupCamera(com.google.common.util.concurrent.ListenableFuture<androidx.camera.lifecycle.ProcessCameraProvider> cameraProviderFuture) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
Adds in the camera's functionality- Parameters:
cameraProviderFuture
- The camera's provider object- Throws:
java.util.concurrent.ExecutionException
- if setup failsjava.lang.InterruptedException
- if setup fails
-
onDestroy
public void onDestroy()
Shut down the camera when it's no longer needed
-
cameraPermissionsGranted
public boolean cameraPermissionsGranted()
Checks if all required permissions are granted- Returns:
- True if every permission under CameraController.REQUIRED_PERMISSIONS is granted
-
-