diff --git a/app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasChooseActivity.java b/app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasChooseActivity.java index 3b24757..95de715 100644 --- a/app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasChooseActivity.java +++ b/app/src/main/java/de/k3b/android/lossless_jpg_crop/CropAreasChooseActivity.java @@ -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); @@ -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 + ":"; } @@ -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. */ diff --git a/fastlane/metadata/android/en-US/changelogs/3.txt b/fastlane/metadata/android/en-US/changelogs/3.txt new file mode 100644 index 0000000..0406952 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/3.txt @@ -0,0 +1,3 @@ +Bugfixes: +#7: illegal chars in filename: ':', non-utf8; +#6: rotation prevents save