From 440b96497b5b455e57354fd417d6be6fd7b32f62 Mon Sep 17 00:00:00 2001 From: Lukas Date: Fri, 22 Sep 2017 18:57:44 +0200 Subject: [PATCH] - Bug fixes --- app/proguard-rules.pro | 6 +++++- .../NestedRecyclerViewAlbumHolder.java | 2 +- .../data/fileOperations/FileOperation.java | 3 +++ .../data/provider/MediaProvider.java | 4 ++++ .../cameraroll/data/provider/Provider.java | 3 +++ .../us/koller/cameraroll/ui/AlbumActivity.java | 8 ++++---- .../us/koller/cameraroll/ui/MainActivity.java | 3 +++ .../cameraroll/ui/widget/CropImageView.java | 8 +++++++- .../us/koller/cameraroll/util/ExifUtil.java | 5 ++++- .../java/us/koller/cameraroll/util/Util.java | 18 ++++++++++++++++++ .../res/values/strings_not_translatable.xml | 2 +- 11 files changed, 53 insertions(+), 9 deletions(-) diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 77ffe391..6128b607 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -21,4 +21,8 @@ -keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** { **[] $VALUES; public *; -} \ No newline at end of file +} + +# will keep line numbers and file name obfuscation +-renamesourcefileattribute SourceFile +-keepattributes SourceFile,LineNumberTable \ No newline at end of file diff --git a/app/src/main/java/us/koller/cameraroll/adapter/main/viewHolder/NestedRecyclerViewAlbumHolder.java b/app/src/main/java/us/koller/cameraroll/adapter/main/viewHolder/NestedRecyclerViewAlbumHolder.java index 6fa5bcc6..7db54f2b 100644 --- a/app/src/main/java/us/koller/cameraroll/adapter/main/viewHolder/NestedRecyclerViewAlbumHolder.java +++ b/app/src/main/java/us/koller/cameraroll/adapter/main/viewHolder/NestedRecyclerViewAlbumHolder.java @@ -317,7 +317,7 @@ public boolean onMenuItemClick(MenuItem item) { intent = new Intent(); intent.setAction(Intent.ACTION_SEND_MULTIPLE) - .setType(MediaType.getMimeType(paths[0])) + .setType(MediaType.getMimeType(getContext(), uris.get(0))) .putExtra(Intent.EXTRA_STREAM, uris); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION diff --git a/app/src/main/java/us/koller/cameraroll/data/fileOperations/FileOperation.java b/app/src/main/java/us/koller/cameraroll/data/fileOperations/FileOperation.java index c0de9ef2..c0fcb7b2 100644 --- a/app/src/main/java/us/koller/cameraroll/data/fileOperations/FileOperation.java +++ b/app/src/main/java/us/koller/cameraroll/data/fileOperations/FileOperation.java @@ -406,6 +406,9 @@ public void run() { } public static void scanPathsWithToast(final Context context, final String[] paths) { + if (paths == null) { + return; + } @SuppressLint("ShowToast") final WeakReference toastWeakReference = new WeakReference<>( Toast.makeText(context, R.string.scanning, Toast.LENGTH_SHORT)); MediaScannerConnection.scanFile(context.getApplicationContext(), diff --git a/app/src/main/java/us/koller/cameraroll/data/provider/MediaProvider.java b/app/src/main/java/us/koller/cameraroll/data/provider/MediaProvider.java index db3ad6a6..d9695e46 100644 --- a/app/src/main/java/us/koller/cameraroll/data/provider/MediaProvider.java +++ b/app/src/main/java/us/koller/cameraroll/data/provider/MediaProvider.java @@ -179,6 +179,10 @@ public static ArrayList getAlbumsWithVirtualDirectories(Activity context) public static void loadAlbum(final Activity context, final String path, final OnAlbumLoadedCallback callback) { + if (path == null) { + return; + } + if (albums == null) { Settings s = Settings.getInstance(context); boolean hiddenFolders = s.getHiddenFolders(); diff --git a/app/src/main/java/us/koller/cameraroll/data/provider/Provider.java b/app/src/main/java/us/koller/cameraroll/data/provider/Provider.java index 5078215c..e8514049 100644 --- a/app/src/main/java/us/koller/cameraroll/data/provider/Provider.java +++ b/app/src/main/java/us/koller/cameraroll/data/provider/Provider.java @@ -369,6 +369,9 @@ public boolean accept(File file) { //external Directory File dir = Environment.getExternalStorageDirectory(); File[] dirs = dir.listFiles(filter); + if (dirs == null) { + dirs = new File[]{}; + } //handle removable storage (e.g. SDCards) ArrayList temp = new ArrayList<>(); diff --git a/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java b/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java index ae4db2cc..df319495 100644 --- a/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java +++ b/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java @@ -529,9 +529,9 @@ public boolean onOptionsItemSelected(MenuItem item) { uris.add(StorageUtil.getContentUri(this, selected_items_paths[i])); } - intent = new Intent(); - intent.setAction(Intent.ACTION_SEND_MULTIPLE) - .setType(MediaType.getMimeType(selected_items_paths[0])) + intent = new Intent() + .setAction(Intent.ACTION_SEND_MULTIPLE) + .setType(MediaType.getMimeType(this, uris.get(0))) .putExtra(Intent.EXTRA_STREAM, uris); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION @@ -735,7 +735,7 @@ public void onReceive(Context context, Intent intent) { private ClipData createClipData(AlbumItem[] items) { String[] mimeTypes = new String[items.length]; for (int i = 0; i < items.length; i++) { - mimeTypes[i] = MediaType.getMimeType(items[i].getPath()); + mimeTypes[i] = MediaType.getMimeType(this, items[i].getUri(this)); } ClipData clipData = diff --git a/app/src/main/java/us/koller/cameraroll/ui/MainActivity.java b/app/src/main/java/us/koller/cameraroll/ui/MainActivity.java index b1c374a7..1045d229 100644 --- a/app/src/main/java/us/koller/cameraroll/ui/MainActivity.java +++ b/app/src/main/java/us/koller/cameraroll/ui/MainActivity.java @@ -13,6 +13,7 @@ import android.os.Handler; import android.provider.MediaStore; import android.support.annotation.RequiresApi; +import android.support.design.widget.BaseTransientBottomBar; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityOptionsCompat; @@ -31,8 +32,10 @@ import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.WindowInsets; +import android.view.accessibility.AccessibilityManager; import android.widget.Toast; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.Map; diff --git a/app/src/main/java/us/koller/cameraroll/ui/widget/CropImageView.java b/app/src/main/java/us/koller/cameraroll/ui/widget/CropImageView.java index 6410f19e..86429ec7 100644 --- a/app/src/main/java/us/koller/cameraroll/ui/widget/CropImageView.java +++ b/app/src/main/java/us/koller/cameraroll/ui/widget/CropImageView.java @@ -269,7 +269,13 @@ public void run() { }); } catch (Exception | OutOfMemoryError e) { e.printStackTrace(); - onResultListener.onResult(new Result(getImageUri(), null)); + CropImageView.this.post(new Runnable() { + @Override + public void run() { + onResultListener.onResult(new Result(getImageUri(), null)); + setProgressBarVisibility(GONE); + } + }); } } }); diff --git a/app/src/main/java/us/koller/cameraroll/util/ExifUtil.java b/app/src/main/java/us/koller/cameraroll/util/ExifUtil.java index cbf139f2..c790dd42 100644 --- a/app/src/main/java/us/koller/cameraroll/util/ExifUtil.java +++ b/app/src/main/java/us/koller/cameraroll/util/ExifUtil.java @@ -4,6 +4,7 @@ import android.net.Uri; import android.os.Build; import android.support.media.ExifInterface; +import android.widget.Toast; import java.io.IOException; import java.io.InputStream; @@ -469,8 +470,10 @@ public static ExifInterface getExifInterface(Context context, AlbumItem albumIte } else { exif = new ExifInterface(albumItem.getPath()); } - } catch (IOException e) { + } catch (IOException | SecurityException e) { e.printStackTrace(); + Toast.makeText(context, "SecurityException", Toast.LENGTH_SHORT).show(); + return null; } return exif; } diff --git a/app/src/main/java/us/koller/cameraroll/util/Util.java b/app/src/main/java/us/koller/cameraroll/util/Util.java index 21442a1d..e6ddd94c 100644 --- a/app/src/main/java/us/koller/cameraroll/util/Util.java +++ b/app/src/main/java/us/koller/cameraroll/util/Util.java @@ -14,6 +14,7 @@ import android.os.Build; import android.os.PowerManager; import android.support.annotation.RequiresApi; +import android.support.design.widget.BaseTransientBottomBar; import android.support.design.widget.Snackbar; import android.support.media.ExifInterface; import android.support.v4.content.res.ResourcesCompat; @@ -21,7 +22,9 @@ import android.support.v7.content.res.AppCompatResources; import android.support.v7.widget.Toolbar; import android.util.DisplayMetrics; +import android.util.Log; import android.view.View; +import android.view.accessibility.AccessibilityManager; import android.widget.TextView; import android.widget.Toast; @@ -29,6 +32,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.Field; import java.util.Locale; import us.koller.cameraroll.R; @@ -151,6 +155,20 @@ public static boolean areStatusBarIconsDark(final View v) { public static void showSnackbar(Snackbar snackbar) { snackbar.getView().setTag(SNACKBAR); + // fixing SnackBar animation, when AccessibilityManager is enabled + // Solution from: https://stackoverflow.com/a/43811447/8378871 + try { + Field mAccessibilityManagerField = BaseTransientBottomBar.class.getDeclaredField("mAccessibilityManager"); + mAccessibilityManagerField.setAccessible(true); + AccessibilityManager accessibilityManager = (AccessibilityManager) mAccessibilityManagerField.get(snackbar); + Field mIsEnabledField = AccessibilityManager.class.getDeclaredField("mIsEnabled"); + mIsEnabledField.setAccessible(true); + mIsEnabledField.setBoolean(accessibilityManager, false); + mAccessibilityManagerField.set(snackbar, accessibilityManager); + } catch (Exception e) { + Log.d("Snackbar", "Reflection error: " + e.toString()); + } + TextView textView = snackbar.getView() .findViewById(android.support.design.R.id.snackbar_text); textView.setTypeface(Typeface.create("sans-serif-monospace", Typeface.NORMAL)); diff --git a/app/src/main/res/values/strings_not_translatable.xml b/app/src/main/res/values/strings_not_translatable.xml index 4e45314a..d7f58f83 100644 --- a/app/src/main/res/values/strings_not_translatable.xml +++ b/app/src/main/res/values/strings_not_translatable.xml @@ -78,7 +78,7 @@ Russian: Atrem Zhiganov
Spanish: Christobal Rojas, Luis Gmz
Bulgarian: psydex
- Croatian: Ivan Krušlin
+ Croatian: Ivan Krušlin
Portuguese: Marcio Zomb13

]]>