Merge pull request #58 from LonamiWebs/master

Fixed #57 and added auto-detect mime-type when setting wallpaper
This commit is contained in:
Tibor Kaputa 2016-11-14 23:04:52 +01:00 committed by GitHub
commit bfb2bdd5ba
2 changed files with 12 additions and 2 deletions

View File

@ -78,7 +78,7 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete
val wantedHeight = wallpaperManager.desiredMinimumHeight val wantedHeight = wallpaperManager.desiredMinimumHeight
val ratio = wantedHeight / bitmap.height.toFloat() val ratio = wantedHeight / bitmap.height.toFloat()
val wantedWidth = (bitmap.width * ratio).toInt() 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) setResult(Activity.RESULT_OK)
finish() finish()
}).start() }).start()

View File

@ -11,6 +11,7 @@ import android.support.v4.view.ViewPager
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.webkit.MimeTypeMap
import android.widget.RelativeLayout import android.widget.RelativeLayout
import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask
import com.simplemobiletools.filepicker.extensions.* 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() { private fun setAsWallpaper() {
val intent = Intent(Intent.ACTION_ATTACH_DATA) 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)) val chooser = Intent.createChooser(intent, getString(R.string.set_as_wallpaper_with))
if (intent.resolveActivity(packageManager) != null) { if (intent.resolveActivity(packageManager) != null) {