From 9b83fb24244ad54f9582d13fd5c9524e6b3af511 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 26 May 2017 10:23:19 +0200 Subject: [PATCH] hide Resize option and fix aspect ratio at editor if its a crop intent --- .../gallery/activities/EditActivity.kt | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) 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 d9dfdf39e..e860cce52 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -22,11 +22,15 @@ import java.io.File import java.io.OutputStream class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener { - val TAG: String = EditActivity::class.java.simpleName + val TAG = EditActivity::class.java.simpleName + val ASPECT_X = "aspectX" + val ASPECT_Y = "aspectY" + val CROP = "crop" lateinit var uri: Uri var resizeWidth = 0 var resizeHeight = 0 + var isCropIntent = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -45,14 +49,20 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener return } + isCropIntent = intent.extras?.get(CROP) == true + crop_image_view.apply { setOnCropImageCompleteListener(this@EditActivity) setImageUriAsync(intent.data) + + if (isCropIntent && shouldCropSquare()) + setFixedAspectRatio(true) } } - override fun onCreateOptionsMenu(menu: Menu?): Boolean { + override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_editor, menu) + menu.findItem(R.id.resize).isVisible = !isCropIntent return true } @@ -82,6 +92,15 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener } } + private fun shouldCropSquare(): Boolean { + val extras = intent.extras + return if (extras != null && extras.containsKey(ASPECT_X) && extras.containsKey(ASPECT_Y)) { + extras.getInt(ASPECT_X) == extras.getInt(ASPECT_Y) + } else { + false + } + } + private fun getAreaSize(): Point? { val rect = crop_image_view.cropRect ?: return null val rotation = crop_image_view.rotatedDegrees