Skip to content

Commit dfeabb6

Browse files
modify annotation,add proguard rules
1 parent 019083b commit dfeabb6

11 files changed

Lines changed: 78 additions & 88 deletions

File tree

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
```java
88
public class ExampleActivity extends Activity{
9-
@AutoAccess(dataName = "name")
10-
String name;
11-
@AutoAccess(dataName = "description")
12-
String description;
9+
@AutoAccess String name;
10+
@AutoAccess String description;
1311

1412
@Override
1513
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -65,9 +63,13 @@ Then, apply the 'android-apt' plugin in your module-level build.gradle and add t
6563
}
6664

6765
dependencies {
68-
compile 'com.thirtydegreesray:dataautoaccess:1.2.1'
69-
apt 'com.thirtydegreesray:dataautoaccess-compiler:1.2.1'
66+
compile 'com.thirtydegreesray:dataautoaccess:1.2.2'
67+
apt 'com.thirtydegreesray:dataautoaccess-compiler:1.2.2'
7068
}
69+
70+
##Proguard
71+
-keep class com.thirtydegreesray.dataautoaccess.** { *; }
72+
-keep class **$$DataAccessor { *; }
7173

7274
##License
7375
Copyright 2016 ThirtyDegreesRay
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
package com.thirtydegreesray.dataautoaccess.annotation;
22

3-
import java.lang.annotation.ElementType;
43
import java.lang.annotation.Retention;
5-
import java.lang.annotation.RetentionPolicy;
64
import java.lang.annotation.Target;
75

6+
import static java.lang.annotation.ElementType.FIELD;
7+
import static java.lang.annotation.RetentionPolicy.CLASS;
8+
89
/**
910
* data auto access<br>
1011
* set this inject, the object will save automatic save when onSaveInstanceState, and get data when onCreate<br>
1112
*
1213
* Created by ThirtyDegreesRay on 2016/9/6 09:35
1314
*/
14-
@Target(ElementType.FIELD)
15-
@Retention(RetentionPolicy.RUNTIME)
15+
@Target(FIELD)
16+
@Retention(CLASS)
1617
public @interface AutoAccess {
1718
/**
18-
* the access key of the filed, must be unique in one class
19+
* the access key of the filed, must be unique in one class<br>
20+
* if don't set this value, use field name as default key
1921
* @return dataName
2022
*/
21-
String dataName() ;
23+
String dataName() default "";
2224
}

dataautoaccess-compiler/src/main/java/com/thirtydegreesray/dataautoaccess/compiler/AutoAccessClass.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private void generateGetDataCode(StringBuilder java){
6969
for(FieldAutoAccess field : fields){
7070
java.append("\t").append("target.").append(field.getFieldName())
7171
.append(" = ")
72-
.append("DataAutoAccess.getCastData(").append("\"").append(field.getDataName()).append("\"")
72+
.append("DataAutoAccess.getCastData(").append("\"").append(field.getFiledKey()).append("\"")
7373
.append(", ").append("dataStore").append(");\n");
7474
}
7575
java.append("}\n");
@@ -82,12 +82,12 @@ private void generateSaveDataCode(StringBuilder java){
8282
//type ArrayList
8383
if(putPreCode.equals("")){
8484
java.append("\t").append("DataAutoAccess.saveArrayList(")
85-
.append("\"").append(field.getDataName()).append("\"").append(", ")
85+
.append("\"").append(field.getFiledKey()).append("\"").append(", ")
8686
.append("target.").append(field.getFieldName()).append(", ")
8787
.append("dataStore").append(");\n");
8888
}else{
8989
java.append("\t").append("dataStore.").append(putPreCode)
90-
.append("(").append("\"").append(field.getDataName()).append("\"").append(", ")
90+
.append("(").append("\"").append(field.getFiledKey()).append("\"").append(", ")
9191
.append("target.").append(field.getFieldName()).append(");\n");
9292
}
9393
}

dataautoaccess-compiler/src/main/java/com/thirtydegreesray/dataautoaccess/compiler/FieldAutoAccess.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ public String getDataName() {
2727
public String getFieldType() {
2828
return fieldType;
2929
}
30+
31+
public String getFiledKey(){
32+
return dataName== null || dataName.equals("") ? fieldName : dataName;
33+
}
3034
}

dataautoaccess/src/main/java/com/thirtydegreesray/dataautoaccess/DataAutoAccess.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
* Android bundle data auto access.<br>
1414
*USE<br>
1515
* <pre><code>
16-
* public class BaseActivity extends Activity {
16+
* public class ExampleActivity extends Activity {
17+
* {@literal @}AutoAccess String name;
18+
* {@literal @}AutoAccess String description;
19+
*
1720
* {@literal @}Override
1821
* protected void onCreate(@Nullable Bundle savedInstanceState) {
1922
* super.onCreate(savedInstanceState);
@@ -25,6 +28,7 @@
2528
* data = savedInstanceState;
2629
* }
2730
* DataAutoAccess.getData(this, data);
31+
* //TODO use fields...
2832
* }
2933
*
3034
* {@literal @}Override
@@ -37,10 +41,10 @@
3741
* </code></pre>
3842
*
3943
* <pre><code>
40-
* public class ExampleActivity extends BaseActivity {
41-
* {@literal @}AutoAccess(dataName = "name") String name;
42-
* {@literal @}AutoAccess(dataName = "description") String description;
43-
* }
44+
* Intent intent = new Intent(this, ExampleActivity.class);
45+
* intent.putExtra("name", "DataAutoAccess");
46+
* intent.putExtra("description", "Android bundle data auto access.");
47+
* startActivity(intent);
4448
* </code></pre>
4549
*
4650
* Created by ThirtyDegreesRay on 2016/9/6 09:35

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ org.gradle.jvmargs=-Xmx1536m
1616
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1717
# org.gradle.parallel=true
1818

19-
VERSION_NAME = 1.2.1
20-
VERSION_CODE = 11
19+
VERSION_NAME = 1.2.2
20+
VERSION_CODE = 12
2121

sample/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ android {
1717
}
1818
buildTypes {
1919
release {
20-
minifyEnabled false
20+
minifyEnabled true
21+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22+
}
23+
debug {
24+
minifyEnabled true
2125
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2226
}
2327
}

sample/proguard-rules.pro

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@
1515
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
1616
# public *;
1717
#}
18+
19+
#DataAutoAccess
20+
-keep class com.thirtydegreesray.dataautoaccess.** { *; }
21+
-keep class **$$DataAccessor { *; }
22+
#DataAutoAccess

sample/src/main/java/com/thirtydegreesray/dataautoaccess/sample/ExampleActivity.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414

1515
public class ExampleActivity extends BaseActivity {
1616

17-
@AutoAccess(dataName = "name")
18-
String name;
19-
@AutoAccess(dataName = "description")
20-
String description;
17+
@AutoAccess String name;
18+
@AutoAccess String description;
2119

2220
private TextView tvName;
2321
private TextView tvDescription;

sample/src/main/java/com/thirtydegreesray/dataautoaccess/sample/TestClass.java

Lines changed: 31 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -9,69 +9,40 @@
99
import java.util.ArrayList;
1010

1111
/**
12-
* Created by YuYunHao on 2016/9/5 17:45
12+
* Created by ThirtyDegreesRay on 2016/9/5 17:45
1313
*/
1414

1515
public class TestClass {
1616

17-
@AutoAccess(dataName = "field1")
18-
String field1 ;
19-
@AutoAccess(dataName = "field2")
20-
int field2 ;
21-
@AutoAccess(dataName = "field3")
22-
boolean field3 ;
23-
@AutoAccess(dataName = "field4")
24-
double field4 ;
25-
@AutoAccess(dataName = "field5")
26-
float field5 ;
27-
@AutoAccess(dataName = "field6")
28-
long field6 ;
29-
@AutoAccess(dataName = "field7")
30-
byte field7 ;
31-
@AutoAccess(dataName = "field8")
32-
char field8 ;
33-
@AutoAccess(dataName = "field9")
34-
short field9 ;
35-
@AutoAccess(dataName = "field1")
36-
Parcelable field10 ;
37-
@AutoAccess(dataName = "field11")
38-
Serializable field11 ;
39-
@AutoAccess(dataName = "field12")
40-
Bundle field12 ;
41-
@AutoAccess(dataName = "field28")
42-
CharSequence field28 ;
43-
44-
45-
@AutoAccess(dataName = "field13")
46-
ArrayList<String> field13 = new ArrayList<>();
47-
@AutoAccess(dataName = "field14")
48-
ArrayList<Integer> field14 = new ArrayList<>();
49-
@AutoAccess(dataName = "field15")
50-
ArrayList<? extends Parcelable> field15 = new ArrayList<>();
51-
@AutoAccess(dataName = "field26")
52-
ArrayList<? extends CharSequence> field26 = new ArrayList<>();
53-
54-
@AutoAccess(dataName = "field16")
55-
String[] field16 ;
56-
@AutoAccess(dataName = "field17")
57-
int[] field17 ;
58-
@AutoAccess(dataName = "field18")
59-
boolean[] field18 ;
60-
@AutoAccess(dataName = "field19")
61-
double[] field19 ;
62-
@AutoAccess(dataName = "field20")
63-
float[] field20 ;
64-
@AutoAccess(dataName = "field21")
65-
long[] field21 ;
66-
@AutoAccess(dataName = "field22")
67-
byte[] field22 ;
68-
@AutoAccess(dataName = "field23")
69-
char[] field23 ;
70-
@AutoAccess(dataName = "field24")
71-
short[] field24 ;
72-
@AutoAccess(dataName = "field25")
73-
Parcelable[] field25 ;
74-
@AutoAccess(dataName = "field27")
75-
CharSequence[] field27 ;
17+
@AutoAccess String field1 ;
18+
@AutoAccess int field2 ;
19+
@AutoAccess boolean field3 ;
20+
@AutoAccess double field4 ;
21+
@AutoAccess float field5 ;
22+
@AutoAccess long field6 ;
23+
@AutoAccess byte field7 ;
24+
@AutoAccess char field8 ;
25+
@AutoAccess short field9 ;
26+
@AutoAccess Parcelable field10 ;
27+
@AutoAccess Serializable field11 ;
28+
@AutoAccess Bundle field12 ;
29+
@AutoAccess CharSequence field28 ;
30+
31+
@AutoAccess ArrayList<String> field13 = new ArrayList<>();
32+
@AutoAccess ArrayList<Integer> field14 = new ArrayList<>();
33+
@AutoAccess ArrayList<? extends Parcelable> field15 = new ArrayList<>();
34+
@AutoAccess ArrayList<? extends CharSequence> field26 = new ArrayList<>();
35+
36+
@AutoAccess String[] field16 ;
37+
@AutoAccess int[] field17 ;
38+
@AutoAccess boolean[] field18 ;
39+
@AutoAccess double[] field19 ;
40+
@AutoAccess float[] field20 ;
41+
@AutoAccess long[] field21 ;
42+
@AutoAccess byte[] field22 ;
43+
@AutoAccess char[] field23 ;
44+
@AutoAccess short[] field24 ;
45+
@AutoAccess Parcelable[] field25 ;
46+
@AutoAccess CharSequence[] field27 ;
7647

7748
}

0 commit comments

Comments
 (0)