@capacitor/camera 8.2.4 → 8.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -111,6 +111,7 @@ public class CameraBottomSheetDialogFragment extends BottomSheetDialogFragment {
111
111
  dialog.setContentView(parentLayout.getRootView());
112
112
 
113
113
  CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) parentLayout.getParent()).getLayoutParams();
114
+ @SuppressWarnings("unchecked")
114
115
  CoordinatorLayout.Behavior<View> behavior = params.getBehavior();
115
116
 
116
117
  if (behavior instanceof BottomSheetBehavior) {
@@ -2,13 +2,9 @@ package com.capacitorjs.plugins.camera
2
2
 
3
3
  import android.Manifest
4
4
  import android.annotation.SuppressLint
5
- import android.content.Intent
6
- import android.content.pm.PackageManager
7
- import android.content.pm.ResolveInfo
8
5
  import android.os.Build
9
6
  import android.os.Bundle
10
7
  import androidx.activity.result.ActivityResult
11
- import com.getcapacitor.Logger
12
8
  import com.getcapacitor.PermissionState
13
9
  import com.getcapacitor.Plugin
14
10
  import com.getcapacitor.PluginCall
@@ -18,6 +14,7 @@ import com.getcapacitor.annotation.CapacitorPlugin
18
14
  import com.getcapacitor.annotation.Permission
19
15
  import com.getcapacitor.annotation.PermissionCallback
20
16
  import org.json.JSONException
17
+
21
18
  /**
22
19
  * The Camera plugin makes it easy to take a photo or have the user select a photo
23
20
  * from their albums.
@@ -74,11 +71,10 @@ class CameraPlugin : Plugin() {
74
71
  activity,
75
72
  bridge,
76
73
  appId,
77
- permissionHelper,
78
- LegacyCameraFlow.ActivityStarter { call, intent, callbackName ->
79
- startActivityForResult(call, intent, callbackName)
80
- }
81
- )
74
+ permissionHelper
75
+ ) { call, intent, callbackName ->
76
+ startActivityForResult(call, intent, callbackName)
77
+ }
82
78
 
83
79
  ionFlow = IonCameraFlow(
84
80
  context,
@@ -205,7 +201,7 @@ class CameraPlugin : Plugin() {
205
201
  if (providedPerms != null) {
206
202
  try {
207
203
  permsList = providedPerms.toList<String?>()
208
- } catch (e: JSONException) {
204
+ } catch (_: JSONException) {
209
205
  }
210
206
  }
211
207
 
@@ -228,45 +224,24 @@ class CameraPlugin : Plugin() {
228
224
 
229
225
  // If Camera is not in the manifest and therefore not required, say the permission is granted
230
226
  if (!isPermissionDeclared(CAMERA)) {
231
- permissionStates.put(CAMERA, PermissionState.GRANTED)
227
+ permissionStates[CAMERA] = PermissionState.GRANTED
232
228
  }
233
229
 
234
230
  if (permissionStates.containsKey(PHOTOS)) {
235
- permissionStates.put(PHOTOS, PermissionState.GRANTED)
231
+ permissionStates[PHOTOS] = PermissionState.GRANTED
236
232
  }
237
233
 
238
234
  // If the SDK version is 30 or higher, update the SAVE_GALLERY state to match the READ_EXTERNAL_STORAGE state.
239
235
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
240
236
  val alias: String = READ_EXTERNAL_STORAGE
241
237
  if (permissionStates.containsKey(alias)) {
242
- permissionStates.put(SAVE_GALLERY, permissionStates.get(alias))
238
+ permissionStates[SAVE_GALLERY] = permissionStates[alias]
243
239
  }
244
240
  }
245
241
 
246
242
  return permissionStates
247
243
  }
248
244
 
249
- private fun getResultType(resultType: String?): CameraResultType? {
250
- if (resultType == null) {
251
- return null
252
- }
253
- try {
254
- return CameraResultType.valueOf(resultType.uppercase())
255
- } catch (ex: java.lang.IllegalArgumentException) {
256
- Logger.debug(
257
- getLogTag(),
258
- "Invalid result type \"" + resultType + "\", defaulting to base64"
259
- )
260
- return CameraResultType.BASE64
261
- }
262
- }
263
-
264
- @Suppress("deprecation")
265
- private fun legacyQueryIntentActivities(intent: Intent): MutableList<ResolveInfo> {
266
- return getContext().getPackageManager()
267
- .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
268
- }
269
-
270
245
  protected override fun saveInstanceState(): Bundle? {
271
246
  val bundle = super.saveInstanceState()
272
247
  legacyFlow.onSaveInstanceState(bundle)
@@ -15,8 +15,6 @@ import androidx.activity.result.ActivityResultLauncher
15
15
  import androidx.activity.result.contract.ActivityResultContracts
16
16
  import androidx.appcompat.app.AppCompatActivity
17
17
  import androidx.core.content.FileProvider
18
- import com.capacitorjs.plugins.camera.IonCameraSettings.Companion.DEFAULT_CORRECT_ORIENTATION
19
- import com.capacitorjs.plugins.camera.IonCameraSettings.Companion.DEFAULT_QUALITY
20
18
  import com.getcapacitor.Bridge
21
19
  import com.getcapacitor.FileUtils
22
20
  import com.getcapacitor.JSArray
@@ -202,10 +200,10 @@ class IonCameraFlow(
202
200
  limit = call.getInt("limit") ?: 0,
203
201
  includeMetadata = call.getBoolean("includeMetadata") ?: false,
204
202
  editable = IonEditableMode.fromString(call.getString("editable")),
205
- quality = call.getInt("quality") ?: DEFAULT_QUALITY,
203
+ quality = call.getInt("quality") ?: IonCameraSettings.DEFAULT_QUALITY,
206
204
  width = call.getInt("targetWidth") ?: 0,
207
205
  height = call.getInt("targetHeight") ?: 0,
208
- correctOrientation = call.getBoolean("correctOrientation") ?: DEFAULT_CORRECT_ORIENTATION
206
+ correctOrientation = call.getBoolean("correctOrientation") ?: IonCameraSettings.DEFAULT_CORRECT_ORIENTATION
209
207
  )
210
208
  }
211
209
 
@@ -241,7 +239,7 @@ class IonCameraFlow(
241
239
 
242
240
 
243
241
  private fun showCamera(call: PluginCall) {
244
- if (!context.getPackageManager()
242
+ if (!context.packageManager
245
243
  .hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)
246
244
  ) {
247
245
  sendError(IONCAMRError.NO_CAMERA_AVAILABLE_ERROR)
@@ -264,7 +262,7 @@ class IonCameraFlow(
264
262
  }
265
263
  currentCall = call
266
264
  manager.takePhoto(activity, settings.encodingType, cameraLauncher)
267
- } catch (ex: Exception) {
265
+ } catch (_: Exception) {
268
266
  sendError(IONCAMRError.TAKE_PHOTO_ERROR)
269
267
  }
270
268
  }
@@ -290,7 +288,7 @@ class IonCameraFlow(
290
288
  ) {
291
289
  sendError(it)
292
290
  }
293
- } catch (ex: Exception) {
291
+ } catch (_: Exception) {
294
292
  sendError(IONCAMRError.CAPTURE_VIDEO_ERROR)
295
293
  }
296
294
  }
@@ -647,15 +645,14 @@ class IonCameraFlow(
647
645
  editIntent.addFlags(flags)
648
646
  editIntent.putExtra(MediaStore.EXTRA_OUTPUT, editUri)
649
647
 
650
- val resInfoList: MutableList<ResolveInfo>?
651
-
652
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
653
- resInfoList = context
654
- .packageManager
655
- .queryIntentActivities(editIntent, PackageManager.ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong()))
656
- } else {
657
- resInfoList = legacyQueryIntentActivities(editIntent)
658
- }
648
+ val resInfoList: MutableList<ResolveInfo> =
649
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
650
+ context
651
+ .packageManager
652
+ .queryIntentActivities(editIntent, PackageManager.ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong()))
653
+ } else {
654
+ legacyQueryIntentActivities(editIntent)
655
+ }
659
656
 
660
657
  for (resolveInfo in resInfoList) {
661
658
  val packageName = resolveInfo.activityInfo.packageName
@@ -663,12 +660,11 @@ class IonCameraFlow(
663
660
  }
664
661
 
665
662
  editIntent
666
- } catch (e: Exception) {
663
+ } catch (_: Exception) {
667
664
  null
668
665
  }
669
666
  }
670
667
 
671
- @Suppress("deprecation")
672
668
  private fun legacyQueryIntentActivities(intent: Intent): MutableList<ResolveInfo> {
673
669
  return context.packageManager
674
670
  .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
@@ -861,10 +857,6 @@ class IonCameraFlow(
861
857
  .getString(STORE, "")
862
858
  fromPreferences.let { uri = Uri.parse(fromPreferences) }
863
859
  }
864
- if (activity == null) {
865
- sendError(IONCAMRError.CAPTURE_VIDEO_ERROR)
866
- return
867
- }
868
860
  val settings = videoParameters ?: run {
869
861
  sendError(IONCAMRError.INVALID_ARGUMENT_ERROR)
870
862
  return
@@ -1044,7 +1036,7 @@ class IonCameraFlow(
1044
1036
  jsonResult.put("message", error.description)
1045
1037
  currentCall?.reject(error.description, formatErrorCode(error.code))
1046
1038
  currentCall = null
1047
- } catch (e: Exception) {
1039
+ } catch (_: Exception) {
1048
1040
  currentCall?.reject("There was an error performing the operation.")
1049
1041
  currentCall = null
1050
1042
  } finally {
@@ -1053,7 +1045,7 @@ class IonCameraFlow(
1053
1045
  }
1054
1046
 
1055
1047
  private fun formatErrorCode(code: Int): String {
1056
- val stringCode = Integer.toString(code)
1048
+ val stringCode = code.toString()
1057
1049
  return ERROR_FORMAT_PREFIX + "0000$stringCode".substring(stringCode.length)
1058
1050
  }
1059
1051
 
@@ -17,7 +17,7 @@ object IonCameraUtils {
17
17
  inputStream.use {
18
18
  saveImage(context, uri, it)
19
19
  }
20
- } catch (e: Exception) {
20
+ } catch (_: Exception) {
21
21
  null
22
22
  }
23
23
  }
@@ -38,7 +38,7 @@ object IonCameraUtils {
38
38
  inputStream.copyTo(output)
39
39
  }
40
40
  Uri.fromFile(tempFile)
41
- } catch (e: Exception) {
41
+ } catch (_: Exception) {
42
42
  null
43
43
  }
44
44
  }
@@ -8,7 +8,7 @@ enum class IonEditableMode(val value: String) {
8
8
  companion object {
9
9
  fun fromString(value: String?): IonEditableMode {
10
10
  if (value == null) return NO
11
- return values().find {
11
+ return entries.find {
12
12
  it.value.equals(value, ignoreCase = true)
13
13
  } ?: NO
14
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/camera",
3
- "version": "8.2.4",
3
+ "version": "8.2.5",
4
4
  "description": "The Camera API provides the ability to take a photo with the camera or choose an existing one from the photo album.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",