str);
14 | }
15 |
--------------------------------------------------------------------------------
/modules_services_api/src/main/java/com/beyondxia/message/export/IMessage.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.message.export;
2 |
3 | import android.content.Context;
4 | import java.lang.String;
5 |
6 | /**
7 | * Auto generate by apt, don't edit */
8 | public interface IMessage {
9 | String SERVICE_NAME = "com.beyondxia.message.export.IMessage";
10 |
11 | String getMessage(String msg);
12 |
13 | void nav2B2Activity(Context context);
14 | }
15 |
--------------------------------------------------------------------------------
/modules_services_api/src/main/java/com/beyondxia/bussiness1/export/IDashboard.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.bussiness1.export;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import java.lang.String;
6 |
7 | /**
8 | * Auto generate by apt, don't edit */
9 | public interface IDashboard {
10 | String SERVICE_NAME = "com.beyondxia.bussiness1.export.IDashboard";
11 |
12 | View getDashboardView(Context context);
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_showfragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/repos/com/beyondxia/modules/plugin_dev/maven-metadata.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | com.beyondxia.modules
4 | plugin_dev
5 |
6 | 1.0.4
7 |
8 | 1.0.3
9 | 1.0.4
10 |
11 | 20210304060103
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/modules-api/src/main/java/com/beyondxia/modules/ILifeCycle.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.modules;
2 |
3 | /**
4 | * Created by xiaojunxia on 2018/9/25.
5 | */
6 |
7 | public interface ILifeCycle {
8 | // public abstract void onInit();
9 |
10 | /**
11 | *
12 | * we suggest you write code here in a new thread, especially it wait a long time
13 | */
14 | public abstract void onInstalled();
15 | public abstract void onUninstalled();
16 | }
17 |
--------------------------------------------------------------------------------
/modules-annotation/src/main/java/com/beyondxia/annotation/ExportMethod.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Create by ChenWei on 2018/8/24 15:42
10 | **/
11 | @Retention(RetentionPolicy.SOURCE)
12 | @Target({ElementType.METHOD})
13 | public @interface ExportMethod {
14 | }
15 |
--------------------------------------------------------------------------------
/repo_plugin.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven-publish'
2 |
3 | publishing {
4 | publications {
5 | mavenJava(MavenPublication) {
6 |
7 | groupId 'com.beyondxia.modules'
8 | artifactId 'plugin_dev'
9 | version '1.0.4'
10 |
11 | from components.java
12 |
13 | }
14 | }
15 | }
16 |
17 | publishing {
18 | repositories {
19 | maven {
20 | url uri('../repos')
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/repo_annotation.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven-publish'
2 |
3 | publishing {
4 | publications {
5 | mavenJava(MavenPublication) {
6 |
7 | groupId 'com.beyondxia.modules'
8 | artifactId 'annotation_dev'
9 | version '1.0.1'
10 |
11 | from components.java
12 |
13 | }
14 | }
15 | }
16 |
17 | publishing {
18 | repositories {
19 | maven {
20 | url uri('../repos')
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/repo_compiler.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven-publish'
2 |
3 | publishing {
4 | publications {
5 | mavenJava(MavenPublication) {
6 |
7 | groupId 'com.beyondxia.modules'
8 | artifactId 'compiler_dev'
9 | version '1.0.1'
10 |
11 | from components.java
12 |
13 | }
14 | }
15 | }
16 |
17 | publishing {
18 | repositories {
19 | maven {
20 | url uri('../repos')
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/beyondxia/host/MyApp.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.host;
2 |
3 | import android.app.Application;
4 |
5 | import com.beyondxia.modules.BuildConfig;
6 | import com.beyondxia.modules.ServiceHelper;
7 |
8 | /**
9 | * Created by xiaojunxia on 2018/9/26.
10 | */
11 |
12 | public class MyApp extends Application {
13 | @Override
14 | public void onCreate() {
15 | super.onCreate();
16 | ServiceHelper.init(this, BuildConfig.DEBUG,true);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/modules-compiler/src/main/java/com/beyondxia/compiler/utils/Constants.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.compiler.utils;
2 |
3 | /**
4 | * Create by ChenWei on 2018/8/27 14:21
5 | **/
6 | public interface Constants {
7 |
8 | String REGISTER_PACKAGE_NAME = "com.beyondxia.modules_interface_library";
9 | String REGISTER_METHOD_NAME = "registerService";
10 | String MODULE_NAME = "moduleName";
11 |
12 | String I_REGISTER_SERVICE = "com.beyondxia.modules" + ".IRegisterService";
13 |
14 | }
--------------------------------------------------------------------------------
/repos/com/beyondxia/modules/annotation_dev/1.0.1/annotation_dev-1.0.1.pom:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | com.beyondxia.modules
6 | annotation_dev
7 | 1.0.1
8 |
9 |
--------------------------------------------------------------------------------
/business1/src/main/java/com/beyondxia/bussiness1/MyLogin.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.bussiness1;
2 |
3 | /**
4 | * Created by xiaojunxia on 2018/9/26.
5 | */
6 |
7 | public class MyLogin {
8 | public static boolean doLogin(String userName, String password) {
9 | if (userName.equals("chenwei") && password.equals("xiaxiaojun")) return true;
10 | return false;
11 | }
12 |
13 | public static String getUserName() {
14 | return "UserName:chenwei";
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/modules_services_api/src/main/java/com/pingan/my/MyMessageService.java:
--------------------------------------------------------------------------------
1 | package com.pingan.my;
2 | import com.beyondxia.modules.PAService;
3 | import com.beyondxia.modules.exception.NoServiceException;
4 |
5 | public abstract class MyMessageService extends PAService implements IMyMessage {
6 | public static IMyMessage get() {
7 | try{
8 | return getService(SERVICE_NAME);
9 | } catch (NoServiceException noServiceException) {
10 | noServiceException.printStackTrace();
11 | }
12 | return null;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/modules-api/src/main/java/com/beyondxia/modules/fetcher/NoCacheServiceFetcher.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.modules.fetcher;
2 |
3 | import com.beyondxia.modules.PAServiceEvn;
4 |
5 | /**
6 | * Create by ChenWei on 2018/8/23 16:27
7 | *
8 | * 无缓存方式, 不经常使用的Service
9 | **/
10 | public abstract class NoCacheServiceFetcher
11 | extends PAServiceEvn.ServiceFetcher implements ServiceFactory {
12 | @Override
13 | public final Object getService(PAServiceEvn ctx) {
14 | return createService();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/beyondxia/host/export/TestServiceImpl1.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.host.export;
2 |
3 | import com.beyondxia.annotation.ExportMethod;
4 | import com.beyondxia.annotation.ExportService;
5 |
6 | /**
7 | * Create by ChenWei on 2018/8/27 14:04
8 | **/
9 | @ExportService(moduleName = "app")
10 | public class TestServiceImpl1 {
11 |
12 | @ExportMethod
13 | public void m1(int a, String s) {
14 |
15 | }
16 |
17 | // @ExportMethod
18 | public int m2() {
19 | return 0;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/modules-api/src/main/java/com/beyondxia/modules/fetcher/CacheServiceFetcher.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.modules.fetcher;
2 |
3 | import com.beyondxia.modules.PAServiceEvn;
4 |
5 | /**
6 | * Create by ChenWei on 2018/8/23 16:12
7 | *
8 | * 有缓存方式, 频繁使用的Service
9 | **/
10 | public abstract class CacheServiceFetcher extends PAServiceEvn.ServiceFetcher
11 | implements ServiceFactory {
12 |
13 | @Override
14 | public final Object createService(PAServiceEvn ctx) {
15 | return createService();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/modules_services_api/src/main/java/com/beyondxia/bussiness1/export/LoginService.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.bussiness1.export;
2 | import com.beyondxia.modules.PAService;
3 | import com.beyondxia.modules.exception.NoServiceException;
4 |
5 | public abstract class LoginService extends PAService implements ILogin {
6 | public static ILogin get() {
7 | try{
8 | return getService(SERVICE_NAME);
9 | } catch (NoServiceException noServiceException) {
10 | noServiceException.printStackTrace();
11 | }
12 | return null;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/modules_services_api/src/main/java/com/beyondxia/message/export/MessageService.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.message.export;
2 | import com.beyondxia.modules.PAService;
3 | import com.beyondxia.modules.exception.NoServiceException;
4 |
5 | public abstract class MessageService extends PAService implements IMessage {
6 | public static IMessage get() {
7 | try{
8 | return getService(SERVICE_NAME);
9 | } catch (NoServiceException noServiceException) {
10 | noServiceException.printStackTrace();
11 | }
12 | return null;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/modules-api/src/main/java/com/beyondxia/modules/PAServiceConfig.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.modules;
2 |
3 | /**
4 | * Create by ChenWei on 2018/8/31 10:17
5 | **/
6 | public class PAServiceConfig {
7 |
8 | private volatile static Boolean isDebug = true;
9 |
10 | public static long maxLifeCycleInitWarningTime = 300;
11 |
12 | public static Boolean getIsDebug() {
13 | return isDebug;
14 | }
15 |
16 | public static void setIsDebug(Boolean isDebug) {
17 | PAServiceConfig.isDebug = isDebug;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/modules_services_api/src/main/java/com/beyondxia/host/export/HostExportService.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.host.export;
2 | import com.beyondxia.modules.PAService;
3 | import com.beyondxia.modules.exception.NoServiceException;
4 |
5 | public abstract class HostExportService extends PAService implements IHostExport {
6 | public static IHostExport get() {
7 | try{
8 | return getService(SERVICE_NAME);
9 | } catch (NoServiceException noServiceException) {
10 | noServiceException.printStackTrace();
11 | }
12 | return null;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/modules-api/src/main/java/com/beyondxia/modules/fetcher/SingleInstanceServiceFetcher.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.modules.fetcher;
2 |
3 | import com.beyondxia.modules.PAServiceEvn;
4 |
5 | /**
6 | * Create by ChenWei on 2018/8/23 16:28
7 | *
8 | * 单例模式, 介于无缓存和有缓存之间
9 | **/
10 | public abstract class SingleInstanceServiceFetcher
11 | extends PAServiceEvn.StaticServiceFetcher implements ServiceFactory {
12 |
13 | @Override
14 | public final Object createStaticService() {
15 | return createService();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/modules_services_api/src/main/java/com/beyondxia/bussiness1/export/DashboardService.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.bussiness1.export;
2 | import com.beyondxia.modules.PAService;
3 | import com.beyondxia.modules.exception.NoServiceException;
4 |
5 | public abstract class DashboardService extends PAService implements IDashboard {
6 | public static IDashboard get() {
7 | try{
8 | return getService(SERVICE_NAME);
9 | } catch (NoServiceException noServiceException) {
10 | noServiceException.printStackTrace();
11 | }
12 | return null;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/modules_services_api/src/main/java/com/beyondxia/bussiness1/export/FragmentShowService.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.bussiness1.export;
2 | import com.beyondxia.modules.PAService;
3 | import com.beyondxia.modules.exception.NoServiceException;
4 |
5 | public abstract class FragmentShowService extends PAService implements IFragmentShow {
6 | public static IFragmentShow get() {
7 | try{
8 | return getService(SERVICE_NAME);
9 | } catch (NoServiceException noServiceException) {
10 | noServiceException.printStackTrace();
11 | }
12 | return null;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/modules_services_api/src/main/java/com/beyondxia/host/export/TestServiceImplService.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.host.export;
2 | import com.beyondxia.modules.PAService;
3 | import com.beyondxia.modules.exception.NoServiceException;
4 |
5 | public abstract class TestServiceImplService extends PAService implements ITestServiceImpl {
6 | public static ITestServiceImpl get() {
7 | try{
8 | return getService(SERVICE_NAME);
9 | } catch (NoServiceException noServiceException) {
10 | noServiceException.printStackTrace();
11 | }
12 | return null;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/modules_services_api/src/main/java/com/beyondxia/host/export/TestServiceImpl1Service.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.host.export;
2 | import com.beyondxia.modules.PAService;
3 | import com.beyondxia.modules.exception.NoServiceException;
4 |
5 | public abstract class TestServiceImpl1Service extends PAService implements ITestServiceImpl1 {
6 | public static ITestServiceImpl1 get() {
7 | try{
8 | return getService(SERVICE_NAME);
9 | } catch (NoServiceException noServiceException) {
10 | noServiceException.printStackTrace();
11 | }
12 | return null;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/other/business2/src/main/java/com/beyondxia/message/MessageModel.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.message;
2 |
3 | /**
4 | * Created by xiaojunxia on 2018/9/27.
5 | */
6 |
7 | public class MessageModel {
8 | // "userName","zhangsan"
9 | // "password", "pass"
10 | public String userName;
11 | public String password;
12 |
13 | @Override
14 | public String toString() {
15 | return "MessageModel{" +
16 | "userName='" + userName + '\'' +
17 | ", password='" + password + '\'' +
18 | '}';
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/business1/src/main/java/com/beyondxia/bussiness1/export/FragmentShow.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.bussiness1.export;
2 |
3 | import android.support.v4.app.Fragment;
4 |
5 | import com.beyondxia.annotation.ExportMethod;
6 | import com.beyondxia.annotation.ExportService;
7 | import com.beyondxia.bussiness1.fragment.SimpleFragment;
8 |
9 | /**
10 | * @author yuandunbin
11 | * @date 2018/9/29
12 | */
13 | @ExportService(moduleName = "business1")
14 | public class FragmentShow {
15 | @ExportMethod
16 | public Fragment getSimpleFragment(){
17 | return new SimpleFragment();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/modules_services_api/src/main/java/com/beyondxia/bussiness1/export/ILogin.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.bussiness1.export;
2 |
3 | import android.content.Context;
4 | import com.beyondxia.modules.BCDictionary;
5 | import java.lang.String;
6 |
7 | /**
8 | * Auto generate by apt, don't edit */
9 | public interface ILogin {
10 | String SERVICE_NAME = "com.beyondxia.bussiness1.export.ILogin";
11 |
12 | boolean doLogin(Context context, String userName, String password);
13 |
14 | String getUserName();
15 |
16 | BCDictionary getUserInfo();
17 |
18 | void nav2LoginActivity(Context context);
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/beyondxia/host/export/TestServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.host.export;
2 |
3 | import com.beyondxia.annotation.ExportMethod;
4 | import com.beyondxia.annotation.ExportService;
5 |
6 | import java.util.Map;
7 |
8 | /**
9 | * Create by ChenWei on 2018/8/27 10:11
10 | **/
11 | @ExportService(moduleName = "apptest",preload = true)
12 | public class TestServiceImpl {
13 |
14 | @ExportMethod
15 | public String t1(String a) {
16 | return "";
17 | }
18 |
19 | @ExportMethod
20 | public int t2(Map str) {
21 | return 0;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/modules-annotation/src/main/java/com/beyondxia/annotation/ExportService.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Create by ChenWei on 2018/8/30 08:59
10 | **/
11 | @Retention(RetentionPolicy.RUNTIME)
12 | @Target(ElementType.TYPE)
13 | public @interface ExportService {
14 | String moduleName() default "";
15 |
16 | // TODO should add the follow function here
17 | boolean preload() default false;
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/modules-plugin/src/main/groovy/com/beyondxia/plugin/PAServicePlugin.groovy:
--------------------------------------------------------------------------------
1 | package com.beyondxia.plugin
2 |
3 | import com.android.build.gradle.AppExtension
4 | import org.gradle.api.Plugin
5 | import org.gradle.api.Project
6 |
7 | class PAServicePlugin implements Plugin {
8 |
9 | @Override
10 | void apply(Project project) {
11 | project.extensions.create("modulesConfig", ConfigExtention)
12 | def android = project.extensions.findByType(AppExtension.class)
13 | if (android != null) {
14 | android.registerTransform(new PATransform(project))
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/modules-plugin/src/main/groovy/com/beyondxia/plugin/constant/ClassConstant.groovy:
--------------------------------------------------------------------------------
1 | package com.beyondxia.plugin.constant
2 |
3 | class ClassConstant {
4 |
5 | public static final String INIT_CLASS_FILE_NAME = "com/beyondxia/modules/ServiceHelper.class"
6 | public static final String INIT_CLASS_NAME = "com/beyondxia/modules/ServiceHelper"
7 | public static final String SERVICE_ROOT_PACKAGE = "com/beyondxia/modules_interface_library"
8 | public static final String SERVICE_INIT_METHOD = "pluginRegisterClassName"
9 | public static final String SERVICE_DO_REGISTER_METHOD = "pluginRegister"
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/beyondxia/host/export/HostExport.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.host.export;
2 |
3 | import com.beyondxia.annotation.ExportMethod;
4 | import com.beyondxia.annotation.ExportService;
5 |
6 | /**
7 | * Created by xiaojunxia on 2018/9/26.
8 | *
9 | * note: the export should not have super class
10 | */
11 | @ExportService(moduleName = "Host")
12 | public class HostExport {
13 | @ExportMethod
14 | public String getHostName() {
15 | return "Host APP Name";
16 | }
17 |
18 | // @ExportMethod
19 | // public String getHostName() {
20 | // return "Host APP Name";
21 | // }
22 | }
23 |
--------------------------------------------------------------------------------
/business1/src/main/java/com/beyondxia/bussiness1/export/Dashboard.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.bussiness1.export;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import com.beyondxia.annotation.ExportMethod;
7 | import com.beyondxia.annotation.ExportService;
8 | import com.beyondxia.bussiness1.view.DashboardView;
9 |
10 | /**
11 | * @author yuandunbin
12 | * @date 2018/9/29
13 | */
14 | @ExportService(moduleName = "business1")
15 | public class Dashboard {
16 | @ExportMethod
17 | public View getDashboardView(Context context) {
18 | return new DashboardView(context);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/business1/src/main/res/layout/stagger_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
15 |
16 |
--------------------------------------------------------------------------------
/modules-plugin/src/main/groovy/com/beyondxia/plugin/utils/SystemUtils.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.plugin.utils;
2 |
3 | /**
4 | * Create by ChenWei on 2018/10/23 17:37
5 | **/
6 | public class SystemUtils {
7 |
8 | public static boolean isWindows() {
9 | return System.getProperties().getProperty("os.name").toUpperCase().contains("WINDOWS");
10 | }
11 |
12 | public static String getPathByOs(String originPath) {
13 | if (originPath == null) {
14 | return "";
15 | }
16 | if (isWindows()) {
17 | return originPath.replace("/", "\\");
18 | }
19 | return originPath;
20 |
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/business1/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #52ce90
4 | #34b574
5 | #FF5722
6 | #FF9800
7 | #FFC107
8 | #3FB830
9 | #00BAED
10 | #263238
11 | #455A64
12 | #ECEFF1
13 | #00b4aa
14 |
15 |
--------------------------------------------------------------------------------
/modules-compiler/src/main/java/com/beyondxia/compiler/utils/SystemUtils.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.compiler.utils;
2 |
3 | /**
4 | * Create by ChenWei on 2018/10/23 17:37
5 | **/
6 | public class SystemUtils {
7 |
8 | public static boolean isWindows() {
9 | return System.getProperties().getProperty("os.name").toUpperCase().contains("WINDOWS");
10 | }
11 |
12 | public static String getPathByOs(String originPath) {
13 | if (originPath == null) {
14 | return "";
15 | }
16 | if (isWindows()) {
17 | return originPath.replace("/", "\\");
18 | }
19 | return originPath;
20 |
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/modules-api/src/main/java/com/beyondxia/modules/PAService.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.modules;
2 |
3 | import android.util.Log;
4 |
5 | import com.beyondxia.modules.exception.NoServiceException;
6 |
7 | /**
8 | * Create by ChenWei on 2018/8/23 15:40
9 | **/
10 | public abstract class PAService {
11 |
12 | protected static T getService(String name) throws NoServiceException {
13 | T t = (T) PAServiceEvn.getService(name);
14 | if (t == null) {
15 | String error = String.format("[=== can not find Service:%s ===]", name);
16 | Log.e("ServiceError", error);
17 | throw new NoServiceException(error);
18 | }
19 | return t;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/business1/src/main/res/layout/simple_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
12 |
17 |
18 |
--------------------------------------------------------------------------------
/business1/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/repos/com/beyondxia/modules/transform-plugin/maven-metadata.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | com.beyondxia.modules
4 | transform-plugin
5 |
6 | 1.3.11
7 |
8 | 1.1.2
9 | 1.1.5
10 | 1.2.3
11 | 1.2.5
12 | 1.2.18
13 | 1.2.20
14 | 1.3.5
15 | 1.3.7
16 | 1.3.8
17 | 1.3.9
18 | 1.3.11
19 |
20 | 20210304060104
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_showview.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
13 |
14 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/business1/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/modules-api/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/other/business2/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/modules_services_api/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/pingan/aptdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.pingan.aptdemo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.nmnet.aptdemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/beyondxia/host/ShowFragmentActivity.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.host;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.FragmentActivity;
6 | import android.support.v7.app.AppCompatActivity;
7 |
8 | import com.beyondxia.bussiness1.export.FragmentShowService;
9 | import com.beyondxia.modules.R;
10 |
11 | /**
12 | * @author yuandunbin
13 | * @date 2018/9/29
14 | */
15 | public class ShowFragmentActivity extends AppCompatActivity {
16 | @Override
17 | protected void onCreate(@Nullable Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_showfragment);
20 | getSupportFragmentManager()
21 | .beginTransaction()
22 | .add(R.id.fragment_container, FragmentShowService.get().getSimpleFragment())
23 | .commit();
24 |
25 | setTitle("HostApp");
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/business1/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Bussiness1
3 | Sign in
4 |
5 |
6 | Email
7 | Password (optional)
8 | Sign in or register
9 | Sign in
10 | This email address is invalid
11 | This password is too short
12 | This password is incorrect
13 | This field is required
14 | "Contacts permissions are needed for providing email
15 | completions."
16 |
17 |
18 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | LOCAL_MAVEN_ADDRESS=./repos
15 | devMode=false
16 | annotation_artifactId='annotation'
17 | annotation_version='1.0.3'
18 | plugin_artifactId='plugin'
19 | plugin_version='1.0.3'
--------------------------------------------------------------------------------
/other/business2/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 21
10 | targetSdkVersion 27
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | if (devMode.toBoolean()) {
31 | annotationProcessor 'com.beyondxia.modules:compiler_dev:1.0.1'
32 | } else {
33 | annotationProcessor 'com.beyondxia.modules:compiler:1.1.1'
34 | }
35 | implementation project(':modules_services_api')
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/beyondxia/host/ShowViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.host;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.widget.LinearLayout;
9 |
10 | import com.beyondxia.bussiness1.export.DashboardService;
11 | import com.beyondxia.modules.R;
12 |
13 | /**
14 | * @author yuandunbin
15 | * @date 2018/9/29
16 | */
17 | public class ShowViewActivity extends AppCompatActivity {
18 | @Override
19 | protected void onCreate(@Nullable Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_showview);
22 |
23 | setTitle("HostApp");
24 |
25 | View view = DashboardService.get().getDashboardView(this);
26 | ((LinearLayout) findViewById(R.id.add_view)).addView(view);
27 |
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/modules-api/src/main/java/com/beyondxia/modules/utils/thread/CancelableCountDownLatch.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.modules.utils.thread;
2 |
3 | import java.util.concurrent.CountDownLatch;
4 |
5 | /**
6 | * As its name.
7 | *
8 | * @author Alex Contact me.
9 | * @version 1.0
10 | * @since 16/8/29 15:48
11 | */
12 | public class CancelableCountDownLatch extends CountDownLatch {
13 | /**
14 | * Constructs a {@code CountDownLatch} initialized with the given count.
15 | *
16 | * @param count the number of times {@link #countDown} must be invoked
17 | * before threads can pass through {@link #await}
18 | * @throws IllegalArgumentException if {@code count} is negative
19 | */
20 | public CancelableCountDownLatch(int count) {
21 | super(count);
22 | }
23 |
24 | public void cancel() {
25 | while (getCount() > 0) {
26 | countDown();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/other/business2/src/main/java/com/beyondxia/message/export/Message.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.message.export;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 |
7 | import com.beyondxia.annotation.ExportMethod;
8 | import com.beyondxia.annotation.ExportService;
9 | import com.beyondxia.message.B2Activity;
10 |
11 | /**
12 | * Created by xiaojunxia on 2018/9/26.
13 | */
14 | @ExportService(moduleName = "business2")
15 | public class Message {
16 |
17 | @ExportMethod
18 | public String getMessage(String msg) {
19 | return "b2 message";
20 | }
21 |
22 | @ExportMethod
23 | public void nav2B2Activity(Context context) {
24 | if (context == null) return;
25 | Intent intent = new Intent(context, B2Activity.class);
26 | if (!(context instanceof Activity)) {
27 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
28 | }
29 | context.startActivity(intent);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/modules_services_api/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 |
6 | defaultConfig {
7 | minSdkVersion 21
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 |
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 |
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | lintOptions {
23 | abortOnError false
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | implementation 'com.android.support:appcompat-v7:27.1.1'
31 | testImplementation 'junit:junit:4.12'
32 | if (devMode.toBoolean()) {
33 | api 'com.beyondxia.modules:api_dev:1.0.1'
34 | } else {
35 | api 'com.beyondxia.modules:api:1.0.4'
36 | }
37 | // api project(':modules-api')
38 | }
39 |
--------------------------------------------------------------------------------
/repos/com/beyondxia/modules/api_dev/1.0.1/api_dev-1.0.1.pom:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | com.beyondxia.modules
6 | api_dev
7 | 1.0.1
8 | aar
9 | api dev
10 |
11 |
12 | com.beyondxia.modules
13 | annotation_dev
14 | 1.0.1
15 | compile
16 |
17 |
18 | com.android.support
19 | appcompat-v7
20 | 25.0.0
21 | compile
22 |
23 |
24 | com.google.code.gson
25 | gson
26 | 2.6.2
27 | compile
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/business1/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 21
10 | targetSdkVersion 27
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | lintOptions {
25 | abortOnError false
26 | }
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 |
32 | implementation 'com.android.support:appcompat-v7:27.1.1'
33 | implementation 'com.android.support:recyclerview-v7:27.1.1'
34 | implementation 'com.android.support:design:27.1.1'
35 | testImplementation 'junit:junit:4.12'
36 | if (devMode.toBoolean()) {
37 | annotationProcessor 'com.beyondxia.modules:compiler_dev:1.0.1'
38 | } else {
39 | annotationProcessor 'com.beyondxia.modules:compiler:1.1.1'
40 | }
41 | implementation project(':modules_services_api')
42 | }
43 |
--------------------------------------------------------------------------------
/modules-annotation/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 |
3 | if (devMode.toBoolean()) {
4 | apply from: '../repo_annotation.gradle'
5 | } else {
6 | apply from: '../bintray.gradle'
7 | }
8 |
9 |
10 |
11 | dependencies {
12 | implementation fileTree(dir: 'libs', include: ['*.jar'])
13 | }
14 | sourceCompatibility = "1.7"
15 | targetCompatibility = "1.7"
16 |
17 |
18 |
19 | //clean ---- build----generatePomFileForReleasePublication---publishReleasePublicationToMabenLocal---bintrayUpload
20 | // ./gradlew bintrayUpload -PbintrayUser=beyondxia -PbintrayKey=**** -PdryRun=false
21 | //apply plugin: 'com.novoda.bintray-release'
22 | //allprojects {
23 | // repositories {
24 | // jcenter()
25 | // }
26 | // tasks.withType(Javadoc) {
27 | // options{ encoding "UTF-8"
28 | // charSet 'UTF-8'
29 | // links "http://docs.oracle.com/javase/7/docs/api"
30 | // }
31 | // }
32 | //}
33 | //publish {
34 | // repoName = 'annotation'
35 | // userOrg = 'beyondxia'
36 | // groupId = 'com.beyondxia.modules'
37 | // artifactId = 'annotation'
38 | // publishVersion = '1.0.3'
39 | // desc = 'This is a annotation for modules'
40 | // website = 'https://github.com/beyondxia/annotation'
41 | //}
--------------------------------------------------------------------------------
/other/business2/src/main/res/layout/activity_b2.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
20 |
21 |
27 |
28 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/repos/com/beyondxia/modules/plugin_dev/1.0.3/plugin_dev-1.0.3.pom:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | com.beyondxia.modules
6 | plugin_dev
7 | 1.0.3
8 |
9 |
10 | com.android.tools.build
11 | gradle
12 | 2.1.3
13 | runtime
14 |
15 |
16 | org.javassist
17 | javassist
18 | 3.20.0-GA
19 | runtime
20 |
21 |
22 | commons-io
23 | commons-io
24 | 2.5
25 | runtime
26 |
27 |
28 | com.beyondxia.modules
29 | annotation_dev
30 | 1.0.1
31 | runtime
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/repos/com/beyondxia/modules/plugin_dev/1.0.4/plugin_dev-1.0.4.pom:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | com.beyondxia.modules
6 | plugin_dev
7 | 1.0.4
8 |
9 |
10 | com.android.tools.build
11 | gradle
12 | 2.1.3
13 | runtime
14 |
15 |
16 | org.javassist
17 | javassist
18 | 3.20.0-GA
19 | runtime
20 |
21 |
22 | commons-io
23 | commons-io
24 | 2.5
25 | runtime
26 |
27 |
28 | com.beyondxia.modules
29 | annotation_dev
30 | 1.0.1
31 | runtime
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/repos/com/beyondxia/modules/transform-plugin/1.1.2/transform-plugin-1.1.2.pom:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | com.beyondxia.modules
6 | transform-plugin
7 | 1.1.2
8 |
9 |
10 | com.android.tools.build
11 | gradle
12 | 2.1.3
13 | runtime
14 |
15 |
16 | org.javassist
17 | javassist
18 | 3.20.0-GA
19 | runtime
20 |
21 |
22 | commons-io
23 | commons-io
24 | 2.5
25 | runtime
26 |
27 |
28 | com.beyondxia.modules
29 | annotation_dev
30 | 1.0.1
31 | runtime
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/repos/com/beyondxia/modules/transform-plugin/1.1.5/transform-plugin-1.1.5.pom:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | com.beyondxia.modules
6 | transform-plugin
7 | 1.1.5
8 |
9 |
10 | com.android.tools.build
11 | gradle
12 | 2.1.3
13 | runtime
14 |
15 |
16 | org.javassist
17 | javassist
18 | 3.20.0-GA
19 | runtime
20 |
21 |
22 | commons-io
23 | commons-io
24 | 2.5
25 | runtime
26 |
27 |
28 | com.beyondxia.modules
29 | annotation_dev
30 | 1.0.1
31 | runtime
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/repos/com/beyondxia/modules/transform-plugin/1.2.3/transform-plugin-1.2.3.pom:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | com.beyondxia.modules
6 | transform-plugin
7 | 1.2.3
8 |
9 |
10 | com.android.tools.build
11 | gradle
12 | 2.1.3
13 | runtime
14 |
15 |
16 | org.javassist
17 | javassist
18 | 3.20.0-GA
19 | runtime
20 |
21 |
22 | commons-io
23 | commons-io
24 | 2.5
25 | runtime
26 |
27 |
28 | com.beyondxia.modules
29 | annotation_dev
30 | 1.0.1
31 | runtime
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/repos/com/beyondxia/modules/transform-plugin/1.2.5/transform-plugin-1.2.5.pom:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | com.beyondxia.modules
6 | transform-plugin
7 | 1.2.5
8 |
9 |
10 | com.android.tools.build
11 | gradle
12 | 2.1.3
13 | runtime
14 |
15 |
16 | org.javassist
17 | javassist
18 | 3.20.0-GA
19 | runtime
20 |
21 |
22 | commons-io
23 | commons-io
24 | 2.5
25 | runtime
26 |
27 |
28 | com.beyondxia.modules
29 | annotation_dev
30 | 1.0.1
31 | runtime
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/test/java/com/pingan/aptdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.pingan.aptdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 |
18 | @Test
19 | public void dotTest() {
20 | String className = "com.test.Test";
21 | String substring = className.substring(className.lastIndexOf(".") + 1, className.length());
22 | String packageName = className.substring(0, className.lastIndexOf("."));
23 | // System.err.println(className.substring(className.lastIndexOf("."), className.length()));
24 | System.err.println(packageName);
25 | System.err.println(substring);
26 | }
27 |
28 | @Test
29 | public void regTest() {
30 | String className = "/User/chenwei/aptDemo/app/build/intermediates/classes/xXx/debug/com.test.Test";
31 | String regex = ".*/build/intermediates/classes/[a-z,A-Z]*[/]?debug/.*";
32 | String[] split = className.split(regex);
33 | for (String s : split) {
34 | System.err.println(s);
35 | }
36 |
37 | System.err.println(className.matches(regex));
38 | }
39 | }
--------------------------------------------------------------------------------
/repos/com/beyondxia/modules/compiler/1.1.0/compiler-1.1.0.pom:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | com.beyondxia.modules
6 | compiler
7 | 1.1.0
8 |
9 |
10 | com.google.auto.service
11 | auto-service
12 | 1.0-rc2
13 | runtime
14 |
15 |
16 | com.squareup
17 | javapoet
18 | 1.10.0
19 | runtime
20 |
21 |
22 | org.apache.commons
23 | commons-lang3
24 | 3.4
25 | runtime
26 |
27 |
28 | org.apache.commons
29 | commons-collections4
30 | 4.1
31 | runtime
32 |
33 |
34 | com.beyondxia.modules
35 | annotation_dev
36 | 1.0.1
37 | runtime
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/repos/com/beyondxia/modules/compiler_dev/1.0.1/compiler_dev-1.0.1.pom:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | com.beyondxia.modules
6 | compiler_dev
7 | 1.0.1
8 |
9 |
10 | com.google.auto.service
11 | auto-service
12 | 1.0-rc2
13 | runtime
14 |
15 |
16 | com.squareup
17 | javapoet
18 | 1.10.0
19 | runtime
20 |
21 |
22 | org.apache.commons
23 | commons-lang3
24 | 3.4
25 | runtime
26 |
27 |
28 | org.apache.commons
29 | commons-collections4
30 | 4.1
31 | runtime
32 |
33 |
34 | com.beyondxia.modules
35 | annotation_dev
36 | 1.0.1
37 | runtime
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/modules-compiler/src/main/java/com/beyondxia/compiler/utils/Logger.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.compiler.utils;
2 |
3 | import org.apache.commons.lang3.StringUtils;
4 |
5 | import javax.annotation.processing.Messager;
6 | import javax.tools.Diagnostic;
7 |
8 | public class Logger {
9 | private Messager msg;
10 |
11 | public Logger(Messager messager) {
12 | msg = messager;
13 | }
14 |
15 | /**
16 | * Print info log.
17 | */
18 | public void info(CharSequence info) {
19 | if (StringUtils.isNotEmpty(info)) {
20 | msg.printMessage(Diagnostic.Kind.NOTE, info);
21 | }
22 | }
23 |
24 | public void error(CharSequence error) {
25 | if (StringUtils.isNotEmpty(error)) {
26 | msg.printMessage(Diagnostic.Kind.ERROR, "An exception is encountered, [" + error + "]");
27 | }
28 | }
29 |
30 | public void error(Throwable error) {
31 | if (null != error) {
32 | msg.printMessage(Diagnostic.Kind.ERROR, "An exception is encountered, [" + error.getMessage() + "]" + "\n" + formatStackTrace(error.getStackTrace()));
33 | }
34 | }
35 |
36 | public void warning(CharSequence warning) {
37 | if (StringUtils.isNotEmpty(warning)) {
38 | msg.printMessage(Diagnostic.Kind.WARNING, warning);
39 | }
40 | }
41 |
42 | private String formatStackTrace(StackTraceElement[] stackTrace) {
43 | StringBuilder sb = new StringBuilder();
44 | for (StackTraceElement element : stackTrace) {
45 | sb.append(" at ").append(element.toString());
46 | sb.append("\n");
47 | }
48 | return sb.toString();
49 | }
50 | }
--------------------------------------------------------------------------------
/modules-compiler/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 |
3 | if (devMode.toBoolean()) {
4 | apply from: '../repo_compiler.gradle'
5 | } else {
6 | apply from: '../bintray.gradle'
7 | }
8 |
9 | dependencies {
10 | implementation fileTree(dir: 'libs', include: ['*.jar'])
11 |
12 | implementation 'com.google.auto.service:auto-service:1.0-rc2'
13 |
14 | implementation 'com.squareup:javapoet:1.10.0'
15 |
16 | implementation 'org.apache.commons:commons-lang3:3.4'
17 | implementation 'org.apache.commons:commons-collections4:4.1'
18 |
19 |
20 | if (devMode.toBoolean()) {
21 | implementation 'com.beyondxia.modules:annotation_dev:1.0.1'
22 | } else {
23 | implementation 'com.beyondxia.modules:annotation:1.0.3'
24 | }
25 | }
26 |
27 | sourceCompatibility = "1.8"
28 | targetCompatibility = "1.8"
29 |
30 |
31 | //clean ---- build----generatePomFileForReleasePublication---publishReleasePublicationToMabenLocal---bintrayUpload
32 | // ./gradlew bintrayUpload -PbintrayUser=beyondxia -PbintrayKey=**** -PdryRun=false
33 | //apply plugin: 'com.novoda.bintray-release'
34 | //allprojects {
35 | // repositories {
36 | // jcenter()
37 | // }
38 | // tasks.withType(Javadoc) {
39 | // options{ encoding "UTF-8"
40 | // charSet 'UTF-8'
41 | // links "http://docs.oracle.com/javase/7/docs/api"
42 | // }
43 | // }
44 | //}
45 | //publish {
46 | // repoName = 'compiler'
47 | // userOrg = 'beyondxia'
48 | // groupId = 'com.beyondxia.modules'
49 | // artifactId = 'compiler'
50 | // publishVersion = '1.2.0'
51 | // desc = 'This is a compiler for modules'
52 | // website = 'https://github.com/beyondxia/compiler'
53 | //}
--------------------------------------------------------------------------------
/modules-api/src/main/java/com/beyondxia/modules/utils/thread/DefaultThreadFactory.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.modules.utils.thread;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | import java.util.concurrent.ThreadFactory;
6 | import java.util.concurrent.atomic.AtomicInteger;
7 |
8 | /**
9 | * 线程池工厂类
10 | *
11 | * @author zhilong Contact me.
12 | * @version 1.0
13 | * @since 15/12/25 上午10:51
14 | */
15 | public class DefaultThreadFactory implements ThreadFactory {
16 | private static final AtomicInteger poolNumber = new AtomicInteger(1);
17 |
18 | private final AtomicInteger threadNumber = new AtomicInteger(1);
19 | private final ThreadGroup group;
20 | private final String namePrefix;
21 |
22 | public DefaultThreadFactory() {
23 | SecurityManager s = System.getSecurityManager();
24 | group = (s != null) ? s.getThreadGroup() :
25 | Thread.currentThread().getThreadGroup();
26 | namePrefix = "ARouter task pool No." + poolNumber.getAndIncrement() + ", thread No.";
27 | }
28 |
29 | public Thread newThread(@NonNull Runnable runnable) {
30 | String threadName = namePrefix + threadNumber.getAndIncrement();
31 | Thread thread = new Thread(group, runnable, threadName, 0);
32 | if (thread.isDaemon()) { //设为非后台线程
33 | thread.setDaemon(false);
34 | }
35 | if (thread.getPriority() != Thread.NORM_PRIORITY) { //优先级为normal
36 | thread.setPriority(Thread.NORM_PRIORITY);
37 | }
38 |
39 | // 捕获多线程处理中的异常
40 | thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
41 | @Override
42 | public void uncaughtException(Thread thread, Throwable ex) {
43 | }
44 | });
45 | return thread;
46 | }
47 | }
--------------------------------------------------------------------------------
/bintray.gradle:
--------------------------------------------------------------------------------
1 | //// 应用插件
2 | //apply plugin: 'com.jfrog.bintray'
3 | //apply plugin: 'maven-publish'
4 | //
5 | //
6 | //def baseUrl = 'https://github.com/beyondxia'
7 | //def siteUrl = baseUrl
8 | //def gitUrl = "${baseUrl}/modules-plugin"
9 | //def issueUrl = "${baseUrl}/issues"
10 | //
11 | //install {
12 | // repositories {
13 | // mavenInstaller {
14 | // pom.project {
15 | //
16 | // //添加项目描述
17 | // name 'Modules Plugin for Android'
18 | // url siteUrl
19 | //
20 | // //设置开源证书信息
21 | // licenses {
22 | // license {
23 | // name 'The Apache Software License, Version 2.0'
24 | // url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
25 | // }
26 | // }
27 | // //添加开发者信息
28 | // developers {
29 | // developer {
30 | // name 'beyondxia'
31 | // email 'junxx@mail.ustc.edu.cn'
32 | // }
33 | // }
34 | //
35 | // scm {
36 | // connection gitUrl
37 | // developerConnection gitUrl
38 | // url siteUrl
39 | // }
40 | // }
41 | // }
42 | //
43 | // }
44 | //}
45 | //
46 | //
47 | ////配置上传Bintray相关信息
48 | //bintray {
49 | // user = 'beyondxia'
50 | // key = '****'
51 | //
52 | // configurations = ['archives']
53 | // pkg {
54 | // repo = 'transform' // 上传到中央仓库的名称
55 | // name = 'plugin' // 上传到jcenter 的项目名称
56 | // desc = 'modules transform plugin' // 项目描述
57 | // websiteUrl = siteUrl
58 | // issueTrackerUrl = issueUrl
59 | // vcsUrl = gitUrl
60 | // labels = ['gradle', 'plugin']
61 | // licenses = ['Apache-2.0']
62 | // publish = true
63 | // }
64 | //}
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/modules-api/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | if (devMode.toBoolean()) {
4 | apply from: '../repo_api.gradle'
5 | } else {
6 | apply from: '../bintray.gradle'
7 | }
8 |
9 | android {
10 | compileSdkVersion 25
11 |
12 | defaultConfig {
13 | minSdkVersion 12
14 | targetSdkVersion 25
15 | versionCode 1
16 | versionName "1.0"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | debuggable false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 | debug {
26 | debuggable true
27 | minifyEnabled false
28 | }
29 | }
30 | lintOptions {
31 | abortOnError false
32 | }
33 |
34 | buildToolsVersion '25.0.0'
35 | }
36 |
37 | dependencies {
38 | implementation "com.android.support:appcompat-v7:25.0.0"
39 | implementation fileTree(dir: 'libs', include: ['*.jar'])
40 | implementation 'com.google.code.gson:gson:2.6.2'
41 |
42 | if (devMode.toBoolean()) {
43 | api 'com.beyondxia.modules:annotation_dev:1.0.1'
44 | } else {
45 | api 'com.beyondxia.modules:annotation:1.0.3'
46 | }
47 | }
48 |
49 |
50 | //clean ---- build----generatePomFileForReleasePublication---publishReleasePublicationToMabenLocal---bintrayUpload
51 | // ./gradlew bintrayUpload -PbintrayUser=beyondxia -PbintrayKey=**** -PdryRun=false
52 | //apply plugin: 'com.novoda.bintray-release'
53 | //allprojects {
54 | // repositories {
55 | // jcenter()
56 | // }
57 | // tasks.withType(Javadoc) {
58 | // options{ encoding "UTF-8"
59 | // charSet 'UTF-8'
60 | // links "http://docs.oracle.com/javase/7/docs/api"
61 | // }
62 | // }
63 | //}
64 | //publish {
65 | // repoName = 'api'
66 | // userOrg = 'beyondxia'
67 | // groupId = 'com.beyondxia.modules'
68 | // artifactId = 'api'
69 | // publishVersion = '1.0.4'
70 | // desc = 'This is a api core for modules'
71 | // website = 'https://github.com/beyondxia/api'
72 | //}
--------------------------------------------------------------------------------
/modules-plugin/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'groovy'
2 |
3 | if (devMode.toBoolean()) {
4 | apply from: '../repo_plugin.gradle'
5 | } else {
6 | apply from: '../bintray.gradle'
7 | }
8 |
9 |
10 | dependencies {
11 | //gradle sdk
12 | implementation gradleApi()
13 | //groovy sdk
14 | implementation localGroovy()
15 | implementation 'com.android.tools.build:gradle:2.1.3'
16 | implementation 'org.javassist:javassist:3.20.0-GA'
17 | implementation 'commons-io:commons-io:2.5'
18 |
19 | if (devMode.toBoolean()) {
20 | implementation 'com.beyondxia.modules:annotation_dev:1.0.1'
21 | } else {
22 | implementation 'com.beyondxia.modules:annotation:1.0.3'
23 | }
24 |
25 | }
26 |
27 | repositories {
28 | maven {
29 | url uri("./repos")
30 | }
31 | jcenter()
32 | google()
33 | }
34 |
35 |
36 |
37 | //publishing {
38 | // publications {
39 | // mavenJava(MavenPublication) {
40 | //
41 | // groupId 'com.beyondxia.modules'
42 | // artifactId _artifactId
43 | // version _version
44 | //
45 | // from components.java
46 | //
47 | // }
48 | // }
49 | //}
50 |
51 | //apply plugin: 'maven-publish'
52 | //publishing {
53 | // repositories {
54 | // maven {
55 | // url uri('./repos')
56 | // }
57 | // }
58 | //}
59 |
60 | //./gradlew clean modules-plugin:build bintrayUpload -PbintrayUser=beyondxia -PbintrayKey=af95d6af14ef35e80d9207234f96e56445b4677b -PdryRun=false
61 | apply plugin: 'com.novoda.bintray-release'
62 | allprojects {
63 | repositories {
64 | jcenter()
65 | }
66 | tasks.withType(Javadoc) {
67 | options {
68 | encoding "UTF-8"
69 | charSet 'UTF-8'
70 | links "http://docs.oracle.com/javase/7/docs/api"
71 | }
72 | }
73 | }
74 | publish {
75 | repoName = 'transform'
76 | userOrg = 'beyondxia'
77 | groupId = 'com.beyondxia.modules'
78 | artifactId = 'transform-plugin'
79 | publishVersion = '1.3.12'
80 | desc = 'This is a plugin for modules'
81 | website = 'https://github.com/beyondxia/transform'
82 | }
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.beyondxia.modules.plugin'
3 |
4 | android {
5 | compileSdkVersion 27
6 | defaultConfig {
7 | applicationId "com.beyondxia.modules"
8 | minSdkVersion 21
9 | targetSdkVersion 27
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 |
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | repositories {
22 | flatDir {
23 | dirs 'libs'
24 | }
25 | }
26 |
27 | lintOptions {
28 | abortOnError false
29 | }
30 |
31 | dexOptions {
32 | preDexLibraries = false
33 | keepRuntimeAnnotatedClasses false
34 | }
35 |
36 | compileOptions {
37 | sourceCompatibility JavaVersion.VERSION_1_8
38 | targetCompatibility JavaVersion.VERSION_1_8
39 | }
40 | }
41 |
42 |
43 |
44 | modulesConfig {
45 | // excludeJars 'annotation_dev-1.0.1.jar', 'InfoMonitor.jar'
46 | // includeClassPackage "com.test", "com.beyondxia"
47 | registerWithPlugin true
48 | // businessMatchStrings "my", "export"
49 | }
50 |
51 | dependencies {
52 | implementation fileTree(dir: 'libs', include: ['*.jar'])
53 | implementation 'com.android.support:appcompat-v7:27.1.1'
54 | implementation 'com.android.support.constraint:constraint-layout:1.1.2'
55 | testImplementation 'junit:junit:4.12'
56 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
57 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
58 |
59 | if (devMode.toBoolean()) {
60 | annotationProcessor 'com.beyondxia.modules:compiler_dev:1.0.1'
61 | } else {
62 | annotationProcessor 'com.beyondxia.modules:compiler:1.1.1'
63 | }
64 |
65 |
66 | implementation project(':modules_services_api')
67 | // runtimeOnly project(':business1')
68 | runtimeOnly project(':other:business2')
69 |
70 | implementation(name: 'business1-debug', ext: 'aar')
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/java/com/beyondxia/host/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.host;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.Toast;
8 |
9 | import com.beyondxia.bussiness1.export.LoginService;
10 | import com.beyondxia.message.export.MessageService;
11 | import com.beyondxia.modules.BCDictionary;
12 | import com.beyondxia.modules.R;
13 |
14 | public class MainActivity extends AppCompatActivity {
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_main);
20 | setTitle("HostApp");
21 |
22 | }
23 |
24 | public void onClick(View view) {
25 | switch (view.getId()) {
26 | case R.id.bt_business1_call:
27 | String username = LoginService.get().getUserName();
28 | Toast.makeText(this,username,Toast.LENGTH_SHORT).show();
29 | break;
30 | case R.id.bt_business1_call2:
31 | boolean success = LoginService.get().doLogin(this,"chenwei","xiaxiaojun");
32 | Toast.makeText(this,success?"login success":"login failed",Toast.LENGTH_SHORT).show();
33 | break;
34 | case R.id.bt_business1_call3:
35 | BCDictionary dictionary = LoginService.get().getUserInfo();
36 | Toast.makeText(this,dictionary.toJson(),Toast.LENGTH_SHORT).show();
37 | break;
38 | case R.id.bt_business1_nav:
39 | LoginService.get().nav2LoginActivity(this);
40 | break;
41 | case R.id.bt_business2_nav:
42 | MessageService.get().nav2B2Activity(this);
43 | break;
44 | case R.id.bt_submodule_view:
45 | startActivity(new Intent(this, ShowViewActivity.class));
46 | break;
47 | case R.id.bt_submodule_fragment:
48 | startActivity(new Intent(this, ShowFragmentActivity.class));
49 | break;
50 | default:
51 | break;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/modules-api/src/main/java/com/beyondxia/modules/BCDictionary.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.modules;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.google.gson.Gson;
6 |
7 | import org.json.JSONException;
8 | import org.json.JSONObject;
9 |
10 | import java.util.HashMap;
11 | import java.util.Iterator;
12 | import java.util.Map;
13 |
14 | /**
15 | * Created by xiaojunxia on 2018/8/8.
16 | *
17 | * 叶子元素只允许是基本类型
18 | */
19 | //public class BCDictionary extends Bundle {
20 | public class BCDictionary extends HashMap {
21 |
22 | public BCDictionary() {
23 | }
24 |
25 | public BCDictionary(String json) {
26 | putAll(getMap(json));
27 | }
28 |
29 | // TODO 如何判断所有叶子节点为基本类型,暂时设为private,否则会出现内存问题
30 | private BCDictionary(BCBaseModel obj) {
31 | this(new Gson().toJson(obj));
32 | }
33 |
34 | public String toJson() {
35 | return new Gson().toJson(this);
36 | }
37 |
38 | // 提供给调用方使用
39 | public V fromDictionary(Class clazz) {
40 | String json = toJson();
41 | return new Gson().fromJson(json, clazz);
42 | }
43 |
44 |
45 | public static class Builder {
46 | private BCDictionary dictionary;
47 |
48 | public Builder() {
49 | dictionary = new BCDictionary();
50 | }
51 |
52 | public Builder put(String key, T value){
53 | dictionary.put(key,value);
54 | return this;
55 | }
56 |
57 | public BCDictionary build(){
58 | return dictionary;
59 | }
60 |
61 | }
62 |
63 | private static Map getMap(String jsonString)
64 | {
65 | JSONObject jsonObject;
66 | try
67 | {
68 | jsonObject = new JSONObject(jsonString); @SuppressWarnings("unchecked")
69 | Iterator keyIter = jsonObject.keys();
70 | String key;
71 | Object value;
72 | Map valueMap = new HashMap();
73 | while (keyIter.hasNext())
74 | {
75 | key = (String) keyIter.next();
76 | value = jsonObject.get(key);
77 | valueMap.put(key, value);
78 | }
79 | return valueMap;
80 | }
81 | catch (JSONException e)
82 | {
83 | e.printStackTrace();
84 | }
85 |
86 | return null;
87 |
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/business1/src/main/java/com/beyondxia/bussiness1/fragment/SimpleFragment.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.bussiness1.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v7.widget.DefaultItemAnimator;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.support.v7.widget.StaggeredGridLayoutManager;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.Toast;
14 |
15 | import com.pingan.bussiness1.R;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | public class SimpleFragment extends Fragment {
21 | private RecyclerView mRecyclerView;
22 | private StaggerGridAdapter mAdapter;
23 | private List mDatas;
24 | @Nullable
25 | @Override
26 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
27 | View view = inflater.inflate(R.layout.simple_fragment, container, false);
28 | mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerview);
29 | initData();
30 |
31 | mAdapter = new StaggerGridAdapter(getActivity(), mDatas);
32 | mAdapter.setOnItemClickListener(new StaggerGridAdapter.OnItemClickListener() {
33 | @Override
34 | public void onItemClick(View view, int position) {
35 | Toast.makeText(getActivity(), "Click" + mDatas.get(position), Toast.LENGTH_SHORT).show();
36 | }
37 |
38 | @Override
39 | public void onItemLongClick(View view, int position) {
40 | Toast.makeText(getActivity(), "LongClick" + mDatas.get(position), Toast.LENGTH_SHORT).show();
41 | }
42 | });
43 |
44 | // 设置布局管理器
45 | mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL));
46 | // 设置 item 动画
47 | mRecyclerView.setItemAnimator(new DefaultItemAnimator());
48 | mRecyclerView.setAdapter(mAdapter);
49 | return view;
50 | }
51 |
52 | protected void initData() {
53 | mDatas = new ArrayList();
54 | for (int i = 0; i < 100; i++) {
55 | mDatas.add(String.valueOf(i));
56 | }
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/business1/src/main/java/com/beyondxia/bussiness1/export/Login.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.bussiness1.export;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.text.TextUtils;
7 |
8 | import com.beyondxia.annotation.ExportMethod;
9 | import com.beyondxia.annotation.ExportService;
10 | import com.beyondxia.bussiness1.LoginActivity;
11 | import com.beyondxia.bussiness1.LoginModel;
12 | import com.beyondxia.bussiness1.MyLogin;
13 | import com.beyondxia.modules.BCDictionary;
14 | import com.beyondxia.modules.ILifeCycle;
15 | import com.beyondxia.modules.PAService;
16 |
17 | /**
18 | * Create by ChenWei on 2018/8/29 11:07
19 | **/
20 | @ExportService(moduleName = "business1")
21 | public class Login implements ILifeCycle{
22 |
23 | @ExportMethod
24 | public boolean doLogin(Context context, String userName, String password) {
25 | if (context == null || TextUtils.isEmpty(userName) || TextUtils.isEmpty(password)) return false;
26 | return MyLogin.doLogin(userName,password);
27 | }
28 |
29 | @ExportMethod
30 | public String getUserName() {
31 | return MyLogin.getUserName();
32 | }
33 |
34 | // use BCDictionary to export model
35 | @ExportMethod
36 | public BCDictionary getUserInfo() {
37 | BCDictionary.Builder builder = new BCDictionary.Builder();
38 | BCDictionary dictionary =
39 | builder.put("userName","zhangsan")
40 | .put("password", "pass")
41 | .build();
42 | return dictionary;
43 |
44 | // return new BCDictionary("zhangsan","pass");
45 | }
46 |
47 | @ExportMethod
48 | public void nav2LoginActivity(Context context) {
49 | if (context == null) return;
50 | Intent intent = new Intent(context, LoginActivity.class);
51 | if (!(context instanceof Activity)) {
52 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
53 | }
54 | context.startActivity(intent);
55 | }
56 |
57 | @Override
58 | public void onInstalled() {
59 | // just for time-spend test, you will get warning log like this: "you should not do some time-consuming operation on main thread! time spend..."
60 | try {
61 | Thread.sleep(1000);
62 | } catch (InterruptedException e) {
63 | e.printStackTrace();
64 | }
65 | }
66 |
67 | @Override
68 | public void onUninstalled() {
69 |
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
24 |
25 |
32 |
33 |
40 |
41 |
48 |
49 |
56 |
57 |
64 |
65 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/other/business2/src/main/java/com/beyondxia/message/B2Activity.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.message;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.View;
6 | import android.widget.Button;
7 | import android.widget.Toast;
8 |
9 | import com.beyondxia.bussiness1.export.LoginService;
10 | import com.beyondxia.host.export.HostExportService;
11 | import com.beyondxia.modules.BCDictionary;
12 |
13 |
14 | public class B2Activity extends AppCompatActivity {
15 | private Button bt_host_call;
16 | private Button bt_business1_call;
17 | private Button bt_business1_call2;
18 | private Button bt_business1_nav;
19 |
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_b2);
25 | setTitle("Business2");
26 |
27 | bt_host_call = (Button) findViewById(R.id.bt_host_call);
28 | bt_business1_call = (Button) findViewById(R.id.bt_business1_call);
29 | bt_business1_call2 = (Button) findViewById(R.id.bt_business1_call2);
30 | bt_business1_nav = (Button) findViewById(R.id.bt_business1_nav);
31 |
32 |
33 | bt_host_call.setOnClickListener(new View.OnClickListener() {
34 | @Override
35 | public void onClick(View view) {
36 | String hostName = HostExportService.get().getHostName();
37 | Toast.makeText(B2Activity.this,hostName,Toast.LENGTH_SHORT).show();
38 | }
39 | });
40 | bt_business1_call.setOnClickListener(new View.OnClickListener() {
41 | @Override
42 | public void onClick(View view) {
43 | boolean success = LoginService.get().doLogin(B2Activity.this,"chenwei","xiaxiaojun");
44 | Toast.makeText(B2Activity.this,success?"login success":"login failed",Toast.LENGTH_SHORT).show();
45 | }
46 | });
47 | bt_business1_call2.setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View view) {
50 | BCDictionary dictionary = LoginService.get().getUserInfo();
51 | // dictionary数据必须为java 基本类型
52 | MessageModel messageModel = dictionary.fromDictionary(MessageModel.class);
53 | Toast.makeText(B2Activity.this,messageModel.toString(),Toast.LENGTH_SHORT).show();
54 | }
55 | });
56 | bt_business1_nav.setOnClickListener(new View.OnClickListener() {
57 | @Override
58 | public void onClick(View view) {
59 | LoginService.get().nav2LoginActivity(B2Activity.this);
60 | }
61 | });
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/modules-api/src/main/java/com/beyondxia/modules/utils/thread/DefaultPoolExecutor.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.modules.utils.thread;
2 |
3 |
4 | import java.util.concurrent.ArrayBlockingQueue;
5 | import java.util.concurrent.BlockingQueue;
6 | import java.util.concurrent.CancellationException;
7 | import java.util.concurrent.ExecutionException;
8 | import java.util.concurrent.Future;
9 | import java.util.concurrent.RejectedExecutionHandler;
10 | import java.util.concurrent.ThreadFactory;
11 | import java.util.concurrent.ThreadPoolExecutor;
12 | import java.util.concurrent.TimeUnit;
13 |
14 | /**
15 | * Executors
16 | *
17 | * @author 正纬 Contact me.
18 | * @version 1.0
19 | * @since 16/4/28 下午4:07
20 | */
21 | public class DefaultPoolExecutor extends ThreadPoolExecutor {
22 | // Thread args
23 | private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
24 | private static final int INIT_THREAD_COUNT = CPU_COUNT + 1;
25 | private static final int MAX_THREAD_COUNT = INIT_THREAD_COUNT;
26 | private static final long SURPLUS_THREAD_LIFE = 30L;
27 |
28 | private static DefaultPoolExecutor instance;
29 |
30 | public static DefaultPoolExecutor getInstance() {
31 | if (null == instance) {
32 | synchronized (DefaultPoolExecutor.class) {
33 | if (null == instance) {
34 | instance = new DefaultPoolExecutor(
35 | INIT_THREAD_COUNT,
36 | MAX_THREAD_COUNT,
37 | SURPLUS_THREAD_LIFE,
38 | TimeUnit.SECONDS,
39 | new ArrayBlockingQueue(64),
40 | new DefaultThreadFactory());
41 | }
42 | }
43 | }
44 | return instance;
45 | }
46 |
47 | private DefaultPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue workQueue, ThreadFactory threadFactory) {
48 | super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, new RejectedExecutionHandler() {
49 | @Override
50 | public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
51 | }
52 | });
53 | }
54 |
55 | /*
56 | * 线程执行结束,顺便看一下有么有什么乱七八糟的异常
57 | *
58 | * @param r the runnable that has completed
59 | * @param t the exception that caused termination, or null if
60 | */
61 | @Override
62 | protected void afterExecute(Runnable r, Throwable t) {
63 | super.afterExecute(r, t);
64 | if (t == null && r instanceof Future>) {
65 | try {
66 | ((Future>) r).get();
67 | } catch (CancellationException ce) {
68 | t = ce;
69 | } catch (ExecutionException ee) {
70 | t = ee.getCause();
71 | } catch (InterruptedException ie) {
72 | Thread.currentThread().interrupt(); // ignore/reset
73 | }
74 | }
75 | if (t != null) {
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/repo_api.gradle:
--------------------------------------------------------------------------------
1 | //
2 | //apply plugin: 'maven-publish'
3 | //
4 | //task sourceJar(type: Jar) {
5 | // from android.sourceSets.main.java.srcDirs
6 | // classifier "sources"
7 | //}
8 | //publishing {
9 | // publications {
10 | // aar(MavenPublication) {
11 | //
12 | //// groupId 'com.beyondxia.modules'
13 | //// artifactId 'api_dev'
14 | //// version '1.0.1'
15 | ////
16 | //// from components.android
17 | //
18 | //
19 | //
20 | // groupId 'com.beyondxia.modules'
21 | // artifactId 'api_dev'
22 | // version '1.0.1'
23 | //
24 | //
25 | //// artifact(sourceJar)
26 | // artifact("$buildDir/outputs/aar/modules-api-debug.aar")
27 | //
28 | // // Add dependencies to POM - normal Java projects use 'from components.java'
29 | // pom.withXml {
30 | // def dependenciesNode = asNode().appendNode('dependencies')
31 | //
32 | // // Iterate over the 'compile' dependencies
33 | // configurations.compile.allDependencies.each {
34 | // def dependencyNode = dependenciesNode.appendNode('dependency')
35 | // dependencyNode.appendNode('groupId', it.group)
36 | // dependencyNode.appendNode('artifactId', it.name)
37 | // dependencyNode.appendNode('version', it.version)
38 | // }
39 | //
40 | // // Iterate over the 'api' dependencies
41 | // configurations.api.allDependencies.each {
42 | // def dependencyNode = dependenciesNode.appendNode('dependency')
43 | // dependencyNode.appendNode('groupId', it.group)
44 | // dependencyNode.appendNode('artifactId', it.name)
45 | // dependencyNode.appendNode('version', it.version)
46 | // }
47 | //
48 | // // Iterate over the 'implementation' dependencies
49 | // configurations.implementation.allDependencies.each {
50 | // def dependencyNode = dependenciesNode.appendNode('dependency')
51 | // dependencyNode.appendNode('groupId', it.group)
52 | // dependencyNode.appendNode('artifactId', it.name)
53 | // dependencyNode.appendNode('version', it.version)
54 | // }
55 | // }
56 | //
57 | // }
58 | // }
59 | //}
60 | //
61 | //publishing {
62 | // repositories {
63 | // maven {
64 | // url uri('../repos')
65 | // }
66 | // }
67 | //}
68 |
69 |
70 |
71 |
72 |
73 | apply plugin: 'maven'
74 |
75 | uploadArchives {
76 | repositories {
77 | mavenDeployer {
78 | repository(url: uri('../repos')) {
79 | // authentication(userName: "framework-deploy", password: "framework-deploy-112")
80 | }
81 |
82 | pom.project {
83 | version '1.0.1'
84 | groupId 'com.beyondxia.modules'
85 | artifactId "api_dev"
86 | packaging "jar"
87 | description "api dev"
88 | }
89 | }
90 | }
91 | }
--------------------------------------------------------------------------------
/business1/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
21 |
22 |
26 |
27 |
32 |
33 |
36 |
37 |
45 |
46 |
47 |
48 |
51 |
52 |
63 |
64 |
65 |
66 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/modules-plugin/src/main/groovy/com/beyondxia/plugin/PATransform.groovy:
--------------------------------------------------------------------------------
1 | package com.beyondxia.plugin
2 |
3 | import com.android.annotations.NonNull
4 | import com.android.build.api.transform.*
5 | import com.android.build.gradle.internal.pipeline.TransformManager
6 | import com.beyondxia.plugin.utils.RegisterUtils
7 | import com.beyondxia.plugin.utils.TransformUtil
8 | import org.apache.commons.codec.digest.DigestUtils
9 | import org.apache.commons.io.FileUtils
10 | import org.gradle.api.Project
11 |
12 | /**
13 | *
14 | * Create by ChenWei on 2018/8/29 16:25
15 | *
16 | **/
17 | class PATransform extends Transform {
18 |
19 | private Project mProject
20 |
21 | public static File fileContainsInitClass
22 | public static List registerList = new ArrayList()
23 |
24 |
25 | PATransform(Project project) {
26 | this.mProject = project
27 | }
28 |
29 | @Override
30 | String getName() {
31 | return "ModulesTransform"
32 | }
33 |
34 | @Override
35 | Set getInputTypes() {
36 | return TransformManager.CONTENT_CLASS
37 | }
38 |
39 | @Override
40 | Set super QualifiedContent.Scope> getScopes() {
41 | return TransformManager.SCOPE_FULL_PROJECT
42 | }
43 |
44 | @Override
45 | boolean isIncremental() {
46 | return false
47 | }
48 |
49 |
50 | @Override
51 | void transform(@NonNull TransformInvocation transformInvocation) {
52 | //首先获取构建类型并给mPool添加classPath
53 | TransformUtil.appendClassPathCore(mProject)
54 |
55 | transformInvocation.inputs.each { TransformInput input ->
56 | //对类型为“文件夹”的input进行遍历
57 | input.directoryInputs.each { DirectoryInput directoryInput ->
58 | TransformUtil.handleDirInput(directoryInput.file.absolutePath, mProject)
59 | if (mProject.modulesConfig.registerWithPlugin) {
60 | RegisterUtils.scanDirectory(directoryInput.file)
61 | }
62 | def dest = transformInvocation.outputProvider.getContentLocation(directoryInput.name,
63 | directoryInput.contentTypes, directoryInput.scopes,
64 | Format.DIRECTORY)
65 | // 将input的目录复制到output指定目录
66 | FileUtils.copyDirectory(directoryInput.file, dest)
67 | }
68 | //遍历jar文件,对jar不进行操作,但是要输出到指定目录
69 | input.jarInputs.each { JarInput jarInput ->
70 | def jarPath = jarInput.file.absolutePath
71 | if (TransformUtil.jarNeedHandle(jarPath, mProject)) {
72 | TransformUtil.handleJarInput(jarPath, mProject)
73 | }
74 | //重命名输出文件(同目录copyFile会冲突)
75 | def jarName = jarInput.name
76 | def md5Name = DigestUtils.md5Hex(jarInput.file.getAbsolutePath())
77 | if (jarName.endsWith(".jar")) {
78 | jarName = jarName.substring(0, jarName.length() - 4)
79 | }
80 | def dest = transformInvocation.outputProvider.getContentLocation(jarName + md5Name, jarInput.contentTypes, jarInput.scopes, Format.JAR)
81 | if (mProject.modulesConfig.registerWithPlugin) {
82 | if (RegisterUtils.shouldProcessPreDexJar(jarName)) {
83 | RegisterUtils.scanJar(jarInput.file, dest)
84 | }
85 | }
86 | FileUtils.copyFile(jarInput.file, dest)
87 | }
88 |
89 | }
90 |
91 | if (mProject.modulesConfig.registerWithPlugin) {
92 | RegisterUtils.insertCodeToInitClass()
93 | }
94 |
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## modules简介
2 | 项目在进行组件化改造中,不可避免的会遇到模块之间的解耦与组件模块之间的服务调用。针对以上问题,本框架提供了一套低侵入、轻便简洁的接入方式。框架通过注解来标识暴露的服务,以确保框架对原代码的低侵入。模块间的服务调用通过调用框架生成的中间类来完成调用,最大程度降低了模块间的耦合
3 |
4 | ## demo
5 | 
6 |
7 | ## 技术原理系列文章
8 | [一种低侵入性的组件化方案之APP组件化简介](https://juejin.im/post/5bc592b1f265da0ace21600b)
9 |
10 | [一种低侵入性的组件化方案 之 组件化需要考虑的几个问题](https://juejin.im/post/5bc6fcb36fb9a05cd45713ab)
11 |
12 | [一种低侵入性的组件化方案 之 传统组件化方案的问题](https://juejin.im/post/5bc70291e51d450e76336a1f)
13 |
14 | [一种简单的低侵入性的组件化方案](https://juejin.im/post/5bc70550e51d450e827b9ca7)
15 |
16 |
17 | ## 一、集成步骤:
18 | ### 1、集成plugin
19 | 在project的build.gradle文件中添加依赖和属性配置:
20 | ```
21 | buildscript {
22 |
23 | repositories {
24 | jcenter()
25 | //...
26 |
27 | }
28 | dependencies {
29 | classpath 'com.beyondxia.modules:transform-plugin:1.3.12'
30 | //...
31 |
32 | }
33 | }
34 | ```
35 |
36 | 并在app module的build.gradle 件中引入该插件:
37 | ```
38 | apply plugin: 'com.beyondxia.modules.plugin'
39 | ```
40 |
41 | ### 2、新建module
42 | 在项目根目录中新建一个名为modules_services_api(工程名要命名为modules_services_api)的android library性质的子module(用来放置生成的公共源码),并在该module的build.gradle文件中添加如下依赖和属性配置:
43 | ```
44 | api 'com.beyondxia.modules:api:1.0.4'
45 | ```
46 | 其他需要组件化业务module均需要依赖此module
47 |
48 | ### 3、添加annotationProcessor
49 | 在需要接入的业务module中添加如下annotationProcessor依赖
50 | ```
51 | annotationProcessor 'com.beyondxia.modules:compiler:1.1.1'
52 | ```
53 | 至此,已完成所有的配置工作
54 |
55 | ## 二、使用步骤:
56 | ### 一、初始化
57 | 在Application类的onCreate中加入:
58 | ```
59 | ServiceHelper.init(this);
60 | ```
61 | ### 二、module向外暴露服务:
62 | 以下是一个典型的对外提供的服务的类
63 | ```
64 | @ExportService(moduleName = "business1")
65 | public class Login implements ILifeCycle{
66 |
67 | @ExportMethod
68 | public boolean doLogin(Context context, String userName, String password) {
69 | //...
70 | }
71 |
72 | @ExportMethod
73 | public String getUserName() {
74 | //...
75 | }
76 |
77 | // use BCDictionary to export model
78 | @ExportMethod
79 | public BCDictionary getUserInfo() {
80 | //...
81 | }
82 |
83 | @ExportMethod
84 | public void nav2LoginActivity(Context context) {
85 | //...
86 | }
87 |
88 | @Override
89 | public void onInstalled() {
90 |
91 | }
92 |
93 | @Override
94 | public void onUninstalled() {
95 | // useless now
96 | }
97 | }
98 | ```
99 | 说明:
100 | a、ExportService:标识对外提供服务的类
101 | 参数介绍:moduleName,本服务往外暴露的模块名,不设置默认为空,一个模块内的所有服务类建议相同,但需保证与其他模块的互异性。
102 |
103 | preLoad,是否预加载该服务类,默认为false。设置为true时,则在启动app的时候则会实例化该服务类, 否则在使用的时候再实例化,可根据当前的模块特性进行灵活配置。
104 |
105 | b、ExportMethod:标识本服务对外提供的方法,在对外提供的服务类中,只有被ExportMethod标记的方法才可以被其他模块所访问。
106 | 注:该注解只能标识在为public的成员方法上,否则会抛出异常,终止构建。
107 |
108 | c、ILifeCycle:服务类的生命周期,是否实现该接口为可选。若实现该接口 ,可在服务安装与卸载的回调中做一些初始化与资源释放等操作。
109 |
110 | d、特别重要:该类不允许存在父类。
111 |
112 | ### 三、生成中间类:
113 | 完成以上服务类的配置工作后,执行./gradlew :moduleName:clean :moduleName:compileDebugJavaWithJavac任务即可完成对应的服务中间类, 生成的中间类的 录为:rootProjectDir/modules_services_api/src/main/java
114 |
115 |
116 |
117 | 说明:服务中间类的生成规则:假如服务类名为ClassName,则会生成对应的一个服务中间类与服务中间接 ,命名规则为:ClassName+Service、I+ClassName。
118 |
119 | ### 四、调用服务:
120 | 在其他模块中,使用以下方法进行服务的调用:
121 | ```
122 | BCDictionary dictionary = LoginService.get().getUserInfo();
123 | ```
124 | 如上图对Login类的调用,通过其中间服务类LoginService的调用即可,避免了对Login类的强依赖,达到了解耦的目的。
125 |
126 |
127 | ## QQ群
128 | QQ群号:881324846
129 |
130 |
131 |
132 | 或者扫描下方二维码关注微信公众号
133 |
134 |
135 |
--------------------------------------------------------------------------------
/modules-api/src/main/java/com/beyondxia/modules/PAServiceEvn.java:
--------------------------------------------------------------------------------
1 | package com.beyondxia.modules;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 | import android.support.v4.app.FragmentActivity;
6 | import android.support.v4.app.FragmentManager;
7 |
8 | import java.util.ArrayList;
9 | import java.util.HashMap;
10 | import java.util.List;
11 |
12 | /**
13 | * Create by ChenWei on 2018/8/23 15:51
14 | **/
15 | public class PAServiceEvn {
16 | private static PAServiceEvn sInstance = new PAServiceEvn();
17 | private Application application;
18 | private FragmentActivity curActivity;
19 | private static final HashMap FEIFAN_SERVICE_MAP =
20 | new HashMap<>();
21 | private static int sNextPerContextServiceCacheIndex = 0;
22 |
23 | public static PAServiceEvn getInstance() {
24 | return sInstance;
25 | }
26 |
27 | private PAServiceEvn() {
28 |
29 | }
30 |
31 | public Application getApplication() {
32 | return application;
33 | }
34 |
35 | public void setApplication(Application app) {
36 | this.application = app;
37 | }
38 |
39 | public Activity getCurActivity() {
40 | return curActivity;
41 | }
42 |
43 | public void setCurActivity(FragmentActivity curActivity) {
44 | this.curActivity = curActivity;
45 | }
46 |
47 | public void destroyCurActivity(Activity curActivity) {
48 | if (this.curActivity == curActivity) {
49 | this.curActivity = null;
50 | }
51 | }
52 |
53 | public FragmentManager getFragmentManager() {
54 | return null == curActivity ? null : curActivity.getSupportFragmentManager();
55 | }
56 |
57 | /**
58 | * 注册模块对应的Service
59 | *
60 | * @param serviceName 注册的Service名称
61 | * @param fetcher ServiceFetcher或StaticServiceFetcher
62 | */
63 | public static void registerService(String serviceName, ServiceFetcher fetcher) {
64 | if (!(fetcher instanceof StaticServiceFetcher)) {
65 | fetcher.mContextCacheIndex = sNextPerContextServiceCacheIndex++;
66 | }
67 | FEIFAN_SERVICE_MAP.put(serviceName, fetcher);
68 | }
69 |
70 | public static Object getService(String name) {
71 | ServiceFetcher fetcher = FEIFAN_SERVICE_MAP.get(name);
72 | return fetcher == null ? null : fetcher.getService(getInstance());
73 | }
74 |
75 |
76 | private final List