Skip to content

Commit 62c5a82

Browse files
committed
Release 1.0.0
1 parent 0cf4243 commit 62c5a82

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

README.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,45 @@ Example: `38;2;164;198;57` set foreground color to rgb(164, 198, 57)
4242

4343

4444
# Setup
45-
## Legacy
45+
46+
## Gradle
47+
48+
Add jitpack, example to add to `settings.gradle`:
49+
```groovy
50+
// Only add if `dependencyResolutionManagement` already exists
51+
dependencyResolutionManagement {
52+
repositories {
53+
maven {
54+
url 'https://jitpack.io'
55+
}
56+
}
57+
}
58+
```
59+
60+
61+
```groovy
62+
// Only add "repositories" if "dependencyResolutionManagement" didn't exists in "settings.gradle"
63+
repositories {
64+
maven {
65+
url 'https://jitpack.io'
66+
}
67+
}
68+
69+
70+
dependencies {
71+
implementation 'com.github.Fox2Code:AndroidANSI:1.0.0'
72+
}
73+
```
74+
75+
## TextView
4676
```java
4777
TextView textView = findViewById(R.id.ansiView);
4878
AnsiParser.setAnsiText(textView, // It's "AndroidANSI!" but with color & style
4979
"\\e[1;38;2;164;198;57mAndroid\\e[0;35mAN\u001B[2mSI\u001B[0;73m!",
5080
AnsiParser.FLAG_PARSE_DISABLE_SUBSCRIPT); // Also disable superscript
5181
```
5282

53-
## TextView
83+
## AnsiTextView
5484
**Layout**
5585
```xml
5686
<com.fox2code.androidansi.AnsiTextView
@@ -65,7 +95,7 @@ textView.setAnsiText("\\e[1;38;2;164;198;57mAndroid\\e[0;35mAN\u001B[2mSI\u001B[
6595
AnsiParser.FLAG_PARSE_DISABLE_SUBSCRIPT);
6696
```
6797

68-
## TextView w/o Java (WIP)
98+
## AnsiTextView w/o Java/Kotlin (WIP)
6999
```xml
70100
<?xml version="1.0" encoding="utf-8"?>
71101
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

library/src/main/java/com/fox2code/androidansi/AnsiTextView.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import android.content.Context;
66
import android.content.res.Resources;
77
import android.content.res.TypedArray;
8+
import android.graphics.Typeface;
89
import android.text.InputFilter;
910
import android.util.AttributeSet;
1011
import android.util.Log;
1112
import android.widget.TextView;
1213

1314
import androidx.annotation.NonNull;
15+
import androidx.annotation.Nullable;
1416
import androidx.emoji2.viewsintegration.EmojiTextViewHelper;
1517

1618
public class AnsiTextView extends TextView {
@@ -20,6 +22,7 @@ public class AnsiTextView extends TextView {
2022
public static final int FLAG_PARSE_DISABLE_SUBSCRIPT = AnsiParser.FLAG_PARSE_DISABLE_SUBSCRIPT;
2123

2224
private Object mEmojiTextViewHelper; // Hold reference without requiring hard references
25+
private boolean mIsSetTypefaceProcessing = false;
2326
private int parseFlags = 0;
2427

2528
public AnsiTextView(Context context) {
@@ -93,4 +96,21 @@ public void setAllCaps(boolean allCaps) {
9396
((EmojiTextViewHelper) this.mEmojiTextViewHelper).setAllCaps(allCaps);
9497
}
9598
}
99+
100+
@Override
101+
public void setTypeface(@Nullable Typeface tf, int style) {
102+
if (this.mIsSetTypefaceProcessing) {
103+
// b/151782655
104+
// Some device up to API19 recursively calls setTypeface. To avoid infinity recursive
105+
// setTypeface call, exit if we know this is re-entrant call.
106+
return;
107+
}
108+
109+
mIsSetTypefaceProcessing = true;
110+
try {
111+
super.setTypeface(tf, style);
112+
} finally {
113+
mIsSetTypefaceProcessing = false;
114+
}
115+
}
96116
}

0 commit comments

Comments
 (0)