Skip to content

Commit

Permalink
update kotlin demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhi1ong committed Jul 12, 2017
1 parent d02b9cd commit aa57975
Show file tree
Hide file tree
Showing 25 changed files with 153 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
9. 页面、拦截器、服务等组件均自动注册到框架
10. 支持多种方式配置转场动画
11. 支持获取Fragment
12. 完全支持Kotlin(配置见文末 其他#5)
12. 完全支持Kotlin以及混编(配置见文末 其他#5)

#### 二、典型应用
1. 从外部URL映射到内部页面,以及参数传递与解析
Expand Down Expand Up @@ -454,6 +454,7 @@ dependencies {

5. Kotlin项目中的配置方式
```
// 可以参考 module-kotlin 模块中的写法
apply plugin: 'kotlin-kapt'
kapt {
Expand Down
3 changes: 2 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
9. 页面、拦截器、服务等组件均自动注册到框架
10. 支持多种方式配置转场动画
11. 支持获取Fragment
12. 完全支持Kotlin(配置见文末 其他#5)
12. 完全支持Kotlin以及混编(配置见文末 其他#5)

#### 二、典型应用
1. 从外部URL映射到内部页面,以及参数传递与解析
Expand Down Expand Up @@ -454,6 +454,7 @@ dependencies {

5. Kotlin项目中的配置方式
```
// 可以参考 module-kotlin 模块中的写法
apply plugin: 'kotlin-kapt'
kapt {
Expand Down
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ dependencies {

annotationProcessor project(':arouter-compiler')
compile project(':arouter-api')
compile project(':test-module-1')
compile project(':module-java')
compile project(':module-kotlin')
compile project(':arouter-annotation')

compile 'com.alibaba:fastjson:1.2.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ public void onClick(View v) {
.build("/test/activity2")
.navigation();
break;
case R.id.kotlinNavigation:
ARouter.getInstance()
.build("/test/kotlin")
.withString("name", "老王")
.withInt("age", 23)
.navigation();
break;
case R.id.normalNavigationWithParams:
// ARouter.getInstance()
// .build("/test/activity2")
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@
android:onClick="onClick"
android:text="简单的应用内跳转" />

<Button
android:id="@+id/kotlinNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="跳转到Kotlin页面" />

<Button
android:id="@+id/normalNavigation2"
android:layout_width="match_parent"
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
jcenter()
}
Expand All @@ -8,6 +9,7 @@ buildscript {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions module-kotlin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

kapt {
arguments {
arg("moduleName", project.getName())
}
}

dependencies {
compile project(':arouter-api')
compile "com.android.support:appcompat-v7:${SUPPORT_LIB_VERSION}"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
kapt 'com.alibaba:arouter-compiler:1.0.3'
}
android {
compileSdkVersion Integer.parseInt(COMPILE_SDK_VERSION)
buildToolsVersion BUILDTOOLS_VERSION

defaultConfig {
minSdkVersion Integer.parseInt(MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(TARGET_SDK_VERSION)
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

buildTypes {
release {
debuggable false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

lintOptions { abortOnError false }
}
}
15 changes: 15 additions & 0 deletions module-kotlin/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alibaba.android.arouter.demo.kotlin">

<!-- 读写存储的权限 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application>
<activity android:name=".KotlinTestActivity"/>
<activity android:name=".TestNormalActivity">
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.alibaba.android.arouter.demo.kotlin

import android.app.Activity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import kotlinx.android.synthetic.main.activity_kotlin_test.*

@Route(path = "/test/kotlin")
class KotlinTestActivity : Activity() {

@Autowired
@JvmField var name: String? = null
@Autowired
@JvmField var age: Int? = 0

override fun onCreate(savedInstanceState: Bundle?) {
ARouter.getInstance().inject(this) // Start auto inject.

super.onCreate(savedInstanceState)
setContentView(R.layout.activity_kotlin_test)

content.text = "name = $name, age = $age"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.alibaba.android.arouter.demo.kotlin;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.alibaba.android.arouter.facade.annotation.Route;

@Route(path = "/test/normal/activity")
public class TestNormalActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_normal);
}
}
14 changes: 14 additions & 0 deletions module-kotlin/src/main/res/layout/activity_kotlin_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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=".KotlinTestActivity">

<TextView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Im kotlin activity."/>
</LinearLayout>
10 changes: 10 additions & 0 deletions module-kotlin/src/main/res/layout/activity_test_normal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.alibaba.android.arouter.demo.kotlin.TestNormalActivity">

</android.support.constraint.ConstraintLayout>
5 changes: 5 additions & 0 deletions module-kotlin/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
1 change: 1 addition & 0 deletions module-kotlin/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<resources></resources>
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ include ':app'
include ':arouter-api'
include ':arouter-compiler'
include ':arouter-annotation'
include ':test-module-1'
include ':module-java'
include ':module-kotlin'
6 changes: 0 additions & 6 deletions test-module-1/src/main/res/values-w820dp/dimens.xml

This file was deleted.

0 comments on commit aa57975

Please sign in to comment.