diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt index b43f09faa..38d430577 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -16,6 +16,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.dialogs.ResizeDialog import com.simplemobiletools.gallery.dialogs.SaveAsDialog import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.extensions.getCompressionFormat import com.simplemobiletools.gallery.extensions.getRealPathFromURI import com.theartofdev.edmodo.cropper.CropImageView import kotlinx.android.synthetic.main.activity_edit.* @@ -139,9 +140,9 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener if (resizeWidth > 0 && resizeHeight > 0) { val resized = Bitmap.createScaledBitmap(bitmap, resizeWidth, resizeHeight, false) - resized.compress(getCompressionFormat(file), 90, out) + resized.compress(file.getCompressionFormat(), 90, out) } else { - bitmap.compress(getCompressionFormat(file), 90, out) + bitmap.compress(file.getCompressionFormat(), 90, out) } setResult(Activity.RESULT_OK, intent) } catch (e: Exception) { @@ -165,12 +166,4 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener finish() } } - - private fun getCompressionFormat(file: File): Bitmap.CompressFormat { - return when (file.extension.toLowerCase()) { - "png" -> Bitmap.CompressFormat.PNG - "webp" -> Bitmap.CompressFormat.WEBP - else -> Bitmap.CompressFormat.JPEG - } - } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 2d1800b7b..c038662bc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -3,6 +3,9 @@ package com.simplemobiletools.gallery.activities import android.app.Activity import android.content.Intent import android.database.Cursor +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.graphics.Matrix import android.media.ExifInterface import android.net.Uri import android.os.Bundle @@ -30,9 +33,11 @@ import com.simplemobiletools.gallery.helpers.REQUEST_SET_WALLPAPER import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.activity_medium.* import java.io.File +import java.io.FileOutputStream import java.net.URLDecoder import java.util.* + class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, ViewPagerFragment.FragmentListener { private var mMedia = ArrayList() private var mPath = "" @@ -168,8 +173,27 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun saveImageAs() { - SaveAsDialog(this, getCurrentMedium()!!.path) { + val currPath = getCurrentMedium()!!.path + SaveAsDialog(this, currPath) { + var fOut: FileOutputStream? = null + try { + var bitmap = BitmapFactory.decodeFile(currPath) + val matrix = Matrix() + matrix.postRotate(mRotationDegrees) + bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true) + val file = File(it) + fOut = FileOutputStream(file) + bitmap.compress(file.getCompressionFormat(), 90, fOut) + fOut.flush() + toast(R.string.file_saved) + } catch (e: OutOfMemoryError) { + toast(R.string.unknown_error_occurred) + } catch (e: Exception) { + toast(R.string.unknown_error_occurred) + } finally { + fOut?.close() + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt index 4d1e74d41..6a481e4ff 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -15,7 +15,6 @@ import com.simplemobiletools.gallery.helpers.VIDEOS import java.io.File import java.util.* - fun Context.getRealPathFromURI(uri: Uri): String? { var cursor: Cursor? = null try { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/file.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/file.kt new file mode 100644 index 000000000..0a0fbc2ba --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/file.kt @@ -0,0 +1,12 @@ +package com.simplemobiletools.gallery.extensions + +import android.graphics.Bitmap +import java.io.File + +fun File.getCompressionFormat(): Bitmap.CompressFormat { + return when (extension.toLowerCase()) { + "png" -> Bitmap.CompressFormat.PNG + "webp" -> Bitmap.CompressFormat.WEBP + else -> Bitmap.CompressFormat.JPEG + } +} diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 1648fb4cc..e10f78f6d 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -66,6 +66,7 @@ Flip Horizontally Vertically + Out of memory error Simple Wallpaper diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 4b5120a0b..673204edb 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -66,6 +66,7 @@ Flip Horizontally Vertically + Out of memory error Simple Wallpaper diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 33b320516..666abc563 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -66,6 +66,7 @@ Flip Horizontally Vertically + Out of memory error Simple fond d\'écran diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 13b3cf01b..6bdcea353 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -66,6 +66,7 @@ Flip Horizontally Vertically + Out of memory error Sfondo Semplice diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index f5c923497..ea56dec2b 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -66,6 +66,7 @@ Flip Horizontally Vertically + Out of memory error シンプル壁紙 diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 31b7a62f1..ea8fd459e 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -66,6 +66,7 @@ Inverter Horizontalmente Verticalmente + Out of memory error Simple Wallpaper diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index ffdcbf818..337d89174 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -66,6 +66,7 @@ Flip Horizontally Vertically + Out of memory error Простые обои diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index 1d81d77c4..3295a70a4 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -66,6 +66,7 @@ Preklopiť Vodorovne Zvisle + Došlo k chybe s nedostatkom pamäte Jednoduchá tapeta diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index f25666cb2..ca5a6ea81 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -66,6 +66,7 @@ Flip Horizontally Vertically + Out of memory error Bakgrundsbild diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 384a2e8ea..b7bec0624 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -66,6 +66,7 @@ Flip Horizontally Vertically + Out of memory error Simple Wallpaper diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 9dbc231f5..97a153bf5 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -66,6 +66,7 @@ Flip Horizontally Vertically + Out of memory error 簡易桌布 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5bbf91894..c10edfa5d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -66,6 +66,7 @@ Flip Horizontally Vertically + Out of memory error Simple Wallpaper