diff options
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java | 9 | ||||
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/utils/FileHelper.java | 82 |
2 files changed, 3 insertions, 88 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java index bc74f39b..992776e5 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java @@ -15,7 +15,7 @@ import de.thedevstack.conversationsplus.ConversationsPlusApplication; import de.thedevstack.conversationsplus.ConversationsPlusPreferences; import de.thedevstack.conversationsplus.enums.UserDecision; import de.thedevstack.conversationsplus.exceptions.UiException; -import de.thedevstack.conversationsplus.utils.FileHelper; +import de.thedevstack.conversationsplus.utils.FileUtils; import de.thedevstack.conversationsplus.utils.ImageUtil; import de.thedevstack.conversationsplus.utils.MessageUtil; import de.thedevstack.conversationsplus.utils.StreamUtil; @@ -48,8 +48,7 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener { this.callback = new UiCallback<Message>() { @Override - public void userInputRequried(PendingIntent pi, - Message object) { + public void userInputRequried(PendingIntent pi, Message object) { hidePrepareFileToast(); } @@ -98,7 +97,6 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener { public void onYes() { this.showPrepareFileToast(); final Message message; - final boolean forceEncryption = ConversationsPlusPreferences.forceEncryption(); if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { message = new Message(conversation, "", Message.ENCRYPTION_DECRYPTED); } else { @@ -135,7 +133,6 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener { public void onNo() { this.showPrepareFileToast(); final Message message; - final boolean forceEncryption = ConversationsPlusPreferences.forceEncryption(); if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { message = new Message(conversation, "", Message.ENCRYPTION_DECRYPTED); } else { @@ -155,7 +152,7 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener { BitmapFactory.decodeStream(is, null, options); int imageHeight = options.outHeight; int imageWidth = options.outWidth; - String filePath = FileHelper.getRealPathFromUri(uri); + String filePath = FileUtils.getPath(uri); MessageUtil.updateMessageWithImageDetails(message, filePath, imageSize, imageWidth, imageHeight); if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { xmppConnectionService.getPgpEngine().encrypt(message, callback); diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/FileHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/FileHelper.java deleted file mode 100644 index 5cba24b8..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/utils/FileHelper.java +++ /dev/null @@ -1,82 +0,0 @@ -package de.thedevstack.conversationsplus.utils; - -import android.annotation.TargetApi; -import android.content.ContentResolver; -import android.database.Cursor; -import android.net.Uri; -import android.os.Build; -import android.provider.DocumentsContract; -import android.provider.MediaStore; - -import de.thedevstack.conversationsplus.ConversationsPlusApplication; - -/** - * Created by tzur on 30.10.2015. - */ -public final class FileHelper { - - /** - * taken from: http://stackoverflow.com/a/29164361 - * @param uri - * @return - */ - @TargetApi(Build.VERSION_CODES.KITKAT) - private static String getRealPathFromUriLollipop(Uri uri) { - String path = null; - - String wholeID = DocumentsContract.getDocumentId(uri); - - // Split at colon, use second item in the array - String id = wholeID.split(":")[1]; - - String[] column = { MediaStore.Images.Media.DATA }; - - // where id is equal to - String sel = MediaStore.Images.Media._ID + "=?"; - - Cursor cursor = ConversationsPlusApplication.getInstance().getContentResolver(). - query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, - column, sel, new String[]{ id }, null); - - int columnIndex = cursor.getColumnIndex(column[0]); - - if (cursor.moveToFirst()) { - path = cursor.getString(columnIndex); - } - cursor.close(); - return path; - } - - /** - * Get the real path from an Uri. - * @param uri the uri to convert to the real path - * @return the real path or <code>null</code> - */ - public static String getRealPathFromUri(Uri uri) { - String path = null; - if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) { - return uri.getPath(); - } else if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) { - String[] projection = {MediaStore.MediaColumns.DATA}; - Cursor metaCursor = ConversationsPlusApplication.getInstance().getContentResolver().query(uri, - projection, null, null, null); - if (metaCursor != null) { - try { - if (metaCursor.moveToFirst()) { - path = metaCursor.getString(0); - } - } finally { - metaCursor.close(); - } - } - } - if (path == null) { - path = getRealPathFromUriLollipop(uri); - } - return path; - } - - private FileHelper() { - // Utility class - do not instantiate - } -} |