11package com.canhub.cropper
22
3- import android.content.Context
4- import android.content.Intent
53import android.graphics.Bitmap
64import android.graphics.Canvas
75import android.graphics.Paint
@@ -10,16 +8,9 @@ import android.graphics.PorterDuffXfermode
108import android.graphics.Rect
119import android.graphics.RectF
1210import android.net.Uri
13- import android.os.Build.VERSION.SDK_INT
14- import android.os.Environment
1511import android.os.Parcel
1612import android.os.Parcelable
17- import android.provider.MediaStore
18- import androidx.core.content.FileProvider
1913import com.canhub.cropper.CropImageView.CropResult
20- import com.canhub.cropper.utils.authority
21- import com.canhub.cropper.utils.getFilePathFromUri
22- import java.io.File
2314
2415/* *
2516 * Helper to simplify crop image work like starting pick-image activity and handling camera/gallery
@@ -80,93 +71,6 @@ object CropImage {
8071 return output
8172 }
8273
83- /* *
84- * Get URI to image received from capture by camera.
85- *
86- * This is not the File Path, for it please use [getCaptureImageOutputUriFilePath]
87- *
88- * [context] used to access Android APIs, like content resolve, it is your activity/fragment/widget.
89- */
90- @Suppress(" DeprecatedCallableAddReplaceWith" , " DEPRECATION" )
91- @Deprecated(" This will become obsolete. There will be no replacement. In case you need this, please raise an issue and explain your use case." )
92- fun getCaptureImageOutputUriContent (context : Context ): Uri {
93- val outputFileUri: Uri
94- val getImage: File ?
95- // We have this because of a HUAWEI path bug when we use getUriForFile
96- if (SDK_INT >= 29 ) {
97- getImage = context.getExternalFilesDir(Environment .DIRECTORY_PICTURES )
98- outputFileUri = try {
99- FileProvider .getUriForFile(
100- context,
101- context.authority(),
102- File (getImage!! .path, " pickImageResult.jpeg" ),
103- )
104- } catch (e: Exception ) {
105- Uri .fromFile(File (getImage!! .path, " pickImageResult.jpeg" ))
106- }
107- } else {
108- getImage = context.externalCacheDir
109- outputFileUri = Uri .fromFile(File (getImage!! .path, " pickImageResult.jpeg" ))
110- }
111- return outputFileUri
112- }
113-
114- /* *
115- * Get File Path to image received from capture by camera.
116- *
117- * [context] used to access Android APIs, like content resolve, it is your activity/fragment/widget.
118- * [uniqueName] If true, make each image cropped have a different file name, this could cause
119- * memory issues, use wisely. [Default: false]
120- */
121- @Suppress(" DeprecatedCallableAddReplaceWith" , " DEPRECATION" )
122- @Deprecated(" This will become obsolete. There will be no replacement. In case you need this, please raise an issue and explain your use case." )
123- fun getCaptureImageOutputUriFilePath (context : Context , uniqueName : Boolean = false): String =
124- getFilePathFromUri(context, getCaptureImageOutputUriContent(context), uniqueName)
125-
126- /* *
127- * Get the URI of the selected image
128- * Will return the correct URI for camera and gallery image.
129- *
130- * This is not the File Path, for it please use [getPickImageResultUriFilePath]
131- *
132- * [context] used to access Android APIs, like content resolve, it is your activity/fragment/widget.
133- * [data] the returned data of the activity result
134- */
135- @JvmStatic
136- @Suppress(" DeprecatedCallableAddReplaceWith" , " DEPRECATION" )
137- @Deprecated(" This will become obsolete. There will be no replacement. In case you need this, please raise an issue and explain your use case." )
138- fun getPickImageResultUriContent (context : Context , data : Intent ? ): Uri {
139- var isCamera = true
140- val uri = data?.data
141- if (uri != null ) {
142- val action = data.action
143- isCamera = action != null && action == MediaStore .ACTION_IMAGE_CAPTURE
144- }
145- return if (isCamera || uri == null ) {
146- getCaptureImageOutputUriContent(context)
147- } else {
148- uri
149- }
150- }
151-
152- /* *
153- * Get the File Path of the selected image
154- *
155- * [context] used to access Android APIs, like content resolve, it is your activity/fragment/widget.
156- * [data] the returned data of the activity result
157- * [uniqueName] If true, make each image cropped have a different file name, this could cause
158- * memory issues, use wisely. [Default: false]
159- */
160- @JvmStatic
161- @Suppress(" DeprecatedCallableAddReplaceWith" , " DEPRECATION" )
162- @Deprecated(" This will become obsolete. There will be no replacement. In case you need this, please raise an issue and explain your use case." )
163- fun getPickImageResultUriFilePath (
164- context : Context ,
165- data : Intent ? ,
166- uniqueName : Boolean = false,
167- ): String =
168- getFilePathFromUri(context, getPickImageResultUriContent(context, data), uniqueName)
169-
17074 /* *
17175 * Result data of Crop Image Activity.
17276 */
0 commit comments