Skip to content

Commit

Permalink
Bug/clear mRestoreCropWindowRect and mRestoreDegreesRotated when usin…
Browse files Browse the repository at this point in the history
…g setImageBitmap (#69)

* !68 - clear mRestoreCropWindowRect and mRestoreDegreesRotated

These both need to be cleared when setting a new image via
setImageBitmap, just like how they are cleared via setImageUriAsync.

Also, the degrees need to be cleared immediately after they are used to
restore the degrees. At the moment they are left there, lurking. I don't
think this one is a bug since they are only used when
mRestoreCropWindowRect is not null (which is also odd?) but it's still
a code smell.

* Update CHANGELOG.md
  • Loading branch information
chriscoomber authored Feb 27, 2021
1 parent e2d1a04 commit 2f74953
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Added
- CropImage.getActivityResult(data).getBitmap(context) [#49](https://github.com/CanHub/Android-Image-Cropper/issues/49)

### Fixed
- CropImageView incorrectly restored on rotation [#68](https://github.com/CanHub/Android-Image-Cropper/issues/68)

## [2.1.0] - 11/02/21
### Changed
- From Java to Kotlin: [CropImageOptions](https://github.com/CanHub/Android-Image-Cropper/issues/40), [CropWindowHandler](https://github.com/CanHub/Android-Image-Cropper/issues/37)
Expand Down
5 changes: 3 additions & 2 deletions cropper/src/main/java/com/canhub/cropper/CropImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1022,8 +1022,6 @@ public void setImageUriAsync(Uri uri) {

// either no existing task is working or we canceled it, need to load new URI
clearImageInt();
mRestoreCropWindowRect = null;
mRestoreDegreesRotated = 0;
mCropOverlayView.setInitialCropWindowRect(null);
mBitmapLoadingWorkerJob = new WeakReference<>(new BitmapLoadingWorkerJob((FragmentActivity)getContext(),this, uri));
mBitmapLoadingWorkerJob.get().start();
Expand Down Expand Up @@ -1236,6 +1234,8 @@ private void clearImageInt() {
mZoomOffsetY = 0;
mImageMatrix.reset();
mSaveInstanceStateBitmapUri = null;
mRestoreCropWindowRect = null;
mRestoreDegreesRotated = 0;

mImageView.setImageBitmap(null);

Expand Down Expand Up @@ -1527,6 +1527,7 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
if (mRestoreDegreesRotated != mInitialDegreesRotated) {
mDegreesRotated = mRestoreDegreesRotated;
applyImageMatrix(r - l, b - t, true, false);
mRestoreDegreesRotated = 0;
}
mImageMatrix.mapRect(mRestoreCropWindowRect);
mCropOverlayView.setCropWindowRect(mRestoreCropWindowRect);
Expand Down

0 comments on commit 2f74953

Please sign in to comment.