Skip to content

Commit

Permalink
Bugfix: #6: rotation prevents save
Browse files Browse the repository at this point in the history
  • Loading branch information
k3b committed May 14, 2019
1 parent 9c4f0e7 commit 494536b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,12 @@ protected void onCreate(Bundle savedInstanceState) {
uCropView.setImageUriAsync(uri);

final boolean noPreviousInstanceState = savedInstanceState == null;
Rect crop = (Rect) (noPreviousInstanceState
final Rect crop = (Rect) (noPreviousInstanceState
? null
: savedInstanceState.getParcelable(CURRENT_CROP_AREA));

Log.d(TAG, getInstanceNo() + "onCreate(savedInstanceState:" + !noPreviousInstanceState +
"): crop=" + crop);
setCropRect(crop);

uCropView.setCropRect(crop);
} catch (Exception e) {
final String msg = getInstanceNo() + "setImageUri '" + uri + "' ";
Log.e(TAG, msg, e);
Expand All @@ -87,6 +85,36 @@ protected void onCreate(Bundle savedInstanceState) {

}

// #7: workaround rotation change while picker is open causes Activity re-create without
// uCropView recreation completed.
private Rect mLastCropRect = null;
private void setCropRect(final Rect crop) {
if (crop != null) {
mLastCropRect = crop;
uCropView.setCropRect(crop);

uCropView.setOnSetImageUriCompleteListener(new CropImageView.OnSetImageUriCompleteListener() {
@Override
public void onSetImageUriComplete(CropImageView view, Uri uri, Exception error) {
// called when uCropView recreation is completed.
uCropView.setCropRect(crop);
Rect newCrop = getCropRect();
Log.d(TAG, getInstanceNo() + "delayed onCreate(): crop=" + crop + "/" + newCrop);
uCropView.setOnSetImageUriCompleteListener(null);
}
});
}
}

private Rect getCropRect() {
if (uCropView == null) {
Log.e(TAG, getInstanceNo() + "ups: no cropView");
return null;
}
final Rect cropRect = uCropView.getCropRect();
return (cropRect != null) ? cropRect : mLastCropRect;
}

private String getInstanceNo() {
return "#" + instanceNo + ":";
}
Expand Down Expand Up @@ -306,14 +334,6 @@ private static String replaceExtension(String path, String extension) {
return ((ext >= 0) ? path.substring(0, ext) : path) + extension;
}

private Rect getCropRect() {
if (uCropView == null) {
Log.e(TAG, getInstanceNo() + "ups: no cropView");
return null;
}
return uCropView.getCropRect();
}

/**
* Callback received when a permissions request has been completed.
*/
Expand Down
3 changes: 3 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfixes:
#7: illegal chars in filename: ':', non-utf8;
#6: rotation prevents save

0 comments on commit 494536b

Please sign in to comment.