diff options
author | steckbrief <steckbrief@chefmail.de> | 2016-03-12 21:14:55 +0100 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2016-03-12 21:14:55 +0100 |
commit | a95d2d9134508ec694cb48db361f1fd4387d1827 (patch) | |
tree | b54e1da9964a71b9ceb5bb3fd1d3cd6697883c3d /src/main | |
parent | 14c2c72bc1a00c8b9839047cdc73116e561ecd62 (diff) |
Fixes FS#155: Check FileHelper vs. FileUtils
Diffstat (limited to '')
5 files changed, 16 insertions, 97 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java index 941aaae1..3678288d 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java @@ -47,7 +47,6 @@ import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -63,7 +62,7 @@ import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.ConversationsPlusApplication; import de.thedevstack.conversationsplus.ConversationsPlusPreferences; import de.thedevstack.conversationsplus.exceptions.FileCopyException; -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.UiUpdateHelper; @@ -402,7 +401,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } message.setCounterpart(conversation.getNextCounterpart()); message.setType(Message.TYPE_FILE); - String path = FileHelper.getRealPathFromUri(uri); + String path = FileUtils.getPath(uri); if (path != null) { message.setRelativeFilePath(path); MessageUtil.updateFileParams(message); diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/PublishProfilePictureActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/PublishProfilePictureActivity.java index 6bf8c590..af253730 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/PublishProfilePictureActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/PublishProfilePictureActivity.java @@ -195,7 +195,7 @@ public class PublishProfilePictureActivity extends XmppActivity { switch (requestCode) { case REQUEST_CHOOSE_FILE_AND_CROP: Uri source = data.getData(); - String original = FileUtils.getPath(this, source); + String original = FileUtils.getPath(source); if (original != null) { source = Uri.parse("file://"+original); } 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 5ab8feb2..8897d8da 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.R; @@ -47,8 +47,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(); } @@ -97,7 +96,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 { @@ -134,7 +132,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 { @@ -154,7 +151,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 - } -} diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java b/src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java index 9b627f6b..b556b72b 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java @@ -11,25 +11,26 @@ import android.os.Environment; import android.provider.DocumentsContract; import android.provider.MediaStore; -public class FileUtils { +import de.thedevstack.conversationsplus.ConversationsPlusApplication; + +public final class FileUtils { /** * Get a file path from a Uri. This will get the the path for Storage Access * Framework Documents, as well as the _data field for the MediaStore and * other file-based ContentProviders. * - * @param context The context. * @param uri The Uri to query. * @author paulburke */ @SuppressLint("NewApi") - public static String getPath(final Context context, final Uri uri) { + public static String getPath(final Uri uri) { if (uri == null) { return null; } final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; - + final Context context = ConversationsPlusApplication.getAppContext(); // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider @@ -98,7 +99,7 @@ public class FileUtils { * @param selectionArgs (Optional) Selection arguments used in the query. * @return The value of the _data column, which is typically a file path. */ - public static String getDataColumn(Context context, Uri uri, String selection, + private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; @@ -176,4 +177,8 @@ public class FileUtils { filename.substring(secondToLastDotPosition + 1, lastDotPosition) : ""; return secondToLastPart; } + + private FileUtils() { + // Utility class - do not instantiate + } } |