@@ -14,6 +14,9 @@ import androidx.activity.result.ActivityResult
1414import androidx.activity.result.ActivityResultLauncher
1515import androidx.activity.result.contract.ActivityResultContracts
1616import androidx.core.content.FileProvider
17+ import com.capacitorjs.plugins.camera.IonCameraSettings.Companion.DEFAULT_CORRECT_ORIENTATION
18+ import com.capacitorjs.plugins.camera.IonCameraSettings.Companion.DEFAULT_QUALITY
19+ import com.capacitorjs.plugins.camera.IonCameraSettings.Companion.DEFAULT_SAVE_IMAGE_TO_GALLERY
1720import com.getcapacitor.FileUtils
1821import com.getcapacitor.JSArray
1922import com.getcapacitor.JSObject
@@ -189,24 +192,16 @@ class IonCameraFlow(
189192
190193 fun getCameraSettings (call : PluginCall ): IonCameraSettings {
191194 val settings = IonCameraSettings ()
192- settings.resultType = CameraResultType .URI // getResultType(call.getString("resultType"))
193- settings.saveToGallery = call.getBoolean(" saveToGallery" , IonCameraSettings .DEFAULT_SAVE_IMAGE_TO_GALLERY )!!
194- settings.allowEdit = call.getBoolean(" allowEdit" , false )!!
195195 settings.quality = call.getInt(" quality" , IonCameraSettings .DEFAULT_QUALITY )!!
196196 settings.width = call.getInt(" width" , 0 )!!
197197 settings.height = call.getInt(" height" , 0 )!!
198- settings.shouldResize = settings.width > 0 || settings.height > 0
199- settings.shouldCorrectOrientation =
200- call.getBoolean(" correctOrientation" , IonCameraSettings .DEFAULT_CORRECT_ORIENTATION )!!
198+ settings.correctOrientation = call.getBoolean(" correctOrientation" , IonCameraSettings .DEFAULT_CORRECT_ORIENTATION )!!
199+ settings.encodingType = call.getInt(" encodingType" , IonCameraSettings .DEFAULT_ENCODING_TYPE )!!
200+ settings.saveToGallery = call.getBoolean(" saveToGallery" , IonCameraSettings .DEFAULT_SAVE_IMAGE_TO_GALLERY )!!
201+ settings.allowEdit = call.getBoolean(" allowEdit" , false )!!
201202 settings.editInApp = call.getBoolean(" editInApp" , true )!!
202203 settings.includeMetadata = call.getBoolean(" includeMetadata" , false )!!
203-
204- try {
205- settings.source =
206- CameraSource .valueOf(call.getString(" source" , CameraSource .PROMPT .getSource())!! )
207- } catch (ex: IllegalArgumentException ) {
208- settings.source = CameraSource .PROMPT
209- }
204+ settings.shouldResize = settings.width > 0 || settings.height > 0
210205 return settings
211206 }
212207
@@ -234,7 +229,7 @@ class IonCameraFlow(
234229 return
235230 }
236231 currentCall = call
237- manager.takePhoto(plugin.getActivity(), CameraPlugin . ENCODING_TYPE , cameraLauncher)
232+ manager.takePhoto(plugin.getActivity(), settings.encodingType , cameraLauncher)
238233 } catch (ex: Exception ) {
239234 sendError(IONCAMRError .FAILED_TO_CAPTURE_IMAGE_ERROR )
240235 }
@@ -369,7 +364,7 @@ class IonCameraFlow(
369364 " $appId .fileprovider" ,
370365 editor.createCaptureFile(
371366 plugin.activity,
372- CameraPlugin . ENCODING_TYPE ,
367+ settings.encodingType ,
373368 plugin.activity.getSharedPreferences(
374369 CameraPlugin .STORE ,
375370 Context .MODE_PRIVATE
@@ -551,13 +546,18 @@ class IonCameraFlow(
551546 return
552547 }
553548
549+ val settings = cameraSettings ? : run {
550+ sendError(IONCAMRError .INVALID_ARGUMENT_ERROR )
551+ return
552+ }
553+
554554 val appId = plugin.getAppId()
555555 val tmpFile = FileProvider .getUriForFile(
556556 plugin.activity,
557557 " $appId .fileprovider" ,
558558 editor.createCaptureFile(
559559 plugin.activity,
560- CameraPlugin . ENCODING_TYPE ,
560+ settings.encodingType ,
561561 plugin.activity.getSharedPreferences(
562562 CameraPlugin .STORE ,
563563 Context .MODE_PRIVATE
@@ -668,34 +668,6 @@ class IonCameraFlow(
668668 }
669669 }
670670
671- private fun handlePhotoBase64Result (image : String ) {
672- val ret = JSObject ()
673- ret.put(" format" , " jpeg" )
674-
675- val settings = cameraSettings ? : run {
676- sendError(IONCAMRError .INVALID_ARGUMENT_ERROR )
677- return
678- }
679-
680- when (settings.resultType) {
681- CameraResultType .BASE64 -> {
682- ret.put(" base64String" , image)
683- }
684-
685- CameraResultType .DATAURL -> {
686- ret.put(" dataUrl" , " data:image/jpeg;base64,$image " )
687- }
688-
689- else -> {
690- sendError(IONCAMRError .PROCESS_IMAGE_ERROR )
691- return
692- }
693- }
694-
695- currentCall?.resolve(ret)
696- currentCall = null
697- }
698-
699671 private fun handleEditBase64Result (image : String ) {
700672 val ret = JSObject ()
701673 ret.put(" format" , " jpeg" )
@@ -713,13 +685,30 @@ class IonCameraFlow(
713685 return
714686 }
715687
688+
689+
716690 val exif = ImageUtils .getExifData(plugin.context, bitmap, uri)
717691 val ret = JSObject ()
718- ret.put(" format " , " jpeg " )
719- ret.put(" exif " , exif.toJson() )
720- ret.put(" path " , mediaResult.uri )
692+ ret.put(" type " , mediaResult.type )
693+ ret.put(" uri " , mediaResult.uri )
694+ ret.put(" thumbnail " , mediaResult.thumbnail )
721695 ret.put(" webPath" , FileUtils .getPortablePath(plugin.context, plugin.bridge.localUrl, uri))
722696 ret.put(" saved" , mediaResult.saved)
697+
698+
699+
700+ val metadata = JSObject ()
701+ mediaResult.metadata?.let {
702+ metadata.put(" duration" , it.duration)
703+ metadata.put(" size" , it.size)
704+ metadata.put(" format" , it.format)
705+ metadata.put(" resolution" , it.resolution)
706+ metadata.put(" creationDate" , it.creationDate)
707+ metadata.put(" exif" , exif.toJson())
708+ }
709+
710+ ret.put(" metadata" , metadata)
711+
723712 currentCall?.resolve(ret)
724713 currentCall = null
725714 lastEditUri = null
@@ -736,13 +725,17 @@ class IonCameraFlow(
736725 ret.put(" webPath" , FileUtils .getPortablePath(plugin.context, plugin.bridge.localUrl, uri))
737726 ret.put(" saved" , mediaResult.saved)
738727
739- mediaResult.metadata?.let { metadata ->
740- ret.put(" duration" , metadata.duration)
741- ret.put(" size" , metadata.size)
742- ret.put(" format" , metadata.format)
743- ret.put(" resolution" , metadata.resolution)
744- ret.put(" creationDate" , metadata.creationDate)
728+ val metadata = JSObject ()
729+ mediaResult.metadata?.let {
730+ metadata.put(" duration" , it.duration)
731+ metadata.put(" size" , it.size)
732+ metadata.put(" format" , it.format)
733+ metadata.put(" resolution" , it.resolution)
734+ metadata.put(" creationDate" , it.creationDate)
745735 }
736+
737+ ret.put(" metadata" , metadata)
738+
746739 currentCall?.resolve(ret)
747740 currentCall = null
748741 }
@@ -793,7 +786,7 @@ class IonCameraFlow(
793786 intent,
794787 ionParams,
795788 { image ->
796- handlePhotoBase64Result(image)
789+ // TODO remove this callback
797790 },
798791 { mediaResult ->
799792 handleMediaResult(mediaResult)
@@ -888,18 +881,17 @@ class IonCameraFlow(
888881 }
889882
890883 private fun IonCameraSettings.toIonParameters (): IONCAMRCameraParameters {
891- val useLatestVersion = (resultType == CameraResultType .URI )
892884 return IONCAMRCameraParameters (
893885 mQuality = quality,
894886 targetWidth = width,
895887 targetHeight = height,
896- encodingType = CameraPlugin . ENCODING_TYPE , // JPEG
888+ encodingType = encodingType,
897889 mediaType = CameraPlugin .MEDIA_TYPE_PICTURE ,
898890 allowEdit = allowEdit,
899- correctOrientation = shouldCorrectOrientation ,
891+ correctOrientation = correctOrientation ,
900892 saveToPhotoAlbum = saveToGallery,
901893 includeMetadata = includeMetadata,
902- latestVersion = useLatestVersion // TODO check this, because now we don't have resultType in the new Api
894+ latestVersion = true // TODO check this, because now we don't have resultType in the new Api
903895 )
904896 }
905897
0 commit comments