From 5a7d5ac2e74303d3e733186d5f7d9562c075bd29 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 5 Oct 2016 22:07:32 +0200 Subject: [PATCH] crop the image on pressing Save --- .../gallery/activities/EditActivity.kt | 13 ++++++++++++- .../simplemobiletools/gallery/extensions/context.kt | 6 ++++++ app/src/main/res/values-de/strings.xml | 9 ++++++--- app/src/main/res/values-es/strings.xml | 9 ++++++--- app/src/main/res/values-it/strings.xml | 9 ++++++--- app/src/main/res/values-ja/strings.xml | 9 ++++++--- app/src/main/res/values-pt-rPT/strings.xml | 9 ++++++--- app/src/main/res/values-sv/strings.xml | 9 ++++++--- app/src/main/res/values/strings.xml | 9 ++++++--- 9 files changed, 60 insertions(+), 22 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt 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 324c65b98..b167bc5a8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -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}") + } + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt new file mode 100644 index 000000000..bb8f3a1c8 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -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() diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index d78f6b4ce..b07aac177 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -31,9 +31,6 @@ Abbrechen Als Hintergrundbild setzen Setzen des Hintergrundbildes fehlgeschlagen - Editor - Save - Rotate 1 Ordner gelöscht @@ -45,6 +42,12 @@ %1$d Dateien gelöscht + + Editor + Save + Rotate + Image croping failed: + Über Weitere einfache Apps und Quellcode findest du auf:\nhttp://simplemobiletools.com diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index eb583f56e..9cdfc704a 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -31,9 +31,6 @@ Cancelar Establecer como fondo de pantalla Error al establecer fondo de pantalla - Editor - Save - Rotate 1 carpeta eliminada @@ -45,6 +42,12 @@ %1$d archivos eliminados + + Editor + Save + Rotate + Image croping failed: + Acerca de Más aplicaciones sencillas y código fuente en:\nhttp://simplemobiletools.com diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index ec804079c..e28a72fb5 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -31,9 +31,6 @@ Cancel Set as Wallpaper Setting as Wallpaper failed - Editor - Save - Rotate 1 cartella eliminata @@ -45,6 +42,12 @@ %1$d file eliminati + + Editor + Save + Rotate + Image croping failed: + Informazioni Altre semplici app e codici sorgenti in:\nhttp://simplemobiletools.com diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 6bce47a03..a0cbd8649 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -31,9 +31,6 @@ Cancel Set as Wallpaper Setting as Wallpaper failed - Editor - Save - Rotate 1 フォルダーを削除しました @@ -45,6 +42,12 @@ %1$d ファイルを削除しました + + Editor + Save + Rotate + Image croping failed: + アプリについて もっとシンプルなアプリとソースコードは:\nhttp://simplemobiletools.com diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 8a10cc308..3cd4979f8 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -31,9 +31,6 @@ Cancelar Definir como fundo de ecrã Falha ao definir como fundo de ecrã - Editor - Save - Rotate 1 pasta eliminada @@ -45,6 +42,12 @@ %1$d ficheiros eliminados + + Editor + Save + Rotate + Image croping failed: + Sobre Mais aplicações simples e código de fonte em:\nhttp://simplemobiletools.com diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index d67e9366a..6cdc45619 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -31,9 +31,6 @@ Cancel Set as Wallpaper Setting as Wallpaper failed - Editor - Save - Rotate 1 mapp borttagen @@ -45,6 +42,12 @@ %1$d filer borttagna + + Editor + Save + Rotate + Image croping failed: + Om Fler enkla appar och källkod här:\nhttp://simplemobiletools.com diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 65c4cfa39..aad0c6d9e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -31,9 +31,6 @@ Cancel Set as Wallpaper Setting as Wallpaper failed - Editor - Save - Rotate 1 folder deleted @@ -45,6 +42,12 @@ %1$d files deleted + + Editor + Save + Rotate + Image croping failed: + About More simple apps and source code at:\nhttp://simplemobiletools.com