-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
259 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Sat Apr 30 13:14:52 CEST 2022 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip | ||
distributionPath=wrapper/dists | ||
zipStorePath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
plugins { | ||
id 'com.android.library' | ||
id 'org.jetbrains.kotlin.android' | ||
id 'maven-publish' | ||
} | ||
|
||
final int androidTargetSdk = // Parse property once | ||
Integer.parseInt(project['andorid.targetSdk'] as String) | ||
|
||
group = 'com.github.Fox2Code.AndoridANSI' | ||
version = project['library.version'] as String | ||
|
||
android { | ||
namespace 'com.fox2code.androidansi.ktx' | ||
compileSdk androidTargetSdk | ||
|
||
defaultConfig { | ||
minSdk 16 | ||
targetSdk androidTargetSdk | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles "consumer-rules.pro" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
publishing { | ||
singleVariant('release') { | ||
withSourcesJar() | ||
withJavadocJar() | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
api(project(":library")) | ||
compileOnly('androidx.appcompat:appcompat:1.6.1') | ||
} | ||
|
||
afterEvaluate { | ||
publishing { | ||
publications { | ||
// Creates a Maven publication called "release". | ||
release(MavenPublication) { | ||
from components.release | ||
groupId = project.group | ||
artifactId = 'library-ktx' | ||
version = '1.0' // JitPack only support 1.0 | ||
} | ||
} | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
67 changes: 67 additions & 0 deletions
67
library-ktx/src/main/java/com/fox2code/androidansi/ktx/AnsiExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
@file:Suppress("NOTHING_TO_INLINE") // Aliases to public API. | ||
|
||
package com.fox2code.androidansi.ktx | ||
|
||
import android.app.ActionBar | ||
import android.app.Activity | ||
import android.app.AlertDialog | ||
import android.content.res.Resources | ||
import android.text.Spannable | ||
import android.widget.TextView | ||
import androidx.annotation.StringRes | ||
import com.fox2code.androidansi.AnsiContext | ||
import com.fox2code.androidansi.AnsiParser | ||
import com.fox2code.androidansi.AnsiTextSpan | ||
import org.jetbrains.annotations.Contract | ||
|
||
const val FLAG_ANSI_PARSE_DISABLE_COLORS: Int = AnsiParser.FLAG_PARSE_DISABLE_COLORS | ||
const val FLAG_ANSI_PARSE_DISABLE_ATTRIBUTES: Int = AnsiParser.FLAG_PARSE_DISABLE_ATTRIBUTES | ||
const val FLAG_ANSI_PARSE_DISABLE_EXTRAS_COLORS: Int = AnsiParser.FLAG_PARSE_DISABLE_EXTRAS_COLORS | ||
const val FLAG_ANSI_PARSE_DISABLE_SUBSCRIPT: Int = AnsiParser.FLAG_PARSE_DISABLE_SUBSCRIPT | ||
const val FLAGS_ANSI_PARSE_DISABLE_ALL: Int = AnsiParser.FLAGS_DISABLE_ALL | ||
|
||
@Contract(pure = true) | ||
inline fun String.patchAnsiEscapeSequences(): String = AnsiParser.patchEscapeSequences(this) | ||
@Contract(pure = true) | ||
inline fun String.removeAnsiEscapeSequences(): String = AnsiParser.removeEscapeSequences(this) | ||
|
||
inline fun String.parseAsAnsi(context: AnsiContext? = null, parseFlags: Int = 0): Spannable { | ||
return if (context == null) { | ||
AnsiParser.parseAsSpannable(this, parseFlags) | ||
} else { | ||
context.parseAsSpannable(this, parseFlags) | ||
} | ||
} | ||
|
||
@Contract(pure = true) | ||
inline fun Resources.getAnsiText(@StringRes text: Int, parseFlags: Int = 0): Spannable { | ||
return AnsiParser.parseAsSpannable(this.getString(text), parseFlags) | ||
} | ||
|
||
inline fun Spannable.clearAnsiSpans() { | ||
this.getSpans(0, this.length, AnsiTextSpan::class.java).forEach { removeSpan(it) } | ||
} | ||
|
||
inline fun TextView.setAnsiText(text: String, parseFlags: Int = 0) { | ||
this.text = AnsiParser.parseAsSpannable(text, parseFlags) | ||
} | ||
|
||
inline fun Activity.setAnsiTitle(text: String, parseFlags: Int = 0) { | ||
this.title = AnsiParser.parseAsSpannable(text, parseFlags) | ||
} | ||
|
||
inline fun AlertDialog.setAnsiTitle(text: String, parseFlags: Int = 0) { | ||
this.setTitle(AnsiParser.parseAsSpannable(text, parseFlags)) | ||
} | ||
|
||
inline fun AlertDialog.setAnsiMessage(text: String, parseFlags: Int = 0) { | ||
this.setMessage(AnsiParser.parseAsSpannable(text, parseFlags)) | ||
} | ||
|
||
inline fun ActionBar.setAnsiTitle(text: String, parseFlags: Int = 0) { | ||
this.title = AnsiParser.parseAsSpannable(text, parseFlags) | ||
} | ||
|
||
inline fun ActionBar.setAnsiSubtitle(text: String, parseFlags: Int = 0) { | ||
this.subtitle = AnsiParser.parseAsSpannable(text, parseFlags) | ||
} |
24 changes: 24 additions & 0 deletions
24
library-ktx/src/main/java/com/fox2code/androidansi/ktx/AnsiXExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@file:Suppress("NOTHING_TO_INLINE") // Aliases to public API. | ||
|
||
package com.fox2code.androidansi.ktx | ||
|
||
import androidx.appcompat.app.ActionBar | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.appcompat.app.AppCompatDialog | ||
import com.fox2code.androidansi.AnsiParser | ||
|
||
inline fun AppCompatDialog.setAnsiTitle(text: String, parseFlags: Int = 0) { | ||
this.setTitle(AnsiParser.parseAsSpannable(text, parseFlags)) | ||
} | ||
|
||
inline fun AlertDialog.setAnsiMessage(text: String, parseFlags: Int = 0) { | ||
this.setMessage(AnsiParser.parseAsSpannable(text, parseFlags)) | ||
} | ||
|
||
inline fun ActionBar.setAnsiTitle(text: String, parseFlags: Int = 0) { | ||
this.title = AnsiParser.parseAsSpannable(text, parseFlags) | ||
} | ||
|
||
inline fun ActionBar.setAnsiSubtitle(text: String, parseFlags: Int = 0) { | ||
this.subtitle = AnsiParser.parseAsSpannable(text, parseFlags) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="com.fox2code.androidansi"> | ||
<manifest> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.