All Projects → mzule → Activityrouter

mzule / Activityrouter

Licence: apache-2.0
Router activities and methods with url for android

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Activityrouter

http-connection-lifecycle
Complete and detailed explanation of HTTP connection lifecycle
Stars: ✭ 43 (-98.47%)
Mutual labels:  router
Ddnsto
DDNSTO 文档以及问题反馈。
Stars: ✭ 255 (-90.93%)
Mutual labels:  router
Muxie
Muxie is a modern, fast and light HTTP multiplexer for Go. Fully compatible with the http.Handler interface. Written for everyone.
Stars: ✭ 257 (-90.86%)
Mutual labels:  router
router
Router is a request matcher and URL generator
Stars: ✭ 38 (-98.65%)
Mutual labels:  router
box-appServer
The Staff-Manager App Server for Enterprise Token Safe BOX
Stars: ✭ 22 (-99.22%)
Mutual labels:  router
Zen
zen is a elegant and lightweight web framework for Go
Stars: ✭ 257 (-90.86%)
Mutual labels:  router
NoCRouter
RTL Network-on-Chip Router Design in SystemVerilog by Andrea Galimberti, Filippo Testa and Alberto Zeni
Stars: ✭ 39 (-98.61%)
Mutual labels:  router
Curi
A JavaScript router for single-page applications
Stars: ✭ 262 (-90.68%)
Mutual labels:  router
Franxx
A vanilla JavaScript router that works everywhere.
Stars: ✭ 255 (-90.93%)
Mutual labels:  router
Found Relay
Relay integration for Found
Stars: ✭ 258 (-90.82%)
Mutual labels:  router
networking-icons
Repo containing various networking icons including routers, switches, servers, firewalls, load balancers and more. Icons are provided in png and svg formats.
Stars: ✭ 61 (-97.83%)
Mutual labels:  router
saffron-php
High performance PHP router
Stars: ✭ 37 (-98.68%)
Mutual labels:  router
Asuswrt Merlin.ng
Third party firmware for Asus routers (newer codebase)
Stars: ✭ 3,400 (+20.95%)
Mutual labels:  router
browser
Routing and Navigation for browser apps
Stars: ✭ 31 (-98.9%)
Mutual labels:  router
Hybrid Navigation
React Native Navigation that supports seamless navigation between Native and React.
Stars: ✭ 258 (-90.82%)
Mutual labels:  router
pi-ap
Raspberry Pi Access Point: This repo automates the configuration of hostapd, dnsmasq, dhcpcd & wpa_supplicant to transform a Pi into a wireless AP. Requirements: a Pi, an Ethernet cable and a DHCP-enabled port on a router with a 'net connection or a switch connected to this router.
Stars: ✭ 69 (-97.55%)
Mutual labels:  router
Hyperapp Router
Declarative routing for Hyperapp V1 using the History API.
Stars: ✭ 256 (-90.89%)
Mutual labels:  router
Frontexpress
An Express.js-Style router for the front-end
Stars: ✭ 263 (-90.64%)
Mutual labels:  router
Vedetta
OpenBSD Router Boilerplate
Stars: ✭ 260 (-90.75%)
Mutual labels:  router
T Mvp
Android AOP Architecture by Apt, AspectJ, Javassisit, based on Realm+Databinding+MVP+Retrofit+Rxjava2
Stars: ✭ 2,740 (-2.53%)
Mutual labels:  router

ActivityRouter

English README.md here

功能

支持给Activity定义 URL,这样可以通过 URL 跳转到Activity,支持在浏览器以及 app 中跳入。

image

image

集成

1. 添加引用

请根据项目的历史情况选择合适的集成方式

1.1 annotaitonProcessor 方式

dependencies {
    compile 'com.github.mzule.activityrouter:activityrouter:1.2.2'
    annotationProcessor 'com.github.mzule.activityrouter:compiler:1.1.7'
}

1.2 apt 方式

根目录 build.gradle

buildscript {
  dependencies {
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
  }
}

项目 app/build.gradle

apply plugin: 'android-apt'

dependencies {
    compile 'com.github.mzule.activityrouter:activityrouter:1.2.2'
    apt 'com.github.mzule.activityrouter:compiler:1.1.7'
}

2. 集成

AndroidManifest.xml配置

<activity
    android:name="com.github.mzule.activityrouter.router.RouterActivity"
    android:theme="@android:style/Theme.NoDisplay">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="mzule" /><!--改成自己的scheme-->
    </intent-filter>
</activity>

在需要配置的Activity上添加注解

@Router("main")
public class MainActivity extends Activity {
	...
}

这样就可以通过mzule://main来打开MainActivity了。

进阶

支持配置多个地址

@Router({"main", "root"})

mzule://mainmzule://root都可以访问到同一个Activity

支持获取 url 中?传递的参数

@Router("main")

上面的配置,可以通过mzule://main?color=0xff878798&name=you+are+best来传递参数,在MainActivity#onCreate中通过getIntent().getStringExtra("name")的方式来获取参数,所有的参数默认为String类型,但是可以通过配置指定参数类型,后面会介绍。

