Skip to content

Commit

Permalink
Update 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox2Code committed May 2, 2023
1 parent 149555c commit 5847530
Show file tree
Hide file tree
Showing 20 changed files with 259 additions and 28 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ repositories {
dependencies {
implementation 'com.github.Fox2Code:AndroidANSI:1.0.1'
implementation 'com.github.Fox2Code.AndroidANSI:library:1.1.0'
// You can also add the ktx module for the kotlin extension.
implementation 'com.github.Fox2Code.AndroidANSI:library-ktx:1.1.0'
}
```

Expand Down
22 changes: 15 additions & 7 deletions androidansiapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ plugins {
id 'com.android.application'
}

final int androidTargetSdk = // Parse property once
Integer.parseInt(project['andorid.targetSdk'] as String)

android {
compileSdk 32
namespace 'com.fox2code.androidansiapp'
compileSdk androidTargetSdk

defaultConfig {
applicationId "com.fox2code.androidansiapp"
minSdk 16
targetSdk 32
targetSdk androidTargetSdk
versionCode 1
versionName "1.0"

Expand All @@ -21,6 +25,9 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand All @@ -29,10 +36,11 @@ android {

dependencies {
implementation(project(":library"))
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
implementation(project(":library-ktx"))
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
3 changes: 1 addition & 2 deletions androidansiapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fox2code.androidansiapp">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand Down
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.library' version '7.2.1' apply false
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.4.2' apply false
id 'com.android.application' version '7.4.2' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}

task clean(type: Delete) {
Expand Down
8 changes: 7 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ android.useAndroidX=true
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
# Update already
android.disableAutomaticComponentCreation=true
# Android targt SDK
andorid.targetSdk=33
# Library version
library.version=1.1.0
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
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
1 change: 1 addition & 0 deletions library-ktx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
63 changes: 63 additions & 0 deletions library-ktx/build.gradle
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 added library-ktx/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions library-ktx/proguard-rules.pro
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
4 changes: 4 additions & 0 deletions library-ktx/src/main/AndroidManifest.xml
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>
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)
}
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)
}
28 changes: 21 additions & 7 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ plugins {
id 'maven-publish'
}

group = 'com.github.Fox2Code'
version = '1.0'
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 {
compileSdk 32
namespace 'com.fox2code.androidansi'

compileSdk androidTargetSdk

defaultConfig {
minSdk 16
targetSdk 32
targetSdk androidTargetSdk

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand All @@ -27,11 +32,20 @@ android {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
publishing {
singleVariant('release') {
withSourcesJar()
withJavadocJar()
}
}
}

dependencies {
//noinspection GradleDependency (Newer versions use Kotlin)
api 'androidx.annotation:annotation:1.3.0'
compileOnly('androidx.emoji2:emoji2-views-helper:1.1.0') {
//noinspection GradleDependency (Version used by Kotlin)
api 'org.jetbrains:annotations:13.0'
compileOnly('androidx.emoji2:emoji2-views-helper:1.3.0') {
transitive = false
}
}
Expand All @@ -43,8 +57,8 @@ afterEvaluate {
release(MavenPublication) {
from components.release
groupId = project.group
artifactId = 'AndroidANSI'
version = project.version
artifactId = 'library'
version = '1.0' // JitPack only support 1.0
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/AndroidManifest.xml
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>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import androidx.annotation.ColorInt;

import org.jetbrains.annotations.Contract;

// https://gist.github.com/Prakasaka/219fe5695beeb4d6311583e79933a009
// https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
public final class AnsiConstants {
Expand Down Expand Up @@ -45,6 +47,7 @@ public int transform(@ColorInt int color, int role) {
COLOR_BRIGHT_WHITE = Color.rgb(255, 255, 255);

@ColorInt
@Contract(pure = true)
static int colorForAnsiCode(int colorAnsi) {
int m = colorAnsi / 10;
if (m == 4 || m == 10)
Expand Down
Loading

0 comments on commit 5847530

Please sign in to comment.