Merge pull request #714 from warrickct/quote-cutoff-fix

Fixing quote cutoff when font is too large.
This commit is contained in:
Harris 2021-08-31 06:14:33 +00:00 committed by GitHub
commit 0120eb3fad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 8 deletions

View File

@ -78,11 +78,13 @@ class QuoteView : LinearLayout {
}
val body = quoteViewBodyTextView.text
val bodyTextViewIntrinsicHeight = TextUtilities.getIntrinsicHeight(body, quoteViewBodyTextView.paint, maxContentWidth)
val staticLayout = TextUtilities.getIntrinsicLayout(body, quoteViewBodyTextView.paint, maxContentWidth)
result += bodyTextViewIntrinsicHeight
if (!quoteViewAuthorTextView.isVisible) {
// We want to at least be as high as the cancel button, and no higher than 56 DP (that's
// approximately the height of 3 lines.
return min(max(result, toPx(32, resources)), toPx(56, resources))
// We want to at least be as high as the cancel button 36DP, and no higher than 3 lines of text.
// Height from intrinsic layout is the height of the text before truncation so we shorten
// proportionally to our max lines setting.
return max(toPx(32, resources) ,min((result / staticLayout.lineCount) * 3, result))
} else {
// Because we're showing the author text view, we should have a height of at least 32 DP
// anyway, so there's no need to constrain to that. We constrain to a max height of 56 DP
@ -97,7 +99,7 @@ class QuoteView : LinearLayout {
// and then center everything inside vertically. This effectively means we're applying padding.
// Applying padding the regular way results in a clipping issue though due to a bug in
// RelativeLayout.
return getIntrinsicContentHeight(maxContentWidth) + 2 * vPadding
return getIntrinsicContentHeight(maxContentWidth) + (2 * vPadding )
}
// endregion

View File

@ -20,6 +20,14 @@ object TextUtilities {
return layout.height
}
fun getIntrinsicLayout(text: CharSequence, paint: TextPaint, width: Int): StaticLayout {
val builder = StaticLayout.Builder.obtain(text, 0, text.length, paint, width)
.setAlignment(Layout.Alignment.ALIGN_NORMAL)
.setLineSpacing(0.0f, 1.0f)
.setIncludePad(false)
return builder.build()
}
fun TextView.getIntersectedModalSpans(event: MotionEvent): List<ModalURLSpan> {
val xInt = event.rawX.toInt()
val yInt = event.rawY.toInt()

View File

@ -67,11 +67,11 @@
android:id="@+id/quoteViewBodyTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yo, I need your help here!"
android:textSize="@dimen/small_font_size"
android:textColor="@color/text"
android:ellipsize="end"
android:maxLines="3"
android:ellipsize="end" />
android:text="Yo, I need your help here!"
android:textColor="@color/text"
android:textSize="@dimen/small_font_size" />
</LinearLayout>