From fcfcd2f4f8734e93ea838170ddcb7aad5aebeb39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B6=9B=28tao281=2Ezhang=29?= Date: Wed, 20 Mar 2024 14:49:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=96=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/therouter/Extension.kt | 7 +++++++ .../main/java/com/therouter/app/MainActivity.java | 3 ++- .../app/navigator/NavigatorTargetActivity.java | 14 ++++++++++++++ .../app/navigator/NavigatorTargetActivity2.java | 2 ++ .../app/navigator/NavigatorTestActivity.java | 3 ++- 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/therouter/Extension.kt diff --git a/app/src/main/java/com/therouter/Extension.kt b/app/src/main/java/com/therouter/Extension.kt new file mode 100644 index 00000000..19ad7ba9 --- /dev/null +++ b/app/src/main/java/com/therouter/Extension.kt @@ -0,0 +1,7 @@ +package com.therouter + +fun require(pass: Boolean, tag: String, msg: String) { + if (!pass) { + throw IllegalArgumentException("TheRouter::$tag::$msg") + } +} diff --git a/app/src/main/java/com/therouter/app/MainActivity.java b/app/src/main/java/com/therouter/app/MainActivity.java index 37547543..26f39499 100644 --- a/app/src/main/java/com/therouter/app/MainActivity.java +++ b/app/src/main/java/com/therouter/app/MainActivity.java @@ -14,8 +14,9 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); - setTitle("功能介绍"); + setTitle("TheRouter功能介绍"); // 如果用到了 @Autowired 注解,需要加这一行,这一行直接写在BaseActivity中更好 + // 如果用到了onNewIntent(),也需要调用这一行,并且在调用前需要将新intent 重新set一遍 // TheRouter.inject(this); TextView textView = findViewById(R.id.content_version); diff --git a/app/src/main/java/com/therouter/app/navigator/NavigatorTargetActivity.java b/app/src/main/java/com/therouter/app/navigator/NavigatorTargetActivity.java index dbe93030..0b0cb4b3 100644 --- a/app/src/main/java/com/therouter/app/navigator/NavigatorTargetActivity.java +++ b/app/src/main/java/com/therouter/app/navigator/NavigatorTargetActivity.java @@ -1,5 +1,7 @@ package com.therouter.app.navigator; +import static com.therouter.ExtensionKt.require; + import android.os.Bundle; import android.view.View; import android.widget.Button; @@ -86,42 +88,54 @@ protected void onCreate(Bundle savedInstanceState) { final TextView textView1 = findViewById(R.id.textview1); textView1.setText("接收int值传递:integer2=" + intValue); + require(intValue == 12345678, "NavigatorTargetActivity", "intValue数值不对"); final TextView textView2 = findViewById(R.id.textview2); textView2.setText("用String传递int数据:" + stringIntValue); + require("12345678".equals(stringIntValue), "NavigatorTargetActivity", "stringIntValue数值不对"); final TextView textView3 = findViewById(R.id.textview3); textView3.setText("接收包含大小写数字的String值传递:" + str_123_Value); + require("测试传中文字符串".equals(str_123_Value), "NavigatorTargetActivity", "str_123_Value数值不对"); final TextView textView4 = findViewById(R.id.textview4); textView4.setText("接收故意传递非boolean值给boolean变量:" + boolParseError); + require(!boolParseError, "NavigatorTargetActivity", "boolParseError数值不对"); final TextView textview4_1 = findViewById(R.id.textview4_1); textview4_1.setText("用字符串传一个很大的值给short变量:" + shortParseError); + require(0 == shortParseError, "NavigatorTargetActivity", "shortParseError数值不对"); final TextView textView5 = findViewById(R.id.textview5); textView5.setText("接收boolean值:boolValue=" + boolValue); + require(boolValue, "NavigatorTargetActivity", "boolValue数值不对"); final TextView textview6 = findViewById(R.id.textview6); textview6.setText("接收Long类型的值:longValue=" + longValue); + require(123456789012345L == longValue, "NavigatorTargetActivity", "longValue数值不对"); final TextView textview7 = findViewById(R.id.textview7); textview7.setText("接收Char类型的值:" + charValue); + require('c' == charValue, "NavigatorTargetActivity", "charValue数值不对"); final TextView textview8 = findViewById(R.id.textview8); textview8.setText("接收double类型的值(key与关键字同名情况):" + doubleValue); + require(3.14159265358972 == doubleValue, "NavigatorTargetActivity", "doubleValue数值不对"); final TextView textview9 = findViewById(R.id.textview9); textview9.setText("接收float类型的值:" + floatValue); + require(3.1415927F == floatValue, "NavigatorTargetActivity", "floatValue数值不对"); final TextView textview10 = findViewById(R.id.textview10); if (serializableBean != null) { textview10.setText("接收 SerializableObject 的值:" + serializableBean.hello); + require("helloField".equals(serializableBean.hello), "NavigatorTargetActivity", "serializableBean.hello数值不对"); } final TextView textview11 = findViewById(R.id.textview11); if (parcelableBean != null) { textview11.setText("接收 ParcelableObject 的值:" + parcelableBean.hello); + require("helloField".equals(parcelableBean.hello), "NavigatorTargetActivity", "parcelableBean.hello数值不对"); } if (button1 != null) { diff --git a/app/src/main/java/com/therouter/app/navigator/NavigatorTargetActivity2.java b/app/src/main/java/com/therouter/app/navigator/NavigatorTargetActivity2.java index 2be29f28..6fdb48ae 100644 --- a/app/src/main/java/com/therouter/app/navigator/NavigatorTargetActivity2.java +++ b/app/src/main/java/com/therouter/app/navigator/NavigatorTargetActivity2.java @@ -1,5 +1,6 @@ package com.therouter.app.navigator; +import static com.therouter.ExtensionKt.require; import static com.therouter.app.KotlinPathIndex.Test.HOME2; import android.os.Bundle; @@ -29,6 +30,7 @@ protected void onCreate(Bundle savedInstanceState) { textView.setText("子类 @Autowired 数据:" + stringChildClassField); if (stringChildClassFields != null) { textView.append("\n stringChildClassFields: " + stringChildClassFields.get(0).get(0)); + require("stringChildClassFields".equals(stringChildClassFields.get(0).get(0)), "NavigatorTargetActivity", "stringChildClassFields数值不对"); } } } diff --git a/app/src/main/java/com/therouter/app/navigator/NavigatorTestActivity.java b/app/src/main/java/com/therouter/app/navigator/NavigatorTestActivity.java index 12aff772..b7ca90d0 100644 --- a/app/src/main/java/com/therouter/app/navigator/NavigatorTestActivity.java +++ b/app/src/main/java/com/therouter/app/navigator/NavigatorTestActivity.java @@ -35,8 +35,9 @@ public class NavigatorTestActivity extends AppCompatActivity { protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.navigator); - setTitle("导航测试用例"); + setTitle("页面导航跳转测试用例"); // @Autowired 注入,这一行应该写在BaseActivity中更好 + // 如果用到了onNewIntent(),也需要调用这一行,并且在调用前需要将新intent 重新set一遍 TheRouter.inject(this); InternalBeanTest.RowBean bean = new InternalBeanTest.RowBean();