Skip to content

Commit

Permalink
Add config to enable saving bitmap to instance state
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHub committed Apr 28, 2017
1 parent 65384a9 commit 005186b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ public class CropImageView extends FrameLayout {
*/
private ScaleType mScaleType;

/**
* if to save bitmap on save instance state.<br>
* It is best to avoid it by using URI in setting image for cropping.<br>
* If false the bitmap is not saved and if restore is required to view will be empty, storing the bitmap
* requires saving it to file which can be expensive.
* default: false.
*/
private boolean mSaveBitmapToInstanceState = false;

/**
* if to show crop overlay UI what contains the crop window UI surrounded by background over the cropping
* image.<br>
Expand Down Expand Up @@ -261,6 +270,8 @@ public CropImageView(Context context, AttributeSet attrs) {
options.flipHorizontally = ta.getBoolean(R.styleable.CropImageView_cropFlipHorizontally, options.flipHorizontally);
options.flipVertically = ta.getBoolean(R.styleable.CropImageView_cropFlipHorizontally, options.flipVertically);

mSaveBitmapToInstanceState = ta.getBoolean(R.styleable.CropImageView_cropSaveBitmapToInstanceState, mSaveBitmapToInstanceState);

// if aspect ratio is set then set fixed to true
if (ta.hasValue(R.styleable.CropImageView_cropAspectRatioX) &&
ta.hasValue(R.styleable.CropImageView_cropAspectRatioX) &&
Expand Down Expand Up @@ -566,6 +577,28 @@ public void setShowCropOverlay(boolean showCropOverlay) {
}
}

/**
* if to save bitmap on save instance state.<br>
* It is best to avoid it by using URI in setting image for cropping.<br>
* If false the bitmap is not saved and if restore is required to view will be empty, storing the bitmap
* requires saving it to file which can be expensive.
* default: false.
*/
public boolean isSaveBitmapToInstanceState() {
return mSaveBitmapToInstanceState;
}

/**
* if to save bitmap on save instance state.<br>
* It is best to avoid it by using URI in setting image for cropping.<br>
* If false the bitmap is not saved and if restore is required to view will be empty, storing the bitmap
* requires saving it to file which can be expensive.
* default: false.
*/
public void setSaveBitmapToInstanceState(boolean saveBitmapToInstanceState) {
mSaveBitmapToInstanceState = saveBitmapToInstanceState;
}

/**
* Returns the integer of the imageResource
*/
Expand Down Expand Up @@ -1149,7 +1182,7 @@ public Parcelable onSaveInstanceState() {

Bundle bundle = new Bundle();
Uri imageUri = mLoadedImageUri;
if (imageUri == null && mImageResource < 1) {
if (mSaveBitmapToInstanceState && imageUri == null && mImageResource < 1) {
mSaveInstanceStateBitmapUri = imageUri = BitmapUtils.writeTempStateStoreBitmap(getContext(), mBitmap, mSaveInstanceStateBitmapUri);
}
if (imageUri != null && mBitmap != null) {
Expand Down
1 change: 1 addition & 0 deletions cropper/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<attr name="cropBackgroundColor" format="color"/>
<attr name="cropSnapRadius" format="dimension"/>
<attr name="cropTouchRadius" format="dimension"/>
<attr name="cropSaveBitmapToInstanceState" format="boolean"/>
<attr name="cropShowCropOverlay" format="boolean"/>
<attr name="cropShowProgressBar" format="boolean"/>
<attr name="cropMinCropWindowWidth" format="dimension"/>
Expand Down

0 comments on commit 005186b

Please sign in to comment.