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

Pan / zoom background images #647

Merged
merged 55 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
74997dd
using Chris Banes' PhotoView for the BackgroundImageView, to provide …
mzorz Feb 23, 2021
ca897d7
save the original ImageMatrix and set it on the ghostPhotoView after …
mzorz Feb 23, 2021
50a78bf
added BackgroundViewInfo data class to remember backing support Photo…
mzorz Feb 24, 2021
47f5053
moved RequestListener out to a function to make code more readable
mzorz Feb 24, 2021
4eca102
use getCurrentStoryFrameAt(oldIndex) instead of getSelectedFrame when…
mzorz Feb 24, 2021
ff08278
using the bbackgroundViewInfo array to built the imageMatrix when sav…
mzorz Feb 24, 2021
a0fec09
removed commented code line
mzorz Feb 24, 2021
49fa468
fixed lint warning'
mzorz Feb 24, 2021
c5a9dab
encapsulated code in new methods setBackgroundViewInfoOnFrame and set…
mzorz Feb 24, 2021
1963373
removed empty line after brace
mzorz Feb 24, 2021
a35fc3b
moved oldSelectedFrame getter code into index boundary check
mzorz Feb 24, 2021
b951f97
handling FIT_CENTER scaleType both in edit mode and in FrameSaveManager
mzorz Mar 1, 2021
cb057c0
removed unused imports, added clarifying comment
mzorz Mar 1, 2021
19066d5
limit workingArea in calculateWorkingArea() to the same size as expor…
mzorz Mar 2, 2021
c7dea6c
using jp.wasabeef:glide-transformations library to add blurried image…
mzorz Mar 2, 2021
4375583
added an opaque bottom bar on top of background views to match the no…
mzorz Mar 3, 2021
b893880
removed unused import
mzorz Mar 3, 2021
62072d0
fixed line lenght excess
mzorz Mar 3, 2021
b7b861d
fixed merge conflict
mzorz Mar 3, 2021
6afe612
moved the bottomOpaqueBar up from PhotoEditorView to the container in…
mzorz Mar 3, 2021
e38dde9
removed unused import
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
f4745ab
removed the calculations to get real pixels; these were wrong because…
mzorz Mar 4, 2021
b1d5d8d
removed unused import
mzorz Mar 4, 2021
b90e3e1
Revert "limit workingArea in calculateWorkingArea() to the same size …
mzorz Mar 4, 2021
f06edcd
added missing import
mzorz Mar 4, 2021
57f0f55
leaving StoryFrameSelector background semitransparent
mzorz Mar 5, 2021
c166db5
removed code for changig StoryFrameSelector's background color
mzorz Mar 5, 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
f064702
Merge pull request #651 from Automattic/issue/646-zoom-in-bkg-picture…
mzorz Mar 19, 2021
491028a
Merge pull request #649 from Automattic/issue/646-zoom-in-bkg-picture…
mzorz Mar 19, 2021
f255374
Merge pull request #648 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
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<color name="black_transp_light_darker">#99000000</color>
<color name="black_transp_delete">#4D000000</color>
<color name="black_transp_story_frame_selector">@color/black_transp_light</color>
<color name="black_opaque_bar">@color/black</color>
<color name="black_transp_edit_mode_controls">@color/black_transp_light</color>
<color name="black_transp_edit_mode_controls_pressed">@color/black_transp_light_darker</color>
<color name="black_transp_error_scrim">#4D000000</color>
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ buildscript {
google()
jcenter()
maven { url "https://dl.bintray.com/automattic/maven/" }
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
Expand All @@ -30,6 +31,7 @@ allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}

if (tasks.findByPath('checkstyle') == null) {
Expand Down
4 changes: 4 additions & 0 deletions photoeditor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ 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')

lintChecks 'org.wordpress:lint:1.0.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ 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,13 +113,33 @@ 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
adjustViewBounds = true
scaleType = CENTER_CROP
scaleType = FIT_CENTER
}

val imgSrcParam = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT).apply {
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import android.graphics.drawable.Drawable
import android.graphics.drawable.Icon
import android.net.Uri
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
import com.github.chrisbanes.photoview.PhotoView

/**
* @author [Burhanuddin Rashid](https://github.com/burhanrashid52)
* @version 0.1.2
* @since 5/21/2018
*/
internal class BackgroundImageView : AppCompatImageView {
class BackgroundImageView : PhotoView {
private var mOnImageChangedListener: OnImageChangedListener? = null

val bitmap: Bitmap?
Expand Down
4 changes: 4 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 All @@ -63,6 +65,8 @@ dependencies {

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"

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

lintChecks 'org.wordpress:lint:1.0.1'

testImplementation 'junit:junit:4.12'
Expand Down
Loading