Skip to content

Commit 8bad7f9

Browse files
committed
native method not working
1 parent 74b8a2d commit 8bad7f9

File tree

7 files changed

+44
-28
lines changed

7 files changed

+44
-28
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ android {
2020
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2121
}
2222
debug {
23-
minifyEnabled true
23+
minifyEnabled false
2424
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2525
}
2626
}

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.os.Bundle;
44
import android.support.v7.app.AppCompatActivity;
55
import android.text.Html;
6+
import android.view.View;
67
import android.widget.TextView;
78

89
import com.stringcare.library.SC;
@@ -16,25 +17,31 @@ protected void onCreate(Bundle savedInstanceState) {
1617
setContentView(R.layout.activity_main);
1718

1819
SC.init(getApplicationContext());
19-
// SC.initForLib(getApplicationContext(), this);
20-
21-
int stringId = R.string.hello;
22-
23-
String message = getString(stringId);
24-
message += " is ";
25-
message += SC.deobfuscate(stringId);
2620

2721
// secret var
2822
String password = "lalilulelo";
2923

30-
message += "\n\nFor Metal Gear lovers:\n\n\"Snake, the password is " + SC.obfuscate(password)
24+
String message = "\n\nFor Metal Gear lovers:\n\n\"Snake, the password is " + SC.obfuscate(password)
3125
+ "\n\n.. or " + SC.deobfuscate(SC.obfuscate(password)) + "\"";
3226

3327
((TextView) findViewById(R.id.example_a)).setText(Html.fromHtml(message));
3428

3529
String numbers = getString(R.string.test_a, "hi", 3) + " is " + SC.deobfuscate(R.string.test_a, "hi", 3);
3630
((TextView) findViewById(R.id.example_b)).setText(numbers);
37-
((SCTextView) findViewById(R.id.auto_tv)).visible(false);
31+
final SCTextView tvAuto = findViewById(R.id.auto_tv);
32+
findViewById(R.id.btn_change).setOnClickListener(new View.OnClickListener() {
33+
@Override
34+
public void onClick(View v) {
35+
if (tvAuto.isHtmlEnabled()) {
36+
tvAuto.htmlEnabled(!tvAuto.isHtmlEnabled());
37+
} else if (tvAuto.isVisible()){
38+
tvAuto.visible(!tvAuto.isVisible());
39+
} else if (!tvAuto.isVisible()){
40+
tvAuto.visible(!tvAuto.isVisible());
41+
tvAuto.htmlEnabled(!tvAuto.isHtmlEnabled());
42+
}
43+
}
44+
});
3845

3946
}
4047
}

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:tools="http://schemas.android.com/tools"
43
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
55
android:id="@+id/activity_main"
66
android:layout_width="match_parent"
77
android:layout_height="match_parent"
@@ -23,24 +23,23 @@
2323

2424
<com.stringcare.library.SCTextView
2525
android:id="@+id/auto_tv"
26-
app:html="false"
2726
android:layout_width="wrap_content"
2827
android:layout_height="wrap_content"
2928
android:layout_gravity="center_horizontal"
3029
android:layout_marginTop="15dp"
3130
android:padding="10dp"
32-
android:text="@string/automatic_decrypt"
33-
android:textColor="@android:color/black" />
31+
android:text="@string/hello"
32+
android:textColor="@android:color/black"
33+
app:html="false"
34+
app:visible="false" />
3435

35-
<com.stringcare.library.SCTextView
36-
app:html="true"
36+
<Button
37+
android:id="@+id/btn_change"
38+
style="@style/Widget.AppCompat.Button.Borderless.Colored"
3739
android:layout_width="wrap_content"
3840
android:layout_height="wrap_content"
39-
android:layout_gravity="center_horizontal"
40-
android:layout_marginTop="15dp"
41-
android:padding="10dp"
42-
android:text="@string/automatic_decrypt"
43-
android:textColor="@android:color/black" />
41+
android:layout_gravity="end"
42+
android:text="Change" />
4443

4544
<TextView
4645
android:id="@+id/example_a"
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<resources>
2+
<string name="app_name">String Obfuscator Sample</string>
23
<string name="hello" hidden="true">
34
<br><b>Hello <i>Mr O'Callaghan</i></b>
45
<br>No, I'm talking with my father.
56
<br>Yes yes, but <strong>take it easy</strong>.<br>
67
</string>
7-
<string name="automatic_decrypt" hidden="true">auto decrypted <b>value</b></string>
8-
<string name="app_name">String Obfuscator Sample</string>
98
<string name="test_a" hidden="true">%1$s (%2$d)</string>
109
</resources>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public static void init(Context c) {
6262
}
6363

6464
public static void onContextReady(ContextListener listener) {
65+
if (context != null) {
66+
listener.contextReady();
67+
return;
68+
}
6569
listeners.add(listener);
6670
}
6771

library/src/main/java/com/stringcare/library/SCTextView.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,23 @@ public SCTextView(Context context, AttributeSet attrs, int defStyleAttr) {
3838

3939
private void loadText(final AttributeSet attrs) {
4040
text = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "text");
41-
visible = true;
4241
if (isHTML == null) {
4342
isHTML = !"false".equalsIgnoreCase(attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "html"));
4443
}
44+
if (visible == null) {
45+
visible = !"false".equalsIgnoreCase(attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "visible"));
46+
}
4547
reloadText();
4648
}
4749

4850
private void reloadText() {
4951
if (text != null) {
50-
if (!visible) {
51-
setText(text);
52-
return;
53-
}
5452
try {
5553
final Integer val = Integer.parseInt(text.substring(1));
54+
if (!visible) {
55+
setText(getContext().getString(val));
56+
return;
57+
}
5658
SC.onContextReady(new ContextListener() {
5759
@Override
5860
public void contextReady() {
@@ -86,4 +88,8 @@ public boolean isHtmlEnabled() {
8688
return isHTML;
8789
}
8890

91+
public boolean isVisible() {
92+
return visible;
93+
}
94+
8995
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<resources>
33
<declare-styleable name="com_stringcare_library_SCTextView">
44
<attr name="html" format="boolean" />
5+
<attr name="visible" format="boolean" />
56
</declare-styleable>
67
</resources>

0 commit comments

Comments
 (0)