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
|
import java.io.OutputStream
|
||||||
|
|
||||||
class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener {
|
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
|
lateinit var uri: Uri
|
||||||
var resizeWidth = 0
|
var resizeWidth = 0
|
||||||
var resizeHeight = 0
|
var resizeHeight = 0
|
||||||
|
var isCropIntent = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -45,14 +49,20 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isCropIntent = intent.extras?.get(CROP) == true
|
||||||
|
|
||||||
crop_image_view.apply {
|
crop_image_view.apply {
|
||||||
setOnCropImageCompleteListener(this@EditActivity)
|
setOnCropImageCompleteListener(this@EditActivity)
|
||||||
setImageUriAsync(intent.data)
|
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)
|
menuInflater.inflate(R.menu.menu_editor, menu)
|
||||||
|
menu.findItem(R.id.resize).isVisible = !isCropIntent
|
||||||
return true
|
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? {
|
private fun getAreaSize(): Point? {
|
||||||
val rect = crop_image_view.cropRect ?: return null
|
val rect = crop_image_view.cropRect ?: return null
|
||||||
val rotation = crop_image_view.rotatedDegrees
|
val rotation = crop_image_view.rotatedDegrees
|
||||||
|
|
Loading…
Reference in a new issue