Skip to content

Commit fc3e612

Browse files
committed
SCTextView
1 parent 5af297e commit fc3e612

File tree

10 files changed

+95
-31
lines changed

10 files changed

+95
-31
lines changed

app/build.gradle

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ android {
44
signingConfigs {
55

66
}
7-
compileSdkVersion 26
8-
buildToolsVersion '26.0.2'
7+
compileSdkVersion 28
8+
buildToolsVersion '28.0.3'
9+
910
defaultConfig {
1011
applicationId "com.efraespada.stringobfuscator"
1112
minSdkVersion 14
12-
targetSdkVersion 26
13+
targetSdkVersion 28
1314
versionCode 1
1415
versionName "1.0"
1516
}
@@ -34,10 +35,10 @@ dependencies {
3435
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
3536
exclude group: 'com.android.support', module: 'support-annotations'
3637
})
37-
implementation 'com.android.support:appcompat-v7:26.1.0'
38+
implementation 'com.android.support:appcompat-v7:28.0.0'
3839
testImplementation 'junit:junit:4.12'
39-
implementation project(path: ':library')
40-
// implementation "com.stringcare:library:$stringcare_version"
40+
// implementation project(path: ':library')
41+
implementation "com.stringcare:library:$stringcare_version"
4142
}
4243

4344

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
android:orientation="vertical"
1818
android:layout_centerInParent="true">
1919

20+
<com.stringcare.library.SCTextView
21+
android:padding="10dp"
22+
android:layout_width="wrap_content"
23+
android:layout_height="wrap_content"
24+
android:layout_gravity="center_horizontal"
25+
android:textColor="@android:color/black"
26+
android:text="@string/automatic_decrypt"/>
27+
2028
<TextView
2129
android:padding="10dp"
2230
android:id="@+id/example_a"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<resources>
22
<string name="hello" hidden="true">hello world!</string>
3+
<string name="automatic_decrypt" hidden="true">auto decrypted value</string>
34
<string name="app_name">String Obfuscator Sample</string>
45
<string name="test_a" hidden="true">%1$s (%2$d)</string>
56
</resources>

build.gradle

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

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

88
repositories {
99
jcenter()
1010
google()
11-
mavenLocal()
11+
mavenCentral()
1212
maven {
1313
url "https://plugins.gradle.org/m2/"
1414
}
1515
}
1616

1717
dependencies {
1818
classpath "com.stringcare:plugin:$stringcare_version"
19-
// classpath files('../AndroidPlugin/build/libs/plugin-0.7.jar')
20-
classpath 'com.android.tools.build:gradle:3.0.1'
19+
// classpath files('../GradlePlugin/build/libs/plugin-0.9.jar')
20+
classpath 'com.android.tools.build:gradle:3.2.1'
2121
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1"
22-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
23-
classpath files('better-connected-plugin-0.1.jar')
22+
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
2423
}
2524
}
2625

