mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
handle Crop intent for setting contact photo etc
This commit is contained in:
parent
d39926a3c2
commit
7358bb7cce
2 changed files with 33 additions and 3 deletions
|
@ -145,6 +145,18 @@
|
|||
|
||||
<data android:mimeType="image/*"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="com.android.camera.action.CROP"/>
|
||||
|
||||
<data android:scheme="content"/>
|
||||
<data android:scheme="file"/>
|
||||
<data android:mimeType="image/*"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.ALTERNATIVE"/>
|
||||
<category android:name="android.intent.category.SELECTED_ALTERNATIVE"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
|
|
|
@ -2,9 +2,11 @@ package com.simplemobiletools.gallery.activities
|
|||
|
||||
import android.app.Activity
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Bitmap.CompressFormat
|
||||
import android.graphics.Point
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
|
@ -18,8 +20,8 @@ import com.simplemobiletools.gallery.dialogs.SaveAsDialog
|
|||
import com.simplemobiletools.gallery.extensions.getRealPathFromURI
|
||||
import com.theartofdev.edmodo.cropper.CropImageView
|
||||
import kotlinx.android.synthetic.main.view_crop_image.*
|
||||
import java.io.File
|
||||
import java.io.OutputStream
|
||||
import java.io.*
|
||||
|
||||
|
||||
class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener {
|
||||
val TAG = EditActivity::class.java.simpleName
|
||||
|
@ -113,7 +115,23 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
|||
|
||||
override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) {
|
||||
if (result.error == null) {
|
||||
if (uri.scheme == "file") {
|
||||
if (isCropIntent && intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true) {
|
||||
val targetUri = intent.extras!!.get(MediaStore.EXTRA_OUTPUT) as Uri
|
||||
var inputStream: InputStream? = null
|
||||
var outputStream: OutputStream? = null
|
||||
try {
|
||||
val stream = ByteArrayOutputStream()
|
||||
result.bitmap.compress(CompressFormat.JPEG, 100, stream)
|
||||
inputStream = ByteArrayInputStream(stream.toByteArray())
|
||||
outputStream = contentResolver.openOutputStream(targetUri)
|
||||
inputStream.copyTo(outputStream)
|
||||
} finally {
|
||||
inputStream?.close()
|
||||
outputStream?.close()
|
||||
}
|
||||
setResult(RESULT_OK)
|
||||
finish()
|
||||
} else if (uri.scheme == "file") {
|
||||
SaveAsDialog(this, uri.path) {
|
||||
saveBitmapToFile(result.bitmap, it)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue