Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pinch to zoom / implemented Glide loading with FitCenter or CenterCrop #651

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c7dea6c
using jp.wasabeef:glide-transformations library to add blurried image…
mzorz Mar 2, 2021
b7b861d
fixed merge conflict
mzorz Mar 3, 2021
5b2e0bd
fixed merge conflicts
mzorz Mar 3, 2021
7d77250
added method onComposerDestroyed so we can avoid trying to load any i…
mzorz Mar 3, 2021
f99c31a
adding blurry image background loading when saving the output file, r…
mzorz Mar 3, 2021
d28da3a
fixed lint error
mzorz Mar 3, 2021
8c90aca
implemented Glide loading with FitCenter or CenterCrop transforms acc…
mzorz Mar 5, 2021
2c07104
changed wording in comment
mzorz Mar 8, 2021
ce82e45
split method into two parts to avoid recursion, using coroutines to f…
mzorz Mar 8, 2021
02f9890
passing bitmap on glide second pass so it doesn't need be fetched and…
mzorz Mar 8, 2021
3da9844
using Drawable instead of bitmap, will be easier to use in the future…
mzorz Mar 9, 2021
3ec01b3
removed ResourceLoader interface, replaced with simpler ImageLoadedIn…
mzorz Mar 9, 2021
a654693
several improvements: only loading futurTarget to as max as the scree…
mzorz Mar 10, 2021
92ccda0
removed unused functions
mzorz Mar 10, 2021
089917a
removed commented code
mzorz Mar 10, 2021
6b440d5
passing scaleType in BackgroundViewInfo, also now calculating screenH…
mzorz Mar 10, 2021
d2aa125
added more comments
mzorz Mar 10, 2021
dab1ca8
setting scaleType and transform on ghost view when exporting, accordi…
mzorz Mar 10, 2021
b9cbe5b
no need to clear the futureTarget after we're done given it's used an…
mzorz Mar 10, 2021
e1b7179
using FIT_START for drawables wider than screen, and FIT_CENTER for d…
mzorz Mar 10, 2021
f64aaf6
moved normalizedSize calculation up so it's always available
mzorz Mar 10, 2021
c434730
fixed lint warnings
mzorz Mar 10, 2021
cc43955
we want the bottom_opaque_bar visible at all times while editing, it …
mzorz Mar 10, 2021
4fc499a
added newline before EOF
mzorz Mar 10, 2021
029163b
Merge branch 'issue/646-zoom-in-bkg-pictures-fit-center-limit-pos-new…
mzorz Mar 10, 2021
ad2fca5
setting backgroundImageBlurred visibility when turning TexturView on/off
mzorz Mar 18, 2021
e694661
Merge pull request #650 from Automattic/issue/646-zoom-in-bkg-picture…
mzorz Mar 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions photoeditor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ dependencies {
implementation 'com.github.bumptech.glide:glide:4.10.0'
kapt 'com.github.bumptech.glide:compiler:4.10.0'

implementation 'jp.wasabeef:glide-transformations:4.3.0'

implementation 'com.github.chrisbanes:PhotoView:2.3.0'

implementation project(path: ':mp4compose')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import android.view.TextureView.SurfaceTextureListener
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.ImageView.ScaleType.CENTER_CROP
import android.widget.ImageView.ScaleType.FIT_CENTER
import android.widget.ProgressBar
import android.widget.RelativeLayout
import androidx.annotation.RequiresApi
import androidx.appcompat.widget.AppCompatImageView
import com.automattic.photoeditor.OnSaveBitmap
import com.automattic.photoeditor.R.styleable
import com.automattic.photoeditor.views.background.fixed.BackgroundImageView
Expand All @@ -24,6 +26,9 @@ import com.automattic.photoeditor.views.brush.BrushDrawingView
import com.automattic.photoeditor.views.filter.CustomEffect
import com.automattic.photoeditor.views.filter.ImageFilterView
import com.automattic.photoeditor.views.filter.PhotoFilter
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import jp.wasabeef.glide.transformations.BlurTransformation

/**
*
Expand All @@ -40,9 +45,11 @@ import com.automattic.photoeditor.views.filter.PhotoFilter
class PhotoEditorView : RelativeLayout {
private lateinit var autoFitTextureView: AutoFitTextureView
private lateinit var backgroundImage: BackgroundImageView
private lateinit var backgroundImageBlurred: AppCompatImageView
private lateinit var brushDrawingView: BrushDrawingView
private lateinit var imageFilterView: ImageFilterView
private lateinit var progressBar: ProgressBar
private var attachedToWindow: Boolean = false

private var surfaceListeners: ArrayList<SurfaceTextureListener> = ArrayList()

Expand Down Expand Up @@ -72,6 +79,9 @@ class PhotoEditorView : RelativeLayout {
val source: ImageView
get() = backgroundImage

val sourceBlurredBkg: ImageView
get() = backgroundImageBlurred

val brush: BrushDrawingView
get() = brushDrawingView

Expand Down Expand Up @@ -103,8 +113,28 @@ class PhotoEditorView : RelativeLayout {
init(attrs)
}

override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
attachedToWindow = false
}

override fun onAttachedToWindow() {
super.onAttachedToWindow()
attachedToWindow = true
}

fun onComposerDestroyed() {
attachedToWindow = false
}

@SuppressLint("Recycle")
private fun init(attrs: AttributeSet?) {
backgroundImageBlurred = AppCompatImageView(context).apply {
id = imgBlurSrcId
adjustViewBounds = true
scaleType = CENTER_CROP
}

// Setup image attributes
backgroundImage = BackgroundImageView(context).apply {
id = imgSrcId
Expand Down Expand Up @@ -159,6 +189,11 @@ class PhotoEditorView : RelativeLayout {

backgroundImage.setOnImageChangedListener(object : BackgroundImageView.OnImageChangedListener {
override fun onBitmapLoaded(sourceBitmap: Bitmap?) {
if (attachedToWindow) {
Glide.with(context).load(sourceBitmap)
.apply(RequestOptions.bitmapTransform(BlurTransformation(25, 3)))
.into(backgroundImageBlurred)
}
imageFilterView.setFilterEffect(PhotoFilter.NONE)
imageFilterView.setSourceBitmap(sourceBitmap)
Log.d(TAG, "onBitmapLoaded() called with: sourceBitmap = [$sourceBitmap]")
Expand All @@ -179,6 +214,9 @@ class PhotoEditorView : RelativeLayout {
// Add camera preview
addView(autoFitTextureView, cameraParam)

// Add image source
addView(backgroundImageBlurred, imgSrcParam)

// Add image source
addView(backgroundImage, imgSrcParam)

Expand Down Expand Up @@ -254,23 +292,27 @@ class PhotoEditorView : RelativeLayout {

internal fun turnTextureViewOn() {
backgroundImage.visibility = View.INVISIBLE
backgroundImageBlurred.visibility = View.INVISIBLE
autoFitTextureView.visibility = View.VISIBLE
}

internal fun turnTextureViewOff() {
backgroundImage.visibility = View.VISIBLE
backgroundImageBlurred.visibility = View.VISIBLE
autoFitTextureView.visibility = View.INVISIBLE
}

internal fun toggleTextureView(): Boolean {
backgroundImage.visibility = autoFitTextureView.visibility.also {
autoFitTextureView.visibility = backgroundImage.visibility
}
backgroundImageBlurred.visibility = backgroundImage.visibility
return autoFitTextureView.visibility == View.VISIBLE
}

internal fun turnTextureAndImageViewOff() {
backgroundImage.visibility = View.INVISIBLE
backgroundImageBlurred.visibility = View.INVISIBLE
autoFitTextureView.visibility = View.INVISIBLE
}

Expand All @@ -286,6 +328,7 @@ class PhotoEditorView : RelativeLayout {

companion object {
private val TAG = "PhotoEditorView"
private val imgBlurSrcId = 5
private val imgSrcId = 1
private val brushSrcId = 2
private val glFilterId = 3
Expand Down
2 changes: 2 additions & 0 deletions stories/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ dependencies {
implementation 'com.github.bumptech.glide:glide:4.10.0'
kapt 'com.github.bumptech.glide:compiler:4.10.0'

implementation 'jp.wasabeef:glide-transformations:4.3.0'

implementation 'org.greenrobot:eventbus:3.1.1'

implementation project(path: ':photoeditor')
Expand Down
Loading