Bill Roth
09/12/2023, 1:00 AMimageCapture.takePicture(cameraExecutor, object : ImageCapture.OnImageCapturedCallback() {
override fun onError(exc: ImageCaptureException) {
Log.e(TAG, "Mem Photo capture failed: ${exc.message}", exc)
}
override fun onCaptureSuccess(image : ImageProxy) {
Log.i(TAG, "Mem Photo capture succeeded")
var info = image.imageInfo
var x = 1
x+=1
}
So WTF is happening here:
object : ImageCapture.OnImageCapturedCallback() {}
Here's what I think is happening:
1. an ImageCapture object is being created and named object
2. The onImageCapturedCallback is being set to the blog of code between the {} (more or less)
Is this correct? It works, but the semantics of this are not clear.
oy. Or: Is it an object expression that is creating an anonymous ImageCapture object while replacing OnImageCapturedCallback ? My brain hurts.Chris Lee
09/12/2023, 1:15 AMobject :
is creating an anonymous object inheriting from a supertype. Kotlin docs.
You could equally extract this to a private class somewhere in scope class MyCallBack : ImageCapture.OnImageCapturedCallback() { … }
.
Within that object you are implementing/overriding the onError
and onCaptureSuccess
functions.Bill Roth
09/12/2023, 1:19 AMBill Roth
09/12/2023, 1:20 AMChris Lee
09/12/2023, 1:21 AMOnImageCapturedCallback
inside of ImageCapture
. Its that class that is the supertype and requires the ()
.
🍻ephemient
09/12/2023, 1:25 AMnew ImageCapture.OnImageCapturedCallback() {}
in Java, but makes it more obvious that something other than an ordinary object instantiation is happeningephemient
09/12/2023, 1:26 AMRobert Williams
09/12/2023, 9:56 AMRobert Williams
09/12/2023, 9:58 AMtakePicture(
executor : Executor,
onSuccess: (ImageProxy) -> Unit,
onError: (ImageCaptureException) -> Unit
)
Bill Roth
10/05/2023, 4:13 PMBill Roth
10/05/2023, 4:14 PM