Skip to content

Commit

Permalink
Update readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhi1ong committed Mar 1, 2019
1 parent 9d170e7 commit 93b3285
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
22 changes: 18 additions & 4 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
</activity>
```

2. 解析URL中的参数
2. 解析参数
``` java
// 为每一个参数声明一个字段,并使用 @Autowired 标注
// URL中不能传递Parcelable类型数据,通过ARouter api可以传递Parcelable对象
Expand All @@ -179,11 +179,25 @@
public String name;
@Autowired
int age;
@Autowired(name = "girl") // 通过name来映射URL中的不同参数

// 通过name来映射URL中的不同参数
@Autowired(name = "girl")
boolean boy;

// 支持解析自定义对象,URL中使用json传递
@Autowired
TestObj obj; // 支持解析自定义对象,URL中使用json传递

TestObj obj;

// 使用 withObject 传递 List 和 Map 的实现了
// Serializable 接口的实现类(ArrayList/HashMap)
// 的时候,接收该对象的地方不能标注具体的实现类类型
// 应仅标注为 List 或 Map,否则会影响序列化中类型
// 的判断, 其他类似情况需要同样处理
@Autowired
List<TestObj> list;
@Autowired
Map<String, List<TestObj>> map;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@
public class TypeUtils {

private Types types;
private Elements elements;
private TypeMirror parcelableType;
private TypeMirror serializableType;

public TypeUtils(Types types, Elements elements) {
this.types = types;
this.elements = elements;

parcelableType = this.elements.getTypeElement(PARCELABLE).asType();
serializableType = this.elements.getTypeElement(SERIALIZABLE).asType();
parcelableType = elements.getTypeElement(PARCELABLE).asType();
serializableType = elements.getTypeElement(SERIALIZABLE).asType();
}

/**
Expand Down Expand Up @@ -74,12 +72,15 @@ public int typeExchange(Element element) {
return TypeKind.CHAR.ordinal();
case STRING:
return TypeKind.STRING.ordinal();
default: // Other side, maybe the PARCELABLE or SERIALIZABLE or OBJECT.
if (types.isSubtype(typeMirror, parcelableType)) { // PARCELABLE
default:
// Other side, maybe the PARCELABLE or SERIALIZABLE or OBJECT.
if (types.isSubtype(typeMirror, parcelableType)) {
// PARCELABLE
return TypeKind.PARCELABLE.ordinal();
} else if (types.isSubtype(typeMirror, serializableType)) { // PARCELABLE
} else if (types.isSubtype(typeMirror, serializableType)) {
// SERIALIZABLE
return TypeKind.SERIALIZABLE.ordinal();
} else { // For others
} else {
return TypeKind.OBJECT.ordinal();
}
}
Expand Down

0 comments on commit 93b3285

Please sign in to comment.