crop the image on pressing Save

This commit is contained in:
tibbi 2016-10-05 22:07:32 +02:00
parent 1e4c1206cc
commit 5a7d5ac2e7
9 changed files with 60 additions and 22 deletions

View file

@ -4,16 +4,18 @@ 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 EditActivity : SimpleActivity() {
class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_edit)
crop_image_view.apply {
guidelines = CropImageView.Guidelines.OFF
setOnCropImageCompleteListener(this@EditActivity)
}
}
@ -25,6 +27,7 @@ class EditActivity : SimpleActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.save -> {
crop_image_view.getCroppedImageAsync()
return true
}
R.id.rotate -> {
@ -34,4 +37,12 @@ class EditActivity : SimpleActivity() {
}
return super.onOptionsItemSelected(item)
}
override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) {
if (result.error == null) {
val bitmap = result.bitmap
} else {
toast("${getString(R.string.image_croping_failed)} ${result.error.message}")
}
}
}

View file

@ -0,0 +1,6 @@
package com.simplemobiletools.gallery.extensions
import android.content.Context
import android.widget.Toast
fun Context.toast(msg: String, duration: Int = Toast.LENGTH_SHORT) = Toast.makeText(this, msg, duration).show()

View file

@ -31,9 +31,6 @@
<string name="cancel">Abbrechen</string>
<string name="set_as_wallpaper">Als Hintergrundbild setzen</string>
<string name="set_as_wallpaper_failed">Setzen des Hintergrundbildes fehlgeschlagen</string>
<string name="editor">Editor</string>
<string name="save">Save</string>
<string name="rotate">Rotate</string>
<plurals name="folders_deleted">
<item quantity="one">1 Ordner gelöscht</item>
@ -45,6 +42,12 @@
<item quantity="other">%1$d Dateien gelöscht</item>
</plurals>
<!-- Editor -->
<string name="editor">Editor</string>
<string name="save">Save</string>
<string name="rotate">Rotate</string>
<string name="image_croping_failed">Image croping failed:</string>
<!-- About -->
<string name="about">Über</string>
<string name="website">Weitere einfache Apps und Quellcode findest du auf:\nhttp://simplemobiletools.com</string>

View file

@ -31,9 +31,6 @@
<string name="cancel">Cancelar</string>
<string name="set_as_wallpaper">Establecer como fondo de pantalla</string>
<string name="set_as_wallpaper_failed">Error al establecer fondo de pantalla</string>
<string name="editor">Editor</string>
<string name="save">Save</string>
<string name="rotate">Rotate</string>
<plurals name="folders_deleted">
<item quantity="one">1 carpeta eliminada</item>
@ -45,6 +42,12 @@
<item quantity="other">%1$d archivos eliminados</item>
</plurals>
<!-- Editor -->
<string name="editor">Editor</string>
<string name="save">Save</string>
<string name="rotate">Rotate</string>
<string name="image_croping_failed">Image croping failed:</string>
<!-- About -->
<string name="about">Acerca de</string>
<string name="website">Más aplicaciones sencillas y código fuente en:\nhttp://simplemobiletools.com</string>

View file

@ -31,9 +31,6 @@
<string name="cancel">Cancel</string>
<string name="set_as_wallpaper">Set as Wallpaper</string>
<string name="set_as_wallpaper_failed">Setting as Wallpaper failed</string>
<string name="editor">Editor</string>
<string name="save">Save</string>
<string name="rotate">Rotate</string>
<plurals name="folders_deleted">
<item quantity="one">1 cartella eliminata</item>
@ -45,6 +42,12 @@
<item quantity="other">%1$d file eliminati</item>
</plurals>
<!-- Editor -->
<string name="editor">Editor</string>
<string name="save">Save</string>
<string name="rotate">Rotate</string>
<string name="image_croping_failed">Image croping failed:</string>
<!-- About -->
<string name="about">Informazioni</string>
<string name="website">Altre semplici app e codici sorgenti in:\nhttp://simplemobiletools.com</string>

View file

@ -31,9 +31,6 @@
<string name="cancel">Cancel</string>
<string name="set_as_wallpaper">Set as Wallpaper</string>
<string name="set_as_wallpaper_failed">Setting as Wallpaper failed</string>
<string name="editor">Editor</string>
<string name="save">Save</string>
<string name="rotate">Rotate</string>
<plurals name="folders_deleted">
<item quantity="one">1 フォルダーを削除しました</item>
@ -45,6 +42,12 @@
<item quantity="other">%1$d ファイルを削除しました</item>
</plurals>
<!-- Editor -->
<string name="editor">Editor</string>
<string name="save">Save</string>
<string name="rotate">Rotate</string>
<string name="image_croping_failed">Image croping failed:</string>
<!-- About -->
<string name="about">アプリについて</string>
<string name="website">もっとシンプルなアプリとソースコードは:\nhttp://simplemobiletools.com</string>

View file

@ -31,9 +31,6 @@
<string name="cancel">Cancelar</string>
<string name="set_as_wallpaper">Definir como fundo de ecrã</string>
<string name="set_as_wallpaper_failed">Falha ao definir como fundo de ecrã</string>
<string name="editor">Editor</string>
<string name="save">Save</string>
<string name="rotate">Rotate</string>
<plurals name="folders_deleted">
<item quantity="one">1 pasta eliminada</item>
@ -45,6 +42,12 @@
<item quantity="other">%1$d ficheiros eliminados</item>
</plurals>
<!-- Editor -->
<string name="editor">Editor</string>
<string name="save">Save</string>
<string name="rotate">Rotate</string>
<string name="image_croping_failed">Image croping failed:</string>
<!-- About -->
<string name="about">Sobre</string>
<string name="website">Mais aplicações simples e código de fonte em:\nhttp://simplemobiletools.com</string>

View file

@ -31,9 +31,6 @@
<string name="cancel">Cancel</string>
<string name="set_as_wallpaper">Set as Wallpaper</string>
<string name="set_as_wallpaper_failed">Setting as Wallpaper failed</string>
<string name="editor">Editor</string>
<string name="save">Save</string>
<string name="rotate">Rotate</string>
<plurals name="folders_deleted">
<item quantity="one">1 mapp borttagen</item>
@ -45,6 +42,12 @@
<item quantity="other">%1$d filer borttagna</item>
</plurals>
<!-- Editor -->
<string name="editor">Editor</string>
<string name="save">Save</string>
<string name="rotate">Rotate</string>
<string name="image_croping_failed">Image croping failed:</string>
<!-- About -->
<string name="about">Om</string>
<string name="website">Fler enkla appar och källkod här:\nhttp://simplemobiletools.com</string>

View file

@ -31,9 +31,6 @@
<string name="cancel">Cancel</string>
<string name="set_as_wallpaper">Set as Wallpaper</string>
<string name="set_as_wallpaper_failed">Setting as Wallpaper failed</string>
<string name="editor">Editor</string>
<string name="save">Save</string>
<string name="rotate">Rotate</string>
<plurals name="folders_deleted">
<item quantity="one">1 folder deleted</item>
@ -45,6 +42,12 @@
<item quantity="other">%1$d files deleted</item>
</plurals>
<!-- Editor -->
<string name="editor">Editor</string>
<string name="save">Save</string>
<string name="rotate">Rotate</string>
<string name="image_croping_failed">Image croping failed:</string>
<!-- About -->
<string name="about">About</string>
<string name="website">More simple apps and source code at:\nhttp://simplemobiletools.com</string>