Android MVC框架 - Baymax

Android MVC框架 - Baymax

优点1:再也不用管AndroidManifest.xml这个烦人的家伙了。
优点2:你一定要相信注解是多么的高效。
优点3:Controller把业务跟UI分离;熟悉Spring的同学可能注意到了,这里的Controller就是从Spring模仿过来的。但用法跟Spring完全不一样。
       网络层已经封装好,你只管专心处理你的业务以及交互。
优点4:提供一个高效超好用的反射工具类,如果你对Hook或者说java反射感兴趣的话,该类可以帮你大忙。
优点5:提供一个View选择器工具,你再也不用写findViewById了。

项目地址:https://github.com/xuehuiniaoyu/Baymax



Android MVC框架 - Baymax




--------------------------------------------------------------------------------------------------------------------------------

Gradle 方式把框架集成到项目

1.Add it in your root build.gradle at the end of repositories (添加maven仓库到根目录下的build.gradle):

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

2.Add the dependency(添加依赖到app下的build.gradle)

dependencies {
    ...
    compile 'com.github.xuehuiniaoyu:Baymax:v1.2'
}

--------------------------------------------------------------------------------------------------------------------------------

Maven 方式把框架继承到项目

1.
<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

2.
<dependency>
    <groupId>com.github.xuehuiniaoyu</groupId>
    <artifactId>Baymax</artifactId>
    <version>v1.2</version>
</dependency>

--------------------------------------------------------------------------------------------------------------------------------

首先你要继承BaymaxApplication然后在AndroidManifest.xml中配置

public class ExampleApplication extends BaymaxApplication {
    @Override
    public void onCreate() {
        super.onCreate();
        Baymax.single().setAnnotationsPackage("com.disney4a.baymax_example.app").play();
    }
}

com.disney4a.baymax_example.app 是注解所在的包

--------------------------------------------------------------------------------------------------------------------------------


接下来就可以完美使用了!


--------------------------------------------------------------------------------------------------------------------------------



Activity的使用:

@Tag_Activity(name = "test-activity")
public class TestActivity extends BaymaxCompatActivity {
    ...
}

打开Actiity

Baymax.single().activity("test-activity").start();



--------------------------------------------------------------------------------------------------------------------------------



Controller的使用:

@Tag_Controller(webSite = "http://www.baidu.com")
public class TestController {

    @Tag_Controller.Path(name = "getBaidyContent")
    @Tag_Http
    public void baidu(Correspondents correspondents, final TextView textView) {
    correspondents.setExpectation(new HttpExpectation() {
            @Override
            public void onRepay(HttpRepay repay) {
                try {
                    final String result = System.currentTimeMillis()+" - "+repay.getResponse().body().string();
                    textView.post(new Runnable() {
                        @Override
                        public void run() {
                            textView.setText(result);
                        }
                    });
                } catch (Exception e) {

                }
            }
        });
        correspondents.go();
    }

}

执行Controller中的baidu方法:

TextView baiduResult;
Baymax.single().execute("getBaidyContent", baiduResult);

correspondents参数为自动创建,只要通过Path注解的方法都必须保证第一个参数为Correspondents或Correspondents的子类型。
你不用管这个对象是怎么来的,你只需要定义它的类型,框架会帮你创建这个对象。

除了correspondents之外的其他参数都要在execute方法执行的时候传递进来。