Skip to content

Commit 75ffc70

Browse files
author
wangshuwen
committed
chore:修改示例工程代码
1 parent 775f6ca commit 75ffc70

File tree

10 files changed

+77
-52
lines changed

10 files changed

+77
-52
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cn.cheney.app;
2+
3+
import android.content.Context;
4+
5+
import androidx.appcompat.app.AlertDialog;
6+
7+
public class AlertUtil {
8+
9+
public static void showAlert(Context context,String msg) {
10+
new AlertDialog.Builder(context)
11+
.setTitle("Result")
12+
.setMessage(msg)
13+
.create()
14+
.show();
15+
}
16+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import cn.cheney.xrouter.annotation.XRoute;
1414
import cn.cheney.xrouter.core.XRouter;
1515

16-
@XRoute(path = "page", module = "home")
16+
@XRoute(path = "page", module = "moduleB")
1717
public class HomeActivity extends AppCompatActivity {
1818

1919
public static final String TAG = HomeActivity.class.getSimpleName();

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

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
import java.util.List;
1414
import java.util.Map;
1515

16-
import cn.cheney.xrouter.core.callback.RouteCallback;
1716
import cn.cheney.xrouter.core.XRouter;
1817
import cn.cheney.xrouter.core.call.MethodCall;
18+
import cn.cheney.xrouter.core.callback.RouteCallback;
1919
import cn.cheney.xrouter.core.util.Logger;
2020

2121
public class MainActivity extends AppCompatActivity {
@@ -24,88 +24,87 @@ public class MainActivity extends AppCompatActivity {
2424
protected void onCreate(Bundle savedInstanceState) {
2525
super.onCreate(savedInstanceState);
2626
setContentView(R.layout.activity_main);
27+
2728
findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener() {
2829
@Override
2930
public void onClick(View v) {
3031
List<String> infoList = new ArrayList<>();
3132
infoList.add("value");
32-
33-
Map<String,String> map = new HashMap<>();
34-
map.put("key","value");
35-
36-
Integer requestCode = XRouter.page("home/page")
33+
Map<String, String> map = new HashMap<>();
34+
map.put("key", "value");
35+
Integer requestCode = XRouter.page("moduleA/page")
3736
.put("infoList", infoList)
3837
.put("infoMap", map)
3938
.action("cn.cheney.xrouter")
4039
.anim(R.anim.enter_bottom, R.anim.exit_bottom)
4140
.requestCode(1000)
4241
.call();
42+
4343
Logger.d("Route Page requestCode= " + requestCode);
4444
}
4545
});
46+
4647
findViewById(R.id.btn2).setOnClickListener(new View.OnClickListener() {
4748
@Override
4849
public void onClick(View v) {
4950
Book book = new Book();
5051
book.name = "Kotlin";
5152
MethodCall<Book> bookMethodCall = XRouter.<Book>method(
52-
"home/getBookName?book={\"name\":\"Kotlin\"}");
53+
"moduleA/getBookName");
5354
Book bookReturn = bookMethodCall.call();
54-
Logger.d("getSyncBookName bookReturn= " + bookReturn
55-
+ " isAsync=" + bookMethodCall.isAsync());
55+
AlertUtil.showAlert(MainActivity.this, bookReturn.toString());
5656
}
5757
});
58+
59+
5860
findViewById(R.id.btn3).setOnClickListener(new View.OnClickListener() {
5961
@Override
6062
public void onClick(View v) {
6163
Book book = new Book();
6264
book.name = "Kotlin";
63-
final MethodCall<Book> methodCall = XRouter.<Book>method("home/getAsyncBookName")
65+
final MethodCall<Book> methodCall = XRouter.<Book>method("moduleA/getAsyncBookName")
6466
.put("book", book);
6567
methodCall.call(new RouteCallback() {
6668
@Override
6769
public void onResult(Map<String, Object> result) {
68-
Logger.d("getAsyncBookName bookReturn= "
69-
+ result + " isAsync=" + methodCall.isAsync());
70+
AlertUtil.showAlert(MainActivity.this, result.toString());
7071
}
7172
});
7273
}
7374
});
7475
findViewById(R.id.btn4).setOnClickListener(new View.OnClickListener() {
7576
@Override
7677
public void onClick(View v) {
77-
Book book = new Book();
78-
book.name = "Kotlin";
79-
Book bookError = XRouter.<Book>method(null)
80-
.put("book", book)
81-
.call(new RouteCallback() {
82-
@Override
83-
public void onResult(Map<String, Object> result) {
84-
Logger.d("Error bookReturn= " + result);
85-
}
86-
});
87-
Logger.d(" bookError= " + bookError);
78+
XRouter.<Void>method("moduleA/setBookInfo?info={\"key\":{\"name\":\"wang\"}}")
79+
.call(MainActivity.this);
8880
}
8981
});
82+
9083
findViewById(R.id.btn5).setOnClickListener(new View.OnClickListener() {
9184
@Override
9285
public void onClick(View v) {
9386
Book book = new Book();
9487
book.name = "Kotlin";
95-
Integer requestCode = XRouter.page("test/page1")
96-
.action("cn.cheney.xrouter")
88+
Integer requestCode = XRouter.page("moduleD/page1")
89+
//.action("cn.cheney.xrouter")
9790
.anim(R.anim.enter_bottom, R.anim.exit_bottom)
9891
.requestCode(1000)
9992
.call();
100-
10193
Logger.d("Route test Module page1 requestCode= " + requestCode);
10294
}
10395
});
96+
10497
findViewById(R.id.btn6).setOnClickListener(new View.OnClickListener() {
10598
@Override
10699
public void onClick(View v) {
107-
XRouter.method("home/setBookInfo?info={\"key\":{\"name\":\"wang\"}}")
108-
.call();
100+
Book bookError = XRouter.<Book>method("sssss")
101+
.call(new RouteCallback() {
102+
@Override
103+
public void onResult(Map<String, Object> result) {
104+
AlertUtil.showAlert(MainActivity.this, "错误异步返回结果=" + result);
105+
}
106+
});
107+
AlertUtil.showAlert(MainActivity.this, "错误同步返回结果=" + bookError);
109108
}
110109
});
111110
}

app/src/main/java/cn/cheney/app/HomeMethod.java renamed to app/src/main/java/cn/cheney/app/ModuleA.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import cn.cheney.xrouter.annotation.XRoute;
1414
import cn.cheney.xrouter.core.XRouter;
1515

16-
@XRoute(module = "home")
17-
public class HomeMethod {
16+
@XRoute(module = "moduleA")
17+
public class ModuleA {
1818

19-
private static final String TAG = HomeMethod.class.getSimpleName();
19+
private static final String TAG = ModuleA.class.getSimpleName();
2020

2121
@XMethod(name = "getBookName")
2222
public static Book getBookName(Context context) {
@@ -35,12 +35,14 @@ public static void getAsyncBookName(@XParam(name = XParam.RequestId) String requ
3535
XRouter.getInstance().invokeCallback(requestId, map);
3636
}
3737

38+
3839
@XMethod(name = "setBookInfo")
39-
public static List<String> setBookInfo(@XParam(name = "info") Map<String, Object> info) {
40-
for (Map.Entry<String, Object> entry : info.entrySet()) {
41-
Object book = entry.getValue();
40+
public static List<String> setBookInfo(Context context, @XParam(name = "info") Map<String, Book> info) {
41+
for (Map.Entry<String, Book> entry : info.entrySet()) {
42+
Book book = entry.getValue();
4243
Log.i(TAG, "setBookInfo KEY:" + entry.getKey() + "|VALUE:" + book);
4344
}
45+
AlertUtil.showAlert(context, "传参 =" + info);
4446
return new ArrayList<>();
4547
}
4648

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,18 @@
2929
android:id="@+id/btn4"
3030
android:layout_width="wrap_content"
3131
android:layout_height="wrap_content"
32-
android:text="错误协议调用" />
33-
32+
android:text="MAP泛型 传参" />
3433

3534
<Button
3635
android:id="@+id/btn5"
3736
android:layout_width="wrap_content"
3837
android:layout_height="wrap_content"
3938
android:text="跨模块调用Test Page1" />
4039

41-
42-
4340
<Button
4441
android:id="@+id/btn6"
4542
android:layout_width="wrap_content"
4643
android:layout_height="wrap_content"
47-
android:text="MAP 传参" />
44+
android:text="错误协议调用" />
45+
</LinearLayout>
4846

49-
</LinearLayout>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cn.cheney.mtest;
2+
3+
import android.content.Context;
4+
5+
import androidx.appcompat.app.AlertDialog;
6+
7+
public class AlertUtil {
8+
9+
public static void showAlert(Context context,String msg) {
10+
new AlertDialog.Builder(context)
11+
.setTitle("Result")
12+
.setMessage(msg)
13+
.create()
14+
.show();
15+
}
16+
}

m_test/src/main/java/cn/cheney/mtest/TestActivity.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
import cn.cheney.xrouter.annotation.XRoute;
1010
import cn.cheney.xrouter.core.XRouter;
11-
import cn.cheney.xrouter.core.util.Logger;
1211

13-
@XRoute(path = "page1", module = "test")
12+
@XRoute(path = "page1", module = "moduleD")
1413
public class TestActivity extends Activity {
1514

1615

@@ -21,9 +20,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
2120
findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener() {
2221
@Override
2322
public void onClick(View v) {
24-
Object bookReturn = XRouter.method("home/getBookName2")
23+
Object bookReturn = XRouter.method("moduleA/getBookName")
2524
.call();
26-
Logger.d("getSyncBookName bookReturn= " + bookReturn);
25+
AlertUtil.showAlert(TestActivity.this, "" + bookReturn);
2726
}
2827
});
2928
}

m_test/src/main/java/cn/cheney/mtest/TestMethod.java renamed to m_test/src/main/java/cn/cheney/mtest/TestModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import cn.cheney.xrouter.annotation.XMethod;
44
import cn.cheney.xrouter.annotation.XRoute;
55

6-
@XRoute(module = "test")
7-
public class TestMethod {
6+
@XRoute(module = "moduleC")
7+
public class TestModule {
88

99
@XMethod(name = "getBookName")
1010
public static String getBookName() {

m_test/src/main/res/layout/mtest_activity_1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
android:layout_width="wrap_content"
1010
android:layout_height="wrap_content"
1111
android:layout_centerInParent="true"
12-
android:text="测试module点击调用app模块方法"
12+
android:text="调用AppModule方法"
1313
android:textSize="20sp"
1414
android:textStyle="bold" />
1515

xrouter_core/src/main/java/cn/cheney/xrouter/core/invok/ParamInfo.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package cn.cheney.xrouter.core.invok;
22

3-
import com.alibaba.fastjson.TypeReference;
4-
53
import java.lang.reflect.Type;
6-
import java.util.Map;
74

85
public class ParamInfo {
96

@@ -13,7 +10,6 @@ public class ParamInfo {
1310
public ParamInfo(String name, Type type) {
1411
this.name = name;
1512
this.type = type;
16-
this.type = new TypeReference<Map<String, Object>>(){}.getType();
1713
}
1814

1915
public String getName() {

0 commit comments

Comments
 (0)