All Projects → Zane96 → Easyrouter

Zane96 / Easyrouter

Licence: apache-2.0
A simple android framework used to route activity or action with url.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Easyrouter

aspectgo
Aspect-Oriented Programming framework for Go
Stars: ✭ 62 (-62.2%)
Mutual labels:  hook, aop
Beike AspectD
Flutter AOP framework.(Flutter面向切面库, 最新适配Flutter v2.5.3, null-safety)
Stars: ✭ 39 (-76.22%)
Mutual labels:  hook, aop
Pine
Dynamic java method hook framework on ART.
Stars: ✭ 171 (+4.27%)
Mutual labels:  hook, aop
T Mvp
Android AOP Architecture by Apt, AspectJ, Javassisit, based on Realm+Databinding+MVP+Retrofit+Rxjava2
Stars: ✭ 2,740 (+1570.73%)
Mutual labels:  router, aop
Virtualxposed
A simple app to use Xposed without root, unlock the bootloader or modify system image, etc.
Stars: ✭ 12,648 (+7612.2%)
Mutual labels:  hook, aop
Sandhook
Android ART Hook/Native Inline Hook/Single Instruction Hook - support 4.4 - 11.0 32/64 bit - Xposed API Compat
Stars: ✭ 1,172 (+614.63%)
Mutual labels:  hook, aop
use-react-router-breadcrumbs
tiny, flexible, hook for rendering route breadcrumbs with react-router v6
Stars: ✭ 170 (+3.66%)
Mutual labels:  hook, router
Epic
Dynamic java method AOP hook for Android(continution of Dexposed on ART), Supporting 5.0~11
Stars: ✭ 3,434 (+1993.9%)
Mutual labels:  hook, aop
Stinger
Stinger is a high-efficiency library with great compatibility, for aop in Objective-C, using libffi instead of Objective-C message forwarding. It is 20+ times faster than the Aspects, from message-sending to Aspect-oriented code ends.
Stars: ✭ 845 (+415.24%)
Mutual labels:  hook, aop
Koatty
Koa2 + Typescript = Koatty. Use Typescript's decorator implement IOC and AOP.
Stars: ✭ 67 (-59.15%)
Mutual labels:  router, aop
Swifthook
A library to hook methods in Swift and Objective-C.
Stars: ✭ 93 (-43.29%)
Mutual labels:  hook, aop
Wechatpc
PC微信hook源码,PC微信注入,逆向编程,可以制作微信机器人玩玩,仅供学习,请不要用于商业、违法途径,本人不对此源码造成的违法负责!
Stars: ✭ 154 (-6.1%)
Mutual labels:  hook
Pyhooked
Pure Python hotkey hook, with thanks to pyHook and pyhk
Stars: ✭ 150 (-8.54%)
Mutual labels:  hook
Scene Router
A complete scene routing library for react native
Stars: ✭ 149 (-9.15%)
Mutual labels:  router
Wxa
🖖 渐进式小程序开发框架。轻量级的渐进式小程序开发框架,专注于小程序原生开发,提供更好的工程化、代码复用能力,提高开发效率并改善开发体验。
Stars: ✭ 149 (-9.15%)
Mutual labels:  aop
Minrouter
a micro middleware router for isomorphic javaScript web apps
Stars: ✭ 159 (-3.05%)
Mutual labels:  router
Redux Tower
Saga powered routing engine for Redux app.
Stars: ✭ 155 (-5.49%)
Mutual labels:  router
Plmcodetemplate
给部门制定的代码框架模板
Stars: ✭ 1,871 (+1040.85%)
Mutual labels:  aop
React Universal Hooks
🎉 React Universal Hooks : just use****** everywhere (Functional or Class Component). Support React DevTools!
Stars: ✭ 148 (-9.76%)
Mutual labels:  hook
Router
Router —— A substitute good of EventBus similar implemented by dynamic proxy
Stars: ✭ 147 (-10.37%)
Mutual labels:  router

EasyRouter

欢迎加入Android技术交流群,群号码:577953847

EasyRouter是一个简易的使用字符串进行Activity,Browser跳转的路由框架,并支持组件化开发。

