mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 14:37:59 +01:00
save the edited bitmap when done
This commit is contained in:
parent
cae7b9458a
commit
a5def53373
9 changed files with 58 additions and 1 deletions
|
@ -183,6 +183,18 @@ public class ViewPagerActivity extends SimpleActivity
|
||||||
startActivityForResult(intent, EDIT_IMAGE);
|
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() {
|
private void setAsWallpaper() {
|
||||||
final Bitmap bitmap = BitmapFactory.decodeFile(getCurrentFile().getAbsolutePath());
|
final Bitmap bitmap = BitmapFactory.decodeFile(getCurrentFile().getAbsolutePath());
|
||||||
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
|
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
|
||||||
|
|
|
@ -1,14 +1,24 @@
|
||||||
package com.simplemobiletools.gallery.activities
|
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.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.extensions.toast
|
import com.simplemobiletools.gallery.extensions.toast
|
||||||
import com.theartofdev.edmodo.cropper.CropImageView
|
import com.theartofdev.edmodo.cropper.CropImageView
|
||||||
import kotlinx.android.synthetic.main.activity_edit.*
|
import kotlinx.android.synthetic.main.activity_edit.*
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener {
|
class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener {
|
||||||
|
val TAG: String = EditActivity::class.java.simpleName
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_edit)
|
setContentView(R.layout.activity_edit)
|
||||||
|
@ -19,6 +29,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.e("DEBUG", "uri $TAG ${intent.data}")
|
||||||
crop_image_view.apply {
|
crop_image_view.apply {
|
||||||
guidelines = CropImageView.Guidelines.OFF
|
guidelines = CropImageView.Guidelines.OFF
|
||||||
setOnCropImageCompleteListener(this@EditActivity)
|
setOnCropImageCompleteListener(this@EditActivity)
|
||||||
|
@ -47,9 +58,36 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
|
|
||||||
override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) {
|
override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) {
|
||||||
if (result.error == null) {
|
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 {
|
} else {
|
||||||
toast("${getString(R.string.image_croping_failed)} ${result.error.message}")
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
<string name="rotate">Rotate</string>
|
<string name="rotate">Rotate</string>
|
||||||
<string name="image_croping_failed">Image croping failed:</string>
|
<string name="image_croping_failed">Image croping failed:</string>
|
||||||
<string name="invalid_image_path">Invalid image path</string>
|
<string name="invalid_image_path">Invalid image path</string>
|
||||||
|
<string name="image_editing_failed">Image editing failed</string>
|
||||||
|
|
||||||
<!-- About -->
|
<!-- About -->
|
||||||
<string name="about">Über</string>
|
<string name="about">Über</string>
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
<string name="rotate">Rotate</string>
|
<string name="rotate">Rotate</string>
|
||||||
<string name="image_croping_failed">Image croping failed:</string>
|
<string name="image_croping_failed">Image croping failed:</string>
|
||||||
<string name="invalid_image_path">Invalid image path</string>
|
<string name="invalid_image_path">Invalid image path</string>
|
||||||
|
<string name="image_editing_failed">Image editing failed</string>
|
||||||
|
|
||||||
<!-- About -->
|
<!-- About -->
|
||||||
<string name="about">Acerca de</string>
|
<string name="about">Acerca de</string>
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
<string name="rotate">Rotate</string>
|
<string name="rotate">Rotate</string>
|
||||||
<string name="image_croping_failed">Image croping failed:</string>
|
<string name="image_croping_failed">Image croping failed:</string>
|
||||||
<string name="invalid_image_path">Invalid image path</string>
|
<string name="invalid_image_path">Invalid image path</string>
|
||||||
|
<string name="image_editing_failed">Image editing failed</string>
|
||||||
|
|
||||||
<!-- About -->
|
<!-- About -->
|
||||||
<string name="about">Informazioni</string>
|
<string name="about">Informazioni</string>
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
<string name="rotate">Rotate</string>
|
<string name="rotate">Rotate</string>
|
||||||
<string name="image_croping_failed">Image croping failed:</string>
|
<string name="image_croping_failed">Image croping failed:</string>
|
||||||
<string name="invalid_image_path">Invalid image path</string>
|
<string name="invalid_image_path">Invalid image path</string>
|
||||||
|
<string name="image_editing_failed">Image editing failed</string>
|
||||||
|
|
||||||
<!-- About -->
|
<!-- About -->
|
||||||
<string name="about">アプリについて</string>
|
<string name="about">アプリについて</string>
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
<string name="rotate">Rotate</string>
|
<string name="rotate">Rotate</string>
|
||||||
<string name="image_croping_failed">Image croping failed:</string>
|
<string name="image_croping_failed">Image croping failed:</string>
|
||||||
<string name="invalid_image_path">Invalid image path</string>
|
<string name="invalid_image_path">Invalid image path</string>
|
||||||
|
<string name="image_editing_failed">Image editing failed</string>
|
||||||
|
|
||||||
<!-- About -->
|
<!-- About -->
|
||||||
<string name="about">Sobre</string>
|
<string name="about">Sobre</string>
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
<string name="rotate">Rotate</string>
|
<string name="rotate">Rotate</string>
|
||||||
<string name="image_croping_failed">Image croping failed:</string>
|
<string name="image_croping_failed">Image croping failed:</string>
|
||||||
<string name="invalid_image_path">Invalid image path</string>
|
<string name="invalid_image_path">Invalid image path</string>
|
||||||
|
<string name="image_editing_failed">Image editing failed</string>
|
||||||
|
|
||||||
<!-- About -->
|
<!-- About -->
|
||||||
<string name="about">Om</string>
|
<string name="about">Om</string>
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
<string name="rotate">Rotate</string>
|
<string name="rotate">Rotate</string>
|
||||||
<string name="image_croping_failed">Image croping failed:</string>
|
<string name="image_croping_failed">Image croping failed:</string>
|
||||||
<string name="invalid_image_path">Invalid image path</string>
|
<string name="invalid_image_path">Invalid image path</string>
|
||||||
|
<string name="image_editing_failed">Image editing failed</string>
|
||||||
|
|
||||||
<!-- About -->
|
<!-- About -->
|
||||||
<string name="about">About</string>
|
<string name="about">About</string>
|
||||||
|
|
Loading…
Reference in a new issue