diff --git a/README.md b/README.md
index 4e39826..834cec6 100755
--- a/README.md
+++ b/README.md
@@ -1,4 +1,3 @@
-[![version][badge]][link]
@@ -50,6 +49,3 @@ License
See the License for the specific language governing permissions and
limitations under the License.
-
-[link]: https://github.com/StringCare/AndroidLibrary
-[badge]: https://img.shields.io/bintray/v/efff/maven/StringCareAndroidLibrary.svg
diff --git a/app/build.gradle b/app/build.gradle
index fb671a9..57b192f 100755
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,6 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
-apply plugin: 'kotlin-android-extensions'
+
apply plugin: StringCare
stringcare {
@@ -11,9 +11,6 @@ stringcare {
}
android {
- signingConfigs {
-
- }
compileSdkVersion 30
defaultConfig {
@@ -23,7 +20,9 @@ android {
versionCode 1
versionName "1.0"
}
+
flavorDimensions "type"
+
buildTypes {
release {
minifyEnabled false
@@ -34,6 +33,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
+
productFlavors {
prod {
dimension "type"
@@ -54,22 +54,17 @@ android {
}
}
-repositories {
- jcenter()
-}
-
-
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
- implementation 'androidx.appcompat:appcompat:1.2.0'
+ implementation 'androidx.appcompat:appcompat:1.3.0'
testImplementation 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'commons-io:commons-io:2.5'
- // implementation project(path: ':library')
- implementation "com.stringcare:library:$stringcare_version"
+ implementation project(path: ':library')
+ // implementation "com.stringcare:library:$stringcare_version"
}
diff --git a/app/src/main/java/com/efraespada/stringobfuscator/MainActivity.java b/app/src/main/java/com/efraespada/stringobfuscator/MainActivity.java
deleted file mode 100755
index 9bd4f34..0000000
--- a/app/src/main/java/com/efraespada/stringobfuscator/MainActivity.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.efraespada.stringobfuscator;
-
-import android.os.Bundle;
-import androidx.appcompat.app.AppCompatActivity;
-import android.widget.TextView;
-
-import com.stringcare.library.SC;
-import com.stringcare.library.SCTextView;
-import com.stringcare.library.Version;
-
-public class MainActivity extends AppCompatActivity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- SC.init(getApplicationContext());
-
- String password = getString(R.string.snake_msg_hidden);
- String original = SC.reveal(password, Version.V3);
-
- String message = "Snake, the password is " + password + original;
-
- ((TextView) findViewById(R.id.programmatically_obfuscation)).setText(message);
-
- String numbers = getString(R.string.pattern, "hi", 3) + " is " + SC.reveal(R.string.pattern, "hi", 3);
- ((TextView) findViewById(R.id.pattern)).setText(numbers);
-
- final SCTextView tvAuto = findViewById(R.id.auto_tv);
- findViewById(R.id.btn_change).setOnClickListener(v -> {
- if (tvAuto.isHtmlEnabled()) {
- tvAuto.setHtmlSupport(!tvAuto.isHtmlEnabled());
- } else if (tvAuto.isRevealingValue()) {
- tvAuto.setRevealed(!tvAuto.isRevealingValue());
- } else if (!tvAuto.isRevealingValue()) {
- tvAuto.setRevealed(!tvAuto.isRevealingValue());
- tvAuto.setHtmlSupport(!tvAuto.isHtmlEnabled());
- }
- });
-
- boolean equals = SC.reveal(R.string.hello_world_b).equals(getString(R.string.hello_world_a));
- String areEquals = "Same result: " + equals;
- ((TextView) findViewById(R.id.same_value)).setText(areEquals);
-
- String jsonObjectName = SC.reveal(R.string.asset_json_file);
- SC.asset().asyncJson(jsonObjectName, json ->
- ((TextView) findViewById(R.id.json_object)).setText(json.toString())
- );
- SC.asset().asyncBytes(jsonObjectName, bytes -> ((TextView) findViewById(R.id.json_object_original)).setText(new String(bytes)), false);
-
- String jsonArrayName = SC.reveal(R.string.asset_json_raw_file);
- SC.asset().asyncJsonArray(jsonArrayName, json -> ((TextView) findViewById(R.id.json_array)).setText(json.toString()));
- SC.asset().asyncBytes(jsonArrayName, bytes -> ((TextView) findViewById(R.id.json_array_original)).setText(new String(bytes)), false);
-
- }
-}
diff --git a/app/src/main/java/com/efraespada/stringobfuscator/MainActivity.kt b/app/src/main/java/com/efraespada/stringobfuscator/MainActivity.kt
new file mode 100755
index 0000000..b96076e
--- /dev/null
+++ b/app/src/main/java/com/efraespada/stringobfuscator/MainActivity.kt
@@ -0,0 +1,51 @@
+package com.efraespada.stringobfuscator
+
+import android.os.Bundle
+import android.view.View
+import android.widget.TextView
+import androidx.appcompat.app.AppCompatActivity
+import com.stringcare.library.*
+import com.stringcare.library.SC.Companion.init
+import com.stringcare.library.SC.Companion.reveal
+
+class MainActivity : AppCompatActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_main)
+ init(applicationContext)
+ val password = getString(R.string.snake_msg_hidden)
+ val original = reveal(password, Version.V3)
+ val message = "Snake, the password is $password$original"
+ (findViewById(R.id.programmatically_obfuscation) as TextView).text = message
+ val numbers =
+ getString(R.string.pattern, "hi", 3) + " is " + reveal(R.string.pattern, "hi", 3)
+ (findViewById(R.id.pattern) as TextView).text = numbers
+ val tvAuto = findViewById(R.id.auto_tv)
+ findViewById(R.id.btn_change).setOnClickListener { v: View? ->
+ if (tvAuto.isHtmlEnabled) {
+ tvAuto.setHtmlSupport(!tvAuto.isHtmlEnabled)
+ } else if (tvAuto.isRevealingValue) {
+ tvAuto.setRevealed(!tvAuto.isRevealingValue)
+ } else if (!tvAuto.isRevealingValue) {
+ tvAuto.setRevealed(!tvAuto.isRevealingValue)
+ tvAuto.setHtmlSupport(!tvAuto.isHtmlEnabled)
+ }
+ }
+ val equals = reveal(R.string.hello_world_b) == getString(R.string.hello_world_a)
+ val areEquals = "Same result: $equals"
+ (findViewById(R.id.same_value) as TextView).text = areEquals
+ val jsonObjectName = R.string.asset_json_file.reveal()
+
+
+ findViewById(R.id.json_object).text = jsonObjectName.json().toString()
+ findViewById(R.id.json_object_original).text =
+ String(jsonObjectName.bytes { false })
+
+
+ val jsonArrayName = R.string.asset_json_raw_file.reveal()
+ findViewById(R.id.json_array).text = jsonArrayName.jsonArray().toString()
+ findViewById(R.id.json_array_original).text =
+ jsonArrayName.bytes { false }.toString()
+
+ }
+}
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 64baf2e..549741b 100755
--- a/build.gradle
+++ b/build.gradle
@@ -1,26 +1,21 @@
-
buildscript {
- ext.kotlin_version = '1.4.0'
ext {
- stringcare_version = '4.0.1'
+ kotlin_version = '1.5.10'
+ stringcare_version = '4.2.1'
}
repositories {
- jcenter()
google()
- mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
- classpath "com.stringcare:plugin:$stringcare_version"
- // classpath files('../KotlinGradlePlugin/build/libs/plugin-4.0.0.jar')
- classpath 'com.android.tools.build:gradle:4.0.1'
- classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5"
- classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
+ classpath "io.github.stringcare:plugin:$stringcare_version"
+ // classpath files('../KotlinGradlePlugin/build/libs/plugin-4.0.6.jar')
+ classpath 'com.android.tools.build:gradle:4.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
@@ -28,8 +23,6 @@ buildscript {
allprojects {
repositories {
- mavenCentral()
- jcenter()
google()
maven {
url "https://plugins.gradle.org/m2/"
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 2ad3d9d..814f229 100755
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
diff --git a/library/build.gradle b/library/build.gradle
index 1dfdcc5..977629d 100755
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -1,10 +1,9 @@
-apply plugin: 'com.android.library'
-apply plugin: 'kotlin-android'
-apply plugin: 'kotlin-android-extensions'
-apply plugin: 'com.github.dcendents.android-maven'
-apply plugin: 'com.jfrog.bintray'
-
-version = "4.0.1"
+plugins {
+ id 'com.android.library'
+ id 'kotlin-android'
+ id 'maven-publish'
+ id 'signing'
+}
android {
compileSdkVersion 30
@@ -45,8 +44,7 @@ dependencies {
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
- implementation 'androidx.appcompat:appcompat:1.2.0'
- implementation 'org.jetbrains.anko:anko:0.10.8'
+ implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'org.apache.commons:commons-lang3:3.9'
testImplementation 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
@@ -55,39 +53,11 @@ dependencies {
def siteUrl = 'https://github.com/StringCare/AndroidLibrary'
def gitUrl = 'https://github.com/StringCare/AndroidLibrary.git'
-group = "com.stringcare"
+group = "io.github.stringcare"
+version = "4.2.1"
-install {
- repositories.mavenInstaller {
- // This generates POM.xml with proper parameters
- pom {
- project {
- packaging 'aar'
- name 'StringCareAndroidLibrary'
- url siteUrl
- // Set your license
- licenses {
- license {
- name 'The Apache Software License, Version 2.0'
- url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
- }
- }
- developers {
- developer {
- id 'efraespada'
- name 'efraespada'
- email 'efraespada@gmail.com'
- }
- }
- scm {
- connection gitUrl
- developerConnection gitUrl
- url siteUrl
- }
- }
- }
- }
-}
+Properties properties = new Properties()
+properties.load(project.rootProject.file('local.properties').newDataInputStream())
task sourcesJar(type: Jar) {
classifier = 'sources'
@@ -106,26 +76,54 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
}
-artifacts {
- archives javadocJar
- archives sourcesJar
-}
+afterEvaluate {
+ publishing {
+ publications {
+ library(MavenPublication) {
+ artifacts = [javadocJar, sourcesJar]
+ from components.release
+ artifactId = "library"
+ pom {
+ packaging = 'aar'
+ name = 'StringCareAndroidLibrary'
+ description = "Stringcare Android library"
+ url = siteUrl
+ scm {
+ connection = gitUrl
+ developerConnection = gitUrl
+ url = siteUrl
+ }
+ licenses {
+ license {
+ name = 'The Apache License, Version 2.0'
+ url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
+ }
+ }
+ developers {
+ developer {
+ id = 'efraespada'
+ name = 'efraespada'
+ email = 'efraespada@gmail.com'
+ }
+ }
+ }
+ }
+ }
+ repositories {
+ maven {
+ //def releaseRepo = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
+ // def snapshotRepo = "https://oss.sonatype.org/content/repositories/snapshots/"
+ url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
+ credentials {
+ username = properties["nexusUsername"]
+ password = properties["nexusPassword"]
+ }
+ }
+ }
+ }
-Properties properties = new Properties()
-properties.load(project.rootProject.file('local.properties').newDataInputStream())
-bintray {
- user = properties.getProperty("bintrayUser")
- key = properties.getProperty("bintrayApiKey")
- configurations = ['archives']
- pkg {
- repo = "maven"
- name = "StringCareAndroidLibrary"
- websiteUrl = siteUrl
- vcsUrl = gitUrl
- licenses = ["Apache-2.0"]
- publish = true
+ signing {
+ useGpgCmd()
+ sign publishing.publications.library
}
}
-repositories {
- mavenCentral()
-}
\ No newline at end of file
diff --git a/library/src/main/java/com/stringcare/library/SC.kt b/library/src/main/java/com/stringcare/library/SC.kt
index 6d4f7c9..ba94ef8 100755
--- a/library/src/main/java/com/stringcare/library/SC.kt
+++ b/library/src/main/java/com/stringcare/library/SC.kt
@@ -3,7 +3,6 @@ package com.stringcare.library
import android.content.Context
import androidx.annotation.StringRes
import android.util.Log
-import org.jetbrains.anko.doAsync
import org.json.JSONArray
import org.json.JSONObject
import java.nio.charset.Charset
@@ -311,96 +310,25 @@ class SC {
}
class Assets {
- fun json(path: String, predicate: () -> Boolean): JSONObject {
- val bytes = assetByteArray(path, predicate)
- return JSONObject(String(bytes, Charset.forName("UTF-8")))
+ fun json(path: String) = try {
+ JSONObject(String(assetByteArray(path), Charset.forName("UTF-8")))
+ } catch (e: Exception) {
+ print(e)
+ JSONObject()
}
- fun asyncJson(path: String,
- predicate: () -> Boolean = { true },
- json: (json: JSONObject) -> Unit) {
- doAsync {
- val j = json(path, predicate)
- json(j)
- }
- }
-
- fun jsonArray(path: String, predicate: () -> Boolean): JSONArray {
- val bytes = assetByteArray(path, predicate)
- return JSONArray(String(bytes, Charset.forName("UTF-8")))
- }
-
- fun asyncJsonArray(path: String,
- predicate: () -> Boolean = { true },
- json: (json: JSONArray) -> Unit) {
- doAsync {
- val j = jsonArray(path, predicate)
- json(j)
- }
- }
-
- fun json(path: String): JSONObject {
- return json(path) { true }
- }
-
- fun json(path: String, predicate: Boolean): JSONObject {
- return json(path) { predicate }
- }
-
- fun asyncJson(path: String, jsonObjectListener: JSONObjectListener) {
- asyncJson(path, jsonObjectListener, true)
- }
-
- fun asyncJson(path: String, jsonObjectListener: JSONObjectListener, predicate: Boolean) {
- asyncJson(path, { predicate }, jsonObjectListener::assetReady)
- }
-
- fun jsonArray(path: String): JSONArray {
- return jsonArray(path) { true }
- }
-
- fun jsonArray(path: String, predicate: Boolean): JSONArray {
- return jsonArray(path) { predicate }
- }
-
- fun asyncJsonArray(path: String, jsonArrayListener: JSONArrayListener) {
- asyncJsonArray(path, jsonArrayListener, true)
- }
-
- fun asyncJsonArray(path: String, jsonArrayListener: JSONArrayListener, predicate: Boolean) {
- asyncJsonArray(path, { predicate }, jsonArrayListener::assetReady)
+ fun jsonArray(path: String) = try {
+ JSONArray(String(assetByteArray(path), Charset.forName("UTF-8")))
+ } catch (e: Exception) {
+ print(e)
+ JSONArray()
}
- fun bytes(path: String, predicate: () -> Boolean): ByteArray {
- return assetByteArray(path, predicate)
- }
-
- fun asyncBytes(path: String,
- predicate: () -> Boolean = { true },
- bytes: (bytes: ByteArray) -> Unit) {
- doAsync {
- bytes(assetByteArray(path, predicate))
- }
- }
+ fun bytes(path: String, predicate: () -> Boolean) = assetByteArray(path, predicate)
- fun bytes(path: String): ByteArray {
- return bytes(path, true)
- }
-
- fun bytes(path: String, predicate: Boolean): ByteArray {
- return bytes(path) { predicate }
- }
-
- fun asyncBytes(path: String, byteArrayListener: AssetByteArrayListener) {
- asyncBytes(path, byteArrayListener, true)
- }
-
- fun asyncBytes(path: String, byteArrayListener: AssetByteArrayListener, predicate: Boolean) {
- doAsync {
- asyncBytes(path, { predicate }, byteArrayListener::assetReady)
- }
- }
+ fun bytes(path: String, predicate: Boolean) = bytes(path) { predicate }
+ fun bytes(path: String) = bytes(path, true)
}
external fun jniObfuscateV1(context: Context, key: String, value: String): String
diff --git a/library/src/main/java/com/stringcare/library/SCTextView.java b/library/src/main/java/com/stringcare/library/SCTextView.java
deleted file mode 100644
index 59bd45c..0000000
--- a/library/src/main/java/com/stringcare/library/SCTextView.java
+++ /dev/null
@@ -1,158 +0,0 @@
-package com.stringcare.library;
-
-import android.content.Context;
-import androidx.appcompat.widget.AppCompatTextView;
-import android.text.Html;
-import android.util.AttributeSet;
-
-/*
- * Credits to Narvelan:
- * https://github.com/StringCare/AndroidLibrary/issues/34
- */
-
-public class SCTextView extends AppCompatTextView {
-
- private String text;
- private Boolean isHTML;
- private Boolean androidTreatment;
- private Boolean revealed;
-
- public SCTextView(Context context) {
- super(context);
- isHTML = null;
- revealed = null;
- androidTreatment = null;
- }
-
- public SCTextView(Context context, AttributeSet attrs) {
- super(context, attrs);
- isHTML = null;
- revealed = null;
- androidTreatment = null;
- loadText(attrs);
- }
-
- public SCTextView(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- isHTML = null;
- revealed = null;
- androidTreatment = null;
- loadText(attrs);
- }
-
- /**
- * Sets the initial parameters
- *
- * @param attrs {AttributeSet}
- */
- private void loadText(final AttributeSet attrs) {
- String mFalse = "false";
-
- String mResourceAndroidSchema = "http://schemas.android.com/apk/res/android";
- String textName = "text";
-
- String mResourceSchema = "http://schemas.android.com/apk/res-auto";
- String htmlName = "htmlSupport";
- String revealValue = "reveal";
- String androidTreatmentName = "androidTreatment";
-
- text = attrs.getAttributeValue(mResourceAndroidSchema, textName);
- if (isHTML == null) {
- isHTML = !mFalse.equalsIgnoreCase(attrs.getAttributeValue(mResourceSchema, htmlName));
- }
- if (revealed == null) {
- revealed = !mFalse.equalsIgnoreCase(attrs.getAttributeValue(mResourceSchema, revealValue));
- }
- if (androidTreatment == null) {
- androidTreatment = !mFalse.equalsIgnoreCase(attrs.getAttributeValue(mResourceSchema, androidTreatmentName));
- }
-
- reloadText();
- }
-
- /**
- * Prints text with the given conditions
- */
- private void reloadText() {
- if (text != null) {
- try {
- final int val = Integer.parseInt(text.substring(1));
- if (!isRevealingValue()) {
- setText(getContext().getString(val));
- return;
- }
- SC.onContextReady(new ContextListener() {
- @Override
- public void contextReady() {
- String value = SC.reveal(val, usesAndroidTreatment());
- if (isHtmlEnabled()) {
- setText(Html.fromHtml(value));
- } else {
- setText(value);
- }
- }
- });
- } catch (NumberFormatException e) {
- setText(text);
- }
- }
- }
-
- /**
- * Reveals the value before print it
- *
- * @param revealed {true|false}
- */
- public void setRevealed(boolean revealed) {
- this.revealed = revealed;
- reloadText();
- }
-
- /**
- * Enables HTML printing
- *
- * @param enabled {true|false}
- */
- public void setHtmlSupport(boolean enabled) {
- isHTML = enabled;
- reloadText();
- }
-
- /**
- * Enables the Android treatment
- *
- * @param enabled {true|false}
- */
- public void setAndroidTreatment(boolean enabled) {
- androidTreatment = enabled;
- reloadText();
- }
-
- /**
- * Returns true if is the value must be print as HTML
- *
- * @return Boolean
- */
- public boolean isHtmlEnabled() {
- return Boolean.TRUE.equals(isHTML);
- }
-
- /**
- * Returns true if the value must be treated as the Android system does
- *
- * @return Boolean
- */
- public boolean usesAndroidTreatment() {
- return Boolean.TRUE.equals(androidTreatment);
- }
-
- /**
- * Returns true if the value should be setRevealed before print it
- *
- * @return Boolean
- */
- public boolean isRevealingValue() {
- return Boolean.TRUE.equals(revealed);
- }
-
-}
diff --git a/library/src/main/java/com/stringcare/library/SCTextView.kt b/library/src/main/java/com/stringcare/library/SCTextView.kt
new file mode 100644
index 0000000..2dec590
--- /dev/null
+++ b/library/src/main/java/com/stringcare/library/SCTextView.kt
@@ -0,0 +1,160 @@
+package com.stringcare.library
+
+import android.content.Context
+import android.text.Html
+import android.util.AttributeSet
+import androidx.appcompat.widget.AppCompatTextView
+import com.stringcare.library.SC.Companion.onContextReady
+import com.stringcare.library.SC.Companion.reveal
+
+/*
+ * Credits to Narvelan:
+ * https://github.com/StringCare/AndroidLibrary/issues/34
+ */
+class SCTextView : AppCompatTextView {
+ private var text: String? = null
+ private var isHTML: Boolean?
+ private var androidTreatment: Boolean?
+ private var revealed: Boolean?
+
+ constructor(context: Context?) : super(context!!) {
+ isHTML = null
+ revealed = null
+ androidTreatment = null
+ }
+
+ constructor(context: Context?, attrs: AttributeSet) : super(
+ context!!, attrs
+ ) {
+ isHTML = null
+ revealed = null
+ androidTreatment = null
+ loadText(attrs)
+ }
+
+ constructor(context: Context?, attrs: AttributeSet, defStyleAttr: Int) : super(
+ context!!, attrs, defStyleAttr
+ ) {
+ isHTML = null
+ revealed = null
+ androidTreatment = null
+ loadText(attrs)
+ }
+
+ /**
+ * Sets the initial parameters
+ *
+ * @param attrs {AttributeSet}
+ */
+ private fun loadText(attrs: AttributeSet) {
+ val mFalse = "false"
+ val mResourceAndroidSchema = "http://schemas.android.com/apk/res/android"
+ val textName = "text"
+ val mResourceSchema = "http://schemas.android.com/apk/res-auto"
+ val htmlName = "htmlSupport"
+ val revealValue = "reveal"
+ val androidTreatmentName = "androidTreatment"
+ text = attrs.getAttributeValue(mResourceAndroidSchema, textName)
+ if (isHTML == null) {
+ isHTML = !mFalse.equals(
+ attrs.getAttributeValue(mResourceSchema, htmlName),
+ ignoreCase = true
+ )
+ }
+ if (revealed == null) {
+ revealed = !mFalse.equals(
+ attrs.getAttributeValue(mResourceSchema, revealValue),
+ ignoreCase = true
+ )
+ }
+ if (androidTreatment == null) {
+ androidTreatment = !mFalse.equals(
+ attrs.getAttributeValue(mResourceSchema, androidTreatmentName),
+ ignoreCase = true
+ )
+ }
+ reloadText()
+ }
+
+ /**
+ * Prints text with the given conditions
+ */
+ private fun reloadText() {
+ if (text != null) {
+ try {
+ val rawValue = text!!.substring(1).toInt()
+ if (!isRevealingValue) {
+ setText(context.getString(rawValue))
+ return
+ }
+ onContextReady(object : ContextListener {
+ override fun contextReady() {
+ val value = reveal(rawValue, usesAndroidTreatment())
+ if (isHtmlEnabled) {
+ setText(Html.fromHtml(value))
+ } else {
+ setText(value)
+ }
+ }
+ })
+ } catch (e: NumberFormatException) {
+ setText(text)
+ }
+ }
+ }
+
+ /**
+ * Reveals the value before print it
+ *
+ * @param revealed {true|false}
+ */
+ fun setRevealed(revealed: Boolean) {
+ this.revealed = revealed
+ reloadText()
+ }
+
+ /**
+ * Enables HTML printing
+ *
+ * @param enabled {true|false}
+ */
+ fun setHtmlSupport(enabled: Boolean) {
+ isHTML = enabled
+ reloadText()
+ }
+
+ /**
+ * Enables the Android treatment
+ *
+ * @param enabled {true|false}
+ */
+ fun setAndroidTreatment(enabled: Boolean) {
+ androidTreatment = enabled
+ reloadText()
+ }
+
+ /**
+ * Returns true if is the value must be print as HTML
+ *
+ * @return Boolean
+ */
+ val isHtmlEnabled: Boolean
+ get() = java.lang.Boolean.TRUE == isHTML
+
+ /**
+ * Returns true if the value must be treated as the Android system does
+ *
+ * @return Boolean
+ */
+ fun usesAndroidTreatment(): Boolean {
+ return java.lang.Boolean.TRUE == androidTreatment
+ }
+
+ /**
+ * Returns true if the value should be setRevealed before print it
+ *
+ * @return Boolean
+ */
+ val isRevealingValue: Boolean
+ get() = java.lang.Boolean.TRUE == revealed
+}
\ No newline at end of file
diff --git a/library/src/main/java/com/stringcare/library/StringExt.kt b/library/src/main/java/com/stringcare/library/StringExt.kt
index 869a34e..eecebbd 100644
--- a/library/src/main/java/com/stringcare/library/StringExt.kt
+++ b/library/src/main/java/com/stringcare/library/StringExt.kt
@@ -26,29 +26,10 @@ fun String.reveal(
version: Version = defaultVersion
): String = SC.reveal(this, androidTreatment, version)
-fun String.json(
- predicate: () -> Boolean = { true }
-): JSONObject = SC.asset().json(this, predicate)
-
-fun String.asyncJson(
- predicate: () -> Boolean = { true },
- json: (json: JSONObject) -> Unit
-) = SC.asset().asyncJson(this, predicate, json)
+fun String.json(): JSONObject = SC.asset().json(this)
-fun String.jsonArray(
- predicate: () -> Boolean = { true }
-): JSONArray = SC.asset().jsonArray(this, predicate)
-
-fun String.asyncJsonArray(
- predicate: () -> Boolean = { true },
- json: (json: JSONArray) -> Unit
-) = SC.asset().asyncJsonArray(this, predicate, json)
+fun String.jsonArray(): JSONArray = SC.asset().jsonArray(this)
fun String.bytes(
predicate: () -> Boolean = { true }
): ByteArray = SC.asset().bytes(this, predicate)
-
-fun String.asyncBytes(
- predicate: () -> Boolean = { true },
- bytes: (bytes: ByteArray) -> Unit
-) = SC.asset().asyncBytes(this, predicate, bytes)