From bb346fbdc0681d5d96b206a7eb124d76158734ce Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 14 Nov 2016 20:32:02 +0100 Subject: [PATCH] Fixed #57 and added auto-detect mime-type when setting wallpaper --- .../gallery/activities/SetWallpaperActivity.kt | 2 +- .../gallery/activities/ViewPagerActivity.kt | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt index 172c6126f..3eb0e3fc7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt @@ -78,7 +78,7 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete val wantedHeight = wallpaperManager.desiredMinimumHeight val ratio = wantedHeight / bitmap.height.toFloat() val wantedWidth = (bitmap.width * ratio).toInt() - wallpaperManager.setBitmap(Bitmap.createScaledBitmap(bitmap, wantedWidth, wantedHeight, false)) + wallpaperManager.setBitmap(Bitmap.createScaledBitmap(bitmap, wantedWidth, wantedHeight, true)) setResult(Activity.RESULT_OK) finish() }).start() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 8c1e40c18..5432a8013 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -11,6 +11,7 @@ import android.support.v4.view.ViewPager import android.view.Menu import android.view.MenuItem import android.view.View +import android.webkit.MimeTypeMap import android.widget.RelativeLayout import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask import com.simplemobiletools.filepicker.extensions.* @@ -200,9 +201,18 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } + private fun getMimeType(url: String): String? { + val extension = MimeTypeMap.getFileExtensionFromUrl(url) + if (extension != null) { + return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) + } + return null + } + private fun setAsWallpaper() { val intent = Intent(Intent.ACTION_ATTACH_DATA) - intent.setDataAndType(Uri.fromFile(getCurrentFile()), "image/jpeg") + val uri = Uri.fromFile(getCurrentFile()) + intent.setDataAndType(uri, getMimeType(uri.toString())) val chooser = Intent.createChooser(intent, getString(R.string.set_as_wallpaper_with)) if (intent.resolveActivity(packageManager) != null) {