Skip to content

Commit

Permalink
Merge pull request #49 from chenenyu/dev
Browse files Browse the repository at this point in the history
1.2.5
  • Loading branch information
chenenyu committed Sep 8, 2017
2 parents 39b6a7b + f1f6d8e commit 3384923
Show file tree
Hide file tree
Showing 27 changed files with 369 additions and 206 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {
}
dependencies {
...
classpath 'com.chenenyu.router:gradle-plugin:1.2.4'
classpath 'com.chenenyu.router:gradle-plugin:最新版本'
}
}
Expand Down
11 changes: 6 additions & 5 deletions Sample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
android:name=".SchemeFilterActivity"
android:label="SchemeFilterActivity">
<intent-filter>
<data
android:host="test"
android:scheme="router" />

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="filter"
android:scheme="router" />
</intent-filter>
</activity>
<activity
Expand All @@ -49,6 +49,7 @@
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="implicit"
Expand All @@ -58,7 +59,7 @@
<activity
android:name=".InterceptedActivity"
android:label="InterceptedActivity" />
<activity android:name=".WebActivity"></activity>
<activity android:name=".WebActivity" />
</application>

</manifest>
11 changes: 10 additions & 1 deletion Sample/app/src/main/assets/scheme.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@
<div>This's a WebView.</div>
<ul>
<li>
<a href="router://test?id=123&status=browser">router://test?id=123&status=browser</a>
<a href="router://filter/test?id=123&status=browser">router://filter/test?id=123&status=browser</a>
</li>
<li>
<a href="router://filter/module1">router://filter/module1</a>
</li>
<li>
<a href="router://implicit">router://implicit</a>
</li>
<li>
<a href="router://empty">router://empty</a>
</li>
</ul>
</body>
Expand Down
10 changes: 6 additions & 4 deletions Sample/app/src/main/java/com/chenenyu/router/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public class App extends Application {
public void onCreate() {
super.onCreate();
// debug模式,显示log
// if (BuildConfig.DEBUG) {
// Router.setDebuggable(true);
// }
Router.initialize(this, true);
if (BuildConfig.DEBUG) {
Router.setDebuggable(true);
}
// The next comment line show how to process aar module.
// AptHub.registerModules("your-aar-module-name");
Router.initialize(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private String uri;
private Button btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9;
private Button btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn10, btn11;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -38,6 +38,8 @@ protected void onCreate(Bundle savedInstanceState) {
btn7 = (Button) findViewById(R.id.btn7);
btn8 = (Button) findViewById(R.id.btn8);
btn9 = (Button) findViewById(R.id.btn9);
btn10 = (Button) findViewById(R.id.btn10);
btn11 = (Button) findViewById(R.id.btn11);

editRoute.addTextChangedListener(new TextWatcher() {
@Override
Expand Down Expand Up @@ -112,6 +114,10 @@ public void callback(RouteResult state, Uri uri, String message) {
Router.build("module2").go(this);
} else if (v == btn9) {
Router.build("intercepted").go(this);
} else if (v == btn10) {
Router.build("intercepted").skipInterceptors("SampleInterceptor").go(this);
} else if (v == btn11) {
Router.build("test").addInterceptors("SampleInterceptor").go(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
public class SampleInterceptor implements RouteInterceptor {
@Override
public boolean intercept(Context context, RouteRequest routeRequest) {
Toast.makeText(context, "Intercepted by SampleInterceptor.", Toast.LENGTH_SHORT).show();
Toast.makeText(context, String.format("Intercepted: {uri: %s, interceptor: %s}",
routeRequest.getUri().toString(), SampleInterceptor.class.getName()),
Toast.LENGTH_LONG).show();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;

import com.chenenyu.router.Router;

Expand All @@ -17,7 +18,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Uri uri = getIntent().getData();
Router.build(uri).go(this);
finish();
if (uri != null) {
Log.d("SchemeFilterActivity", "uri: " + uri.toString());
if (!"router://filter".equals(uri.toString())) {
Router.build(uri).go(this);
}
finish();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
import com.chenenyu.router.annotation.InjectParam;
import com.chenenyu.router.annotation.Route;

@Route({"test", "http://example.com/user", "router://test"})
@Route({"test", "http://example.com/user", "router://filter/test"})
public class TestActivity extends AppCompatActivity {
@InjectParam
String id = "0000";
@InjectParam(key = "status")
private String sts = "default";
String sts = "default";

@InjectParam
private short test1;
short test1;
@InjectParam
byte[] test2;
@InjectParam
Model test3;
@InjectParam
private Model test4;
Model test4;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@
import android.webkit.WebView;

public class WebActivity extends AppCompatActivity {
WebView webView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

WebView webView = new WebView(this);
webView = new WebView(this);
setContentView(webView);
webView.loadUrl("file:///android_asset/scheme.html");
}

@Override
protected void onDestroy() {
super.onDestroy();
webView.destroy();
}
}
7 changes: 5 additions & 2 deletions Sample/app/src/main/res/layout/activity_intercepted.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.chenenyu.router.app.InterceptedActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是一个通过注解添加了拦截器的Activity" />
</FrameLayout>
14 changes: 14 additions & 0 deletions Sample/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@
android:onClick="onClick"
android:text="测试自定义拦截器" />

<Button
android:id="@+id/btn10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="临时移除拦截器" />

<Button
android:id="@+id/btn11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="临时添加拦截器" />

</LinearLayout>

</ScrollView>
15 changes: 10 additions & 5 deletions Sample/kotlin-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ android {

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

javaCompileOptions {
annotationProcessorOptions {
arguments = [ "moduleName" : project.name ]
}
}
// no need any more since 1.2.4
// javaCompileOptions {
// annotationProcessorOptions {
// arguments = [ "moduleName" : project.name ]
// }
// }
}

buildTypes {
Expand All @@ -30,6 +31,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}

//kapt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.chenenyu.router.annotation.Route;
import com.chenenyu.router.module1.R;

@Route("module1")
@Route({"module1", "router://filter/module1"})
public class Module1Activity extends AppCompatActivity {

@Override
Expand Down
6 changes: 3 additions & 3 deletions VERSION.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# router gradle plugin version
GRADLE_PLUGIN_VERSION=1.2.4
GRADLE_PLUGIN_VERSION=1.2.5
# router library version
ROUTER_VERSION=1.2.4
ROUTER_VERSION=1.2.5
# compiler library version
COMPILER_VERSION=1.2.4
COMPILER_VERSION=1.2.5
# annotation library version
ANNOTATION_VERSION=0.3.0
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.0.0-beta4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
Expand All @@ -29,7 +29,7 @@ ext {
targetCompatibility = JavaVersion.VERSION_1_7

compileSdkVersion = 25
buildToolsVersion = "26.0.0"
buildToolsVersion = "26.0.1"
minSdkVersion = 14
targetSdkVersion = 26

Expand Down
50 changes: 28 additions & 22 deletions buildSrc/src/main/groovy/com/chenenyu/router/RouterPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RouterPlugin implements Plugin<Project> {
// Add dependencies
Project router = project.rootProject.findProject("router")
Project routerCompiler = project.rootProject.findProject("compiler")
if (router && routerCompiler) {
if (router && routerCompiler) { // local
project.dependencies {
compile router
if (isKotlinProject) {
Expand All @@ -47,9 +47,9 @@ class RouterPlugin implements Plugin<Project> {
annotationProcessor routerCompiler
}
}
} else {
String routerVersion = "1.2.4"
String compilerVersion = "1.2.4"
} else { // remote
String routerVersion = "1.2.5"
String compilerVersion = "1.2.5"
// org.gradle.api.internal.plugins.DefaultExtraPropertiesExtension
ExtraPropertiesExtension ext = project.rootProject.ext
if (ext.has("routerVersion")) {
Expand Down Expand Up @@ -80,6 +80,7 @@ class RouterPlugin implements Plugin<Project> {
}

if (project.plugins.hasPlugin(APP)) {

// Read template in advance, it can't be read in GenerateBuildInfoTask.
InputStream is = RouterPlugin.class.getResourceAsStream("/RouterBuildInfo.template")
String template
Expand All @@ -89,30 +90,35 @@ class RouterPlugin implements Plugin<Project> {
File routerFolder = new File(project.buildDir,
"generated" + File.separator + "source" + File.separator + "router")

// Record lib modules' name
StringBuilder sb = new StringBuilder()
Set<Project> subs = project.rootProject.subprojects
subs.each {
if (it.plugins.hasPlugin(LIBRARY) && it.plugins.hasPlugin(RouterPlugin)) {
sb.append(it.name.replace('.', '_').replace('-', '_')).append(",")
project.gradle.projectsEvaluated {
// Record router modules' name, include library and app modules.
StringBuilder sb = new StringBuilder()
Set<Project> subs = project.rootProject.subprojects
subs.findAll {
it.plugins.hasPlugin(LIBRARY) && it.plugins.hasPlugin(RouterPlugin)
}.each {
sb.append(validateName(it.name)).append(",") // library
}
}
String validAppName = project.name.replace('.', '_').replace('-', '_')
sb.append(validAppName)
sb.append(validateName(project.name)) // app

project.android.applicationVariants.all { variant ->
// Create task
Task generateTask = project.tasks.create("generate${variant.name.capitalize()}BuildInfo", GenerateBuildInfoTask) {
it.routerFolder = routerFolder
it.buildInfoContent = template.replaceAll("%ALL_MODULES%", sb.toString())
project.android.applicationVariants.all { variant ->
// Create task
Task generateTask = project.tasks.create(
"generate${variant.name.capitalize()}BuildInfo", GenerateBuildInfoTask) {
it.routerFolder = routerFolder
it.buildInfoContent = template.replaceAll("%ALL_MODULES%", sb.toString())
}
// Add generated file to javac source
variant.javaCompile.source(routerFolder)
variant.javaCompile.dependsOn generateTask
}

// Add generated file to javac source
variant.javaCompile.source(routerFolder)
variant.javaCompile.dependsOn generateTask
}
}
}
}

static String validateName(String moduleName) {
moduleName.replace('.', '_').replace('-', '_')
}

}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Jun 12 14:37:31 CST 2017
#Mon Sep 04 12:31:05 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-milestone-1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

0 comments on commit 3384923

Please sign in to comment.