Skip to content

Commit

Permalink
Release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox2Code committed Jun 1, 2022
1 parent 0cf4243 commit 62c5a82
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,45 @@ Example: `38;2;164;198;57` set foreground color to rgb(164, 198, 57)


# Setup
## Legacy

## Gradle

Add jitpack, example to add to `settings.gradle`:
```groovy
// Only add if `dependencyResolutionManagement` already exists
dependencyResolutionManagement {
repositories {
maven {
url 'https://jitpack.io'
}
}
}
```


```groovy
// Only add "repositories" if "dependencyResolutionManagement" didn't exists in "settings.gradle"
repositories {
maven {
url 'https://jitpack.io'
}
}
dependencies {
implementation 'com.github.Fox2Code:AndroidANSI:1.0.0'
}
```

## TextView
```java
TextView textView = findViewById(R.id.ansiView);
AnsiParser.setAnsiText(textView, // It's "AndroidANSI!" but with color & style
"\\e[1;38;2;164;198;57mAndroid\\e[0;35mAN\u001B[2mSI\u001B[0;73m!",
AnsiParser.FLAG_PARSE_DISABLE_SUBSCRIPT); // Also disable superscript
```

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

## TextView w/o Java (WIP)
## AnsiTextView w/o Java/Kotlin (WIP)
```xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
Expand Down
20 changes: 20 additions & 0 deletions library/src/main/java/com/fox2code/androidansi/AnsiTextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.text.InputFilter;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.emoji2.viewsintegration.EmojiTextViewHelper;

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

private Object mEmojiTextViewHelper; // Hold reference without requiring hard references
private boolean mIsSetTypefaceProcessing = false;
private int parseFlags = 0;

public AnsiTextView(Context context) {
Expand Down Expand Up @@ -93,4 +96,21 @@ public void setAllCaps(boolean allCaps) {
((EmojiTextViewHelper) this.mEmojiTextViewHelper).setAllCaps(allCaps);
}
}

@Override
public void setTypeface(@Nullable Typeface tf, int style) {
if (this.mIsSetTypefaceProcessing) {
// b/151782655
// Some device up to API19 recursively calls setTypeface. To avoid infinity recursive
// setTypeface call, exit if we know this is re-entrant call.
return;
}

mIsSetTypefaceProcessing = true;
try {
super.setTypeface(tf, style);
} finally {
mIsSetTypefaceProcessing = false;
}
}
}

0 comments on commit 62c5a82

Please sign in to comment.