diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt
index e636f8263..8c88743e7 100644
--- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt
@@ -75,7 +75,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
finish()
}
} else {
- toast("${getString(R.string.image_croping_failed)} ${result.error.message}")
+ toast("${getString(R.string.image_editing_failed)} ${result.error.message}")
}
}
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 14201f1ac..2e8161a79 100644
--- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt
@@ -1,12 +1,77 @@
package com.simplemobiletools.gallery.activities
+import android.app.Activity
+import android.app.WallpaperManager
+import android.graphics.Bitmap
+import android.net.Uri
import android.os.Bundle
+import android.view.Menu
+import android.view.MenuItem
import com.simplemobiletools.gallery.R
+import com.simplemobiletools.gallery.extensions.toast
+import com.theartofdev.edmodo.cropper.CropImageView
+import kotlinx.android.synthetic.main.activity_edit.*
-class SetWallpaperActivity : SimpleActivity() {
+class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener {
+ lateinit var uri: Uri
+ lateinit var wallpaperManager: WallpaperManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_set_wallpaper)
+
+ if (intent.data == null) {
+ toast(R.string.invalid_image_path)
+ finish()
+ return
+ }
+
+ uri = intent.data
+ if (uri.scheme != "file" && uri.scheme != "content") {
+ toast(R.string.unknown_file_location)
+ finish()
+ return
+ }
+
+ wallpaperManager = WallpaperManager.getInstance(applicationContext)
+ crop_image_view.apply {
+ guidelines = CropImageView.Guidelines.OFF
+ setOnCropImageCompleteListener(this@SetWallpaperActivity)
+ setImageUriAsync(intent.data)
+ setAspectRatio(wallpaperManager.desiredMinimumWidth, wallpaperManager.desiredMinimumHeight)
+ }
+ }
+
+ override fun onCreateOptionsMenu(menu: Menu?): Boolean {
+ menuInflater.inflate(R.menu.menu_set_wallpaper, menu)
+ return true
+ }
+
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ when (item.itemId) {
+ R.id.save -> {
+ crop_image_view.getCroppedImageAsync()
+ return true
+ }
+ R.id.rotate -> {
+ crop_image_view.rotateImage(90)
+ return true
+ }
+ }
+ return super.onOptionsItemSelected(item)
+ }
+
+ override fun onCropImageComplete(view: CropImageView?, result: CropImageView.CropResult) {
+ if (result.error == null) {
+ val bitmap = result.bitmap
+ val wantedHeight = wallpaperManager.desiredMinimumHeight
+ val ratio = wantedHeight / bitmap.height.toFloat()
+ val wantedWidth = (bitmap.width * ratio).toInt()
+ wallpaperManager.setBitmap(Bitmap.createScaledBitmap(bitmap, wantedWidth, wantedHeight, false))
+ setResult(Activity.RESULT_OK)
+ finish()
+ } else {
+ toast("${getString(R.string.image_editing_failed)}: ${result.error.message}")
+ }
}
}
diff --git a/app/src/main/res/layout/activity_set_wallpaper.xml b/app/src/main/res/layout/activity_set_wallpaper.xml
index 93d6c62b4..27a8ba280 100644
--- a/app/src/main/res/layout/activity_set_wallpaper.xml
+++ b/app/src/main/res/layout/activity_set_wallpaper.xml
@@ -1,9 +1,16 @@