mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 00:17:58 +01:00
Fixed #57 and added auto-detect mime-type when setting wallpaper
This commit is contained in:
parent
8e61e46a90
commit
bb346fbdc0
2 changed files with 12 additions and 2 deletions
|
@ -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()
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue