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 @@ + + diff --git a/app/src/main/res/menu/menu_set_wallpaper.xml b/app/src/main/res/menu/menu_set_wallpaper.xml new file mode 100644 index 000000000..d1ffb1215 --- /dev/null +++ b/app/src/main/res/menu/menu_set_wallpaper.xml @@ -0,0 +1,14 @@ + + + + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 2c11a7dcf..dfb2e64a7 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -45,7 +45,6 @@ Editor Save Rotate - Image croping failed: Invalid image path Image editing failed Edit image with: diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index f7cfa551f..4efab98c2 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -45,7 +45,6 @@ Editor Save Rotate - Image croping failed: Invalid image path Image editing failed Edit image with: diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index e3b61abee..38d6784f8 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -45,7 +45,6 @@ Editor Save Rotate - Image croping failed: Invalid image path Image editing failed Edit image with: diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index f3eb86a7a..e00414b17 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -45,7 +45,6 @@ Editor Save Rotate - Image croping failed: Invalid image path Image editing failed Edit image with: diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index d9f7ab405..46647600e 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -45,7 +45,6 @@ Editor Save Rotate - Image croping failed: Invalid image path Image editing failed Edit image with: diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index beaec85d8..589a4c7d1 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -45,7 +45,6 @@ Editor Save Rotate - Image croping failed: Invalid image path Image editing failed Edit image with: diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 165306346..e0d0c7253 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -45,7 +45,6 @@ Editor Save Rotate - Image croping failed: Invalid image path Image editing failed Edit image with: