summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2023-08-19 10:46:17 +0200
committerGitHub <noreply@github.com>2023-08-19 10:46:17 +0200
commit49ac7a83b8cd82a6bdbb14e046aab7e3e3ba0146 (patch)
tree34dcfa9392756e71c90abec0ae4084df3555f751
parentca9358234f9e806cbc6271159daed49f744942ca (diff)
downloadAntennaPod-49ac7a83b8cd82a6bdbb14e046aab7e3e3ba0146.zip
Relayout NoRelayoutTextView if text gets longer (#6587)
-rw-r--r--app/src/main/java/de/danoeh/antennapod/view/NoRelayoutTextView.java20
1 files changed, 17 insertions, 3 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/view/NoRelayoutTextView.java b/app/src/main/java/de/danoeh/antennapod/view/NoRelayoutTextView.java
index 3f921b445..cbb2ef0af 100644
--- a/app/src/main/java/de/danoeh/antennapod/view/NoRelayoutTextView.java
+++ b/app/src/main/java/de/danoeh/antennapod/view/NoRelayoutTextView.java
@@ -1,6 +1,5 @@
package de.danoeh.antennapod.view;
-import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
@@ -8,6 +7,9 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;
public class NoRelayoutTextView extends AppCompatTextView {
+ private boolean requestLayoutEnabled = false;
+ private float maxTextLength = 0;
+
public NoRelayoutTextView(@NonNull Context context) {
super(context);
}
@@ -20,9 +22,21 @@ public class NoRelayoutTextView extends AppCompatTextView {
super(context, attrs, defStyleAttr);
}
- @SuppressLint("MissingSuperCall")
@Override
public void requestLayout() {
- // Deliberate no-op
+ if (requestLayoutEnabled) {
+ super.requestLayout();
+ }
+ requestLayoutEnabled = false;
+ }
+
+ @Override
+ public void setText(CharSequence text, BufferType type) {
+ float textLength = getPaint().measureText(text.toString());
+ if (textLength > maxTextLength) {
+ maxTextLength = textLength;
+ requestLayoutEnabled = true;
+ }
+ super.setText(text, type);
}
}