Skip to content

Commit a99a32a

Browse files
authored
Merge pull request #66 from StringCare/develop
Develop
2 parents f533964 + 097c263 commit a99a32a

File tree

10 files changed

+110
-67
lines changed

10 files changed

+110
-67
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ dependencies {
5555
})
5656
implementation 'com.android.support:appcompat-v7:28.0.0'
5757
testImplementation 'junit:junit:4.12'
58-
implementation project(path: ':library')
5958
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
6059
implementation 'commons-io:commons-io:2.5'
61-
// implementation "com.stringcare:library:$stringcare_version"
60+
// implementation project(path: ':library')
61+
implementation "com.stringcare:library:$stringcare_version"
6262
}
6363

6464

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ protected void onCreate(Bundle savedInstanceState) {
3030
final SCTextView tvAuto = findViewById(R.id.auto_tv);
3131
findViewById(R.id.btn_change).setOnClickListener(v -> {
3232
if (tvAuto.isHtmlEnabled()) {
33-
tvAuto.htmlEnabled(!tvAuto.isHtmlEnabled());
34-
} else if (tvAuto.isVisible()){
35-
tvAuto.visible(!tvAuto.isVisible());
36-
} else if (!tvAuto.isVisible()){
37-
tvAuto.visible(!tvAuto.isVisible());
38-
tvAuto.htmlEnabled(!tvAuto.isHtmlEnabled());
33+
tvAuto.setHtmlSupport(!tvAuto.isHtmlEnabled());
34+
} else if (tvAuto.isRevealingValue()) {
35+
tvAuto.setRevealed(!tvAuto.isRevealingValue());
36+
} else if (!tvAuto.isRevealingValue()) {
37+
tvAuto.setRevealed(!tvAuto.isRevealingValue());
38+
tvAuto.setHtmlSupport(!tvAuto.isHtmlEnabled());
3939
}
4040
});
4141

4242
boolean equals = SC.reveal(R.string.hello_world_b).equals(getString(R.string.hello_world_a));
43-
String areEquals = "Same result: " + equals;
43+
String areEquals = "Same result: " + equals;
4444
((TextView) findViewById(R.id.same_value)).setText(areEquals);
4545

4646
String jsonObjectName = SC.reveal(R.string.asset_json_file);

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
android:padding="25dp"
3939
android:text="@string/hello"
4040
android:textColor="@android:color/black"
41-
app:html="true"
42-
app:visible="false" />
41+
app:htmlSupport="true"
42+
app:reveal="true" />
4343

4444
<Button
4545
android:id="@+id/btn_change"
@@ -120,8 +120,8 @@
120120
android:textSize="12sp"
121121
android:text="@string/hello_world_b"
122122
android:textColor="@android:color/black"
123-
app:html="false"
124-
app:visible="true" />
123+
app:htmlSupport="false"
124+
app:reveal="true" />
125125

126126
<TextView
127127
android:layout_width="wrap_content"
@@ -154,9 +154,9 @@
154154
android:textSize="12sp"
155155
android:text="@string/hello_world_c"
156156
android:textColor="@android:color/black"
157-
app:html="false"
157+
app:htmlSupport="false"
158158
app:androidTreatment="false"
159-
app:visible="true" />
159+
app:reveal="true" />
160160

161161
<TextView
162162
android:layout_width="wrap_content"

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
ext.kotlin_version = '1.3.50'
44

55
ext {
6-
stringcare_version = '3.3'
6+
stringcare_version = '3.6.1'
77
}
88

99
repositories {
@@ -16,9 +16,9 @@ buildscript {
1616
}
1717

1818
dependencies {
19-
// classpath "com.stringcare:plugin:$stringcare_version"
20-
classpath files('../KotlinGradlePlugin/build/libs/plugin-3.5.jar')
21-
classpath 'com.android.tools.build:gradle:3.5.1'
19+
classpath "com.stringcare:plugin:$stringcare_version"
20+
// classpath files('../KotlinGradlePlugin/build/libs/plugin-3.5.jar')
21+
classpath 'com.android.tools.build:gradle:3.5.3'
2222
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1"
2323
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
2424
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

library/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ cmake_minimum_required(VERSION 3.10.2)
1111
# Gradle automatically packages shared libraries with your APK.
1212

1313
add_library( # Sets the name of the library.
14-
native-lib
14+
sc-native-lib
1515

1616
# Sets the library as a shared library.
1717
SHARED
1818

1919
# Provides a relative path to your source file(s).
20-
../../stringcare-jni-android-library/lib/native-lib.cpp)
20+
../../stringcare-jni-android-library/lib/sc-native-lib.cpp)
2121

2222
# Searches for a specified prebuilt library and stores the path as a
2323
# variable. Because CMake includes system libraries in the search path by
@@ -37,7 +37,7 @@ find_library( # Sets the name of the path variable.
3737
# build script, prebuilt third-party libraries, or system libraries.
3838

3939
target_link_libraries( # Specifies the target library.
40-
native-lib
40+
sc-native-lib
4141

4242
# Links the target library to the log library
4343
# included in the NDK.

library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apply plugin: 'kotlin-android-extensions'
44
apply plugin: 'com.github.dcendents.android-maven'
55
apply plugin: 'com.jfrog.bintray'
66

7-
version = "3.6"
7+
version = "3.6.1"
88

99
android {
1010
compileSdkVersion 28

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class SC {
1717
companion object {
1818

1919
init {
20-
System.loadLibrary("native-lib")
20+
System.loadLibrary("sc-native-lib")
2121
}
2222

2323
val context: Context
Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,70 @@
11
package com.stringcare.library;
22

3-
/*
4-
* Credits to Narvelan:
5-
* https://github.com/StringCare/AndroidLibrary/issues/34
6-
*/
7-
83
import android.content.Context;
94
import android.support.v7.widget.AppCompatTextView;
105
import android.text.Html;
116
import android.util.AttributeSet;
127

13-
import java.util.Formatter;
8+
/*
9+
* Credits to Narvelan:
10+
* https://github.com/StringCare/AndroidLibrary/issues/34
11+
*/
1412

1513
public class SCTextView extends AppCompatTextView {
1614

1715
private String text;
1816
private Boolean isHTML;
1917
private Boolean androidTreatment;
20-
private Boolean visible;
18+
private Boolean revealed;
2119

2220
public SCTextView(Context context) {
2321
super(context);
2422
isHTML = null;
25-
visible = null;
23+
revealed = null;
2624
androidTreatment = null;
2725
}
2826

2927
public SCTextView(Context context, AttributeSet attrs) {
3028
super(context, attrs);
3129
isHTML = null;
32-
visible = null;
30+
revealed = null;
3331
androidTreatment = null;
3432
loadText(attrs);
3533
}
3634

3735
public SCTextView(Context context, AttributeSet attrs, int defStyleAttr) {
3836
super(context, attrs, defStyleAttr);
3937
isHTML = null;
40-
visible = null;
38+
revealed = null;
4139
androidTreatment = null;
4240
loadText(attrs);
4341
}
4442

4543
/**
46-
* Defines initial vars
44+
* Sets the initial parameters
4745
*
4846
* @param attrs {AttributeSet}
4947
*/
5048
private void loadText(final AttributeSet attrs) {
51-
text = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "text");
49+
String mFalse = "false";
50+
51+
String mResourceAndroidSchema = "http://schemas.android.com/apk/res/android";
52+
String textName = "text";
53+
54+
String mResourceSchema = "http://schemas.android.com/apk/res-auto";
55+
String htmlName = "htmlSupport";
56+
String revealValue = "reveal";
57+
String androidTreatmentName = "androidTreatment";
58+
59+
text = attrs.getAttributeValue(mResourceAndroidSchema, textName);
5260
if (isHTML == null) {
53-
isHTML = !"false".equalsIgnoreCase(attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "html"));
61+
isHTML = !mFalse.equalsIgnoreCase(attrs.getAttributeValue(mResourceSchema, htmlName));
5462
}
55-
if (visible == null) {
56-
visible = !"false".equalsIgnoreCase(attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "visible"));
63+
if (revealed == null) {
64+
revealed = !mFalse.equalsIgnoreCase(attrs.getAttributeValue(mResourceSchema, revealValue));
5765
}
5866
if (androidTreatment == null) {
59-
androidTreatment = !"false".equalsIgnoreCase(attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "androidTreatment"));
67+
androidTreatment = !mFalse.equalsIgnoreCase(attrs.getAttributeValue(mResourceSchema, androidTreatmentName));
6068
}
6169

6270
reloadText();
@@ -68,16 +76,16 @@ private void loadText(final AttributeSet attrs) {
6876
private void reloadText() {
6977
if (text != null) {
7078
try {
71-
final Integer val = Integer.parseInt(text.substring(1));
72-
if (!visible) {
79+
final int val = Integer.parseInt(text.substring(1));
80+
if (!isRevealingValue()) {
7381
setText(getContext().getString(val));
7482
return;
7583
}
7684
SC.onContextReady(new ContextListener() {
7785
@Override
7886
public void contextReady() {
79-
String value = SC.reveal(val, androidTreatment);
80-
if (isHTML) {
87+
String value = SC.reveal(val, usesAndroidTreatment());
88+
if (isHtmlEnabled()) {
8189
setText(Html.fromHtml(value));
8290
} else {
8391
setText(value);
@@ -91,12 +99,12 @@ public void contextReady() {
9199
}
92100

93101
/**
94-
* Enables de-obfuscation before print the value
102+
* Reveals the value before print it
95103
*
96-
* @param visible {true|false}
104+
* @param revealed {true|false}
97105
*/
98-
public void visible(boolean visible) {
99-
this.visible = visible;
106+
public void setRevealed(boolean revealed) {
107+
this.revealed = revealed;
100108
reloadText();
101109
}
102110

@@ -105,40 +113,46 @@ public void visible(boolean visible) {
105113
*
106114
* @param enabled {true|false}
107115
*/
108-
public void htmlEnabled(boolean enabled) {
116+
public void setHtmlSupport(boolean enabled) {
109117
isHTML = enabled;
110118
reloadText();
111119
}
112120

113121
/**
114-
* Returns true if is the value must be print as HTML or plain text
122+
* Enables the Android treatment
123+
*
124+
* @param enabled {true|false}
125+
*/
126+
public void setAndroidTreatment(boolean enabled) {
127+
androidTreatment = enabled;
128+
reloadText();
129+
}
130+
131+
/**
132+
* Returns true if is the value must be print as HTML
115133
*
116134
* @return Boolean
117135
*/
118136
public boolean isHtmlEnabled() {
119-
return isHTML;
137+
return Boolean.TRUE.equals(isHTML);
120138
}
121139

122140
/**
123-
* Returns true if is de-obfuscating the value before print it
141+
* Returns true if the value must be treated as the Android system does
124142
*
125143
* @return Boolean
126144
*/
127-
public boolean isVisible() {
128-
return visible;
145+
public boolean usesAndroidTreatment() {
146+
return Boolean.TRUE.equals(androidTreatment);
129147
}
130148

131-
public String escapeUnicode(String input) {
132-
StringBuilder b = new StringBuilder(input.length());
133-
Formatter f = new Formatter(b);
134-
for (char c : input.toCharArray()) {
135-
if (c < 128) {
136-
b.append(c);
137-
} else {
138-
f.format("\\u%04x", (int) c);
139-
}
140-
}
141-
return b.toString();
149+
/**
150+
* Returns true if the value should be setRevealed before print it
151+
*
152+
* @return Boolean
153+
*/
154+
public boolean isRevealingValue() {
155+
return Boolean.TRUE.equals(revealed);
142156
}
143157

144158
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fun String.reveal(
2626
version: Version = defaultVersion
2727
): String = SC.reveal(this, androidTreatment, version)
2828

29+
// lambdas
2930
fun String.json(
3031
predicate: () -> Boolean = { true }
3132
): JSONObject = SC.asset().json(this, predicate)
@@ -52,3 +53,31 @@ fun String.asyncBytes(
5253
predicate: () -> Boolean = { true },
5354
bytes: (bytes: ByteArray) -> Unit
5455
) = SC.asset().asyncBytes(this, predicate, bytes)
56+
57+
// param
58+
fun String.json(
59+
predicate: Boolean = true
60+
): JSONObject = SC.asset().json(this, predicate)
61+
62+
fun String.asyncJson(
63+
predicate: Boolean = true,
64+
json: (json: JSONObject) -> Unit
65+
) = SC.asset().asyncJson(this, { predicate }, json)
66+
67+
fun String.jsonArray(
68+
predicate: Boolean = true
69+
): JSONArray = SC.asset().jsonArray(this, predicate)
70+
71+
fun String.asyncJsonArray(
72+
predicate: Boolean = true,
73+
json: (json: JSONArray) -> Unit
74+
) = SC.asset().asyncJsonArray(this, { predicate }, json)
75+
76+
fun String.bytes(
77+
predicate: Boolean = true
78+
): ByteArray = SC.asset().bytes(this, predicate)
79+
80+
fun String.asyncBytes(
81+
predicate: Boolean = true,
82+
bytes: (bytes: ByteArray) -> Unit
83+
) = SC.asset().asyncBytes(this, { predicate }, bytes)

library/src/main/res/values/attrs.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<declare-styleable name="com_stringcare_library_SCTextView">
4-
<attr name="html" format="boolean" />
5-
<attr name="visible" format="boolean" />
4+
<attr name="htmlSupport" format="boolean" />
5+
<attr name="reveal" format="boolean" />
66
<attr name="androidTreatment" format="boolean" />
77
</declare-styleable>
88
</resources>

0 commit comments

Comments
 (0)