Skip to content

Commit 564066e

Browse files
author
wangshuwen15222
committed
feat:整理示例工程&&readme
1 parent 52879c3 commit 564066e

File tree

22 files changed

+225
-334
lines changed

22 files changed

+225
-334
lines changed

README.md

Lines changed: 75 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,100 +3,110 @@
33
# XRRouter
44

55
#### 最新版本
6+
67
| 模块 | xrouter_annotation | xrouter_complier|xrouter_core|
78
| ------------ | ------------ | ------------ | ------------ |
8-
| 最新版本 |[ ![Download](https://api.bintray.com/packages/wenwen/maven/annotation/images/download.svg) ](https://bintray.com/wenwen/maven/annotation/_latestVersion) | [ ![Download](https://api.bintray.com/packages/wenwen/maven/compiler/images/download.svg) ](https://bintray.com/wenwen/maven/compiler/_latestVersion) |[ ![Download](https://api.bintray.com/packages/wenwen/maven/core/images/download.svg) ](https://bintray.com/wenwen/maven/core/_latestVersion) |
9+
| 最新版本 | 1.0.4| 1.0.4 |1.0.4 |
10+
11+
912

1013
#### 添加依赖和配置
1114

1215
1.root project build.gradle
13-
``` gradle
16+
17+
```gradle
1418
allprojects {
15-
repositories {
16-
jcenter()
17-
}
19+
repositories {
20+
mavenCentral()
21+
}
1822
}
19-
```
23+
```
2024

2125
2.module build.gradle
2226

23-
``` gradle
27+
```gradle
2428
dependencies {
25-
implementation 'cn.cheney.xrouter:core:x.x.x'
26-
annotationProcessor 'cn.cheney.xrouter:compiler:x.x.x'
29+
implementation 'cn.cheney.xrouter:core:x.x.x'
30+
annotationProcessor 'cn.cheney.xrouter:compiler:x.x.x'
2731
}
28-
```
32+
```
33+
2934
#### 功能&说明
35+
3036
url : `scheme://moduleName/methodName?key=value`
37+
3138
* 协议方法必须为static
3239
* 支持任意数据类型路由传参
3340

34-
35-
3641
#### 功能使用
42+
3743
1.初始化
38-
```java
44+
45+
```java
3946
public class App extends Application {
4047

41-
@Override
42-
public void onCreate() {
43-
super.onCreate();
44-
//初始化
45-
XRouter.init(this, "scheme");
46-
//增加拦截器
47-
XRouter.getInstance().addInterceptor(new RouterInterceptor() {
48-
@Override
49-
public Invokable intercept(Chain chain) {
50-
BaseCall call = chain.call();
51-
String urlStr = call.getUri().toString();
52-
Logger.d(" RouterInterceptor urlStr=" + urlStr);
53-
return chain.proceed(call);
54-
}
55-
});
56-
//全局路由错误处理
57-
XRouter.getInstance().setErroHandler(new RouterErrorHandler() {
58-
@Override
59-
public void onError(String url, String errorMsg) {
60-
Logger.e("Url:" + url + " errorMsg:" + errorMsg);
61-
}
62-
});
63-
}
48+
@Override
49+
public void onCreate() {
50+
super.onCreate();
51+
//初始化
52+
XRouter.init(this, "scheme");
53+
//增加拦截器
54+
XRouter.getInstance().addInterceptor(new RouterInterceptor() {
55+
@Override
56+
public Invokable intercept(Chain chain) {
57+
BaseCall call = chain.call();
58+
String urlStr = call.getUri().toString();
59+
Logger.d(" RouterInterceptor urlStr=" + urlStr);
60+
return chain.proceed(call);
61+
}
62+
});
63+
//全局路由错误处理
64+
XRouter.getInstance().setErroHandler(new RouterErrorHandler() {
65+
@Override
66+
public void onError(String url, String errorMsg) {
67+
Logger.e("Url:" + url + " errorMsg:" + errorMsg);
68+
}
69+
});
70+
}
6471
}
65-
```
72+
```
73+
6674
2.注解
67-
```java
75+
76+
```java
6877
@XRoute(path = "pageName", module = "moduleName")
6978
public class YourActivity extends Activity {
7079

71-
@XParam(name = "paramObjectName")
72-
Object book;
73-
@XParam(name = "paramStrName")
74-
String paramStr;
75-
76-
@Override
77-
protected void onCreate(@Nullable Bundle savedInstanceState) {
78-
super.onCreate(savedInstanceState);
79-
setContentView(R.layout.xxx);
80-
XRouter.getInstance().inject(this);
81-
}
80+
@XParam(name = "paramObjectName")
81+
Object book;
82+
@XParam(name = "paramStrName")
83+
String paramStr;
84+
85+
@Override
86+
protected void onCreate(@Nullable Bundle savedInstanceState) {
87+
super.onCreate(savedInstanceState);
88+
setContentView(R.layout.xxx);
89+
XRouter.getInstance().inject(this);
90+
}
8291
}
8392

8493
@XRoute(module = "moduleName")
8594
public class YourModule{
86-
//同步方法
87-
@XMethod(name = "methodA")
88-
public static Object methodA(@XParam(name = "book") String paramValue) {
89-
return "";
90-
}
91-
//异步方法,必须包含requestId参数
92-
@XMethod(name = "asyncMethodB")
93-
public static void asyncMethodB(@XParam(name = XParam.RequestId) String requestId) {
94-
XRouter.getInstance().invokeCallback(requestId, new HashMap());
95-
}
95+
//同步方法
96+
@XMethod(name = "methodA")
97+
public static Object methodA(@XParam(name = "book") String paramValue) {
98+
return "";
99+
}
100+
//异步方法,必须包含requestId参数
101+
@XMethod(name = "asyncMethodB")
102+
public static void asyncMethodB(@XParam(name = XParam.RequestId) String requestId) {
103+
XRouter.getInstance().invokeCallback(requestId, new HashMap());
104+
}
96105
}
97-
```
106+
```
107+
108+
3.调用
98109

99-
3.调用
100110
```java
101111
//跳转界面
102112
Integer requestCode = XRouter.page("moduleName/methodName")
@@ -119,14 +129,16 @@ T result = XRouter.<T>method("moduleName/methodName")
119129

120130
}
121131
});
122-
123-
124132
```
133+
125134
#### 混淆配置
135+
126136
```
127137
内部已有混淆规则,不用配置
128138
```
139+
129140
#### 致谢
141+
130142
* JavaPoet,感谢提供高效的生成代码方式
131143
* ARouter,感谢提供了inject思路
132144

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,12 @@
1414
tools:ignore="GoogleAppIndexingWarning">
1515

1616
<activity
17-
android:name="cn.cheney.app.activity.MainActivity"
17+
android:name="cn.cheney.app.MainActivity"
1818
android:theme="@style/AppTheme">
1919
<intent-filter>
2020
<action android:name="android.intent.action.MAIN" />
2121
<category android:name="android.intent.category.LAUNCHER" />
22-
2322
</intent-filter>
24-
25-
</activity>
26-
27-
<activity android:name="cn.cheney.app.activity.ActivityA">
28-
2923
</activity>
3024

3125
</application>

app/src/main/java/cn/cheney/app/AlertUtil.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/src/main/java/cn/cheney/app/App.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ public class App extends Application {
1515
@Override
1616
public void onCreate() {
1717
super.onCreate();
18-
1918
XRouter.init(this, "cheney");
20-
2119
//url 拦截
2220
XRouter.getInstance().addInterceptor(new RouterInterceptor() {
2321
@Override
@@ -28,7 +26,7 @@ public Invokable<?> intercept(Chain chain) {
2826
return chain.proceed(call);
2927
}
3028
});
31-
29+
//全局错误监听
3230
XRouter.getInstance().setErrorHandler(new RouterErrorHandler() {
3331
@Override
3432
public void onError(String url, String errorMsg) {
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package cn.cheney.app;
2+
3+
import android.content.Intent;
4+
import android.net.Uri;
5+
import android.os.Bundle;
6+
7+
import androidx.annotation.Nullable;
8+
import androidx.appcompat.app.AppCompatActivity;
9+
10+
import java.util.ArrayList;
11+
import java.util.HashMap;
12+
import java.util.List;
13+
import java.util.Map;
14+
15+
import cn.cheney.mtest.AlertUtil;
16+
import cn.cheney.mtest.entity.Book;
17+
import cn.cheney.xrouter.core.XRouter;
18+
import cn.cheney.xrouter.core.call.MethodCall;
19+
import cn.cheney.xrouter.core.callback.RouteCallback;
20+
import cn.cheney.xrouter.core.util.Logger;
21+
22+
public class MainActivity extends AppCompatActivity {
23+
24+
@Override
25+
protected void onCreate(Bundle savedInstanceState) {
26+
super.onCreate(savedInstanceState);
27+
setContentView(R.layout.activity_main);
28+
//路由跳转界面
29+
findViewById(R.id.btn1).setOnClickListener(v -> {
30+
List<String> infoList = new ArrayList<>();
31+
infoList.add("stringValue");
32+
Map<String, String> map = new HashMap<>();
33+
map.put("key", "stringValue");
34+
Integer requestCode = XRouter.page("moduleA/page/a")
35+
.put("infoList", infoList)
36+
.put("infoMap", map)
37+
.put("book", new Book("Java"))
38+
.action("cn.cheney.xrouter")
39+
.anim(R.anim.enter_bottom, R.anim.no_anim)
40+
.call();
41+
42+
Logger.d("Route Page requestCode= " + requestCode);
43+
});
44+
45+
//路由执行同步方法
46+
findViewById(R.id.btn2).setOnClickListener(v -> {
47+
Book book = new Book();
48+
book.name = "Kotlin";
49+
MethodCall<Book> bookMethodCall = XRouter.<Book>method(
50+
"moduleA/getBookName");
51+
Book bookReturn = bookMethodCall.call();
52+
AlertUtil.showAlert(MainActivity.this, bookReturn.toString());
53+
});
54+
55+
//路由执行异步方法
56+
findViewById(R.id.btn3).setOnClickListener(v -> {
57+
Book book = new Book();
58+
book.name = "Kotlin";
59+
XRouter.<Book>method("moduleA/setBookInfo?info={\"key\":{\"name\":\"wang\"}}")
60+
.put("book", book).call(result ->
61+
AlertUtil.showAlert(MainActivity.this, result.toString()));
62+
});
63+
64+
findViewById(R.id.btn4).setOnClickListener(v -> {
65+
Book bookError = XRouter.<Book>method("sssss")
66+
.call(new RouteCallback() {
67+
@Override
68+
public void onResult(Map<String, Object> result) {
69+
AlertUtil.showAlert(MainActivity.this, "错误异步返回结果=" + result);
70+
}
71+
});
72+
AlertUtil.showAlert(MainActivity.this, "错误同步返回结果=" + bookError);
73+
});
74+
}
75+
76+
@Override
77+
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
78+
super.onActivityResult(requestCode, resultCode, data);
79+
if (requestCode == 2000) {
80+
if (null != data) {
81+
Uri uri = data.getData();
82+
Logger.d("uri=" + uri);
83+
}
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)