Skip to content

Commit 6fb16f8

Browse files
committed
parenthesis bugfix
1 parent 7edc8cb commit 6fb16f8

File tree

9 files changed

+29
-10
lines changed

9 files changed

+29
-10
lines changed

README.md

Lines changed: 3 additions & 1 deletion
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 {
@@ -59,6 +59,7 @@ The plugin will encrypt all string tags with `hidden="true"` as attribute.
5959
<resources>
6060
<string name="hello" hidden="true">hello world!</string>
6161
<string name="app_name">StringObfuscator</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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ buildscript {
1616

1717
dependencies {
1818
classpath "com.stringcare:plugin:$stringcare_version"
19-
classpath files('../AndroidPlugin/build/libs/plugin-0.7.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/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ dependencies {
3636
})
3737
implementation 'com.android.support:appcompat-v7:26.1.0'
3838
testImplementation 'junit:junit:4.12'
39-
implementation project(path: ':library')
40-
// implementation "com.stringcare:library:$stringcare_version"
39+
// implementation project(path: ':library')
40+
implementation "com.stringcare:library:$stringcare_version"
4141
}
4242

4343

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected void onCreate(Bundle savedInstanceState) {
2929

3030
((TextView) findViewById(R.id.example_a)).setText(message);
3131

32-
String numbers = getString(R.string.test_a) + " is " + SC.getString(R.string.test_a);
32+
String numbers = getString(R.string.test_a, "hi", 3) + " is " + SC.getString(R.string.test_a, "hi", 3);
3333
((TextView) findViewById(R.id.example_b)).setText(numbers);
3434

3535
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
android:layout_centerInParent="true">
1919

2020
<TextView
21+
android:padding="10dp"
2122
android:id="@+id/example_a"
2223
android:layout_width="wrap_content"
2324
android:layout_height="wrap_content"
@@ -26,6 +27,7 @@
2627
android:text="" />
2728

2829
<TextView
30+
android:padding="10dp"
2931
android:id="@+id/example_b"
3032
android:layout_width="wrap_content"
3133
android:layout_height="wrap_content"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +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">test (hi)</string>
4+
<string name="test_a" hidden="true">%1$s (%2$d)</string>
55
</resources>

0 commit comments

Comments
 (0)