Skip to content

Commit 49f07ca

Browse files
authored
Merge pull request #200 from Dhaval2404/feature/v2.0
v2.0 Released
2 parents 371b84f + 2788406 commit 49f07ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1101
-670
lines changed

.github/workflows/ci-build-debug.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: build debug
1+
name: Build
22

33
on:
44
push:

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
/.idea/gradle.xml
1313
/.idea/runConfigurations.xml
1414
/.idea/codeStyles
15-
/.idea/compiler.xml
15+
/.idea/dictionaries
16+
/.idea/icon.png
1617
/.idea/jarRepositories.xml
18+
/.idea/compiler.xml
1719
.DS_Store
1820
/build
1921
/captures

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [2.0] - 2021-05-15
10+
### Added
11+
* Added arabic translation [#157](https://github.com/Dhaval2404/ImagePicker/pull/157) (Special Thanks to [zhangzhu95](https://github.com/zhangzhu95))
12+
* Added norwegian translation [#163](https://github.com/Dhaval2404/ImagePicker/pull/163) (Special Thanks to [TorkelV](https://github.com/TorkelV))
13+
* Added german translation [#192](https://github.com/Dhaval2404/ImagePicker/pull/192) (Special Thanks to [MDXDave](https://github.com/MDXDave))
14+
* Added method to return Intent for manual launching ImagePicker [#182](https://github.com/Dhaval2404/ImagePicker/pull/182) (Special Thanks to [tobiasKaminsky](https://github.com/tobiasKaminsky))
15+
* Added support for android 11 [#199](https://github.com/Dhaval2404/ImagePicker/issues/199)
16+
### Changed
17+
* Fixed Playstore requestLegacyExternalStorage flag issue [#199](https://github.com/Dhaval2404/ImagePicker/issues/199)
18+
* Fixed android scope storage issue [#29](https://github.com/Dhaval2404/ImagePicker/issues/29)
19+
* Removed storage permissions [#29](https://github.com/Dhaval2404/ImagePicker/issues/29)
20+
* Fixed calculateInSampleSize leads to overly degraded quality [#152](https://github.com/Dhaval2404/ImagePicker/issues/152) (Special Thanks to [FlorianDenis](https://github.com/FlorianDenis))
21+
* Fixed camera app not found issue [#162](https://github.com/Dhaval2404/ImagePicker/issues/162)
22+
923
## [1.8] - 2020-12-22
1024
### Added
1125
* Added dialog dismiss listener (Special Thanks to [kibotu](https://github.com/kibotu))
@@ -92,7 +106,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
92106
* Handle Runtime Permission for Camera and Storage
93107
* Retrieve Image Result as File, File Path as String or Uri object
94108

95-
[Unreleased]: https://github.com/Dhaval2404/ImagePicker/compare/v2.0...HEAD
109+
[Unreleased]: https://github.com/Dhaval2404/ImagePicker/compare/v2.1...HEAD
110+
[2.0]: https://github.com/Dhaval2404/ImagePicker/compare/v1.8...v2.0
96111
[1.8]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.5...v1.8
97112
[1.7.5]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.4...v1.7.5
98113
[1.7.4]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.3...v1.7.4

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2019-2021, Dhaval Patel
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 103 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# 📸Image Picker Library for Android
22

3-
[![Download](https://api.bintray.com/packages/dhaval2404/maven/imagepicker/images/download.svg) ](https://bintray.com/dhaval2404/maven/imagepicker/_latestVersion)
3+
[![Download](https://jitpack.io/v/Dhaval2404/ImagePicker.svg)](https://jitpack.io/#Dhaval2404/ImagePicker)
44
[![Releases](https://img.shields.io/github/release/dhaval2404/imagePicker/all.svg?style=flat-square)](https://github.com/Dhaval2404/ImagePicker/releases)
55
[![API](https://img.shields.io/badge/API-19%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=19)
6+
![Build Status](https://github.com/Dhaval2404/ImagePicker/workflows/build%20debug/badge.svg)
67
![Language](https://img.shields.io/badge/language-Kotlin-orange.svg)
78
[![Android Arsenal]( https://img.shields.io/badge/Android%20Arsenal-ImagePicker-green.svg?style=flat )]( https://android-arsenal.com/details/1/7510 )
9+
[![ktlint](https://img.shields.io/badge/code%20style-%E2%9D%A4-FF4081.svg)](https://ktlint.github.io/)
810
[![PRWelcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Dhaval2404/ImagePicker)
9-
[![Say Thanks!](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)](https://saythanks.io/to/Dhaval2404)
11+
[![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=102)](https://opensource.org/licenses/Apache-2.0)
12+
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/Dhaval2404/ImagePicker/blob/master/LICENSE)
1013
[![Twitter](https://img.shields.io/twitter/url/https/github.com/Dhaval2404/ImagePicker.svg?style=social)](https://twitter.com/intent/tweet?text=Check+out+an+ImagePicker+library+to+Pick+an+image+from+the+Gallery+or+Capture+an+image+with+Camera.+https%3A%2F%2Fgithub.com%2FDhaval2404%2FImagePicker+%40dhaval2404+%23Android+%23Kotlin+%23AndroidDev)
1114

1215
<div align="center">
@@ -29,8 +32,9 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
2932
* Capture Camera Image
3033
* Crop Image(Crop image based on provided aspect ratio or let user choose one)
3134
* Compress Image(Compress image based on provided resolution and size)
32-
* Retrieve Image Result as File, File Path as String or Uri object
33-
* Handle Runtime Permission for Camera and Storage
35+
* Retrieve Image Result as Uri object (Retrieve as File object feature is removed in v2.0 to support scope storage)
36+
* Handle runtime permission for camera
37+
* Does not require storage permission to pick gallery image or capture new image.
3438

3539
# 🎬Preview
3640

@@ -47,79 +51,56 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
4751
```groovy
4852
allprojects {
4953
repositories {
50-
jcenter()
5154
maven { url "https://jitpack.io" } //Make sure to add this in your project for uCrop
5255
}
5356
}
5457
```
5558

5659
```groovy
57-
implementation 'com.github.dhaval2404:imagepicker:1.8'
60+
implementation 'com.github.dhaval2404:imagepicker:2.0'
5861
```
59-
62+
6063
**If you are yet to Migrate on AndroidX, Use support build artifact:**
6164
```groovy
6265
implementation 'com.github.dhaval2404:imagepicker-support:1.7.1'
6366
```
6467
65-
**If you want to get the activity result inline in a modern way (lambda) install [InlineActivityResult](https://github.com/florent37/InlineActivityResult) library:**
66-
```groovy
67-
implementation 'com.github.florent37:inline-activity-result-kotlin:1.0.4'
68-
```
69-
70-
2. <span style="color:red">**If you target Android 10 or higher(targetSdkVersion >= 29)**</span>, set the value of ``requestLegacyExternalStorage`` to true in your app's manifest file:
7168
72-
```xml
73-
<manifest ... >
74-
<!-- This attribute is "false" by default on apps targeting
75-
Android 10 or higher. -->
76-
<application android:requestLegacyExternalStorage="true" ... >
77-
...
78-
</application>
79-
</manifest>
80-
```
81-
82-
3. The ImagePicker configuration is created using the builder pattern.
69+
2. The ImagePicker configuration is created using the builder pattern.
8370
8471
**Kotlin**
85-
72+
8673
```kotlin
8774
ImagePicker.with(this)
8875
.crop() //Crop image(Optional), Check Customization for more option
8976
.compress(1024) //Final image size will be less than 1 MB(Optional)
9077
.maxResultSize(1080, 1080) //Final image resolution will be less than 1080 x 1080(Optional)
9178
.start()
9279
```
93-
80+
9481
**Java**
95-
82+
9683
```kotlin
97-
ImagePicker.Companion.with(this)
84+
ImagePicker.with(this)
9885
.crop() //Crop image(Optional), Check Customization for more option
9986
.compress(1024) //Final image size will be less than 1 MB(Optional)
10087
.maxResultSize(1080, 1080) //Final image resolution will be less than 1080 x 1080(Optional)
10188
.start()
10289
```
103-
104-
4. Handling results
10590
106-
107-
**Default method(Preferred way)**<br>
108-
Override `onActivityResult` method and handle ImagePicker result.
91+
3. Handling results
92+
93+
**Override `onActivityResult` method and handle ImagePicker result.**
10994
11095
```kotlin
11196
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
11297
super.onActivityResult(requestCode, resultCode, data)
11398
if (resultCode == Activity.RESULT_OK) {
11499
//Image Uri will not be null for RESULT_OK
115-
val fileUri = data?.data
100+
val uri: Uri = data?.data!!
101+
102+
// Use Uri object instead of File to avoid storage permissions
116103
imgProfile.setImageURI(fileUri)
117-
118-
//You can get File object from intent
119-
val file:File = ImagePicker.getFile(data)!!
120-
121-
//You can also get File Path from intent
122-
val filePath:String = ImagePicker.getFilePath(data)!!
123104
} else if (resultCode == ImagePicker.RESULT_ERROR) {
124105
Toast.makeText(this, ImagePicker.getError(data), Toast.LENGTH_SHORT).show()
125106
} else {
@@ -128,31 +109,49 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
128109
}
129110
```
130111
131-
**Inline method (with InlineActivityResult library, Only Works with FragmentActivity and AppCompatActivity) (Not to be used with crop. See [#32](https://github.com/Dhaval2404/ImagePicker/issues/32))**
132-
112+
**Inline method (with registerForActivityResult, Only Works with FragmentActivity and AppCompatActivity)**
113+
114+
i. Add required dependency for registerForActivityResult API
115+
116+
```groovy
117+
implementation "androidx.activity:activity-ktx:1.2.3"
118+
implementation "androidx.fragment:fragment-ktx:1.3.3"
119+
```
120+
121+
ii. Declare this method inside fragment or activity class
122+
123+
```kotlin
124+
private val startForProfileImageResult =
125+
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
126+
val resultCode = result.resultCode
127+
val data = result.data
128+
129+
if (resultCode == Activity.RESULT_OK) {
130+
//Image Uri will not be null for RESULT_OK
131+
val fileUri = data?.data!!
132+
133+
mProfileUri = fileUri
134+
imgProfile.setImageURI(fileUri)
135+
} else if (resultCode == ImagePicker.RESULT_ERROR) {
136+
Toast.makeText(this, ImagePicker.getError(data), Toast.LENGTH_SHORT).show()
137+
} else {
138+
Toast.makeText(this, "Task Cancelled", Toast.LENGTH_SHORT).show()
139+
}
140+
}
141+
```
142+
143+
iii. Create ImagePicker instance and launch intent
144+
133145
```kotlin
134146
ImagePicker.with(this)
135147
.compress(1024) //Final image size will be less than 1 MB(Optional)
136148
.maxResultSize(1080, 1080) //Final image resolution will be less than 1080 x 1080(Optional)
137-
.start { resultCode, data ->
138-
if (resultCode == Activity.RESULT_OK) {
139-
//Image Uri will not be null for RESULT_OK
140-
val fileUri = data?.data
141-
imgProfile.setImageURI(fileUri)
142-
143-
//You can get File object from intent
144-
val file:File = ImagePicker.getFile(data)
145-
146-
//You can also get File Path from intent
147-
val filePath:String = ImagePicker.getFilePath(data)
148-
} else if (resultCode == ImagePicker.RESULT_ERROR) {
149-
Toast.makeText(context, ImagePicker.getError(data), Toast.LENGTH_SHORT).show()
150-
} else {
151-
Toast.makeText(context, "Task Cancelled", Toast.LENGTH_SHORT).show()
152-
}
149+
.createIntent { intent ->
150+
startForProfileImageResult.launch(intent)
153151
}
154152
```
155153
154+
156155
# 🎨Customization
157156
158157
* Pick image using Gallery
@@ -171,7 +170,7 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
171170
.start()
172171
```
173172
* Crop image
174-
173+
175174
```kotlin
176175
ImagePicker.with(this)
177176
.crop() //Crop image and let user choose aspect ratio.
@@ -225,14 +224,39 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
225224
.start()
226225
```
227226
228-
* Specify Directory to store captured, cropped or compressed images
227+
* Specify Directory to store captured, cropped or compressed images. *Do not use external public storage directory (i.e. Environment.getExternalStorageDirectory())*
229228
230229
```kotlin
231230
ImagePicker.with(this)
232-
//Provide directory path to save images
233-
.saveDir(File(Environment.getExternalStorageDirectory(), "ImagePicker"))
234-
// .saveDir(Environment.getExternalStorageDirectory())
235-
// .saveDir(getExternalFilesDir(null)!!)
231+
/// Provide directory path to save images, Added example saveDir method. You can choose directory as per your need.
232+
233+
// Path: /storage/sdcard0/Android/data/package/files
234+
.saveDir(getExternalFilesDir(null)!!)
235+
// Path: /storage/sdcard0/Android/data/package/files/DCIM
236+
.saveDir(getExternalFilesDir(Environment.DIRECTORY_DCIM)!!)
237+
// Path: /storage/sdcard0/Android/data/package/files/Download
238+
.saveDir(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)!!)
239+
// Path: /storage/sdcard0/Android/data/package/files/Pictures
240+
.saveDir(getExternalFilesDir(Environment.DIRECTORY_PICTURES)!!)
241+
// Path: /storage/sdcard0/Android/data/package/files/Pictures/ImagePicker
242+
.saveDir(File(getExternalFilesDir(Environment.DIRECTORY_PICTURES)!!, "ImagePicker"))
243+
// Path: /storage/sdcard0/Android/data/package/files/ImagePicker
244+
.saveDir(getExternalFilesDir("ImagePicker")!!)
245+
// Path: /storage/sdcard0/Android/data/package/cache/ImagePicker
246+
.saveDir(File(getExternalCacheDir(), "ImagePicker"))
247+
// Path: /data/data/package/cache/ImagePicker
248+
.saveDir(File(getCacheDir(), "ImagePicker"))
249+
// Path: /data/data/package/files/ImagePicker
250+
.saveDir(File(getFilesDir(), "ImagePicker"))
251+
252+
// Below saveDir path will not work, So do not use it
253+
// Path: /storage/sdcard0/DCIM
254+
// .saveDir(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM))
255+
// Path: /storage/sdcard0/Pictures
256+
// .saveDir(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES))
257+
// Path: /storage/sdcard0/ImagePicker
258+
// .saveDir(File(Environment.getExternalStorageDirectory(), "ImagePicker"))
259+
236260
.start()
237261
```
238262
@@ -276,6 +300,20 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
276300
277301
# ✔️Changelog
278302
303+
304+
### Version: 2.0
305+
306+
* Added arabic translation [#157](https://github.com/Dhaval2404/ImagePicker/pull/157) (Special Thanks to [zhangzhu95](https://github.com/zhangzhu95))
307+
* Added norwegian translation [#163](https://github.com/Dhaval2404/ImagePicker/pull/163) (Special Thanks to [TorkelV](https://github.com/TorkelV))
308+
* Added german translation [#192](https://github.com/Dhaval2404/ImagePicker/pull/192) (Special Thanks to [MDXDave](https://github.com/MDXDave))
309+
* Added method to return Intent for manual launching ImagePicker [#182](https://github.com/Dhaval2404/ImagePicker/pull/182) (Special Thanks to [tobiasKaminsky](https://github.com/tobiasKaminsky))
310+
* Added support for android 11 [#199](https://github.com/Dhaval2404/ImagePicker/issues/199)
311+
* Fixed android scope storage issue [#29](https://github.com/Dhaval2404/ImagePicker/issues/29)
312+
* Removed storage permissions [#29](https://github.com/Dhaval2404/ImagePicker/issues/29)
313+
* Fixed calculateInSampleSize leads to overly degraded quality [#152](https://github.com/Dhaval2404/ImagePicker/issues/152) (Special Thanks to [FlorianDenis](https://github.com/FlorianDenis))
314+
* Fixed camera app not found issue [#162](https://github.com/Dhaval2404/ImagePicker/issues/162)
315+
* Fixed Playstore requestLegacyExternalStorage flag issue [#199](https://github.com/Dhaval2404/ImagePicker/issues/199)
316+
279317
### Version: 1.8
280318
281319
* Added dialog dismiss listener (Special Thanks to [kibotu](https://github.com/kibotu))
@@ -339,15 +377,14 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
339377
## 📃 Libraries Used
340378
* uCrop [https://github.com/Yalantis/uCrop](https://github.com/Yalantis/uCrop)
341379
* Compressor [https://github.com/zetbaitsu/Compressor](https://github.com/zetbaitsu/Compressor)
342-
* InlineActivityResult [https://github.com/florent37/InlineActivityResult](https://github.com/florent37/InlineActivityResult)
343380
344381
### Let us know!
345382
346383
We'll be really happy if you sent us links to your projects where you use our component. Just send an email to **[email protected]** And do let us know if you have any questions or suggestion regarding the library.
347384
348385
## License
349386
350-
Copyright 2019-2020, Dhaval Patel
387+
Copyright 2019-2021, Dhaval Patel
351388
352389
Licensed under the Apache License, Version 2.0 (the "License");
353390
you may not use this file except in compliance with the License.

build.gradle

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.3.61'
4+
ext.kotlin_version = '1.4.0'
55
repositories {
66
google()
7-
jcenter()
87
maven { url "https://jitpack.io" }
8+
jcenter()
99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.6.1'
11+
classpath 'com.android.tools.build:gradle:4.2.0'
1212
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1313
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.15.0"
14-
15-
//jcenter plugins
16-
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
17-
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1814
}
1915
}
2016

@@ -23,8 +19,8 @@ allprojects {
2319

2420
repositories {
2521
google()
26-
jcenter()
2722
maven { url "https://jitpack.io" }
23+
jcenter()
2824
}
2925

3026
detekt {

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip

0 commit comments

Comments
 (0)