支持在 path 中定义参数

@Router("main/:color")

通过:color的方式定义参数,参数名为color,访问mzule://main/0xff878798,可以在MainActivity#onCreate通过getIntent().getStringExtra("color")获取到 color 的值0xff878798

支持多级 path 参数

@Router("user/:userId/:topicId/:commentId")

@Router("user/:userId/topic/:topicId/comment/:commentId")

上面两种方式都是被支持的,分别定义了三个参数,userId,topicId,commentId

支持指定参数类型

@Router(value = "main/:color", intParams = "color")

这样指定了参数color的类型为int,在MainActivity#onCreate获取 color 可以通过getIntent().getIntExtra("color", 0)来获取。支持的参数类型有int,long,short,byte,char,float,double,boolean,默认不指定则为String类型。

支持优先适配

@Router("user/:userId")
public class UserActivity extends Activity {
	...
}

@Router("user/statistics")
public class UserStatisticsActivity extends Activity {
	...
}

假设有上面两个配置,

不支持优先适配的情况下,mzule://user/statistics可能会适配到@Router("user/:userId"),并且userId=statistics

支持优先适配,意味着,mzule://user/statistics会直接适配到@Router("user/statistics"),不会适配前一个@Router("user/:userId")

支持 Callback

public class App extends Application implements RouterCallbackProvider {
    @Override
    public RouterCallback provideRouterCallback() {
        return new SimpleRouterCallback() {
            @Override
            public boolean beforeOpen(Context context, Uri uri) {
                context.startActivity(new Intent(context, LaunchActivity.class));
                // 是否拦截,true 拦截,false 不拦截
                return false;
            }

            @Override
            public void afterOpen(Context context, Uri uri) {
            }

            @Override
            public void notFound(Context context, Uri uri) {
                context.startActivity(new Intent(context, NotFoundActivity.class));
            }
            
            @Override
            public void error(Context context, Uri uri, Throwable e) {
                context.startActivity(ErrorStackActivity.makeIntent(context, uri, e));
            }
        };
    }
}

Application中实现RouterCallbackProvider接口,通过provideRouterCallback()方法提供RouterCallback,具体 API 如上。

支持 Http(s) 协议

@Router({"http://mzule.com/main", "main"})

AndroidManifest.xml

<activity
    android:name="com.github.mzule.activityrouter.router.RouterActivity"
    android:theme="@android:style/Theme.NoDisplay">
    ...
    <intent-filter>
    	<action android:name="android.intent.action.VIEW" />
    	<category android:name="android.intent.category.DEFAULT" />
    	<category android:name="android.intent.category.BROWSABLE" />
    	<data android:scheme="http" android:host="mzule.com" />
	</intent-filter>
</activity>

这样,http://mzule.com/mainmzule://main都可以映射到同一个 Activity,值得注意的是,在@Router中声明http协议地址时,需要写全称。

支持参数 transfer

@Router(value = "item", longParams = "id", transfer = "id=>itemId")

这里通过transfer = "id=>itemId"的方式,设定了 url 中名称为id的参数会被改名成itemId放到参数Bundle中,类型为long. 值得注意的是,这里,通过longParams = "id"或者longParams = "itemId"都可以设置参数类型为long.

支持应用内调用

Routers.open(context, "mzule://main/0xff878798")
Routers.open(context, Uri.parse("mzule://main/0xff878798"))
Routers.openForResult(activity, "mzule://main/0xff878798", REQUEST_CODE);
Routers.openForResult(activity, Uri.parse("mzule://main/0xff878798"), REQUEST_CODE);
// 获取 Intent
Intent intent = Routers.resolve(context, "mzule://main/0xff878798")

通过Routers.open(Context, String)或者Routers.open(Context, Uri)可以直接在应用内打开对应的 Activity,不去要经过 RouterActivity 跳转,效率更高。

支持获取原始 url 信息

getIntent().getStringExtra(Routers.KEY_RAW_URL);

支持通过 url 调用方法

@Router("logout")
public static void logout(Context context, Bundle bundle) {
}

在任意参数为 Context 和 Bundle 的静态公共方法上, 通过 @Router 标记即可定义方法的 url. @Router 使用方式与上述一致。

支持多模块

  • 每个包含 activity 的 module 都要添加 apt 依赖
  • 每个 module(包含主项目) 都要添加一个 @Module(name) 的注解在任意类上面,name 是项目的名称
  • 主项目要添加一个 @Modules({name0, name1, name2}) 的注解,指定所有的 module 名称集合

混淆配置

-keep class com.github.mzule.activityrouter.router.** { *; }

许可

Apache License 2.0

联系我

任何相关问题都可以通过以下方式联系我。

  1. 提 issue
  2. 新浪微博 http://weibo.com/mzule
  3. 个人博客 https://mzule.github.io/
  4. 邮件 "mzule".concat("4j").concat("@").concat("gmail.com")
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].