Skip to content

Commit

Permalink
Fix Android state restore overrides state set by client.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur committed Jun 17, 2016
1 parent d5f8254 commit 886eff3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 48 deletions.
17 changes: 4 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cropper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 886eff3

Please sign in to comment.