Skip to content

Commit

Permalink
making sure emoji have an autoSizeTextType=uniform TextView so, setti…
Browse files Browse the repository at this point in the history
…ng a different size on the TextView's layout should trigger the autosizeable fontSize setting mechanism from TextViewCompat
  • Loading branch information
mzorz committed Nov 21, 2019
1 parent 253bb50 commit e25ff09
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
34 changes: 22 additions & 12 deletions photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.automattic.photoeditor.gesture.MultiTouchListener.OnMultiTouchListene
import com.automattic.photoeditor.util.BitmapUtil
import com.automattic.photoeditor.views.PhotoEditorView
import com.automattic.photoeditor.views.ViewType
import com.automattic.photoeditor.views.ViewType.EMOJI
import com.automattic.photoeditor.views.added.AddedView
import com.automattic.photoeditor.views.added.AddedViewList
import com.automattic.photoeditor.views.brush.BrushDrawingView
Expand Down Expand Up @@ -309,7 +310,6 @@ class PhotoEditor private constructor(builder: Builder) :
brushDrawingView.brushDrawingMode = false
getLayout(ViewType.EMOJI)?.apply {
val emojiTextView = findViewById<TextView>(R.id.tvPhotoEditorText)

if (emojiTypeface != null) {
emojiTextView.typeface = emojiTypeface
emojiTextView.text = emojiName
Expand Down Expand Up @@ -359,11 +359,22 @@ class PhotoEditor private constructor(builder: Builder) :
* @param rootView rootview of image,text and emoji
*/
private fun addViewToParent(rootView: View, viewType: ViewType, sourceUri: Uri? = null) {
val params = RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT
)
params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE)
parentView.addView(rootView, params)
if (viewType != EMOJI) {
val params = RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT
)
params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE)
parentView.addView(rootView, params)
} else {
val params = RelativeLayout.LayoutParams(
context.resources.getDimensionPixelSize(R.dimen.autosize_tv_initial_height),
context.resources.getDimensionPixelSize(R.dimen.autosize_tv_initial_height)
)
params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE)
rootView.tvPhotoEditorText.layoutParams = params

parentView.addView(rootView, params)
}
addedViews.add(AddedView(rootView, viewType, sourceUri))
mOnPhotoEditorListener?.onAddViewListener(viewType, addedViews.size)
}
Expand All @@ -389,14 +400,13 @@ class PhotoEditor private constructor(builder: Builder) :
ViewType.IMAGE -> rootView = layoutInflater.inflate(R.layout.view_photo_editor_image, null)
ViewType.EMOJI -> {
rootView = layoutInflater.inflate(R.layout.view_photo_editor_text, null)
val txtTextEmoji = rootView.tvPhotoEditorText
if (txtTextEmoji != null) {
if (mDefaultEmojiTypeface != null) {
txtTextEmoji.typeface = mDefaultEmojiTypeface
if (rootView.tvPhotoEditorText != null && mDefaultTextTypeface != null) {
rootView.tvPhotoEditorText.gravity = Gravity.CENTER
if (mDefaultTextTypeface != null) {
rootView.tvPhotoEditorText.typeface = mDefaultTextTypeface
}
txtTextEmoji.gravity = Gravity.CENTER
txtTextEmoji.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
}
rootView.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
}
}

Expand Down
5 changes: 3 additions & 2 deletions photoeditor/src/main/res/layout/view_photo_editor_text.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tvPhotoEditorText"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="4dp"
android:textColor="#000000"
app:autoSizeTextType="uniform"
tools:text="Burhanuddin"
tools:textColor="@android:color/black" />
6 changes: 6 additions & 0 deletions photoeditor/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="autosize_tv_margin">4dp</dimen>
<dimen name="autosize_tv_initial_width">96dp</dimen>
<dimen name="autosize_tv_initial_height">96dp</dimen>
</resources>

0 comments on commit e25ff09

Please sign in to comment.