Skip to content

Commit 74b8a2d

Browse files
committed
testing attr
1 parent 9761028 commit 74b8a2d

File tree

5 files changed

+108
-39
lines changed

5 files changed

+108
-39
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.widget.TextView;
77

88
import com.stringcare.library.SC;
9+
import com.stringcare.library.SCTextView;
910

1011
public class MainActivity extends AppCompatActivity {
1112

@@ -33,6 +34,7 @@ protected void onCreate(Bundle savedInstanceState) {
3334

3435
String numbers = getString(R.string.test_a, "hi", 3) + " is " + SC.deobfuscate(R.string.test_a, "hi", 3);
3536
((TextView) findViewById(R.id.example_b)).setText(numbers);
37+
((SCTextView) findViewById(R.id.auto_tv)).visible(false);
3638

3739
}
3840
}
Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,67 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
45
android:id="@+id/activity_main"
56
android:layout_width="match_parent"
67
android:layout_height="match_parent"
7-
android:paddingBottom="@dimen/activity_vertical_margin"
8+
android:background="@android:color/background_light"
89
android:paddingLeft="@dimen/activity_horizontal_margin"
9-
android:paddingRight="@dimen/activity_horizontal_margin"
1010
android:paddingTop="@dimen/activity_vertical_margin"
11-
android:background="@android:color/background_light"
11+
android:paddingRight="@dimen/activity_horizontal_margin"
12+
android:paddingBottom="@dimen/activity_vertical_margin"
1213
tools:context="com.efraespada.stringobfuscator.MainActivity">
1314

14-
<LinearLayout
15+
<ScrollView
1516
android:layout_width="match_parent"
16-
android:layout_height="wrap_content"
17-
android:orientation="vertical"
18-
android:layout_centerInParent="true">
17+
android:layout_height="wrap_content">
1918

20-
<com.stringcare.library.SCTextView
21-
android:padding="10dp"
22-
android:layout_width="wrap_content"
19+
<LinearLayout
20+
android:layout_width="match_parent"
2321
android:layout_height="wrap_content"
24-
android:layout_gravity="center_horizontal"
25-
android:textColor="@android:color/black"
26-
android:layout_marginTop="15dp"
27-
android:text="@string/automatic_decrypt"/>
28-
29-
<TextView
30-
android:padding="10dp"
31-
android:id="@+id/example_a"
32-
android:layout_width="wrap_content"
33-
android:layout_height="wrap_content"
34-
android:layout_gravity="center_horizontal"
35-
android:textColor="@android:color/black"
36-
android:layout_marginTop="15dp" />
37-
38-
<TextView
39-
android:padding="10dp"
40-
android:id="@+id/example_b"
41-
android:layout_width="wrap_content"
42-
android:layout_height="wrap_content"
43-
android:layout_gravity="center_horizontal"
44-
android:textColor="@android:color/black"
45-
android:layout_marginTop="15dp" />
22+
android:orientation="vertical">
23+
24+
<com.stringcare.library.SCTextView
25+
android:id="@+id/auto_tv"
26+
app:html="false"
27+
android:layout_width="wrap_content"
28+
android:layout_height="wrap_content"
29+
android:layout_gravity="center_horizontal"
30+
android:layout_marginTop="15dp"
31+
android:padding="10dp"
32+
android:text="@string/automatic_decrypt"
33+
android:textColor="@android:color/black" />
34+
35+
<com.stringcare.library.SCTextView
36+
app:html="true"
37+
android:layout_width="wrap_content"
38+
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" />
44+
45+
<TextView
46+
android:id="@+id/example_a"
47+
android:layout_width="wrap_content"
48+
android:layout_height="wrap_content"
49+
android:layout_gravity="center_horizontal"
50+
android:layout_marginTop="15dp"
51+
android:padding="10dp"
52+
android:textColor="@android:color/black" />
53+
54+
<TextView
55+
android:id="@+id/example_b"
56+
android:layout_width="wrap_content"
57+
android:layout_height="wrap_content"
58+
android:layout_gravity="center_horizontal"
59+
android:layout_marginTop="15dp"
60+
android:padding="10dp"
61+
android:textColor="@android:color/black" />
4662

47-
</LinearLayout>
63+
</LinearLayout>
4864

65+
</ScrollView>
4966

50-
</RelativeLayout>
67+
</LinearLayout>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<br>No, I'm talking with my father.
55
<br>Yes yes, but <strong>take it easy</strong>.<br>
66
</string>
7-
<string name="automatic_decrypt" hidden="true">auto decrypted value</string>
7+
<string name="automatic_decrypt" hidden="true">auto decrypted <b>value</b></string>
88
<string name="app_name">String Obfuscator Sample</string>
99
<string name="test_a" hidden="true">%1$s (%2$d)</string>
1010
</resources>
Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,66 @@
11
package com.stringcare.library;
22

3-
/**
3+
/*
44
* Credits to Narvelan:
55
* https://github.com/StringCare/AndroidLibrary/issues/34
66
*/
77

88
import android.content.Context;
99
import android.support.v7.widget.AppCompatTextView;
10+
import android.text.Html;
1011
import android.util.AttributeSet;
1112

1213
public class SCTextView extends AppCompatTextView {
1314

15+
private String text;
16+
private Boolean isHTML;
17+
private Boolean visible;
18+
1419
public SCTextView(Context context) {
1520
super(context);
21+
isHTML = null;
22+
visible = null;
1623
}
1724

1825
public SCTextView(Context context, AttributeSet attrs) {
1926
super(context, attrs);
27+
isHTML = null;
28+
visible = null;
2029
loadText(attrs);
2130
}
2231

2332
public SCTextView(Context context, AttributeSet attrs, int defStyleAttr) {
2433
super(context, attrs, defStyleAttr);
34+
isHTML = null;
35+
visible = null;
2536
loadText(attrs);
2637
}
2738

2839
private void loadText(final AttributeSet attrs) {
29-
String text = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "text");
40+
text = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "text");
41+
visible = true;
42+
if (isHTML == null) {
43+
isHTML = !"false".equalsIgnoreCase(attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "html"));
44+
}
45+
reloadText();
46+
}
47+
48+
private void reloadText() {
3049
if (text != null) {
50+
if (!visible) {
51+
setText(text);
52+
return;
53+
}
3154
try {
3255
final Integer val = Integer.parseInt(text.substring(1));
3356
SC.onContextReady(new ContextListener() {
3457
@Override
3558
public void contextReady() {
36-
setText(SC.deobfuscate(val));
59+
if (isHTML) {
60+
setText(Html.fromHtml(SC.deobfuscate(val)));
61+
} else {
62+
setText(SC.deobfuscate(val));
63+
}
3764
}
3865
});
3966
} catch (NumberFormatException e) {
@@ -42,4 +69,21 @@ public void contextReady() {
4269
}
4370
}
4471

72+
public void visible(boolean visible) {
73+
this.visible = visible;
74+
reloadText();
75+
}
76+
77+
public void htmlEnabled(boolean enabled) {
78+
isHTML = enabled;
79+
if (visible == null) {
80+
visible = true;
81+
}
82+
reloadText();
83+
}
84+
85+
public boolean isHtmlEnabled() {
86+
return isHTML;
87+
}
88+
4589
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<declare-styleable name="com_stringcare_library_SCTextView">
4+
<attr name="html" format="boolean" />
5+
</declare-styleable>
6+
</resources>

0 commit comments

Comments
 (0)