Skip to content

Commit

Permalink
added max/minTextSize setters on AutoResizeTextView and using them pr…
Browse files Browse the repository at this point in the history
…operly when generating AutoResizeTextView based layouts
  • Loading branch information
mzorz committed Nov 26, 2019
1 parent 0bd2455 commit 844ba01
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 844ba01

Please sign in to comment.