mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-01-18 22:37:59 +01:00
add background bitmap loading at the editor draw canvas
This commit is contained in:
parent
c44a884a95
commit
bab1211339
2 changed files with 48 additions and 6 deletions
|
@ -18,6 +18,7 @@ import android.widget.RelativeLayout
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.DataSource
|
import com.bumptech.glide.load.DataSource
|
||||||
|
import com.bumptech.glide.load.DecodeFormat
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import com.bumptech.glide.load.engine.GlideException
|
import com.bumptech.glide.load.engine.GlideException
|
||||||
import com.bumptech.glide.request.RequestListener
|
import com.bumptech.glide.request.RequestListener
|
||||||
|
@ -79,8 +80,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
private var isCropIntent = false
|
private var isCropIntent = false
|
||||||
private var isEditingWithThirdParty = false
|
private var isEditingWithThirdParty = false
|
||||||
private var oldExif: ExifInterface? = null
|
private var oldExif: ExifInterface? = null
|
||||||
|
private var filterInitialBitmap: Bitmap? = null
|
||||||
private var initialBitmap: Bitmap? = null
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -195,17 +195,17 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
|
|
||||||
override fun onResourceReady(bitmap: Bitmap?, model: Any?, target: Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
|
override fun onResourceReady(bitmap: Bitmap?, model: Any?, target: Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
|
||||||
val currentFilter = getFiltersAdapter()?.getCurrentFilter()
|
val currentFilter = getFiltersAdapter()?.getCurrentFilter()
|
||||||
if (initialBitmap == null) {
|
if (filterInitialBitmap == null) {
|
||||||
loadCropImageView()
|
loadCropImageView()
|
||||||
bottomCropRotateClicked()
|
bottomCropRotateClicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initialBitmap != null && currentFilter != null && currentFilter.filter.name != getString(R.string.none)) {
|
if (filterInitialBitmap != null && currentFilter != null && currentFilter.filter.name != getString(R.string.none)) {
|
||||||
default_image_view.onGlobalLayout {
|
default_image_view.onGlobalLayout {
|
||||||
applyFilter(currentFilter)
|
applyFilter(currentFilter)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
initialBitmap = bitmap
|
filterInitialBitmap = bitmap
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCropIntent) {
|
if (isCropIntent) {
|
||||||
|
@ -239,6 +239,31 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
default_image_view.beGone()
|
default_image_view.beGone()
|
||||||
crop_image_view.beGone()
|
crop_image_view.beGone()
|
||||||
editor_draw_canvas.beVisible()
|
editor_draw_canvas.beVisible()
|
||||||
|
|
||||||
|
Thread {
|
||||||
|
val size = Point()
|
||||||
|
windowManager.defaultDisplay.getSize(size)
|
||||||
|
val options = RequestOptions()
|
||||||
|
.format(DecodeFormat.PREFER_ARGB_8888)
|
||||||
|
.skipMemoryCache(true)
|
||||||
|
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||||
|
.fitCenter()
|
||||||
|
|
||||||
|
try {
|
||||||
|
val builder = Glide.with(applicationContext)
|
||||||
|
.asBitmap()
|
||||||
|
.load(uri)
|
||||||
|
.apply(options)
|
||||||
|
.into(size.x, size.y)
|
||||||
|
|
||||||
|
val bitmap = builder.get()
|
||||||
|
runOnUiThread {
|
||||||
|
editor_draw_canvas.updateBackgroundBitmap(bitmap)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
showErrorToast(e)
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.N)
|
@TargetApi(Build.VERSION_CODES.N)
|
||||||
|
@ -462,7 +487,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun applyFilter(filterItem: FilterItem) {
|
private fun applyFilter(filterItem: FilterItem) {
|
||||||
val newBitmap = Bitmap.createBitmap(initialBitmap)
|
val newBitmap = Bitmap.createBitmap(filterInitialBitmap)
|
||||||
default_image_view.setImageBitmap(filterItem.filter.processFilter(newBitmap))
|
default_image_view.setImageBitmap(filterItem.filter.processFilter(newBitmap))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,26 @@
|
||||||
package com.simplemobiletools.gallery.pro.views
|
package com.simplemobiletools.gallery.pro.views
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.Canvas
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
|
||||||
class EditorDrawCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
|
class EditorDrawCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
|
||||||
|
private var backgroundBitmap: Bitmap? = null
|
||||||
|
|
||||||
|
override fun onDraw(canvas: Canvas) {
|
||||||
|
super.onDraw(canvas)
|
||||||
|
|
||||||
|
if (backgroundBitmap != null) {
|
||||||
|
val left = (width - backgroundBitmap!!.width) / 2
|
||||||
|
val top = (height - backgroundBitmap!!.height) / 2
|
||||||
|
canvas.drawBitmap(backgroundBitmap, left.toFloat(), top.toFloat(), null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateBackgroundBitmap(bitmap: Bitmap) {
|
||||||
|
backgroundBitmap = bitmap
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue