Skip to content

Commit

Permalink
Merge pull request #215 from Automattic/remove/surrrounding-framelayout
Browse files Browse the repository at this point in the history
Remove surrounding framelayout
  • Loading branch information
aforcier authored Dec 5, 2019
2 parents bc423fb + f40fc5b commit fdfbfb1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 107 deletions.
85 changes: 10 additions & 75 deletions photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
Expand All @@ -25,7 +24,6 @@ import androidx.annotation.IntRange
import androidx.annotation.RequiresPermission
import androidx.annotation.UiThread
import androidx.emoji.text.EmojiCompat
import androidx.emoji.text.EmojiCompat.InitCallback
import com.automattic.photoeditor.gesture.MultiTouchListener
import com.automattic.photoeditor.gesture.MultiTouchListener.OnMultiTouchListener
import com.automattic.photoeditor.util.BitmapUtil
Expand Down Expand Up @@ -178,48 +176,16 @@ class PhotoEditor private constructor(builder: Builder) :
fun addImage(desiredImage: Bitmap) {
getLayout(ViewType.IMAGE)?.apply {
val imageView = findViewById<ImageView>(R.id.imgPhotoEditorImage)
val frmBorder = findViewById<FrameLayout>(R.id.frmBorder)
val imgClose = findViewById<ImageView>(R.id.imgPhotoEditorClose)

imageView.setImageBitmap(desiredImage)

val multiTouchListenerInstance = newMultiTouchListener
multiTouchListenerInstance.setOnGestureControl(object : MultiTouchListener.OnGestureControl {
override fun onClick() {
val isBackgroundVisible = frmBorder.tag != null && frmBorder.tag as Boolean
frmBorder.setBackgroundResource(if (isBackgroundVisible) 0 else R.drawable.rounded_border_tv)
imgClose.visibility = if (isBackgroundVisible) View.GONE else View.VISIBLE
frmBorder.tag = !isBackgroundVisible
}

override fun onLongClick() {}
})

setOnTouchListener(multiTouchListenerInstance)

addViewToParent(this, ViewType.IMAGE)
}
}

