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

Bugfix/427 back button doesnt work when activity launched #429

3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added the option to set custom color to toolbar of CropImageActivity [#421](https://github.com/CanHub/Android-Image-Cropper/issues/421)
- Added the option to set custom background color to activity of CropImageActivity [#421](https://github.com/CanHub/Android-Image-Cropper/issues/421)
- Fixed accidentally swiping back on newer Android devices when trying to resize the crop window [#423](https://github.com/CanHub/Android-Image-Cropper/issues/423)
- Fixed an issue on sample project where back button would not work when dialog is shown [#427](https://github.com/CanHub/Android-Image-Cropper/issues/427)
- Fixed an issue on sample project where cancelling/going back would go to a screen with empty image [#427](https://github.com/CanHub/Android-Image-Cropper/issues/427)

## [4.3.1] - 20/07/2022
### Fix
Expand Down Expand Up @@ -231,4 +233,3 @@ Versions `2.0.1` and `2.0.2` are similar, issues with jitpack.

## [1.0.0] - 21/11/20
- Copy from previous repo [ArthurHub](https://github.com/ArthurHub/Android-Image-Cropper/)
-
7 changes: 7 additions & 0 deletions cropper/src/main/java/com/canhub/cropper/CropImageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
import androidx.activity.result.contract.ActivityResultContracts
Expand Down Expand Up @@ -158,6 +159,12 @@ open class CropImageActivity :
open fun showImageSourceDialog(openSource: (Source) -> Unit) {
AlertDialog.Builder(this)
.setCancelable(false)
.setOnKeyListener { _, keyCode, keyEvent ->
if (keyCode == KeyEvent.KEYCODE_BACK && keyEvent.action == KeyEvent.ACTION_UP) {
onBackPressed()
}
true
}
.setTitle(R.string.pick_image_chooser_title)
.setItems(
arrayOf(
Expand Down
3 changes: 3 additions & 0 deletions sample/src/main/java/com/canhub/cropper/sample/SampleCrop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ internal class SampleCrop : Fragment() {
}
}
private val customCropImage = registerForActivityResult(CropImageContract()) {
if (it is CropImage.CancelledResult) {
return@registerForActivityResult
}
handleCropImageResult(it.uriContent.toString())
}

Expand Down