From f4010dbc133feff3dd85cc172c49a81afda5f10a Mon Sep 17 00:00:00 2001 From: guiying712 Date: Mon, 20 Mar 2017 13:39:22 +0800 Subject: [PATCH 01/76] =?UTF-8?q?1=EF=BC=9A=E6=B6=88=E9=99=A4=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E8=AD=A6=E5=91=8A=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/src/main/AndroidManifest.xml | 2 +- .../main/java/com/guiying/common/base/BaseApplication.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/common/src/main/AndroidManifest.xml b/common/src/main/AndroidManifest.xml index 19d2195..e144c94 100644 --- a/common/src/main/AndroidManifest.xml +++ b/common/src/main/AndroidManifest.xml @@ -24,7 +24,7 @@ - + diff --git a/common/src/main/java/com/guiying/common/base/BaseApplication.java b/common/src/main/java/com/guiying/common/base/BaseApplication.java index 3bfefbb..3ce3746 100644 --- a/common/src/main/java/com/guiying/common/base/BaseApplication.java +++ b/common/src/main/java/com/guiying/common/base/BaseApplication.java @@ -1,6 +1,7 @@ package com.guiying.common.base; import android.app.Activity; +import android.app.ActivityManager; import android.app.Application; import android.content.Context; import android.util.Log; @@ -111,8 +112,9 @@ public void finishAllActivity() { public void exitApp(Context context) { try { finishAllActivity(); - android.app.ActivityManager activityMgr = (android.app.ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); - activityMgr.restartPackage(context.getPackageName()); + //杀死后台进程需要在AndroidManifest中声明android.permission.KILL_BACKGROUND_PROCESSES; + ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + activityManager.killBackgroundProcesses(context.getPackageName()); System.exit(0); } catch (Exception e) { Log.e("ActivityManager", "app exit" + e.getMessage()); From 81dbbe5af27ca79b677e20ff5af3edf120257f5b Mon Sep 17 00:00:00 2001 From: guiying712 Date: Sat, 1 Apr 2017 12:48:15 +0800 Subject: [PATCH 02/76] =?UTF-8?q?1=EF=BC=9A=E4=BF=AE=E6=94=B9=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=8C=96=E6=9E=B6=E6=9E=84=EF=BC=8C=E5=B0=86APP?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=94=B9=E6=88=90=E4=B8=80=E4=B8=AA=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E7=95=8C=E9=9D=A2=E7=9A=84=E5=A3=B3=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E5=8F=96=E4=BA=86=E4=B8=80=E4=B8=AA=E6=96=B0?= =?UTF-8?q?=E7=BB=84=E4=BB=B6main=EF=BC=8C=E8=B4=9F=E8=B4=A3=E5=90=AF?= =?UTF-8?q?=E5=8A=A8APP=E5=92=8C=E4=B8=BB=E7=95=8C=E9=9D=A2=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 9 +--- .../{AppModule.java => App.java} | 4 +- .../androidmodulepattern/MyApplication.java | 35 +------------ app/src/main/res/values/colors.xml | 4 -- app/src/main/res/values/strings.xml | 2 - build.gradle | 2 +- .../guiying/common/base/BaseApplication.java | 2 +- main/.gitignore | 1 + main/build.gradle | 50 +++++++++++++++++++ main/proguard-rules.pro | 25 ++++++++++ main/src/main/debug/AndroidManifest.xml | 21 ++++++++ main/src/main/java/com/guiying/main/Main.java | 17 +++++++ .../java/com/guiying/main}/MainActivity.java | 2 +- main/src/main/java/debug/MainApplication.java | 50 +++++++++++++++++++ main/src/main/release/AndroidManifest.xml | 14 ++++++ .../src/main/res/layout/activity_main.xml | 2 +- {app => main}/src/main/res/values/dimens.xml | 7 ++- main/src/main/res/values/strings.xml | 6 +++ settings.gradle | 1 + 20 files changed, 201 insertions(+), 54 deletions(-) rename app/src/main/java/com/guiying/androidmodulepattern/{AppModule.java => App.java} (68%) delete mode 100644 app/src/main/res/values/colors.xml create mode 100644 main/.gitignore create mode 100644 main/build.gradle create mode 100644 main/proguard-rules.pro create mode 100644 main/src/main/debug/AndroidManifest.xml create mode 100644 main/src/main/java/com/guiying/main/Main.java rename {app/src/main/java/com/guiying/androidmodulepattern => main/src/main/java/com/guiying/main}/MainActivity.java (97%) create mode 100644 main/src/main/java/debug/MainApplication.java create mode 100644 main/src/main/release/AndroidManifest.xml rename {app => main}/src/main/res/layout/activity_main.xml (93%) rename {app => main}/src/main/res/values/dimens.xml (59%) create mode 100644 main/src/main/res/values/strings.xml diff --git a/app/build.gradle b/app/build.gradle index cbe047f..eb8760c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -53,6 +53,7 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) if (!isModule.toBoolean()) { + compile project(':main') compile project(':girls') compile project(':news') } else { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e90ddfb..0daa87f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,6 +9,8 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> + + @@ -22,13 +24,6 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/guiying/androidmodulepattern/AppModule.java b/app/src/main/java/com/guiying/androidmodulepattern/App.java similarity index 68% rename from app/src/main/java/com/guiying/androidmodulepattern/AppModule.java rename to app/src/main/java/com/guiying/androidmodulepattern/App.java index 08257b5..c1858cf 100644 --- a/app/src/main/java/com/guiying/androidmodulepattern/AppModule.java +++ b/app/src/main/java/com/guiying/androidmodulepattern/App.java @@ -3,7 +3,7 @@ import com.github.mzule.activityrouter.annotation.Module; /** - *

类说明

+ *

这就是个壳工程,没有任何界面,只负责管理组件

* * @author 张华洋 2017/2/15 20:42 * @version V1.2.0 @@ -11,5 +11,5 @@ */ @Module("app") -public class AppModule { +public class App { } diff --git a/app/src/main/java/com/guiying/androidmodulepattern/MyApplication.java b/app/src/main/java/com/guiying/androidmodulepattern/MyApplication.java index a4f3976..9fb5a5b 100644 --- a/app/src/main/java/com/guiying/androidmodulepattern/MyApplication.java +++ b/app/src/main/java/com/guiying/androidmodulepattern/MyApplication.java @@ -2,52 +2,21 @@ import com.github.mzule.activityrouter.annotation.Modules; import com.guiying.common.base.BaseApplication; -import com.guiying.common.http.HttpClient; -import com.guiying.common.http.OnResultListener; -import com.orhanobut.logger.Logger; /** - *

类说明

+ *

应用程序的Application只负责管理组件

* * @author 张华洋 2017/2/15 20:14 * @version V1.2.0 * @name MyApplication */ -@Modules({"app", "girls", "news"}) +@Modules({"app", "main", "girls", "news"}) public class MyApplication extends BaseApplication { @Override public void onCreate() { super.onCreate(); - login(); } - /** - * 在这里模拟登陆,然后拿到sessionId或者Token - * 这样就能够在组件请求接口了 - */ - private void login() { - HttpClient client = new HttpClient.Builder() - .baseUrl("http://gank.io/api/data/") - .url("福利/10/1") - .build(); - client.get(new OnResultListener() { - - @Override - public void onSuccess(String result) { - Logger.e(result); - } - - @Override - public void onError(int code, String message) { - Logger.e(message); - } - - @Override - public void onFailure(String message) { - Logger.e(message); - } - }); - } } diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml deleted file mode 100644 index d781ec5..0000000 --- a/app/src/main/res/values/colors.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1c37bea..99d6e54 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,6 +3,4 @@ module - 再按一次退出程序哦~ - diff --git a/build.gradle b/build.gradle index 15257b7..1026373 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ ext { javaVersion = JavaVersion.VERSION_1_8 // App dependencies version - supportLibraryVersion = "25.2.0" + supportLibraryVersion = "25.3.0" retrofitVersion = "2.1.0" glideVersion = "3.7.0" loggerVersion = "1.15" diff --git a/common/src/main/java/com/guiying/common/base/BaseApplication.java b/common/src/main/java/com/guiying/common/base/BaseApplication.java index 3ce3746..d0845d8 100644 --- a/common/src/main/java/com/guiying/common/base/BaseApplication.java +++ b/common/src/main/java/com/guiying/common/base/BaseApplication.java @@ -14,7 +14,7 @@ /** * 要想使用BaseApplication,必须在组件中实现自己的Application,并且继承BaseApplication; - * 组件中实现的Application必须在AndroidManifest.xml中注册,否则无法使用; + * 组件中实现的Application必须在debug包中的AndroidManifest.xml中注册,否则无法使用; * 组件的Application需置于java/debug文件夹中,不得放于主代码; * 组件中获取Context的方法必须为:Utils.getContext(),不允许其他写法; * BaseApplication主要用来管理全局Activity; diff --git a/main/.gitignore b/main/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/main/.gitignore @@ -0,0 +1 @@ +/build diff --git a/main/build.gradle b/main/build.gradle new file mode 100644 index 0000000..7fd1812 --- /dev/null +++ b/main/build.gradle @@ -0,0 +1,50 @@ +if (isModule.toBoolean()) { + apply plugin: 'com.android.application' +} else { + apply plugin: 'com.android.library' +} + +apply plugin: 'com.neenbedankt.android-apt' + +android { + compileSdkVersion rootProject.ext.compileSdkVersion + buildToolsVersion rootProject.ext.buildToolsVersion + + defaultConfig { + minSdkVersion rootProject.ext.minSdkVersion + targetSdkVersion rootProject.ext.targetSdkVersion + versionCode rootProject.ext.versionCode + versionName rootProject.ext.versionName + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + sourceSets { + main { + if (isModule.toBoolean()) { + manifest.srcFile 'src/main/debug/AndroidManifest.xml' + } else { + manifest.srcFile 'src/main/release/AndroidManifest.xml' + //release模式下排除debug文件夹中的所有Java文件 + java { + exclude 'debug/**' + } + } + } + } + //设置了resourcePrefix值后,所有的资源名必须以指定的字符串做前缀,否则会报错。 + //但是resourcePrefix这个值只能限定xml里面的资源,并不能限定图片资源,所有图片资源仍然需要手动去修改资源名。 + //resourcePrefix "girls_" +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile project(':common') + //router + apt "com.github.mzule.activityrouter:compiler:$rootProject.aptCompilerVersion" +} diff --git a/main/proguard-rules.pro b/main/proguard-rules.pro new file mode 100644 index 0000000..c341b8b --- /dev/null +++ b/main/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in D:\SDK/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/main/src/main/debug/AndroidManifest.xml b/main/src/main/debug/AndroidManifest.xml new file mode 100644 index 0000000..fc3933a --- /dev/null +++ b/main/src/main/debug/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/java/com/guiying/main/Main.java b/main/src/main/java/com/guiying/main/Main.java new file mode 100644 index 0000000..87e625b --- /dev/null +++ b/main/src/main/java/com/guiying/main/Main.java @@ -0,0 +1,17 @@ +package com.guiying.main; + +import com.github.mzule.activityrouter.annotation.Module; + +/** + *

声明主要组件

+ *

+ * 这个组件是应用默认启动的组件 + * + * @author 张华洋 2017/4/1 12:39 + * @version V1.2.0 + * @name Main + */ + +@Module("main") +public class Main { +} diff --git a/app/src/main/java/com/guiying/androidmodulepattern/MainActivity.java b/main/src/main/java/com/guiying/main/MainActivity.java similarity index 97% rename from app/src/main/java/com/guiying/androidmodulepattern/MainActivity.java rename to main/src/main/java/com/guiying/main/MainActivity.java index b751ae9..8110108 100644 --- a/app/src/main/java/com/guiying/androidmodulepattern/MainActivity.java +++ b/main/src/main/java/com/guiying/main/MainActivity.java @@ -1,4 +1,4 @@ -package com.guiying.androidmodulepattern; +package com.guiying.main; import android.os.Bundle; import android.support.design.widget.Snackbar; diff --git a/main/src/main/java/debug/MainApplication.java b/main/src/main/java/debug/MainApplication.java new file mode 100644 index 0000000..293f166 --- /dev/null +++ b/main/src/main/java/debug/MainApplication.java @@ -0,0 +1,50 @@ +package debug; + +import com.guiying.common.base.BaseApplication; +import com.guiying.common.http.HttpClient; +import com.guiying.common.http.OnResultListener; +import com.orhanobut.logger.Logger; + +/** + *

类说明

+ * + * @author 张华洋 2017/2/15 20:09 + * @version V1.2.0 + * @name GirlsApplication + */ +public class MainApplication extends BaseApplication { + + @Override + public void onCreate() { + super.onCreate(); + login(); + } + + /** + * 在这里模拟登陆,然后拿到sessionId或者Token + * 这样就能够在组件请求接口了 + */ + private void login() { + HttpClient client = new HttpClient.Builder() + .baseUrl("http://gank.io/api/data/") + .url("福利/10/1") + .build(); + client.get(new OnResultListener() { + + @Override + public void onSuccess(String result) { + Logger.e(result); + } + + @Override + public void onError(int code, String message) { + Logger.e(message); + } + + @Override + public void onFailure(String message) { + Logger.e(message); + } + }); + } +} diff --git a/main/src/main/release/AndroidManifest.xml b/main/src/main/release/AndroidManifest.xml new file mode 100644 index 0000000..4249b68 --- /dev/null +++ b/main/src/main/release/AndroidManifest.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/main/src/main/res/layout/activity_main.xml similarity index 93% rename from app/src/main/res/layout/activity_main.xml rename to main/src/main/res/layout/activity_main.xml index 9e0fb9f..e5e21fe 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/main/src/main/res/layout/activity_main.xml @@ -9,7 +9,7 @@ android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" - tools:context="com.guiying.androidmodulepattern.MainActivity"> + tools:context="com.guiying.main.MainActivity">