Skip to content

Commit 005186b

Browse files
committed
Add config to enable saving bitmap to instance state
1 parent 65384a9 commit 005186b

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImageView.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ public class CropImageView extends FrameLayout {
112112
*/
113113
private ScaleType mScaleType;
114114

115+
/**
116+
* if to save bitmap on save instance state.<br>
117+
* It is best to avoid it by using URI in setting image for cropping.<br>
118+
* If false the bitmap is not saved and if restore is required to view will be empty, storing the bitmap
119+
* requires saving it to file which can be expensive.
120+
* default: false.
121+
*/
122+
private boolean mSaveBitmapToInstanceState = false;
123+
115124
/**
116125
* if to show crop overlay UI what contains the crop window UI surrounded by background over the cropping
117126
* image.<br>
@@ -261,6 +270,8 @@ public CropImageView(Context context, AttributeSet attrs) {
261270
options.flipHorizontally = ta.getBoolean(R.styleable.CropImageView_cropFlipHorizontally, options.flipHorizontally);
262271
options.flipVertically = ta.getBoolean(R.styleable.CropImageView_cropFlipHorizontally, options.flipVertically);
263272

273+
mSaveBitmapToInstanceState = ta.getBoolean(R.styleable.CropImageView_cropSaveBitmapToInstanceState, mSaveBitmapToInstanceState);
274+
264275
// if aspect ratio is set then set fixed to true
265276
if (ta.hasValue(R.styleable.CropImageView_cropAspectRatioX) &&
266277
ta.hasValue(R.styleable.CropImageView_cropAspectRatioX) &&
@@ -566,6 +577,28 @@ public void setShowCropOverlay(boolean showCropOverlay) {
566577
}
567578
}
568579

580+
/**
581+
* if to save bitmap on save instance state.<br>
582+
* It is best to avoid it by using URI in setting image for cropping.<br>
583+
* If false the bitmap is not saved and if restore is required to view will be empty, storing the bitmap
584+
* requires saving it to file which can be expensive.
585+
* default: false.
586+
*/
587+
public boolean isSaveBitmapToInstanceState() {
588+
return mSaveBitmapToInstanceState;
589+
}
590+
591+
/**
592+
* if to save bitmap on save instance state.<br>
593+
* It is best to avoid it by using URI in setting image for cropping.<br>
594+
* If false the bitmap is not saved and if restore is required to view will be empty, storing the bitmap
595+
* requires saving it to file which can be expensive.
596+
* default: false.
597+
*/
598+
public void setSaveBitmapToInstanceState(boolean saveBitmapToInstanceState) {
599+
mSaveBitmapToInstanceState = saveBitmapToInstanceState;
600+
}
601+
569602
/**
570603
* Returns the integer of the imageResource
571604
*/
@@ -1149,7 +1182,7 @@ public Parcelable onSaveInstanceState() {
11491182

11501183
Bundle bundle = new Bundle();
11511184
Uri imageUri = mLoadedImageUri;
1152-
if (imageUri == null && mImageResource < 1) {
1185+
if (mSaveBitmapToInstanceState && imageUri == null && mImageResource < 1) {
11531186
mSaveInstanceStateBitmapUri = imageUri = BitmapUtils.writeTempStateStoreBitmap(getContext(), mBitmap, mSaveInstanceStateBitmapUri);
11541187
}
11551188
if (imageUri != null && mBitmap != null) {

cropper/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<attr name="cropBackgroundColor" format="color"/>
3535
<attr name="cropSnapRadius" format="dimension"/>
3636
<attr name="cropTouchRadius" format="dimension"/>
37+
<attr name="cropSaveBitmapToInstanceState" format="boolean"/>
3738
<attr name="cropShowCropOverlay" format="boolean"/>
3839
<attr name="cropShowProgressBar" format="boolean"/>
3940
<attr name="cropMinCropWindowWidth" format="dimension"/>

0 commit comments

Comments
 (0)