Skip to content

Commit 2c2fff2

Browse files
authored
Merge pull request #30 from StringCare/develop
Develop
2 parents a393553 + 344a936 commit 2c2fff2

File tree

8 files changed

+57
-17
lines changed

8 files changed

+57
-17
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Gradle implementation
1616
buildscript {
1717
1818
ext {
19-
stringcare_version = '0.6'
19+
stringcare_version = '0.7'
2020
}
2121
2222
repositories {
@@ -57,8 +57,9 @@ The plugin will encrypt all string tags with `hidden="true"` as attribute.
5757

5858
```xml
5959
<resources>
60-
<string name="hello" hidden="true">hello world!</string>
61-
<string name="app_name">StringObfuscator</string>
60+
<string name="app_name">StringObfuscator</string>
61+
<string name="hello" hidden="true">hello world!</string>
62+
<string name="test_a" hidden="true">%1$s (%2$d)</string>
6263
</resources>
6364
```
6465

@@ -72,6 +73,7 @@ String encrypted = SC.encryptString(string_var);
7273
From resources:
7374
```java
7475
String decrypted = SC.getString(R.string.hello);
76+
String decrypted = SC.getString(R.string.test_a, "hi", 3); // hi (3)
7577
```
7678
Or from encrypted variables:
7779
```java

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
buildscript {
33

44
ext {
5-
stringcare_version = '0.6'
5+
stringcare_version = '0.7'
66
}
77

88
repositories {
@@ -16,7 +16,7 @@ buildscript {
1616

1717
dependencies {
1818
classpath "com.stringcare:plugin:$stringcare_version"
19-
// classpath files('../AndroidPlugin/build/libs/plugin-0.4.jar')
19+
// classpath files('../AndroidPlugin/build/libs/plugin-0.7.jar')
2020
classpath 'com.android.tools.build:gradle:3.0.1'
2121
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1"
2222
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
22
apply plugin: 'com.github.dcendents.android-maven'
33
apply plugin: 'com.jfrog.bintray'
44

5-
version = "0.6"
5+
version = "0.7"
66

77
android {
88
compileSdkVersion 25
@@ -11,7 +11,7 @@ android {
1111
defaultConfig {
1212
minSdkVersion 9
1313
targetSdkVersion 25
14-
versionCode 1
14+
versionCode 2
1515
versionName version
1616

1717
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import android.content.pm.PackageInfo;
55
import android.content.pm.PackageManager;
66
import android.content.pm.Signature;
7+
import android.content.res.Resources;
8+
import android.os.Build;
9+
import android.support.annotation.StringRes;
710
import android.util.Log;
811

912
import java.io.ByteArrayInputStream;
@@ -16,6 +19,7 @@
1619
import java.security.cert.CertificateFactory;
1720
import java.security.cert.X509Certificate;
1821
import java.util.Arrays;
22+
import java.util.Locale;
1923

2024
import javax.crypto.Cipher;
2125
import javax.crypto.SecretKey;
@@ -148,7 +152,7 @@ private static String byteArrayToHexString(byte[] bytes) {
148152
* @param id
149153
* @return String
150154
*/
151-
public static String getString(int id) {
155+
public static String getString(@StringRes int id) {
152156
if (context == null) {
153157
Log.e(TAG, "Library not initialized: SC.init(Context)");
154158
return null;
@@ -163,6 +167,17 @@ public static String getString(int id) {
163167
return context.getString(id); // returns original value, maybe not encrypted
164168
}
165169

170+
public static String getString(@StringRes int id, Object... formatArgs) {
171+
String value = getString(id);
172+
Locale locale;
173+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
174+
locale = Resources.getSystem().getConfiguration().getLocales().get(0);
175+
} else {
176+
locale = Resources.getSystem().getConfiguration().locale;
177+
}
178+
return String.format(locale, value, formatArgs);
179+
}
180+
166181
/**
167182
* encrypts the given value
168183
* @param value
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<resources>
2-
<string name="app_name">AndroidStringObfuscator</string>
2+
<string name="app_name">StringCareLibrary</string>
33
</resources>

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ protected void onCreate(Bundle savedInstanceState) {
2121
message += " is ";
2222
message += SC.getString(stringId);
2323

24-
// secret
24+
// secret var
2525
String mySecret = "lalilulelo";
2626

2727
message += "\n\nFor Metal Gear lovers:\n\n\"Snake, the password is " + SC.encryptString(message)
2828
+ "\n\n.. or " + SC.decryptString(SC.encryptString(mySecret)) + "\"";
2929

30-
((TextView) findViewById(R.id.example)).setText(message);
30+
((TextView) findViewById(R.id.example_a)).setText(message);
31+
32+
String numbers = getString(R.string.test_a, "hi", 3) + " is " + SC.getString(R.string.test_a, "hi", 3);
33+
((TextView) findViewById(R.id.example_b)).setText(numbers);
34+
3135
}
3236
}

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,31 @@
1111
android:background="@android:color/background_light"
1212
tools:context="com.efraespada.stringobfuscator.MainActivity">
1313

14-
<TextView
15-
android:id="@+id/example"
16-
android:layout_width="wrap_content"
14+
<LinearLayout
15+
android:layout_width="match_parent"
1716
android:layout_height="wrap_content"
18-
android:layout_centerInParent="true"
19-
android:textColor="@android:color/black"
20-
android:text="" />
17+
android:orientation="vertical"
18+
android:layout_centerInParent="true">
19+
20+
<TextView
21+
android:padding="10dp"
22+
android:id="@+id/example_a"
23+
android:layout_width="wrap_content"
24+
android:layout_height="wrap_content"
25+
android:layout_gravity="center_horizontal"
26+
android:textColor="@android:color/black"
27+
android:text="" />
28+
29+
<TextView
30+
android:padding="10dp"
31+
android:id="@+id/example_b"
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:text="" />
37+
38+
</LinearLayout>
2139

2240

2341
</RelativeLayout>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<resources>
22
<string name="hello" hidden="true">hello world!</string>
33
<string name="app_name">String Obfuscator Sample</string>
4+
<string name="test_a" hidden="true">%1$s (%2$d)</string>
45
</resources>

0 commit comments

Comments
 (0)