diff --git a/README.md b/README.md index 023bcf4c..78aa7dc2 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,10 @@ For more information, see the [GitHub Wiki](https://github.com/ArthurHub/Android - [Adding auto-zoom feature to Android-Image-Cropper](https://theartofdev.com/2016/04/25/adding-auto-zoom-feature-to-android-image-cropper/) ## Change log +*2.2.3* + +- Fix Android state restore overrides state set by client. + *2.2.2* - Fix rotation zooms and changes aspect ratio when fixed aspect ratio is used. @@ -117,19 +121,6 @@ For more information, see the [GitHub Wiki](https://github.com/ArthurHub/Android - Add activity counter-clockwise rotation button (configurable, hidden by default). - Add activity rotation degrees configuration (default 90) -*2.1.4* - -- Support for requesting CAMERA permission for android M when CAMERA is requested in the manifest. -- Add `pick_image_intent_chooser_title` for changing and localizing pick image chooser title (thx maksymkhar). -- NPE when clicking crop twice fast (thx Jesse). - -*2.1.1* - -- Built-in `CropImageActivity` for quick start and common scenarios. -- Save cropped image to Uri API `saveCroppedImageAsync(Uri)`. -- Handle possible out-of-memory in image load by down-sampling until succeed. -- Minor fixes. - See [full change log](https://github.com/ArthurHub/Android-Image-Cropper/wiki/Change-Log). ## License diff --git a/cropper/build.gradle b/cropper/build.gradle index 709cb5de..90486b0e 100644 --- a/cropper/build.gradle +++ b/cropper/build.gradle @@ -6,7 +6,7 @@ apply plugin: 'maven-publish' ext { PUBLISH_GROUP_ID = 'com.theartofdev.edmodo' PUBLISH_ARTIFACT_ID = 'android-image-cropper' - PUBLISH_VERSION = '2.2.2' + PUBLISH_VERSION = '2.2.3' // gradlew clean build generateRelease } diff --git a/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImageView.java b/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImageView.java index ee842f83..0ed2c609 100644 --- a/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImageView.java +++ b/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImageView.java @@ -986,54 +986,57 @@ public Parcelable onSaveInstanceState() { @Override public void onRestoreInstanceState(Parcelable state) { + if (state instanceof Bundle) { Bundle bundle = (Bundle) state; - Bitmap bitmap = null; - Uri uri = bundle.getParcelable("LOADED_IMAGE_URI"); - if (uri != null) { - String key = bundle.getString("LOADED_IMAGE_STATE_BITMAP_KEY"); - if (key != null) { - Bitmap stateBitmap = BitmapUtils.mStateBitmap != null && BitmapUtils.mStateBitmap.first.equals(key) - ? BitmapUtils.mStateBitmap.second.get() : null; - if (stateBitmap != null && !stateBitmap.isRecycled()) { - BitmapUtils.mStateBitmap = null; - setBitmap(stateBitmap, true); - mLoadedImageUri = uri; - mLoadedSampleSize = bundle.getInt("LOADED_SAMPLE_SIZE"); + // prevent restoring state if already set by outside code + if (mBitmapLoadingWorkerTask == null && mLoadedImageUri == null && mBitmap == null && mImageResource == 0) { + + Uri uri = bundle.getParcelable("LOADED_IMAGE_URI"); + if (uri != null) { + String key = bundle.getString("LOADED_IMAGE_STATE_BITMAP_KEY"); + if (key != null) { + Bitmap stateBitmap = BitmapUtils.mStateBitmap != null && BitmapUtils.mStateBitmap.first.equals(key) + ? BitmapUtils.mStateBitmap.second.get() : null; + if (stateBitmap != null && !stateBitmap.isRecycled()) { + BitmapUtils.mStateBitmap = null; + setBitmap(stateBitmap, true); + mLoadedImageUri = uri; + mLoadedSampleSize = bundle.getInt("LOADED_SAMPLE_SIZE"); + } + } + if (mLoadedImageUri == null) { + setImageUriAsync(uri); } - } - if (mLoadedImageUri == null) { - setImageUriAsync(uri); - } - - } else { - int resId = bundle.getInt("LOADED_IMAGE_RESOURCE"); - if (resId > 0) { - setImageResource(resId); } else { - bitmap = bundle.getParcelable("SET_BITMAP"); - if (bitmap != null) { - setBitmap(bitmap, true); + int resId = bundle.getInt("LOADED_IMAGE_RESOURCE"); + if (resId > 0) { + setImageResource(resId); } else { - uri = bundle.getParcelable("LOADING_IMAGE_URI"); - if (uri != null) { - setImageUriAsync(uri); + Bitmap bitmap = bundle.getParcelable("SET_BITMAP"); + if (bitmap != null) { + setBitmap(bitmap, true); + } else { + uri = bundle.getParcelable("LOADING_IMAGE_URI"); + if (uri != null) { + setImageUriAsync(uri); + } } } } - } - mDegreesRotated = bundle.getInt("DEGREES_ROTATED"); + mDegreesRotated = bundle.getInt("DEGREES_ROTATED"); - mCropOverlayView.setInitialCropWindowRect((Rect) bundle.getParcelable("INITIAL_CROP_RECT")); + mCropOverlayView.setInitialCropWindowRect((Rect) bundle.getParcelable("INITIAL_CROP_RECT")); - mRestoreCropWindowRect = bundle.getParcelable("CROP_WINDOW_RECT"); + mRestoreCropWindowRect = bundle.getParcelable("CROP_WINDOW_RECT"); - mCropOverlayView.setCropShape(CropShape.valueOf(bundle.getString("CROP_SHAPE"))); + mCropOverlayView.setCropShape(CropShape.valueOf(bundle.getString("CROP_SHAPE"))); - mAutoZoomEnabled = bundle.getBoolean("CROP_AUTO_ZOOM_ENABLED"); - mMaxZoom = bundle.getInt("CROP_MAX_ZOOM"); + mAutoZoomEnabled = bundle.getBoolean("CROP_AUTO_ZOOM_ENABLED"); + mMaxZoom = bundle.getInt("CROP_MAX_ZOOM"); + } super.onRestoreInstanceState(bundle.getParcelable("instanceState")); } else {