From 5936efea53b0c0c328e1928e3f5abb5305e8784d Mon Sep 17 00:00:00 2001 From: Warrick Corfe-Tan Date: Thu, 26 Aug 2021 10:38:05 +1000 Subject: [PATCH 1/2] Fixing quote cutoff when font is too large. --- .../securesms/conversation/v2/messages/QuoteView.kt | 7 +++++-- .../securesms/conversation/v2/utilities/TextUtilities.kt | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt index 0f6fe2773d..65af5edcee 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt @@ -78,11 +78,14 @@ 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)) + + // Calculating height based on proportion of the static layout. + return 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 +100,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 diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/TextUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/TextUtilities.kt index b7ced4abb3..800ace54c3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/TextUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/TextUtilities.kt @@ -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 { val xInt = event.rawX.toInt() val yInt = event.rawY.toInt() From 0539ca412df2a44eb460a8a4b2af76daef50404a Mon Sep 17 00:00:00 2001 From: Warrick Corfe-Tan Date: Thu, 26 Aug 2021 15:18:13 +1000 Subject: [PATCH 2/2] constrain min size for cancel button when drafting a quote reply. --- .../securesms/conversation/v2/messages/QuoteView.kt | 9 ++++----- app/src/main/res/layout/view_quote.xml | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt index 65af5edcee..d873978ca7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt @@ -81,11 +81,10 @@ class QuoteView : LinearLayout { 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. - - // Calculating height based on proportion of the static layout. - return min((result / staticLayout.lineCount) * 3, result) + // 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 diff --git a/app/src/main/res/layout/view_quote.xml b/app/src/main/res/layout/view_quote.xml index d2835c8fb9..32112435a1 100644 --- a/app/src/main/res/layout/view_quote.xml +++ b/app/src/main/res/layout/view_quote.xml @@ -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" />