From 330702f0698e581bc94feba2956101297cffc014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A3=E7=BA=AC?= Date: Tue, 21 Mar 2017 20:54:46 +0800 Subject: [PATCH] Add fragment support. --- README.md | 4 ++++ README_CN.md | 4 ++++ .../android/arouter/demo/BlankFragment.java | 2 ++ .../alibaba/android/arouter/demo/MainActivity.java | 5 +++++ app/src/main/res/layout/activity_main.xml | 7 +++++++ .../android/arouter/core/LogisticsCenter.java | 2 ++ .../alibaba/android/arouter/launcher/_ARouter.java | 14 ++++++++++++++ .../arouter/compiler/processor/RouteProcessor.java | 8 ++++++-- gradle.properties | 4 ++-- 9 files changed, 46 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 622e1e7a..0c65aa9a 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ 8. 支持用户指定全局降级与局部降级策略 9. 页面、拦截器、服务等组件均自动注册到框架 10. 支持多种方式配置转场动画 +11. 支持获取Fragment #### 二、典型应用 1. 从外部URL映射到内部页面,以及参数传递与解析 @@ -298,6 +299,9 @@ .withFlags(); .navigation(); + // 获取Fragment + Fragment fragment = (Fragment) ARouter.getInstance().build("/test/fragment").navigation(); + // 对象传递 ARouter.getInstance() .withObject("key", new TestObj("Jack", "Rose")) diff --git a/README_CN.md b/README_CN.md index 7c097f9a..a840b9b2 100644 --- a/README_CN.md +++ b/README_CN.md @@ -27,6 +27,7 @@ 8. 支持用户指定全局降级与局部降级策略 9. 页面、拦截器、服务等组件均自动注册到框架 10. 支持多种方式配置转场动画 +11. 支持获取Fragment #### 二、典型应用 1. 从外部URL映射到内部页面,以及参数传递与解析 @@ -300,6 +301,9 @@ ARouter.getInstance() .withObject("key", new TestObj("Jack", "Rose")) .navigation(); + + // 获取Fragment + Fragment fragment = (Fragment) ARouter.getInstance().build("/test/fragment").navigation(); // 觉得接口不够多,可以直接拿出Bundle赋值 ARouter.getInstance() diff --git a/app/src/main/java/com/alibaba/android/arouter/demo/BlankFragment.java b/app/src/main/java/com/alibaba/android/arouter/demo/BlankFragment.java index 88f11a36..8b64afbf 100644 --- a/app/src/main/java/com/alibaba/android/arouter/demo/BlankFragment.java +++ b/app/src/main/java/com/alibaba/android/arouter/demo/BlankFragment.java @@ -9,10 +9,12 @@ import android.widget.TextView; import com.alibaba.android.arouter.facade.annotation.Autowired; +import com.alibaba.android.arouter.facade.annotation.Route; /** * A simple {@link Fragment} subclass. */ +@Route(path = "/test/fragment") public class BlankFragment extends Fragment { @Autowired diff --git a/app/src/main/java/com/alibaba/android/arouter/demo/MainActivity.java b/app/src/main/java/com/alibaba/android/arouter/demo/MainActivity.java index 2d1cce8d..cbc7ae93 100644 --- a/app/src/main/java/com/alibaba/android/arouter/demo/MainActivity.java +++ b/app/src/main/java/com/alibaba/android/arouter/demo/MainActivity.java @@ -5,6 +5,7 @@ import android.os.Build; import android.os.Bundle; import android.support.v4.app.ActivityOptionsCompat; +import android.support.v4.app.Fragment; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; @@ -151,6 +152,10 @@ public void onLost(Postcard postcard) { .build("/test/activity2") .navigation(this, 666); break; + case R.id.getFragment: + Fragment fragment = (Fragment) ARouter.getInstance().build("/test/fragment").navigation(); + Toast.makeText(this, "找到Fragment:" + fragment.toString(), Toast.LENGTH_SHORT).show(); + break; default: break; } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 82b64231..52a86809 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -88,6 +88,13 @@ android:onClick="onClick" android:text="跳转ForResult" /> +