diff --git a/ApiComponentService/.gitignore b/ApiComponentService/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/ApiComponentService/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/ApiComponentService/build.gradle b/ApiComponentService/build.gradle
new file mode 100644
index 0000000..9f37b7e
--- /dev/null
+++ b/ApiComponentService/build.gradle
@@ -0,0 +1,31 @@
+apply plugin: 'com.android.library'
+apply from: "${rootDir}/copy2.gradle"
+android {
+ compileSdkVersion 26
+ buildToolsVersion "26.0.1"
+
+ defaultConfig {
+ minSdkVersion 15
+ targetSdkVersion 26
+ versionCode 1
+ versionName "1.0"
+
+ testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
+ }
+}
+
+dependencies {
+ compile project(':basicres')
+ compile fileTree(include: ['*.jar'], dir: 'libs')
+ androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
+ exclude group: 'com.android.support', module: 'support-annotations'
+ })
+ testCompile 'junit:junit:4.12'
+}
diff --git a/ApiComponentService/proguard-rules.pro b/ApiComponentService/proguard-rules.pro
new file mode 100644
index 0000000..3f87d4e
--- /dev/null
+++ b/ApiComponentService/proguard-rules.pro
@@ -0,0 +1,25 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /Users/klee/Library/Android/sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/ApiComponentService/src/main/AndroidManifest.xml b/ApiComponentService/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..700a34b
--- /dev/null
+++ b/ApiComponentService/src/main/AndroidManifest.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/ApiComponentService/src/main/res/values/strings.xml b/ApiComponentService/src/main/res/values/strings.xml
new file mode 100644
index 0000000..601c61f
--- /dev/null
+++ b/ApiComponentService/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
+
+ componentservice
+
diff --git a/README.md b/README.md
index 41fce38..ab3c648 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,15 @@
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/luojilab/DDComponentForAndroid/pulls)
[![License](https://img.shields.io/badge/License-Apache%202.0-orange.svg)](https://github.com/luojilab/DDComponentForAndroid/blob/master/LICENSE)
+### 部分想法
+在得到的DDComponent基础上,加上了部分的想法实现
+
++ 1、实现组件对内对外的代码都放在组件内部,对外的改后缀名为.api,编译之前自动copy&rename为.java文件。
+ - a. 可以通过判断是sync还是assemble打包来确定要编译的组件
+ - b. 如果是sync的话,则读取所有组件中的.api文件
+ - c. 如果是某个组件单独运行的话,则只扫描该组件所依赖的组件中的.api文件以及自己组件中的.api文件
++ 2、内部有具体的实现Native方式(不使用Annotation)来进行UI跳转,这部分可忽略。
+
### 最新版本
模块|build-gradle|componentlib|router-anno-compiler|router-annotation
diff --git a/UIRouterTable/KotlinRouterTable.txt b/UIRouterTable/KotlinRouterTable.txt
index 447b4e9..9d0dad5 100644
--- a/UIRouterTable/KotlinRouterTable.txt
+++ b/UIRouterTable/KotlinRouterTable.txt
@@ -2,8 +2,8 @@ auto generated, do not change !!!!
HOST : kotlin
-分享杂志页面
+־ҳ
/shareMagazine
-author:com.luojilab.componentservice.share.bean.Author
+author:com.luojilab.api.share.bean.Author
bookName:String
diff --git a/UIRouterTable/ShareRouterTable.txt b/UIRouterTable/ShareRouterTable.txt
index 2a1176c..b6efce0 100644
--- a/UIRouterTable/ShareRouterTable.txt
+++ b/UIRouterTable/ShareRouterTable.txt
@@ -2,8 +2,8 @@ auto generated, do not change !!!!
HOST : share
-分享书籍页面
+鼮ҳ
/shareBook
-author:com.luojilab.componentservice.share.bean.Author
+author:com.luojilab.api.share.bean.Author
bookName:String
diff --git a/app/build.gradle b/app/build.gradle
index a5731d2..4699d68 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -41,7 +41,8 @@ android {
}
dependencies {
- compile project(':componentservice')
+ // compile project(':componentservice')
+ compile project(':ApiComponentService')
annotationProcessor project(':router-anno-compiler')
}
@@ -49,4 +50,3 @@ combuild {
applicationName = 'com.luojilab.componentdemo.application.AppApplication'
isRegisterCompoAuto = true
}
-
diff --git a/app/src/main/java/com/luojilab/componentdemo/MainActivity.java b/app/src/main/java/com/luojilab/componentdemo/MainActivity.java
index 2f598e4..fe8087b 100644
--- a/app/src/main/java/com/luojilab/componentdemo/MainActivity.java
+++ b/app/src/main/java/com/luojilab/componentdemo/MainActivity.java
@@ -7,11 +7,11 @@
import android.view.View;
import android.widget.Button;
+import com.luojilab.api.reader.readerbook.ReadBookService;
import com.luojilab.component.basiclib.ToastManager;
import com.luojilab.component.basicres.BaseActivity;
import com.luojilab.component.basicres.BaseApplication;
import com.luojilab.component.componentlib.router.Router;
-import com.luojilab.componentservice.readerbook.ReadBookService;
import com.luojilab.router.facade.annotation.RouteNode;
@RouteNode(path = "/main", desc = "首页")
@@ -28,8 +28,8 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
- installReadBookBtn = findViewById(R.id.install_share);
- uninstallReadBtn = findViewById(R.id.uninstall_share);
+ installReadBookBtn = (Button) findViewById(R.id.install_share);
+ uninstallReadBtn = (Button) findViewById(R.id.uninstall_share);
installReadBookBtn.setOnClickListener(this);
uninstallReadBtn.setOnClickListener(this);
showFragment();
@@ -69,8 +69,11 @@ public void onClick(View v) {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
- if (data != null) {
- ToastManager.show(BaseApplication.getAppContext(), data.getStringExtra("result"));
+ //分享组件 的 RESULT_CODE
+ if (resultCode == 8888) {
+ if (data != null) {
+ ToastManager.show(BaseApplication.getAppContext(), data.getStringExtra("result"));
+ }
}
}
}
diff --git a/bintrayv1.gradle b/bintrayv1.gradle
new file mode 100644
index 0000000..0c0b7bb
--- /dev/null
+++ b/bintrayv1.gradle
@@ -0,0 +1,65 @@
+apply plugin: 'com.jfrog.bintray'
+
+version = libraryVersion
+
+if (project.hasProperty("android")) { // Android libraries
+ task sourcesJar(type: Jar) {
+ classifier = 'sources'
+ from android.sourceSets.main.java.srcDirs
+ }
+
+ task javadoc(type: Javadoc) {
+ source = android.sourceSets.main.java.srcDirs
+ classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
+ }
+} else { // Java libraries
+ task sourcesJar(type: Jar, dependsOn: classes) {
+ classifier = 'sources'
+ from sourceSets.main.allSource
+ }
+}
+
+task javadocJar(type: Jar, dependsOn: javadoc) {
+ classifier = 'javadoc'
+ from javadoc.destinationDir
+}
+
+artifacts {
+ archives javadocJar
+ archives sourcesJar
+}
+
+//指定编译的编码
+tasks.withType(JavaCompile){
+ options.encoding = "UTF-8"
+}
+
+
+// Bintray
+Properties properties = new Properties()
+properties.load(project.rootProject.file('local.properties').newDataInputStream())
+
+bintray {
+ user = properties.getProperty("bintray.user")
+ key = properties.getProperty("bintray.apikey")
+
+ configurations = ['archives']
+ pkg {
+ repo = bintrayRepo
+ name = bintrayName
+ desc = libraryDescription
+ websiteUrl = siteUrl
+ vcsUrl = gitUrl
+ licenses = allLicenses
+ publish = true
+ publicDownloadNumbers = true
+ version {
+ desc = libraryDescription
+ gpg {
+ sign = true //Determines whether to GPG sign the files. The default is false
+ passphrase = properties.getProperty("bintray.gpg.password")
+ //Optional. The passphrase for GPG signing'
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/build-gradle/build.gradle b/build-gradle/build.gradle
index 8103d3f..0fe5a5d 100644
--- a/build-gradle/build.gradle
+++ b/build-gradle/build.gradle
@@ -10,8 +10,10 @@ ext {
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}
-apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
-apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
+//apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
+//apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
+apply from: '../installv1.gradle'
+apply from: '../bintrayv1.gradle'
dependencies {
compile 'com.android.tools.build:gradle:2.3.2'
diff --git a/build-gradle/src/main/groovy/com.dd.buildgradle/ComBuild.groovy b/build-gradle/src/main/groovy/com.dd.buildgradle/ComBuild.groovy
index 5e8405e..2f2897c 100644
--- a/build-gradle/src/main/groovy/com.dd.buildgradle/ComBuild.groovy
+++ b/build-gradle/src/main/groovy/com.dd.buildgradle/ComBuild.groovy
@@ -3,6 +3,7 @@ package com.dd.buildgradle
import com.dd.buildgradle.exten.ComExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
+import org.gradle.api.Task
class ComBuild implements Plugin {
@@ -10,6 +11,16 @@ class ComBuild implements Plugin {
String compilemodule = "app"
void apply(Project project) {
+ /**
+ * 每个Gradle的Project都维护了一个ExtenionContainer,
+ 我们可以通过project.extentions访问额外的Property和定义额外的Property
+
+ 弄好之后,在build.gradle中的配置如下面所示的格式
+ * combuild {
+ applicationName = 'com.luojilab.reader.runalone.application.ReaderApplication'
+ isRegisterCompoAuto = false
+ }
+ */
project.extensions.create('combuild', ComExtension)
String taskNames = project.gradle.startParameter.taskNames.toString()
@@ -44,6 +55,7 @@ class ComBuild implements Plugin {
//根据配置添加各种组件依赖,并且自动化生成组件加载代码
if (isRunAlone) {
+ //应用plugin为 application
project.apply plugin: 'com.android.application'
if (!module.equals(mainmodulename)) {
project.android.sourceSets {
@@ -56,10 +68,12 @@ class ComBuild implements Plugin {
}
System.out.println("apply plugin is " + 'com.android.application')
if (assembleTask.isAssemble && module.equals(compilemodule)) {
+ //编译组件
compileComponents(assembleTask, project)
project.android.registerTransform(new ComCodeTransform(project))
}
} else {
+ //应用plugin为 library
project.apply plugin: 'com.android.library'
System.out.println("apply plugin is " + 'com.android.library')
}
@@ -92,6 +106,7 @@ class ComBuild implements Plugin {
private AssembleTask getTaskInfo(List taskNames) {
AssembleTask assembleTask = new AssembleTask()
for (String task : taskNames) {
+ //ASSEMBLE打包 、 aR = assembleRelease 、RESGUARD混淆
if (task.toUpperCase().contains("ASSEMBLE")
|| task.contains("aR")
|| task.toUpperCase().contains("INSTALL")
@@ -101,6 +116,12 @@ class ComBuild implements Plugin {
}
assembleTask.isAssemble = true
String[] strs = task.split(":")
+ /**
+ * 根据当前的task,获取要运行的组件,规则如下:
+ * assembleRelease ---app
+ * app:assembleRelease :app:assembleRelease ---app
+ * sharecomponent:assembleRelease :sharecomponent:assembleRelease ---sharecomponent
+ */
assembleTask.modules.add(strs.length > 1 ? strs[strs.length - 2] : "all")
break
}
@@ -115,6 +136,11 @@ class ComBuild implements Plugin {
* @param project
*/
private void compileComponents(AssembleTask assembleTask, Project project) {
+ /**
+ * 从配置文件中读取要依赖的组件名 配置文件格式如下:
+ debugComponent=readercomponent,sharecomponent,sharecomponentkotlin
+ compileComponent=readercomponent,sharecomponent,sharecomponentkotlin
+ */
String components
if (assembleTask.isDebug) {
components = (String) project.properties.get("debugComponent")
@@ -126,6 +152,7 @@ class ComBuild implements Plugin {
System.out.println("there is no add dependencies ")
return
}
+ //通过 逗号分隔 转换为组件名数组
String[] compileComponents = components.split(",")
if (compileComponents == null || compileComponents.length == 0) {
System.out.println("there is no add dependencies ")
@@ -146,6 +173,7 @@ class ComBuild implements Plugin {
* 示例语法:module
* compileComponent=readercomponent,sharecomponent
*/
+ //如果为直接引用module工程
project.dependencies.add("compile", project.project(':' + str))
System.out.println("add dependencies project : " + str)
}
diff --git a/build-gradle/src/main/groovy/com.dd.buildgradle/ComCodeTransform.groovy b/build-gradle/src/main/groovy/com.dd.buildgradle/ComCodeTransform.groovy
index d0e9607..a081275 100644
--- a/build-gradle/src/main/groovy/com.dd.buildgradle/ComCodeTransform.groovy
+++ b/build-gradle/src/main/groovy/com.dd.buildgradle/ComCodeTransform.groovy
@@ -46,9 +46,9 @@ class ComCodeTransform extends Transform {
for (CtClass ctClass : activators) {
System.out.println("applicationlike is " + ctClass.getName())
}
-
+ //Transform的inputs有两种类型,一种是项目内的目录,一种是第三方的jar包,要分开遍历
transformInvocation.inputs.each { TransformInput input ->
- //对类型为jar文件的input进行遍历
+ //对类型为 jar文件 的input进行遍历
input.jarInputs.each { JarInput jarInput ->
//jar文件一般是第三方依赖库jar文件
// 重命名输出文件(同目录copyFile会冲突)
@@ -76,6 +76,7 @@ class ComCodeTransform extends Transform {
.replace("\\", ".")
.replace("/", ".")
if (classNameTemp.endsWith(".class")) {
+ // ".class".length == 6
String className = classNameTemp.substring(1, classNameTemp.length() - 6)
if (className.equals(applicationName)) {
injectApplicationCode(applications.get(0), activators, fileName)
@@ -83,6 +84,7 @@ class ComCodeTransform extends Transform {
}
}
}
+ //获取 output 目录
def dest = transformInvocation.outputProvider.getContentLocation(directoryInput.name,
directoryInput.contentTypes,
directoryInput.scopes, Format.DIRECTORY)
@@ -103,11 +105,16 @@ class ComCodeTransform extends Transform {
private void injectApplicationCode(CtClass ctClassApplication, List activators, String patch) {
System.out.println("injectApplicationCode begin")
+
+ //Defrosts the class so that the class can be modified again.
ctClassApplication.defrost()
try {
+ //在主项目的Application.onCreate()中插入调用ApplicationLike.onCreate()的代码
CtMethod attachBaseContextMethod = ctClassApplication.getDeclaredMethod("onCreate", null)
attachBaseContextMethod.insertAfter(getAutoLoadComCode(activators))
} catch (CannotCompileException | NotFoundException e) {
+ //在主项目的Application.onCreate()中插入调用ApplicationLike.onCreate()的代码
+ //如果上面的方法出现异常,则自己拼凑onCreate方法的具体实现
StringBuilder methodBody = new StringBuilder()
methodBody.append("protected void onCreate() {")
methodBody.append("super.onCreate();")
@@ -116,7 +123,7 @@ class ComCodeTransform extends Transform {
methodBody.append("}")
ctClassApplication.addMethod(CtMethod.make(methodBody.toString(), ctClassApplication))
} catch (Exception e) {
-
+ e.printStackTrace()
}
ctClassApplication.writeFile(patch)
ctClassApplication.detach()
@@ -124,6 +131,9 @@ class ComCodeTransform extends Transform {
System.out.println("injectApplicationCode success ")
}
+ /**
+ * 生成 ApplicationLike.onCreate() 的代码,便于在主项目的Application.onCreate()中插入
+ */
private String getAutoLoadComCode(List activators) {
StringBuilder autoLoadComCode = new StringBuilder()
for (CtClass ctClass : activators) {
@@ -133,7 +143,9 @@ class ComCodeTransform extends Transform {
return autoLoadComCode.toString()
}
-
+ /**
+ * 是否为真正的application
+ */
private boolean isApplication(CtClass ctClass) {
try {
if (applicationName != null && applicationName.equals(ctClass.getName())) {
@@ -144,7 +156,9 @@ class ComCodeTransform extends Transform {
}
return false
}
-
+ /**
+ * 是否为applicationlikes
+ */
private boolean isActivator(CtClass ctClass) {
try {
for (CtClass ctClassInter : ctClass.getInterfaces()) {
diff --git a/build-gradle/src/main/groovy/com.dd.buildgradle/ConvertUtils.groovy b/build-gradle/src/main/groovy/com.dd.buildgradle/ConvertUtils.groovy
index cd06dbe..e713270 100644
--- a/build-gradle/src/main/groovy/com.dd.buildgradle/ConvertUtils.groovy
+++ b/build-gradle/src/main/groovy/com.dd.buildgradle/ConvertUtils.groovy
@@ -19,7 +19,9 @@ class ConvertUtils {
classPool.insertClassPath(it.file.absolutePath)
org.apache.commons.io.FileUtils.listFiles(it.file, null, true).each {
if (it.absolutePath.endsWith(SdkConstants.DOT_CLASS)) {
- def className = it.absolutePath.substring(dirPath.length() + 1, it.absolutePath.length() - SdkConstants.DOT_CLASS.length()).replaceAll(Matcher.quoteReplacement(File.separator), '.')
+ def className = it.absolutePath.substring(dirPath.length() + 1,
+ it.absolutePath.length() - SdkConstants.DOT_CLASS.length())
+ .replaceAll(Matcher.quoteReplacement(File.separator), '.')
if (classNames.contains(className)) {
throw new RuntimeException("You have duplicate classes with the same name : " + className + " please remove duplicate classes ")
}
@@ -36,15 +38,19 @@ class ConvertUtils {
JarEntry libClass = classes.nextElement()
String className = libClass.getName()
if (className.endsWith(SdkConstants.DOT_CLASS)) {
- className = className.substring(0, className.length() - SdkConstants.DOT_CLASS.length()).replaceAll('/', '.')
+ className = className.substring(0, className.length() - SdkConstants.DOT_CLASS.length())
+ .replaceAll('/', '.')
if (classNames.contains(className)) {
- throw new RuntimeException("You have duplicate classes with the same name : " + className + " please remove duplicate classes ")
+ throw new RuntimeException("You have duplicate classes with the same name : "
+ + className + " please remove duplicate classes ")
}
classNames.add(className)
}
}
+ jarInputs.close()
}
}
+
classNames.each {
try {
allClass.add(classPool.get(it))
@@ -56,4 +62,4 @@ class ConvertUtils {
}
-}
\ No newline at end of file
+}
diff --git a/build-gradle/src/main/groovy/com.dd.buildgradle/exten/ComExtension.groovy b/build-gradle/src/main/groovy/com.dd.buildgradle/exten/ComExtension.groovy
index d92ee1c..59f4001 100644
--- a/build-gradle/src/main/groovy/com.dd.buildgradle/exten/ComExtension.groovy
+++ b/build-gradle/src/main/groovy/com.dd.buildgradle/exten/ComExtension.groovy
@@ -1,12 +1,12 @@
package com.dd.buildgradle.exten
-public class ComExtension {
+class ComExtension {
/**
* 是否自动注册组件,true则会使用字节码插入的方式自动注册代码
* false的话,需要手动使用反射的方式来注册
*/
- boolean isRegisterCompoAuto = false;
+ boolean isRegisterCompoAuto = false
/**
* 当前组件的applicationName,用于字节码插入。
diff --git a/componentlib/build.gradle b/componentlib/build.gradle
index 4974271..564b413 100644
--- a/componentlib/build.gradle
+++ b/componentlib/build.gradle
@@ -48,5 +48,7 @@ dependencies {
}
-apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
-apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
\ No newline at end of file
+//apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
+//apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
+apply from: '../installv1.gradle'
+apply from: '../bintrayv1.gradle'
\ No newline at end of file
diff --git a/componentservice/build.gradle b/componentservice/build.gradle
index d32d2d0..ab016fc 100644
--- a/componentservice/build.gradle
+++ b/componentservice/build.gradle
@@ -22,7 +22,6 @@ android {
}
dependencies {
-// compile project(':componentlib')
compile project(':basicres')
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
diff --git a/componentservice/src/main/java/com/luojilab/componentservice/share/ShareService.java b/componentservice/src/main/java/com/luojilab/componentservice/share/ShareService.java
new file mode 100644
index 0000000..2fc6209
--- /dev/null
+++ b/componentservice/src/main/java/com/luojilab/componentservice/share/ShareService.java
@@ -0,0 +1,13 @@
+package com.luojilab.componentservice.share;
+
+import android.app.Activity;
+
+/**
+ * 原生方式启动ShareActivity
+ *
+ * created by OuyangPeng at 2018/1/15 上午 11:36
+ */
+public interface ShareService {
+ void startShare2Activity(Activity context, String bookName , String author);
+ void startShare2ActivityForResult(Activity context, String bookName , String author , int requestCode);
+}
diff --git a/copy.gradle b/copy.gradle
new file mode 100644
index 0000000..badbbe3
--- /dev/null
+++ b/copy.gradle
@@ -0,0 +1,26 @@
+//同步任务(Sync)继承自复制任务(Copy),
+//当执行时会复制源文件到目标目录,然后从目标目录删除所有非复制文件。
+task copyApiToJava(type: Sync) {
+ description "复制组件中的 .api 文件到 ApiComponentService 库中,然后改名为 .java"
+ println "------> copyApiToJava() 开始了,复制组件中的 .api 文件到 ApiComponentService 库中,然后改名为 .java"
+
+ project.rootProject.subprojects.each {
+ println "------> copyApiToJava() 扫描项目 =" + it.name
+ if (it.name.toUpperCase().contains("COMPONENT")){
+ println "------>------>------> copyApiToJava() 开始扫描到的组件库为 : " + it.name
+ from "${rootDir}/${it.name}/src/main/java/com/luojilab/api"
+ }
+ }
+
+ into "${rootDir}/ApiComponentService/src/main/java/com/luojilab/api"
+ exclude '**/*.java'
+ include '**/*.api'
+
+ rename{String fileName ->
+ println "------> copyApiToJava() 要重命名文件:" + fileName
+ fileName.replace('.api', '.java')
+ }
+}
+
+preBuild.dependsOn copyApiToJava
+
diff --git a/copy2.gradle b/copy2.gradle
new file mode 100644
index 0000000..9d80d01
--- /dev/null
+++ b/copy2.gradle
@@ -0,0 +1,108 @@
+//同步任务(Sync)继承自复制任务(Copy),
+//当执行时会复制源文件到目标目录,然后从目标目录删除所有非复制文件。
+task copyApiToJava(type: Sync) {
+ description "复制需要依赖的组件中的 .api 文件到 ApiComponentService 库中,然后改名为 .java"
+ println "------> copyApiToJava()\t开始了,复制需要依赖的组件中的 .api 文件到 ApiComponentService 库中,然后改名为 .java"
+
+ //第一步、解析所有的task列表,确定好是点击Sync按钮还是哪个组件单独打包运行
+ List taskNames = project.gradle.startParameter.taskNames
+ println("------> copyApiToJava()\ttaskNames 列表为: " + taskNames.toString())
+
+ //是否打包的时候是debug模式
+ boolean isDebug = false
+ //是否打包
+ boolean isAssemble = false
+ //解析所有的任务,封装为modules列表
+ List modules = new ArrayList<>()
+ for (String task : taskNames) {
+ //ASSEMBLE打包 、 aR = assembleRelease 、RESGUARD混淆
+ if (task.toUpperCase().contains("ASSEMBLE")
+ || task.contains("aR")
+ || task.toUpperCase().contains("INSTALL")
+ || task.toUpperCase().contains("RESGUARD")) {
+ if (task.toUpperCase().contains("DEBUG")) {
+ isDebug = true
+ }
+ isAssemble = true
+ String[] strs = task.split(":")
+ /**
+ * 根据当前的task,获取要运行的组件,规则如下:
+ * assembleRelease ---app
+ * app:assembleRelease :app:assembleRelease ---app
+ * sharecomponent:assembleRelease :sharecomponent:assembleRelease ---sharecomponent
+ */
+ modules.add(strs.length > 1 ? strs[strs.length - 2] : "all")
+ break
+ }
+ }
+ //如果要打包的模块没有,那么就表示只是在Android Studio中点了Sync按钮同步代码而已,如果是同步的话就默认去扫描所有的组件中的.api
+ //默认是app,直接运行assembleRelease的时候,等同于运行app:assembleRelease
+ String compilemodule = "app"
+ if (modules.size() > 0 && modules.get(0) != null
+ && modules.get(0).trim().length() > 0 && !modules.get(0).equals("all")) {
+ compilemodule = modules.get(0)
+ println("------> copyApiToJava()\t要进行打包的模块为:" + modules.toString())
+ } else {
+ compilemodule = project.rootProject.property("mainmodulename")
+ println("------> copyApiToJava()\t没有要打包的模块,只是在【Android Studio】中点了【Sync】按钮同步代码而已,去扫描所有的组件中的.api")
+ }
+ if (compilemodule == null || compilemodule.trim().length() <= 0) {
+ compilemodule = "app"
+ println("------> copyApiToJava()\t没有要打包的模块,去扫描 app 中依赖的组件 的.api")
+ }
+
+ //第二步、读取从第一步得知的具体哪个组件的配置文件 gradle.properties,获取Project依赖的组件
+ Properties gradle_properties = new Properties()
+ String gradlePropertiesPath = "${rootDir}/${compilemodule}/gradle.properties"
+ println("------> copyApiToJava()\t要编译的组件为: " + compilemodule +" ,下面来读取该组件需要依赖的其他组件,读取的配置文件为:"+ gradlePropertiesPath)
+ gradle_properties.load(project.file(gradlePropertiesPath).newDataInputStream())
+
+ String components
+ if(isAssemble){
+ if (isDebug){
+ components = gradle_properties.getProperty("debugComponent")
+ println("------> copyApiToJava()\t任务为 Bubug版本的打包任务,读取gradle.properties配置文件中的【debugComponent】属性")
+ } else{
+ components = gradle_properties.getProperty("compileComponent")
+ println("------> copyApiToJava()\t任务为 Release版本的打包任务,读取gradle.properties配置文件中的【compileComponent】属性")
+ }
+ } else{
+ println("------> copyApiToJava()\t任务 不是 打包任务,读取gradle.properties配置文件中的【debugComponent】属性")
+ components = gradle_properties.getProperty("debugComponent")
+ }
+
+ //第三步、遍历 Project所依赖的组件 中的全部.api文件以及自己组件中的api文件,然后复制到ApiComponentService库中
+ println("------> copyApiToJava()\t读取到要依赖的组件为为:【"+ components + "】")
+ if(components == null || components.length() == 0){
+ println("------> copyApiToJava()\t没有需要额外依赖的组件")
+ } else {
+ //通过 逗号分隔 转换为组件名数组
+ String[] compileComponents = components.split(",")
+ if (compileComponents == null || compileComponents.length == 0) {
+ println("------> copyApiToJava()\t没有需要额外依赖的组件")
+ } else {
+ //copy依赖的库的组件中的api
+ for (String str : compileComponents) {
+ println("------> copyApiToJava()\t检测组件【 " + str +" 】,中是否有需要开始复制 .api 文件")
+ from "${rootDir}/${str}/src/main/java/com/luojilab/api"
+ }
+ }
+ }
+ //copy自己当前组件中的api
+ println("------> copyApiToJava()\t检测自己的组件【 " + compilemodule +" 】,中是否有需要开始复制 .api 文件")
+ from "${rootDir}/${compilemodule}/src/main/java/com/luojilab/api"
+ //复制到 ApiComponentService/src/main/java 目录中去
+ into "${rootDir}/ApiComponentService/src/main/java"
+ //排除所有的.java文件
+ exclude '**/*.java'
+ //包括所有的.api文件
+ include '**/*.api'
+ //改名
+ rename{String fileName ->
+ println "------> copyApiToJava() 要重命名文件:" + fileName
+ fileName.replace('.api', '.java')
+ }
+}
+//在preBuild之前,必须先运行copyApiToJava
+preBuild.dependsOn copyApiToJava
+
diff --git a/gradle.properties b/gradle.properties
index e4d5af6..a227d87 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -11,7 +11,10 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
+
+#mainmodulenameĿеhosṭһΪapp
mainmodulename=app
+
bintrayRepo=compbuild
publishedGroupId=com.luojilab.ddcomponent
siteUrl=https://github.com/luojilab/DDComponentForAndroid
diff --git a/installv1.gradle b/installv1.gradle
new file mode 100644
index 0000000..cdb363c
--- /dev/null
+++ b/installv1.gradle
@@ -0,0 +1,42 @@
+apply plugin: 'com.github.dcendents.android-maven'
+
+group = publishedGroupId // Maven Group ID for the artifact
+
+install {
+ repositories.mavenInstaller {
+ // This generates POM.xml with proper parameters
+ pom {
+ project {
+ packaging 'aar'
+ groupId publishedGroupId
+ artifactId artifact
+
+ // Add your description here
+ name libraryName
+ description libraryDescription
+ url siteUrl
+
+ // Set your license
+ licenses {
+ license {
+ name licenseName
+ url licenseUrl
+ }
+ }
+ developers {
+ developer {
+ id developerId
+ name developerName
+ email developerEmail
+ }
+ }
+ scm {
+ connection gitUrl
+ developerConnection gitUrl
+ url siteUrl
+
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/readercomponent/build.gradle b/readercomponent/build.gradle
index 48e8550..952ea54 100644
--- a/readercomponent/build.gradle
+++ b/readercomponent/build.gradle
@@ -1,5 +1,4 @@
apply plugin: 'com.dd.comgradle'
-
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
@@ -36,7 +35,8 @@ android {
}
dependencies {
- compile project(':componentservice')
+// compile project(':componentservice')
+ compile project(':ApiComponentService')
compile fileTree(include: ['*.jar'], dir: 'libs')
annotationProcessor 'com.luojilab.ddcomponent:router-anno-compiler:1.0.0'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
diff --git a/readercomponent/src/main/java/com/luojilab/api/reader/readerbook/ReadBookService.api b/readercomponent/src/main/java/com/luojilab/api/reader/readerbook/ReadBookService.api
new file mode 100644
index 0000000..4d160a1
--- /dev/null
+++ b/readercomponent/src/main/java/com/luojilab/api/reader/readerbook/ReadBookService.api
@@ -0,0 +1,13 @@
+package com.luojilab.api.reader.readerbook;
+
+import android.support.v4.app.Fragment;
+
+/**
+ * export module services
+ * Created by mrzhang on 2017/6/15.
+ */
+
+public interface ReadBookService {
+
+ Fragment getReadBookFragment();
+}
diff --git a/readercomponent/src/main/java/com/luojilab/api/reader/readerbook/ReadBookServiceTest.api b/readercomponent/src/main/java/com/luojilab/api/reader/readerbook/ReadBookServiceTest.api
new file mode 100644
index 0000000..40a51ff
--- /dev/null
+++ b/readercomponent/src/main/java/com/luojilab/api/reader/readerbook/ReadBookServiceTest.api
@@ -0,0 +1,13 @@
+package com.luojilab.api.reader.readerbook;
+
+import com.luojilab.api.share.bean.Author;
+
+/**
+ * export module services
+ * Created by mrzhang on 2017/6/15.
+ */
+
+public interface ReadBookServiceTest {
+ Author getAuthor();
+ void test(String author,String reader);
+}
diff --git a/readercomponent/src/main/java/com/luojilab/reader/ReaderFragment.java b/readercomponent/src/main/java/com/luojilab/reader/ReaderFragment.java
index 4ddbfdc..c3709ae 100644
--- a/readercomponent/src/main/java/com/luojilab/reader/ReaderFragment.java
+++ b/readercomponent/src/main/java/com/luojilab/reader/ReaderFragment.java
@@ -7,10 +7,11 @@
import android.view.View;
import android.view.ViewGroup;
+import com.luojilab.api.share.ShareService;
+import com.luojilab.api.share.bean.Author;
+import com.luojilab.component.componentlib.router.Router;
import com.luojilab.component.componentlib.router.ui.UIRouter;
import com.luojilab.component.componentlib.service.JsonService;
-import com.luojilab.componentservice.share.bean.Author;
-
/**
* Created by mrzhang on 2017/6/15.
@@ -51,7 +52,20 @@ public void onClick(View v) {
goToShareActivityForResult();
}
});
+ rootView.findViewById(R.id.tv_4).setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ goToShareActivityByNative();
+ }
+ });
+ rootView.findViewById(R.id.tv_5).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ goToShareActivityForResultByNative();
+ }
+ });
}
return rootView;
}
@@ -86,5 +100,43 @@ private void goToShareActivityForResult() {
"DDComp://share/shareBook?bookName=Gone with the Wind&author="
+ JsonService.Factory.getInstance().create().toJsonString(author), null, REQUEST_CODE);
}
+ /**
+ * 使用原生的方法来进行跳转
+ */
+ private void goToShareActivityByNative() {
+ Author author = new Author();
+ author.setName("OuyangPeng");
+ author.setCounty("China");
+ String authorString = JsonService.Factory.getInstance().create().toJsonString(author);
+
+ String bookName = "goToShareActivityByNative";
+
+ Router router = Router.getInstance();
+ ShareService service = (ShareService) router.getService(ShareService.class.getSimpleName());
+ if (service != null) {
+ service.startShare2Activity(getActivity(), bookName, authorString);
+ }
+ }
+
+ /**
+ * 使用原生的方法来进行跳转,并且处理返回结果
+ */
+ private void goToShareActivityForResultByNative() {
+ Author author = new Author();
+ author.setName("OuyangPeng");
+ author.setCounty("China");
+ String authorString = JsonService.Factory.getInstance().create().toJsonString(author);
+
+ String bookName = "goToShareActivityForResultByNative";
+
+ Router router = Router.getInstance();
+
+ ShareService service = (ShareService) router.getService(ShareService.class.getSimpleName());
+ if (service != null) {
+ service.startShare2ActivityForResult(getActivity(), bookName, authorString, REQUEST_CODE);
+ }
+ }
+
+
}
diff --git a/readercomponent/src/main/java/com/luojilab/reader/applike/ReaderAppLike.java b/readercomponent/src/main/java/com/luojilab/reader/applike/ReaderAppLike.java
index 14d2b5a..1320aa6 100644
--- a/readercomponent/src/main/java/com/luojilab/reader/applike/ReaderAppLike.java
+++ b/readercomponent/src/main/java/com/luojilab/reader/applike/ReaderAppLike.java
@@ -1,9 +1,9 @@
package com.luojilab.reader.applike;
+import com.luojilab.api.reader.readerbook.ReadBookService;
import com.luojilab.component.componentlib.applicationlike.IApplicationLike;
import com.luojilab.component.componentlib.router.Router;
import com.luojilab.component.componentlib.router.ui.UIRouter;
-import com.luojilab.componentservice.readerbook.ReadBookService;
import com.luojilab.reader.serviceimpl.ReadBookServiceImpl;
/**
diff --git a/readercomponent/src/main/java/com/luojilab/reader/serviceimpl/ReadBookServiceImpl.java b/readercomponent/src/main/java/com/luojilab/reader/serviceimpl/ReadBookServiceImpl.java
index fb15792..e5ddd3f 100644
--- a/readercomponent/src/main/java/com/luojilab/reader/serviceimpl/ReadBookServiceImpl.java
+++ b/readercomponent/src/main/java/com/luojilab/reader/serviceimpl/ReadBookServiceImpl.java
@@ -2,7 +2,7 @@
import android.support.v4.app.Fragment;
-import com.luojilab.componentservice.readerbook.ReadBookService;
+import com.luojilab.api.reader.readerbook.ReadBookService;
import com.luojilab.reader.ReaderFragment;
/**
diff --git a/readercomponent/src/main/res/layout/readerbook_fragment_reader.xml b/readercomponent/src/main/res/layout/readerbook_fragment_reader.xml
index d093bdd..917e897 100644
--- a/readercomponent/src/main/res/layout/readerbook_fragment_reader.xml
+++ b/readercomponent/src/main/res/layout/readerbook_fragment_reader.xml
@@ -45,4 +45,26 @@
android:textAllCaps="false"
android:textSize="16sp" />
+
+
+
+
diff --git a/readercomponent/src/main/runalone/java/com/luojilab/reader/runalone/ReaderTestActivity.java b/readercomponent/src/main/runalone/java/com/luojilab/reader/runalone/ReaderTestActivity.java
index ea58943..607edb1 100644
--- a/readercomponent/src/main/runalone/java/com/luojilab/reader/runalone/ReaderTestActivity.java
+++ b/readercomponent/src/main/runalone/java/com/luojilab/reader/runalone/ReaderTestActivity.java
@@ -1,10 +1,13 @@
package com.luojilab.reader.runalone;
+import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
+import com.luojilab.component.basiclib.ToastManager;
+import com.luojilab.component.basicres.BaseApplication;
import com.luojilab.reader.R;
import com.luojilab.reader.ReaderFragment;
@@ -24,4 +27,16 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.tab_content, fragment).commitAllowingStateLoss();
}
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ //分享组件 的 RESULT_CODE
+ if (resultCode == 8888) {
+ if (data != null) {
+ ToastManager.show(BaseApplication.getAppContext(), data.getStringExtra("result"));
+ }
+ }
+ }
+
}
diff --git a/router-anno-compiler/build.gradle b/router-anno-compiler/build.gradle
index 258fd87..324fa51 100644
--- a/router-anno-compiler/build.gradle
+++ b/router-anno-compiler/build.gradle
@@ -11,8 +11,10 @@ ext {
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}
-apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
-apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
+//apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
+//apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
+apply from: '../installv1.gradle'
+apply from: '../bintrayv1.gradle'
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
diff --git a/router-annotation/build.gradle b/router-annotation/build.gradle
index 7070f6a..661b72b 100644
--- a/router-annotation/build.gradle
+++ b/router-annotation/build.gradle
@@ -20,5 +20,7 @@ compileJava {
targetCompatibility = '1.7'
}
-apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
-apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
\ No newline at end of file
+//apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
+//apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
+apply from: '../installv1.gradle'
+apply from: '../bintrayv1.gradle'
diff --git a/settings.gradle b/settings.gradle
index e174e0b..84de9ed 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -3,7 +3,8 @@ include ':app',
':componentlib',
':readercomponent',
':sharecomponent',
- ':componentservice',
+ ':ApiComponentService',
+// ':componentservice',
':build-gradle',
':basiclib',
':basicres',
diff --git a/sharecomponent/build.gradle b/sharecomponent/build.gradle
index 0ac7c71..fc91872 100644
--- a/sharecomponent/build.gradle
+++ b/sharecomponent/build.gradle
@@ -1,6 +1,5 @@
apply plugin: 'com.dd.comgradle'
-
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
@@ -33,7 +32,8 @@ android {
}
dependencies {
- compile project(':componentservice')
+// compile project(':componentservice')
+ compile project(':ApiComponentService')
annotationProcessor 'com.luojilab.ddcomponent:router-anno-compiler:1.0.0'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
diff --git a/sharecomponent/src/main/AndroidManifest.xml b/sharecomponent/src/main/AndroidManifest.xml
index daba9b1..ce36db8 100644
--- a/sharecomponent/src/main/AndroidManifest.xml
+++ b/sharecomponent/src/main/AndroidManifest.xml
@@ -13,6 +13,9 @@
+
+
+
diff --git a/sharecomponent/src/main/java/com/luojilab/api/share/ShareService.api b/sharecomponent/src/main/java/com/luojilab/api/share/ShareService.api
new file mode 100644
index 0000000..cd863dd
--- /dev/null
+++ b/sharecomponent/src/main/java/com/luojilab/api/share/ShareService.api
@@ -0,0 +1,13 @@
+package com.luojilab.api.share;
+
+import android.app.Activity;
+
+/**
+ * 原生方式启动ShareActivity
+ *
+ * created by OuyangPeng at 2018/1/15 上午 11:36
+ */
+public interface ShareService {
+ void startShare2Activity(Activity context, String bookName, String author);
+ void startShare2ActivityForResult(Activity context, String bookName, String author, int requestCode);
+}
diff --git a/sharecomponent/src/main/java/com/luojilab/api/share/bean/Author.api b/sharecomponent/src/main/java/com/luojilab/api/share/bean/Author.api
new file mode 100644
index 0000000..c4727e9
--- /dev/null
+++ b/sharecomponent/src/main/java/com/luojilab/api/share/bean/Author.api
@@ -0,0 +1,35 @@
+package com.luojilab.api.share.bean;
+
+/**
+ * Created by mrzhang on 2017/12/14.
+ */
+
+public class Author {
+ private String name;
+ private int age;
+ private String county;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public String getCounty() {
+ return county;
+ }
+
+ public void setCounty(String county) {
+ this.county = county;
+ }
+}
diff --git a/sharecomponent/src/main/java/com/luojilab/share/Share2Activity.java b/sharecomponent/src/main/java/com/luojilab/share/Share2Activity.java
new file mode 100644
index 0000000..a665a47
--- /dev/null
+++ b/sharecomponent/src/main/java/com/luojilab/share/Share2Activity.java
@@ -0,0 +1,69 @@
+package com.luojilab.share;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v7.app.AppCompatActivity;
+import android.widget.TextView;
+
+import com.luojilab.api.share.bean.Author;
+import com.luojilab.component.componentlib.service.AutowiredService;
+import com.luojilab.component.componentlib.service.JsonService;
+
+/**
+ * 测试使用原生的是否可以
+ *
+ * created by OuyangPeng at 2018/1/15 上午 11:29
+ */
+public class Share2Activity extends AppCompatActivity {
+
+ String bookName;
+
+ Author author;
+
+ private TextView tvShareTitle;
+ private TextView tvShareBook;
+ private TextView tvAuthor;
+ private TextView tvCounty;
+
+ private final static int RESULT_CODE = 8888;
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ AutowiredService.Factory.getInstance().create().autowire(this);
+ setContentView(R.layout.share_activity_share);
+
+ tvShareTitle = (TextView)findViewById(R.id.share_title);
+ tvShareBook = (TextView)findViewById(R.id.share_tv_tag);
+ tvAuthor = (TextView)findViewById(R.id.share_tv_author);
+ tvCounty = (TextView)findViewById(R.id.share_tv_county);
+
+ tvShareTitle.setText("Book2");
+
+
+ bookName = getIntent().getStringExtra("bookName");
+ String authorString = getIntent().getStringExtra("author");
+ System.out.println("获取到的参数为:bookName = " + bookName + " author = " + authorString);
+ author = JsonService.Factory.getInstance().create().parseObject(authorString,Author.class);
+
+ if (bookName != null) {
+ tvShareBook.setText(bookName);
+ }
+
+ if (author != null) {
+ tvAuthor.setText(author.getName());
+ tvCounty.setText(author.getCounty());
+ }
+
+ Intent intent = new Intent();
+ intent.putExtra("result", "Share Success! OuyangPeng's method!");
+ setResult(RESULT_CODE, intent);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+
+ }
+}
diff --git a/sharecomponent/src/main/java/com/luojilab/share/ShareActivity.java b/sharecomponent/src/main/java/com/luojilab/share/ShareActivity.java
index 8f24820..7f4c30b 100644
--- a/sharecomponent/src/main/java/com/luojilab/share/ShareActivity.java
+++ b/sharecomponent/src/main/java/com/luojilab/share/ShareActivity.java
@@ -3,12 +3,11 @@
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
-import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
+import com.luojilab.api.share.bean.Author;
import com.luojilab.component.basicres.BaseActivity;
import com.luojilab.component.componentlib.service.AutowiredService;
-import com.luojilab.componentservice.share.bean.Author;
import com.luojilab.router.facade.annotation.Autowired;
import com.luojilab.router.facade.annotation.RouteNode;
@@ -37,10 +36,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
AutowiredService.Factory.getInstance().create().autowire(this);
setContentView(R.layout.share_activity_share);
- tvShareTitle = findViewById(R.id.share_title);
- tvShareBook = findViewById(R.id.share_tv_tag);
- tvAuthor = findViewById(R.id.share_tv_author);
- tvCounty = findViewById(R.id.share_tv_county);
+ tvShareTitle = (TextView)findViewById(R.id.share_title);
+ tvShareBook = (TextView)findViewById(R.id.share_tv_tag);
+ tvAuthor = (TextView)findViewById(R.id.share_tv_author);
+ tvCounty = (TextView)findViewById(R.id.share_tv_county);
tvShareTitle.setText("Book");
@@ -54,8 +53,14 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}
Intent intent = new Intent();
- intent.putExtra("result", "Share Success");
+ intent.putExtra("result", "Share Success! OuyangPeng");
setResult(RESULT_CODE, intent);
}
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+
+ }
}
diff --git a/sharecomponent/src/main/java/com/luojilab/share/applike/ShareApplike.java b/sharecomponent/src/main/java/com/luojilab/share/applike/ShareApplike.java
index d4f7567..eab6a78 100644
--- a/sharecomponent/src/main/java/com/luojilab/share/applike/ShareApplike.java
+++ b/sharecomponent/src/main/java/com/luojilab/share/applike/ShareApplike.java
@@ -1,23 +1,28 @@
package com.luojilab.share.applike;
+import com.luojilab.api.share.ShareService;
import com.luojilab.component.componentlib.applicationlike.IApplicationLike;
+import com.luojilab.component.componentlib.router.Router;
import com.luojilab.component.componentlib.router.ui.UIRouter;
+import com.luojilab.share.serviceimpl.ShareServiceImpl;
/**
* Created by mrzhang on 2017/6/15.
*/
public class ShareApplike implements IApplicationLike {
-
+ Router router = Router.getInstance();
UIRouter uiRouter = UIRouter.getInstance();
@Override
public void onCreate() {
uiRouter.registerUI("share");
+ router.addService(ShareService.class.getSimpleName(), new ShareServiceImpl());
}
@Override
public void onStop() {
uiRouter.unregisterUI("share");
+ router.removeService(ShareService.class.getSimpleName());
}
}
diff --git a/sharecomponent/src/main/java/com/luojilab/share/serviceimpl/ShareServiceImpl.java b/sharecomponent/src/main/java/com/luojilab/share/serviceimpl/ShareServiceImpl.java
new file mode 100644
index 0000000..ff82192
--- /dev/null
+++ b/sharecomponent/src/main/java/com/luojilab/share/serviceimpl/ShareServiceImpl.java
@@ -0,0 +1,29 @@
+package com.luojilab.share.serviceimpl;
+
+import android.app.Activity;
+import android.content.Intent;
+import com.luojilab.api.share.ShareService;
+import com.luojilab.share.Share2Activity;
+
+/**
+ * 实现原生方式跳转Activity
+ *
+ * created by OuyangPeng at 2018/1/15 上午 11:40
+ */
+public class ShareServiceImpl implements ShareService {
+ @Override
+ public void startShare2Activity(Activity context, String bookName, String author) {
+ Intent intent = new Intent(context, Share2Activity.class);
+ intent.putExtra("bookName", bookName);
+ intent.putExtra("author", author);
+ context.startActivity(intent);
+ }
+
+ @Override
+ public void startShare2ActivityForResult(Activity context, String bookName, String author, int requestCode) {
+ Intent intent = new Intent(context, Share2Activity.class);
+ intent.putExtra("bookName", bookName);
+ intent.putExtra("author", author);
+ context.startActivityForResult(intent,requestCode);
+ }
+}
diff --git a/sharecomponentkotlin/build.gradle b/sharecomponentkotlin/build.gradle
index ac2f0b0..2922f9d 100644
--- a/sharecomponentkotlin/build.gradle
+++ b/sharecomponentkotlin/build.gradle
@@ -2,7 +2,6 @@ apply plugin: 'com.dd.comgradle'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
-
kapt {
arguments {
arg("host", "kotlin")
@@ -36,7 +35,8 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
- compile project(':componentservice')
+ // compile project(':componentservice')
+ compile project(':ApiComponentService')
kapt 'com.luojilab.ddcomponent:router-anno-compiler:1.0.0'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
diff --git a/sharecomponentkotlin/src/main/java/com/luojilab/share/kotlin/ShareMessageActivity.kt b/sharecomponentkotlin/src/main/java/com/luojilab/share/kotlin/ShareMessageActivity.kt
index b13ebd7..70966af 100644
--- a/sharecomponentkotlin/src/main/java/com/luojilab/share/kotlin/ShareMessageActivity.kt
+++ b/sharecomponentkotlin/src/main/java/com/luojilab/share/kotlin/ShareMessageActivity.kt
@@ -1,8 +1,8 @@
package com.luojilab.share.kotlin
import android.os.Bundle
+import com.luojilab.api.share.bean.Author
import com.luojilab.component.basicres.BaseActivity
-import com.luojilab.componentservice.share.bean.Author
import com.luojilab.router.facade.annotation.Autowired
import com.luojilab.router.facade.annotation.RouteNode
import kotlinx.android.synthetic.main.kotlin_activity_share.*