From e93eb51ffe47a806c25cfe8623a5d5097bbc5d80 Mon Sep 17 00:00:00 2001 From: tobiaskaminsky Date: Fri, 1 Dec 2017 16:00:09 +0100 Subject: [PATCH 1/2] "set picture as" with resized images --- .../ui/fragment/OCFileListFragment.java | 7 +--- .../ui/helpers/FileOperationsHelper.java | 35 +++++++++++-------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index 26e876f0ae..4181357347 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -985,12 +985,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi } } case R.id.action_set_as_wallpaper: { - if (singleFile.isDown()) { - mContainerActivity.getFileOperationsHelper().setPictureAs(singleFile); - } else { - Log_OC.d(TAG, singleFile.getRemotePath() + " : File must be downloaded"); - ((FileDisplayActivity) mContainerActivity).startDownloadForSending(singleFile, DOWNLOAD_SET_AS); - } + mContainerActivity.getFileOperationsHelper().setPictureAs(singleFile); return true; } } diff --git a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java index 9cf2e0ec1a..b89a77362e 100755 --- a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java +++ b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java @@ -56,6 +56,7 @@ import com.owncloud.android.ui.events.FavoriteEvent; import com.owncloud.android.ui.events.SyncEventFinished; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; +import com.owncloud.android.utils.UriUtils; import org.greenrobot.eventbus.EventBus; @@ -582,30 +583,34 @@ public class FileOperationsHelper { public void setPictureAs(OCFile file) { if (file != null) { - if (file.isDown()) { - Context context = MainApp.getAppContext(); + Context context = MainApp.getAppContext(); + Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); + Uri uri; - try { + try { + if (file.isDown()) { File externalFile = new File(file.getStoragePath()); - Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); - Uri sendUri; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - sendUri = FileProvider.getUriForFile(context, + uri = FileProvider.getUriForFile(context, context.getResources().getString(R.string.file_provider_authority), externalFile); } else { - sendUri = Uri.fromFile(externalFile); + uri = Uri.fromFile(externalFile); } - - intent.setDataAndType(sendUri, file.getMimetype()); - intent.putExtra("mimeType", file.getMimetype()); - mFileActivity.startActivityForResult(Intent.createChooser(intent, - mFileActivity.getString(R.string.set_as)), 200); - - } catch (ActivityNotFoundException exception) { - Toast.makeText(context, R.string.picture_set_as_no_app, Toast.LENGTH_LONG).show(); + } else { + uri = Uri.parse(UriUtils.URI_CONTENT_SCHEME + + context.getResources().getString(R.string.image_cache_provider_authority) + + file.getRemotePath()); } + + intent.setDataAndType(uri, file.getMimetype()); + mFileActivity.startActivityForResult(Intent.createChooser(intent, + mFileActivity.getString(R.string.set_as)), 200); + + intent.setDataAndType(uri, file.getMimetype()); + } catch (ActivityNotFoundException exception) { + Toast.makeText(context, R.string.picture_set_as_no_app, Toast.LENGTH_LONG).show(); } } else { Log_OC.wtf(TAG, "Trying to send a NULL OCFile"); From 297c6024bce963a187eb4b6b81c41aed9652be79 Mon Sep 17 00:00:00 2001 From: tobiaskaminsky Date: Mon, 4 Dec 2017 10:50:38 +0100 Subject: [PATCH 2/2] - replace Toast with Snackbar - remove not used code --- .../android/ui/activity/FileDisplayActivity.java | 13 ++----------- .../android/ui/fragment/OCFileListFragment.java | 3 +-- .../android/ui/helpers/FileOperationsHelper.java | 7 ++++--- .../android/ui/preview/PreviewImageFragment.java | 2 +- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index 24ef443f93..98fedb13e8 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1449,9 +1449,6 @@ public class FileDisplayActivity extends HookActivity case OCFileListFragment.DOWNLOAD_SEND: sendDownloadedFile(); break; - case OCFileListFragment.DOWNLOAD_SET_AS: - setPictureAs(); - break; default: // do nothing break; @@ -1609,7 +1606,7 @@ public class FileDisplayActivity extends HookActivity mUploaderBinder = null; } } - }; + } private MediaServiceConnection newMediaConnection(){ return new MediaServiceConnection(); @@ -1639,7 +1636,7 @@ public class FileDisplayActivity extends HookActivity mMediaServiceBinder = null; } } - }; + } /** * Updates the view associated to the activity after the finish of some operation over files @@ -1986,12 +1983,6 @@ public class FileDisplayActivity extends HookActivity mWaitingToSend = null; } - private void setPictureAs() { - getFileOperationsHelper().setPictureAs(mWaitingToSend); - mWaitingToSend = null; - } - - /** * Requests the download of the received {@link OCFile} , updates the UI * to monitor the download progress and prepares the activity to send the file diff --git a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index 4181357347..a725efed23 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -129,7 +129,6 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi public static final String DOWNLOAD_BEHAVIOUR = "DOWNLOAD_BEHAVIOUR"; public static final String DOWNLOAD_SEND = "DOWNLOAD_SEND"; - public static final String DOWNLOAD_SET_AS = "DOWNLOAD_SET_AS"; public static final String SEARCH_EVENT = "SEARCH_EVENT"; @@ -985,7 +984,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi } } case R.id.action_set_as_wallpaper: { - mContainerActivity.getFileOperationsHelper().setPictureAs(singleFile); + mContainerActivity.getFileOperationsHelper().setPictureAs(singleFile, getView()); return true; } } diff --git a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java index b89a77362e..16e14af627 100755 --- a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java +++ b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java @@ -30,9 +30,10 @@ import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Build; import android.support.annotation.Nullable; +import android.support.design.widget.Snackbar; import android.support.v4.content.FileProvider; +import android.view.View; import android.webkit.MimeTypeMap; -import android.widget.Toast; import com.owncloud.android.MainApp; import com.owncloud.android.R; @@ -581,7 +582,7 @@ public class FileOperationsHelper { } } - public void setPictureAs(OCFile file) { + public void setPictureAs(OCFile file, View view) { if (file != null) { Context context = MainApp.getAppContext(); Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); @@ -610,7 +611,7 @@ public class FileOperationsHelper { intent.setDataAndType(uri, file.getMimetype()); } catch (ActivityNotFoundException exception) { - Toast.makeText(context, R.string.picture_set_as_no_app, Toast.LENGTH_LONG).show(); + Snackbar.make(view, R.string.picture_set_as_no_app, Snackbar.LENGTH_LONG).show(); } } else { Log_OC.wtf(TAG, "Trying to send a NULL OCFile"); diff --git a/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java b/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java index 42d0cfb3fc..b1f789e54e 100644 --- a/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java @@ -452,7 +452,7 @@ public class PreviewImageFragment extends FileFragment { return true; case R.id.action_set_as_wallpaper: - mContainerActivity.getFileOperationsHelper().setPictureAs(getFile()); + mContainerActivity.getFileOperationsHelper().setPictureAs(getFile(), getImageView()); return true; default: