├── .gitignore ├── LICENSE ├── README.md ├── jimu-core ├── .gitignore ├── bintrayv1.gradle ├── build-gradle │ ├── .gitignore │ ├── build.gradle │ └── src │ │ ├── main │ │ ├── groovy │ │ │ ├── com.dd.buildgradle │ │ │ │ ├── ComBuild.groovy │ │ │ │ ├── ComCodeTransform.groovy │ │ │ │ ├── ConvertUtils.groovy │ │ │ │ ├── exten │ │ │ │ │ └── ComExtension.groovy │ │ │ │ └── util │ │ │ │ │ └── StringUtil.java │ │ │ ├── com │ │ │ │ └── luojilab │ │ │ │ │ └── component │ │ │ │ │ └── componentlib │ │ │ │ │ └── applicationlike │ │ │ │ │ └── RegisterCompManual.java │ │ │ ├── org │ │ │ │ └── github │ │ │ │ │ └── jimu │ │ │ │ │ └── msg │ │ │ │ │ ├── MsgBridgeService.java │ │ │ │ │ └── ServiceInfoBean.groovy │ │ │ └── osp │ │ │ │ └── leobert │ │ │ │ └── magnet │ │ │ │ ├── Log.groovy │ │ │ │ └── plugin │ │ │ │ └── manifest │ │ │ │ ├── ManifestMergerImpl.groovy │ │ │ │ └── XmlnsSweeper.groovy │ │ └── resources │ │ │ └── META-INF │ │ │ └── gradle-plugins │ │ │ └── com.dd.comgradle.properties │ │ └── test │ │ ├── groovy │ │ └── util │ │ │ ├── ComCodeTransformTest.groovy │ │ │ └── StringUtilTest.java │ │ └── java │ │ └── com │ │ └── dd │ │ └── buildgradle │ │ └── util │ │ └── StringUtilTest.java ├── build.gradle ├── buildSrc │ └── build.gradle ├── componentlib │ ├── .gitignore │ ├── build.gradle │ ├── release │ │ ├── component-baselib-0.0.1.1.jar │ │ └── component-baselib-0.0.2.jar │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ ├── com │ │ │ └── luojilab │ │ │ │ └── component │ │ │ │ └── componentlib │ │ │ │ ├── applicationlike │ │ │ │ ├── IApplicationLike.java │ │ │ │ └── RegisterCompManual.java │ │ │ │ ├── exceptions │ │ │ │ ├── ParamException.java │ │ │ │ └── UiRouterException.java │ │ │ │ ├── log │ │ │ │ ├── ILogger.java │ │ │ │ └── impl │ │ │ │ │ └── DefaultLogger.java │ │ │ │ ├── router │ │ │ │ ├── ISyringe.java │ │ │ │ ├── Router.java │ │ │ │ └── ui │ │ │ │ │ ├── AbsDispatcherActivity.java │ │ │ │ │ ├── BaseCompRouter.java │ │ │ │ │ ├── IComponentRouter.java │ │ │ │ │ ├── IUIRouter.java │ │ │ │ │ ├── UIRouter.java │ │ │ │ │ └── VerifyResult.java │ │ │ │ ├── service │ │ │ │ ├── AutowiredService.java │ │ │ │ ├── AutowiredServiceImpl.java │ │ │ │ ├── JsonService.java │ │ │ │ └── JsonServiceImpl.java │ │ │ │ └── utils │ │ │ │ └── UriUtils.java │ │ └── org │ │ │ └── github │ │ │ └── jimu │ │ │ └── msg │ │ │ ├── AriseAt.java │ │ │ ├── Constants.java │ │ │ ├── ConsumeOn.java │ │ │ ├── EventListener.java │ │ │ ├── EventManager.java │ │ │ ├── MsgBridgeService.java │ │ │ ├── Utils.java │ │ │ ├── bean │ │ │ ├── ConsumerMeta.java │ │ │ ├── EventBean.java │ │ │ ├── ManagerMethod.java │ │ │ ├── RemoteEventBean.java │ │ │ └── State.java │ │ │ ├── core │ │ │ ├── CrossSubscriberHandler.java │ │ │ ├── MessageBridgeAttacher.java │ │ │ ├── MessageBridgeService.java │ │ │ ├── MessageFactory.java │ │ │ ├── RemoteObservableHandler.java │ │ │ ├── Secy.java │ │ │ ├── SubscriberCache.java │ │ │ └── SubscriberList.java │ │ │ ├── executor │ │ │ ├── CrossProcessPoster.java │ │ │ ├── IPoster.java │ │ │ ├── LocalProcessBackgroundPoster.java │ │ │ └── LocalProcessMainThreadPoster.java │ │ │ └── notation │ │ │ ├── AriseProcess.java │ │ │ ├── Consumer.java │ │ │ └── Event.java │ │ └── res │ │ └── values │ │ └── strings.xml ├── gradle.properties.bak ├── gradlew ├── gradlew.bat ├── installv1.gradle ├── router-anno-compiler │ ├── .gitignore │ ├── build.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── luojilab │ │ │ └── router │ │ │ └── compiler │ │ │ ├── model │ │ │ └── MethodInfo.java │ │ │ ├── processor │ │ │ ├── AutowiredProcessor.java │ │ │ └── RouterProcessor.java │ │ │ └── utils │ │ │ ├── AnnoUtils.java │ │ │ ├── Constants.java │ │ │ ├── FileUtils.java │ │ │ ├── Logger.java │ │ │ └── TypeUtils.java │ │ └── resources │ │ └── META-INF │ │ └── services │ │ └── javax.annotation.processing.Processor ├── router-annotation │ ├── .gitignore │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── luojilab │ │ └── router │ │ └── facade │ │ ├── annotation │ │ ├── Autowired.java │ │ └── RouteNode.java │ │ ├── enums │ │ ├── NodeType.java │ │ └── Type.java │ │ ├── model │ │ └── Node.java │ │ └── utils │ │ └── RouteUtils.java └── settings.gradle ├── jimu-sample-project ├── .gitignore ├── AptHotfix │ ├── .gitignore │ ├── build.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── jimu │ │ │ └── hotfix │ │ │ ├── AutowiredProcessorHotfix.java │ │ │ └── RouterProcessorHotfix.java │ │ └── resources │ │ └── META-INF │ │ └── services │ │ └── javax.annotation.processing.Processor ├── UIRouterTable │ ├── AppRouterTable.txt │ ├── KotlinRouterTable.txt │ └── ShareRouterTable.txt ├── app │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── luojilab │ │ │ └── componentdemo │ │ │ └── UiRouterTest.java │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── luojilab │ │ │ └── componentdemo │ │ │ ├── DemoActivity.java │ │ │ ├── DispatcherActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── application │ │ │ └── AppApplication.java │ │ │ ├── msg │ │ │ ├── AppComponentEventManager.java │ │ │ ├── Foo.java │ │ │ ├── MainProcessMsgService.java │ │ │ ├── Msg1Activity.java │ │ │ ├── Msg2Activity.java │ │ │ ├── Msg3Activity.java │ │ │ ├── RemoteMsgService.java │ │ │ └── event │ │ │ │ ├── EventA.java │ │ │ │ └── EventB.java │ │ │ ├── router │ │ │ ├── UiRouterDemoActivity.java │ │ │ └── cases │ │ │ │ ├── Demo1Activity.java │ │ │ │ ├── Demo2Activity.java │ │ │ │ ├── Demo3Activity.java │ │ │ │ ├── Demo4Activity.java │ │ │ │ ├── Demo5Activity.java │ │ │ │ ├── Demo6Activity.java │ │ │ │ ├── Demo7Activity.java │ │ │ │ ├── Demo8Activity.java │ │ │ │ └── TestActivity.java │ │ │ └── utils │ │ │ └── Utils.java │ │ └── res │ │ ├── drawable │ │ ├── ic_dashboard_black_24dp.xml │ │ ├── ic_home_black_24dp.xml │ │ └── ic_notifications_black_24dp.xml │ │ ├── layout │ │ ├── activity_demo.xml │ │ ├── activity_main.xml │ │ ├── activity_msg.xml │ │ ├── activity_test.xml │ │ └── activity_ui_router_demo.xml │ │ ├── menu │ │ └── navigation.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── dimens.xml │ │ └── strings.xml ├── basiclib │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com.luojilab.component.basiclib │ │ │ └── ToastManager.java │ │ └── res │ │ └── values │ │ └── strings.xml ├── basicres │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── luojilab │ │ │ └── component │ │ │ └── basicres │ │ │ ├── BaseActivity.java │ │ │ └── BaseApplication.java │ │ └── res │ │ └── values │ │ ├── color.xml │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── buildSrc │ ├── build.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── JimuHotfix.java │ │ └── resources │ │ └── META-INF │ │ └── gradle-plugins │ │ └── JimuHotfix.properties ├── componentservice │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── luojilab │ │ │ └── componentservice │ │ │ └── ExampleInstrumentedTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── luojilab │ │ │ │ └── componentservice │ │ │ │ ├── readerbook │ │ │ │ └── ReadBookService.java │ │ │ │ └── share │ │ │ │ └── bean │ │ │ │ ├── Author.java │ │ │ │ └── AuthorKt.kt │ │ └── res │ │ │ └── values │ │ │ └── strings.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── luojilab │ │ └── componentservice │ │ └── ExampleUnitTest.java ├── gradle.properties ├── gradlew ├── gradlew.bat ├── readercomponent │ ├── .gitignore │ ├── UIRouterTable │ │ └── ShareRouterTable.txt │ ├── build.gradle │ ├── gradle.properties │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── luojilab │ │ │ └── component │ │ │ └── componentlib │ │ │ └── msg │ │ │ └── EventManagerTest.java │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── luojilab │ │ │ └── reader │ │ │ ├── ReaderActivity.java │ │ │ ├── ReaderFragment.java │ │ │ ├── applike │ │ │ └── ReaderAppLike.java │ │ │ └── serviceimpl │ │ │ ├── ReadBookServiceImpl.java │ │ │ └── ReadBookServiceImplKotlin.kt │ │ ├── res │ │ ├── layout │ │ │ ├── activity_reader.xml │ │ │ └── readerbook_fragment_reader.xml │ │ └── values │ │ │ └── strings.xml │ │ └── runalone │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── luojilab │ │ │ └── reader │ │ │ └── runalone │ │ │ ├── ReaderTestActivity.java │ │ │ └── application │ │ │ └── ReaderApplication.java │ │ ├── mergedManifest.xml │ │ └── res │ │ ├── layout │ │ └── readerbook_activity_test.xml │ │ └── values │ │ └── strings.xml ├── settings.gradle ├── sharecomponent │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── luojilab │ │ │ └── share │ │ │ └── ExampleInstrumentedTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── luojilab │ │ │ │ └── share │ │ │ │ ├── BookShareEditActivity.java │ │ │ │ ├── applike │ │ │ │ └── ShareApplike.java │ │ │ │ ├── bean │ │ │ │ ├── AppShareBean.java │ │ │ │ └── BookShareBean.java │ │ │ │ └── core │ │ │ │ ├── AbsShareBean.java │ │ │ │ ├── IShareApi.java │ │ │ │ └── SampleShareCore.java │ │ ├── res │ │ │ ├── layout │ │ │ │ └── share_activity_share.xml │ │ │ └── values │ │ │ │ └── strings.xml │ │ └── runalone │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com.luojilab.share.runalone │ │ │ │ ├── DispatcherActivity.java │ │ │ │ └── application │ │ │ │ └── ShareApplication.java │ │ │ └── mergedManifest.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── luojilab │ │ └── share │ │ └── ExampleUnitTest.java └── sharecomponentkotlin │ ├── .gitignore │ ├── build.gradle │ ├── gradle.properties │ ├── proguard-rules.pro │ └── src │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── luojilab │ │ │ └── share │ │ │ └── kotlin │ │ │ ├── JavaTarget.java │ │ │ ├── ShareMessageActivity.kt │ │ │ └── applike │ │ │ └── KotlinAppLike.kt │ ├── res │ │ ├── layout │ │ │ └── kotlin_activity_share.xml │ │ └── values │ │ │ └── strings.xml │ └── runalone │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com.luojilab.share.runalone │ │ │ └── application │ │ │ ├── KotlinApplication.kt │ │ │ └── MainActivity.kt │ │ └── mergedManifest.xml │ └── test │ └── java │ └── com │ └── luojilab │ └── share │ └── kotlin │ └── ExampleUnitTest.java ├── src_build └── main │ └── java │ └── jimu │ └── Consts.java ├── stop_gradle.bat └── 得到组件化改造大流程 by leobert.png /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | /local_repo -------------------------------------------------------------------------------- /jimu-core/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | /gradle 9 | /gradle.properties 10 | -------------------------------------------------------------------------------- /jimu-core/bintrayv1.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.jfrog.bintray' 2 | 3 | version = libraryVersion 4 | 5 | if (project.hasProperty("android")) { // Android libraries 6 | task sourcesJar(type: Jar) { 7 | classifier = 'sources' 8 | from android.sourceSets.main.java.srcDirs 9 | } 10 | 11 | task javadoc(type: Javadoc) { 12 | options.encoding "UTF-8" 13 | options.charSet 'UTF-8' 14 | source = android.sourceSets.main.java.srcDirs 15 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 16 | } 17 | } else { // Java libraries 18 | task sourcesJar(type: Jar, dependsOn: classes) { 19 | classifier = 'sources' 20 | from sourceSets.main.allSource 21 | } 22 | } 23 | 24 | task javadocJar(type: Jar, dependsOn: javadoc) { 25 | classifier = 'javadoc' 26 | from javadoc.destinationDir 27 | } 28 | 29 | artifacts { 30 | archives javadocJar 31 | archives sourcesJar 32 | } 33 | 34 | // Bintray 35 | Properties properties = new Properties() 36 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 37 | 38 | bintray { 39 | user = properties.getProperty("bintray.user") 40 | key = properties.getProperty("bintray.apikey") 41 | 42 | configurations = ['archives'] 43 | pkg { 44 | repo = bintrayRepo 45 | name = bintrayName 46 | desc = libraryDescription 47 | websiteUrl = siteUrl 48 | vcsUrl = gitUrl 49 | licenses = allLicenses 50 | publish = true 51 | publicDownloadNumbers = true 52 | version { 53 | desc = libraryDescription 54 | gpg { 55 | sign = true //Determines whether to GPG sign the files. The default is false 56 | passphrase = properties.getProperty("bintray.gpg.password") 57 | //Optional. The passphrase for GPG signing' 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /jimu-core/build-gradle/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /jimu-core/build-gradle/src/main/groovy/com.dd.buildgradle/exten/ComExtension.groovy: -------------------------------------------------------------------------------- 1 | package com.dd.buildgradle.exten 2 | 3 | class ComExtension { 4 | 5 | /** 6 | * 是否自动注册组件,true则会使用字节码插入的方式自动注册代码 7 | * false的话,需要手动使用反射的方式来注册. 8 | * 9 | * 10 | * represent the strategy used to load the sub component. 11 | * if it is true in the host module(the one you are building), 12 | * the plugin will try to generate auto load codes in the Application 13 | * class of the host module. caution: Applike notated with 14 | * {@link com.luojilab.component.componentlib.applicationlike.RegisterCompManual} 15 | * won't be auto load 16 | * 17 | */ 18 | boolean isRegisterCompoAuto = false 19 | 20 | /** 21 | * 当前组件的applicationName,用于字节码插入。 22 | * 当isRegisterCompoAuto==true的时候是必须的 23 | */ 24 | String applicationName 25 | 26 | String runAloneManifest 27 | String originalManifest 28 | String targetManifest 29 | 30 | boolean enableManifestMerge = true 31 | 32 | /** 33 | * 是否使用Maat进行按序初始化业务,如果使用则需要自动织入代码 34 | * */ 35 | boolean useMaat = true 36 | } -------------------------------------------------------------------------------- /jimu-core/build-gradle/src/main/groovy/com.dd.buildgradle/util/StringUtil.java: -------------------------------------------------------------------------------- 1 | package com.dd.buildgradle.util; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | public class StringUtil { 6 | /** 7 | * is maven repo dependencyLe 8 | */ 9 | public static boolean isMavenArtifact(String str) { 10 | if (str == null || str.isEmpty()) { 11 | return false; 12 | } 13 | return Pattern.matches("\\S+(\\.\\S+)+:\\S+(:\\S+)?(@\\S+)?", str); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jimu-core/build-gradle/src/main/groovy/com/luojilab/component/componentlib/applicationlike/RegisterCompManual.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.component.componentlib.applicationlike; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | 6 | /** 7 | *

Package: com.dd.buildgradle.exten

8 | *

Project: jimu-core

9 | *

Classname: RegisterCompManual

10 | *

Description: annotate the Applike with this annotation 11 | * represent to register it manual. 12 | * it will never auto register

13 | * Created by leobert on 2018/5/10. 14 | */ 15 | @Retention(RetentionPolicy.CLASS) 16 | public @interface RegisterCompManual { 17 | } 18 | -------------------------------------------------------------------------------- /jimu-core/build-gradle/src/main/groovy/org/github/jimu/msg/MsgBridgeService.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg; 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 | *

Package: org.github.jimu.msg

10 | *

Project: jimu-core

11 | *

Classname: MsgBridgeService

12 | *

Description: annotation for MessageBridgeService

13 | * Created by leobert on 2018/6/11. 14 | */ 15 | @Target(ElementType.TYPE) 16 | @Retention(RetentionPolicy.RUNTIME) // not sure if it is applicable to using CLASS 17 | public @interface MsgBridgeService { 18 | /** 19 | * @return the full name of the process that the service runs in 20 | */ 21 | String workProcessName(); 22 | } 23 | -------------------------------------------------------------------------------- /jimu-core/build-gradle/src/main/groovy/org/github/jimu/msg/ServiceInfoBean.groovy: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg 2 | 3 | import javassist.CtClass 4 | 5 | class ServiceInfoBean { 6 | String fullProcessName 7 | CtClass serviceClass 8 | 9 | ServiceInfoBean(String fullProcessName, CtClass serviceClass) { 10 | this.fullProcessName = fullProcessName 11 | this.serviceClass = serviceClass 12 | } 13 | 14 | @Override 15 | String toString() { 16 | return "ServiceInfoBean{" + 17 | "fullProcessName='" + fullProcessName + '\'' + 18 | ", serviceClass=" + serviceClass + 19 | '}' 20 | } 21 | } -------------------------------------------------------------------------------- /jimu-core/build-gradle/src/main/groovy/osp/leobert/magnet/Log.groovy: -------------------------------------------------------------------------------- 1 | package osp.leobert.magnet 2 | 3 | /** 4 | *

Package: osp.leobert.magnet

5 | *

Classname: Log

6 | * Created by leobert on 2020/8/24. 7 | */ 8 | public class Log { 9 | public static void info(String msg) { 10 | System.out.println(msg) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /jimu-core/build-gradle/src/main/groovy/osp/leobert/magnet/plugin/manifest/XmlnsSweeper.groovy: -------------------------------------------------------------------------------- 1 | package osp.leobert.magnet.plugin.manifest 2 | 3 | import osp.leobert.magnet.Log 4 | 5 | class XmlnsSweeper { 6 | 7 | static final String TEMP_NS_PREFIX = "TEMP_NS_PREFIX" 8 | static final String STANDARD_NS_PREFIX = "xmlns" 9 | // static final String ANDROID_MANIFEST_NAME = "AndroidManifest.xml" 10 | 11 | static final List xmlnsShouldSweep = ["android=\"http://schemas.android.com/apk/res/android\""] 12 | 13 | XmlnsSweeper() { 14 | } 15 | 16 | static void sweep(String processManifestOutputFilePath) { 17 | 18 | File manifestFile = new File(processManifestOutputFilePath) 19 | Log.info("start sweep manifest xmlns at " + processManifestOutputFilePath) 20 | if (!manifestFile.exists() /*|| manifestFile.name != ANDROID_MANIFEST_NAME*/) { 21 | return 22 | } 23 | String manifestFileContent = manifestFile.text 24 | Log.info("\r\n\r\nstart sweep manifest xmlns:\r\n" + manifestFileContent) 25 | StringBuilder builder = new StringBuilder(manifestFileContent) 26 | 27 | xmlnsShouldSweep.each { String xmlnsItem -> 28 | 29 | String fullName = STANDARD_NS_PREFIX + ":" + xmlnsItem 30 | 31 | // maintain first xmlns 32 | int firstIndex = builder.indexOf(fullName) 33 | if (firstIndex < 0) { 34 | return 35 | } 36 | builder.replace(firstIndex, firstIndex + STANDARD_NS_PREFIX.length(), TEMP_NS_PREFIX) 37 | 38 | // replace all except first xmlns 39 | replaceAll(builder, fullName, "") 40 | 41 | // recovery first item 42 | replaceAll(builder, TEMP_NS_PREFIX, STANDARD_NS_PREFIX) 43 | 44 | } 45 | 46 | manifestFile.text = builder.toString() 47 | } 48 | 49 | static void replaceAll(StringBuilder sb, String regex, String replacement) { 50 | String aux = sb.toString() 51 | aux = aux.replaceAll(regex, replacement) 52 | sb.setLength(0) 53 | sb.append(aux) 54 | } 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /jimu-core/build-gradle/src/main/resources/META-INF/gradle-plugins/com.dd.comgradle.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.dd.buildgradle.ComBuild -------------------------------------------------------------------------------- /jimu-core/build-gradle/src/test/groovy/util/ComCodeTransformTest.groovy: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import com.dd.buildgradle.ComCodeTransform 4 | import javassist.ClassPool 5 | import javassist.CtClass 6 | import org.github.jimu.msg.ServiceInfoBean 7 | 8 | public class ComCodeTransformTest { 9 | 10 | @org.junit.Test 11 | public void testGenerateEventManagerInitializeCode() { 12 | 13 | CtClass ctClass = ClassPool.getDefault().makeClass("com.sss.Test"); 14 | List serviceInfoBeans = [] 15 | serviceInfoBeans.add(new ServiceInfoBean("test",ctClass)) 16 | String s = ComCodeTransform.generateEventManagerInitializeCode(serviceInfoBeans) 17 | 18 | System.out.println(s) 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /jimu-core/build-gradle/src/test/groovy/util/StringUtilTest.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import com.dd.buildgradle.util.StringUtil; 4 | 5 | import static org.junit.Assert.assertFalse; 6 | import static org.junit.Assert.assertTrue; 7 | 8 | public class StringUtilTest { 9 | 10 | @org.junit.Test 11 | public void isMavenArtifact() { 12 | assertTrue(StringUtil.isMavenArtifact("com.android.databinding:dataBinder:1.0-rc4@aar")); 13 | assertTrue(StringUtil.isMavenArtifact("com.android.databinding:dataBinder:1.0-rc4@jar")); 14 | assertTrue(StringUtil.isMavenArtifact("com.android.databinding:dataBinder:1.0-rc4")); 15 | assertTrue(StringUtil.isMavenArtifact("com.android.databinding:dataBinder:1.0")); 16 | assertTrue(StringUtil.isMavenArtifact("com.android.databinding:dataBinder")); 17 | } 18 | 19 | @org.junit.Test 20 | public void notMavenArtifact() { 21 | assertFalse(StringUtil.isMavenArtifact("app")); 22 | assertFalse(StringUtil.isMavenArtifact(":app")); 23 | assertFalse(StringUtil.isMavenArtifact(":modules:umeng_bbs")); 24 | assertFalse(StringUtil.isMavenArtifact("modules:umeng_bbs")); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /jimu-core/build-gradle/src/test/java/com/dd/buildgradle/util/StringUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.dd.buildgradle.util; 2 | 3 | import static org.junit.Assert.assertFalse; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | public class StringUtilTest { 7 | 8 | @org.junit.Test 9 | public void isMavenArtifact() { 10 | assertTrue(StringUtil.isMavenArtifact("com.android.databinding:dataBinder:1.0-rc4@aar")); 11 | assertTrue(StringUtil.isMavenArtifact("com.android.databinding:dataBinder:1.0-rc4@jar")); 12 | assertTrue(StringUtil.isMavenArtifact("com.android.databinding:dataBinder:1.0-rc4")); 13 | assertTrue(StringUtil.isMavenArtifact("com.android.databinding:dataBinder:1.0")); 14 | assertTrue(StringUtil.isMavenArtifact("com.android.databinding:dataBinder")); 15 | } 16 | 17 | @org.junit.Test 18 | public void notMavenArtifact() { 19 | assertFalse(StringUtil.isMavenArtifact("app")); 20 | assertFalse(StringUtil.isMavenArtifact(":app")); 21 | assertFalse(StringUtil.isMavenArtifact(":modules:umeng_bbs")); 22 | assertFalse(StringUtil.isMavenArtifact("modules:umeng_bbs")); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /jimu-core/buildSrc/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "kotlin" 2 | 3 | sourceSets { 4 | main { 5 | java { 6 | srcDirs "../../src_build/main/java" 7 | } 8 | } 9 | } 10 | buildscript { 11 | ext.kotlin_version = "1.4.21" 12 | repositories { 13 | jcenter() 14 | } 15 | dependencies { 16 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 17 | gradleApi() 18 | } 19 | } 20 | repositories { 21 | // mavenCentral() 22 | // google() 23 | jcenter() 24 | } -------------------------------------------------------------------------------- /jimu-core/componentlib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /jimu-core/componentlib/release/component-baselib-0.0.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mqzhangw/JIMU/9d573de883f5fe5c0d649699931c1c050341e721/jimu-core/componentlib/release/component-baselib-0.0.1.1.jar -------------------------------------------------------------------------------- /jimu-core/componentlib/release/component-baselib-0.0.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mqzhangw/JIMU/9d573de883f5fe5c0d649699931c1c050341e721/jimu-core/componentlib/release/component-baselib-0.0.2.jar -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/com/luojilab/component/componentlib/applicationlike/IApplicationLike.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.component.componentlib.applicationlike; 2 | 3 | /** 4 | * Created by mrzhang on 2017/6/15. 5 | */ 6 | 7 | public interface IApplicationLike { 8 | 9 | void onCreate(); 10 | 11 | void onStop(); 12 | } 13 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/com/luojilab/component/componentlib/applicationlike/RegisterCompManual.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.component.componentlib.applicationlike; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | 6 | /** 7 | *

Package: com.dd.buildgradle.exten

8 | *

Project: jimu-core

9 | *

Classname: RegisterCompManual

10 | *

Description: notate the Applike with this annotation 11 | * means that:you will register it manually. the auto register strategy will escape this module 12 | * it will never auto register

13 | * Created by leobert on 2018/5/10. 14 | */ 15 | @Retention(RetentionPolicy.CLASS) 16 | public @interface RegisterCompManual { 17 | } 18 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/com/luojilab/component/componentlib/exceptions/ParamException.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.component.componentlib.exceptions; 2 | 3 | /** 4 | *

Package: com.luojilab.component.componentlib.exceptions

5 | *

Project: DDComponentForAndroid

6 | *

Classname: ParamException

7 | *

Description: missing required params exception

8 | * Created by leobert on 12/01/2018. 9 | */ 10 | 11 | public final class ParamException extends UiRouterException { 12 | public ParamException(String paramName) { 13 | super(paramName + " is required param, but didn't contains in the bundle;"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/com/luojilab/component/componentlib/exceptions/UiRouterException.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.component.componentlib.exceptions; 2 | 3 | /** 4 | *

Package: com.luojilab.component.componentlib.exceptions

5 | *

Project: DDComponentForAndroid

6 | *

Classname: UiRouterException

7 | *

Description: none matched node for the target navigation url exception

8 | * Created by leobert on 11/01/2018. 9 | */ 10 | 11 | public abstract class UiRouterException extends Exception { 12 | public UiRouterException() { 13 | } 14 | 15 | public UiRouterException(String message) { 16 | super(message); 17 | } 18 | 19 | public UiRouterException(String message, Throwable cause) { 20 | super(message, cause); 21 | } 22 | 23 | public UiRouterException(Throwable cause) { 24 | super(cause); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/com/luojilab/component/componentlib/log/ILogger.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.component.componentlib.log; 2 | 3 | import com.luojilab.component.componentlib.log.impl.DefaultLogger; 4 | 5 | /** 6 | *

Package: com.luojilab.component.componentlib.log

7 | *

Project: DDComponentForAndroid

8 | *

Classname: ILogger

9 | *

Description: logger

10 | * Created by leobert on 11/01/2018. 11 | */ 12 | 13 | public interface ILogger { 14 | String defaultTag = "[DD-Compo]"; 15 | 16 | ILogger logger = new DefaultLogger(defaultTag); 17 | 18 | void showLog(boolean isShowLog); 19 | 20 | void showStackTrace(boolean isShowStackTrace); 21 | 22 | void showMonitor(boolean isShowMonitor); 23 | 24 | void debug(String tag, String message); 25 | 26 | void info(String tag, String message); 27 | 28 | void warning(String tag, String message); 29 | 30 | void error(String tag, String message); 31 | 32 | void monitor(String message); 33 | 34 | boolean isMonitorMode(); 35 | 36 | String getDefaultTag(); 37 | 38 | void setDefaultTag(String defaultTag); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/com/luojilab/component/componentlib/router/ISyringe.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.component.componentlib.router; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.luojilab.component.componentlib.exceptions.ParamException; 6 | 7 | /** 8 | *

Package: com.luojilab.component.componentlib.di.route

9 | *

Project: DDComponentForAndroid

10 | *

Classname: ISyringe

11 | *

Description: desc the function of Syringe, one that used to inject 12 | * sth. to a container

13 | * Created by leobert on 2017/9/18. 14 | */ 15 | 16 | public interface ISyringe { 17 | /** 18 | * @param self the container itself, members to be inject into have been annotated 19 | * with one annotation called Autowired 20 | */ 21 | void inject(Object self); 22 | 23 | void preCondition(Bundle bundle) throws ParamException; 24 | } 25 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/com/luojilab/component/componentlib/router/ui/IUIRouter.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.component.componentlib.router.ui; 2 | 3 | /** 4 | * router behaviors for component type, sub of {@link IComponentRouter} 5 | * Created by mrzhang on 2017/6/20. 6 | */ 7 | 8 | public interface IUIRouter extends IComponentRouter { 9 | 10 | int PRIORITY_NORMAL = 0; 11 | int PRIORITY_LOW = -1000; 12 | int PRIORITY_HEIGHT = 1000; 13 | 14 | void registerUI(IComponentRouter router, int priority); 15 | 16 | void registerUI(IComponentRouter router); 17 | 18 | void registerUI(String host); 19 | 20 | void registerUI(String host, int priority); 21 | 22 | void unregisterUI(IComponentRouter router); 23 | 24 | void unregisterUI(String host); 25 | } 26 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/com/luojilab/component/componentlib/router/ui/VerifyResult.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.component.componentlib.router.ui; 2 | 3 | /** 4 | *

Package: com.luojilab.component.componentlib.router.ui

5 | *

Project: DDComponentForAndroid

6 | *

Classname: VerifyResult

7 | *

Description: TODO

8 | * Created by leobert on 23/02/2018. 9 | */ 10 | 11 | public class VerifyResult { 12 | private final boolean isSuccess; 13 | 14 | private Throwable throwable; 15 | 16 | public VerifyResult(boolean isSuccess) { 17 | this.isSuccess = isSuccess; 18 | } 19 | 20 | public VerifyResult(boolean isSuccess, Throwable throwable) { 21 | this.isSuccess = isSuccess; 22 | this.throwable = throwable; 23 | } 24 | 25 | public boolean isSuccess() { 26 | return isSuccess; 27 | } 28 | 29 | public Throwable getThrowable() { 30 | return throwable; 31 | } 32 | 33 | public void setThrowable(Throwable throwable) { 34 | this.throwable = throwable; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/com/luojilab/component/componentlib/service/AutowiredService.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.component.componentlib.service; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.luojilab.component.componentlib.exceptions.ParamException; 6 | 7 | /** 8 | *

Package: com.luojilab.component.componentlib.di

9 | *

Project: DDComponentForAndroid

10 | *

Classname: AutowiredService

11 | *

Description: Autowired Dependency inject

12 | * Created by leobert on 2017/9/18. 13 | */ 14 | 15 | public interface AutowiredService { 16 | boolean THROW_CONFIG = true; 17 | 18 | /** 19 | * Autowired core. 20 | * 21 | * @param instance the instance who need autowired. 22 | */ 23 | void autowire(Object instance); 24 | 25 | void preCondition(Class targetActivityClz, Bundle params) throws ParamException; 26 | 27 | 28 | class Factory { 29 | private volatile static AutowiredService autowiredServiceImpl; 30 | 31 | public static AutowiredService getSingletonImpl() { 32 | if (autowiredServiceImpl == null) { 33 | synchronized (AutowiredService.class) { 34 | if (autowiredServiceImpl == null) 35 | autowiredServiceImpl = new AutowiredServiceImpl(); 36 | } 37 | } 38 | return autowiredServiceImpl; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/com/luojilab/component/componentlib/service/JsonService.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.component.componentlib.service; 2 | 3 | 4 | import java.util.List; 5 | 6 | /** 7 | *

Package: com.luojilab.component.json

8 | *

Project: DDComponentForAndroid

9 | *

Classname: JsonService

10 | *

Description: APIs provided by the JsonComponent. 11 | * you can implement it via fast-json,gson,jackson etc. 12 | *

13 | * currently only basic functions contains! 14 | *

15 | * Created by leobert on 2017/9/18. 16 | */ 17 | 18 | public interface JsonService { 19 | 20 | T parseObject(String text, Class clazz); 21 | 22 | List parseArray(String text, Class clazz); 23 | 24 | String toJsonString(Object instance); 25 | 26 | class Factory { 27 | private volatile static JsonService jsonService; 28 | 29 | public static JsonService getSingletonImpl() { 30 | if (jsonService == null) { 31 | synchronized (Factory.class) { 32 | if (jsonService == null) 33 | jsonService = new JsonServiceImpl(); 34 | } 35 | } 36 | return jsonService; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/com/luojilab/component/componentlib/service/JsonServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.component.componentlib.service; 2 | 3 | /** 4 | * Created by mrzhang on 2017/12/14. 5 | */ 6 | 7 | import com.google.gson.Gson; 8 | import com.google.gson.reflect.TypeToken; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | *

Package: com.luojilab.component.json.serviceimpl

14 | *

Project: DDComponentForAndroid

15 | *

Classname: JsonServiceImpl

16 | *

Description: implement of {@link JsonService}, in this, 17 | * base on fast-json 18 | *

19 | * Created by leobert on 2017/9/18. 20 | */ 21 | 22 | class JsonServiceImpl implements JsonService { 23 | @Override 24 | public T parseObject(String text, Class clazz) { 25 | Gson gson = new Gson(); 26 | return gson.fromJson(text, clazz); 27 | } 28 | 29 | @Override 30 | public List parseArray(String text, Class clazz) { 31 | Gson gson = new Gson(); 32 | return gson.fromJson(text, new TypeToken>() { 33 | }.getType()); 34 | } 35 | 36 | @Override 37 | public String toJsonString(Object instance) { 38 | Gson gson = new Gson(); 39 | return gson.toJson(instance); 40 | } 41 | } -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/AriseAt.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg; 2 | 3 | import com.luojilab.component.componentlib.log.ILogger; 4 | 5 | /** 6 | *

Package: org.github.jimu.msg.bean

7 | *

Project: JIMU

8 | *

Classname: AriseAt

9 | *

Description: represent the relationship between the 'poster' and the 'subscriber' 10 | * of their process

11 | * Created by leobert on 2018/4/25. 12 | */ 13 | public class AriseAt { 14 | 15 | private String processFullName; 16 | private boolean isLocal; 17 | 18 | private AriseAt(String processFullName, boolean isLocal) { 19 | this.processFullName = processFullName; 20 | this.isLocal = isLocal; 21 | } 22 | 23 | public String getProcessFullName() { 24 | return processFullName; 25 | } 26 | 27 | public static AriseAt local() { 28 | return new AriseAt(Utils.getProcessName(), true); 29 | } 30 | 31 | public static AriseAt remote(String processFullName) { 32 | return new AriseAt(processFullName, false); 33 | } 34 | 35 | public boolean isLocal() { 36 | return isLocal; 37 | } 38 | 39 | public void log() { 40 | ILogger.logger.monitor("AriseAt:{ processFullName:" + processFullName + "}"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/Constants.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg; 2 | 3 | /** 4 | *

Package: org.github.jimu.msg

5 | *

Project: JIMU

6 | *

Classname: Constants

7 | *

Description: Constants

8 | * Created by leobert on 2018/4/24. 9 | */ 10 | public interface Constants { 11 | int WHAT_SEND_CROSS_PROCESS_EVENT = 10000; 12 | int WHAT_RECEIVE_EVENT_FROM_REMOTE = 2; 13 | 14 | int WHAT_SUBSCRIBE_CROSS_PROCESS_EVENT = 9999; 15 | 16 | String BUNDLE_STR_EVENT_CLZ = "bundle_str_event_clz"; 17 | String BUNDLE_PARCEL_EVENT = "bundle_event_parcelable"; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/ConsumeOn.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg; 2 | 3 | /** 4 | *

Package: org.github.jimu.msg

5 | *

Project: JIMU

6 | *

Classname: ConsumeOn

7 | *

Description: enum, thread the callback will be invoked

8 | * Created by leobert on 2018/4/26. 9 | */ 10 | public enum ConsumeOn { 11 | Main,Background 12 | } 13 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/EventListener.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg; 2 | 3 | import org.github.jimu.msg.bean.EventBean; 4 | 5 | /** 6 | *

Package: org.github.jimu.msg

7 | *

Project: JIMU

8 | *

Classname: EventListener

9 | *

Description: callbacks for the event

10 | * Created by leobert on 2018/4/25. 11 | */ 12 | public interface EventListener { 13 | void onEvent(T event); 14 | 15 | EventListener NONE_NULL = new EventListener() { 16 | @Override 17 | public void onEvent(EventBean event) { 18 | } 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/MsgBridgeService.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg; 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 | *

Package: org.github.jimu.msg

10 | *

Project: jimu-core

11 | *

Classname: MsgBridgeService

12 | *

Description: annotation for MessageBridgeService

13 | * Created by leobert on 2018/6/11. 14 | */ 15 | @Target(ElementType.TYPE) 16 | @Retention(RetentionPolicy.RUNTIME) // not sure if it is applicable to using CLASS 17 | public @interface MsgBridgeService { 18 | /** 19 | * @return the full name of the process that the service runs in 20 | */ 21 | String workProcessName(); 22 | } 23 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/Utils.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg; 2 | 3 | import android.os.Looper; 4 | import android.text.TextUtils; 5 | 6 | import java.io.BufferedReader; 7 | import java.io.FileReader; 8 | import java.io.IOException; 9 | 10 | /** 11 | *

Package: org.github.jimu.msg

12 | *

Project: JIMU

13 | *

Classname: Utils

14 | *

Description: utilities

15 | * Created by leobert on 2018/4/26. 16 | */ 17 | public class Utils { 18 | public static String getProcessName() { 19 | BufferedReader reader = null; 20 | try { 21 | reader = new BufferedReader(new FileReader("/proc/" + android.os.Process.myPid() + "/cmdline")); 22 | String processName = reader.readLine(); 23 | if (!TextUtils.isEmpty(processName)) { 24 | processName = processName.trim(); 25 | } 26 | return processName; 27 | } catch (Throwable throwable) { 28 | throwable.printStackTrace(); 29 | } finally { 30 | try { 31 | if (reader != null) { 32 | reader.close(); 33 | } 34 | } catch (IOException exception) { 35 | exception.printStackTrace(); 36 | } 37 | } 38 | return null; 39 | } 40 | 41 | public static boolean isMainThread() { 42 | return Looper.myLooper() == Looper.getMainLooper(); 43 | } 44 | 45 | static void validateCompoEventManagerInterface(Class service) { 46 | if (!service.isInterface()) { 47 | throw new IllegalArgumentException("CompoEventManagerAPI must be declared as interfaces."); 48 | } 49 | if (service.getInterfaces().length > 0) { 50 | throw new IllegalArgumentException("CompoEventManagerAPI interfaces must not extend any other interfaces."); 51 | } 52 | } 53 | 54 | public static void checkNotNull(Object obj, String msg) { 55 | if (obj == null) 56 | throw new NullPointerException("null check failed; " + msg); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/bean/ConsumerMeta.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg.bean; 2 | 3 | 4 | import org.github.jimu.msg.ConsumeOn; 5 | import org.github.jimu.msg.EventListener; 6 | import org.github.jimu.msg.Utils; 7 | 8 | /** 9 | *

Package: org.github.jimu.msg.bean

10 | *

Project: jimu-core

11 | *

Classname: ConsumerMeta

12 | *

Description: mate info of the consumer

13 | * Created by leobert on 2018/7/30. 14 | */ 15 | public final class ConsumerMeta { 16 | private ConsumeOn consumeOn; 17 | private EventListener eventListener; 18 | private String process; 19 | 20 | public ConsumeOn getConsumeOn() { 21 | return consumeOn; 22 | } 23 | 24 | public EventListener getEventListener() { 25 | return eventListener; 26 | } 27 | 28 | public String getProcess() { 29 | return process; 30 | } 31 | 32 | private ConsumerMeta(Builder builder) { 33 | consumeOn = builder.consumeOn; 34 | eventListener = builder.eventListener; 35 | process = builder.process; 36 | Utils.checkNotNull(eventListener, "eventListener cannot be null," + 37 | "call ConsumerMate.Builder.eventListener before build"); 38 | 39 | Utils.checkNotNull(process, "process cannot be null, you can use empty string for the default main process"); 40 | } 41 | 42 | 43 | public static Builder newBuilder() { 44 | return new Builder(); 45 | } 46 | 47 | 48 | public static final class Builder { 49 | private ConsumeOn consumeOn = ConsumeOn.Main; 50 | private EventListener eventListener; 51 | /** 52 | * "" mean the default process when application is created 53 | */ 54 | private String process = ""; 55 | 56 | private Builder() { 57 | } 58 | 59 | public Builder consumeOn(ConsumeOn val) { 60 | consumeOn = val; 61 | return this; 62 | } 63 | 64 | 65 | public Builder process(String val) { 66 | process = val; 67 | return this; 68 | } 69 | 70 | public Builder currentProcess() { 71 | process = Utils.getProcessName(); 72 | return this; 73 | } 74 | 75 | public Builder eventListener(EventListener val) { 76 | eventListener = val; 77 | return this; 78 | } 79 | 80 | public ConsumerMeta build() { 81 | return new ConsumerMeta<>(this); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/bean/EventBean.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg.bean; 2 | 3 | /** 4 | *

Package: org.github.jimu.msg.bean

5 | *

Project: JIMU

6 | *

Classname: EventBean

7 | *

Description:

8 | * Created by leobert on 2018/4/26. 9 | */ 10 | public interface EventBean { 11 | } 12 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/bean/RemoteEventBean.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg.bean; 2 | 3 | import android.os.Parcelable; 4 | 5 | /** 6 | *

Package: org.github.jimu.msg.bean

7 | *

Project: JIMU

8 | *

Classname: RemoteEventBean

9 | *

Description: TODO

10 | * Created by leobert on 2018/4/26. 11 | */ 12 | public interface RemoteEventBean extends EventBean, Parcelable { 13 | } 14 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/bean/State.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg.bean; 2 | 3 | import android.support.annotation.NonNull; 4 | import android.support.annotation.Nullable; 5 | import android.support.annotation.VisibleForTesting; 6 | 7 | import org.github.jimu.msg.Utils; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | *

Package: org.github.jimu.msg.bean

14 | *

Project: JIMU

15 | *

Classname: State

16 | *

Description: TODO

17 | * Created by leobert on 2018/4/25. 18 | */ 19 | public class State { 20 | private final List eventQueue = new ArrayList<>(); 21 | public boolean onPosting= false; 22 | public final boolean onMainThread; 23 | 24 | public State() { 25 | onMainThread = Utils.isMainThread(); 26 | } 27 | 28 | public void addEvent2Queue(@NonNull T event) { 29 | eventQueue.add(event); 30 | } 31 | 32 | public boolean isQueueEmpty() { 33 | return eventQueue.isEmpty(); 34 | } 35 | 36 | @VisibleForTesting 37 | public int queneSize() { 38 | return eventQueue.size(); 39 | } 40 | 41 | @Nullable 42 | @SuppressWarnings("unchecked") 43 | public T peekFromQueue() { 44 | try { 45 | return (T) eventQueue.remove(0); 46 | } catch (IndexOutOfBoundsException e) { 47 | return null; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/core/MessageBridgeService.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg.core; 2 | 3 | import android.app.Service; 4 | import android.content.Intent; 5 | import android.os.IBinder; 6 | import android.os.Messenger; 7 | 8 | import com.luojilab.component.componentlib.log.ILogger; 9 | 10 | import org.github.jimu.msg.EventManager; 11 | import org.github.jimu.msg.Utils; 12 | 13 | /** 14 | *

Package: org.github.jimu.msg

15 | *

Project: JIMU

16 | *

Classname: MessageBridgeService

17 | *

Description: service for the binder used in cross process communication. 18 | * define the unique sub-class for the specific process, 19 | * and notate with {@link org.github.jimu.msg.MsgBridgeService} 20 | *

21 | * Created by leobert on 2018/4/25. 22 | * 23 | * @see org.github.jimu.msg.MsgBridgeService MsgBridgeService 24 | */ 25 | public abstract class MessageBridgeService extends Service { 26 | 27 | private Messenger currentProcessMessenger = new Messenger(new RemoteObservableHandler()); 28 | 29 | @Override 30 | public final IBinder onBind(Intent intent) { 31 | String pn = Utils.getProcessName(); 32 | ILogger.logger.monitor("set messenger in order: " + pn); 33 | EventManager.getInstance().updateMessenger(pn, currentProcessMessenger); 34 | return currentProcessMessenger.getBinder(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/core/MessageFactory.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg.core; 2 | 3 | import android.os.Bundle; 4 | import android.os.Message; 5 | import android.os.Messenger; 6 | import android.support.annotation.NonNull; 7 | 8 | import org.github.jimu.msg.Constants; 9 | import org.github.jimu.msg.bean.RemoteEventBean; 10 | 11 | /** 12 | *

Package: org.github.jimu.msg.core

13 | *

Project: JIMU

14 | *

Classname: MessageFactory

15 | *

Description: factory for message

16 | * Created by leobert on 2018/4/24. 17 | */ 18 | public class MessageFactory { 19 | public static final int WHAT_SUBSCRIBE_CROSS_PROCESS_EVENT = Constants.WHAT_SUBSCRIBE_CROSS_PROCESS_EVENT; 20 | 21 | public static final int WHAT_SEND_CROSS_PROCESS_EVENT = Constants.WHAT_SEND_CROSS_PROCESS_EVENT; 22 | 23 | public static final String BUNDLE_STR_EVENT_CLZ = Constants.BUNDLE_STR_EVENT_CLZ; 24 | 25 | public static final String BUNDLE_PARCEL_EVENT = Constants.BUNDLE_PARCEL_EVENT; 26 | 27 | 28 | /** 29 | * obtain subscribe message, contains the key-point information 30 | * of on cross-process subscriber and the event class it subscribes to 31 | * 32 | * @param consumerMessenger Local side Messenger,if the event arise at the remote, 33 | * remote will send it through this 34 | * @param eventClz Class of the event want to subscribe 35 | * @return the subscribe message 36 | */ 37 | public static Message obtainSubscribeMsg(Messenger consumerMessenger, Class eventClz) { 38 | Message message = Message.obtain(); 39 | message.what = WHAT_SUBSCRIBE_CROSS_PROCESS_EVENT; 40 | message.replyTo = consumerMessenger; 41 | Bundle bundle = new Bundle(); 42 | bundle.putString(BUNDLE_STR_EVENT_CLZ, eventClz.getName()); 43 | message.setData(bundle); 44 | return message; 45 | } 46 | 47 | public static Message obtainEventMsg(@NonNull T event) { 48 | Message message = Message.obtain();// new Message(); 49 | message.what = WHAT_SEND_CROSS_PROCESS_EVENT; 50 | Bundle bundle = new Bundle(); 51 | bundle.putString(BUNDLE_STR_EVENT_CLZ, event.getClass().getName()); 52 | bundle.putParcelable(BUNDLE_PARCEL_EVENT, event); 53 | message.setData(bundle); 54 | return message; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/core/SubscriberCache.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg.core; 2 | 3 | import org.github.jimu.msg.bean.EventBean; 4 | 5 | import java.util.HashMap; 6 | 7 | /** 8 | *

Package: org.github.jimu.msg.core

9 | *

Project: JIMU

10 | *

Classname: SubscriberCache

11 | *

Description: just avoid too verbose rawType

12 | * Created by leobert on 2018/4/27. 13 | */ 14 | public final class SubscriberCache extends HashMap> { 16 | 17 | public SubscriberCache(int initialCapacity, float loadFactor) { 18 | super(initialCapacity, loadFactor); 19 | } 20 | 21 | public SubscriberCache(int initialCapacity) { 22 | super(initialCapacity); 23 | } 24 | 25 | public SubscriberCache() { 26 | } 27 | 28 | @Override 29 | public SubscriberList get(Object key) { 30 | return super.get(key); 31 | } 32 | 33 | @Override 34 | public SubscriberList put(Class key, SubscriberList value) { 35 | return super.put(key, value); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/core/SubscriberList.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg.core; 2 | 3 | import org.github.jimu.msg.EventListener; 4 | import org.github.jimu.msg.bean.EventBean; 5 | 6 | import java.lang.ref.WeakReference; 7 | import java.util.concurrent.CopyOnWriteArrayList; 8 | 9 | /** 10 | *

Package: org.github.jimu.msg.core

11 | *

Project: JIMU

12 | *

Classname: SubscriberList

13 | *

Description: just lazy...

14 | * Created by leobert on 2018/4/27. 15 | */ 16 | public final class SubscriberList extends CopyOnWriteArrayList>> { 17 | 18 | @Override 19 | public WeakReference> get(int index) { 20 | return super.get(index); 21 | } 22 | 23 | public boolean removeCallback(EventListener listener) { 24 | boolean ret = false; 25 | for (int i = 0;i> ref = get(i); 27 | if (ref == null || ref.get() == null) 28 | continue; 29 | 30 | if (ref.get().equals(listener)) { 31 | ret = true; 32 | remove(ref); 33 | i--; 34 | ref.clear(); 35 | } 36 | } 37 | return ret; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/executor/CrossProcessPoster.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg.executor; 2 | 3 | import android.os.Messenger; 4 | import android.os.RemoteException; 5 | import android.support.annotation.NonNull; 6 | import android.support.annotation.Nullable; 7 | 8 | import com.luojilab.component.componentlib.log.ILogger; 9 | import org.github.jimu.msg.EventListener; 10 | import org.github.jimu.msg.bean.EventBean; 11 | import org.github.jimu.msg.bean.RemoteEventBean; 12 | import org.github.jimu.msg.core.MessageFactory; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | /** 18 | *

Package: org.github.jimu.msg.executor

19 | *

Project: JIMU

20 | *

Classname: CrossProcessPoster

21 | *

Description: TODO

22 | * Created by leobert on 2018/4/25. 23 | */ 24 | public class CrossProcessPoster implements IPoster { 25 | 26 | @Nullable 27 | private Messenger remoteMessenger; 28 | 29 | public void setRemoteMessenger(@Nullable Messenger remoteMessenger) { 30 | this.remoteMessenger = remoteMessenger; 31 | post2Remote(); 32 | } 33 | 34 | private final List eventCache = new ArrayList<>(); 35 | 36 | private void post(@NonNull T event) { 37 | synchronized (eventCache) { 38 | eventCache.add(event); 39 | post2Remote(); 40 | } 41 | } 42 | 43 | private void post2Remote() { 44 | if (remoteMessenger == null) { 45 | ILogger.logger.monitor("remoteMessenger is not in order "); 46 | return; 47 | } 48 | 49 | ILogger.logger.monitor("post to remote process"); 50 | 51 | synchronized (eventCache) { 52 | while (!eventCache.isEmpty()) { 53 | RemoteEventBean bean = eventCache.remove(0); 54 | try { 55 | remoteMessenger.send(MessageFactory.obtainEventMsg(bean)); 56 | } catch (RemoteException | NullPointerException e) { 57 | e.printStackTrace(); 58 | } 59 | } 60 | } 61 | } 62 | 63 | 64 | @Override 65 | public void postEvent(@NonNull T event, @NonNull EventListener target) { 66 | post((RemoteEventBean) event); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/executor/IPoster.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg.executor; 2 | 3 | import android.support.annotation.NonNull; 4 | 5 | import org.github.jimu.msg.EventListener; 6 | import org.github.jimu.msg.bean.EventBean; 7 | 8 | /** 9 | *

Package: org.github.jimu.msg.executor

10 | *

Project: JIMU

11 | *

Classname: IPoster

12 | *

Description: TODO

13 | * Created by leobert on 2018/4/25. 14 | */ 15 | public interface IPoster { 16 | void postEvent(@NonNull T event, @NonNull EventListener target); 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/executor/LocalProcessBackgroundPoster.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg.executor; 2 | 3 | import android.support.annotation.NonNull; 4 | import android.support.v4.util.Pair; 5 | 6 | import org.github.jimu.msg.EventListener; 7 | import org.github.jimu.msg.bean.EventBean; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import java.util.concurrent.ExecutorService; 12 | 13 | import osp.leobert.android.reportprinter.notation.Bug; 14 | 15 | /** 16 | *

Package: org.github.jimu.msg.executor

17 | *

Project: JIMU

18 | *

Classname: LocalProcessBackgroundPoster

19 | *

Description: TODO

20 | * Created by leobert on 2018/5/3. 21 | */ 22 | public class LocalProcessBackgroundPoster implements IPoster, Runnable { 23 | private final List>> cache; 24 | 25 | private boolean started = false; 26 | private final ExecutorService executorService; 27 | 28 | public LocalProcessBackgroundPoster(@NonNull ExecutorService executorService) { 29 | cache = new ArrayList<>(); 30 | this.executorService = executorService; 31 | } 32 | 33 | @Override 34 | public void postEvent(@NonNull T event, @NonNull EventListener target) { 35 | synchronized (cache) { 36 | Pair> pair = new Pair<>((EventBean) event, (EventListener) target); 37 | cache.add(pair); 38 | if (!started) { 39 | started = true; 40 | executorService.execute(this); 41 | } 42 | } 43 | } 44 | 45 | /** 46 | * todo consider the waste of cpu performance in the infinite loop 47 | */ 48 | @Override 49 | @SuppressWarnings("InfiniteLoopStatement") 50 | @Bug(desc = "consider the waste of cpu performance in the infinite loop") 51 | public void run() { 52 | try { 53 | while (true) { 54 | synchronized (cache) { 55 | if (!cache.isEmpty()) { 56 | Pair> temp = cache.remove(0); 57 | if (temp.second != null) 58 | temp.second.onEvent(temp.first); 59 | } 60 | } 61 | } 62 | } finally { //thread must be interrupted 63 | synchronized (cache) { 64 | started = false; 65 | } 66 | } 67 | 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/executor/LocalProcessMainThreadPoster.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg.executor; 2 | 3 | import android.os.Handler; 4 | import android.os.Looper; 5 | import android.os.Message; 6 | import android.support.annotation.NonNull; 7 | import android.support.v4.util.Pair; 8 | 9 | import org.github.jimu.msg.EventListener; 10 | import org.github.jimu.msg.bean.EventBean; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | *

Package: org.github.jimu.msg.executor

17 | *

Project: JIMU

18 | *

Classname: LocalProcessPoster

19 | *

Description: TODO

20 | * Created by leobert on 2018/4/25. 21 | */ 22 | public class LocalProcessMainThreadPoster extends Handler implements IPoster { 23 | 24 | private final List>> cache; 25 | private boolean started; 26 | private static final long threshold = 10; 27 | 28 | // TODO: 2018/4/27 考虑负载问题 29 | 30 | public LocalProcessMainThreadPoster() { 31 | super(Looper.getMainLooper()); 32 | cache = new ArrayList<>(); 33 | } 34 | 35 | @Override 36 | public void postEvent(@NonNull T event, @NonNull EventListener target) { 37 | synchronized (cache) { 38 | 39 | Pair> pair = new Pair<>((EventBean) event, (EventListener) target); 40 | cache.add(pair); 41 | if (!started) { 42 | removeMessages(0); 43 | start(); 44 | } 45 | } 46 | } 47 | 48 | @Override 49 | public void handleMessage(Message msg) { 50 | // super.handleMessage(msg); 51 | long startStamp = System.currentTimeMillis(); 52 | while (true) { 53 | long t = System.currentTimeMillis(); 54 | if (t > startStamp + threshold) { 55 | started = false; 56 | resumeLater(); 57 | return; 58 | } 59 | synchronized (cache) { 60 | if (cache.size() > 0) { 61 | Pair> temp = cache.remove(0); 62 | try { 63 | if (temp.second != null) 64 | temp.second.onEvent(temp.first); 65 | } finally { 66 | //ignore 67 | } 68 | } else { 69 | started = false; 70 | resumeLater(); 71 | break; 72 | } 73 | } 74 | } 75 | } 76 | 77 | private void start() { 78 | sendEmptyMessage(0); 79 | } 80 | 81 | private void resumeLater() { 82 | sendEmptyMessageDelayed(0, 100); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/notation/AriseProcess.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg.notation; 2 | 3 | import org.github.jimu.msg.bean.ConsumerMeta; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | *

Package: org.github.jimu.msg.notation

12 | *

Project: jimu-core

13 | *

Classname: AriseProcess

14 | *

Description: all event are created in the process it running at,if the subscriber 15 | * is running in the same process, we call say that the event arises at the local process, otherwise, 16 | * a remote process. 17 | * But, when we code the code, we knows the arise process of event, or said: the component itself knows 18 | * what process the event arise at. 19 | * The sense may be complicated, so we just notate the method to tell what process the event arise at, then 20 | * use {@link ConsumerMeta} and {@link Consumer} to tell what process the consumer 21 | * ran at. 22 | *

23 | * Created by leobert on 2018/7/14. 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ElementType.METHOD}) 27 | public @interface AriseProcess { 28 | 29 | /** 30 | * maybe we should use a alias when integrate-test the sub component 31 | * 32 | * @return the full process name alias if from remote process, if is the default "" 33 | * means it arise at the default process when application is created. 34 | */ 35 | String pa() default ""; 36 | } 37 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/notation/Consumer.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg.notation; 2 | 3 | import org.github.jimu.msg.bean.ConsumerMeta; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | *

Package: org.github.jimu.msg.notation

12 | *

Project: jimu-core

13 | *

Classname: Consumer

14 | *

Description: notate the parameter {@link ConsumerMeta}

15 | * Created by leobert on 2018/7/14. 16 | */ 17 | @Retention(RetentionPolicy.RUNTIME) 18 | @Target(ElementType.PARAMETER) 19 | public @interface Consumer { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/java/org/github/jimu/msg/notation/Event.java: -------------------------------------------------------------------------------- 1 | package org.github.jimu.msg.notation; 2 | 3 | import org.github.jimu.msg.bean.EventBean; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | *

Package: org.github.jimu.msg.notation

12 | *

Project: jimu-core

13 | *

Classname: Event

14 | *

Description: an notation to notate the event class you subscribe to

15 | * Created by leobert on 2018/7/30. 16 | */ 17 | @Retention(RetentionPolicy.RUNTIME) 18 | @Target({ElementType.METHOD}) 19 | public @interface Event { 20 | Class clz(); 21 | } 22 | -------------------------------------------------------------------------------- /jimu-core/componentlib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | basiclib 3 | 4 | -------------------------------------------------------------------------------- /jimu-core/gradle.properties.bak: -------------------------------------------------------------------------------- 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 | mainmodulename=app 15 | bintrayRepo=maven 16 | publishedGroupId=com.github.jimu 17 | siteUrl=https://github.com/mqzhangw/JIMU 18 | gitUrl=https://github.com/mqzhangw/JIMU.git 19 | developerId=mqzhang,leobert 20 | developerName=mqzhang,leobert 21 | developerEmail=zhmqq0527@gmail.com,leobert.l@hotmail.com 22 | -------------------------------------------------------------------------------- /jimu-core/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 | -------------------------------------------------------------------------------- /jimu-core/installv1.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.github.dcendents.android-maven' 2 | 3 | group = publishedGroupId // Maven Group ID for the artifact 4 | 5 | install { 6 | repositories.mavenInstaller { 7 | // This generates POM.xml with proper parameters 8 | pom { 9 | project { 10 | packaging 'aar' 11 | groupId publishedGroupId 12 | artifactId artifact 13 | 14 | // Add your description here 15 | name libraryName 16 | description libraryDescription 17 | url siteUrl 18 | 19 | // Set your license 20 | licenses { 21 | license { 22 | name licenseName 23 | url licenseUrl 24 | } 25 | } 26 | developers { 27 | developer { 28 | id developerId 29 | name developerName 30 | email developerEmail 31 | } 32 | } 33 | scm { 34 | connection gitUrl 35 | developerConnection gitUrl 36 | url siteUrl 37 | 38 | } 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /jimu-core/router-anno-compiler/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /jimu-core/router-anno-compiler/src/main/java/com/luojilab/router/compiler/utils/AnnoUtils.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.router.compiler.utils; 2 | 3 | import com.luojilab.router.compiler.model.MethodInfo; 4 | import com.squareup.javapoet.ParameterSpec; 5 | import com.squareup.javapoet.ParameterizedTypeName; 6 | import com.squareup.javapoet.TypeName; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | import javax.lang.model.element.Element; 12 | import javax.lang.model.element.ExecutableElement; 13 | import javax.lang.model.element.Modifier; 14 | import javax.lang.model.element.VariableElement; 15 | import javax.lang.model.type.TypeMirror; 16 | 17 | /** 18 | *

Package: com.luojilab.router.compiler.utils

19 | *

Project: DDComponentForAndroid

20 | *

Classname: AnnoUtils

21 | *

Description: AnnoUtils

22 | * Created by leobert on 2017/9/25. 23 | */ 24 | 25 | public class AnnoUtils { 26 | public static MethodInfo generateMethodInfo(ExecutableElement methodElement) { 27 | //modifiers 28 | ArrayList methodModifiers = new ArrayList<>(); 29 | methodModifiers.add(Modifier.PUBLIC); 30 | //name 31 | String methodName = getSimpleName(methodElement); 32 | //params 33 | List methodParams = new ArrayList<>(); 34 | for (VariableElement typeParameterElement : methodElement.getParameters()) { 35 | methodParams.add(typeParameterElement); 36 | } 37 | //return type 38 | TypeMirror methodReturnType = methodElement.getReturnType(); 39 | return new MethodInfo().setMethodName(methodName) 40 | .setMethodModifiers(methodModifiers) 41 | .setMethodParameters(methodParams) 42 | .setMethodReturnType(methodReturnType); 43 | } 44 | 45 | public static String getSimpleName(Element element) { 46 | return element.getSimpleName().toString(); 47 | } 48 | 49 | public static ParameterSpec generateMethodParameterSpec(TypeMirror typeMirror, 50 | String paramName) { 51 | TypeName tn = 52 | ParameterizedTypeName.get(typeMirror); 53 | 54 | return ParameterSpec.builder(tn, paramName).build(); 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /jimu-core/router-anno-compiler/src/main/java/com/luojilab/router/compiler/utils/Constants.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.router.compiler.utils; 2 | 3 | /** 4 | *

Package: com.luojilab.router.compiler.utils

5 | *

Project: DDComponentForAndroid

6 | *

Classname: Constants

7 | *

Description: Constants used by apt

8 | * Created by leobert on 2017/9/18. 9 | */ 10 | 11 | public interface Constants { 12 | 13 | String ANNO_FACADE_PKG = "com.luojilab.router.facade"; 14 | 15 | 16 | /////////////////////////////////////////////////////////////////////////// 17 | // Options of processor 18 | /////////////////////////////////////////////////////////////////////////// 19 | String KEY_HOST_NAME = "host"; 20 | 21 | String ANNOTATION_TYPE_ROUTE_NODE = ANNO_FACADE_PKG + ".annotation.RouteNode"; 22 | String ANNOTATION_TYPE_ROUTER = ANNO_FACADE_PKG + ".annotation.Router"; 23 | String ANNOTATION_TYPE_AUTOWIRED = ANNO_FACADE_PKG + ".annotation.Autowired"; 24 | 25 | String PREFIX_OF_LOGGER = "[Router-Anno-Compiler]-- "; 26 | 27 | 28 | // System interface 29 | String ACTIVITY = "android.app.Activity"; 30 | String FRAGMENT = "android.app.Fragment"; 31 | String FRAGMENT_V4 = "android.support.v4.app.Fragment"; 32 | String SERVICE = "android.app.Service"; 33 | String PARCELABLE = "android.os.Parcelable"; 34 | String SERIALIZABLE = "java.io.Serializable"; 35 | String BUNDLE = "android.os.Bundle"; 36 | 37 | // Java type 38 | String LANG = "java.lang"; 39 | String BYTE = LANG + ".Byte"; 40 | String SHORT = LANG + ".Short"; 41 | String INTEGER = LANG + ".Integer"; 42 | String LONG = LANG + ".Long"; 43 | String FLOAT = LANG + ".Float"; 44 | String DOUBEL = LANG + ".Double"; 45 | String BOOLEAN = LANG + ".Boolean"; 46 | String STRING = LANG + ".String"; 47 | 48 | String ISYRINGE = "com.luojilab.component.componentlib.router.ISyringe"; 49 | 50 | String JSON_SERVICE = "com.luojilab.component.componentlib.service.JsonService"; 51 | 52 | String BASECOMPROUTER = "com.luojilab.component.componentlib.router.ui.BaseCompRouter"; 53 | 54 | String MISSING_BASECOMPROUTER_MSG = "class BaseCompRouter not found\n确认以下细节:" + 55 | "1.该Module是否使用了componentlib依赖\n" + 56 | "2.确保版本适配,最新的适配版本套件,参考仓库release-note\n" + 57 | "3.使用的componentlib库中BaseCompRouter没有被混淆\n" + 58 | "more detail: https://github.com/mqzhangw/JIMU/issues/26"; 59 | } 60 | -------------------------------------------------------------------------------- /jimu-core/router-anno-compiler/src/main/java/com/luojilab/router/compiler/utils/FileUtils.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.router.compiler.utils; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.OutputStreamWriter; 8 | 9 | /** 10 | * Created by mrzhang on 2017/12/20. 11 | */ 12 | 13 | public class FileUtils { 14 | 15 | 16 | /** 17 | * @param fileName 18 | */ 19 | public static boolean createFile(String fileName) { 20 | try { 21 | File file = new File(fileName); 22 | if (!file.exists()) { 23 | File dir = new File(file.getParent()); 24 | dir.mkdirs(); 25 | file.createNewFile(); 26 | } 27 | return true; 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | } 31 | return false; 32 | } 33 | 34 | 35 | /** 36 | * @param fileName 37 | * @param content 38 | */ 39 | public static void writeStringToFile(String fileName, String content, boolean append) { 40 | BufferedWriter out = null; 41 | FileOutputStream fileOutputStream = null; 42 | OutputStreamWriter osw = null; 43 | try { 44 | fileOutputStream = new FileOutputStream(fileName, append); 45 | osw = new OutputStreamWriter(fileOutputStream, "UTF-8"); 46 | out = new BufferedWriter(osw); 47 | out.write(content); 48 | } catch (Exception e) { 49 | e.printStackTrace(); 50 | } finally { 51 | try { 52 | if (out != null) 53 | out.close(); 54 | if (osw != null) 55 | osw.close(); 56 | if (fileOutputStream != null) 57 | fileOutputStream.close(); 58 | } catch (IOException e) { 59 | e.printStackTrace(); 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /jimu-core/router-anno-compiler/src/main/java/com/luojilab/router/compiler/utils/Logger.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.router.compiler.utils; 2 | 3 | import javax.annotation.processing.Messager; 4 | import javax.tools.Diagnostic; 5 | 6 | /** 7 | *

Package: com.luojilab.router.compiler.utils

8 | *

Project: DDComponentForAndroid

9 | *

Classname: Logger

10 | *

Description: logger for apt

11 | * Created by leobert on 2017/9/18. 12 | */ 13 | 14 | public class Logger { 15 | private Messager msg; 16 | 17 | public Logger(Messager messager) { 18 | msg = messager; 19 | } 20 | 21 | /** 22 | * Print info log. 23 | */ 24 | public void info(CharSequence info) { 25 | if (isNotEmpty(info)) { 26 | msg.printMessage(Diagnostic.Kind.NOTE, Constants.PREFIX_OF_LOGGER + info); 27 | } 28 | } 29 | 30 | public void error(CharSequence error) { 31 | if (isNotEmpty(error)) { 32 | msg.printMessage(Diagnostic.Kind.ERROR, Constants.PREFIX_OF_LOGGER + "An exception is encountered, [" + error + "]"); 33 | } 34 | } 35 | 36 | public void error(Throwable error) { 37 | if (null != error) { 38 | msg.printMessage(Diagnostic.Kind.ERROR, Constants.PREFIX_OF_LOGGER + "An exception is encountered, [" + error.getMessage() + "]" + "\n" + formatStackTrace(error.getStackTrace())); 39 | } 40 | } 41 | 42 | public void warning(CharSequence warning) { 43 | if (isNotEmpty(warning)) { 44 | msg.printMessage(Diagnostic.Kind.WARNING, Constants.PREFIX_OF_LOGGER + warning); 45 | } 46 | } 47 | 48 | private String formatStackTrace(StackTraceElement[] stackTrace) { 49 | StringBuilder sb = new StringBuilder(); 50 | for (StackTraceElement element : stackTrace) { 51 | sb.append(" at ").append(element.toString()); 52 | sb.append("\n"); 53 | } 54 | return sb.toString(); 55 | } 56 | 57 | private static boolean isNotEmpty(final CharSequence cs) { 58 | boolean isEmpty = cs == null || cs.length() == 0; 59 | return !isEmpty; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /jimu-core/router-anno-compiler/src/main/resources/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | com.luojilab.router.compiler.processor.AutowiredProcessor 2 | com.luojilab.router.compiler.processor.RouterProcessor -------------------------------------------------------------------------------- /jimu-core/router-annotation/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /jimu-core/router-annotation/src/main/java/com/luojilab/router/facade/annotation/Autowired.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.router.facade.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 | *

Package: com.luojilab.router.facade.annotation

10 | *

Project: DDComponentForAndroid

11 | *

Classname: Autowired

12 | *

Description: used to auto-inject dependency

13 | * Created by leobert on 2017/9/18. 14 | */ 15 | @Target({ElementType.FIELD}) 16 | @Retention(RetentionPolicy.CLASS) 17 | public @interface Autowired { 18 | 19 | /** 20 | * @return param's name or service name. 21 | */ 22 | String name() default ""; 23 | 24 | /** 25 | * primitive java type check will be ignore 26 | * check the result of DI, if inject failed, the value of 27 | * the field will be null, if required, output log 28 | * 29 | * @return true for required,false otherwise 30 | */ 31 | boolean required() default false; 32 | 33 | /** 34 | * throw exception when the required field is null after inject. 35 | *

36 | * It can help developer find most data delivering bugs when developing. 37 | * but not suggest to open this function after release. 38 | *

39 | * I suggest to define a Constant maintained manually 40 | *

41 | * only activated when required = true and throwOnNull = true. 42 | * 43 | * @return true if throwing exception when null is required, false otherwise 44 | */ 45 | boolean throwOnNull() default false; 46 | 47 | /** 48 | * @return field description 49 | */ 50 | String desc() default "none desc."; 51 | } 52 | -------------------------------------------------------------------------------- /jimu-core/router-annotation/src/main/java/com/luojilab/router/facade/annotation/RouteNode.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.router.facade.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 | *

Package: com.luojilab.router.facade.annotation

10 | *

Project: DDComponentForAndroid

11 | *

Classname: RouteDef

12 | *

Description: used to decline a route node

13 | * Created by leobert on 2017/9/18. 14 | */ 15 | @Target({ElementType.TYPE}) 16 | @Retention(RetentionPolicy.CLASS) 17 | public @interface RouteNode { 18 | /** 19 | * path of one route 20 | */ 21 | String path(); 22 | /** 23 | * The priority of route. 24 | * 25 | * we inspect the path and throw exception when duplicated 26 | * paths were find, thus, it's useless and impossible to use priority 27 | */ 28 | @Deprecated 29 | int priority() default -1; 30 | 31 | /** 32 | * description of the activity, user for gen route table 33 | */ 34 | String desc() default ""; 35 | } 36 | -------------------------------------------------------------------------------- /jimu-core/router-annotation/src/main/java/com/luojilab/router/facade/enums/NodeType.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.router.facade.enums; 2 | 3 | /** 4 | *

Package: com.luojilab.router.facade.enums

5 | *

Project: DDComponentForAndroid

6 | *

Classname: NodeType

7 | *

Description: TODO

8 | * Created by leobert on 2017/9/19. 9 | */ 10 | 11 | public enum NodeType { 12 | ACTIVITY(0, "android.app.Activity"), 13 | INVALID(-1,"invalid node type, currently only activity allowed"); 14 | 15 | int id; 16 | String className; 17 | 18 | NodeType(int id, String className) { 19 | this.id = id; 20 | this.className = className; 21 | } 22 | 23 | public int getId() { 24 | return id; 25 | } 26 | 27 | public NodeType setId(int id) { 28 | this.id = id; 29 | return this; 30 | } 31 | 32 | public String getClassName() { 33 | return className; 34 | } 35 | 36 | public NodeType setClassName(String className) { 37 | this.className = className; 38 | return this; 39 | } 40 | 41 | public static NodeType parse(String name) { 42 | for (NodeType nodeType : NodeType.values()) { 43 | if (nodeType.getClassName().equals(name)) { 44 | return nodeType; 45 | } 46 | } 47 | 48 | return INVALID; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /jimu-core/router-annotation/src/main/java/com/luojilab/router/facade/enums/Type.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.router.facade.enums; 2 | 3 | /** 4 | *

Package: com.luojilab.router.facade.enums

5 | *

Project: DDComponentForAndroid

6 | *

Classname: Type

7 | *

Description: enums for java basic types and STRING,PARCELABLE,OBJECT

8 | * Created by leobert on 2017/9/18. 9 | */ 10 | 11 | public enum Type { 12 | 13 | /////////////////////////////////////////////// 14 | // Base type 15 | /////////////////////////////////////////////// 16 | 17 | BOOLEAN, 18 | BYTE, 19 | SHORT, 20 | INT, 21 | LONG, 22 | CHAR, 23 | FLOAT, 24 | DOUBLE, 25 | 26 | /////////////////////////////////////////////// 27 | // Other type 28 | /////////////////////////////////////////////// 29 | 30 | STRING, 31 | PARCELABLE, 32 | OBJECT, 33 | SERIALIZABLE 34 | 35 | } 36 | -------------------------------------------------------------------------------- /jimu-core/router-annotation/src/main/java/com/luojilab/router/facade/model/Node.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.router.facade.model; 2 | 3 | import com.luojilab.router.facade.enums.NodeType; 4 | 5 | import java.util.Map; 6 | 7 | import javax.lang.model.element.Element; 8 | 9 | /** 10 | *

Package: com.luojilab.router.facade.model

11 | *

Project: DDComponentForAndroid

12 | *

Classname: Node

13 | *

Description: TODO

14 | * Created by leobert on 2017/9/19. 15 | */ 16 | 17 | public class Node { 18 | private NodeType nodeType; 19 | private Element rawType; // Raw type of route 20 | private Class destination; // Destination 21 | private String path; // Path of route 22 | private String desc; // Desc of route 23 | private int priority = -1; // The smaller the number, the higher the priority 24 | private Map paramsType; 25 | private Map paramsDesc; 26 | 27 | public NodeType getNodeType() { 28 | return nodeType; 29 | } 30 | 31 | public void setNodeType(NodeType nodeType) { 32 | this.nodeType = nodeType; 33 | } 34 | 35 | public Element getRawType() { 36 | return rawType; 37 | } 38 | 39 | public void setRawType(Element rawType) { 40 | this.rawType = rawType; 41 | } 42 | 43 | public Class getDestination() { 44 | return destination; 45 | } 46 | 47 | public void setDestination(Class destination) { 48 | this.destination = destination; 49 | } 50 | 51 | public String getPath() { 52 | return path; 53 | } 54 | 55 | public void setPath(String path) { 56 | this.path = path; 57 | } 58 | 59 | public int getPriority() { 60 | return priority; 61 | } 62 | 63 | public void setPriority(int priority) { 64 | this.priority = priority; 65 | } 66 | 67 | public Map getParamsType() { 68 | return paramsType; 69 | } 70 | 71 | public void setParamsType(Map paramsType) { 72 | this.paramsType = paramsType; 73 | } 74 | 75 | public Map getParamsDesc() { 76 | return paramsDesc; 77 | } 78 | 79 | public void setParamsDesc(Map paramsDesc) { 80 | this.paramsDesc = paramsDesc; 81 | } 82 | 83 | public String getDesc() { 84 | return desc; 85 | } 86 | 87 | public void setDesc(String desc) { 88 | this.desc = desc; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /jimu-core/router-annotation/src/main/java/com/luojilab/router/facade/utils/RouteUtils.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.router.facade.utils; 2 | 3 | /** 4 | * Created by mrzhang on 2017/12/18. 5 | */ 6 | 7 | public class RouteUtils { 8 | 9 | private static final String ROUTERIMPL_OUTPUT_PKG = "com.luojilab.gen.router"; 10 | private static final String DOT = "."; 11 | private static final String UIROUTER = "UiRouter"; 12 | 13 | private static final String ROUTERTABLE = "RouterTable"; 14 | 15 | public static String firstCharUpperCase(String str) { 16 | char[] ch = str.toCharArray(); 17 | if (ch[0] >= 'a' && ch[0] <= 'z') { 18 | ch[0] = (char) (ch[0] - 32); 19 | } 20 | return new String(ch); 21 | } 22 | 23 | public static String genHostUIRouterClass(String host) { 24 | String claName = ROUTERIMPL_OUTPUT_PKG + DOT + firstCharUpperCase(host) + UIROUTER; 25 | return new String(claName); 26 | } 27 | 28 | 29 | public static String genRouterTable(String host) { 30 | String claName = "./UIRouterTable/" + firstCharUpperCase(host) + ROUTERTABLE + ".txt"; 31 | return new String(claName); 32 | } 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /jimu-core/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':build-gradle' 2 | include ':componentlib' 3 | include ':router-annotation' 4 | include ':router-anno-compiler' 5 | -------------------------------------------------------------------------------- /jimu-sample-project/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | /gradle 9 | /buildSrc/build/ 10 | -------------------------------------------------------------------------------- /jimu-sample-project/AptHotfix/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /jimu-sample-project/AptHotfix/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | 5 | java { 6 | sourceCompatibility = JavaVersion.VERSION_1_7 7 | targetCompatibility = JavaVersion.VERSION_1_7 8 | } 9 | 10 | repositories { 11 | mavenCentral() 12 | google() 13 | jcenter() 14 | } 15 | dependencies { 16 | 17 | implementation "io.github.leobert-lan:jimu-router-anno-compiler:1.0.1" 18 | implementation 'com.google.auto.service:auto-service:1.0-rc2' 19 | implementation 'com.squareup:javapoet:1.9.0' 20 | 21 | 22 | implementation 'org.apache.commons:commons-lang3:3.4' 23 | implementation 'org.apache.commons:commons-collections4:4.1' 24 | implementation "io.github.leobert-lan:jimu-router-annotation:1.0.1" 25 | } -------------------------------------------------------------------------------- /jimu-sample-project/AptHotfix/src/main/java/com/jimu/hotfix/AutowiredProcessorHotfix.java: -------------------------------------------------------------------------------- 1 | package com.jimu.hotfix; 2 | 3 | import com.google.auto.service.AutoService; 4 | import com.luojilab.router.compiler.processor.AutowiredProcessor; 5 | import com.luojilab.router.compiler.utils.Constants; 6 | 7 | import javax.annotation.processing.Processor; 8 | import javax.annotation.processing.SupportedAnnotationTypes; 9 | import javax.annotation.processing.SupportedOptions; 10 | import javax.annotation.processing.SupportedSourceVersion; 11 | import javax.lang.model.SourceVersion; 12 | 13 | 14 | /** 15 | *

Package: apt

16 | *

Project: jimu-sample-project

17 | *

Classname: AutowiredProcessorHotfix

18 | *

Description: TODO

19 | * Created by leobert on 2021/6/10. 20 | */ 21 | @AutoService(Processor.class) 22 | @SupportedOptions(Constants.KEY_HOST_NAME) 23 | @SupportedSourceVersion(SourceVersion.RELEASE_7) 24 | @SupportedAnnotationTypes({Constants.ANNOTATION_TYPE_AUTOWIRED}) 25 | public class AutowiredProcessorHotfix extends AutowiredProcessor { 26 | } 27 | -------------------------------------------------------------------------------- /jimu-sample-project/AptHotfix/src/main/java/com/jimu/hotfix/RouterProcessorHotfix.java: -------------------------------------------------------------------------------- 1 | package com.jimu.hotfix; 2 | 3 | import com.google.auto.service.AutoService; 4 | import com.luojilab.router.compiler.processor.RouterProcessor; 5 | import com.luojilab.router.compiler.utils.Constants; 6 | 7 | import javax.annotation.processing.Processor; 8 | import javax.annotation.processing.SupportedAnnotationTypes; 9 | import javax.annotation.processing.SupportedOptions; 10 | import javax.annotation.processing.SupportedSourceVersion; 11 | import javax.lang.model.SourceVersion; 12 | 13 | /** 14 | *

Package: apt

15 | *

Project: jimu-sample-project

16 | *

Classname: RouterProcessor

17 | *

Description: TODO

18 | * Created by leobert on 2021/6/10. 19 | */ 20 | @AutoService(Processor.class) 21 | @SupportedOptions(Constants.KEY_HOST_NAME) 22 | @SupportedSourceVersion(SourceVersion.RELEASE_7) 23 | @SupportedAnnotationTypes({Constants.ANNOTATION_TYPE_ROUTE_NODE, Constants.ANNOTATION_TYPE_ROUTER}) 24 | public class RouterProcessorHotfix extends RouterProcessor { 25 | } 26 | -------------------------------------------------------------------------------- /jimu-sample-project/AptHotfix/src/main/resources/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | com.jimu.hotfix.AutowiredProcessorHotfix 2 | com.jimu.hotfix.RouterProcessorHotfix -------------------------------------------------------------------------------- /jimu-sample-project/UIRouterTable/AppRouterTable.txt: -------------------------------------------------------------------------------- 1 | auto generated, do not change !!!! 2 | 3 | HOST : app 4 | 5 | 主进程页面1 6 | /msg/demo/1 7 | 8 | remote进程页面 9 | /msg/demo/3 10 | 11 | 主进程页面2 12 | /msg/demo/2 13 | 14 | 首页 15 | /main 16 | 17 | 使用Url传参 18 | /uirouter/demo/3 19 | foo:String 20 | EXTRA_STR_BAR:String 21 | 22 | Url和Bundle同时包含参数 23 | /uirouter/demo/4 24 | foo:String 25 | EXTRA_STR_BAR:String 26 | 27 | Parcelable和Serializable 28 | /uirouter/demo/5 29 | foo:parcelable 30 | 31 | 使用bundle传递参数 32 | /uirouter/demo/2 33 | foo:String 34 | EXTRA_STR_BAR:String 35 | 36 | 必须参数2 37 | /uirouter/demo/8 38 | foo:String 39 | 40 | 必须参数 41 | /uirouter/demo/7 42 | foo:String 43 | 44 | 使用json字符串传参 45 | /uirouter/demo/6 46 | EXTRA_OBJ_FOO:com.luojilab.componentdemo.router.cases.Demo6Activity.Foo 47 | 48 | 无参数 49 | /uirouter/demo/1 50 | 51 | UiRouter使用演示页面 52 | /uirouter/demo 53 | 54 | -------------------------------------------------------------------------------- /jimu-sample-project/UIRouterTable/KotlinRouterTable.txt: -------------------------------------------------------------------------------- 1 | auto generated, do not change !!!! 2 | 3 | HOST : kotlin 4 | 5 | 分享杂志页面 6 | /shareMagazine 7 | author:com.luojilab.componentservice.share.bean.AuthorKt 8 | bookName:String 9 | 10 | test multi java and kotlin in one module 11 | /javatest 12 | author:com.luojilab.componentservice.share.bean.AuthorKt 13 | bookName:String 14 | 15 | -------------------------------------------------------------------------------- /jimu-sample-project/UIRouterTable/ShareRouterTable.txt: -------------------------------------------------------------------------------- 1 | auto generated, do not change !!!! 2 | 3 | HOST : share 4 | 5 | 分享书籍-内容编辑页面 6 | /share/edit/book 7 | author:com.luojilab.componentservice.share.bean.Author 8 | bookName:String 9 | 10 | -------------------------------------------------------------------------------- /jimu-sample-project/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /jimu-sample-project/app/build.gradle: -------------------------------------------------------------------------------- 1 | import jimu.Consts 2 | 3 | apply plugin: Consts.jimu_plugin_name 4 | //apply plugin: 'JimuHotfix' 5 | 6 | android { 7 | compileSdkVersion versions.compileSdk 8 | buildToolsVersion versions.androidTools 9 | 10 | defaultConfig { 11 | minSdkVersion versions.minSdk 12 | targetSdkVersion versions.targetSdk 13 | versionCode 1 14 | versionName "1.0" 15 | applicationId "com.luojilab.androidcomponent" 16 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 17 | 18 | javaCompileOptions { 19 | annotationProcessorOptions { 20 | arguments = [host: "app"] 21 | } 22 | } 23 | 24 | vectorDrawables.useSupportLibrary = true 25 | 26 | } 27 | buildTypes { 28 | release { 29 | minifyEnabled true 30 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 31 | } 32 | 33 | debug { 34 | signingConfig signingConfigs.debug 35 | minifyEnabled false 36 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 37 | } 38 | } 39 | 40 | lintOptions { 41 | checkReleaseBuilds false 42 | // Or, if you prefer, you can continue to check for errors in release builds, 43 | // but continue the build even when errors are found: 44 | abortOnError false 45 | } 46 | 47 | 48 | } 49 | 50 | dependencies { 51 | implementation project(':componentservice') 52 | implementation 'androidx.constraintlayout:constraintlayout:2.0.1' 53 | implementation 'com.google.android.material:material:1.2.1' 54 | implementation 'androidx.vectordrawable:vectordrawable:1.1.0' 55 | 56 | 57 | annotationProcessor Consts.Deps.JIMU_ROUTER_COMPILER 58 | // annotationProcessor(project(":AptHotfix")) 59 | } 60 | 61 | def projectRoot = project.getRootProject().rootDir.absolutePath 62 | 63 | 64 | combuild { 65 | applicationName = 'com.luojilab.componentdemo.application.AppApplication' 66 | isRegisterCompoAuto = true 67 | 68 | originalManifest = projectRoot + "/app/src/main/AndroidManifest.xml" 69 | 70 | runAloneManifest = projectRoot + "/app/src/main/AndroidManifest.xml" 71 | targetManifest = projectRoot + "/app/src/main/AndroidManifest.xml" 72 | //如果不需要合并,改为false 73 | enableManifestMerge = false 74 | } 75 | -------------------------------------------------------------------------------- /jimu-sample-project/app/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 | isRunAlone=true 15 | debugComponent=sharecomponent,sharecomponentkotlin,readercomponent 16 | compileComponent=sharecomponent,sharecomponentkotlin,readercomponent 17 | 18 | 19 | -------------------------------------------------------------------------------- /jimu-sample-project/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/klee/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -ignorewarnings 27 | -dontoptimize 28 | -keep class !android.support.v7.view.menu.*MenuBuilder*, android.support.v7.** { *; } 29 | -keep class android.support.v4.** { *; } 30 | -keep interface android.support.** { *; } 31 | -keepattributes Signature 32 | -keepattributes SourceFile,LineNumberTable 33 | -keep public class * extends android.support.** 34 | -keep public class * extends android.app.Fragment 35 | -keep public class * extends android.app.Activity 36 | -keep public class * extends android.app.Application 37 | -keep public class * extends android.app.Service 38 | -keep public class * extends android.content.BroadcastReceiver 39 | -keep public class * extends android.content.ContentProvider 40 | -keep public class * extends android.app.backup.BackupAgentHelper 41 | -keep public class * extends android.preference.Preference 42 | -keep public class * extends com.netease.ntespmmvp.** {*;} 43 | 44 | -keep enum * { *;} 45 | 46 | -keep interface * { 47 | ; 48 | } 49 | -keep class com.luojilab.component.componentlib.** {*;} 50 | -keep class com.luojilab.router.** {*;} 51 | -keep class com.luojilab.gen.** {*;} 52 | -keep class * implements com.luojilab.component.componentlib.router.ISyringe {*;} 53 | -keep class * implements com.luojilab.component.componentlib.applicationlike.IApplicationLike {*;} 54 | -dontwarn okio.** 55 | -dontwarn okhttp3.** 56 | -dontwarn com.squareup.** 57 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/androidTest/java/com/luojilab/componentdemo/UiRouterTest.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo; 2 | 3 | import android.content.Context; 4 | import android.net.Uri; 5 | import android.os.Bundle; 6 | 7 | import com.luojilab.component.componentlib.router.ui.IComponentRouter; 8 | import com.luojilab.component.componentlib.router.ui.UIRouter; 9 | 10 | import org.junit.Assert; 11 | import org.junit.Before; 12 | import org.junit.Test; 13 | 14 | /** 15 | *

Package: com.luojilab.componentdemo

16 | *

Project: DDComponentForAndroid

17 | *

Classname: UiRouterTest

18 | *

Description: test cases for {@link UIRouter}

19 | * Created by leobert on 11/01/2018. 20 | */ 21 | public class UiRouterTest { 22 | 23 | private UIRouter uiRouter; 24 | 25 | private static final String TARGET_URI = "https://test/UiRouter/target"; 26 | 27 | @Before 28 | public void setUp() throws Exception { 29 | uiRouter = UIRouter.getInstance(); 30 | // UIRouter.enableDebug(); 31 | 32 | uiRouter.registerUI(new IComponentRouter() { 33 | @Override 34 | public boolean openUri(Context context, String url, Bundle bundle) { 35 | return false; 36 | } 37 | 38 | @Override 39 | public boolean openUri(Context context, Uri uri, Bundle bundle) { 40 | return false; 41 | } 42 | 43 | @Override 44 | public boolean openUri(Context context, String url, Bundle bundle, Integer requestCode) { 45 | return false; 46 | } 47 | 48 | @Override 49 | public boolean openUri(Context context, Uri uri, Bundle bundle, Integer requestCode) { 50 | return false; 51 | } 52 | 53 | @Override 54 | public boolean verifyUri(Uri uri) { 55 | if (uri == null) 56 | return false; 57 | return TARGET_URI.equals(uri.toString()); 58 | } 59 | }); 60 | } 61 | 62 | @Test 63 | public void testVerifyUri() { 64 | Uri[] errorCases = new Uri[]{ 65 | Uri.parse("http://error/1"), 66 | Uri.EMPTY, 67 | null 68 | }; 69 | 70 | for (Uri uri : errorCases) { 71 | Assert.assertEquals(false, uiRouter.verifyUri(uri)); 72 | } 73 | 74 | Assert.assertEquals(true,uiRouter.verifyUri(Uri.parse(TARGET_URI))); 75 | } 76 | } -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/DemoActivity.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo; 2 | 3 | import android.os.Bundle; 4 | import androidx.annotation.NonNull; 5 | import com.google.android.material.bottomnavigation.BottomNavigationView; 6 | import androidx.appcompat.app.AppCompatActivity; 7 | import android.view.MenuItem; 8 | import android.widget.TextView; 9 | 10 | public class DemoActivity extends AppCompatActivity { 11 | 12 | private TextView mTextMessage; 13 | 14 | private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener 15 | = new BottomNavigationView.OnNavigationItemSelectedListener() { 16 | 17 | @Override 18 | public boolean onNavigationItemSelected(@NonNull MenuItem item) { 19 | switch (item.getItemId()) { 20 | case R.id.navigation_home: 21 | mTextMessage.setText(R.string.title_home); 22 | return true; 23 | case R.id.navigation_dashboard: 24 | mTextMessage.setText(R.string.title_dashboard); 25 | return true; 26 | case R.id.navigation_notifications: 27 | mTextMessage.setText(R.string.title_notifications); 28 | return true; 29 | } 30 | return false; 31 | } 32 | }; 33 | 34 | @Override 35 | protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_demo); 38 | 39 | mTextMessage = (TextView) findViewById(R.id.message); 40 | BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation); 41 | navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/application/AppApplication.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.application; 2 | 3 | import android.util.Log; 4 | 5 | import com.luojilab.component.basicres.BaseApplication; 6 | import com.luojilab.component.componentlib.log.ILogger; 7 | import com.luojilab.component.componentlib.router.Router; 8 | import com.luojilab.component.componentlib.router.ui.UIRouter; 9 | import com.luojilab.componentdemo.msg.AppComponentEventManager; 10 | 11 | import org.github.jimu.msg.EventManager; 12 | import org.jetbrains.annotations.NotNull; 13 | import org.jetbrains.annotations.Nullable; 14 | 15 | import kotlin.Unit; 16 | import kotlin.jvm.functions.Function1; 17 | import kotlin.jvm.functions.Function3; 18 | import osp.leobert.android.maat.JOB; 19 | import osp.leobert.android.maat.Maat; 20 | 21 | /** 22 | * Created by mrzhang on 2017/6/15. 23 | */ 24 | 25 | public class AppApplication extends BaseApplication { 26 | 27 | @Override 28 | public void onCreate() { 29 | super.onCreate(); 30 | ILogger.logger.setDefaultTag("JIMU"); 31 | UIRouter.enableDebug(); 32 | Maat.Companion.init(this, 8, new Maat.Logger() { 33 | @Override 34 | public boolean getEnable() { 35 | return true; 36 | } 37 | 38 | @Override 39 | public void log(@NotNull String s, @Nullable Throwable throwable) { 40 | if (throwable != null) { 41 | // ILogger.logger.error("maat", s); 42 | // throwable.printStackTrace(); 43 | Log.e("maat",s,throwable); 44 | } else { 45 | // ILogger.logger.debug("maat", s); 46 | Log.d("maat",s); 47 | } 48 | } 49 | }, new Maat.Callback(new Function1() { 50 | @Override 51 | public Unit invoke(Maat maat) { 52 | Maat.Companion.release(); 53 | return null; 54 | } 55 | }, new Function3() { 56 | @Override 57 | public Unit invoke(Maat maat, JOB job, Throwable throwable) { 58 | return null; 59 | } 60 | })); 61 | 62 | // EventManager.appendMapper("com.luojilab.componentdemo.application", MainProcessMsgService.class); 63 | // EventManager.appendMapper("com.luojilab.componentdemo.application:remote", RemoteMsgService.class); 64 | 65 | EventManager.init(this); 66 | 67 | UIRouter.getInstance().registerUI("app"); 68 | 69 | //如果isRegisterCompoAuto为false,则需要通过反射加载组件 70 | Router.registerComponent("com.luojilab.reader.applike.ReaderAppLike"); 71 | // Router.registerComponent("com.luojilab.share.applike.ShareApplike"); 72 | 73 | Router.getInstance().addService(AppComponentEventManager.class.getSimpleName(), 74 | EventManager.create(AppComponentEventManager.class)); 75 | 76 | } 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/msg/AppComponentEventManager.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.msg; 2 | 3 | import com.luojilab.componentdemo.msg.event.EventA; 4 | import com.luojilab.componentdemo.msg.event.EventB; 5 | 6 | import org.github.jimu.msg.bean.ConsumerMeta; 7 | import org.github.jimu.msg.notation.AriseProcess; 8 | import org.github.jimu.msg.notation.Consumer; 9 | import org.github.jimu.msg.notation.Event; 10 | 11 | /** 12 | *

Package: com.luojilab.componentdemo.msg

13 | *

Project: jimu-sample-project

14 | *

Classname: AppComponentEventManager

15 | *

Description: TODO

16 | * Created by leobert on 2018/7/30. 17 | */ 18 | public interface AppComponentEventManager { 19 | @AriseProcess() 20 | @Event(clz = EventA.class) 21 | void subscribeEventA(@Consumer ConsumerMeta meta); 22 | 23 | @AriseProcess(pa = ":remote") 24 | @Event(clz = EventB.class) 25 | void subscribeEventB(@Consumer ConsumerMeta meta); 26 | } 27 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/msg/Foo.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.msg; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Color; 5 | import android.os.Bundle; 6 | import androidx.annotation.Nullable; 7 | import android.text.method.LinkMovementMethod; 8 | import android.widget.TextView; 9 | 10 | import com.luojilab.componentdemo.R; 11 | 12 | /** 13 | *

Package: com.luojilab.componentdemo.msg

14 | *

Project: jimu-sample-project

15 | *

Classname: Foo

16 | *

Description: TODO

17 | * Created by leobert on 2018/6/7. 18 | */ 19 | public abstract class Foo extends Activity { 20 | protected TextView tvMsg; 21 | protected TextView btn; 22 | 23 | @Override 24 | protected void onCreate(@Nullable Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_msg); 27 | tvMsg = findViewById(R.id.demo_msg_tv); 28 | btn = findViewById(R.id.demo_msg_btn); 29 | btn.setText(getBtnText()); 30 | btn.setMovementMethod(LinkMovementMethod.getInstance()); 31 | btn.setHighlightColor(Color.TRANSPARENT); 32 | } 33 | 34 | protected abstract CharSequence getBtnText(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/msg/MainProcessMsgService.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.msg; 2 | 3 | import org.github.jimu.msg.MsgBridgeService; 4 | import org.github.jimu.msg.core.MessageBridgeService; 5 | 6 | //@MsgBridgeService(workProcessName = "com.luojilab.componentdemo.application") 7 | // empty can represent the default process 8 | @MsgBridgeService(workProcessName = "") 9 | public class MainProcessMsgService extends MessageBridgeService { 10 | public MainProcessMsgService() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/msg/Msg2Activity.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.msg; 2 | 3 | import android.os.Bundle; 4 | import android.text.SpannableString; 5 | import android.text.Spanned; 6 | import android.text.style.ClickableSpan; 7 | import android.view.View; 8 | 9 | import org.github.jimu.msg.ConsumeOn; 10 | import org.github.jimu.msg.EventListener; 11 | import org.github.jimu.msg.EventManager; 12 | import org.github.jimu.msg.bean.ConsumerMeta; 13 | 14 | import com.luojilab.component.componentlib.router.Router; 15 | import com.luojilab.componentdemo.msg.event.EventA; 16 | import com.luojilab.componentdemo.msg.event.EventB; 17 | import com.luojilab.router.facade.annotation.RouteNode; 18 | 19 | @RouteNode(path = "/msg/demo/2", desc = "主进程页面2") 20 | public class Msg2Activity extends Foo { 21 | 22 | EventListener eventAEventListener; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | eventAEventListener = new EventListener() { 28 | @Override 29 | public void onEvent(EventA event) { 30 | tvMsg.setText("event has been send and received." + event.getMsg()); 31 | } 32 | }; 33 | // EventManager.getInstance().subscribe(EventA.class, eventAEventListener); 34 | 35 | AppComponentEventManager manager = (AppComponentEventManager) Router.getInstance() 36 | .getService(AppComponentEventManager.class.getSimpleName()); 37 | 38 | manager.subscribeEventA(ConsumerMeta.newBuilder() 39 | .consumeOn(ConsumeOn.Main) 40 | .eventListener(eventAEventListener) 41 | .build()); 42 | } 43 | 44 | @Override 45 | protected CharSequence getBtnText() { 46 | SpannableString spans1 = new SpannableString("send eventA"); 47 | spans1.setSpan(new ClickableSpan() { 48 | @Override 49 | public void onClick(View widget) { 50 | EventManager.getInstance().postEvent(new EventA("event a from Msg2Activity")); 51 | } 52 | }, 0, spans1.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 53 | 54 | return spans1; 55 | } 56 | 57 | @Override 58 | protected void onDestroy() { 59 | EventManager.getInstance().unsubscribe(eventAEventListener); 60 | super.onDestroy(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/msg/Msg3Activity.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.msg; 2 | 3 | import android.os.Bundle; 4 | import android.text.SpannableString; 5 | import android.text.Spanned; 6 | import android.text.style.ClickableSpan; 7 | import android.view.View; 8 | 9 | import org.github.jimu.msg.ConsumeOn; 10 | import org.github.jimu.msg.EventListener; 11 | import org.github.jimu.msg.EventManager; 12 | import org.github.jimu.msg.bean.ConsumerMeta; 13 | 14 | import com.luojilab.component.componentlib.router.Router; 15 | import com.luojilab.componentdemo.msg.event.EventA; 16 | import com.luojilab.componentdemo.msg.event.EventB; 17 | import com.luojilab.router.facade.annotation.RouteNode; 18 | 19 | @RouteNode(path = "/msg/demo/3", desc = "remote进程页面") 20 | public class Msg3Activity extends Foo { 21 | 22 | EventListener eventBEventListener; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | eventBEventListener = new EventListener() { 28 | @Override 29 | public void onEvent(EventB event) { 30 | tvMsg.setText("event has been send and received." + event.getMsg()); 31 | } 32 | }; 33 | EventManager.getInstance().subscribe(EventB.class, eventBEventListener); 34 | 35 | AppComponentEventManager manager = (AppComponentEventManager) Router.getInstance() 36 | .getService(AppComponentEventManager.class.getSimpleName()); 37 | 38 | 39 | 40 | manager.subscribeEventB(ConsumerMeta.newBuilder() 41 | .consumeOn(ConsumeOn.Main) 42 | .process(":remote") // 一般来说,都不需要特地写进程了,我们约定""就代表默认进程,其他新开辟的进程中需要写 43 | .eventListener(eventBEventListener) 44 | .build()); 45 | } 46 | 47 | @Override 48 | protected CharSequence getBtnText() { 49 | SpannableString spans1 = new SpannableString("send eventB"); 50 | spans1.setSpan(new ClickableSpan() { 51 | @Override 52 | public void onClick(View widget) { 53 | EventManager.getInstance().postEvent(new EventB("event b from Msg3Activity")); 54 | } 55 | }, 0, spans1.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 56 | 57 | return spans1; 58 | } 59 | 60 | @Override 61 | protected void onDestroy() { 62 | EventManager.getInstance().unsubscribe(eventBEventListener); 63 | super.onDestroy(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/msg/RemoteMsgService.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.msg; 2 | 3 | import org.github.jimu.msg.MsgBridgeService; 4 | import org.github.jimu.msg.core.MessageBridgeService; 5 | 6 | @MsgBridgeService(workProcessName = ":remote") 7 | public class RemoteMsgService extends MessageBridgeService { 8 | public RemoteMsgService() { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/msg/event/EventA.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.msg.event; 2 | 3 | import org.github.jimu.msg.bean.EventBean; 4 | 5 | /** 6 | *

Package: com.luojilab.componentdemo.msg.event

7 | *

Project: jimu-sample-project

8 | *

Classname: EventA

9 | *

Description: TODO

10 | * Created by leobert on 2018/6/7. 11 | */ 12 | public class EventA implements EventBean { 13 | private String msg; 14 | 15 | public String getMsg() { 16 | return msg; 17 | } 18 | 19 | public EventA(String msg) { 20 | this.msg = msg; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/msg/event/EventB.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.msg.event; 2 | 3 | import android.os.Parcel; 4 | 5 | import org.github.jimu.msg.bean.RemoteEventBean; 6 | 7 | /** 8 | *

Package: com.luojilab.componentdemo.msg.event

9 | *

Project: jimu-sample-project

10 | *

Classname: EventB

11 | *

Description: TODO

12 | * Created by leobert on 2018/6/7. 13 | */ 14 | public class EventB implements RemoteEventBean{ 15 | private String msg; 16 | 17 | public EventB(String msg) { 18 | this.msg = msg; 19 | } 20 | 21 | protected EventB(Parcel in) { 22 | msg = in.readString(); 23 | } 24 | 25 | public static final Creator CREATOR = new Creator() { 26 | @Override 27 | public EventB createFromParcel(Parcel in) { 28 | return new EventB(in); 29 | } 30 | 31 | @Override 32 | public EventB[] newArray(int size) { 33 | return new EventB[size]; 34 | } 35 | }; 36 | 37 | @Override 38 | public int describeContents() { 39 | return 0; 40 | } 41 | 42 | @Override 43 | public void writeToParcel(Parcel dest, int flags) { 44 | dest.writeString(msg); 45 | } 46 | 47 | public String getMsg() { 48 | return msg; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/router/cases/Demo1Activity.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.router.cases; 2 | 3 | import android.widget.TextView; 4 | 5 | import com.luojilab.componentdemo.router.UiRouterDemoActivity; 6 | import com.luojilab.router.facade.annotation.RouteNode; 7 | 8 | /** 9 | *

Package: com.luojilab.componentdemo.router.cases

10 | *

Project: JIMU

11 | *

Classname: Demo1Activity

12 | *

Description: TODO

13 | * Created by leobert on 28/03/2018. 14 | */ 15 | @RouteNode(path = "/uirouter/demo/1", desc = "无参数") 16 | public class Demo1Activity extends TestActivity { 17 | public static final UiRouterDemoActivity.Case aCase 18 | = new UiRouterDemoActivity.Case(false, 19 | "无参数跳转", 20 | "JIMU://app/uirouter/demo/1", 21 | null); 22 | 23 | 24 | @Override 25 | protected void displayInfo(TextView textView) { 26 | textView.setText("无参数跳转成功"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/router/cases/Demo2Activity.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.router.cases; 2 | 3 | import android.os.Bundle; 4 | import android.widget.TextView; 5 | 6 | import com.luojilab.componentdemo.router.UiRouterDemoActivity; 7 | import com.luojilab.router.facade.annotation.Autowired; 8 | import com.luojilab.router.facade.annotation.RouteNode; 9 | 10 | /** 11 | *

Package: com.luojilab.componentdemo.router.cases

12 | *

Project: JIMU

13 | *

Classname: Demo2Activity

14 | *

Description: TODO

15 | * Created by leobert on 01/04/2018. 16 | */ 17 | @RouteNode(path = "/uirouter/demo/2", desc = "使用bundle传递参数") 18 | public class Demo2Activity extends TestActivity { 19 | private static Bundle bundle = new Bundle(); 20 | 21 | static { 22 | bundle.putString("foo", "foo string"); 23 | bundle.putString("EXTRA_STR_BAR", "bar string"); 24 | } 25 | 26 | @Autowired() //不指定名称时将使用变量名,若被混淆可能出现问题, 27 | // 建议使用name指定key,参考bar的使用 28 | String foo; 29 | 30 | @Autowired(name = "EXTRA_STR_BAR") 31 | String bar; 32 | 33 | public static final UiRouterDemoActivity.Case aCase 34 | = new UiRouterDemoActivity.Case(false, 35 | "使用bundle传递参数", 36 | "JIMU://app/uirouter/demo/2", 37 | bundle); 38 | 39 | @Override 40 | protected void displayInfo(TextView textView) { 41 | StringBuilder stringBuilder = new StringBuilder(); 42 | stringBuilder.append("使用bundle传递参数成功\r\n"); 43 | stringBuilder.append("foo:").append(foo).append("\r\n"); 44 | stringBuilder.append("bar:").append(bar).append("\r\n"); 45 | 46 | textView.setText(stringBuilder.toString()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/router/cases/Demo3Activity.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.router.cases; 2 | 3 | import android.os.Bundle; 4 | import android.widget.TextView; 5 | 6 | import com.luojilab.componentdemo.router.UiRouterDemoActivity; 7 | import com.luojilab.router.facade.annotation.Autowired; 8 | import com.luojilab.router.facade.annotation.RouteNode; 9 | 10 | /** 11 | *

Package: com.luojilab.componentdemo.router.cases

12 | *

Project: JIMU

13 | *

Classname: Demo3Activity

14 | *

Description: TODO

15 | * Created by leobert on 01/04/2018. 16 | */ 17 | @RouteNode(path = "/uirouter/demo/3" ,desc = "使用Url传参") 18 | public class Demo3Activity extends TestActivity{ 19 | 20 | @Autowired() //不指定名称时将使用变量名,若被混淆可能出现问题, 21 | // 建议使用name指定key,参考bar的使用 22 | String foo; 23 | 24 | @Autowired(name = "EXTRA_STR_BAR") 25 | String bar; 26 | 27 | /*注意,仅支持在queryString中设置参数,不支持在path中传递参数*/ 28 | public static final UiRouterDemoActivity.Case aCase 29 | = new UiRouterDemoActivity.Case(false, 30 | "使用Url传参", 31 | "JIMU://app/uirouter/demo/3?foo=foo string&EXTRA_STR_BAR=bar string", 32 | null); 33 | 34 | @Override 35 | protected void displayInfo(TextView textView) { 36 | StringBuilder stringBuilder = new StringBuilder(); 37 | stringBuilder.append("使用bundle传递参数成功\r\n"); 38 | stringBuilder.append("foo:").append(foo).append("\r\n"); 39 | stringBuilder.append("bar:").append(bar).append("\r\n"); 40 | 41 | textView.setText(stringBuilder.toString()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/router/cases/Demo4Activity.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.router.cases; 2 | 3 | import android.os.Bundle; 4 | import android.widget.TextView; 5 | 6 | import com.luojilab.componentdemo.router.UiRouterDemoActivity; 7 | import com.luojilab.router.facade.annotation.Autowired; 8 | import com.luojilab.router.facade.annotation.RouteNode; 9 | 10 | /** 11 | *

Package: com.luojilab.componentdemo.router.cases

12 | *

Project: JIMU

13 | *

Classname: Demo3Activity

14 | *

Description: TODO

15 | * Created by leobert on 01/04/2018. 16 | */ 17 | @RouteNode(path = "/uirouter/demo/4", desc = "Url和Bundle同时包含参数") 18 | public class Demo4Activity extends TestActivity { 19 | private static Bundle bundle = new Bundle(); 20 | 21 | static { 22 | bundle.putString("foo", "foo string in bundle"); 23 | bundle.putString("EXTRA_STR_BAR", "bar string in bundle"); 24 | } 25 | 26 | @Autowired() 27 | String foo; 28 | 29 | @Autowired(name = "EXTRA_STR_BAR") 30 | String bar; 31 | 32 | 33 | public static final UiRouterDemoActivity.Case aCase 34 | = new UiRouterDemoActivity.Case(false, 35 | "Url和Bundle同时包含参数", 36 | "JIMU://app/uirouter/demo/4?foo=foo string in url&EXTRA_STR_BAR=bar string in url", 37 | null); 38 | 39 | @Override 40 | protected void displayInfo(TextView textView) { 41 | StringBuilder stringBuilder = new StringBuilder(); 42 | stringBuilder.append("Url和Bundle同时包含参数,以url为准\r\n"); 43 | stringBuilder.append("foo:").append(foo).append("\r\n"); 44 | stringBuilder.append("bar:").append(bar).append("\r\n"); 45 | 46 | textView.setText(stringBuilder.toString()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/router/cases/Demo6Activity.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.router.cases; 2 | 3 | import android.widget.TextView; 4 | 5 | import com.google.gson.Gson; 6 | import com.luojilab.componentdemo.router.UiRouterDemoActivity; 7 | import com.luojilab.router.facade.annotation.Autowired; 8 | import com.luojilab.router.facade.annotation.RouteNode; 9 | 10 | 11 | @RouteNode(path = "/uirouter/demo/6", desc = "使用json字符串传参") 12 | public class Demo6Activity extends TestActivity { 13 | 14 | @Autowired(name = "EXTRA_OBJ_FOO") 15 | Foo foo; 16 | private static Foo test; 17 | 18 | static { 19 | test = new Foo(); 20 | test.setFooInt(2); 21 | test.setFooString("foo string"); 22 | } 23 | 24 | /*注意,仅支持在queryString中设置参数,不支持在path中传递参数*/ 25 | public static final UiRouterDemoActivity.Case aCase 26 | = new UiRouterDemoActivity.Case(false, 27 | "使用json字符串传参", 28 | "JIMU://app/uirouter/demo/6?EXTRA_OBJ_FOO=" + new Gson().toJson(test), 29 | null); 30 | 31 | @Override 32 | protected void displayInfo(TextView textView) { 33 | StringBuilder stringBuilder = new StringBuilder(); 34 | stringBuilder.append("使用json字符串传参成功\r\n"); 35 | stringBuilder.append("foo:").append(foo).append("\r\n"); 36 | 37 | textView.setText(stringBuilder.toString()); 38 | } 39 | 40 | public static final class Foo { 41 | private int fooInt; 42 | private String fooString; 43 | 44 | public int getFooInt() { 45 | return fooInt; 46 | } 47 | 48 | public void setFooInt(int fooInt) { 49 | this.fooInt = fooInt; 50 | } 51 | 52 | public String getFooString() { 53 | return fooString; 54 | } 55 | 56 | public void setFooString(String fooString) { 57 | this.fooString = fooString; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "Foo:{" + 63 | "fooInt:" + fooInt + "," 64 | + "fooString:" + fooString + 65 | "}"; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/router/cases/Demo7Activity.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.router.cases; 2 | 3 | import android.widget.TextView; 4 | 5 | import com.luojilab.componentdemo.router.UiRouterDemoActivity; 6 | import com.luojilab.router.facade.annotation.Autowired; 7 | import com.luojilab.router.facade.annotation.RouteNode; 8 | 9 | /** 10 | *

Package: com.luojilab.componentdemo.router.cases

11 | *

Project: JIMU

12 | *

Classname: Demo3Activity

13 | *

Description: TODO

14 | * Created by leobert on 01/04/2018. 15 | */ 16 | @RouteNode(path = "/uirouter/demo/7", desc = "必须参数") 17 | public class Demo7Activity extends TestActivity { 18 | 19 | @Autowired(required = true) 20 | String foo; 21 | 22 | public static final UiRouterDemoActivity.Case aCase 23 | = new UiRouterDemoActivity.Case(false, 24 | "必须参数-log输出", 25 | "JIMU://app/uirouter/demo/7", 26 | null); 27 | 28 | @Override 29 | protected void displayInfo(TextView textView) { 30 | textView.setText("此处Autowired没有使用异常抛出功能,\r\n" + 31 | "通过安全模式可以捕获ParamException\r\n" + 32 | "直接跳转,控制台输出错误日志,通过AutowiredProcessor 进行过滤\r\n" + 33 | "显然,通过异常抛出更容易发现问题"); 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/router/cases/Demo8Activity.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.router.cases; 2 | 3 | import android.widget.TextView; 4 | 5 | import com.luojilab.componentdemo.router.UiRouterDemoActivity; 6 | import com.luojilab.router.facade.annotation.Autowired; 7 | import com.luojilab.router.facade.annotation.RouteNode; 8 | 9 | /** 10 | *

Package: com.luojilab.componentdemo.router.cases

11 | *

Project: JIMU

12 | *

Classname: Demo3Activity

13 | *

Description: TODO

14 | * Created by leobert on 01/04/2018. 15 | */ 16 | @RouteNode(path = "/uirouter/demo/8", desc = "必须参数2") 17 | public class Demo8Activity extends TestActivity { 18 | 19 | @Autowired(required = true,throwOnNull = true) 20 | String foo; 21 | 22 | public static final UiRouterDemoActivity.Case aCase 23 | = new UiRouterDemoActivity.Case(true, 24 | "必须参数-空指针校验,primitive无效!", 25 | "JIMU://app/uirouter/demo/8", 26 | null); 27 | 28 | @Override 29 | protected void displayInfo(TextView textView) { 30 | textView.setText("不使用safemode 将直接crash"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/router/cases/TestActivity.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.router.cases; 2 | 3 | import android.os.Bundle; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | import android.widget.TextView; 6 | 7 | import com.luojilab.component.componentlib.service.AutowiredService; 8 | import com.luojilab.componentdemo.R; 9 | 10 | abstract class TestActivity extends AppCompatActivity { 11 | 12 | private TextView textView; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_test); 18 | textView = findViewById(R.id.demo_tv_info); 19 | AutowiredService.Factory.getSingletonImpl() 20 | .autowire(this); 21 | displayInfo(textView); 22 | } 23 | 24 | protected abstract void displayInfo(TextView textView); 25 | } 26 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/java/com/luojilab/componentdemo/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package com.luojilab.componentdemo.utils; 2 | 3 | import android.content.res.Resources; 4 | 5 | 6 | public final class Utils { 7 | 8 | private Utils() { 9 | } 10 | 11 | public static float dp2px(Resources resources, float dp) { 12 | final float scale = resources.getDisplayMetrics().density; 13 | return dp * scale + 0.5f; 14 | } 15 | 16 | public static float sp2px(Resources resources, float sp) { 17 | final float scale = resources.getDisplayMetrics().scaledDensity; 18 | return sp * scale; 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/res/drawable/ic_dashboard_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/res/drawable/ic_home_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/res/drawable/ic_notifications_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/res/layout/activity_demo.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 20 | 21 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /jimu-sample-project/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 13 | 14 |