From c54669a381ce3e1f71f028bf9ce9b4e783fff122 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Sat, 9 Nov 2019 11:21:06 -0300 Subject: [PATCH 1/2] removed unused/hidden border and close button from basic views to simplify layout --- .../com/automattic/photoeditor/PhotoEditor.kt | 85 +++---------------- .../res/layout/view_photo_editor_text.xml | 40 +++------ 2 files changed, 21 insertions(+), 104 deletions(-) diff --git a/photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt b/photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt index eebbb5104..3aa1b763d 100644 --- a/photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt +++ b/photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt @@ -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 @@ -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 @@ -178,25 +176,9 @@ class PhotoEditor private constructor(builder: Builder) : fun addImage(desiredImage: Bitmap) { getLayout(ViewType.IMAGE)?.apply { val imageView = findViewById(R.id.imgPhotoEditorImage) - val frmBorder = findViewById(R.id.frmBorder) - val imgClose = findViewById(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) } } @@ -204,22 +186,6 @@ class PhotoEditor private constructor(builder: Builder) : fun addNewImageView(isAnimated: Boolean, uri: Uri) { getLayout(ViewType.IMAGE)?.apply { val imageView = findViewById(R.id.imgPhotoEditorImage) - val frmBorder = findViewById(R.id.frmBorder) - val imgClose = findViewById(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) @@ -233,22 +199,6 @@ class PhotoEditor private constructor(builder: Builder) : fun addNewImageView(isAnimated: Boolean): ImageView? { getLayout(ViewType.IMAGE)?.apply { val imageView = findViewById(R.id.imgPhotoEditorImage) - val frmBorder = findViewById(R.id.frmBorder) - val imgClose = findViewById(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) @@ -270,12 +220,6 @@ class PhotoEditor private constructor(builder: Builder) : brushDrawingView.brushDrawingMode = false getLayout(ViewType.TEXT)?.apply { val textInputTv = findViewById(R.id.tvPhotoEditorText) - val imgClose = findViewById(R.id.imgPhotoEditorClose) - val frmBorder = findViewById(R.id.frmBorder) - - // hide cross and background borders for now - imgClose.visibility = View.GONE - frmBorder.setBackgroundResource(0) textInputTv.text = text textInputTv.setTextColor(colorCodeTextView) @@ -365,8 +309,6 @@ class PhotoEditor private constructor(builder: Builder) : brushDrawingView.brushDrawingMode = false getLayout(ViewType.EMOJI)?.apply { val emojiTextView = findViewById(R.id.tvPhotoEditorText) - val frmBorder = findViewById(R.id.frmBorder) - val imgClose = findViewById(R.id.imgPhotoEditorClose) if (emojiTypeface != null) { emojiTextView.typeface = emojiTypeface @@ -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() { @@ -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(R.id.imgPhotoEditorClose) - val finalRootView = rootView - imgClose?.setOnClickListener { viewUndo(finalRootView, viewType) } } return rootView } @@ -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 } /** @@ -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(R.id.frmBorder) - frmBorder?.setBackgroundResource(0) - val imgClose = childAt.findViewById(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(R.id.frmBorder) +// frmBorder?.setBackgroundResource(0) +// val imgClose = childAt.findViewById(R.id.imgPhotoEditorClose) +// if (imgClose != null) { +// imgClose.visibility = View.GONE +// } +// } } /** diff --git a/photoeditor/src/main/res/layout/view_photo_editor_text.xml b/photoeditor/src/main/res/layout/view_photo_editor_text.xml index 52d08f71a..60bc480bd 100644 --- a/photoeditor/src/main/res/layout/view_photo_editor_text.xml +++ b/photoeditor/src/main/res/layout/view_photo_editor_text.xml @@ -2,33 +2,15 @@ - - - - - - - - - + android:layout_height="wrap_content" + xmlns:app="http://schemas.android.com/apk/res-auto"> + From f40fc5bc6829647bd100d8781992231d106878f8 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Wed, 20 Nov 2019 16:05:32 -0300 Subject: [PATCH 2/2] removed unneeded FrameLayout --- .../res/layout/view_photo_editor_text.xml | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/photoeditor/src/main/res/layout/view_photo_editor_text.xml b/photoeditor/src/main/res/layout/view_photo_editor_text.xml index 60bc480bd..c920e5f1e 100644 --- a/photoeditor/src/main/res/layout/view_photo_editor_text.xml +++ b/photoeditor/src/main/res/layout/view_photo_editor_text.xml @@ -1,16 +1,11 @@ - - - + 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" />