Skip to content

Commit 4d166d8

Browse files
committed
支持arouter
1 parent 1196b4e commit 4d166d8

File tree

27 files changed

+310
-51
lines changed

27 files changed

+310
-51
lines changed

.idea/caches/build_file_checksums.ser

0 Bytes
Binary file not shown.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ android {
1010
versionName "1.0"
1111
javaCompileOptions {
1212
annotationProcessorOptions {
13-
arguments = [moduleName: project.getName()]
13+
arguments = [ AROUTER_MODULE_NAME : project.getName() ]
1414
}
1515
}
16+
17+
1618
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1719
}
1820
buildTypes {
@@ -31,6 +33,12 @@ dependencies {
3133
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
3234
api rootProject.ext.dependencies["appcompat-v7"]
3335
api rootProject.ext.dependencies["multidex"]
34-
implementation project(':module-home')
35-
implementation project(':module-push')
36+
api rootProject.ext.dependencies["arouter"]
37+
if (!isModule) {
38+
implementation project(':module-home')
39+
implementation project(':module-push')
40+
41+
}
42+
annotationProcessor rootProject.ext.dependencies["arouterCompile"]
43+
implementation project(':lib-core')
3644
}

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package="com.example.kson.moduledemo">
44

55
<application
6+
android:name=".MyApp"
67
android:allowBackup="true"
78
android:icon="@mipmap/ic_launcher"
89
android:label="@string/app_name"
@@ -17,8 +18,9 @@
1718
</intent-filter>
1819
</activity>
1920
<activity android:name="com.example.kson.module_home.Main2Activity"/>
20-
2121
<activity android:name="com.example.kson.module_push.PushActivity"/>
22+
<activity android:name=".Main2Activity">
23+
</activity>
2224
</application>
2325

2426
</manifest>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.example.kson.moduledemo;
2+
3+
import android.support.v7.app.AppCompatActivity;
4+
import android.os.Bundle;
5+
6+
import com.alibaba.android.arouter.facade.annotation.Route;
7+
8+
@Route(path = "/com/main2")
9+
public class Main2Activity extends AppCompatActivity {
10+
11+
@Override
12+
protected void onCreate(Bundle savedInstanceState) {
13+
super.onCreate(savedInstanceState);
14+
setContentView(R.layout.activity_main22);
15+
}
16+
}
Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.example.kson.moduledemo;
22

3-
import android.content.Intent;
4-
import android.support.v7.app.AppCompatActivity;
53
import android.os.Bundle;
4+
import android.support.v4.app.Fragment;
5+
import android.support.v7.app.AppCompatActivity;
66
import android.view.View;
7+
import android.widget.Button;
78

8-
import com.example.kson.module_home.Main2Activity;
9-
import com.example.kson.module_push.PushActivity;
10-
9+
import com.alibaba.android.arouter.facade.Postcard;
10+
import com.alibaba.android.arouter.facade.callback.NavCallback;
11+
import com.alibaba.android.arouter.launcher.ARouter;
12+
import com.example.kson.lib_core.constants.Apath;
1113

1214
public class MainActivity extends AppCompatActivity {
1315

@@ -16,13 +18,50 @@ protected void onCreate(Bundle savedInstanceState) {
1618
super.onCreate(savedInstanceState);
1719
setContentView(R.layout.activity_main);
1820

21+
Button button = findViewById(R.id.fromg);
22+
button.setOnClickListener(new View.OnClickListener() {
23+
@Override
24+
public void onClick(View view) {
25+
26+
ARouter.getInstance().build("/home/home2").navigation(MainActivity.this, new NavCallback() {
27+
@Override
28+
public void onArrival(Postcard postcard) {
29+
30+
}
31+
32+
@Override
33+
public void onInterrupt(Postcard postcard) {
34+
super.onInterrupt(postcard);
35+
}
36+
});
37+
38+
}
39+
});
40+
41+
// Fragment fragmentHome = (Fragment) ARouter.getInstance().build(Apath.HOME_MAIN).navigation();
42+
//
43+
//
44+
//
45+
// getSupportFragmentManager().beginTransaction()
46+
// .add(R.id.fr_content, fragmentHome)
47+
//// .add(R.id.fl_Content, marketFragment)
48+
//// .add(R.id.fl_Content, messageFragment)
49+
//// .add(R.id.fl_Content, mineFragment)
50+
//// .add(R.id.fl_Content, walletFragment)
51+
// .show(fragmentHome)
52+
//// .hide(marketFragment)
53+
//// .hide(messageFragment)
54+
//// .hide(mineFragment)
55+
//// .hide(walletFragment)
56+
// .commit();
57+
1958

2059
}
2160

2261
public void home(View view) {
2362

2463
//集成开发模式,可以调用
25-
startActivity(new Intent(this, PushActivity.class));
64+
// startActivity(new Intent(this, PushActivity.class));
2665

2766
}
2867
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.example.kson.moduledemo;
2+
3+
import android.app.Application;
4+
5+
import com.alibaba.android.arouter.launcher.ARouter;
6+
7+
/**
8+
* Author:kson
9+
10+
* Time:2018/10/30
11+
* Description:
12+
*/
13+
public class MyApp extends Application {
14+
15+
@Override
16+
public void onCreate() {
17+
super.onCreate();
18+
// 这两行必须写在init之前,否则这些配置在init过程中将无效
19+
ARouter.openLog(); // 打印日志
20+
ARouter.openDebug(); // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险) }
21+
ARouter.init(this);
22+
}
23+
}
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<android.support.constraint.ConstraintLayout
2+
<LinearLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:app="http://schemas.android.com/apk/res-auto"
55
xmlns:tools="http://schemas.android.com/tools"
66
android:layout_width="match_parent"
77
android:layout_height="match_parent"
8+
android:orientation="vertical"
89
tools:context=".MainActivity">
910

10-
<TextView
11-
android:onClick="home"
12-
android:layout_width="wrap_content"
13-
android:layout_height="wrap_content"
14-
android:text="Hello World!"
15-
app:layout_constraintBottom_toBottomOf="parent"
16-
app:layout_constraintLeft_toLeftOf="parent"
17-
app:layout_constraintRight_toRightOf="parent"
18-
app:layout_constraintTop_toTopOf="parent"/>
11+
<FrameLayout
12+
android:id="@+id/fr_content"
13+
android:layout_width="match_parent"
14+
android:layout_height="200dp"/>
1915

20-
</android.support.constraint.ConstraintLayout>
16+
<Button
17+
android:id="@+id/fromg"
18+
android:text="跳转"
19+
android:layout_width="match_parent"
20+
android:layout_height="wrap_content"/>
21+
22+
</LinearLayout>

module-home/src/main/res/layout/activity_main2.xml renamed to app/src/main/res/layout/activity_main2.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
tools:context=".Main2Activity">
99

1010
<TextView
11+
android:text="ninini"
1112
android:layout_width="wrap_content"
12-
android:layout_height="wrap_content"
13-
android:text="我是首页模块"/>
13+
android:layout_height="wrap_content"/>
1414

1515
</android.support.constraint.ConstraintLayout>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99
dependencies {
1010
classpath 'com.android.tools.build:gradle:3.1.4'
11-
11+
classpath "com.alibaba:arouter-register:1.0.2"
1212

1313
// NOTE: Do not place your application dependencies here; they belong
1414
// in the individual module build.gradle files

config.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ ext {
1010

1111
def dependVersion = [
1212
support : "27.1.1",
13-
multidex: "1.0.1"
13+
multidex: "1.0.1",
14+
arouterCompile : "1.2.2",
15+
arouter : "1.4.1",
1416
]
1517

1618
dependencies = [
1719
"appcompat-v7": "com.android.support:appcompat-v7:${dependVersion.support}",
1820
"multidex" : "com.android.support:multidex:${dependVersion.multidex}",
21+
"arouterCompile" : "com.alibaba:arouter-compiler:${dependVersion.arouterCompile}",
22+
"arouter" : "com.alibaba:arouter-api:${dependVersion.arouter}",
1923
]
2024
}

lib-core/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ android {
2626

2727
dependencies {
2828
implementation fileTree(dir: 'libs', include: ['*.jar'])
29-
29+
api rootProject.ext.dependencies["arouter"]
3030
api rootProject.ext.dependencies["appcompat-v7"]
31+
3132
testImplementation 'junit:junit:4.12'
3233
androidTestImplementation 'com.android.support.test:runner:1.0.2'
3334
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.example.kson.lib_core;
2+
3+
/**
4+
* Author:kson
5+
6+
* Time:2018/10/30
7+
* Description:
8+
*/
9+
public class GE {
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.example.kson.lib_core.constants;
2+
3+
/**
4+
* Author:kson
5+
6+
* Time:2018/10/30
7+
* Description:
8+
*/
9+
public class Apath {
10+
public static final String HOME_MAIN = "/home/main";
11+
public static final String PUSH_MAIN = "/push/main";
12+
}

module-home/build.gradle

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ android {
1414
targetSdkVersion 27
1515
versionCode 1
1616
versionName "1.0"
17+
javaCompileOptions {
18+
annotationProcessorOptions {
19+
arguments = [ AROUTER_MODULE_NAME : project.getName() ]
20+
}
21+
}
22+
23+
1724
//组件模式下
1825
if (isModule) {
1926
applicationId appId['module-home']
@@ -31,11 +38,7 @@ android {
3138
}
3239
}
3340
}
34-
javaCompileOptions {
35-
annotationProcessorOptions {
36-
arguments = [moduleName: project.getName()]
37-
}
38-
}
41+
3942
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
4043

4144
}
@@ -56,6 +59,8 @@ dependencies {
5659
testImplementation 'junit:junit:4.12'
5760
androidTestImplementation 'com.android.support.test:runner:1.0.2'
5861
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
59-
implementation project(':lib-core')
62+
api project(':lib-core')
6063
implementation project(':lib-net')
64+
annotationProcessor rootProject.ext.dependencies["arouterCompile"]
65+
api rootProject.ext.dependencies["arouter"]
6166
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.example.kson.module_home;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.NonNull;
5+
import android.support.annotation.Nullable;
6+
import android.support.v4.app.Fragment;
7+
import android.view.LayoutInflater;
8+
import android.view.View;
9+
import android.view.ViewGroup;
10+
11+
import com.alibaba.android.arouter.facade.annotation.Route;
12+
import com.example.kson.lib_core.constants.Apath;
13+
14+
/**
15+
* Author:kson
16+
17+
* Time:2018/10/30
18+
* Description:
19+
*/
20+
@Route(path = Apath.HOME_MAIN)
21+
public class HomeFragment extends Fragment{
22+
23+
@Nullable
24+
@Override
25+
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
26+
View view = View.inflate(getContext(), R.layout.frag_home, null);
27+
return view;
28+
}
29+
30+
}

module-home/src/main/java/com/example/kson/module_home/Main2Activity.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,24 @@
22

33
import android.support.v7.app.AppCompatActivity;
44
import android.os.Bundle;
5+
import android.view.View;
6+
import android.widget.TextView;
57

8+
import com.alibaba.android.arouter.facade.annotation.Route;
9+
import com.alibaba.android.arouter.launcher.ARouter;
10+
@Route(path = "/home/home2")
611
public class Main2Activity extends AppCompatActivity {
712

813
@Override
914
protected void onCreate(Bundle savedInstanceState) {
1015
super.onCreate(savedInstanceState);
11-
setContentView(R.layout.activity_main2);
16+
setContentView(R.layout.activity_main22);
17+
TextView push = findViewById(R.id.push1);
18+
push.setOnClickListener(new View.OnClickListener() {
19+
@Override
20+
public void onClick(View v) {
21+
ARouter.getInstance().build("/push/push").navigation();
22+
}
23+
});
1224
}
1325
}

module-home/src/main/module/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package="com.example.kson.module_home">
44

55
<application
6+
android:name=".MyApp"
67
android:allowBackup="true"
78
android:label="@string/app_name"
89
android:supportsRtl="true"

0 commit comments

Comments
 (0)