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.8 Released #142

Merged
merged 26 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
326cead
Set translatable false
Dhaval2404 Dec 18, 2020
2901c7d
Copy exif data on compression
Dhaval2404 Dec 18, 2020
9e0054d
Upgraded uCrop
Dhaval2404 Dec 18, 2020
6df15ed
Added check for camera intent
Dhaval2404 Dec 18, 2020
9749db3
Fixed KotlinNullPointerException
Dhaval2404 Dec 18, 2020
d576b34
Merge pull request #140 from Dhaval2404/master
Dhaval2404 Dec 19, 2020
1aeb1ad
Added RTL support
Dhaval2404 Dec 19, 2020
093b415
Added missing uCrop string resource
Dhaval2404 Dec 19, 2020
dc9659b
Fixed string resources
Dhaval2404 Dec 19, 2020
eac8256
Fixed grammer
Dhaval2404 Dec 19, 2020
1de8b03
Added dialog dissmiss event listener
Dhaval2404 Dec 19, 2020
6310603
Added hindi text translations
Dhaval2404 Dec 19, 2020
e864ce4
Added gujarati text translations
Dhaval2404 Dec 19, 2020
1fb6cc9
Added spanish text translations
Dhaval2404 Dec 20, 2020
9144e03
Fixed saving image in cache issue
Dhaval2404 Dec 21, 2020
85649c2
Code optimization
Dhaval2404 Dec 21, 2020
cf55b94
applied ktlint
Dhaval2404 Dec 21, 2020
0fc5ddb
Skip image rotate
Dhaval2404 Dec 21, 2020
e204d42
Update ucrop widget background color
Dhaval2404 Dec 21, 2020
9bbaaff
Fixed kitkat vector image issue
Dhaval2404 Dec 21, 2020
016d066
Added dismiss listener example
Dhaval2404 Dec 21, 2020
824cf83
Update saveDir example
Dhaval2404 Dec 21, 2020
d3a7f1a
Fixed issue selecting images from download folder
Dhaval2404 Dec 21, 2020
0668d14
Fixed Copyright
Dhaval2404 Dec 21, 2020
b978693
applied ktlint
Dhaval2404 Dec 21, 2020
63efbe4
v1.8 Released
Dhaval2404 Dec 22, 2020
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.8] - 2020-12-22
### Added
* Added dialog dismiss listener (Special Thanks to [kibotu](https://github.com/kibotu))
* Added text localization (Special Thanks to [yamin8000](https://github.com/yamin8000) and Jose Bravo)
### Changed
* Fixed crash issue on missing camera app [#69](https://github.com/Dhaval2404/ImagePicker/issues/69)
* Fixed issue selecting images from download folder [#86](https://github.com/Dhaval2404/ImagePicker/issues/86)
* Fixed exif information lost issue [#121](https://github.com/Dhaval2404/ImagePicker/issues/121)
* Fixed crash issue on large image crop [#122](https://github.com/Dhaval2404/ImagePicker/issues/122)
* Fixed saving image in cache issue [#127](https://github.com/Dhaval2404/ImagePicker/issues/127)

## [1.7.5] - 2020-08-30
### Changed
* Added Polish text translation [#115](https://github.com/Dhaval2404/ImagePicker/issues/115) (Special Thanks to [MarcelKijanka](https://github.com/MarcelKijanka))
Expand Down Expand Up @@ -81,6 +93,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Retrieve Image Result as File, File Path as String or Uri object

[Unreleased]: https://github.com/Dhaval2404/ImagePicker/compare/v2.0...HEAD
[1.8]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.5...v1.8
[1.7.5]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.4...v1.7.5
[1.7.4]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.3...v1.7.4
[1.7.3]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.2...v1.7.3
Expand Down
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
* Capture Camera Image
* Crop Image(Crop image based on provided aspect ratio or let user choose one)
* Compress Image(Compress image based on provided resolution and size)
* Retrive Image Result as File, File Path as String or Uri object
* Retrieve Image Result as File, File Path as String or Uri object
* Handle Runtime Permission for Camera and Storage

# 🎬Preview
Expand All @@ -54,7 +54,7 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
```

```groovy
implementation 'com.github.dhaval2404:imagepicker:1.7.5'
implementation 'com.github.dhaval2404:imagepicker:1.8'
```

**If you are yet to Migrate on AndroidX, Use support build artifact:**
Expand Down Expand Up @@ -214,6 +214,16 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
}
.start()
```
* Intercept Dialog dismiss event

```kotlin
ImagePicker.with(this)
.setDismissListener {
// Handle dismiss event
Log.d("ImagePicker", "onDismiss");
}
.start()
```

* Specify Directory to store captured, cropped or compressed images

Expand Down Expand Up @@ -266,6 +276,16 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w

# ✔️Changelog

### Version: 1.8

* Added dialog dismiss listener (Special Thanks to [kibotu](https://github.com/kibotu))
* Added text localization (Special Thanks to [yamin8000](https://github.com/yamin8000) and Jose Bravo)
* Fixed crash issue on missing camera app [#69](https://github.com/Dhaval2404/ImagePicker/issues/69)
* Fixed issue selecting images from download folder [#86](https://github.com/Dhaval2404/ImagePicker/issues/86)
* Fixed exif information lost issue [#121](https://github.com/Dhaval2404/ImagePicker/issues/121)
* Fixed crash issue on large image crop [#122](https://github.com/Dhaval2404/ImagePicker/issues/122)
* Fixed saving image in cache issue [#127](https://github.com/Dhaval2404/ImagePicker/issues/127)

### Version: 1.7

* Added option to limit MIME types while choosing a gallery image (Special Thanks to [Marchuck](https://github.com/Marchuck))
Expand Down Expand Up @@ -327,7 +347,7 @@ We'll be really happy if you sent us links to your projects where you use our co

## License

Copyright 2019, The Android Open Source Project
Copyright 2019-2020, Dhaval Patel

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
8 changes: 4 additions & 4 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 13
versionName "1.7.5"
versionCode 14
versionName "1.8"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -49,7 +49,7 @@ dependencies {
implementation "androidx.exifinterface:exifinterface:1.1.0"

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

//More Info: https://github.com/florent37/InlineActivityResult
compileOnly 'com.github.florent37:inline-activity-result-kotlin:1.0.4'
Expand All @@ -72,7 +72,7 @@ ext {
siteUrl = 'https://github.com/Dhaval2404/ImagePicker/'
gitUrl = 'https://github.com/Dhaval2404/ImagePicker.git'

libraryVersion = '1.7.5'
libraryVersion = '1.8'
//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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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.listener.DismissListener
import com.github.dhaval2404.imagepicker.listener.ResultListener
import com.github.dhaval2404.imagepicker.util.DialogHelper
import com.github.florent37.inlineactivityresult.kotlin.startForResult
Expand All @@ -27,6 +28,8 @@ open class ImagePicker {
const val RESULT_ERROR = 64

internal const val EXTRA_IMAGE_PROVIDER = "extra.image_provider"
internal const val EXTRA_CAMERA_DEVICE = "extra.camera_device"

internal const val EXTRA_IMAGE_MAX_SIZE = "extra.image_max_size"
internal const val EXTRA_CROP = "extra.crop"
internal const val EXTRA_CROP_X = "extra.crop_x"
Expand Down Expand Up @@ -118,6 +121,11 @@ open class ImagePicker {

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

/**
* Dialog dismiss event listener
*/
private var dismissListener: DismissListener? = null

/**
* File Directory
*
Expand Down Expand Up @@ -249,6 +257,26 @@ open class ImagePicker {
return this
}

/**
* Sets the callback that will be called when the dialog is dismissed for any reason.
*/
fun setDismissListener(listener: DismissListener): Builder {
this.dismissListener = listener
return this
}

/**
* Sets the callback that will be called when the dialog is dismissed for any reason.
*/
fun setDismissListener(listener: (() -> Unit)): Builder {
this.dismissListener = object : DismissListener {
override fun onDismiss() {
listener.invoke()
}
}
return this
}

/**
* Start Image Picker Activity
*/
Expand Down Expand Up @@ -292,7 +320,7 @@ open class ImagePicker {
startActivity(reqCode)
}
}
})
}, dismissListener)
}

/**
Expand All @@ -310,7 +338,7 @@ open class ImagePicker {
completionHandler?.invoke(Activity.RESULT_CANCELED, intent)
}
}
})
}, dismissListener)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.dhaval2404.imagepicker.listener

/**
* Interface used to allow the creator of a dialog to run some code when the
* dialog is dismissed.
*
* @author Dhaval Patel
* @version 1.8
* @since 19 December 2020
*/
interface DismissListener {

/**
* This method will be invoked when the dialog is dismissed.
*/
fun onDismiss()
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CameraProvider(activity: ImagePickerActivity) : BaseProvider(activity) {
private var mFileDir: File? = null

init {
val bundle = activity.intent.extras!!
val bundle = activity.intent.extras ?: Bundle()

// Get File Directory
val fileDir = bundle.getString(ImagePicker.EXTRA_SAVE_DIRECTORY)
Expand Down Expand Up @@ -102,6 +102,11 @@ class CameraProvider(activity: ImagePickerActivity) : BaseProvider(activity) {
* Start Camera Capture Intent
*/
fun startIntent() {
if (!IntentUtils.isCameraAppAvailable(this)) {
setError(R.string.error_camera_app_not_found)
return
}

checkPermission()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import android.annotation.SuppressLint
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.AsyncTask
import android.os.Bundle
import com.github.dhaval2404.imagepicker.ImagePicker
import com.github.dhaval2404.imagepicker.ImagePickerActivity
import com.github.dhaval2404.imagepicker.util.ExifDataCopier
import com.github.dhaval2404.imagepicker.util.FileUriUtils
import com.github.dhaval2404.imagepicker.util.FileUtil
import com.github.dhaval2404.imagepicker.util.ImageUtil
Expand All @@ -32,7 +34,7 @@ class CompressionProvider(activity: ImagePickerActivity) : BaseProvider(activity
private var mFileDir: File? = null

init {
val bundle = activity.intent.extras!!
val bundle = activity.intent.extras ?: Bundle()

// Get Max Width/Height parameter from Intent
mMaxWidth = bundle.getInt(ImagePicker.EXTRA_MAX_WIDTH, 0)
Expand Down Expand Up @@ -143,6 +145,9 @@ class CompressionProvider(activity: ImagePickerActivity) : BaseProvider(activity
}
} while (isCompressionRequired(newFile!!))

// Copy Exif Data
ExifDataCopier.copyExif(file, newFile)

return newFile
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CropProvider(activity: ImagePickerActivity) : BaseProvider(activity) {
private var mFileDir: File? = null

init {
val bundle = activity.intent.extras!!
val bundle = activity.intent.extras ?: Bundle()

// Get Max Width/Height parameter from Intent
mMaxWidth = bundle.getInt(ImagePicker.EXTRA_MAX_WIDTH, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.dhaval2404.imagepicker.provider
import android.Manifest
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import androidx.core.app.ActivityCompat.requestPermissions
import com.github.dhaval2404.imagepicker.ImagePicker
import com.github.dhaval2404.imagepicker.ImagePickerActivity
Expand Down Expand Up @@ -38,7 +39,7 @@ class GalleryProvider(activity: ImagePickerActivity) :
private val mimeTypes: Array<String>

init {
val bundle = activity.intent.extras!!
val bundle = activity.intent.extras ?: Bundle()

mimeTypes = bundle.getStringArray(ImagePicker.EXTRA_MIME_TYPES) ?: emptyArray()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.LayoutInflater
import androidx.appcompat.app.AlertDialog
import com.github.dhaval2404.imagepicker.R
import com.github.dhaval2404.imagepicker.constant.ImageProvider
import com.github.dhaval2404.imagepicker.listener.DismissListener
import com.github.dhaval2404.imagepicker.listener.ResultListener
import kotlinx.android.synthetic.main.dialog_choose_app.view.*

Expand All @@ -21,7 +22,11 @@ internal object DialogHelper {
* Show Image Provide Picker Dialog. This will streamline the code to pick/capture image
*
*/
fun showChooseAppDialog(context: Context, listener: ResultListener<ImageProvider>) {
fun showChooseAppDialog(
context: Context,
listener: ResultListener<ImageProvider>,
dismissListener: DismissListener?
) {
val layoutInflater = LayoutInflater.from(context)
val customView = layoutInflater.inflate(R.layout.dialog_choose_app, null)

Expand All @@ -34,6 +39,9 @@ internal object DialogHelper {
.setNegativeButton(R.string.action_cancel) { _, _ ->
listener.onResult(null)
}
.setOnDismissListener {
dismissListener?.onDismiss()
}
.show()

// Handle Camera option click
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.github.dhaval2404.imagepicker.util

import android.util.Log
import androidx.exifinterface.media.ExifInterface
import java.io.File

/**
* This file was taken from
* https://raw.githubusercontent.com/flutter/plugins/05879a3a4d8e582702227731ccdcf8b115f6b83d/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ExifDataCopier.java
*/
object ExifDataCopier {

fun copyExif(filePathOri: File, filePathDest: File) {
try {
val oldExif = ExifInterface(filePathOri)
val newExif = ExifInterface(filePathDest)
val attributes: List<String> = listOf(
"FNumber",
"ExposureTime",
"ISOSpeedRatings",
"GPSAltitude",
"GPSAltitudeRef",
"FocalLength",
"GPSDateStamp",
"WhiteBalance",
"GPSProcessingMethod",
"GPSTimeStamp",
"DateTime",
"Flash",
"GPSLatitude",
"GPSLatitudeRef",
"GPSLongitude",
"GPSLongitudeRef",
"Make",
"Model",
"Orientation"
)
for (attribute in attributes) {
setIfNotNull(oldExif, newExif, attribute)
}
newExif.saveAttributes()
} catch (ex: Exception) {
Log.e("ExifDataCopier", "Error preserving Exif data on selected image: $ex")
}
}

private fun setIfNotNull(oldExif: ExifInterface, newExif: ExifInterface, property: String) {
if (oldExif.getAttribute(property) != null) {
newExif.setAttribute(property, oldExif.getAttribute(property))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@ object FileUriUtils {
} else if (isDownloadsDocument(uri)) {
val fileName = getFilePath(context, uri)
if (fileName != null) {
return Environment.getExternalStorageDirectory().toString() + "/Download/" + fileName
val path = Environment.getExternalStorageDirectory().toString() + "/Download/" + fileName
if (File(path).exists()) {
return path
}
}

val id = DocumentsContract.getDocumentId(uri)
var id = DocumentsContract.getDocumentId(uri)
if (id.contains(":")) {
id = id.split(":")[1]
}
val contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), java.lang.Long.valueOf(id)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,4 @@ object FileUtil {
else -> Bitmap.CompressFormat.JPEG
}
}

}
Loading