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

v1.7 Release #65

Merged
merged 15 commits into from
Mar 25, 2020
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
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.7] - 2020-03-23
### Changed
* Added option to limit MIME types while choosing a gallery image (Special Thanks to [Marchuck](https://github.com/Marchuck))
* Introduced ImageProviderInterceptor, Can be used for analytics (Special Thanks to [Marchuck](https://github.com/Marchuck))
* Fixed FileProvider of the library clashes with the FileProvider of the app [#51](https://github.com/Dhaval2404/ImagePicker/issues/51) (Special Thanks to [OyaCanli](https://github.com/OyaCanli))
* Added option to set Storage Directory [#52](https://github.com/Dhaval2404/ImagePicker/issues/52)
* Fixed NullPointerException in FileUriUtils.getPathFromRemoteUri() [#61](https://github.com/Dhaval2404/ImagePicker/issues/61) (Special Thanks to [himphen](https://github.com/himphen))

## [1.6] - 2020-01-06
### Changed
* Improved UI/UX of sample app
Expand Down Expand Up @@ -51,7 +59,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Handle Runtime Permission for Camera and Storage
* Retrive Image Result as File, File Path as String or Uri object

[Unreleased]: https://github.com/Dhaval2404/ImagePicker/compare/v1.6...HEAD
[Unreleased]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7...HEAD
[1.7]: https://github.com/Dhaval2404/ImagePicker/compare/v1.6...v1.7
[1.6]: https://github.com/Dhaval2404/ImagePicker/compare/v1.5...v1.6
[1.5]: https://github.com/Dhaval2404/ImagePicker/compare/v1.4...v1.5
[1.4]: https://github.com/Dhaval2404/ImagePicker/compare/v1.3...v1.4
Expand Down
81 changes: 61 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,62 +176,104 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
ImagePicker.with(this)
.crop() //Crop image and let user choose aspect ratio.
.start()

```
* Crop image with fixed Aspect Ratio

```kotlin
ImagePicker.with(this)
.crop(16f, 9f) //Crop image with 16:9 aspect ratio
.start()

```
```
* Crop square image(e.g for profile)

```kotlin
ImagePicker.with(this)
.cropSquare() //Crop square image, its same as crop(1f, 1f)
.start()
.cropSquare() //Crop square image, its same as crop(1f, 1f)
.start()
```
* Compress image size(e.g image should be maximum 1 MB)

```kotlin
ImagePicker.with(this)
.compress(1024) //Final image size will be less than 1 MB
.start()
```
* Set Resize image resolution

```kotlin
ImagePicker.with(this)
.maxResultSize(620, 620) //Final image resolution will be less than 620 x 620
.maxResultSize(620, 620) //Final image resolution will be less than 620 x 620
.start()
```
* Intercept ImageProvider, Can be used for analytics

```kotlin
ImagePicker.with(this)
.setImageProviderInterceptor { imageProvider -> //Intercept ImageProvider
Log.d("ImagePicker", "Selected ImageProvider: "+imageProvider.name)
}
.start()
```

* Specify Directory to store captured, cropped or compressed images

```kotlin
ImagePicker.with(this)
//Provide directory path to save images
.saveDir(File(Environment.getExternalStorageDirectory(), "ImagePicker"))
// .saveDir(Environment.getExternalStorageDirectory())
// .saveDir(getExternalFilesDir(null)!!)
.start()
```

* Limit MIME types while choosing a gallery image

```kotlin
ImagePicker.with(this)
.galleryMimeTypes( //Exclude gif images
mimeTypes = arrayOf(
"image/png",
"image/jpg",
"image/jpeg"
)
)
.start()
```

* You can also specify the request code with ImagePicker

```kotlin
ImagePicker.with(this)
.maxResultSize(620, 620)
.maxResultSize(620, 620)
.start(101) //Here 101 is request code, you may use this in onActivityResult
```
```

* Add Following parameters in your **colors.xml** file, If you want to customize uCrop Activity.

```xml
<resources>
<!-- Here you can add color of your choice -->
<color name="ucrop_color_toolbar">@color/teal_500</color>
<color name="ucrop_color_statusbar">@color/teal_700</color>
<color name="ucrop_color_widget_active">@color/teal_500</color>
</resources>
</resources>
```

# 💥Compatibility

* Library - Android Kitkat 4.4+ (API 19)
* Sample - Android Kitkat 4.4+ (API 19)

# ✔️Changelog

### Version: 1.7

* Added option to limit MIME types while choosing a gallery image (Special Thanks to [Marchuck](https://github.com/Marchuck))
* Introduced ImageProviderInterceptor, Can be used for analytics (Special Thanks to [Marchuck](https://github.com/Marchuck))
* Fixed FileProvider of the library clashes with the FileProvider of the app [#51](https://github.com/Dhaval2404/ImagePicker/issues/51) (Special Thanks to [OyaCanli](https://github.com/OyaCanli))
* Added option to set Storage Directory [#52](https://github.com/Dhaval2404/ImagePicker/issues/52)
* Fixed NullPointerException in FileUriUtils.getPathFromRemoteUri() [#61](https://github.com/Dhaval2404/ImagePicker/issues/61) (Special Thanks to [himphen](https://github.com/himphen))

### Version: 1.6

* Improved UI/UX of sample app
Expand All @@ -244,7 +286,6 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
* Fixed app crash issue, due to Camera Permission in manifest [#34](https://github.com/Dhaval2404/ImagePicker/issues/34)
* Added Option for Dynamic Crop Ratio. Let User choose aspect ratio [#36](https://github.com/Dhaval2404/ImagePicker/issues/36) (Special Thanks to [Dor-Sloim](https://github.com/Dor-Sloim))


### Version: 1.4

* Optimized Uri to File Conversion (Inspired by [Flutter ImagePicker](https://github.com/flutter/plugins/tree/master/packages/image_picker))
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.41'
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:3.6.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

//jcenter plugins
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip
12 changes: 6 additions & 6 deletions imagepicker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 7
versionName "1.6"
versionCode 8
versionName "1.7"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -44,17 +44,17 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "androidx.exifinterface:exifinterface:1.1.0"

//More Info: https://github.com/Yalantis/uCrop
implementation 'com.github.yalantis:ucrop:2.2.4'

//More Info: https://github.com/florent37/InlineActivityResult
compileOnly 'com.github.florent37:inline-activity-result-kotlin:1.0.1'
compileOnly 'com.github.florent37:inline-activity-result-kotlin:1.0.3'

testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:core:1.2.0'
}
Expand All @@ -72,7 +72,7 @@ ext {
siteUrl = 'https://github.com/Dhaval2404/ImagePicker/'
gitUrl = 'https://github.com/Dhaval2404/ImagePicker.git'

libraryVersion = '1.6'
libraryVersion = '1.7'
//If you are uploading new library try : gradlew install
//If you are updating existing library then execute: gradlew bintrayUpload
//In both the case don't forgot to put bintray credentials in local.properties file.
Expand Down
4 changes: 2 additions & 2 deletions imagepicker/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:name="com.github.dhaval2404.imagepicker.ImagePickerFileProvider"
android:authorities="@string/image_picker_provider_authority"
android:exported="false"
android:grantUriPermissions="true">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.github.dhaval2404.imagepicker.constant.ImageProvider
import com.github.dhaval2404.imagepicker.constant.ImageProvider.BOTH
import com.github.dhaval2404.imagepicker.constant.ImageProvider.CAMERA
import com.github.dhaval2404.imagepicker.constant.ImageProvider.GALLERY
import com.github.dhaval2404.imagepicker.listener.ResultListener
import com.github.dhaval2404.imagepicker.util.DialogHelper
import com.github.florent37.inlineactivityresult.kotlin.startForResult
Expand All @@ -36,10 +33,11 @@ open class ImagePicker {
internal const val EXTRA_CROP_Y = "extra.crop_y"
internal const val EXTRA_MAX_WIDTH = "extra.max_width"
internal const val EXTRA_MAX_HEIGHT = "extra.max_height"
internal const val EXTRA_SAVE_DIRECTORY = "extra.save_directory"

internal const val EXTRA_ERROR = "extra.error"
internal const val EXTRA_FILE_PATH = "extra.file_path"
internal const val EXTRA_GALLERY_MIME_TYPES = "extra.gallery.mime.types"
internal const val EXTRA_MIME_TYPES = "extra.mime_types"

/**
* Use this to use ImagePicker in Activity Class
Expand Down Expand Up @@ -95,9 +93,9 @@ open class ImagePicker {
private var fragment: Fragment? = null

// Image Provider
private var imageProvider = BOTH
private var imageProvider = ImageProvider.BOTH

//mime types restrictions for gallery. by default all mime types are valid
// Mime types restrictions for gallery. by default all mime types are valid
private var mimeTypes: Array<String> = emptyArray()

/*
Expand All @@ -120,6 +118,15 @@ open class ImagePicker {

private var imageProviderInterceptor: ((ImageProvider) -> Unit)? = null

/**
* File Directory
*
* Camera, Crop, Compress Image Will be store in this directory.
*
* If null, Image will be stored in {@see [Environment.DIRECTORY_DCIM]}
*/
private var saveDir: String? = null

/**
* Call this while picking image for fragment.
*/
Expand All @@ -140,7 +147,7 @@ open class ImagePicker {
*/
// @Deprecated("Please use provider(ImageProvider.CAMERA) instead")
fun cameraOnly(): Builder {
this.imageProvider = CAMERA
this.imageProvider = ImageProvider.CAMERA
return this
}

Expand All @@ -149,12 +156,12 @@ open class ImagePicker {
*/
// @Deprecated("Please use provider(ImageProvider.GALLERY) instead")
fun galleryOnly(): Builder {
this.imageProvider = GALLERY
this.imageProvider = ImageProvider.GALLERY
return this
}

/**
* restrict mime types during gallery fetching, for instance if you do not want GIF images,
* Restrict mime types during gallery fetching, for instance if you do not want GIF images,
* you can use arrayOf("image/png","image/jpeg","image/jpg")
* by default array is empty, which indicates no additional restrictions, just images
* @param mimeTypes
Expand Down Expand Up @@ -212,8 +219,33 @@ open class ImagePicker {
return this
}

fun setImageProviderInterceptor(imageProviderInterceptor: (ImageProvider) -> Unit): Builder {
this.imageProviderInterceptor = imageProviderInterceptor
/**
* Provide Directory to store Captured/Modified images
*
* @param path Folder Directory
*/
fun saveDir(path: String): Builder {
this.saveDir = path
return this
}

/**
* Provide Directory to store Captured/Modified images
*
* @param file Folder Directory
*/
fun saveDir(file: File): Builder {
this.saveDir = file.absolutePath
return this
}

/**
* Intercept Selected ImageProvider, Useful for Analytics
*
* @param interceptor ImageProvider Interceptor
*/
fun setImageProviderInterceptor(interceptor: (ImageProvider) -> Unit): Builder {
this.imageProviderInterceptor = interceptor
return this
}

Expand All @@ -228,7 +260,7 @@ open class ImagePicker {
* Start Image Picker Activity
*/
fun start(reqCode: Int) {
if (imageProvider == BOTH) {
if (imageProvider == ImageProvider.BOTH) {
// Pick Image Provider if not specified
showImageProviderDialog(reqCode)
} else {
Expand All @@ -240,7 +272,7 @@ open class ImagePicker {
* Start Image Picker Activity
*/
fun start(completionHandler: ((resultCode: Int, data: Intent?) -> Unit)? = null) {
if (imageProvider == BOTH) {
if (imageProvider == ImageProvider.BOTH) {
// Pick Image Provider if not specified
showImageProviderDialog(completionHandler)
} else {
Expand Down Expand Up @@ -287,18 +319,18 @@ open class ImagePicker {
private fun getBundle(): Bundle {
return Bundle().apply {
putSerializable(EXTRA_IMAGE_PROVIDER, imageProvider)

putStringArray(EXTRA_GALLERY_MIME_TYPES, mimeTypes)
putStringArray(EXTRA_MIME_TYPES, mimeTypes)

putBoolean(EXTRA_CROP, crop)

putFloat(EXTRA_CROP_X, cropX)
putFloat(EXTRA_CROP_Y, cropY)

putInt(EXTRA_MAX_WIDTH, maxWidth)
putInt(EXTRA_MAX_HEIGHT, maxHeight)

putLong(EXTRA_IMAGE_MAX_SIZE, maxSize)

putString(EXTRA_SAVE_DIRECTORY, saveDir)
}
}

Expand Down Expand Up @@ -326,12 +358,8 @@ open class ImagePicker {
}
} catch (e: Exception) {
if (e is ClassNotFoundException) {
Toast.makeText(
if (fragment != null) fragment!!.context else activity,
"InlineActivityResult library not installed falling back to default method, please install " +
"it from https://github.com/florent37/InlineActivityResult if you want to get inline activity results.",
Toast.LENGTH_LONG
).show()
Toast.makeText(if (fragment != null) fragment!!.context else activity, "InlineActivityResult library not installed falling back to default method, please install " +
"it from https://github.com/florent37/InlineActivityResult if you want to get inline activity results.", Toast.LENGTH_LONG).show()
startActivity(REQUEST_CODE)
}
}
Expand Down
Loading