fun addNewImageView(isAnimated: Boolean, uri: Uri) {
getLayout(ViewType.IMAGE)?.apply {
val imageView = findViewById<ImageView>(R.id.imgPhotoEditorImage)
val frmBorder = findViewById<FrameLayout>(R.id.frmBorder)
val imgClose = findViewById<ImageView>(R.id.imgPhotoEditorClose)

val multiTouchListenerInstance = newMultiTouchListener
multiTouchListenerInstance.setOnGestureControl(object : MultiTouchListener.OnGestureControl {
override fun onClick() {
val isBackgroundVisible = frmBorder.tag != null && frmBorder.tag as Boolean
frmBorder.setBackgroundResource(if (isBackgroundVisible) 0 else R.drawable.rounded_border_tv)
imgClose.visibility = if (isBackgroundVisible) View.GONE else View.VISIBLE
frmBorder.tag = !isBackgroundVisible
}

override fun onLongClick() {}
})

setOnTouchListener(multiTouchListenerInstance)

addViewToParent(this, if (isAnimated) ViewType.STICKER_ANIMATED else ViewType.IMAGE, uri)

Expand All @@ -233,22 +199,6 @@ class PhotoEditor private constructor(builder: Builder) :
fun addNewImageView(isAnimated: Boolean): ImageView? {
getLayout(ViewType.IMAGE)?.apply {
val imageView = findViewById<ImageView>(R.id.imgPhotoEditorImage)
val frmBorder = findViewById<FrameLayout>(R.id.frmBorder)
val imgClose = findViewById<ImageView>(R.id.imgPhotoEditorClose)

val multiTouchListenerInstance = newMultiTouchListener
multiTouchListenerInstance.setOnGestureControl(object : MultiTouchListener.OnGestureControl {
override fun onClick() {
val isBackgroundVisible = frmBorder.tag != null && frmBorder.tag as Boolean
frmBorder.setBackgroundResource(if (isBackgroundVisible) 0 else R.drawable.rounded_border_tv)
imgClose.visibility = if (isBackgroundVisible) View.GONE else View.VISIBLE
frmBorder.tag = !isBackgroundVisible
}

override fun onLongClick() {}
})

setOnTouchListener(multiTouchListenerInstance)

addViewToParent(this, if (isAnimated) ViewType.STICKER_ANIMATED else ViewType.IMAGE)

Expand All @@ -270,12 +220,6 @@ class PhotoEditor private constructor(builder: Builder) :
brushDrawingView.brushDrawingMode = false
getLayout(ViewType.TEXT)?.apply {
val textInputTv = findViewById<TextView>(R.id.tvPhotoEditorText)
val imgClose = findViewById<ImageView>(R.id.imgPhotoEditorClose)
val frmBorder = findViewById<FrameLayout>(R.id.frmBorder)

// hide cross and background borders for now
imgClose.visibility = View.GONE
frmBorder.setBackgroundResource(0)

textInputTv.text = text
textInputTv.setTextColor(colorCodeTextView)
Expand Down Expand Up @@ -365,8 +309,6 @@ class PhotoEditor private constructor(builder: Builder) :
brushDrawingView.brushDrawingMode = false
getLayout(ViewType.EMOJI)?.apply {
val emojiTextView = findViewById<TextView>(R.id.tvPhotoEditorText)
val frmBorder = findViewById<FrameLayout>(R.id.frmBorder)
val imgClose = findViewById<ImageView>(R.id.imgPhotoEditorClose)

if (emojiTypeface != null) {
emojiTextView.typeface = emojiTypeface
Expand Down Expand Up @@ -396,10 +338,6 @@ class PhotoEditor private constructor(builder: Builder) :
}
emojiTextView.textSize = 56f

// hide cross and background borders for now
imgClose.visibility = View.GONE
frmBorder.setBackgroundResource(0)

val multiTouchListenerInstance = newMultiTouchListener
multiTouchListenerInstance.setOnGestureControl(object : MultiTouchListener.OnGestureControl {
override fun onClick() {
Expand Down Expand Up @@ -466,9 +404,6 @@ class PhotoEditor private constructor(builder: Builder) :
// We are setting tag as ViewType to identify what type of the view it is
// when we remove the view from stack i.e onRemoveViewListener(ViewType viewType, int numberOfAddedViews);
rootView.tag = viewType
val imgClose = rootView.findViewById<ImageView>(R.id.imgPhotoEditorClose)
val finalRootView = rootView
imgClose?.setOnClickListener { viewUndo(finalRootView, viewType) }
}
return rootView
}
Expand All @@ -479,7 +414,7 @@ class PhotoEditor private constructor(builder: Builder) :
* @param brushDrawingMode true if mode is enabled
*/
fun setBrushDrawingMode(brushDrawingMode: Boolean) {
brushDrawingView.brushDrawingMode = brushDrawingMode
brushDrawingView.brushDrawingMode = brushDrawingMode
}

/**
Expand Down Expand Up @@ -615,15 +550,15 @@ class PhotoEditor private constructor(builder: Builder) :
*/
@UiThread
fun clearHelperBox() {
for (i in 0 until parentView.childCount) {
val childAt = parentView.getChildAt(i)
val frmBorder = childAt.findViewById<FrameLayout>(R.id.frmBorder)
frmBorder?.setBackgroundResource(0)
val imgClose = childAt.findViewById<ImageView>(R.id.imgPhotoEditorClose)
if (imgClose != null) {
imgClose.visibility = View.GONE
}
}
// for (i in 0 until parentView.childCount) {
// val childAt = parentView.getChildAt(i)
// val frmBorder = childAt.findViewById<FrameLayout>(R.id.frmBorder)
// frmBorder?.setBackgroundResource(0)
// val imgClose = childAt.findViewById<ImageView>(R.id.imgPhotoEditorClose)
// if (imgClose != null) {
// imgClose.visibility = View.GONE
// }
// }
}

/**
Expand Down
41 changes: 9 additions & 32 deletions photoeditor/src/main/res/layout/view_photo_editor_text.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<FrameLayout
android:id="@+id/frmBorder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:background="@drawable/rounded_border_tv">

<TextView
android:id="@+id/tvPhotoEditorText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:textColor="#000000"
android:textSize="18sp"
tools:text="Burhanuddin"
tools:textColor="@android:color/black" />

</FrameLayout>

<ImageView
android:id="@+id/imgPhotoEditorClose"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_gravity="top|start"
android:elevation="1dp"
android:src="@drawable/ic_remove" />

</FrameLayout>
android:id="@+id/tvPhotoEditorText"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="4dp"
android:textColor="#000000"
tools:text="Burhanuddin"
tools:textColor="@android:color/black" />

0 comments on commit fdfbfb1

Please sign in to comment.