Skip to content

Commit 432369a

Browse files
committed
完成搭建组件化框架
1 parent 0584063 commit 432369a

27 files changed

Lines changed: 1814 additions & 31 deletions

Girls/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
println isModule.toBoolean()
21
if (isModule.toBoolean()) {
32
apply plugin: 'com.android.application'
43
} else {
@@ -28,9 +27,9 @@ android {
2827
sourceSets {
2928
main {
3029
if (isModule.toBoolean()) {
31-
Manifest.srcFile 'src/main/debug/AndroidManifest.xml'
30+
manifest.srcFile 'src/main/debug/AndroidManifest.xml'
3231
} else {
33-
Manifest.srcFile 'src/main/release/AndroidManifest.xml'
32+
manifest.srcFile 'src/main/release/AndroidManifest.xml'
3433
//release模式下排除debug文件夹中的所有Java文件
3534
java {
3635
exclude 'debug/**'

News/build.gradle

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,50 @@
1-
apply plugin: 'com.android.application'
1+
if (isModule.toBoolean()) {
2+
apply plugin: 'com.android.application'
3+
} else {
4+
apply plugin: 'com.android.library'
5+
}
6+
7+
apply plugin: 'com.neenbedankt.android-apt'
28

39
android {
4-
compileSdkVersion 25
5-
buildToolsVersion "25.0.2"
10+
compileSdkVersion rootProject.ext.compileSdkVersion
11+
buildToolsVersion rootProject.ext.buildToolsVersion
612

713
defaultConfig {
8-
applicationId "com.guiying.news"
9-
minSdkVersion 15
10-
targetSdkVersion 25
11-
versionCode 1
12-
versionName "1.0"
13-
14+
minSdkVersion rootProject.ext.minSdkVersion
15+
targetSdkVersion rootProject.ext.targetSdkVersion
16+
versionCode rootProject.ext.versionCode
17+
versionName rootProject.ext.versionName
1418
}
19+
1520
buildTypes {
1621
release {
1722
minifyEnabled false
1823
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1924
}
2025
}
26+
27+
sourceSets {
28+
main {
29+
if (isModule.toBoolean()) {
30+
manifest.srcFile 'src/main/debug/AndroidManifest.xml'
31+
} else {
32+
manifest.srcFile 'src/main/release/AndroidManifest.xml'
33+
//release模式下排除debug文件夹中的所有Java文件
34+
java {
35+
exclude 'debug/**'
36+
}
37+
}
38+
}
39+
}
40+
//设置了resourcePrefix值后,所有的资源名必须以指定的字符串做前缀,否则会报错。
41+
//但是resourcePrefix这个值只能限定xml里面的资源,并不能限定图片资源,所有图片资源仍然需要手动去修改资源名。
42+
//resourcePrefix "girls_"
2143
}
2244

2345
dependencies {
2446
compile fileTree(dir: 'libs', include: ['*.jar'])
25-
compile 'com.android.support:appcompat-v7:25.1.0'
47+
compile project(':common')
48+
//router
49+
apt "com.github.mzule.activityrouter:compiler:$rootProject.aptCompilerVersion"
2650
}

app/build.gradle

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,63 @@
11
apply plugin: 'com.android.application'
2+
apply plugin: 'com.neenbedankt.android-apt'
3+
4+
def buildTime() {
5+
return new Date().format("yyyyMMdd");
6+
}
27

38
android {
4-
compileSdkVersion 25
5-
buildToolsVersion "25.0.2"
9+
compileSdkVersion rootProject.ext.compileSdkVersion
10+
buildToolsVersion rootProject.ext.buildToolsVersion
611
defaultConfig {
712
applicationId "com.guiying.androidmodulepattern"
8-
minSdkVersion 15
9-
targetSdkVersion 25
10-
versionCode 1
11-
versionName "1.0"
13+
minSdkVersion rootProject.ext.minSdkVersion
14+
targetSdkVersion rootProject.ext.targetSdkVersion
15+
versionCode rootProject.ext.versionCode
16+
versionName rootProject.ext.versionName
17+
//multiDexEnabled true
18+
//打包时间
19+
resValue "string", "build_time", buildTime()
1220
}
21+
1322
buildTypes {
1423
release {
15-
minifyEnabled false
24+
//更改AndroidManifest.xml中预先定义好占位符信息
25+
//manifestPlaceholders = [app_icon: "@drawable/icon"]
26+
// 不显示Log
27+
buildConfigField "boolean", "LEO_DEBUG", "false"
28+
//是否zip对齐
29+
zipAlignEnabled true
30+
// 缩减resource文件
31+
shrinkResources true
32+
//Proguard
33+
minifyEnabled true
1634
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
35+
//签名
36+
//signingConfig signingConfigs.release
37+
}
38+
39+
debug {
40+
//给applicationId添加后缀“.debug”
41+
applicationIdSuffix ".debug"
42+
//manifestPlaceholders = [app_icon: "@drawable/launch_beta"]
43+
buildConfigField "boolean", "LOG_DEBUG", "true"
44+
zipAlignEnabled false
45+
shrinkResources false
46+
minifyEnabled false
47+
debuggable true
1748
}
1849
}
1950
}
2051

2152
dependencies {
2253
compile fileTree(dir: 'libs', include: ['*.jar'])
23-
compile 'com.android.support:appcompat-v7:25.1.0'
54+
55+
if (!isModule.toBoolean()) {
56+
compile project(':girls')
57+
compile project(':news')
58+
} else {
59+
compile project(':common')
60+
}
61+
//router
62+
apt "com.github.mzule.activityrouter:compiler:$rootProject.aptCompilerVersion"
2463
}

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ext {
5252

5353
//不成熟开源库,需经常检查升级版本
5454
aptCompilerVersion = "1.1.7"
55-
routerVersion = "1.2.1"
56-
easyRecyclerVersion = "4.3.4"
57-
cookieVersion = "v1.0.0"
55+
routerVersion = "1.2.2"
56+
easyRecyclerVersion = "4.3.8"
57+
cookieVersion = "v1.0.1"
5858
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.guiying.common.base;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.support.annotation.IdRes;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.view.View;
8+
9+
/**
10+
* <p>Activity基类 </p>
11+
*
12+
* @author 2016/12/2 17:33
13+
* @version V1.0.0
14+
* @name BaseActivity
15+
*/
16+
public abstract class BaseActivity extends AppCompatActivity {
17+
18+
/**
19+
* 处理Intent,防止开发人员没做Intent判空
20+
*/
21+
protected void handleIntent(Intent intent) {
22+
}
23+
24+
/**
25+
* 封装的findViewByID方法
26+
*/
27+
@SuppressWarnings("unchecked")
28+
protected <T extends View> T $(@IdRes int id) {
29+
return (T) super.findViewById(id);
30+
}
31+
32+
@Override
33+
protected void onCreate(Bundle savedInstanceState) {
34+
super.onCreate(savedInstanceState);
35+
BaseApplication.getIns().addActivity(this);
36+
//强制在基类Intent判空
37+
if (null != getIntent()) {
38+
handleIntent(getIntent());
39+
}
40+
}
41+
42+
@Override
43+
protected void onDestroy() {
44+
super.onDestroy();
45+
BaseApplication.getIns().finishActivity(this);
46+
}
47+
48+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
package com.guiying.common.base;
2+
3+
import android.app.Activity;
4+
import android.app.Application;
5+
import android.content.Context;
6+
import android.content.pm.ApplicationInfo;
7+
import android.content.pm.PackageManager;
8+
import android.util.Log;
9+
10+
import com.common.util.StringUtils;
11+
import com.orhanobut.logger.LogLevel;
12+
import com.orhanobut.logger.Logger;
13+
14+
import java.util.Stack;
15+
16+
/**
17+
* 要想使用BaseApplication,必须在组件中实现自己的Application,并且继承BaseApplication;
18+
* 组件中实现的Application必须在AndroidManifest.xml中注册,否则无法使用;
19+
* 组件的Application需置于java/debug文件夹中,不得放于主代码;
20+
* 组件中获取Context的方法必须为:BaseApplication.context,不允许其他写法;
21+
* BaseApplication主要有如下功能:
22+
* 1、全局获取Context;
23+
* 2、用来管理全局Activity;
24+
*
25+
* @author 2016/12/2 17:02
26+
* @version V1.0.0
27+
* @name BaseApplication
28+
*/
29+
public class BaseApplication extends Application {
30+
31+
private static BaseApplication sInstance;
32+
33+
public static Context context;
34+
35+
private static Stack<Activity> activityStack;
36+
37+
public static BaseApplication getIns() {
38+
return sInstance;
39+
}
40+
41+
@Override
42+
public void onCreate() {
43+
super.onCreate();
44+
sInstance = this;
45+
context = this.getApplicationContext();
46+
if (isAppDebug(context)) {
47+
//只有debug模式才会打印日志
48+
Logger.init("Petrel").logLevel(LogLevel.FULL);
49+
} else {
50+
Logger.init("Petrel").logLevel(LogLevel.NONE);
51+
}
52+
}
53+
54+
/**
55+
* 添加指定Activity到堆栈
56+
*/
57+
public void addActivity(Activity activity) {
58+
if (activityStack == null) {
59+
activityStack = new Stack<>();
60+
}
61+
activityStack.add(activity);
62+
}
63+
64+
/**
65+
* 获取当前Activity
66+
*/
67+
public Activity currentActivity() {
68+
return activityStack.lastElement();
69+
}
70+
71+
/**
72+
* 结束当前Activity
73+
*/
74+
public void finishActivity() {
75+
Activity activity = activityStack.lastElement();
76+
finishActivity(activity);
77+
}
78+
79+
/**
80+
* 结束指定的Activity
81+
*/
82+
public void finishActivity(Activity activity) {
83+
if (activity != null) {
84+
activityStack.remove(activity);
85+
activity.finish();
86+
activity = null;
87+
}
88+
}
89+
90+
/**
91+
* 结束指定Class的Activity
92+
*/
93+
public void finishActivity(Class<?> cls) {
94+
for (Activity activity : activityStack) {
95+
if (activity.getClass().equals(cls)) {
96+
finishActivity(activity);
97+
return;
98+
}
99+
}
100+
}
101+
102+
/**
103+
* 结束全部的Activity
104+
*/
105+
public void finishAllActivity() {
106+
for (int i = 0, size = activityStack.size(); i < size; i++) {
107+
if (null != activityStack.get(i)) {
108+
activityStack.get(i).finish();
109+
}
110+
}
111+
activityStack.clear();
112+
}
113+
114+
/**
115+
* 退出应用程序
116+
*/
117+
public void exitApp(Context context) {
118+
try {
119+
finishAllActivity();
120+
android.app.ActivityManager activityMgr = (android.app.ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
121+
activityMgr.restartPackage(context.getPackageName());
122+
System.exit(0);
123+
} catch (Exception e) {
124+
Log.e("ActivityManager", "app exit" + e.getMessage());
125+
}
126+
}
127+
128+
/**
129+
* 判断App是否是Debug版本
130+
*
131+
* @param context 上下文
132+
* @return {@code true}: 是<br>{@code false}: 否
133+
*/
134+
public static boolean isAppDebug(Context context) {
135+
if (StringUtils.isSpace(context.getPackageName())) return false;
136+
try {
137+
PackageManager pm = context.getPackageManager();
138+
ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 0);
139+
return ai != null && (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
140+
} catch (PackageManager.NameNotFoundException e) {
141+
e.printStackTrace();
142+
return false;
143+
}
144+
}
145+
146+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* @ProjectName: ISMS_Petrel_MCU
3+
* @Copyright: 2016 HangZhou Hikvision System Technology Co., Ltd. All Right Reserved.
4+
* @address: http://www.hikvision.com
5+
* @Description: 本内容仅限于杭州海康威视系统技术公有限司内部使用,禁止转发.
6+
*/
7+
8+
package com.guiying.common.base;
9+
10+
public interface BasePresenter {
11+
12+
void start();
13+
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* @ProjectName: ISMS_Petrel_MCU
3+
* @Copyright: 2016 HangZhou Hikvision System Technology Co., Ltd. All Right Reserved.
4+
* @address: http://www.hikvision.com
5+
* @Description: 本内容仅限于杭州海康威视系统技术公有限司内部使用,禁止转发.
6+
*/
7+
8+
package com.guiying.common.base;
9+
10+
public interface BaseView<T> {
11+
12+
void setPresenter(T presenter);
13+
14+
}

0 commit comments

Comments
 (0)