mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
add simple file saving to viewpager activity
This commit is contained in:
parent
9a9ce890ca
commit
00dc0c16d3
16 changed files with 52 additions and 12 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Medium>()
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -66,6 +66,7 @@
|
|||
<string name="flip">Flip</string>
|
||||
<string name="horizontally">Horizontally</string>
|
||||
<string name="vertically">Vertically</string>
|
||||
<string name="out_of_memory_error">Out of memory error</string>
|
||||
|
||||
<!-- Set wallpaper -->
|
||||
<string name="simple_wallpaper">Simple Wallpaper</string>
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
<string name="flip">Flip</string>
|
||||
<string name="horizontally">Horizontally</string>
|
||||
<string name="vertically">Vertically</string>
|
||||
<string name="out_of_memory_error">Out of memory error</string>
|
||||
|
||||
<!-- Set wallpaper -->
|
||||
<string name="simple_wallpaper">Simple Wallpaper</string>
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
<string name="flip">Flip</string>
|
||||
<string name="horizontally">Horizontally</string>
|
||||
<string name="vertically">Vertically</string>
|
||||
<string name="out_of_memory_error">Out of memory error</string>
|
||||
|
||||
<!-- Set wallpaper -->
|
||||
<string name="simple_wallpaper">Simple fond d\'écran</string>
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
<string name="flip">Flip</string>
|
||||
<string name="horizontally">Horizontally</string>
|
||||
<string name="vertically">Vertically</string>
|
||||
<string name="out_of_memory_error">Out of memory error</string>
|
||||
|
||||
<!-- Set wallpaper -->
|
||||
<string name="simple_wallpaper">Sfondo Semplice</string>
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
<string name="flip">Flip</string>
|
||||
<string name="horizontally">Horizontally</string>
|
||||
<string name="vertically">Vertically</string>
|
||||
<string name="out_of_memory_error">Out of memory error</string>
|
||||
|
||||
<!-- Set wallpaper -->
|
||||
<string name="simple_wallpaper">シンプル壁紙</string>
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
<string name="flip">Inverter</string>
|
||||
<string name="horizontally">Horizontalmente</string>
|
||||
<string name="vertically">Verticalmente</string>
|
||||
<string name="out_of_memory_error">Out of memory error</string>
|
||||
|
||||
<!-- Set wallpaper -->
|
||||
<string name="simple_wallpaper">Simple Wallpaper</string>
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
<string name="flip">Flip</string>
|
||||
<string name="horizontally">Horizontally</string>
|
||||
<string name="vertically">Vertically</string>
|
||||
<string name="out_of_memory_error">Out of memory error</string>
|
||||
|
||||
<!-- Set wallpaper -->
|
||||
<string name="simple_wallpaper">Простые обои</string>
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
<string name="flip">Preklopiť</string>
|
||||
<string name="horizontally">Vodorovne</string>
|
||||
<string name="vertically">Zvisle</string>
|
||||
<string name="out_of_memory_error">Došlo k chybe s nedostatkom pamäte</string>
|
||||
|
||||
<!-- Set wallpaper -->
|
||||
<string name="simple_wallpaper">Jednoduchá tapeta</string>
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
<string name="flip">Flip</string>
|
||||
<string name="horizontally">Horizontally</string>
|
||||
<string name="vertically">Vertically</string>
|
||||
<string name="out_of_memory_error">Out of memory error</string>
|
||||
|
||||
<!-- Set wallpaper -->
|
||||
<string name="simple_wallpaper">Bakgrundsbild</string>
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
<string name="flip">Flip</string>
|
||||
<string name="horizontally">Horizontally</string>
|
||||
<string name="vertically">Vertically</string>
|
||||
<string name="out_of_memory_error">Out of memory error</string>
|
||||
|
||||
<!-- Set wallpaper -->
|
||||
<string name="simple_wallpaper">Simple Wallpaper</string>
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
<string name="flip">Flip</string>
|
||||
<string name="horizontally">Horizontally</string>
|
||||
<string name="vertically">Vertically</string>
|
||||
<string name="out_of_memory_error">Out of memory error</string>
|
||||
|
||||
<!-- Set wallpaper -->
|
||||
<string name="simple_wallpaper">簡易桌布</string>
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
<string name="flip">Flip</string>
|
||||
<string name="horizontally">Horizontally</string>
|
||||
<string name="vertically">Vertically</string>
|
||||
<string name="out_of_memory_error">Out of memory error</string>
|
||||
|
||||
<!-- Set wallpaper -->
|
||||
<string name="simple_wallpaper">Simple Wallpaper</string>
|
||||
|
|
Loading…
Reference in a new issue