diff --git a/photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt b/photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt index 391bbe8ed..64f30937c 100644 --- a/photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt +++ b/photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt @@ -412,12 +412,10 @@ class PhotoEditor private constructor(builder: Builder) : txtTextView.typeface = mDefaultTextTypeface } txtTextView.gravity = Gravity.CENTER - // txtTextView.setLayerType(View.LAYER_TYPE_SOFTWARE, null) - val maxHeight = parentView.height - rootView.tvPhotoEditorText.textSize = + txtTextView.maxTextSize = TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_SP, - maxHeight.toFloat(), + DEFAULT_AUTO_SIZE_MAX_TEXT_SIZE_IN_SP, context.resources.displayMetrics ) } @@ -431,7 +429,7 @@ class PhotoEditor private constructor(builder: Builder) : txtTextEmoji.typeface = mDefaultEmojiTypeface } txtTextEmoji.gravity = Gravity.CENTER - txtTextEmoji.textSize = + txtTextEmoji.maxTextSize = TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_SP, DEFAULT_AUTO_SIZE_MAX_TEXT_SIZE_IN_SP, diff --git a/photoeditor/src/main/java/com/automattic/photoeditor/views/AutoResizeTextView.kt b/photoeditor/src/main/java/com/automattic/photoeditor/views/AutoResizeTextView.kt index 5f8ada25a..b63a958c9 100644 --- a/photoeditor/src/main/java/com/automattic/photoeditor/views/AutoResizeTextView.kt +++ b/photoeditor/src/main/java/com/automattic/photoeditor/views/AutoResizeTextView.kt @@ -23,10 +23,18 @@ import androidx.appcompat.widget.AppCompatTextView class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = android.R.attr.textViewStyle) : AppCompatTextView(context, attrs, defStyle) { private val availableSpaceRect = RectF() private val sizeTester: SizeTester - private var maxTextSize: Float = 0.toFloat() + var maxTextSize: Float = 0.toFloat() + set(maxSize) { + field = maxSize + adjustTextSize() + } + var minTextSize: Float = 0.toFloat() + set(minSize) { + field = minSize + adjustTextSize() + } private var spacingMult = 1.0f private var spacingAdd = 0.0f - private var minTextSize: Float = 0.toFloat() private var widthLimit: Int = 0 private var maxLines: Int = 0 private var initialized = false @@ -165,16 +173,6 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr spacingAdd = add } - /** - * Set the lower text size limit and invalidate the view - * - * @param minTextSize - */ - fun setMinTextSize(minTextSize: Float) { - this.minTextSize = minTextSize - adjustTextSize() - } - private fun adjustTextSize() { // This is a workaround for truncated text issue on ListView, as shown here: https://github.com/AndroidDeveloperLB/AutoFitTextView/pull/14 // TODO think of a nicer, elegant solution.