2726
allprojects {
2827
repositories {
28+
mavenCentral()
2929
jcenter()
3030
google()
3131
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Oct 30 22:21:49 CET 2017
1+
#Wed Nov 07 22:16:56 CET 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

library/build.gradle

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

5-
version = "0.8"
5+
version = "0.9"
66

77
android {
8-
compileSdkVersion 25
9-
buildToolsVersion '26.0.2'
8+
compileSdkVersion 28
9+
buildToolsVersion '28.0.3'
1010

1111
defaultConfig {
12-
minSdkVersion 9
13-
targetSdkVersion 25
14-
versionCode 3
12+
minSdkVersion 14
13+
targetSdkVersion 28
14+
versionCode 4
1515
versionName version
1616

1717
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -30,12 +30,12 @@ android {
3030
}
3131

3232
dependencies {
33-
compile fileTree(dir: 'libs', include: ['*.jar'])
34-
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
33+
implementation fileTree(dir: 'libs', include: ['*.jar'])
34+
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
3535
exclude group: 'com.android.support', module: 'support-annotations'
3636
})
37-
compile 'com.android.support:appcompat-v7:25.4.0'
38-
testCompile 'junit:junit:4.12'
37+
implementation 'com.android.support:appcompat-v7:28.0.0'
38+
testImplementation 'junit:junit:4.12'
3939
}
4040

4141
def siteUrl = 'https://github.com/StringCare/AndroidLibrary'
@@ -81,13 +81,15 @@ task sourcesJar(type: Jar) {
8181
}
8282

8383
task javadoc(type: Javadoc) {
84+
exclude '**/**.java'
8485
source = android.sourceSets.main.java.srcDirs
8586
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
8687
}
8788

8889
task javadocJar(type: Jar, dependsOn: javadoc) {
8990
classifier = 'javadoc'
9091
from javadoc.destinationDir
92+
9193
}
9294

9395
artifacts {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
package com.stringcare.library;
22

33
public interface ContextListener {
4+
5+
void contextReady();
6+
47
}

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import java.security.cert.CertificateException;
1919
import java.security.cert.CertificateFactory;
2020
import java.security.cert.X509Certificate;
21+
import java.util.ArrayList;
2122
import java.util.Arrays;
23+
import java.util.List;
2224
import java.util.Locale;
2325

2426
import javax.crypto.Cipher;
@@ -31,26 +33,32 @@
3133

3234
public class SC {
3335

34-
private static final int LENGTH = 16;
35-
private static String libPackage;
3636
private static final String CODIFICATION = "UTF-8";
3737
private static final String TRANSFORMATION = "AES/ECB/PKCS5Padding";
3838
private static final char[] hexArray = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
3939
private static final String TAG = SC.class.getSimpleName();
4040
private static Context context;
41+
private static List<ContextListener> listeners = new ArrayList<>();
4142

43+
private SC () {
44+
// nothing to do here
45+
}
4246
public static void init(Context c) {
4347
context = c;
48+
if (!listeners.isEmpty()) {
49+
for (ContextListener listener : listeners) {
50+
listener.contextReady();
51+
}
52+
}
4453
}
4554

46-
public static void initForLib(Context c, Object object) {
47-
context = c;
48-
libPackage = object.getClass().getPackage().getName();
55+
public static void onContextReady(ContextListener listener) {
56+
listeners.add(listener);
4957
}
5058

5159
private static String getCertificateSHA1Fingerprint() {
5260
String packageName = context.getPackageName();
53-
return getCertificateSHA1Fingerprint(libPackage != null ? libPackage : packageName);
61+
return getCertificateSHA1Fingerprint(packageName);
5462
}
5563

5664
private static String getCertificateSHA1Fingerprint(String packageName) {
Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,45 @@
11
package com.stringcare.library;
22

3-
public class SCTextView {
3+
/**
4+
* Credits to Narvelan:
5+
* https://github.com/StringCare/AndroidLibrary/issues/34
6+
*/
7+
8+
import android.content.Context;
9+
import android.support.v7.widget.AppCompatTextView;
10+
import android.util.AttributeSet;
11+
12+
public class SCTextView extends AppCompatTextView {
13+
14+
public SCTextView(Context context) {
15+
super(context);
16+
}
17+
18+
public SCTextView(Context context, AttributeSet attrs) {
19+
super(context, attrs);
20+
loadText(attrs);
21+
}
22+
23+
public SCTextView(Context context, AttributeSet attrs, int defStyleAttr) {
24+
super(context, attrs, defStyleAttr);
25+
loadText(attrs);
26+
}
27+
28+
private void loadText(final AttributeSet attrs) {
29+
String text = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "text");
30+
if (text != null) {
31+
try {
32+
final Integer val = Integer.parseInt(text.substring(1));
33+
SC.onContextReady(new ContextListener() {
34+
@Override
35+
public void contextReady() {
36+
setText(SC.getString(val));
37+
}
38+
});
39+
} catch (NumberFormatException e) {
40+
setText(text);
41+
}
42+
}
43+
}
44+
445
}

white.png

1.26 KB
Loading

0 commit comments

Comments
 (0)