├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── io │ │ └── github │ │ └── iamyours │ │ └── plugins │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── iamyours │ │ │ └── plugins │ │ │ ├── App.kt │ │ │ ├── MainActivity.kt │ │ │ └── TestActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.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 │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── io │ └── github │ └── iamyours │ └── plugins │ └── ExampleUnitTest.kt ├── build.gradle ├── buildsrc ├── .gitignore ├── binary.gradle ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── groovy │ └── io │ │ └── github │ │ └── iamyours │ │ ├── RouterPlugin.groovy │ │ └── transform │ │ └── RouterTransform.groovy │ └── resources │ └── META-INF │ └── gradle-plugins │ └── RouterPlugin.properties ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── news ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── io │ │ └── github │ │ └── iamyours │ │ └── news │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── iamyours │ │ │ └── news │ │ │ └── NewsListActivity.kt │ └── res │ │ ├── layout │ │ └── activity_news_list.xml │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── io │ └── github │ └── iamyours │ └── news │ └── ExampleUnitTest.java ├── router-api ├── .gitignore ├── binary.gradle ├── build.gradle └── src │ └── main │ └── java │ └── io │ └── github │ └── iamyours │ └── router │ ├── ARouter.java │ ├── Callback.java │ ├── CallbackFragment.java │ ├── Postcard.java │ ├── RouteMap.java │ └── annotation │ └── Route.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SimpleRouter 2 | a router plugin for android 3 | 4 | # Feature 5 | - simple config,easy to use 6 | - without reflection,batter performance 7 | - simple callback without onActivityResult in activity 8 | 9 | # Lastest version 10 | module|router-api|router-plugin 11 | ---|---|--- 12 | version|[ ![Download](https://api.bintray.com/packages/iamyours/maven/router-api/images/download.svg?version=1.0.1) ](https://bintray.com/iamyours/maven/router-api/1.0.1/link)|[ ![Download](https://api.bintray.com/packages/iamyours/maven/router-plugin/images/download.svg?version=1.0.1) ](https://bintray.com/iamyours/maven/router-plugin/1.0.1/link) 13 | 14 | # Quick start 15 | ### Configuration 16 | add classpath in yours project build.gradle 17 | ``` gradle 18 | classpath 'io.github.iamyours:router-plugin:1.0.1' 19 | ``` 20 | apply plugin in app module 21 | ``` gradle 22 | apply plugin: 'RouterPlugin' 23 | ``` 24 | add dependency in the module that will use @Route annotation,you can add it in common module. 25 | ``` gradle 26 | api 'io.github.iamyours:router-api:1.0.1' 27 | ``` 28 | 29 | ### add route annotation 30 | ``` kotlin 31 | @Route(path = "/test/activity") 32 | class YourActivity : AppCompatActivity(){ 33 | ... 34 | } 35 | ``` 36 | ### jump with router 37 | ``` kotlin 38 | ARouter.getInstance() 39 | .build("/test/test") 40 | .navigation(this) { _, resultCode, data -> 41 | val title = data?.getStringExtra("title")//data can be null,so mark it with ? 42 | } 43 | 44 | ``` 45 | ### for java 46 | ``` java 47 | ARouter.getInstance() 48 | .build("/test/test") 49 | .navigation(this, new Callback() { 50 | @Override 51 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 52 | 53 | } 54 | }); 55 | ``` 56 | ### If Proguard is turn on 57 | add rules in proguard-rules.pro 58 | ``` 59 | -keep public class io.github.iamyours.router.**{*;} 60 | ``` 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | apply plugin: 'RouterPlugin' 6 | 7 | android { 8 | compileSdkVersion 28 9 | defaultConfig { 10 | applicationId "io.github.iamyours.plugins" 11 | minSdkVersion 14 12 | targetSdkVersion 28 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(dir: 'libs', include: ['*.jar']) 27 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 28 | implementation 'com.android.support:appcompat-v7:28.0.0' 29 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 30 | testImplementation 'junit:junit:4.12' 31 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 33 | implementation project(':news') 34 | } 35 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/io/github/iamyours/plugins/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.iamyours.plugins 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("io.github.iamyours.plugins", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/iamyours/plugins/App.kt: -------------------------------------------------------------------------------- 1 | package io.github.iamyours.plugins 2 | 3 | import android.app.Application 4 | import io.github.iamyours.router.ARouter 5 | 6 | class App : Application() { 7 | override fun onCreate() { 8 | super.onCreate() 9 | ARouter.getInstance().init() 10 | } 11 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/iamyours/plugins/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.iamyours.plugins 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import android.support.v7.app.AppCompatActivity 6 | import android.util.Log 7 | import io.github.iamyours.router.ARouter 8 | import io.github.iamyours.router.annotation.Route 9 | import kotlinx.android.synthetic.main.activity_main.* 10 | 11 | @Route(path = "/app/main") 12 | class MainActivity : AppCompatActivity() { 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | setContentView(R.layout.activity_main) 17 | tv1.setOnClickListener { 18 | ARouter.getInstance().build("/news/news_list") 19 | .withString("title", "from main") 20 | .navigation(this, 1) { _, resultCode, data -> 21 | Log.i("test", "resultCode:$resultCode,data:$data") 22 | tv1.text = data?.getStringExtra("name") ?: "" 23 | } 24 | } 25 | } 26 | 27 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 28 | super.onActivityResult(requestCode, resultCode, data) 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/iamyours/plugins/TestActivity.java: -------------------------------------------------------------------------------- 1 | package io.github.iamyours.plugins; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.app.AppCompatActivity; 7 | 8 | import io.github.iamyours.router.ARouter; 9 | import io.github.iamyours.router.Callback; 10 | 11 | public class TestActivity extends AppCompatActivity{ 12 | @Override 13 | protected void onCreate(@Nullable Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | ARouter.getInstance().build("/app/main") 16 | .navigation(this, new Callback() { 17 | @Override 18 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 19 | 20 | } 21 | }); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamyours/SimpleRouter/bdbb7367a47a7941f97f72425164ac7b582d6810/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamyours/SimpleRouter/bdbb7367a47a7941f97f72425164ac7b582d6810/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamyours/SimpleRouter/bdbb7367a47a7941f97f72425164ac7b582d6810/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamyours/SimpleRouter/bdbb7367a47a7941f97f72425164ac7b582d6810/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamyours/SimpleRouter/bdbb7367a47a7941f97f72425164ac7b582d6810/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamyours/SimpleRouter/bdbb7367a47a7941f97f72425164ac7b582d6810/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamyours/SimpleRouter/bdbb7367a47a7941f97f72425164ac7b582d6810/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamyours/SimpleRouter/bdbb7367a47a7941f97f72425164ac7b582d6810/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamyours/SimpleRouter/bdbb7367a47a7941f97f72425164ac7b582d6810/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamyours/SimpleRouter/bdbb7367a47a7941f97f72425164ac7b582d6810/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CommonPlugins 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/io/github/iamyours/plugins/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.iamyours.plugins 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.2.30' 5 | repositories { 6 | google() 7 | jcenter() 8 | maven{url "https://dl.bintray.com/iamyours/maven/"} 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.1.2' 12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 13 | // classpath "io.github.iamyours:router-plugin:1.0.0" 14 | // 15 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' 16 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' 17 | // NOTE: Do not place your application dependencies here; they belong 18 | // in the individual module build.gradle files 19 | } 20 | } 21 | 22 | allprojects { 23 | repositories { 24 | google() 25 | jcenter() 26 | maven{url "https://dl.bintray.com/iamyours/maven/"} 27 | } 28 | } 29 | 30 | task clean(type: Delete) { 31 | delete rootProject.buildDir 32 | } 33 | -------------------------------------------------------------------------------- /buildsrc/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /buildsrc/binary.gradle: -------------------------------------------------------------------------------- 1 | //apply plugin: 'com.jfrog.bintray' 2 | //apply plugin: 'maven-publish' 3 | //apply plugin: 'java' 4 | //apply plugin: 'signing' 5 | //apply plugin: 'maven' 6 | // 7 | //group = "io.github.iamyours" 8 | //version = "1.0.1" 9 | //project.archivesBaseName = "router-plugin" 10 | // 11 | //task javadocJar(type: Jar, dependsOn: javadoc) { 12 | // classifier = 'javadoc' 13 | // from javadoc.destinationDir 14 | //} 15 | // 16 | //task sourceJar(type: Jar) { 17 | // classifier = 'sources' 18 | // from sourceSets.main.allSource 19 | //} 20 | // 21 | //ext { 22 | // pomFilePath = "${project.buildDir.absolutePath}/tmp/pom.xml" 23 | // pomFile = file(pomFilePath) 24 | //} 25 | // 26 | //configurations { 27 | // pom 28 | //} 29 | // 30 | //artifacts { 31 | // archives jar 32 | // archives sourceJar 33 | // archives javadocJar 34 | // if (pomFile.exists()) { 35 | // pom pomFile 36 | // } 37 | //} 38 | // 39 | //task signJars(type: Sign, dependsOn: [jar, javadocJar, sourceJar]) { 40 | // sign configurations.archives 41 | //} 42 | // 43 | //task signPom(type: Sign) { 44 | // sign configurations.pom 45 | //} 46 | // 47 | //if (project.ext.pomFile.exists()) { 48 | // task preparePublication(dependsOn: [signJars, signPom]) 49 | //} else { 50 | // task preparePublication(dependsOn: signJars) 51 | //} 52 | // 53 | //def getSignatureFiles = { 54 | // def allFiles = project.tasks.signJars.signatureFiles.collect{it} 55 | // def signedSources = allFiles.find{ it.name.contains('-sources') } 56 | // def signedJavadoc = allFiles.find{ it.name.contains('-javadoc') } 57 | // def signedJar = (allFiles - [signedSources, signJars])[0] 58 | // return [ 59 | // [archive: signedSources, classifier: 'sources', extension: 'jar.asc'], 60 | // [archive: signedJavadoc, classifier: 'javadoc', extension: 'jar.asc'], 61 | // [archive: signedJar, classifier: 'null', extension: 'jar.asc'] 62 | // ] 63 | //} 64 | // 65 | //def getPomSignature = { 66 | // return project.tasks.signPom.signatureFiles.collect{ it }[0] 67 | //} 68 | // 69 | //def siteUrl = 'https://github.com/iamyours/SimpleRouter' 70 | //def gitUrl = 'https://github.com/iamyours/SimpleRouter.git' 71 | //def issueUrl = 'https://github.com/iamyours/SimpleRouter/issues' 72 | // 73 | //install { 74 | // repositories.mavenInstaller { 75 | //// generates POM.xml with proper parameters 76 | // pom { 77 | // project { 78 | // packaging 'jar' 79 | // name 'The Android Plugin for Router' 80 | // url siteUrl 81 | // 82 | // licenses { 83 | // license { 84 | // name 'The Apache Software License, Version 2.0' 85 | // url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 86 | // } 87 | // } 88 | // developers { 89 | // developer { 90 | // id 'RogerYan' //填写的一些基本信息 91 | // name 'Roger' 92 | // email 'yan127422@163.com' 93 | // } 94 | // } 95 | // 96 | // scm { 97 | // connection gitUrl 98 | // developerConnection gitUrl 99 | // url siteUrl 100 | // } 101 | // } 102 | // } 103 | // } 104 | //} 105 | // 106 | // 107 | //bintray { 108 | // user = "iamyours" 109 | // key = "xx" 110 | // configurations = ['archives'] 111 | // pkg { 112 | // repo = "maven" //bintray 上面 Package名字 113 | // name = "router-plugin" //bintray 上面项目名 114 | // desc = 'The Android Plugin for Router' 115 | // websiteUrl = siteUrl 116 | // vcsUrl = gitUrl 117 | // issueTrackerUrl = issueUrl 118 | // licenses = ["Apache-2.0"] 119 | // labels = 'Groovy' 120 | // publicDownloadNumbers = true 121 | // publish = true 122 | // } 123 | //} 124 | -------------------------------------------------------------------------------- /buildsrc/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | 3 | dependencies { 4 | implementation 'com.android.tools.build:gradle:3.1.2' 5 | compile 'com.android.tools.build:transform-api:1.5.0' 6 | compile 'org.javassist:javassist:3.20.0-GA' 7 | compile gradleApi() 8 | compile localGroovy() 9 | } 10 | repositories { 11 | jcenter() 12 | google() 13 | } 14 | 15 | apply from: 'binary.gradle' -------------------------------------------------------------------------------- /buildsrc/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /buildsrc/src/main/groovy/io/github/iamyours/RouterPlugin.groovy: -------------------------------------------------------------------------------- 1 | package io.github.iamyours 2 | 3 | import io.github.iamyours.transform.RouterTransform 4 | import org.gradle.api.Plugin 5 | import org.gradle.api.Project 6 | 7 | class RouterPlugin implements Plugin { 8 | 9 | @Override 10 | void apply(Project project) { 11 | project.android.registerTransform(new RouterTransform(project)) 12 | } 13 | } -------------------------------------------------------------------------------- /buildsrc/src/main/groovy/io/github/iamyours/transform/RouterTransform.groovy: -------------------------------------------------------------------------------- 1 | package io.github.iamyours.transform 2 | 3 | import com.android.build.api.transform.QualifiedContent 4 | import com.android.build.api.transform.Transform 5 | 6 | import com.android.build.api.transform.* 7 | import com.android.build.gradle.internal.pipeline.TransformManager 8 | import javassist.ClassPool 9 | import javassist.CtClass 10 | import javassist.CtMethod 11 | import org.apache.commons.codec.digest.DigestUtils 12 | import org.apache.commons.io.FileUtils 13 | import org.apache.commons.io.IOUtils 14 | import org.gradle.api.Project 15 | import org.objectweb.asm.ClassReader 16 | import org.objectweb.asm.tree.AnnotationNode 17 | import org.objectweb.asm.tree.ClassNode 18 | 19 | import java.util.jar.JarEntry 20 | import java.util.jar.JarFile 21 | import java.util.jar.JarOutputStream 22 | import java.util.zip.ZipEntry 23 | 24 | public class RouterTransform extends Transform { 25 | private static final String DEFAULT_NAME = "RouterTransform" 26 | Project project 27 | 28 | RouterTransform(Project project) { 29 | this.project = project 30 | } 31 | 32 | @Override 33 | String getName() { 34 | return DEFAULT_NAME 35 | } 36 | 37 | @Override 38 | Set getInputTypes() { 39 | return TransformManager.CONTENT_CLASS 40 | } 41 | 42 | @Override 43 | Set getScopes() { 44 | return TransformManager.SCOPE_FULL_PROJECT 45 | } 46 | 47 | @Override 48 | boolean isIncremental() { 49 | return false 50 | } 51 | 52 | def routeMap = [:] 53 | static final ROUTE_NAME = "io.github.iamyours:router-api:" 54 | 55 | @Override 56 | void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException { 57 | def sTime = System.currentTimeMillis() 58 | def inputs = transformInvocation.inputs 59 | def routeJarInput 60 | def outputProvider = transformInvocation.outputProvider 61 | outputProvider.deleteAll() 62 | for (TransformInput input : inputs) { 63 | for (DirectoryInput dirInput : input.directoryInputs) { 64 | readClassWithPath(dirInput.file) 65 | File dest = outputProvider.getContentLocation(dirInput.name, 66 | dirInput.contentTypes, 67 | dirInput.scopes, 68 | Format.DIRECTORY) 69 | FileUtils.copyDirectory(dirInput.file, dest) 70 | } 71 | for (JarInput jarInput : input.jarInputs) { 72 | if (jarInput.name.startsWith(ROUTE_NAME)) { 73 | routeJarInput = jarInput 74 | } 75 | if (jarInput.scopes.contains(QualifiedContent.Scope.SUB_PROJECTS)) {//module library 76 | //从module中获取注解信息 77 | readClassWithJar(jarInput) 78 | } 79 | copyFile(jarInput, outputProvider) 80 | } 81 | } 82 | def eTime = System.currentTimeMillis() 83 | println("route map:" + routeMap) 84 | insertCodeIntoJar(routeJarInput, transformInvocation.outputProvider) 85 | 86 | println("===========route transform finished:" + (eTime - sTime)) 87 | } 88 | 89 | 90 | void copyFile(JarInput jarInput, TransformOutputProvider outputProvider) { 91 | def dest = getDestFile(jarInput, outputProvider) 92 | FileUtils.copyFile(jarInput.file, dest) 93 | } 94 | 95 | static File getDestFile(JarInput jarInput, TransformOutputProvider outputProvider) { 96 | def destName = jarInput.name 97 | // 重名名输出文件,因为可能同名,会覆盖 98 | def hexName = DigestUtils.md5Hex(jarInput.file.absolutePath) 99 | if (destName.endsWith(".jar")) { 100 | destName = destName.substring(0, destName.length() - 4) 101 | } 102 | // 获得输出文件 103 | File dest = outputProvider.getContentLocation(destName + "_" + hexName, jarInput.contentTypes, jarInput.scopes, Format.JAR) 104 | return dest 105 | } 106 | 107 | /** 108 | * 插入代码 109 | * @param jarFile 110 | */ 111 | void insertCodeIntoJar(JarInput jarInput, TransformOutputProvider out) { 112 | File jarFile = jarInput.file 113 | def tmp = new File(jarFile.getParent(), jarFile.name + ".tmp") 114 | if (tmp.exists()) tmp.delete() 115 | def file = new JarFile(jarFile) 116 | def dest = getDestFile(jarInput, out) 117 | Enumeration enumeration = file.entries() 118 | JarOutputStream jos = new JarOutputStream(new FileOutputStream(tmp)) 119 | while (enumeration.hasMoreElements()) { 120 | JarEntry jarEntry = enumeration.nextElement() 121 | String entryName = jarEntry.name 122 | ZipEntry zipEntry = new ZipEntry(entryName) 123 | InputStream is = file.getInputStream(jarEntry) 124 | jos.putNextEntry(zipEntry) 125 | if (isRouteMapClass(entryName)) { 126 | jos.write(hackRouteMap(jarFile)) 127 | } else { 128 | jos.write(IOUtils.toByteArray(is)) 129 | } 130 | is.close() 131 | jos.closeEntry() 132 | } 133 | jos.close() 134 | file.close() 135 | FileUtils.copyFile(tmp, dest) 136 | } 137 | 138 | private static final String ROUTE_MAP_CLASS_NAME = "io.github.iamyours.router.RouteMap" 139 | private static 140 | final String ROUTE_MAP_CLASS_FILE_NAME = ROUTE_MAP_CLASS_NAME.replaceAll("\\.", "/") + ".class" 141 | 142 | private boolean isRouteMapClass(String entryName) { 143 | return ROUTE_MAP_CLASS_FILE_NAME == entryName 144 | } 145 | 146 | private byte[] hackRouteMap(File jarFile) { 147 | ClassPool pool = ClassPool.getDefault() 148 | pool.insertClassPath(jarFile.absolutePath) 149 | CtClass ctClass = pool.get(ROUTE_MAP_CLASS_NAME) 150 | CtMethod method = ctClass.getDeclaredMethod("loadInto") 151 | StringBuffer code = new StringBuffer("{") 152 | for (String key : routeMap.keySet()) { 153 | String value = routeMap[key] 154 | code.append("\$1.put(\"" + key + "\",\"" + value + "\");") 155 | } 156 | code.append("}") 157 | method.setBody(code.toString()) 158 | byte[] bytes = ctClass.toBytecode() 159 | ctClass.stopPruning(true) 160 | ctClass.defrost() 161 | return bytes 162 | } 163 | 164 | //从目录中读取class 165 | void readClassWithPath(File dir) { 166 | def root = dir.absolutePath 167 | dir.eachFileRecurse { File file -> 168 | def filePath = file.absolutePath 169 | if (!filePath.endsWith(".class")) return 170 | def className = getClassName(root, filePath) 171 | if (isSystemClass(className)) return 172 | addRouteMap(filePath, className) 173 | } 174 | } 175 | 176 | //从jar中读取class 177 | void readClassWithJar(JarInput jarInput) { 178 | JarFile jarFile = new JarFile(jarInput.file) 179 | Enumeration enumeration = jarFile.entries() 180 | while (enumeration.hasMoreElements()) { 181 | JarEntry entry = enumeration.nextElement() 182 | String entryName = entry.getName() 183 | if (!entryName.endsWith(".class")) continue 184 | String className = entryName.substring(0, entryName.length() - 6).replaceAll("/", ".") 185 | InputStream is = jarFile.getInputStream(entry) 186 | addRouteMap(is, className) 187 | } 188 | } 189 | static final ANNOTATION_DESC = "Lio/github/iamyours/router/annotation/Route;" 190 | /** 191 | * 从class中获取Route注解信息 192 | * @param filePath 193 | */ 194 | void addRouteMap(String filePath, String className) { 195 | addRouteMap(new FileInputStream(new File(filePath)), className) 196 | } 197 | 198 | void addRouteMap(InputStream is, String className) { 199 | ClassReader reader = new ClassReader(is) 200 | ClassNode node = new ClassNode() 201 | reader.accept(node, 1) 202 | def list = node.invisibleAnnotations 203 | for (AnnotationNode an : list) { 204 | if (ANNOTATION_DESC == an.desc) { 205 | def path = an.values[1] 206 | routeMap[path] = className 207 | break 208 | } 209 | } 210 | } 211 | 212 | //默认排除 213 | static final DEFAULT_EXCLUDE = [ 214 | '^android\\..*', 215 | '^androidx\\..*', 216 | '.*\\.R$', 217 | '.*\\.R\\$.*$', 218 | '.*\\.BuildConfig$', 219 | ] 220 | 221 | //获取类名 222 | String getClassName(String root, String classPath) { 223 | return classPath.substring(root.length() + 1, classPath.length() - 6) 224 | .replaceAll("/", ".") // unix/linux 225 | .replaceAll("\\\\", ".") //windows 226 | } 227 | 228 | boolean isSystemClass(String fileName) { 229 | for (def exclude : DEFAULT_EXCLUDE) { 230 | if (fileName.matches(exclude)) return true 231 | } 232 | return false 233 | } 234 | 235 | 236 | } -------------------------------------------------------------------------------- /buildsrc/src/main/resources/META-INF/gradle-plugins/RouterPlugin.properties: -------------------------------------------------------------------------------- 1 | implementation-class=io.github.iamyours.RouterPlugin -------------------------------------------------------------------------------- /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 | android.useAndroidX=true 15 | android.enableJetifier=true 16 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamyours/SimpleRouter/bdbb7367a47a7941f97f72425164ac7b582d6810/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Apr 23 09:59:46 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /news/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /news/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | android { 5 | compileSdkVersion 28 6 | 7 | 8 | 9 | defaultConfig { 10 | minSdkVersion 14 11 | targetSdkVersion 28 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 31 | implementation 'com.android.support:appcompat-v7:28.0.0' 32 | testImplementation 'junit:junit:4.12' 33 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 34 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 35 | // api project(':router-api') 36 | api 'io.github.iamyours:router-api:1.0.0' 37 | } 38 | -------------------------------------------------------------------------------- /news/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /news/src/androidTest/java/io/github/iamyours/news/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package io.github.iamyours.news; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("io.github.iamyours.news.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /news/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /news/src/main/java/io/github/iamyours/news/NewsListActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.iamyours.news 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import android.support.v7.app.AppCompatActivity 6 | import io.github.iamyours.router.annotation.Route 7 | import kotlinx.android.synthetic.main.activity_news_list.* 8 | 9 | @Route(path = "/news/news_list") 10 | class NewsListActivity : AppCompatActivity() { 11 | override fun onCreate(savedInstanceState: Bundle?) { 12 | super.onCreate(savedInstanceState) 13 | setContentView(R.layout.activity_news_list) 14 | val title = intent.getStringExtra("title") 15 | tv_test.text = title 16 | tv_test.setOnClickListener { 17 | val intent = Intent() 18 | intent.putExtra("name","张三") 19 | setResult(1000,intent) 20 | finish() 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /news/src/main/res/layout/activity_news_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | -------------------------------------------------------------------------------- /news/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | news 3 | 4 | -------------------------------------------------------------------------------- /news/src/test/java/io/github/iamyours/news/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package io.github.iamyours.news; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /router-api/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /router-api/binary.gradle: -------------------------------------------------------------------------------- 1 | //apply plugin: 'com.jfrog.bintray' 2 | //apply plugin: 'maven-publish' 3 | //apply plugin: 'java' 4 | //apply plugin: 'signing' 5 | //apply plugin: 'maven' 6 | // 7 | //group = "io.github.iamyours" 8 | //version = "1.0.1" 9 | //project.archivesBaseName = "router-api" 10 | // 11 | //task javadocJar(type: Jar, dependsOn: javadoc) { 12 | // classifier = 'javadoc' 13 | // from javadoc.destinationDir 14 | //} 15 | // 16 | //task sourceJar(type: Jar) { 17 | // classifier = 'sources' 18 | // from sourceSets.main.allSource 19 | //} 20 | // 21 | //ext { 22 | // pomFilePath = "${project.buildDir.absolutePath}/tmp/pom.xml" 23 | // pomFile = file(pomFilePath) 24 | //} 25 | // 26 | //configurations { 27 | // pom 28 | //} 29 | // 30 | //artifacts { 31 | // archives jar 32 | // archives sourceJar 33 | // archives javadocJar 34 | // if (pomFile.exists()) { 35 | // pom pomFile 36 | // } 37 | //} 38 | // 39 | //task signJars(type: Sign, dependsOn: [jar, javadocJar, sourceJar]) { 40 | // sign configurations.archives 41 | //} 42 | // 43 | //task signPom(type: Sign) { 44 | // sign configurations.pom 45 | //} 46 | // 47 | //if (project.ext.pomFile.exists()) { 48 | // task preparePublication(dependsOn: [signJars, signPom]) 49 | //} else { 50 | // task preparePublication(dependsOn: signJars) 51 | //} 52 | // 53 | //def getSignatureFiles = { 54 | // def allFiles = project.tasks.signJars.signatureFiles.collect{it} 55 | // def signedSources = allFiles.find{ it.name.contains('-sources') } 56 | // def signedJavadoc = allFiles.find{ it.name.contains('-javadoc') } 57 | // def signedJar = (allFiles - [signedSources, signJars])[0] 58 | // return [ 59 | // [archive: signedSources, classifier: 'sources', extension: 'jar.asc'], 60 | // [archive: signedJavadoc, classifier: 'javadoc', extension: 'jar.asc'], 61 | // [archive: signedJar, classifier: 'null', extension: 'jar.asc'] 62 | // ] 63 | //} 64 | // 65 | //def getPomSignature = { 66 | // return project.tasks.signPom.signatureFiles.collect{ it }[0] 67 | //} 68 | // 69 | //def siteUrl = 'https://github.com/iamyours/SimpleRouter' 70 | //def gitUrl = 'https://github.com/iamyours/SimpleRouter.git' 71 | //def issueUrl = 'https://github.com/iamyours/SimpleRouter/issues' 72 | // 73 | //install { 74 | // repositories.mavenInstaller { 75 | //// generates POM.xml with proper parameters 76 | // pom { 77 | // project { 78 | // packaging 'jar' 79 | // name 'The Android Plugin for Router' 80 | // url siteUrl 81 | // 82 | // licenses { 83 | // license { 84 | // name 'The Apache Software License, Version 2.0' 85 | // url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 86 | // } 87 | // } 88 | // developers { 89 | // developer { 90 | // id 'RogerYan' //填写的一些基本信息 91 | // name 'Roger' 92 | // email 'yan127422@163.com' 93 | // } 94 | // } 95 | // 96 | // scm { 97 | // connection gitUrl 98 | // developerConnection gitUrl 99 | // url siteUrl 100 | // } 101 | // } 102 | // } 103 | // } 104 | //} 105 | // 106 | // 107 | //bintray { 108 | // user = "iamyours" 109 | // key = "xxx" 110 | // configurations = ['archives'] 111 | // pkg { 112 | // repo = "maven" //bintray 上面 Package名字 113 | // name = "router-api" //bintray 上面项目名 114 | // desc = 'Router api for android' 115 | // websiteUrl = siteUrl 116 | // vcsUrl = gitUrl 117 | // issueTrackerUrl = issueUrl 118 | // licenses = ["Apache-2.0"] 119 | // labels = 'java' 120 | // publicDownloadNumbers = true 121 | // publish = true 122 | // } 123 | //} 124 | -------------------------------------------------------------------------------- /router-api/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java-library' 2 | dependencies { 3 | implementation fileTree(dir: 'libs', include: ['*.jar']) 4 | compileOnly 'com.google.android:android:4.1.1.4' 5 | } 6 | 7 | sourceCompatibility = "1.7" 8 | targetCompatibility = "1.7" 9 | 10 | apply from: 'binary.gradle' -------------------------------------------------------------------------------- /router-api/src/main/java/io/github/iamyours/router/ARouter.java: -------------------------------------------------------------------------------- 1 | package io.github.iamyours.router; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class ARouter { 7 | private static final ARouter instance = new ARouter(); 8 | private Map routeMap = new HashMap<>(); 9 | private boolean loaded; 10 | 11 | private ARouter() { 12 | } 13 | 14 | public static ARouter getInstance() { 15 | if (!instance.loaded) instance.init(); 16 | return instance; 17 | } 18 | 19 | public void init() { 20 | if (loaded) return; 21 | new RouteMap().loadInto(routeMap); 22 | loaded = true; 23 | } 24 | 25 | public Map getMap() { 26 | return routeMap; 27 | } 28 | 29 | public Postcard build(String path) { 30 | String component = routeMap.get(path); 31 | if (component == null) throw new RuntimeException("could not find route with " + path); 32 | return new Postcard(component); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /router-api/src/main/java/io/github/iamyours/router/Callback.java: -------------------------------------------------------------------------------- 1 | package io.github.iamyours.router; 2 | 3 | import android.content.Intent; 4 | 5 | /** 6 | * 回调 7 | */ 8 | public interface Callback { 9 | void onActivityResult(int requestCode, int resultCode, Intent data); 10 | } 11 | -------------------------------------------------------------------------------- /router-api/src/main/java/io/github/iamyours/router/CallbackFragment.java: -------------------------------------------------------------------------------- 1 | package io.github.iamyours.router; 2 | 3 | import android.app.Fragment; 4 | import android.content.Intent; 5 | 6 | public class CallbackFragment extends Fragment { 7 | private Callback callback; 8 | 9 | public CallbackFragment setCallback(Callback callback) { 10 | this.callback = callback; 11 | return this; 12 | } 13 | 14 | @Override 15 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 16 | super.onActivityResult(requestCode, resultCode, data); 17 | if (callback != null) { 18 | callback.onActivityResult(requestCode, resultCode, data); 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /router-api/src/main/java/io/github/iamyours/router/Postcard.java: -------------------------------------------------------------------------------- 1 | package io.github.iamyours.router; 2 | 3 | import android.app.Activity; 4 | import android.app.FragmentManager; 5 | import android.content.ComponentName; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.os.Bundle; 9 | import android.os.Parcelable; 10 | 11 | public class Postcard { 12 | private String activityName; 13 | private Bundle mBundle; 14 | 15 | public Postcard(String activityName) { 16 | this.activityName = activityName; 17 | mBundle = new Bundle(); 18 | } 19 | 20 | public Postcard withString(String key, String value) { 21 | mBundle.putString(key, value); 22 | return this; 23 | } 24 | 25 | public Postcard withInt(String key, int value) { 26 | mBundle.putInt(key, value); 27 | return this; 28 | } 29 | 30 | public Postcard withFloat(String key, float value) { 31 | mBundle.putFloat(key, value); 32 | return this; 33 | } 34 | 35 | public Postcard withLong(String key, long value) { 36 | mBundle.putLong(key, value); 37 | return this; 38 | } 39 | 40 | public Postcard withParcelable(String key, Parcelable value) { 41 | mBundle.putParcelable(key, value); 42 | return this; 43 | } 44 | 45 | public Postcard with(Bundle bundle) { 46 | if (null != bundle) { 47 | mBundle = bundle; 48 | } 49 | return this; 50 | } 51 | 52 | public void navigation(Context context) { 53 | Intent intent = new Intent(); 54 | intent.setComponent(new ComponentName(context.getPackageName(), activityName)); 55 | intent.putExtras(mBundle); 56 | context.startActivity(intent); 57 | } 58 | 59 | public void navigation(Activity context, int requestCode) { 60 | Intent intent = new Intent(); 61 | intent.setComponent(new ComponentName(context.getPackageName(), activityName)); 62 | intent.putExtras(mBundle); 63 | context.startActivityForResult(intent, requestCode); 64 | } 65 | 66 | public void navigation(Context context, int requestCode, Callback callback) { 67 | if (context instanceof Activity) { 68 | Activity activity = (Activity) context; 69 | Intent intent = new Intent(); 70 | intent.setComponent(new ComponentName(context.getPackageName(), activityName)); 71 | intent.putExtras(mBundle); 72 | getFragment(activity) 73 | .setCallback(callback) 74 | .startActivityForResult(intent, requestCode); 75 | } 76 | } 77 | 78 | public void navigation(Context context, Callback callback) { 79 | navigation(context, 10, callback); 80 | } 81 | 82 | private static final String TAG = "io.github.iamyours.router.Postcard"; 83 | 84 | private CallbackFragment getFragment(Activity activity) { 85 | CallbackFragment fragment = (CallbackFragment) activity.getFragmentManager().findFragmentByTag(TAG); 86 | if (fragment == null) { 87 | fragment = new CallbackFragment(); 88 | FragmentManager fm = activity.getFragmentManager(); 89 | fm.beginTransaction().add(fragment, TAG) 90 | .commitAllowingStateLoss(); 91 | fm.executePendingTransactions(); 92 | } 93 | return fragment; 94 | } 95 | 96 | 97 | } 98 | -------------------------------------------------------------------------------- /router-api/src/main/java/io/github/iamyours/router/RouteMap.java: -------------------------------------------------------------------------------- 1 | package io.github.iamyours.router; 2 | 3 | import java.util.Map; 4 | 5 | public class RouteMap { 6 | void loadInto(Map map){ 7 | throw new RuntimeException("加载Router映射错误!"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /router-api/src/main/java/io/github/iamyours/router/annotation/Route.java: -------------------------------------------------------------------------------- 1 | package io.github.iamyours.router.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 | @Target({ElementType.TYPE}) 9 | @Retention(RetentionPolicy.CLASS) 10 | public @interface Route { 11 | String path(); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':buildsrc', ':router-api', ':news' 2 | --------------------------------------------------------------------------------