Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static fun java #111

Closed
wants to merge 4 commits into from
Closed
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [2.3.2] - 12/04/21
### Added
- @JvmStatic annotation in CropImage.activity() and fun activity(uri) [#108](https://github.com/CanHub/Android-Image-Cropper/issues/108)
- @JvmStatic annotation in all static function in CropImage [#108](https://github.com/CanHub/Android-Image-Cropper/issues/108)


## [2.3.1] - 01/04/21
### Changed
Expand Down
15 changes: 15 additions & 0 deletions cropper/src/main/java/com/canhub/cropper/CropImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ object CropImage {
* Create a new bitmap that has all pixels beyond the oval shape transparent. Old bitmap is
* recycled.
*/
@JvmStatic
fun toOvalBitmap(bitmap: Bitmap): Bitmap {
val width = bitmap.width
val height = bitmap.height
Expand All @@ -128,6 +129,7 @@ object CropImage {
*
* @param activity the activity to be used to start activity from
*/
@JvmStatic
fun startPickImageActivity(activity: Activity) {
activity.startActivityForResult(
getPickImageChooserIntent(activity), PICK_IMAGE_CHOOSER_REQUEST_CODE
Expand All @@ -141,6 +143,7 @@ object CropImage {
* @param context The Fragments context. Use getContext()
* @param fragment The calling Fragment to start and return the image to
*/
@JvmStatic
fun startPickImageActivity(context: Context, fragment: Fragment) {
fragment.startActivityForResult(
getPickImageChooserIntent(context), PICK_IMAGE_CHOOSER_REQUEST_CODE
Expand All @@ -156,6 +159,7 @@ object CropImage {
* @param context used to access Android APIs, like content resolve, it is your
* activity/fragment/widget.
*/
@JvmStatic
fun getPickImageChooserIntent(context: Context): Intent {
return getPickImageChooserIntent(
context = context,
Expand All @@ -176,6 +180,7 @@ object CropImage {
* @param includeDocuments if to include KitKat documents activity containing all sources
* @param includeCamera if to include camera intents
*/
@JvmStatic
fun getPickImageChooserIntent(
context: Context,
title: CharSequence?,
Expand Down Expand Up @@ -215,6 +220,7 @@ object CropImage {
* @param outputFileUri the Uri where the picture will be placed.
*/
// todo this need be public?
@JvmStatic
fun getCameraIntent(
context: Context,
outputFileUri: Uri?,
Expand All @@ -232,6 +238,7 @@ object CropImage {
* Get all Camera intents for capturing image using device camera apps.
*/
// todo this need be public?
@JvmStatic
fun getCameraIntents(
context: Context,
packageManager: PackageManager,
Expand All @@ -258,6 +265,7 @@ object CropImage {
* images.
*/
// todo this need be public?
@JvmStatic
fun getGalleryIntents(
packageManager: PackageManager,
action: String?,
Expand Down Expand Up @@ -304,6 +312,7 @@ object CropImage {
*/
// todo, if true, return error saying permission is needed.
// on settings give option to library asked permission (default true)
@JvmStatic
fun isExplicitCameraPermissionRequired(context: Context): Boolean = (
CommonVersionCheck.isAtLeastM23() &&
hasPermissionInManifest(context, "android.permission.CAMERA") &&
Expand All @@ -316,6 +325,7 @@ object CropImage {
* @param permissionName the permission to check
* @return true - the permission in requested in manifest, false - not.
*/
@JvmStatic
fun hasPermissionInManifest(
context: Context,
permissionName: String,
Expand All @@ -341,6 +351,7 @@ object CropImage {
* @param context used to access Android APIs, like content resolve, it is your
* activity/fragment/widget.
*/
@JvmStatic
fun getCaptureImageOutputUri(context: Context): Uri {
val outputFileUri: Uri
val getImage: File?
Expand Down Expand Up @@ -371,6 +382,7 @@ object CropImage {
* activity/fragment/widget.
* @param data the returned data of the activity result
*/
@JvmStatic
fun getPickImageResultUri(context: Context, data: Intent?): Uri {
var isCamera = true
if (data != null && data.data != null) {
Expand All @@ -392,6 +404,7 @@ object CropImage {
* @return true - required permission are not granted, false - either no need for permissions or
* they are granted
*/
@JvmStatic
fun isReadExternalStoragePermissionsRequired(
context: Context,
uri: Uri,
Expand All @@ -408,6 +421,7 @@ object CropImage {
* activity/fragment/widget.
* @param uri the result URI of image pick.
*/
@JvmStatic
fun isUriRequiresPermissions(context: Context, uri: Uri): Boolean {
return try {
val resolver = context.contentResolver
Expand Down Expand Up @@ -452,6 +466,7 @@ object CropImage {
* @return Crop Image Activity Result object or null if none exists
*/
// TODO don't return null
@JvmStatic
fun getActivityResult(data: Intent?): ActivityResult? =
data?.getParcelableExtra<Parcelable>(CROP_IMAGE_EXTRA_RESULT) as? ActivityResult?

Expand Down