mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 08:18:00 +01:00
hide Resize option and fix aspect ratio at editor if its a crop intent
This commit is contained in:
parent
ff9e6d9b7c
commit
9b83fb2424
1 changed files with 21 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue