Skip to content

Commit fd775a6

Browse files
committed
samples working
1 parent 09982ab commit fd775a6

6 files changed

Lines changed: 167 additions & 47 deletions

File tree

app/src/main/java/com/efraespada/stringobfuscator/MainActivity.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
import android.os.Bundle;
44
import android.support.v7.app.AppCompatActivity;
5-
import android.util.Log;
65
import android.widget.TextView;
76

87
import com.stringcare.library.SC;
98
import com.stringcare.library.SCTextView;
109
import com.stringcare.library.Version;
1110

12-
import org.json.JSONArray;
13-
import org.json.JSONObject;
14-
1511
public class MainActivity extends AppCompatActivity {
1612

1713
@Override
@@ -47,14 +43,13 @@ protected void onCreate(Bundle savedInstanceState) {
4743
String areEquals = "Same result: " + equals;
4844
((TextView) findViewById(R.id.same_value)).setText(areEquals);
4945

50-
JSONObject jsonObject = SC.jsonObjectAsset("test.json");
51-
SC.jsonObjectAssetAsync("test.json", json -> {
52-
String value = json.toString();
53-
});
46+
String jsonObjectName = SC.reveal(R.string.asset_json_file);
47+
SC.asset().asyncJson(jsonObjectName, json -> ((TextView) findViewById(R.id.json_object)).setText(json.toString()));
48+
SC.asset().asyncBytes(jsonObjectName, bytes -> ((TextView) findViewById(R.id.json_object_original)).setText(new String(bytes)), false);
49+
50+
String jsonArrayName = SC.reveal(R.string.asset_json_raw_file);
51+
SC.asset().asyncJsonArray(jsonArrayName, json -> ((TextView) findViewById(R.id.json_array)).setText(json.toString()));
52+
SC.asset().asyncBytes(jsonArrayName, bytes -> ((TextView) findViewById(R.id.json_array_original)).setText(new String(bytes)), false);
5453

55-
JSONArray jsonArray = SC.jsonArrayAsset("raw/test_array.json");
56-
SC.jsonArrayAssetAsync("raw/test_array.json", json -> {
57-
String value = json.toString();
58-
});
5954
}
6055
}

app/src/main/res/layout/activity_main.xml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,70 @@
158158
app:androidTreatment="false"
159159
app:visible="true" />
160160

161+
<TextView
162+
android:layout_width="wrap_content"
163+
android:layout_height="wrap_content"
164+
android:layout_gravity="start"
165+
android:layout_marginTop="15dp"
166+
style="@style/TextAppearance.AppCompat.Title"
167+
android:text="@string/json_object_asset"
168+
android:padding="25dp"
169+
android:textColor="@android:color/black" />
170+
171+
<TextView
172+
android:id="@+id/json_object_original"
173+
android:layout_width="wrap_content"
174+
android:layout_height="wrap_content"
175+
android:layout_gravity="center_horizontal"
176+
android:layout_marginTop="15dp"
177+
android:paddingStart="25dp"
178+
android:paddingEnd="25dp"
179+
android:textSize="12sp"
180+
android:textColor="@android:color/darker_gray" />
181+
182+
<TextView
183+
android:id="@+id/json_object"
184+
android:layout_width="wrap_content"
185+
android:layout_height="wrap_content"
186+
android:layout_gravity="center_horizontal"
187+
android:layout_marginTop="15dp"
188+
android:paddingStart="25dp"
189+
android:paddingEnd="25dp"
190+
android:textColor="@android:color/black" />
191+
192+
<TextView
193+
android:layout_width="wrap_content"
194+
android:layout_height="wrap_content"
195+
android:layout_gravity="start"
196+
android:layout_marginTop="15dp"
197+
style="@style/TextAppearance.AppCompat.Title"
198+
android:text="@string/json_array_asset"
199+
android:padding="25dp"
200+
android:textColor="@android:color/black" />
201+
202+
<TextView
203+
android:id="@+id/json_array_original"
204+
android:layout_width="wrap_content"
205+
android:layout_height="wrap_content"
206+
android:layout_gravity="center_horizontal"
207+
android:layout_marginTop="15dp"
208+
android:paddingStart="25dp"
209+
android:paddingEnd="25dp"
210+
android:paddingBottom="25dp"
211+
android:textSize="12sp"
212+
android:textColor="@android:color/darker_gray" />
213+
214+
<TextView
215+
android:id="@+id/json_array"
216+
android:layout_width="wrap_content"
217+
android:layout_height="wrap_content"
218+
android:layout_gravity="center_horizontal"
219+
android:layout_marginTop="15dp"
220+
android:paddingStart="25dp"
221+
android:paddingEnd="25dp"
222+
android:paddingBottom="25dp"
223+
android:textColor="@android:color/black" />
224+
161225
</LinearLayout>
162226

163227
</ScrollView>

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616
<string name="hello_world_c" hidden="true" androidTreatment="false">Hello
1717
World
1818
</string>
19+
<string name="asset_json_file" hidden="true">test.json</string>
20+
<string name="asset_json_raw_file" hidden="true">raw/test_array.json</string>
1921
<string name="long_new_line_comparison">Long New Line Comparison</string>
2022
<string name="html_treatment">HTML treatment</string>
2123
<string name="programmatically_obfuscation">Programmatically Obfuscation</string>
2224
<string name="patterns">Patterns</string>
2325
<string name="string_resource_disabling_android_treatment">String resource disabling Android treatment:</string>
26+
<string name="json_object_asset">JSON Asset</string>
27+
<string name="json_array_asset">JSON Array Raw Asset</string>
2428
</resources>

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ stringcare {
5151
}
5252
variants {
5353
prod {
54-
skip = true
5554
applicationId = "com.efraespada.stringobfuscator"
5655
}
5756
dev {

library/src/main/java/com/stringcare/library/SC.kt

Lines changed: 62 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -303,75 +303,103 @@ class SC {
303303
return bytes
304304
}
305305

306-
fun jsonObjectAsset(path: String, predicate: () -> Boolean): JSONObject {
306+
@JvmStatic
307+
fun asset(): Assets {
308+
return Assets()
309+
}
310+
311+
}
312+
313+
class Assets {
314+
fun json(path: String, predicate: () -> Boolean): JSONObject {
307315
val bytes = assetByteArray(path, predicate)
308316
return JSONObject(String(bytes, Charset.forName("UTF-8")))
309317
}
310318

311-
fun jsonObjectAssetAsync(path: String, json: (json: JSONObject) -> Unit, predicate: () -> Boolean) {
319+
fun asyncJson(path: String,
320+
predicate: () -> Boolean = { true },
321+
json: (json: JSONObject) -> Unit) {
312322
doAsync {
313-
val j = jsonObjectAsset(path, predicate)
323+
val j = json(path, predicate)
314324
json(j)
315325
}
316326
}
317327

318-
fun jsonArrayAsset(path: String, predicate: () -> Boolean): JSONArray {
328+
fun jsonArray(path: String, predicate: () -> Boolean): JSONArray {
319329
val bytes = assetByteArray(path, predicate)
320330
return JSONArray(String(bytes, Charset.forName("UTF-8")))
321331
}
322332

323-
fun jsonArrayAssetAsync(path: String, json: (json: JSONArray) -> Unit, predicate: () -> Boolean) {
333+
fun asyncJsonArray(path: String,
334+
predicate: () -> Boolean = { true },
335+
json: (json: JSONArray) -> Unit) {
324336
doAsync {
325-
val j = jsonArrayAsset(path, predicate)
337+
val j = jsonArray(path, predicate)
326338
json(j)
327339
}
328340
}
329341

330-
@JvmStatic
331-
fun jsonObjectAsset(path: String): JSONObject {
332-
return jsonObjectAsset(path) { true }
342+
fun json(path: String): JSONObject {
343+
return json(path) { true }
333344
}
334345

335-
@JvmStatic
336-
fun jsonObjectAsset(path: String, predicate: Boolean): JSONObject {
337-
return jsonObjectAsset(path) { predicate }
346+
fun json(path: String, predicate: Boolean): JSONObject {
347+
return json(path) { predicate }
338348
}
339349

340-
@JvmStatic
341-
fun jsonObjectAssetAsync(path: String, jsonObjectListener: JSONObjectListener) {
342-
jsonObjectAssetAsync(path, jsonObjectListener, true)
350+
fun asyncJson(path: String, jsonObjectListener: JSONObjectListener) {
351+
asyncJson(path, jsonObjectListener, true)
343352
}
344353

345-
@JvmStatic
346-
fun jsonObjectAssetAsync(path: String, jsonObjectListener: JSONObjectListener, predicate: Boolean) {
347-
jsonObjectAssetAsync(path, { file ->
348-
jsonObjectListener.assetReady(file)
349-
}) { predicate }
354+
fun asyncJson(path: String, jsonObjectListener: JSONObjectListener, predicate: Boolean) {
355+
asyncJson(path, { predicate }, jsonObjectListener::assetReady)
350356
}
351357

358+
fun jsonArray(path: String): JSONArray {
359+
return jsonArray(path) { true }
360+
}
352361

353-
@JvmStatic
354-
fun jsonArrayAsset(path: String): JSONArray {
355-
return jsonArrayAsset(path) { true }
362+
fun jsonArray(path: String, predicate: Boolean): JSONArray {
363+
return jsonArray(path) { predicate }
356364
}
357365

358-
@JvmStatic
359-
fun jsonArrayAsset(path: String, predicate: Boolean): JSONArray {
360-
return jsonArrayAsset(path) { predicate }
366+
fun asyncJsonArray(path: String, jsonArrayListener: JSONArrayListener) {
367+
asyncJsonArray(path, jsonArrayListener, true)
361368
}
362369

363-
@JvmStatic
364-
fun jsonArrayAssetAsync(path: String, jsonArrayListener: JSONArrayListener) {
365-
jsonArrayAssetAsync(path, jsonArrayListener, true)
370+
fun asyncJsonArray(path: String, jsonArrayListener: JSONArrayListener, predicate: Boolean) {
371+
asyncJsonArray(path, { predicate }, jsonArrayListener::assetReady)
366372
}
367373

368-
@JvmStatic
369-
fun jsonArrayAssetAsync(path: String, jsonArrayListener: JSONArrayListener, predicate: Boolean) {
370-
jsonArrayAssetAsync(path, { file ->
371-
jsonArrayListener.assetReady(file)
372-
}) { predicate }
374+
fun bytes(path: String, predicate: () -> Boolean): ByteArray {
375+
return assetByteArray(path, predicate)
373376
}
374377

378+
fun asyncBytes(path: String,
379+
predicate: () -> Boolean = { true },
380+
bytes: (bytes: ByteArray) -> Unit) {
381+
doAsync {
382+
bytes(assetByteArray(path, predicate))
383+
}
384+
}
385+
386+
fun bytes(path: String): ByteArray {
387+
return bytes(path, true)
388+
}
389+
390+
fun bytes(path: String, predicate: Boolean): ByteArray {
391+
return bytes(path) { predicate }
392+
}
393+
394+
fun asyncBytes(path: String, byteArrayListener: AssetByteArrayListener) {
395+
asyncBytes(path, byteArrayListener, true)
396+
}
397+
398+
fun asyncBytes(path: String, byteArrayListener: AssetByteArrayListener, predicate: Boolean) {
399+
doAsync {
400+
asyncBytes(path, { predicate }, byteArrayListener::assetReady)
401+
}
402+
}
375403

376404
}
377405

library/src/main/java/com/stringcare/library/StringExt.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.stringcare.library
22

3+
import org.json.JSONArray
4+
import org.json.JSONObject
5+
36
fun Int.string(): String = SC.context.getString(this)
47

58
fun Int.reveal(
@@ -22,3 +25,30 @@ fun String.reveal(
2225
androidTreatment: Boolean = defaultAndroidTreatment,
2326
version: Version = defaultVersion
2427
): String = SC.reveal(this, androidTreatment, version)
28+
29+
fun String.json(
30+
predicate: () -> Boolean = { true }
31+
): JSONObject = SC.asset().json(this, predicate)
32+
33+
fun String.asyncJson(
34+
predicate: () -> Boolean = { true },
35+
json: (json: JSONObject) -> Unit
36+
) = SC.asset().asyncJson(this, predicate, json)
37+
38+
fun String.jsonArray(
39+
predicate: () -> Boolean = { true }
40+
): JSONArray = SC.asset().jsonArray(this, predicate)
41+
42+
fun String.asyncJsonArray(
43+
predicate: () -> Boolean = { true },
44+
json: (json: JSONArray) -> Unit
45+
) = SC.asset().asyncJsonArray(this, predicate, json)
46+
47+
fun String.bytes(
48+
predicate: () -> Boolean = { true }
49+
): ByteArray = SC.asset().bytes(this, predicate)
50+
51+
fun String.asyncBytes(
52+
predicate: () -> Boolean = { true },
53+
bytes: (bytes: ByteArray) -> Unit
54+
) = SC.asset().asyncBytes(this, predicate, bytes)

0 commit comments

Comments
 (0)