From 3cd98b3a46e775413e40e940ae0fa5bcffca0700 Mon Sep 17 00:00:00 2001 From: Efra Espada Date: Sat, 17 Aug 2019 16:48:40 +0200 Subject: [PATCH 1/5] obfuscating assets --- app/build.gradle | 4 +- app/src/main/assets/test.json | 4 ++ build.gradle | 12 ++-- gradle/wrapper/gradle-wrapper.properties | 4 +- .../java/com/stringcare/library/CPlusLogic.kt | 55 ++++++++++++------- 5 files changed, 52 insertions(+), 27 deletions(-) create mode 100644 app/src/main/assets/test.json diff --git a/app/build.gradle b/app/build.gradle index 7a673b7..5da86ea 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -55,9 +55,9 @@ dependencies { }) implementation 'com.android.support:appcompat-v7:28.0.0' testImplementation 'junit:junit:4.12' - // implementation project(path: ':library') + implementation project(path: ':library') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation "com.stringcare:library:$stringcare_version" + // implementation "com.stringcare:library:$stringcare_version" } diff --git a/app/src/main/assets/test.json b/app/src/main/assets/test.json new file mode 100644 index 0000000..5b7ee43 --- /dev/null +++ b/app/src/main/assets/test.json @@ -0,0 +1,4 @@ +{ + "user": "user123", + "message": "hello world" +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index e0dad05..3cae8db 100755 --- a/build.gradle +++ b/build.gradle @@ -16,9 +16,9 @@ buildscript { } dependencies { - classpath "com.stringcare:plugin:$stringcare_version" - // classpath files('../KotlinGradlePlugin/build/libs/plugin-3.1.jar') - classpath 'com.android.tools.build:gradle:3.4.2' + // classpath "com.stringcare:plugin:$stringcare_version" + classpath files('../KotlinGradlePlugin/build/libs/plugin-3.3.jar') + classpath 'com.android.tools.build:gradle:3.6.0-alpha06' classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1" classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" @@ -44,7 +44,11 @@ apply plugin: StringCare stringcare { debug true - + modules { + app { + assetsFiles = ["*.json"] + } + } variants { prod { skip = true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6217071..c82546e 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat May 25 04:13:40 CEST 2019 +#Fri Aug 16 21:23:15 CEST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip diff --git a/library/src/main/java/com/stringcare/library/CPlusLogic.kt b/library/src/main/java/com/stringcare/library/CPlusLogic.kt index 4ced1ce..adbe361 100644 --- a/library/src/main/java/com/stringcare/library/CPlusLogic.kt +++ b/library/src/main/java/com/stringcare/library/CPlusLogic.kt @@ -2,10 +2,9 @@ package com.stringcare.library import android.content.Context import android.content.res.Resources -import android.os.Build import android.support.annotation.StringRes import java.nio.charset.Charset -import java.util.* +import kotlin.Exception class CPlusLogic { @@ -75,8 +74,13 @@ class CPlusLogic { */ @JvmStatic fun revealV2(context: Context, @StringRes id: Int): String { - val arr: ByteArray = context.getString(id).split(", ").map { it.toInt().toByte() }.toByteArray() - return String(SC().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr)) + val value = context.getString(id) + return try { + val arr: ByteArray = value.split(", ").map { it.toInt().toByte() }.toByteArray() + String(SC().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr)) + } catch (e: Exception) { + value + } } /** @@ -86,8 +90,12 @@ class CPlusLogic { */ @JvmStatic fun revealV2(context: Context, value: String): String { - val arr: ByteArray = value.split(", ").map { it.toInt().toByte() }.toByteArray() - return String(SC().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr)) + return try { + val arr: ByteArray = value.split(", ").map { it.toInt().toByte() }.toByteArray() + return String(SC().jniRevealV2(context, getCertificateSHA1Fingerprint(context), arr)) + } catch (e: Exception) { + value + } } /** @@ -125,11 +133,16 @@ class CPlusLogic { */ @JvmStatic fun revealV3(context: Context, @StringRes id: Int, androidTreatment: Boolean): String { - val arr: ByteArray = context.getString(id).split(", ").map { it.toInt().toByte() }.toByteArray() - val reveal = String(SC().jniRevealV3(context, getCertificateSHA1Fingerprint(context), arr)) - return when (androidTreatment) { - true -> reveal.unescape() - false -> reveal + val value = context.getString(id) + return try { + val arr: ByteArray = value.split(", ").map { it.toInt().toByte() }.toByteArray() + val reveal = String(SC().jniRevealV3(context, getCertificateSHA1Fingerprint(context), arr)) + when (androidTreatment) { + true -> reveal.unescape() + false -> reveal + } + } catch (e: Exception) { + value } } @@ -140,14 +153,18 @@ class CPlusLogic { */ @JvmStatic fun revealV3(context: Context, value: String, androidTreatment: Boolean): String { - val arr: ByteArray = when (androidTreatment) { - true -> value.unescape() - false -> value - }.split(", ").map { it.toInt().toByte() }.toByteArray() - val reveal = String(SC().jniRevealV3(context, getCertificateSHA1Fingerprint(context), arr)) - return when (androidTreatment) { - true -> reveal.unescape() - false -> reveal + return try { + val arr: ByteArray = when (androidTreatment) { + true -> value.unescape() + false -> value + }.split(", ").map { it.toInt().toByte() }.toByteArray() + val reveal = String(SC().jniRevealV3(context, getCertificateSHA1Fingerprint(context), arr)) + when (androidTreatment) { + true -> reveal.unescape() + false -> reveal + } + } catch (e: Exception) { + value } } From 09982ab46330354d04afcffdb81fdb0095fe0db6 Mon Sep 17 00:00:00 2001 From: Efra Espada Date: Sat, 17 Aug 2019 18:46:56 +0200 Subject: [PATCH 2/5] revealing assets --- app/build.gradle | 5 +- app/src/main/assets/raw/test_array.json | 10 +++ .../stringobfuscator/MainActivity.java | 14 ++++ library/build.gradle | 3 +- .../library/AssetByteArrayListener.kt | 5 ++ .../com/stringcare/library/AssetListener.kt | 3 + .../java/com/stringcare/library/CPlusLogic.kt | 14 ++++ .../stringcare/library/JSONArrayListener.kt | 7 ++ .../stringcare/library/JSONObjectListener.kt | 7 ++ .../main/java/com/stringcare/library/SC.kt | 82 +++++++++++++++++++ 10 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 app/src/main/assets/raw/test_array.json create mode 100644 library/src/main/java/com/stringcare/library/AssetByteArrayListener.kt create mode 100644 library/src/main/java/com/stringcare/library/AssetListener.kt create mode 100644 library/src/main/java/com/stringcare/library/JSONArrayListener.kt create mode 100644 library/src/main/java/com/stringcare/library/JSONObjectListener.kt diff --git a/app/build.gradle b/app/build.gradle index 5da86ea..e239197 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,7 +11,7 @@ android { defaultConfig { applicationId "com.efraespada.stringobfuscator" - minSdkVersion 14 + minSdkVersion 15 targetSdkVersion 28 versionCode 1 versionName "1.0" @@ -57,7 +57,8 @@ dependencies { testImplementation 'junit:junit:4.12' implementation project(path: ':library') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - // implementation "com.stringcare:library:$stringcare_version" + implementation 'commons-io:commons-io:2.5' +// implementation "com.stringcare:library:$stringcare_version" } diff --git a/app/src/main/assets/raw/test_array.json b/app/src/main/assets/raw/test_array.json new file mode 100644 index 0000000..f6ad3d4 --- /dev/null +++ b/app/src/main/assets/raw/test_array.json @@ -0,0 +1,10 @@ +[ + { + "user": "user123", + "message": "hello world" + }, + { + "user": "user456", + "message": "hello there" + } +] \ No newline at end of file diff --git a/app/src/main/java/com/efraespada/stringobfuscator/MainActivity.java b/app/src/main/java/com/efraespada/stringobfuscator/MainActivity.java index 576af23..453c852 100755 --- a/app/src/main/java/com/efraespada/stringobfuscator/MainActivity.java +++ b/app/src/main/java/com/efraespada/stringobfuscator/MainActivity.java @@ -2,12 +2,16 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.util.Log; import android.widget.TextView; import com.stringcare.library.SC; import com.stringcare.library.SCTextView; import com.stringcare.library.Version; +import org.json.JSONArray; +import org.json.JSONObject; + public class MainActivity extends AppCompatActivity { @Override @@ -42,5 +46,15 @@ protected void onCreate(Bundle savedInstanceState) { 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); + + JSONObject jsonObject = SC.jsonObjectAsset("test.json"); + SC.jsonObjectAssetAsync("test.json", json -> { + String value = json.toString(); + }); + + JSONArray jsonArray = SC.jsonArrayAsset("raw/test_array.json"); + SC.jsonArrayAssetAsync("raw/test_array.json", json -> { + String value = json.toString(); + }); } } diff --git a/library/build.gradle b/library/build.gradle index d9ddd72..0aa70f2 100755 --- a/library/build.gradle +++ b/library/build.gradle @@ -11,7 +11,7 @@ android { buildToolsVersion '28.0.3' defaultConfig { - minSdkVersion 14 + minSdkVersion 15 targetSdkVersion 28 versionCode 4 versionName version @@ -46,6 +46,7 @@ dependencies { exclude group: 'com.android.support', module: 'support-annotations' }) implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'org.jetbrains.anko:anko:0.10.8' implementation 'org.apache.commons:commons-lang3:3.9' testImplementation 'junit:junit:4.12' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" diff --git a/library/src/main/java/com/stringcare/library/AssetByteArrayListener.kt b/library/src/main/java/com/stringcare/library/AssetByteArrayListener.kt new file mode 100644 index 0000000..e9a71e0 --- /dev/null +++ b/library/src/main/java/com/stringcare/library/AssetByteArrayListener.kt @@ -0,0 +1,5 @@ +package com.stringcare.library + +interface AssetByteArrayListener : AssetListener { + fun assetReady(byteArray: ByteArray) +} diff --git a/library/src/main/java/com/stringcare/library/AssetListener.kt b/library/src/main/java/com/stringcare/library/AssetListener.kt new file mode 100644 index 0000000..baa82fb --- /dev/null +++ b/library/src/main/java/com/stringcare/library/AssetListener.kt @@ -0,0 +1,3 @@ +package com.stringcare.library + +interface AssetListener diff --git a/library/src/main/java/com/stringcare/library/CPlusLogic.kt b/library/src/main/java/com/stringcare/library/CPlusLogic.kt index adbe361..8cdba29 100644 --- a/library/src/main/java/com/stringcare/library/CPlusLogic.kt +++ b/library/src/main/java/com/stringcare/library/CPlusLogic.kt @@ -179,6 +179,20 @@ class CPlusLogic { return java.lang.String.format(Resources.getSystem().locale(), revealV3(context, id, androidTreatment), *formatArgs) } + /** + * Reveals the given ByteArray + * @param value + * @return String + */ + @JvmStatic + fun revealByteArray(context: Context, value: ByteArray): ByteArray { + return try { + SC().jniRevealV3(context, getCertificateSHA1Fingerprint(context), value) + } catch (e: Exception) { + value + } + } + } } \ No newline at end of file diff --git a/library/src/main/java/com/stringcare/library/JSONArrayListener.kt b/library/src/main/java/com/stringcare/library/JSONArrayListener.kt new file mode 100644 index 0000000..385b601 --- /dev/null +++ b/library/src/main/java/com/stringcare/library/JSONArrayListener.kt @@ -0,0 +1,7 @@ +package com.stringcare.library + +import org.json.JSONArray + +interface JSONArrayListener : AssetListener { + fun assetReady(json: JSONArray) +} diff --git a/library/src/main/java/com/stringcare/library/JSONObjectListener.kt b/library/src/main/java/com/stringcare/library/JSONObjectListener.kt new file mode 100644 index 0000000..991ec15 --- /dev/null +++ b/library/src/main/java/com/stringcare/library/JSONObjectListener.kt @@ -0,0 +1,7 @@ +package com.stringcare.library + +import org.json.JSONObject + +interface JSONObjectListener : AssetListener { + fun assetReady(json: JSONObject) +} diff --git a/library/src/main/java/com/stringcare/library/SC.kt b/library/src/main/java/com/stringcare/library/SC.kt index 6273c2b..d74f457 100755 --- a/library/src/main/java/com/stringcare/library/SC.kt +++ b/library/src/main/java/com/stringcare/library/SC.kt @@ -3,6 +3,10 @@ package com.stringcare.library import android.content.Context import android.support.annotation.StringRes import android.util.Log +import org.jetbrains.anko.doAsync +import org.json.JSONArray +import org.json.JSONObject +import java.nio.charset.Charset /** * Created by efrainespada on 02/10/2016. @@ -290,6 +294,84 @@ class SC { } } + private fun assetByteArray(path: String, predicate: () -> Boolean = { true }): ByteArray { + val inputStream = context.assets.openFd(path) + var bytes = inputStream.createInputStream().readBytes() + if (predicate()) { + bytes = CPlusLogic.revealByteArray(context, bytes) + } + return bytes + } + + fun jsonObjectAsset(path: String, predicate: () -> Boolean): JSONObject { + val bytes = assetByteArray(path, predicate) + return JSONObject(String(bytes, Charset.forName("UTF-8"))) + } + + fun jsonObjectAssetAsync(path: String, json: (json: JSONObject) -> Unit, predicate: () -> Boolean) { + doAsync { + val j = jsonObjectAsset(path, predicate) + json(j) + } + } + + fun jsonArrayAsset(path: String, predicate: () -> Boolean): JSONArray { + val bytes = assetByteArray(path, predicate) + return JSONArray(String(bytes, Charset.forName("UTF-8"))) + } + + fun jsonArrayAssetAsync(path: String, json: (json: JSONArray) -> Unit, predicate: () -> Boolean) { + doAsync { + val j = jsonArrayAsset(path, predicate) + json(j) + } + } + + @JvmStatic + fun jsonObjectAsset(path: String): JSONObject { + return jsonObjectAsset(path) { true } + } + + @JvmStatic + fun jsonObjectAsset(path: String, predicate: Boolean): JSONObject { + return jsonObjectAsset(path) { predicate } + } + + @JvmStatic + fun jsonObjectAssetAsync(path: String, jsonObjectListener: JSONObjectListener) { + jsonObjectAssetAsync(path, jsonObjectListener, true) + } + + @JvmStatic + fun jsonObjectAssetAsync(path: String, jsonObjectListener: JSONObjectListener, predicate: Boolean) { + jsonObjectAssetAsync(path, { file -> + jsonObjectListener.assetReady(file) + }) { predicate } + } + + + @JvmStatic + fun jsonArrayAsset(path: String): JSONArray { + return jsonArrayAsset(path) { true } + } + + @JvmStatic + fun jsonArrayAsset(path: String, predicate: Boolean): JSONArray { + return jsonArrayAsset(path) { predicate } + } + + @JvmStatic + fun jsonArrayAssetAsync(path: String, jsonArrayListener: JSONArrayListener) { + jsonArrayAssetAsync(path, jsonArrayListener, true) + } + + @JvmStatic + fun jsonArrayAssetAsync(path: String, jsonArrayListener: JSONArrayListener, predicate: Boolean) { + jsonArrayAssetAsync(path, { file -> + jsonArrayListener.assetReady(file) + }) { predicate } + } + } From fd775a6210a517e1c911a9bfe92bd45282dbc541 Mon Sep 17 00:00:00 2001 From: Efra Espada Date: Sat, 17 Aug 2019 20:06:40 +0200 Subject: [PATCH 3/5] samples working --- .../stringobfuscator/MainActivity.java | 19 ++-- app/src/main/res/layout/activity_main.xml | 64 +++++++++++++ app/src/main/res/values/strings.xml | 4 + build.gradle | 1 - .../main/java/com/stringcare/library/SC.kt | 96 ++++++++++++------- .../java/com/stringcare/library/StringExt.kt | 30 ++++++ 6 files changed, 167 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/com/efraespada/stringobfuscator/MainActivity.java b/app/src/main/java/com/efraespada/stringobfuscator/MainActivity.java index 453c852..89bdf6a 100755 --- a/app/src/main/java/com/efraespada/stringobfuscator/MainActivity.java +++ b/app/src/main/java/com/efraespada/stringobfuscator/MainActivity.java @@ -2,16 +2,12 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; -import android.util.Log; import android.widget.TextView; import com.stringcare.library.SC; import com.stringcare.library.SCTextView; import com.stringcare.library.Version; -import org.json.JSONArray; -import org.json.JSONObject; - public class MainActivity extends AppCompatActivity { @Override @@ -47,14 +43,13 @@ protected void onCreate(Bundle savedInstanceState) { String areEquals = "Same result: " + equals; ((TextView) findViewById(R.id.same_value)).setText(areEquals); - JSONObject jsonObject = SC.jsonObjectAsset("test.json"); - SC.jsonObjectAssetAsync("test.json", json -> { - String value = json.toString(); - }); + 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); - JSONArray jsonArray = SC.jsonArrayAsset("raw/test_array.json"); - SC.jsonArrayAssetAsync("raw/test_array.json", json -> { - String value = json.toString(); - }); } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 70aacde..63eca97 100755 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -158,6 +158,70 @@ app:androidTreatment="false" app:visible="true" /> + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b5c6f97..0f78cac 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -16,9 +16,13 @@ + + Long New Line Comparison HTML treatment Programmatically Obfuscation Patterns String resource disabling Android treatment: + JSON Asset + JSON Array Raw Asset \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3cae8db..99cf2bf 100755 --- a/build.gradle +++ b/build.gradle @@ -51,7 +51,6 @@ stringcare { } variants { prod { - skip = true applicationId = "com.efraespada.stringobfuscator" } dev { diff --git a/library/src/main/java/com/stringcare/library/SC.kt b/library/src/main/java/com/stringcare/library/SC.kt index d74f457..a742981 100755 --- a/library/src/main/java/com/stringcare/library/SC.kt +++ b/library/src/main/java/com/stringcare/library/SC.kt @@ -303,75 +303,103 @@ class SC { return bytes } - fun jsonObjectAsset(path: String, predicate: () -> Boolean): JSONObject { + @JvmStatic + fun asset(): Assets { + return Assets() + } + + } + + class Assets { + fun json(path: String, predicate: () -> Boolean): JSONObject { val bytes = assetByteArray(path, predicate) return JSONObject(String(bytes, Charset.forName("UTF-8"))) } - fun jsonObjectAssetAsync(path: String, json: (json: JSONObject) -> Unit, predicate: () -> Boolean) { + fun asyncJson(path: String, + predicate: () -> Boolean = { true }, + json: (json: JSONObject) -> Unit) { doAsync { - val j = jsonObjectAsset(path, predicate) + val j = json(path, predicate) json(j) } } - fun jsonArrayAsset(path: String, predicate: () -> Boolean): JSONArray { + fun jsonArray(path: String, predicate: () -> Boolean): JSONArray { val bytes = assetByteArray(path, predicate) return JSONArray(String(bytes, Charset.forName("UTF-8"))) } - fun jsonArrayAssetAsync(path: String, json: (json: JSONArray) -> Unit, predicate: () -> Boolean) { + fun asyncJsonArray(path: String, + predicate: () -> Boolean = { true }, + json: (json: JSONArray) -> Unit) { doAsync { - val j = jsonArrayAsset(path, predicate) + val j = jsonArray(path, predicate) json(j) } } - @JvmStatic - fun jsonObjectAsset(path: String): JSONObject { - return jsonObjectAsset(path) { true } + fun json(path: String): JSONObject { + return json(path) { true } } - @JvmStatic - fun jsonObjectAsset(path: String, predicate: Boolean): JSONObject { - return jsonObjectAsset(path) { predicate } + fun json(path: String, predicate: Boolean): JSONObject { + return json(path) { predicate } } - @JvmStatic - fun jsonObjectAssetAsync(path: String, jsonObjectListener: JSONObjectListener) { - jsonObjectAssetAsync(path, jsonObjectListener, true) + fun asyncJson(path: String, jsonObjectListener: JSONObjectListener) { + asyncJson(path, jsonObjectListener, true) } - @JvmStatic - fun jsonObjectAssetAsync(path: String, jsonObjectListener: JSONObjectListener, predicate: Boolean) { - jsonObjectAssetAsync(path, { file -> - jsonObjectListener.assetReady(file) - }) { predicate } + fun asyncJson(path: String, jsonObjectListener: JSONObjectListener, predicate: Boolean) { + asyncJson(path, { predicate }, jsonObjectListener::assetReady) } + fun jsonArray(path: String): JSONArray { + return jsonArray(path) { true } + } - @JvmStatic - fun jsonArrayAsset(path: String): JSONArray { - return jsonArrayAsset(path) { true } + fun jsonArray(path: String, predicate: Boolean): JSONArray { + return jsonArray(path) { predicate } } - @JvmStatic - fun jsonArrayAsset(path: String, predicate: Boolean): JSONArray { - return jsonArrayAsset(path) { predicate } + fun asyncJsonArray(path: String, jsonArrayListener: JSONArrayListener) { + asyncJsonArray(path, jsonArrayListener, true) } - @JvmStatic - fun jsonArrayAssetAsync(path: String, jsonArrayListener: JSONArrayListener) { - jsonArrayAssetAsync(path, jsonArrayListener, true) + fun asyncJsonArray(path: String, jsonArrayListener: JSONArrayListener, predicate: Boolean) { + asyncJsonArray(path, { predicate }, jsonArrayListener::assetReady) } - @JvmStatic - fun jsonArrayAssetAsync(path: String, jsonArrayListener: JSONArrayListener, predicate: Boolean) { - jsonArrayAssetAsync(path, { file -> - jsonArrayListener.assetReady(file) - }) { predicate } + 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): 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) + } + } } diff --git a/library/src/main/java/com/stringcare/library/StringExt.kt b/library/src/main/java/com/stringcare/library/StringExt.kt index 3e5cdf0..869a34e 100644 --- a/library/src/main/java/com/stringcare/library/StringExt.kt +++ b/library/src/main/java/com/stringcare/library/StringExt.kt @@ -1,5 +1,8 @@ package com.stringcare.library +import org.json.JSONArray +import org.json.JSONObject + fun Int.string(): String = SC.context.getString(this) fun Int.reveal( @@ -22,3 +25,30 @@ fun String.reveal( androidTreatment: Boolean = defaultAndroidTreatment, 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.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.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) From 6d12180d6c48cfa09936cf22177884b8981c5584 Mon Sep 17 00:00:00 2001 From: Efra Espada Date: Sat, 17 Aug 2019 22:58:42 +0200 Subject: [PATCH 4/5] readme v3.4 --- README.md | 8 +++++++- library/build.gradle | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8faeb00..f1da2b3 100755 --- a/README.md +++ b/README.md @@ -10,7 +10,13 @@ #### [Implementation](https://github.com/StringCare/AndroidLibrary/wiki/Implementation) -#### [Usage](https://github.com/StringCare/AndroidLibrary/wiki/Usage) +#### [What Is StringCare](https://github.com/StringCare/AndroidLibrary/wiki/What-is-StringCare) + +#### [Implementation](https://github.com/StringCare/AndroidLibrary/wiki/Implementation) + +#### [Strings Usage](https://github.com/StringCare/AndroidLibrary/wiki/Strings-Usage) + +#### [Assets Usage](https://github.com/StringCare/AndroidLibrary/wiki/Assets-Usage) #### [Configuration](https://github.com/StringCare/AndroidLibrary/wiki/Configuration) diff --git a/library/build.gradle b/library/build.gradle index 0aa70f2..57273f7 100755 --- a/library/build.gradle +++ b/library/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'kotlin-android-extensions' apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' -version = "3.3" +version = "3.4" android { compileSdkVersion 28 From 01088bb0400d6359dc2e18fe513287f1dd6f602a Mon Sep 17 00:00:00 2001 From: Efra Espada Date: Sat, 17 Aug 2019 23:06:15 +0200 Subject: [PATCH 5/5] readme v3.4 --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index f1da2b3..90def3b 100755 --- a/README.md +++ b/README.md @@ -10,10 +10,6 @@ #### [Implementation](https://github.com/StringCare/AndroidLibrary/wiki/Implementation) -#### [What Is StringCare](https://github.com/StringCare/AndroidLibrary/wiki/What-is-StringCare) - -#### [Implementation](https://github.com/StringCare/AndroidLibrary/wiki/Implementation) - #### [Strings Usage](https://github.com/StringCare/AndroidLibrary/wiki/Strings-Usage) #### [Assets Usage](https://github.com/StringCare/AndroidLibrary/wiki/Assets-Usage)