Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void setupDialog(Dialog dialog, int style) {
dialog.setContentView(parentLayout.getRootView());

CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) parentLayout.getParent()).getLayoutParams();
@SuppressWarnings("unchecked")
CoordinatorLayout.Behavior<View> behavior = params.getBehavior();

if (behavior instanceof BottomSheetBehavior) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package com.capacitorjs.plugins.camera

import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.os.Build
import android.os.Bundle
import androidx.activity.result.ActivityResult
import com.getcapacitor.Logger
import com.getcapacitor.PermissionState
import com.getcapacitor.Plugin
import com.getcapacitor.PluginCall
Expand All @@ -18,6 +14,7 @@ import com.getcapacitor.annotation.CapacitorPlugin
import com.getcapacitor.annotation.Permission
import com.getcapacitor.annotation.PermissionCallback
import org.json.JSONException

/**
* The Camera plugin makes it easy to take a photo or have the user select a photo
* from their albums.
Expand Down Expand Up @@ -74,11 +71,10 @@ class CameraPlugin : Plugin() {
activity,
bridge,
appId,
permissionHelper,
LegacyCameraFlow.ActivityStarter { call, intent, callbackName ->
startActivityForResult(call, intent, callbackName)
}
)
permissionHelper
) { call, intent, callbackName ->
startActivityForResult(call, intent, callbackName)
}

ionFlow = IonCameraFlow(
context,
Expand Down Expand Up @@ -205,7 +201,7 @@ class CameraPlugin : Plugin() {
if (providedPerms != null) {
try {
permsList = providedPerms.toList<String?>()
} catch (e: JSONException) {
} catch (_: JSONException) {
}
}

Expand All @@ -228,45 +224,24 @@ class CameraPlugin : Plugin() {

// If Camera is not in the manifest and therefore not required, say the permission is granted
if (!isPermissionDeclared(CAMERA)) {
permissionStates.put(CAMERA, PermissionState.GRANTED)
permissionStates[CAMERA] = PermissionState.GRANTED
}

if (permissionStates.containsKey(PHOTOS)) {
permissionStates.put(PHOTOS, PermissionState.GRANTED)
permissionStates[PHOTOS] = PermissionState.GRANTED
}

// If the SDK version is 30 or higher, update the SAVE_GALLERY state to match the READ_EXTERNAL_STORAGE state.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val alias: String = READ_EXTERNAL_STORAGE
if (permissionStates.containsKey(alias)) {
permissionStates.put(SAVE_GALLERY, permissionStates.get(alias))
permissionStates[SAVE_GALLERY] = permissionStates[alias]
}
}

return permissionStates
}

private fun getResultType(resultType: String?): CameraResultType? {
if (resultType == null) {
return null
}
try {
return CameraResultType.valueOf(resultType.uppercase())
} catch (ex: java.lang.IllegalArgumentException) {
Logger.debug(
getLogTag(),
"Invalid result type \"" + resultType + "\", defaulting to base64"
)
return CameraResultType.BASE64
}
}

@Suppress("deprecation")
private fun legacyQueryIntentActivities(intent: Intent): MutableList<ResolveInfo> {
return getContext().getPackageManager()
.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
}

protected override fun saveInstanceState(): Bundle? {
val bundle = super.saveInstanceState()
legacyFlow.onSaveInstanceState(bundle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.FileProvider
import com.capacitorjs.plugins.camera.IonCameraSettings.Companion.DEFAULT_CORRECT_ORIENTATION
import com.capacitorjs.plugins.camera.IonCameraSettings.Companion.DEFAULT_QUALITY
import com.getcapacitor.Bridge
import com.getcapacitor.FileUtils
import com.getcapacitor.JSArray
Expand Down Expand Up @@ -202,10 +200,10 @@ class IonCameraFlow(
limit = call.getInt("limit") ?: 0,
includeMetadata = call.getBoolean("includeMetadata") ?: false,
editable = IonEditableMode.fromString(call.getString("editable")),
quality = call.getInt("quality") ?: DEFAULT_QUALITY,
quality = call.getInt("quality") ?: IonCameraSettings.DEFAULT_QUALITY,
width = call.getInt("targetWidth") ?: 0,
height = call.getInt("targetHeight") ?: 0,
correctOrientation = call.getBoolean("correctOrientation") ?: DEFAULT_CORRECT_ORIENTATION
correctOrientation = call.getBoolean("correctOrientation") ?: IonCameraSettings.DEFAULT_CORRECT_ORIENTATION
)
}

Expand Down Expand Up @@ -241,7 +239,7 @@ class IonCameraFlow(


private fun showCamera(call: PluginCall) {
if (!context.getPackageManager()
if (!context.packageManager
.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)
) {
sendError(IONCAMRError.NO_CAMERA_AVAILABLE_ERROR)
Expand All @@ -264,7 +262,7 @@ class IonCameraFlow(
}
currentCall = call
manager.takePhoto(activity, settings.encodingType, cameraLauncher)
} catch (ex: Exception) {
} catch (_: Exception) {
sendError(IONCAMRError.TAKE_PHOTO_ERROR)
}
}
Expand All @@ -290,7 +288,7 @@ class IonCameraFlow(
) {
sendError(it)
}
} catch (ex: Exception) {
} catch (_: Exception) {
sendError(IONCAMRError.CAPTURE_VIDEO_ERROR)
}
}
Expand Down Expand Up @@ -647,28 +645,26 @@ class IonCameraFlow(
editIntent.addFlags(flags)
editIntent.putExtra(MediaStore.EXTRA_OUTPUT, editUri)

val resInfoList: MutableList<ResolveInfo>?

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
resInfoList = context
.packageManager
.queryIntentActivities(editIntent, PackageManager.ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong()))
} else {
resInfoList = legacyQueryIntentActivities(editIntent)
}
val resInfoList: MutableList<ResolveInfo> =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context
.packageManager
.queryIntentActivities(editIntent, PackageManager.ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong()))
} else {
legacyQueryIntentActivities(editIntent)
}

for (resolveInfo in resInfoList) {
val packageName = resolveInfo.activityInfo.packageName
context.grantUriPermission(packageName, editUri, flags)
}

editIntent
} catch (e: Exception) {
} catch (_: Exception) {
null
}
}

@Suppress("deprecation")
private fun legacyQueryIntentActivities(intent: Intent): MutableList<ResolveInfo> {
return context.packageManager
.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
Expand Down Expand Up @@ -861,10 +857,6 @@ class IonCameraFlow(
.getString(STORE, "")
fromPreferences.let { uri = Uri.parse(fromPreferences) }
}
if (activity == null) {
sendError(IONCAMRError.CAPTURE_VIDEO_ERROR)
return
}
val settings = videoParameters ?: run {
sendError(IONCAMRError.INVALID_ARGUMENT_ERROR)
return
Expand Down Expand Up @@ -1044,7 +1036,7 @@ class IonCameraFlow(
jsonResult.put("message", error.description)
currentCall?.reject(error.description, formatErrorCode(error.code))
currentCall = null
} catch (e: Exception) {
} catch (_: Exception) {
currentCall?.reject("There was an error performing the operation.")
currentCall = null
} finally {
Expand All @@ -1053,7 +1045,7 @@ class IonCameraFlow(
}

private fun formatErrorCode(code: Int): String {
val stringCode = Integer.toString(code)
val stringCode = code.toString()
return ERROR_FORMAT_PREFIX + "0000$stringCode".substring(stringCode.length)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object IonCameraUtils {
inputStream.use {
saveImage(context, uri, it)
}
} catch (e: Exception) {
} catch (_: Exception) {
null
}
}
Expand All @@ -38,7 +38,7 @@ object IonCameraUtils {
inputStream.copyTo(output)
}
Uri.fromFile(tempFile)
} catch (e: Exception) {
} catch (_: Exception) {
null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ enum class IonEditableMode(val value: String) {
companion object {
fun fromString(value: String?): IonEditableMode {
if (value == null) return NO
return values().find {
return entries.find {
it.value.equals(value, ignoreCase = true)
} ?: NO
}
Expand Down
Loading