Skip to content

Commit

Permalink
Merge pull request #49 from Dhaval2404/feature/v1.6
Browse files Browse the repository at this point in the history
v1.6 Release
  • Loading branch information
Dhaval2404 authored Jan 6, 2020
2 parents f5c60a3 + 4f08aef commit d4939eb
Show file tree
Hide file tree
Showing 56 changed files with 778 additions and 286 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.6] - 2020-01-06
### Changed
* Improved UI/UX of sample app
* Removed Bitmap Deprecated Property [#33](https://github.com/Dhaval2404/ImagePicker/issues/33) (Special Thanks to [nauhalf](https://github.com/nauhalf))
* Camera opens twice when "Don't keep activities" option is ON [#41](https://github.com/Dhaval2404/ImagePicker/issues/41) (Special Thanks to [benji101](https://github.com/benji101))
* Fixed uCrop Crash Issue [#42](https://github.com/Dhaval2404/ImagePicker/issues/42)

## [1.5] - 2019-10-14
### Added
* 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))
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
```

```groovy
implementation 'com.github.dhaval2404:imagepicker:1.5'
implementation 'com.github.dhaval2404:imagepicker:1.6'
```

**If you are yet to Migrate on AndroidX, Use support build artifact:**
Expand Down Expand Up @@ -225,6 +225,13 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
# ✔️Changelog
### Version: 1.6
* Improved UI/UX of sample app
* Removed Bitmap Deprecated Property [#33](https://github.com/Dhaval2404/ImagePicker/issues/33) (Special Thanks to [nauhalf](https://github.com/nauhalf))
* Camera opens twice when "Don't keep activities" option is ON [#41](https://github.com/Dhaval2404/ImagePicker/issues/41) (Special Thanks to [benji101](https://github.com/benji101))
* Fixed uCrop Crash Issue [#42](https://github.com/Dhaval2404/ImagePicker/issues/42)
### Version: 1.5
* Fixed app crash issue, due to Camera Permission in manifest [#34](https://github.com/Dhaval2404/ImagePicker/issues/34)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

//jcenter plugins
Expand Down
10 changes: 5 additions & 5 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 6
versionName "1.5"
versionCode 7
versionName "1.6"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -43,10 +43,10 @@ dependencies {

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

//More Info: https://github.com/Yalantis/uCrop
implementation 'com.github.yalantis:ucrop:2.2.2'
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'
Expand All @@ -69,7 +69,7 @@ ext {
siteUrl = 'https://github.com/Dhaval2404/ImagePicker/'
gitUrl = 'https://github.com/Dhaval2404/ImagePicker.git'

libraryVersion = '1.5'
libraryVersion = '1.6'
//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 @@ -17,4 +17,4 @@ class ExampleInstrumentedTest {

assertEquals("com.github.dhaval2404.imagepicker.test", appContext.packageName)
}
}
}
1 change: 0 additions & 1 deletion imagepicker/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />

<application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.FragmentActivity
import androidx.appcompat.app.AppCompatActivity
import com.github.dhaval2404.imagepicker.constant.ImageProvider
import com.github.dhaval2404.imagepicker.provider.CameraProvider
import com.github.dhaval2404.imagepicker.provider.CompressionProvider
Expand All @@ -21,11 +21,16 @@ import java.io.File
* @version 1.0
* @since 04 January 2019
*/
class ImagePickerActivity : FragmentActivity() {
class ImagePickerActivity : AppCompatActivity() {

companion object {
private const val TAG = "image_picker"

/**
* Key to Save/Retrieve Image File state
*/
private const val STATE_IMAGE_FILE = "state.image_file"

internal fun getCancelledIntent(context: Context): Intent {
val intent = Intent()
val message = context.getString(R.string.error_task_cancelled)
Expand All @@ -39,37 +44,68 @@ class ImagePickerActivity : FragmentActivity() {
private lateinit var mCropProvider: CropProvider
private lateinit var mCompressionProvider: CompressionProvider

private var mOriginalFile: File? = null
/** File provided by GalleryProvider or CameraProvider */
private var mImageFile: File? = null

/** File provided by CropProvider */
private var mCropFile: File? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
loadBundle()
restoreInstanceState(savedInstanceState)
loadBundle(savedInstanceState)
}

/**
* Restore saved state
*/
private fun restoreInstanceState(savedInstanceState: Bundle?) {
if (savedInstanceState != null) {
mImageFile = savedInstanceState.getSerializable(STATE_IMAGE_FILE) as File?
}
}

/**
* Save all appropriate activity state.
*/
public override fun onSaveInstanceState(outState: Bundle) {
outState.putSerializable(STATE_IMAGE_FILE, mImageFile)
mCameraProvider?.onSaveInstanceState(outState)
mCropProvider.onSaveInstanceState(outState)
super.onSaveInstanceState(outState)
}

/**
* Parse Intent Bundle and initialize variables
*/
private fun loadBundle() {
private fun loadBundle(savedInstanceState: Bundle?) {
// Create Crop Provider
mCropProvider = CropProvider(this)
mCropProvider.onRestoreInstanceState(savedInstanceState)

// Create Compression Provider
mCompressionProvider = CompressionProvider(this)

val bundle = intent?.extras
val provider = bundle?.getSerializable(ImagePicker.EXTRA_IMAGE_PROVIDER) as ImageProvider?
// Retrieve Image Provider
val provider: ImageProvider? =
intent?.getSerializableExtra(ImagePicker.EXTRA_IMAGE_PROVIDER) as ImageProvider?

// Create provider object and start process
// Create Gallery/Camera Provider
when (provider) {
ImageProvider.GALLERY -> {
mGalleryProvider = GalleryProvider(this)
mGalleryProvider?.startIntent()
// Pick Gallery Image
savedInstanceState ?: mGalleryProvider?.startIntent()
}
ImageProvider.CAMERA -> {
mCameraProvider = CameraProvider(this)
mCameraProvider?.startIntent()
mCameraProvider?.onRestoreInstanceState(savedInstanceState)
// Pick Camera Image
savedInstanceState ?: mCameraProvider?.startIntent()
}
else -> {
Log.e(TAG, "Image provider can not be null")
// Something went Wrong! This case should never happen
Log.e(TAG, "Image provider can not be null")
setError(getString(R.string.error_task_cancelled))
}
}
Expand Down Expand Up @@ -111,7 +147,7 @@ class ImagePickerActivity : FragmentActivity() {
* @param file Capture/Gallery image file
*/
fun setImage(file: File) {
mOriginalFile = file
mImageFile = file
when {
mCropProvider.isCropEnabled() -> mCropProvider.startIntent(file)
mCompressionProvider.isCompressionRequired(file) -> mCompressionProvider.compress(file)
Expand All @@ -132,8 +168,8 @@ class ImagePickerActivity : FragmentActivity() {
mCameraProvider?.let {
// Delete Camera file after crop. Else there will be two image for the same action.
// In case of Gallery Provider, we will get original image path, so we will not delete that.
mOriginalFile?.delete()
mOriginalFile = null
mImageFile?.delete()
mImageFile = null
}

if (mCompressionProvider.isCompressionRequired(file)) {
Expand All @@ -153,7 +189,7 @@ class ImagePickerActivity : FragmentActivity() {
mCameraProvider?.let {
// Delete Camera file after Compress. Else there will be two image for the same action.
// In case of Gallery Provider, we will get original image path, so we will not delete that.
mOriginalFile?.delete()
mImageFile?.delete()
}

// If crop file is not null, Delete it after crop
Expand Down Expand Up @@ -195,4 +231,4 @@ class ImagePickerActivity : FragmentActivity() {
setResult(ImagePicker.RESULT_ERROR, intent)
finish()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ enum class ImageProvider {
GALLERY,
CAMERA,
BOTH
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ package com.github.dhaval2404.imagepicker.listener
internal interface ResultListener<T> {

fun onResult(t: T?)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.dhaval2404.imagepicker.provider

import android.content.ContextWrapper
import android.os.Bundle
import android.widget.Toast
import com.github.dhaval2404.imagepicker.ImagePickerActivity

Expand Down Expand Up @@ -55,4 +56,19 @@ abstract class BaseProvider(protected val activity: ImagePickerActivity) : Conte
*/
protected open fun onFailure() {
}
}

/**
* Save all appropriate provider state.
*/
open fun onSaveInstanceState(outState: Bundle) {
}

/**
* Restores the saved state for all Providers.
*
* @param savedInstanceState the Bundle returned by {@link #onSaveInstanceState()}
* @see #onSaveInstanceState()
*/
open fun onRestoreInstanceState(savedInstanceState: Bundle?) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.Manifest
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.core.app.ActivityCompat.requestPermissions
import com.github.dhaval2404.imagepicker.ImagePickerActivity
import com.github.dhaval2404.imagepicker.R
Expand All @@ -23,6 +24,10 @@ import java.io.File
class CameraProvider(activity: ImagePickerActivity) : BaseProvider(activity) {

companion object {
/**
* Key to Save/Retrieve Camera File state
*/
private const val STATE_CAMERA_FILE = "state.camera_file"

/**
* Permission Require for Image Capture using Camera
Expand Down Expand Up @@ -54,6 +59,29 @@ class CameraProvider(activity: ImagePickerActivity) : BaseProvider(activity) {
private val mAskCameraPermission = PermissionUtil
.isPermissionInManifest(this, Manifest.permission.CAMERA)

/**
* Save CameraProvider state
* mCameraFile will lose its state when activity is recreated on
* Orientation change or for Low memory device.
*
* Here, We Will save its state for later use
*
* Note: To produce this scenario, enable "Don't keep activities" from developer options
**/
override fun onSaveInstanceState(outState: Bundle) {
// Save Camera File
outState.putSerializable(STATE_CAMERA_FILE, mCameraFile)
}

/**
* Retrieve CameraProvider state
*/
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
// Restore Camera File
mCameraFile = savedInstanceState?.getSerializable(STATE_CAMERA_FILE) as File?
}

/**
* Start Camera Capture Intent
*/
Expand Down Expand Up @@ -83,11 +111,12 @@ class CameraProvider(activity: ImagePickerActivity) : BaseProvider(activity) {
*/
private fun startCameraIntent() {
// Create and get empty file to store capture image content
mCameraFile = FileUtil.getImageFile()
val file = FileUtil.getImageFile()
mCameraFile = file

// Check if file exists
if (mCameraFile != null && mCameraFile!!.exists()) {
val cameraIntent = IntentUtils.getCameraIntent(this, mCameraFile!!)
if (file != null && file.exists()) {
val cameraIntent = IntentUtils.getCameraIntent(this, file)
activity.startActivityForResult(cameraIntent, CAMERA_INTENT_REQ_CODE)
} else {
setError(R.string.error_failed_to_create_camera_image_file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,4 @@ class CompressionProvider(activity: ImagePickerActivity) : BaseProvider(activity
BitmapFactory.decodeFile(file.absolutePath, options)
return intArrayOf(options.outWidth, options.outHeight)
}
}
}
Loading

0 comments on commit d4939eb

Please sign in to comment.