Skip to content

Commit

Permalink
version 1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
holmeszyx committed Aug 1, 2016
1 parent dcc6ef5 commit e48b2f4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sp-gen 即是 "Shared Preference Generator"。想法来源于GreenDao
sp-gen 即是 "Shared Preference Generator"。想法来源于[GreenDao](https://github.com/greenrobot/greenDAO)

用于生成Android中直接调用Shared preference的代码。
主要目的:
Expand All @@ -17,7 +17,7 @@ sp-gen 即是 "Shared Preference Generator"。想法来源于GreenDao

加入依赖

`compile 'z.hol.spgen:sp-gen:1.0.2'`
`compile 'z.hol.spgen:sp-gen:1.0.3'`

引入jcenter仓库

Expand All @@ -42,7 +42,7 @@ repositories {
}
dependencies {
compile 'z.hol.spgen:sp-gen:1.0.1'
compile 'z.hol.spgen:sp-gen:1.0.3'
}
mainClassName = "z.hol.spgen.example.GenExample"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'z.hol.spgen'
version '1.0.2'
version '1.0.3'

apply plugin: 'java'

Expand Down
2 changes: 1 addition & 1 deletion example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
// compile rootProject
compile 'z.hol.spgen:sp-gen:1.0.2'
compile 'z.hol.spgen:sp-gen:1.0.3'
}

mainClassName = "z.hol.spgen.example.GenExample"
Expand Down
35 changes: 32 additions & 3 deletions example/src/main/java/z/hol/spgen/example/GenExample.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package z.hol.spgen.example;

import z.hol.spgen.Rule;
import z.hol.spgen.Schema;
import z.hol.spgen.SpGenerator;
import z.hol.spgen.*;

import java.io.IOException;

Expand All @@ -23,16 +21,47 @@ public static void main(String[] args) throws IOException {
r.addEntity("avatar_url").asBoolean();
r.addEntity("tags").asStringSet();

DotParamIntercept dotParamIntercept = new DotParamIntercept();
Rule r2 = schema.addRule("Setting", "app_setting");
r2.setParamKeyIntercept(dotParamIntercept);
r2.setCanClear(true);
r2.setComment("应用设置");
r2.addEntity("first_launch").asBoolean().defaultValue(false);
r2.addEntity("last_login_timestamp").asLong();
r2.addEntity("price").asFloat().defaultValue(12.3F);
r2.addEntity("item.first").asString().defaultValue("one");
r2.addEntity("item.second").asString().defaultValue("two");
r2.addEntity("item.other").asString().defaultValue("many");

SpGenerator generator = new SpGenerator();
generator.generateAll(schema, "src-gen/");

}

private static class DotParamIntercept implements TextIntercept {

public String intercept(String src) {
String result;
final String name = src;
int length = name.length();
StringBuilder sb = new StringBuilder(length);
boolean nextCap = false;
for (int i = 0; i < length; i++) {
char c = name.charAt(i);
if (c == '_' || c == '-' || c == '.') {
nextCap = true;
continue;
}
if (sb.length() > 0 && nextCap && c >= 'a' && c <= 'z') {
c = Character.toUpperCase(c);
nextCap = false;
}
sb.append(c);
}
result = sb.toString();
return result;
}
}


}
2 changes: 1 addition & 1 deletion publisher.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ext {
libraryDescription = 'The code generator for shared preference in Android. '
siteUrl = 'https://github.com/holmeszyx/sp-gen'
gitUrl = '[email protected]:holmeszyx/sp-gen.git'
libraryVersion = '1.0.2'
libraryVersion = '1.0.3'
developerId = 'holmeszyx'
developerName = 'holmes zhang'
developerEmail = '[email protected]'
Expand Down

0 comments on commit e48b2f4

Please sign in to comment.