Browse Source

1:适配Android Studio 3.0;

guiying712 8 years ago
parent
commit
7e403d3f96

+ 5 - 0
README.md

@@ -14,12 +14,17 @@
 Android项目组件化示例代码
 
 **Android组件化方案**:http://blog.csdn.net/guiying712/article/details/55213884
+
 **Android组件化之终极方案**:http://blog.csdn.net/guiying712/article/details/78057120
 
 1. 现在的 AndroidModulePattern 使用 阿里ARouter作为路由;
+
 2. Android组件化方案已经支持 **Fragment组件化**,使用方法请下载Demo查看;
+
 3. 目前Android组件化方案还没有写完,后续会**继续更新**,完善组件化方案。
 
+4. 本项目已适配Android Studio 3.0.1版本(Google仓库会带来一定影响)
+
 
 ## 集成开发模式和组件开发模式转换
 

+ 5 - 34
build.gradle

@@ -1,11 +1,12 @@
 // Top-level build file where you can add configuration options common to all sub-projects/modules.
 
 buildscript {
+    apply from: '/versions.gradle'
+
     repositories {
+        google()
         jcenter()
-        mavenCentral()
     }
-
     dependencies {
         //classpath "com.android.tools.build:gradle:$localGradlePluginVersion"
         //$localGradlePluginVersion是gradle.properties中的数据
@@ -15,10 +16,9 @@ buildscript {
 
 allprojects {
     repositories {
+        google()
         jcenter()
-        mavenCentral()
-        //Add the JitPack repository
-        maven { url "https://jitpack.io" }
+        maven { url 'https://jitpack.io' }
         //支持arr包
         flatDir {
             dirs 'libs'
@@ -30,32 +30,3 @@ task clean(type: Delete) {
     delete rootProject.buildDir
 }
 
-// Define versions in a single place
-//时间:2017.2.13;每次修改版本号都要添加修改时间
-ext {
-    // Sdk and tools
-    //localBuildToolsVersion是gradle.properties中的数据
-    buildToolsVersion = localBuildToolsVersion
-    compileSdkVersion = 25
-    minSdkVersion = 16
-    targetSdkVersion = 25
-    versionCode = 1
-    versionName = "1.0"
-    javaVersion = JavaVersion.VERSION_1_8
-
-    // App dependencies version
-    supportLibraryVersion = "25.3.1"
-    retrofitVersion = "2.1.0"
-    glideVersion = "3.7.0"
-    loggerVersion = "1.15"
-    eventbusVersion = "3.0.0"
-    gsonVersion = "2.8.0"
-    photoViewVersion = "2.0.0"
-
-    //检查时间:2017.6.6
-    annotationProcessor = "1.0.3"
-    routerVersion = "1.2.1.1"
-    easyRecyclerVersion = "4.4.0"
-    cookieVersion = "v1.0.1"
-    toastyVersion = "1.1.3"
-}

+ 1 - 3
gradle.properties

@@ -18,10 +18,8 @@ org.gradle.jvmargs=-Xmx2048m
 org.gradle.daemon=true
 org.gradle.configureondemand=true
 org.gradle.parallel=true
-# 为自动化出包配置(因为每个开发的电脑坏境不一致)
-localBuildToolsVersion=25.0.3
 # 这个值一般跟你的AndroidStudio版本号一致
-localGradlePluginVersion=2.3.3
+localGradlePluginVersion=3.0.1
 
 # 每次更改“isModule”的值后,需要点击 "Sync Project" 按钮
 # isModule是“集成开发模式”和“组件开发模式”的切换开关

+ 4 - 0
keystore.properties

@@ -0,0 +1,4 @@
+storePassword=guiying712
+keyPassword=guiying712
+keyAlias=guiying712
+storeFile=/mykey.jks

+ 16 - 17
lib_common/build.gradle

@@ -2,8 +2,6 @@ apply plugin: 'com.android.library'
 
 android {
     compileSdkVersion rootProject.ext.compileSdkVersion
-    buildToolsVersion rootProject.ext.buildToolsVersion
-
     defaultConfig {
         minSdkVersion rootProject.ext.minSdkVersion
         targetSdkVersion rootProject.ext.targetSdkVersion
@@ -13,25 +11,26 @@ android {
 }
 
 dependencies {
-    compile fileTree(dir: 'libs', include: ['*.jar'])
+    api fileTree(dir: 'libs', include: ['*.jar'])
     //Android Support
-    compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
-    compile "com.android.support:design:$rootProject.supportLibraryVersion"
-    compile "com.android.support:percent:$rootProject.supportLibraryVersion"
+    api "com.android.support:support-v4:$rootProject.supportLibraryVersion"
+    api "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
+    api "com.android.support:design:$rootProject.supportLibraryVersion"
+    api "com.android.support:percent:$rootProject.supportLibraryVersion"
     //网络请求相关
-    compile "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
-    compile "com.squareup.retrofit2:retrofit-mock:$rootProject.retrofitVersion"
-    compile "com.github.franmontiel:PersistentCookieJar:$rootProject.cookieVersion"
+    api "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
+    api "com.squareup.retrofit2:retrofit-mock:$rootProject.retrofitVersion"
+    api "com.github.franmontiel:PersistentCookieJar:$rootProject.cookieVersion"
     //稳定的
-    compile "com.github.bumptech.glide:glide:$rootProject.glideVersion"
-    compile "com.orhanobut:logger:$rootProject.loggerVersion"
-    compile "org.greenrobot:eventbus:$rootProject.eventbusVersion"
-    compile "com.google.code.gson:gson:$rootProject.gsonVersion"
-    compile "com.github.chrisbanes:PhotoView:$rootProject.photoViewVersion"
+    api "com.github.bumptech.glide:glide:$rootProject.glideVersion"
+    api "com.orhanobut:logger:$rootProject.loggerVersion"
+    api "org.greenrobot:eventbus:$rootProject.eventbusVersion"
+    api "com.google.code.gson:gson:$rootProject.gsonVersion"
+    api "com.github.chrisbanes:PhotoView:$rootProject.photoViewVersion"
 
-    compile "com.jude:easyrecyclerview:$rootProject.easyRecyclerVersion"
-    compile "com.github.GrenderG:Toasty:$rootProject.toastyVersion"
+    api "com.jude:easyrecyclerview:$rootProject.easyRecyclerVersion"
+    api "com.github.GrenderG:Toasty:$rootProject.toastyVersion"
 
     //router
-    compile "com.alibaba:arouter-api:$rootProject.routerVersion"
+    api "com.alibaba:arouter-api:$rootProject.routerVersion"
 }

+ 0 - 2
lib_common/src/main/java/com/guiying/module/common/base/ApplicationDelegate.java

@@ -7,8 +7,6 @@ package com.guiying.module.common.base;
  * @version V2.8.3
  * @name ApplicationDelegate
  */
-
-
 public interface ApplicationDelegate {
 
     void onCreate();

+ 1 - 0
lib_common/src/main/java/com/guiying/module/common/base/BaseApplication.java

@@ -41,6 +41,7 @@ public class BaseApplication extends Application {
         for (ApplicationDelegate delegate : mAppDelegateList) {
             delegate.onCreate();
         }
+
     }
 
     @Override

+ 3 - 2
lib_common/src/main/java/com/guiying/module/common/base/ClassUtils.java

@@ -53,7 +53,8 @@ public class ClassUtils {
      * @param <T>     U know
      * @return 对象列表
      */
-    public static <T> List<T> getObjectsWithInterface(Context context, Class<T> clazz, String path) {
+    public static <T> List<T>
+    getObjectsWithInterface(Context context, Class<T> clazz, String path) {
         List<T> objectList = new ArrayList<>();
         try {
             //找出所有路径中的类名,主要用于各个组件根包名一致的情况
@@ -273,7 +274,7 @@ public class ClassUtils {
 
         }
 
-        Log.i("galaxy", "VM with name " + vmName + (isMultidexCapable ? " has multidex support" : " does not have multidex support"));
+        Log.i(TAG, "VM with name " + vmName + (isMultidexCapable ? " has multidex support" : " does not have multidex support"));
         return isMultidexCapable;
     }
 

+ 84 - 0
lib_common/src/main/java/com/guiying/module/common/utils/ScreenLockUtil.java

@@ -0,0 +1,84 @@
+package com.guiying.module.common.utils;
+
+import android.app.Activity;
+import android.app.KeyguardManager;
+import android.app.KeyguardManager.KeyguardLock;
+import android.content.Context;
+import android.os.PowerManager;
+import android.os.PowerManager.WakeLock;
+import android.util.Log;
+
+import java.util.HashMap;
+
+/**
+ * 用于保持屏幕高亮的工具
+ */
+public class ScreenLockUtil {
+    private static final String TAG = "ScreenLockUtil";
+
+    private ScreenLockUtil() {
+        throw new UnsupportedOperationException("cannot be instantiated");
+    }
+
+    static private HashMap<Activity, WakeLock> mWakeLockArray = new HashMap<>();
+    static private HashMap<Activity, Boolean> mIsUnlockArray = new HashMap<>();
+
+
+    /**
+     * 保持屏幕常亮
+     *
+     * @param activity you know
+     */
+    public static void keepScreenOn(Activity activity) {
+        WakeLock wakeLock = mWakeLockArray.get(activity);
+        if (wakeLock == null) {
+            PowerManager powerManager = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
+            wakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK,
+                    activity.getClass().getName());
+        }
+
+        if (!wakeLock.isHeld()) {
+            wakeLock.acquire();
+        }
+
+        mWakeLockArray.put(activity, wakeLock);
+
+        cancelLockScreen(activity);
+
+        Log.i(TAG, "开启屏幕常亮");
+    }
+
+
+    /**
+     * 取消屏幕常亮
+     *
+     * @param activity you know
+     */
+    public static void cancelKeepScreen(Activity activity) {
+        WakeLock wakeLock = mWakeLockArray.get(activity);
+        if (wakeLock != null) {
+            if (wakeLock.isHeld()) {
+                wakeLock.release();
+            }
+        }
+
+        Log.i(TAG, "取消屏幕常亮");
+    }
+
+    /**
+     * 取消锁屏限制
+     *
+     * @param activity you know
+     */
+    private static void cancelLockScreen(Activity activity) {
+        Boolean isUnlock = mIsUnlockArray.get(activity);
+        if (isUnlock != null && isUnlock) {
+            return;
+        }
+        KeyguardManager mKeyguardManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
+        KeyguardLock mKeyguardLock = mKeyguardManager.newKeyguardLock(activity.getClass().getName());
+        mKeyguardLock.disableKeyguard();
+
+        mIsUnlockArray.put(activity, true);
+    }
+}

+ 19 - 13
module_app/build.gradle

@@ -1,5 +1,13 @@
 apply plugin: 'com.android.application'
 
+// Create a variable called keystorePropertiesFile, and initialize it to your
+// keystore.properties file, in the rootProject folder.
+def keystorePropertiesFile = rootProject.file("keystore.properties")
+// Initialize a new Properties() object called keystoreProperties.
+def keystoreProperties = new Properties()
+// Load your keystore.properties file into the keystoreProperties object.
+keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
+
 static def buildTime() {
     return new Date().format("yyyyMMdd");
 }
@@ -7,15 +15,14 @@ static def buildTime() {
 android {
     signingConfigs {
         release {
-            keyAlias 'guiying712'
-            keyPassword 'guiying712'
-            storeFile file('/mykey.jks')
-            storePassword 'guiying712'
+            keyAlias keystoreProperties['keyAlias']
+            keyPassword keystoreProperties['keyPassword']
+            storeFile file(keystoreProperties['storeFile'])
+            storePassword keystoreProperties['storePassword']
         }
     }
 
     compileSdkVersion rootProject.ext.compileSdkVersion
-    buildToolsVersion rootProject.ext.buildToolsVersion
     defaultConfig {
         applicationId "com.guiying.module"
         minSdkVersion rootProject.ext.minSdkVersion
@@ -60,13 +67,12 @@ android {
 }
 
 dependencies {
-    compile fileTree(dir: 'libs', include: ['*.jar'])
-    compile 'com.android.support:multidex:1.0.1'
-    if (isModule.toBoolean()) {
-        compile project(':lib_common')
-    } else {
-        compile project(':module_main')
-        compile project(':module_girls')
-        compile project(':module_news')
+    implementation fileTree(dir: 'libs', include: ['*.jar'])
+    implementation 'com.android.support:multidex:1.0.2'
+    implementation project(':lib_common')
+    if (!isModule.toBoolean()) {
+        implementation project(':module_main')
+        implementation project(':module_girls')
+        implementation project(':module_news')
     }
 }

+ 2 - 4
module_girls/build.gradle

@@ -6,8 +6,6 @@ if (isModule.toBoolean()) {
 
 android {
     compileSdkVersion rootProject.ext.compileSdkVersion
-    buildToolsVersion rootProject.ext.buildToolsVersion
-
     defaultConfig {
         minSdkVersion rootProject.ext.minSdkVersion
         targetSdkVersion rootProject.ext.targetSdkVersion
@@ -39,7 +37,7 @@ android {
 }
 
 dependencies {
-    compile fileTree(dir: 'libs', include: ['*.jar'])
+    implementation fileTree(dir: 'libs', include: ['*.jar'])
     annotationProcessor "com.alibaba:arouter-compiler:$rootProject.annotationProcessor"
-    compile project(':lib_common')
+    implementation project(':lib_common')
 }

+ 2 - 6
module_main/build.gradle

@@ -6,8 +6,6 @@ if (isModule.toBoolean()) {
 
 android {
     compileSdkVersion rootProject.ext.compileSdkVersion
-    buildToolsVersion rootProject.ext.buildToolsVersion
-
     defaultConfig {
         minSdkVersion rootProject.ext.minSdkVersion
         targetSdkVersion rootProject.ext.targetSdkVersion
@@ -42,9 +40,7 @@ android {
 }
 
 dependencies {
-    compile fileTree(dir: 'libs', include: ['*.jar'])
+    implementation fileTree(dir: 'libs', include: ['*.jar'])
     annotationProcessor "com.alibaba:arouter-compiler:$rootProject.annotationProcessor"
-    compile project(':lib_common')
-    compile 'com.android.support:design:25.3.1'
-    compile 'com.android.support:support-vector-drawable:25.3.1'
+    implementation project(':lib_common')
 }

+ 2 - 5
module_news/build.gradle

@@ -6,8 +6,6 @@ if (isModule.toBoolean()) {
 
 android {
     compileSdkVersion rootProject.ext.compileSdkVersion
-    buildToolsVersion rootProject.ext.buildToolsVersion
-
     defaultConfig {
         minSdkVersion rootProject.ext.minSdkVersion
         targetSdkVersion rootProject.ext.targetSdkVersion
@@ -39,8 +37,7 @@ android {
 }
 
 dependencies {
-    compile fileTree(dir: 'libs', include: ['*.jar'])
+    implementation fileTree(dir: 'libs', include: ['*.jar'])
     annotationProcessor "com.alibaba:arouter-compiler:$rootProject.annotationProcessor"
-    compile project(':lib_common')
-    compile 'com.android.support:support-v4:25.3.1'
+    implementation project(':lib_common')
 }

+ 2 - 2
module_news/src/main/java/com/guiying/module/news/MyDelegate.java

@@ -2,6 +2,7 @@ package com.guiying.module.news;
 
 import com.guiying.module.common.base.ApplicationDelegate;
 import com.guiying.module.common.base.ViewManager;
+import com.orhanobut.logger.Logger;
 
 /**
  * <p>类说明</p>
@@ -10,12 +11,11 @@ import com.guiying.module.common.base.ViewManager;
  * @version V2.8.3
  * @name MyDelegate
  */
-
-
 public class MyDelegate implements ApplicationDelegate {
 
     @Override
     public void onCreate() {
+        Logger.init("pattern");
         ViewManager.getInstance().addFragment(0, new NewsFragment());
     }
 

+ 27 - 0
versions.gradle

@@ -0,0 +1,27 @@
+// Define versions in a single place
+//时间:2017.2.13;每次修改版本号都要添加修改时间
+rootProject.ext {
+    // Sdk and tools
+    compileSdkVersion = 25
+    minSdkVersion = 16
+    targetSdkVersion = 25
+    versionCode = 1
+    versionName = "1.0"
+    javaVersion = JavaVersion.VERSION_1_8
+
+    // App dependencies versions
+    supportLibraryVersion = "25.4.0"
+    retrofitVersion = "2.1.0"
+    glideVersion = "3.8.0"
+    loggerVersion = "1.15"
+    eventbusVersion = "3.0.0"
+    gsonVersion = "2.8.0"
+    photoViewVersion = "2.0.0"
+
+    //检查时间:2017.6.6
+    annotationProcessor = "1.0.3"
+    routerVersion = "1.2.1.1"
+    easyRecyclerVersion = "4.4.0"
+    cookieVersion = "v1.0.1"
+    toastyVersion = "1.1.3"
+}