Features

  • EasyRouter实现了通过字符串进行Activity之间跳转路由,通过APT在编译器实现路由表的构建,劫持了startActivity()进行动态路由
  • EasyRouter实现了Activity之间跳转,返回时的数据自动注入,完全屏蔽了原生的一套繁琐API
  • EasyRouter实现了通过字符串进程Browser的路由跳转
  • EasyRouter支持更换路由跳转时数据序列化的解析器,默认为Gson,可以通过EasyRouterSet进行更换
  • EasyRouter劫持了onActivityResult(),并将其改为接口回调
  • EasyRouter通过transform+ASM实现了一个gradle插件来支持组件化开发

Usage

1.在Activity中自定义URL标识符,目前只支持单一的URL标识,URL的Scheme均为activity://

@Route("activity://main")
public class MainActivity extends AppCompatActivity {
}

2.在Application中进行初始化

EasyRouter.init(this);

3.跳转

  • Activity之间无参数传递跳转
Message message = new MessageBuilder().setAddress("activity://two").build();
EasyRouter.route(MainActivity.this, message);
  • Activity之间有参数传递跳转
Message message = new MessageBuilder()
                        .setAddress("activity://two")
                        .addParam("data", "haha", String.class)
                        .addParam("person", new Person(21, "Zane"), Person.class)
                        .build();
EasyRouter.route(MainActivity.this, message);

被启动Activity需要用@Param标记参数变量

@Route("activity://two")
public class ActivityTwo extends AppCompatActivity{

    @Param("data")
    public String data;
    @Param("person")
    public Person person;
}
  • Activity需要回调的启动(startActivityForResult())
Message message = new MessageBuilder()
                               .setAddress("activity://two")
                               .addParam("data", "haha", String.class)
                               .addParam("person", new Person(21, "Zane"), Person.class)
                               .build();
EasyRouter.routeForResult(MainActivity.this, message, new OnActivityResultListener() {
          @Override
          public void onActivityResult(int resultCode, Intent data) {
                //dosomething
          }
});

如果有返回的数据,需要通过@Result标记返回参数变量

@Route("activity://main")
public class MainActivity extends AppCompatActivity {

    @Result("result_three")
    public String resultThree;
    @Result("result_two")
    public String resultTwo;
}
  • Activity的setResult()
EasyRouter.setResult(ActivityTwo.this, 0, new MessageBuilder()
                                                   .addParam("result_two", "data from two", String.class)
                                                   .build());
finish();
  • Web页面跳转
EasyRouter.route(MainActivity.this, new MessageBuilder()
                                             .setAddress("http://xzane.cc")
                                             .build());
  • 更改数据序列化的工具

首先需要实现一个序列化工具的工厂类,可以参考框架中的GsonConvertFactory

EasyRouterSet.setConverterFactory(GsonConventerFactory.creat());

Principle

  • 使用动态代理生成Instrumentation代理类并通过反射替换ActivityThread中的Instrumentation变量,劫持execStartActivity()方法达到动态查找路由表并进行跳转的效果
  • 所有的参数注入代码以及路由表的代码生成均通过APT在编译期完成
  • onActivityResult方法的劫持是通过生成无View的Fragment达到的,借鉴了RxPermission
  • 通过registerActivityLifecycleCallbacks(Application.ActivityLifecycleCallbacks callback)去劫持所有Activity的onCreat()方法
  • 编译期通过transform获取编译产物,使用ASM进行AOP操作融合application和library的路由表

Dependency

  • 在Project build.gradle中
allprojects {
 repositories {
    maven { url "https://jitpack.io" }
 }
}
  • 在Application build.gradle中
dependencies {
    compile 'com.github.Zane96.EasyRouter:router:v1.1.1'
    annotationProcessor 'com.github.Zane96.EasyRouter:easyrouter-compiler:v1.1.1'
}
  • 如果您希望支持Android组件化开发,那么还需要在Project的build.gradle中添加如下依赖:
buildscript {
    dependencies {
        classpath 'com.zane:easyrouterMerge:1.0.0'
    }
}

并在Application和Library的build.gradle中均添加如下插件:

apply plugin: 'me.zane.easyrouter-merge'

TODO

  • 返回数据,自动注入
  • 请求报文实体类封装,Builder类生成URL,头部,数据body
  • 支持组件化开发
  • 跳转时候的参数应该不依赖key的值,要自动或者手动注入
  • 地址做成多个

License

Copyright 2017 Zane

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
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].