allow croping and rotating the wallpaper before setting
This commit is contained in:
parent
1a7c0861c3
commit
d907e3cef5
11 changed files with 88 additions and 9 deletions
|
@ -75,7 +75,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
toast("${getString(R.string.image_croping_failed)} ${result.error.message}")
|
toast("${getString(R.string.image_editing_failed)} ${result.error.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,77 @@
|
||||||
package com.simplemobiletools.gallery.activities
|
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.os.Bundle
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
import com.simplemobiletools.gallery.R
|
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?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_set_wallpaper)
|
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}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/coordinator_layout"
|
android:id="@+id/coordinator_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@android:color/black">
|
android:background="@android:color/black">
|
||||||
|
|
||||||
|
<com.theartofdev.edmodo.cropper.CropImageView
|
||||||
|
android:id="@+id/crop_image_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:cropInitialCropWindowPaddingRatio="0"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
14
app/src/main/res/menu/menu_set_wallpaper.xml
Normal file
14
app/src/main/res/menu/menu_set_wallpaper.xml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/rotate"
|
||||||
|
android:icon="@mipmap/rotate"
|
||||||
|
android:title="@string/rotate"
|
||||||
|
app:showAsAction="ifRoom"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/save"
|
||||||
|
android:icon="@mipmap/check"
|
||||||
|
android:title="@string/save"
|
||||||
|
app:showAsAction="ifRoom"/>
|
||||||
|
</menu>
|
|
@ -45,7 +45,6 @@
|
||||||
<string name="editor">Editor</string>
|
<string name="editor">Editor</string>
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<string name="rotate">Rotate</string>
|
<string name="rotate">Rotate</string>
|
||||||
<string name="image_croping_failed">Image croping failed:</string>
|
|
||||||
<string name="invalid_image_path">Invalid image path</string>
|
<string name="invalid_image_path">Invalid image path</string>
|
||||||
<string name="image_editing_failed">Image editing failed</string>
|
<string name="image_editing_failed">Image editing failed</string>
|
||||||
<string name="edit_image_with">Edit image with:</string>
|
<string name="edit_image_with">Edit image with:</string>
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
<string name="editor">Editor</string>
|
<string name="editor">Editor</string>
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<string name="rotate">Rotate</string>
|
<string name="rotate">Rotate</string>
|
||||||
<string name="image_croping_failed">Image croping failed:</string>
|
|
||||||
<string name="invalid_image_path">Invalid image path</string>
|
<string name="invalid_image_path">Invalid image path</string>
|
||||||
<string name="image_editing_failed">Image editing failed</string>
|
<string name="image_editing_failed">Image editing failed</string>
|
||||||
<string name="edit_image_with">Edit image with:</string>
|
<string name="edit_image_with">Edit image with:</string>
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
<string name="editor">Editor</string>
|
<string name="editor">Editor</string>
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<string name="rotate">Rotate</string>
|
<string name="rotate">Rotate</string>
|
||||||
<string name="image_croping_failed">Image croping failed:</string>
|
|
||||||
<string name="invalid_image_path">Invalid image path</string>
|
<string name="invalid_image_path">Invalid image path</string>
|
||||||
<string name="image_editing_failed">Image editing failed</string>
|
<string name="image_editing_failed">Image editing failed</string>
|
||||||
<string name="edit_image_with">Edit image with:</string>
|
<string name="edit_image_with">Edit image with:</string>
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
<string name="editor">Editor</string>
|
<string name="editor">Editor</string>
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<string name="rotate">Rotate</string>
|
<string name="rotate">Rotate</string>
|
||||||
<string name="image_croping_failed">Image croping failed:</string>
|
|
||||||
<string name="invalid_image_path">Invalid image path</string>
|
<string name="invalid_image_path">Invalid image path</string>
|
||||||
<string name="image_editing_failed">Image editing failed</string>
|
<string name="image_editing_failed">Image editing failed</string>
|
||||||
<string name="edit_image_with">Edit image with:</string>
|
<string name="edit_image_with">Edit image with:</string>
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
<string name="editor">Editor</string>
|
<string name="editor">Editor</string>
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<string name="rotate">Rotate</string>
|
<string name="rotate">Rotate</string>
|
||||||
<string name="image_croping_failed">Image croping failed:</string>
|
|
||||||
<string name="invalid_image_path">Invalid image path</string>
|
<string name="invalid_image_path">Invalid image path</string>
|
||||||
<string name="image_editing_failed">Image editing failed</string>
|
<string name="image_editing_failed">Image editing failed</string>
|
||||||
<string name="edit_image_with">Edit image with:</string>
|
<string name="edit_image_with">Edit image with:</string>
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
<string name="editor">Editor</string>
|
<string name="editor">Editor</string>
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<string name="rotate">Rotate</string>
|
<string name="rotate">Rotate</string>
|
||||||
<string name="image_croping_failed">Image croping failed:</string>
|
|
||||||
<string name="invalid_image_path">Invalid image path</string>
|
<string name="invalid_image_path">Invalid image path</string>
|
||||||
<string name="image_editing_failed">Image editing failed</string>
|
<string name="image_editing_failed">Image editing failed</string>
|
||||||
<string name="edit_image_with">Edit image with:</string>
|
<string name="edit_image_with">Edit image with:</string>
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
<string name="editor">Editor</string>
|
<string name="editor">Editor</string>
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<string name="rotate">Rotate</string>
|
<string name="rotate">Rotate</string>
|
||||||
<string name="image_croping_failed">Image croping failed:</string>
|
|
||||||
<string name="invalid_image_path">Invalid image path</string>
|
<string name="invalid_image_path">Invalid image path</string>
|
||||||
<string name="image_editing_failed">Image editing failed</string>
|
<string name="image_editing_failed">Image editing failed</string>
|
||||||
<string name="edit_image_with">Edit image with:</string>
|
<string name="edit_image_with">Edit image with:</string>
|
||||||
|
|
Loading…
Reference in a new issue