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

Photo editor module refactor #11

Merged
merged 15 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import android.widget.Toast
import androidx.core.content.ContextCompat
import com.automattic.photoeditor.OnPhotoEditorListener
import com.automattic.photoeditor.PhotoEditor
import com.automattic.photoeditor.ViewType
import com.automattic.photoeditor.state.BackgroundSurfaceManager
import com.automattic.photoeditor.views.ViewType
import com.automattic.portkey.R
import com.automattic.portkey.R.color
import com.automattic.portkey.R.id
Expand All @@ -23,6 +24,7 @@ import kotlinx.android.synthetic.main.content_composer.*

class ComposeLoopFrameActivity : AppCompatActivity() {
private lateinit var photoEditor: PhotoEditor
private lateinit var backgroundSurfaceManager: BackgroundSurfaceManager

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -68,6 +70,19 @@ class ComposeLoopFrameActivity : AppCompatActivity() {
// no op
}
})

backgroundSurfaceManager = BackgroundSurfaceManager(
this,
savedInstanceState,
lifecycle,
photoEditorView,
supportFragmentManager)
lifecycle.addObserver(backgroundSurfaceManager)
}

override fun onSaveInstanceState(outState: Bundle) {
backgroundSurfaceManager.saveStateToBundle(outState)
super.onSaveInstanceState(outState)
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
Expand Down Expand Up @@ -103,6 +118,20 @@ class ComposeLoopFrameActivity : AppCompatActivity() {
testSticker()
true
}

id.action_bkg_camera_preview -> {
testCameraPreview()
true
}
id.action_bkg_static -> {
testStaticBackground()
true
}
id.action_bkg_play_video -> {
testPlayVideo()
true
}

id.action_save -> {
Toast.makeText(this, "Not implemented", Toast.LENGTH_SHORT).show()
true
Expand Down Expand Up @@ -142,4 +171,19 @@ class ComposeLoopFrameActivity : AppCompatActivity() {
txtCurrentTool.setText("")
photoEditor.addNewImageView(true, Uri.parse("https://i.giphy.com/Ok4HaWlYrewuY.gif"))
}

private fun testCameraPreview() {
txtCurrentTool.setText(string.main_test_camera_preview)
backgroundSurfaceManager.switchCameraPreviewOn()
}

private fun testPlayVideo() {
txtCurrentTool.setText(string.main_test_play_video)
backgroundSurfaceManager.switchVideoPlayerOn()
}

private fun testStaticBackground() {
txtCurrentTool.setText(string.main_test_static_background)
backgroundSurfaceManager.switchStaticImageBackgroundModeOn()
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/content_composer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
tools:showIn="@layout/activity_main"
tools:context=".MainActivity">

<com.automattic.photoeditor.PhotoEditorView
<com.automattic.photoeditor.views.PhotoEditorView
android:id="@+id/photoEditorView"
android:layout_width="0dp"
android:layout_height="0dp"
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@
android:title="@string/main_test_sticker"
android:orderInCategory="100"
app:showAsAction="never"/>

<item android:id="@+id/action_bkg_camera_preview"
android:title="@string/main_test_camera_preview"
android:orderInCategory="100"
app:showAsAction="never"/>
<item android:id="@+id/action_bkg_static"
android:title="@string/main_test_static_background"
android:orderInCategory="100"
app:showAsAction="never"/>
<item android:id="@+id/action_bkg_play_video"
android:title="@string/main_test_play_video"
android:orderInCategory="100"
app:showAsAction="never"/>

<item android:id="@+id/action_save"
android:title="@string/main_test_save"
android:orderInCategory="100"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<string name="main_test_emoji">Test emoji</string>
<string name="main_test_text">Test text</string>
<string name="main_test_sticker">Test sticker</string>
<string name="main_test_camera_preview">Camera preview</string>
<string name="main_test_static_background">Static bkg</string>
<string name="main_test_play_video">Play video</string>
<string name="main_test_save">Save</string>


Expand Down
2 changes: 1 addition & 1 deletion photoeditor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.github.bumptech.glide:glide:4.9.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.automattic.photoeditor

import android.view.View
import com.automattic.photoeditor.views.ViewType

/**
* @author [Burhanuddin Rashid](https://github.com/burhanrashid52)
Expand Down
27 changes: 17 additions & 10 deletions photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,18 @@ import androidx.annotation.ColorInt
import androidx.annotation.IntRange
import androidx.annotation.RequiresPermission
import androidx.annotation.UiThread
import com.automattic.photoeditor.ViewType.STICKER_ANIMATED
import com.automattic.photoeditor.views.AddedView
import com.automattic.photoeditor.views.AddedViewList
import com.automattic.photoeditor.views.ViewType.BRUSH_DRAWING
import com.automattic.photoeditor.views.ViewType.STICKER_ANIMATED
import com.automattic.photoeditor.gesture.MultiTouchListener
import com.automattic.photoeditor.util.BitmapUtil
import com.automattic.photoeditor.views.PhotoEditorView
import com.automattic.photoeditor.views.ViewType
import com.automattic.photoeditor.views.added.AddedView
import com.automattic.photoeditor.views.added.AddedViewList
import com.automattic.photoeditor.views.brush.BrushDrawingView
import com.automattic.photoeditor.views.brush.BrushViewChangeListener
import com.automattic.photoeditor.views.filter.CustomEffect
import com.automattic.photoeditor.views.filter.PhotoFilter
import com.bumptech.glide.Glide

import java.io.File
Expand All @@ -45,7 +54,8 @@ import kotlinx.android.synthetic.main.view_photo_editor_text.view.*
* @since 18/01/2017
*/

class PhotoEditor private constructor(builder: Builder) : BrushViewChangeListener {
class PhotoEditor private constructor(builder: Builder) :
BrushViewChangeListener {
private val layoutInflater: LayoutInflater
private val context: Context
private val parentView: PhotoEditorView
Expand Down Expand Up @@ -153,7 +163,6 @@ class PhotoEditor private constructor(builder: Builder) : BrushViewChangeListene

imageView.setImageBitmap(desiredImage)

val multiTouchListener = multiTouchListener
multiTouchListener.setOnGestureControl(object : MultiTouchListener.OnGestureControl {
override fun onClick() {
val isBackgroundVisible = frmBorder.tag != null && frmBorder.tag as Boolean
Expand All @@ -176,7 +185,6 @@ class PhotoEditor private constructor(builder: Builder) : BrushViewChangeListene
val frmBorder = imageRootView.findViewById<FrameLayout>(R.id.frmBorder)
val imgClose = imageRootView.findViewById<ImageView>(R.id.imgPhotoEditorClose)

val multiTouchListener = multiTouchListener
multiTouchListener.setOnGestureControl(object : MultiTouchListener.OnGestureControl {
override fun onClick() {
val isBackgroundVisible = frmBorder.tag != null && frmBorder.tag as Boolean
Expand Down Expand Up @@ -204,7 +212,6 @@ class PhotoEditor private constructor(builder: Builder) : BrushViewChangeListene
val frmBorder = imageRootView.findViewById<FrameLayout>(R.id.frmBorder)
val imgClose = imageRootView.findViewById<ImageView>(R.id.imgPhotoEditorClose)

val multiTouchListener = multiTouchListener
multiTouchListener.setOnGestureControl(object : MultiTouchListener.OnGestureControl {
override fun onClick() {
val isBackgroundVisible = frmBorder.tag != null && frmBorder.tag as Boolean
Expand Down Expand Up @@ -245,7 +252,7 @@ class PhotoEditor private constructor(builder: Builder) : BrushViewChangeListene
if (textTypeface != null) {
textInputTv.typeface = textTypeface
}
val multiTouchListener = multiTouchListener

multiTouchListener.setOnGestureControl(object : MultiTouchListener.OnGestureControl {
override fun onClick() {
val isBackgroundVisible = frmBorder.tag != null && frmBorder.tag as Boolean
Expand Down Expand Up @@ -329,7 +336,7 @@ class PhotoEditor private constructor(builder: Builder) : BrushViewChangeListene
}
emojiTextView.textSize = 56f
emojiTextView.text = emojiName
val multiTouchListener = multiTouchListener

multiTouchListener.setOnGestureControl(object : MultiTouchListener.OnGestureControl {
override fun onClick() {
val isBackgroundVisible = frmBorder.tag != null && frmBorder.tag as Boolean
Expand Down Expand Up @@ -823,7 +830,7 @@ class PhotoEditor private constructor(builder: Builder) : BrushViewChangeListene
if (redoViews.size > 0) {
redoViews.removeAt(redoViews.size - 1)
}
addedViews.add(AddedView(brushDrawingView, ViewType.BRUSH_DRAWING))
addedViews.add(AddedView(brushDrawingView, BRUSH_DRAWING))
mOnPhotoEditorListener?.onAddViewListener(ViewType.BRUSH_DRAWING, addedViews.size)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ import android.view.View
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.automattic.photoeditor.FileUtils
import com.automattic.photoeditor.util.FileUtils
import com.automattic.photoeditor.R
import com.automattic.photoeditor.views.background.video.AutoFitTextureView
import java.io.File
import java.io.IOException
import java.util.Arrays
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ import android.view.TextureView
import java.io.File
import android.media.AudioManager
import android.media.MediaPlayer
import androidx.core.app.ActivityCompat
import androidx.fragment.app.Fragment
import com.automattic.photoeditor.views.background.video.AutoFitTextureView
import java.io.IOException

class VideoPlayingBasicHandling : Fragment(),
ActivityCompat.OnRequestPermissionsResultCallback, SurfaceFragmentHandler {
class VideoPlayingBasicHandling : Fragment(), SurfaceFragmentHandler {
/**
* [TextureView.SurfaceTextureListener] handles several lifecycle events on a
* [TextureView].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.automattic.photoeditor
package com.automattic.photoeditor.gesture

import android.graphics.Rect
import android.view.GestureDetector
Expand All @@ -7,6 +7,9 @@ import android.view.View
import android.view.View.OnTouchListener
import android.widget.ImageView
import android.widget.RelativeLayout
import com.automattic.photoeditor.OnPhotoEditorListener
import com.automattic.photoeditor.views.ViewType
import com.automattic.photoeditor.gesture.ScaleGestureDetector.SimpleOnScaleGestureListener

/**
* Created on 18/01/2017.
Expand Down Expand Up @@ -86,11 +89,16 @@ internal class MultiTouchListener(
val currX = event.getX(pointerIndexMove)
val currY = event.getY(pointerIndexMove)
if (!mScaleGestureDetector.isInProgress) {
adjustTranslation(view, currX - mPrevX, currY - mPrevY)
adjustTranslation(
view,
currX - mPrevX,
currY - mPrevY
)
}
}
}
MotionEvent.ACTION_CANCEL -> mActivePointerId = INVALID_POINTER_ID
MotionEvent.ACTION_CANCEL -> mActivePointerId =
INVALID_POINTER_ID
MotionEvent.ACTION_UP -> {
mActivePointerId = INVALID_POINTER_ID
if (deleteView != null && isViewInBounds(deleteView, x, y)) {
Expand Down Expand Up @@ -140,7 +148,7 @@ internal class MultiTouchListener(
this.onMultiTouchListener = onMultiTouchListener
}

private inner class ScaleGestureListener : ScaleGestureDetector.SimpleOnScaleGestureListener() {
private inner class ScaleGestureListener : SimpleOnScaleGestureListener() {
private var mPivotX: Float = 0.toFloat()
private var mPivotY: Float = 0.toFloat()
private val mPrevSpanVector = Vector2D()
Expand All @@ -156,7 +164,10 @@ internal class MultiTouchListener(
val info = TransformInfo()
info.deltaScale = if (isScaleEnabled) detector.scaleFactor else 1.0f
info.deltaAngle =
if (isRotateEnabled) Vector2D.getAngle(mPrevSpanVector, detector.currentSpanVector) else 0.0f
if (isRotateEnabled) Vector2D.getAngle(
mPrevSpanVector,
detector.currentSpanVector
) else 0.0f
info.deltaX = if (isTranslateEnabled) detector.focusX - mPivotX else 0.0f
info.deltaY = if (isTranslateEnabled) detector.focusY - mPivotY else 0.0f
info.pivotX = mPivotX
Expand Down Expand Up @@ -225,15 +236,24 @@ internal class MultiTouchListener(
}

private fun move(view: View, info: TransformInfo) {
computeRenderOffset(view, info.pivotX, info.pivotY)
adjustTranslation(view, info.deltaX, info.deltaY)
computeRenderOffset(
view,
info.pivotX,
info.pivotY
)
adjustTranslation(
view,
info.deltaX,
info.deltaY
)

var scale = view.scaleX * info.deltaScale
scale = Math.max(info.minimumScale, Math.min(info.maximumScale, scale))
view.scaleX = scale
view.scaleY = scale

val rotation = adjustAngle(view.rotation + info.deltaAngle)
val rotation =
adjustAngle(view.rotation + info.deltaAngle)
view.rotation = rotation
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.automattic.photoeditor
package com.automattic.photoeditor.gesture

import android.util.Log
import android.view.MotionEvent
Expand Down Expand Up @@ -234,7 +234,8 @@ internal class ScaleGestureDetector(private val mListener: OnScaleGestureListene
* A convenience class to extend when you only want to listen for a subset
* of scaling-related events. This implements all methods in
*/
internal open class SimpleOnScaleGestureListener : OnScaleGestureListener {
internal open class SimpleOnScaleGestureListener :
OnScaleGestureListener {
override fun onScale(view: View, detector: ScaleGestureDetector): Boolean {
return false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.automattic.photoeditor
package com.automattic.photoeditor.gesture

import android.graphics.PointF

Expand Down
Loading