From 31809924fffddab4501cbdbc8d4e5732ee18e24f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Eisfeld?= Date: Mon, 12 Jun 2017 13:03:45 +0200 Subject: [PATCH] Catching some frequent IllegalStateExceptions --- .../components/OverlayPinchImageView.java | 7 ++++++- .../augendiagnoselib/util/DialogUtil.java | 20 +++++++++++++++++-- .../util/imagefile/MediaStoreUtil.java | 8 ++++++-- AugendiagnoseIdea/build.gradle | 2 +- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/components/OverlayPinchImageView.java b/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/components/OverlayPinchImageView.java index d7ff130d..6c5574c6 100644 --- a/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/components/OverlayPinchImageView.java +++ b/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/components/OverlayPinchImageView.java @@ -1806,7 +1806,12 @@ public static RetainFragment findOrCreateRetainFragment(@NonNull final FragmentM RetainFragment fragment = (RetainFragment) fm.findFragmentByTag(TAG + index); if (fragment == null) { fragment = new RetainFragment(); - fm.beginTransaction().add(fragment, TAG + index).commit(); + try { + fm.beginTransaction().add(fragment, TAG + index).commit(); + } + catch (IllegalStateException e) { + TrackingUtil.sendException("opv1", e); + } } return fragment; } diff --git a/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/util/DialogUtil.java b/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/util/DialogUtil.java index f90b9e42..4700791f 100644 --- a/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/util/DialogUtil.java +++ b/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/util/DialogUtil.java @@ -94,7 +94,15 @@ public static void displayInfo(@NonNull final Activity activity, @Nullable final } DialogFragment fragment = new DisplayMessageDialogFragment(); fragment.setArguments(bundle); - fragment.show(activity.getFragmentManager(), fragment.getClass().toString()); + try { + fragment.show(activity.getFragmentManager(), fragment.getClass().toString()); + } + catch (IllegalStateException e) { + displayToast(activity, resource, args); + if (listener != null) { + listener.onDialogClick(fragment); + } + } } /** @@ -119,7 +127,15 @@ private static void displayError(@NonNull final Activity activity, final int res DialogFragment fragment = new DisplayMessageDialogFragment(); fragment.setArguments(bundle); - fragment.show(activity.getFragmentManager(), fragment.getClass().toString()); + try { + fragment.show(activity.getFragmentManager(), fragment.getClass().toString()); + } + catch (IllegalStateException e) { + displayToast(activity, resource, args); + if (listener != null) { + listener.onDialogClick(fragment); + } + } } /** diff --git a/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/util/imagefile/MediaStoreUtil.java b/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/util/imagefile/MediaStoreUtil.java index 71479820..1edcbbf1 100644 --- a/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/util/imagefile/MediaStoreUtil.java +++ b/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/util/imagefile/MediaStoreUtil.java @@ -201,8 +201,12 @@ public static Bitmap getThumbnailFromPath(final String path, final int maxSize) BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = MINI_THUMB_SIZE / maxSize; setDither(options); - return MediaStore.Images.Thumbnails.getThumbnail(resolver, imageId, MediaStore.Images.Thumbnails.MINI_KIND, - options); + try { + return MediaStore.Images.Thumbnails.getThumbnail(resolver, imageId, MediaStore.Images.Thumbnails.MINI_KIND, options); + } + catch (Exception e) { + return null; + } } catch (ImageNotFoundException e) { diff --git a/AugendiagnoseIdea/build.gradle b/AugendiagnoseIdea/build.gradle index 4aa9de97..b7629373 100644 --- a/AugendiagnoseIdea/build.gradle +++ b/AugendiagnoseIdea/build.gradle @@ -4,7 +4,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.2' + classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.google.gms:google-services:3.0.0' } }