save the edited bitmap when done

This commit is contained in:
tibbi 2016-10-06 19:54:09 +02:00
parent cae7b9458a
commit a5def53373
9 changed files with 58 additions and 1 deletions

View file

@ -183,6 +183,18 @@ public class ViewPagerActivity extends SimpleActivity
startActivityForResult(intent, EDIT_IMAGE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == EDIT_IMAGE) {
if (resultCode == RESULT_OK && data != null) {
} else {
Utils.showToast(getApplicationContext(), R.string.image_editing_failed);
}
}
super.onActivityResult(requestCode, resultCode, data);
}
private void setAsWallpaper() {
final Bitmap bitmap = BitmapFactory.decodeFile(getCurrentFile().getAbsolutePath());
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());

View file

@ -1,14 +1,24 @@
package com.simplemobiletools.gallery.activities
import android.app.Activity
import android.graphics.Bitmap
import android.media.MediaScannerConnection
import android.net.Uri
import android.os.Bundle
import android.util.Log
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.*
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener {
val TAG: String = EditActivity::class.java.simpleName
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_edit)
@ -19,6 +29,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
return
}
Log.e("DEBUG", "uri $TAG ${intent.data}")
crop_image_view.apply {
guidelines = CropImageView.Guidelines.OFF
setOnCropImageCompleteListener(this@EditActivity)
@ -47,9 +58,36 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) {
if (result.error == null) {
val bitmap = result.bitmap
val path = intent.data.path
val file = File(path)
var out: FileOutputStream? = null
try {
out = FileOutputStream(file)
result.bitmap.compress(getFileExtension(file), 100, out)
setResult(Activity.RESULT_OK, intent)
} catch (e: Exception) {
Log.e(TAG, "Crop compressing failed $e")
} finally {
try {
out?.close()
} catch (e: IOException) {
Log.e(TAG, "FileOutputStream closing failed $e")
}
}
MediaScannerConnection.scanFile(applicationContext, arrayOf(path), null, { s: String, uri: Uri ->
finish()
})
} else {
toast("${getString(R.string.image_croping_failed)} ${result.error.message}")
}
}
private fun getFileExtension(file: File): Bitmap.CompressFormat {
return when (file.extension) {
"png" -> Bitmap.CompressFormat.PNG
"webp" -> Bitmap.CompressFormat.WEBP
else -> Bitmap.CompressFormat.JPEG
}
}
}

View file

@ -49,6 +49,7 @@
<string name="rotate">Rotate</string>
<string name="image_croping_failed">Image croping failed:</string>
<string name="invalid_image_path">Invalid image path</string>
<string name="image_editing_failed">Image editing failed</string>
<!-- About -->
<string name="about">Über</string>

View file

@ -49,6 +49,7 @@
<string name="rotate">Rotate</string>
<string name="image_croping_failed">Image croping failed:</string>
<string name="invalid_image_path">Invalid image path</string>
<string name="image_editing_failed">Image editing failed</string>
<!-- About -->
<string name="about">Acerca de</string>

View file

@ -49,6 +49,7 @@
<string name="rotate">Rotate</string>
<string name="image_croping_failed">Image croping failed:</string>
<string name="invalid_image_path">Invalid image path</string>
<string name="image_editing_failed">Image editing failed</string>
<!-- About -->
<string name="about">Informazioni</string>

View file

@ -49,6 +49,7 @@
<string name="rotate">Rotate</string>
<string name="image_croping_failed">Image croping failed:</string>
<string name="invalid_image_path">Invalid image path</string>
<string name="image_editing_failed">Image editing failed</string>
<!-- About -->
<string name="about">アプリについて</string>

View file

@ -49,6 +49,7 @@
<string name="rotate">Rotate</string>
<string name="image_croping_failed">Image croping failed:</string>
<string name="invalid_image_path">Invalid image path</string>
<string name="image_editing_failed">Image editing failed</string>
<!-- About -->
<string name="about">Sobre</string>

View file

@ -49,6 +49,7 @@
<string name="rotate">Rotate</string>
<string name="image_croping_failed">Image croping failed:</string>
<string name="invalid_image_path">Invalid image path</string>
<string name="image_editing_failed">Image editing failed</string>
<!-- About -->
<string name="about">Om</string>

View file

@ -49,6 +49,7 @@
<string name="rotate">Rotate</string>
<string name="image_croping_failed">Image croping failed:</string>
<string name="invalid_image_path">Invalid image path</string>
<string name="image_editing_failed">Image editing failed</string>
<!-- About -->
<string name="about">About</string>