I want to use a Kotlin Android library (FotoApparat) in a Java Android project.
In a Kotlin code base the whenAvailble function gets a kotlin callback as a param, which will be called when the async operation is done.
val photoResult = fotoapparat.takePicture()
// Asynchronously saves photo to file
photoResult.saveToFile(someFile)
// Asynchronously converts photo to bitmap and returns the result on the main thread
photoResult
.toBitmap()
.whenAvailable { bitmapPhoto ->
val imageView = (ImageView) findViewById(R.id.result)
imageView.setImageBitmap(bitmapPhoto.bitmap)
imageView.setRotation(-bitmapPhoto.rotationDegrees)
}
whenAvailable code can be found here
The equivalent java implementation would be: (Previously the library was written in java)
fotoApparat.takePicture().
toPendingResult().
whenAvailable( /* some sort of call back */);
How do I provide the whenAvailable callback from a Java code?
In previous versions of the lib, there was a Java pending result callback class which no longer available.