diff --git a/CHANGELOG.md b/CHANGELOG.md index 52098557b1..73e8145bf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +* `22/10/15` [add] Fix some issue. Publish v1.31.1 +* `21/12/06` [add] Publish v1.31.0 +* `21/05/13` [add] Support publish mavenCentral. +* `21/02/22` [add] Fix ToastUtils rtl bug. Publish v1.30.6. +* `20/11/16` [add] Add ImageUtils#save2Album support param of dirName. +* `20/11/13` [add] Fix MessengerUtils ANR. Add NetworkUtils#getWifiScanResult, [add|remove]OnWifiChangedConsumer. Publish v1.30.5. +* `20/10/29` [add] Fix MessengerUtils startService IllegalStateException. Publish v1.30.4. +* `20/10/28` [add] Fix BusUtils ConcurrentModificationException. Publish v1.30.3. +* `20/10/27` [add] Fix AppUtils#getAppSignatures. Add DeviceUtils#isDevelopmentSettingsEnabled. Publish v1.30.2. * `20/10/26` [add] Fix AppUtils#isAppForeground. Publish v1.30.1. * `20/10/24` [add] Publish v1.30.0. * `20/10/23` [fix] LanguageUtils crash on some device. @@ -102,6 +111,7 @@ * `19/04/24` [upd] The swipe panel. * `19/03/17` [fix] The ugly UI. * `19/03/14` [fix] AdaptScreenUtils didn't work on some HaWei tablet. +* `19/03/09` [fix] UriUtils#uri2File. * `19/03/08` [add] LogUtils support multi process. Publish v1.23.7. * `19/03/02` [fix] LogUtils#file. * `19/02/28` [fix] ImageUtils#calculateInSampleSize. Publish v1.23.6. diff --git a/build.gradle b/build.gradle index dd27b98617..e0f0f36c87 100644 --- a/build.gradle +++ b/build.gradle @@ -2,26 +2,25 @@ buildscript { ConfigUtils.init(gradle) repositories { - // use for debug plugin local - if (Config.depConfig.plugin_bus.useLocal || Config.depConfig.plugin_api.useLocal) { - maven() { url uri("${project.rootDir.path}/mavenLocal") } - } + mavenLocal() google() + mavenCentral() jcenter() } dependencies { for (def entrySet : ConfigUtils.getApplyPlugins().entrySet()) { - classpath entrySet.value.dep + classpath entrySet.value.path } } } allprojects { repositories { - maven() { url uri("${project.rootDir.path}/mavenLocal") } + mavenLocal() maven { url "https://jitpack.io/" } google() + mavenCentral() jcenter() } @@ -29,8 +28,8 @@ allprojects { resolutionStrategy.cacheChangingModulesFor 0, 'seconds' resolutionStrategy.eachDependency { - if (it.requested.group == 'com.android.support' - && !it.requested.name.contains('multidex')) { + if (it.requested.group == 'com.android.support' && !it.requested.name.contains( + 'multidex')) { it.useVersion Config.supportVersion } } diff --git a/buildApp.gradle b/buildApp.gradle index 0af2639065..93f0b9b1d4 100644 --- a/buildApp.gradle +++ b/buildApp.gradle @@ -1,28 +1,30 @@ +apply plugin: "com.android.application" + apply { - plugin "com.android.application" - from "${rootDir.path}/buildCommon.gradle" - if (Config.depConfig.plugin_api.isApply) { - plugin Config.depConfig.plugin_api.pluginId + from "${rootDir.path}/buildCommon.gradle" + from "${rootDir.path}/config/flavor.gradle" + if (Config.plugins.plugin_api.isApply) { + plugin Config.plugins.plugin_api.id } - if (Config.depConfig.plugin_bus.isApply) { - plugin Config.depConfig.plugin_bus.pluginId + if (Config.plugins.plugin_bus.isApply) { + plugin Config.plugins.plugin_bus.id } } configSigning() configApkName() -if (Config.depConfig.plugin_bus.isApply) { - bus { - onlyScanLibRegex = '^([:]|(com\\.blankj)).+$' - } -} - -if (Config.depConfig.plugin_api.isApply) { - api { - onlyScanLibRegex = '^([:]|(com\\.blankj)).+$' - } -} +//if (PluginConfig.plugin_bus.isApply) { +// bus { +// onlyScanLibRegex = '^([:]|(com\\.blankj)).+$' +// } +//} +// +//if (PluginConfig.plugin_api.isApply) { +// api { +// onlyScanLibRegex = '^([:]|(com\\.blankj)).+$' +// } +//} android { defaultConfig { @@ -32,17 +34,11 @@ android { } buildTypes { - debug { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - applicationIdSuffix ".debug" - resValue "string", "app_name", Config.appName + suffix + ".debug" - } + debug {} release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - resValue "string", "app_name", Config.appName + suffix } } @@ -56,29 +52,42 @@ android { maxProcessCount 8 dexInProcess = true } -} + productFlavors { + dev { + applicationIdSuffix ".dev" + versionNameSuffix "-dev" + resValue "string", "app_name", Config.appName + suffix + "-dev" + } + + production { + resValue "string", "app_name", Config.appName + suffix + } + } +} dependencies { // LeakCanary - debugImplementation Config.depConfig.leakcanary.dep + debugImplementation Config.libs.leakcanary.path - debugImplementation Config.depConfig.lib_utildebug.dep - releaseImplementation Config.depConfig.lib_utildebug_no_op.dep + debugImplementation Config.modules.lib_utildebug.dep + releaseImplementation Config.modules.lib_utildebug_no_op.dep // 根据 Config.pkgConfig 来依赖所有 pkg for (def entrySet : ConfigUtils.getApplyPkgs().entrySet()) { api entrySet.value.dep } - if (Config.depConfig.feature_mock.isApply) { - api Config.depConfig.feature_mock.dep + if (Config.modules.feature_mock.isApply) { + api ModuleConfig.modules.feature_mock.dep } } def getSuffix() { if (project.name == "feature_launcher_app") return "" - return "." + project.name.substring("feature_".length(), project.name.length() - "_app".length()) + return "." + project. + name. + substring("feature_".length(), project.name.length() - "_app".length()) } def configSigning() { @@ -108,12 +117,14 @@ def configApkName() { if (variant.buildType.name != "debug") { def artifact = variant.getPackageApplicationProvider().get() artifact.outputDirectory = new File("${rootDir.path}/apk") - artifact.outputScope.apkDatas.forEach { apkData -> - apkData.outputFileName = "util" + suffix + - (variant.flavorName == "" ? "" : ("_" + variant.flavorName)) + - "_" + variant.versionName.replace(".", "_") + - "_" + variant.buildType.name + - ".apk" + variant.outputs.each { + it.outputFileName = "util" + suffix + + (variant.flavorName == "" ? "" : ("_" + variant.flavorName)) + + "_" + + variant.versionName.replace(".", "_") + + "_" + + variant.buildType.name + + ".apk" } } } diff --git a/buildCommon.gradle b/buildCommon.gradle index f83f74f52d..2cba3ffea2 100644 --- a/buildCommon.gradle +++ b/buildCommon.gradle @@ -19,23 +19,12 @@ android { } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + lintOptions { abortOnError false } - -// viewBinding { -// enabled = true -// } - -// flavorDimensions "region" -// -// productFlavors { -// china { -// dimension "region" -// } -// -// oversea { -// dimension "region" -// } -// } } \ No newline at end of file diff --git a/buildLib.gradle b/buildLib.gradle index ac9c42ac1c..aed207cbee 100644 --- a/buildLib.gradle +++ b/buildLib.gradle @@ -8,6 +8,6 @@ dependencies { api entrySet.value.dep } } else if (project.name.endsWith("_export")) { - api Config.depConfig.lib_common.dep + api Config.modules.lib_common.dep } } \ No newline at end of file diff --git a/buildSrc/settings.gradle b/buildSrc/settings.gradle new file mode 100644 index 0000000000..8a313c3b99 --- /dev/null +++ b/buildSrc/settings.gradle @@ -0,0 +1,8 @@ +//dependencyResolutionManagement { +// repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) +// repositories { +// google() +// mavenCentral() +// jcenter() // Warning: this repository is going to shut down soon +// } +//} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/Config.groovy b/buildSrc/src/main/groovy/Config.groovy index b193347c12..9a8d69d659 100644 --- a/buildSrc/src/main/groovy/Config.groovy +++ b/buildSrc/src/main/groovy/Config.groovy @@ -1,11 +1,3 @@ -/** - *
- *     author: blankj
- *     blog  : http://blankj.com
- *     time  : 2019/07/13
- *     desc  :
- * 
- */ class Config { static applicationId = 'com.blankj.androidutilcode' @@ -14,76 +6,84 @@ class Config { static compileSdkVersion = 29 static minSdkVersion = 14 static targetSdkVersion = 29 - static versionCode = 1_030_001 - static versionName = '1.30.1'// E.g. 1.9.72 => 1,009,072 + static versionCode = 1_031_001 + static versionName = '1.31.1'// E.g. 1.9.72 => 1,009,072 // lib version - static gradlePluginVersion = '3.5.0' + static gradlePluginVersion = '4.1.0' static kotlinVersion = '1.3.72' - static supportVersion = '28.0.0' + static androidxVersion = '1.0.0' - static depConfig = [ - /*Never delete this line*/ - /*Generated by "config.json"*/ - plugin_api_gradle_plugin : new DepConfig(true , true , ":plugin:api-gradle-plugin"), - plugin_bus_gradle_plugin : new DepConfig(true , true , ":plugin:bus-gradle-plugin"), - plugin_lib_base_transform : new DepConfig(true , false, ":plugin:lib:base-transform", "com.blankj:base-transform:1.0"), - feature_mock : new DepConfig(false, true , ":feature:mock"), - feature_launcher_app : new DepConfig(true , true , ":feature:launcher:app"), - feature_main_app : new DepConfig(false, true , ":feature:main:app"), - feature_main_pkg : new DepConfig(true , true , ":feature:main:pkg"), - feature_subutil_app : new DepConfig(false, true , ":feature:subutil:app"), - feature_subutil_pkg : new DepConfig(true , true , ":feature:subutil:pkg"), - feature_subutil_export : new DepConfig(true , true , ":feature:subutil:export"), - feature_utilcode_app : new DepConfig(false, true , ":feature:utilcode:app"), - feature_utilcode_pkg : new DepConfig(true , true , ":feature:utilcode:pkg"), - feature_utilcode_export : new DepConfig(true , true , ":feature:utilcode:export", "com.blankj:utilcode-export:1.1"), - lib_base : new DepConfig(true , true , ":lib:base"), - lib_common : new DepConfig(true , true , ":lib:common"), - lib_subutil : new DepConfig(true , true , ":lib:subutil"), - lib_utilcode : new DepConfig(true , true , ":lib:utilcode", "com.blankj:utilcode:$versionName"), - lib_utildebug : new DepConfig(true , true , ":lib:utildebug"), - lib_utildebug_no_op : new DepConfig(true , true , ":lib:utildebug-no-op"), - /*Never delete this line*/ - plugin_gradle : new DepConfig(pluginPath: "com.android.tools.build:gradle:$gradlePluginVersion"), - plugin_kotlin : new DepConfig(pluginPath: "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"), - plugin_maven : new DepConfig(pluginPath: "com.github.dcendents:android-maven-gradle-plugin:2.1", pluginId: "com.github.dcendents.android-maven"),// 上传到 maven - plugin_bintray : new DepConfig(pluginPath: "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4", pluginId: "com.jfrog.bintray"),// 上传到 bintray - plugin_traute : new DepConfig(pluginPath: "tech.harmonysoft:traute-gradle:1.1.10", pluginId: "tech.harmonysoft.oss.traute"),// 注解转非空判断 + static modules = [ + /*Don't delete this line*/ + /*Generated by "module_config.json"*/ + plugin_api_gradle_plugin : new ModuleConfig(isApply: true , useLocal: true , localPath: "./plugin/api-gradle-plugin"), + plugin_bus_gradle_plugin : new ModuleConfig(isApply: true , useLocal: true , localPath: "./plugin/bus-gradle-plugin"), + plugin_lib_base_transform : new ModuleConfig(isApply: true , useLocal: true , localPath: "./plugin/lib/base-transform", remotePath: "com.blankj:base-transform:1.0"), + plugin_buildSrc_plugin : new ModuleConfig(isApply: true , useLocal: true , localPath: "./plugin/buildSrc-plugin"), + feature_mock : new ModuleConfig(isApply: false, useLocal: true , localPath: "./feature/mock"), + feature_launcher_app : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/launcher/app"), + feature_main_app : new ModuleConfig(isApply: false, useLocal: true , localPath: "./feature/main/app"), + feature_main_pkg : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/main/pkg"), + feature_subutil_app : new ModuleConfig(isApply: false, useLocal: true , localPath: "./feature/subutil/app"), + feature_subutil_pkg : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/subutil/pkg"), + feature_subutil_export : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/subutil/export"), + feature_utilcode_app : new ModuleConfig(isApply: false, useLocal: true , localPath: "./feature/utilcode/app"), + feature_utilcode_pkg : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/utilcode/pkg"), + feature_utilcode_export : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/utilcode/export", remotePath: "com.blankj:utilcode-export:1.1"), + lib_base : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/base"), + lib_common : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/common"), + lib_subutil : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/subutil"), + lib_utilcode : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/utilcode", remotePath: "com.blankj:utilcodex:$Config.versionName"), + lib_utildebug : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/utildebug"), + lib_utildebug_no_op : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/utildebug-no-op"), + /*Don't delete this line*/ + ] + + static plugins = [ + plugin_gradle : new PluginConfig(path: "com.android.tools.build:gradle:$gradlePluginVersion"), + plugin_kotlin : new PluginConfig(path: "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"), + // 上传到 maven + plugin_maven : new PluginConfig(path: "com.github.dcendents:android-maven-gradle-plugin:2.1", id: "com.github.dcendents.android-maven"), - // 上传新版本插件更新 pluginPath 中的版本号,并设置 isApply = false + // 上传新版本插件更新 path 中的版本号,并设置 isApply = false // 通过 mavenLocal 上传本地版本,设置 isApply = true 即可应用插件来调试,最后通过 bintrayUpload 来发布插件 - plugin_api : new DepConfig(isApply: true, useLocal: false, pluginPath: "com.blankj:api-gradle-plugin:1.4", pluginId: "com.blankj.api"), + plugin_api : new PluginConfig(isApply: true, useLocal: false, path: "com.blankj:api-gradle-plugin:1.5", id: "com.blankj.api"), //./gradlew clean :plugin_api-gradle-plugin:mavenLocal // 上传到本地 mavenLocal //./gradlew clean :plugin_api-gradle-plugin:bintrayUpload // 上传到 jcenter - plugin_bus : new DepConfig(isApply: true, useLocal: false, pluginPath: "com.blankj:bus-gradle-plugin:2.6", pluginId: "com.blankj.bus"), + plugin_bus : new PluginConfig(isApply: true, useLocal: false, path: "com.blankj:bus-gradle-plugin:2.6", id: "com.blankj.bus"), //./gradlew clean :plugin_bus-gradle-plugin:mavenLocal // 上传到本地 mavenLocal //./gradlew clean :plugin_bus-gradle-plugin:bintrayUpload // 上传到 jcenter + plugin_buildSrc: new PluginConfig(isApply: false, useLocal: false, path: "com.blankj:buildSrc-plugin:1.0", id: "com.blankj.buildSrc"), + //./gradlew clean :plugin_bus-gradle-plugin:mavenLocal // 上传到本地 mavenLocal + //./gradlew clean :plugin_bus-gradle-plugin:bintrayUpload // 上传到 jcenter + ] - support_appcompat_v7 : new DepConfig("com.android.support:appcompat-v7:$supportVersion"), - support_design : new DepConfig("com.android.support:design:$supportVersion"), - support_multidex : new DepConfig("com.android.support:multidex:1.0.2"), - support_constraint : new DepConfig("com.android.support.constraint:constraint-layout:1.1.3"), + static libs = [ + androidx_appcompat : new LibConfig(path: "androidx.appcompat:appcompat:$androidxVersion"), + androidx_material : new LibConfig(path: "com.google.android.material:material:$androidxVersion"), + androidx_multidex : new LibConfig(path: "androidx.multidex:multidex:2.0.0"), + androidx_constraint: new LibConfig(path: "androidx.constraintlayout:constraintlayout:1.1.3"), - kotlin : new DepConfig("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"), + kotlin : new LibConfig(path: "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"), - leakcanary : new DepConfig("com.squareup.leakcanary:leakcanary-android:2.1"), + leakcanary : new LibConfig(path: "com.squareup.leakcanary:leakcanary-android:2.1"), - free_proguard : new DepConfig("com.blankj:free-proguard:1.0.2"), - swipe_panel : new DepConfig("com.blankj:swipe-panel:1.2"), + free_proguard : new LibConfig(path: "com.blankj:free-proguard:1.0.2"), + swipe_panel : new LibConfig(path: "com.blankj:swipe-panel:1.2"), - gson : new DepConfig("com.google.code.gson:gson:2.8.5"), - glide : new DepConfig("com.github.bumptech.glide:glide:4.7.1"), - retrofit : new DepConfig("com.squareup.retrofit2:retrofit:2.4.0"), - commons_io : new DepConfig("commons-io:commons-io:2.6"), + gson : new LibConfig(path: "com.google.code.gson:gson:2.8.5"), + glide : new LibConfig(path: "com.github.bumptech.glide:glide:4.7.1"), + retrofit : new LibConfig(path: "com.squareup.retrofit2:retrofit:2.4.0"), + commons_io : new LibConfig(path: "commons-io:commons-io:2.6"), - eventbus_lib : new DepConfig("org.greenrobot:eventbus:3.1.1"), - eventbus_processor : new DepConfig("org.greenrobot:eventbus-annotation-processor:3.0.1"), + eventbus_lib : new LibConfig(path: "org.greenrobot:eventbus:3.1.1"), + eventbus_processor : new LibConfig(path: "org.greenrobot:eventbus-annotation-processor:3.0.1"), - photo_view : new DepConfig("com.github.chrisbanes:PhotoView:2.0.0"), + photo_view : new LibConfig(path: "com.github.chrisbanes:PhotoView:2.0.0"), - test_junit : new DepConfig("junit:junit:4.12"), - test_robolectric : new DepConfig("org.robolectric:robolectric:4.3.1"), + test_junit : new LibConfig(path: "junit:junit:4.12"), + test_robolectric : new LibConfig(path: "org.robolectric:robolectric:4.3.1"), ] } //./gradlew clean :lib_utilcode:bintrayUpload \ No newline at end of file diff --git a/buildSrc/src/main/groovy/ConfigUtils.groovy b/buildSrc/src/main/groovy/ConfigUtils.groovy index d60518fac5..6a09d2f2d9 100644 --- a/buildSrc/src/main/groovy/ConfigUtils.groovy +++ b/buildSrc/src/main/groovy/ConfigUtils.groovy @@ -17,7 +17,6 @@ class ConfigUtils { generateDep(gradle) addCommonGradle(gradle) TaskDurationUtils.init(gradle) - GitUtils.init(gradle) } /** @@ -25,16 +24,12 @@ class ConfigUtils { */ private static void generateDep(Gradle gradle) { def configs = [:] - for (Map.Entry entry : Config.depConfig.entrySet()) { + for (Map.Entry entry : Config.modules.entrySet()) { def (name, config) = [entry.key, entry.value] - if (entry.value.pluginPath) { - config.dep = config.pluginPath + if (config.useLocal) { + config.dep = gradle.rootProject.findProject(name) } else { - if (config.useLocal) { - config.dep = gradle.rootProject.findProject(config.projectPath) - } else { - config.dep = config.remotePath - } + config.dep = config.remotePath } configs.put(name, config) } @@ -46,20 +41,18 @@ class ConfigUtils { @Override void beforeEvaluate(Project project) { // 在 project 的 build.gradle 前 do sth. - if (project.subprojects.isEmpty()) { - if (project.path.startsWith(":plugin")) { - return + if (project.name.contains("plugin")) { + return + } + if (project.name.endsWith("_app")) { + GLog.l(project.toString() + " applies buildApp.gradle") + project.apply { + from "${project.rootDir.path}/buildApp.gradle" } - if (project.name.endsWith("_app")) { - GLog.l(project.toString() + " applies buildApp.gradle") - project.apply { - from "${project.rootDir.path}/buildApp.gradle" - } - } else { - GLog.l(project.toString() + " applies buildLib.gradle") - project.apply { - from "${project.rootDir.path}/buildLib.gradle" - } + } else { + GLog.l(project.toString() + " applies buildLib.gradle") + project.apply { + from "${project.rootDir.path}/buildLib.gradle" } } } @@ -73,8 +66,8 @@ class ConfigUtils { static getApplyPlugins() { def plugins = [:] - for (Map.Entry entry : Config.depConfig.entrySet()) { - if (entry.value.isApply && entry.value.pluginPath) { + for (Map.Entry entry : Config.plugins.entrySet()) { + if (entry.value.isApply) { plugins.put(entry.key, entry.value) } } @@ -84,7 +77,7 @@ class ConfigUtils { static getApplyPkgs() { def pkgs = [:] - for (Map.Entry entry : Config.depConfig.entrySet()) { + for (Map.Entry entry : Config.modules.entrySet()) { if (entry.value.isApply && entry.key.endsWith("_pkg")) { pkgs.put(entry.key, entry.value) } @@ -95,7 +88,7 @@ class ConfigUtils { static getApplyExports() { def exports = [:] - for (Map.Entry entry : Config.depConfig.entrySet()) { + for (Map.Entry entry : Config.modules.entrySet()) { if (entry.value.isApply && entry.key.endsWith("_export")) { exports.put(entry.key, entry.value) } diff --git a/buildSrc/src/main/groovy/DepConfig.groovy b/buildSrc/src/main/groovy/DepConfig.groovy deleted file mode 100644 index 042b67036d..0000000000 --- a/buildSrc/src/main/groovy/DepConfig.groovy +++ /dev/null @@ -1,93 +0,0 @@ -/** - *
- *     author: blankj
- *     blog  : http://blankj.com
- *     time  : 2019/07/13
- *     desc  :
- * 
- */ -class DepConfig { - boolean isApply // 是否应用 - boolean useLocal // 是否使用本地的 - String localPath // 本地路径 - String remotePath// 远程路径 - String pluginPath// 插件路径 - String pluginId // 插件 ID - def dep // 根据条件生成项目最终的依赖项 - - DepConfig() { - isApply = true - } - - DepConfig(String path) { - this(true, path) - } - - DepConfig(boolean isApply, String path) { - if (path.startsWith(":")) { - this.useLocal = true - this.localPath = path - this.isApply = isApply - } else { - this.useLocal = false - this.remotePath = path - this.isApply = isApply - } - } - - DepConfig(boolean useLocal, String localPath, String remotePath) { - this(true, useLocal, localPath, remotePath) - } - - DepConfig(boolean isApply, boolean useLocal, String localPath) { - this(isApply, useLocal, localPath, null) - } - - DepConfig(boolean isApply, boolean useLocal, String localPath, String remotePath) { - this.isApply = isApply - this.useLocal = useLocal - this.localPath = localPath - this.remotePath = remotePath - } - - void setPluginPath(String pluginPath) { - this.pluginPath = pluginPath - this.remotePath = pluginPath - } - - String getPath() { - if (pluginPath != null) return pluginPath - return useLocal ? localPath : remotePath - } - - String getGroupId() { - String[] splits = remotePath.split(":") - return splits.length == 3 ? splits[0] : null - } - - String getArtifactId() { - String[] splits = remotePath.split(":") - return splits.length == 3 ? splits[1] : null - } - - String getVersion() { - String[] splits = remotePath.split(":") - return splits.length == 3 ? splits[2] : null - } - - String getProjectPath() { - return ":" + localPath.substring(1).replace(":", "_") - } - - @Override - String toString() { - return "{ isApply = ${getFlag(isApply)}" + - ", useLocal = ${getFlag(useLocal)}" + - (dep == null ? ", path = " + path : (", dep = " + dep)) + - " }" - } - - static String getFlag(boolean b) { - return b ? "✅" : "❌" - } -} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/GitUtils.groovy b/buildSrc/src/main/groovy/GitUtils.groovy deleted file mode 100644 index f525377a79..0000000000 --- a/buildSrc/src/main/groovy/GitUtils.groovy +++ /dev/null @@ -1,111 +0,0 @@ -import org.gradle.api.Action -import org.gradle.api.Project -import org.gradle.api.invocation.Gradle - -import java.text.SimpleDateFormat - -/** - *
- *     author: blankj
- *     blog  : http://blankj.com
- *     time  : 2019/08/16
- *     desc  :
- * 
- */ -class GitUtils { - - private static Project rootProject; - - static void init(Gradle gradle) { - rootProject = gradle.rootProject - addGitHelpTask() - } - - static def addGitHelpTask() { - rootProject.task("gitHelp").doLast { - def commands = [ - " ############## input command code #################", - " # [1] Git Push #", - " # [2] Git Push And Merge to Master #", - " # [3] Git New Branch #", - " # [0] exit #", - " ###################################################", - ] - String commandTips = String.join(System.getProperty("line.separator"), commands) - while (true) { - GLog.l(commandTips) - Scanner scanner = new Scanner(System.in) - def input = scanner.next() - GLog.l(input) - switch (input) { - case "1": - gitPush() - break - case "2": - gitPushAndMerge2Master() - break - case "3": - gitNewBranch() - break - case "0": - return - } - } - } - } - - static void gitPush() { - String branchName = getGitBranch() - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd") - String date = simpleDateFormat.format(new Date()) - exeCmd( - "git add -A", - "git commit -m \"see $date log\"", - "git push origin $branchName" - ) - } - - static void gitPushAndMerge2Master() { - String branchName = getGitBranch() - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd") - String date = simpleDateFormat.format(new Date()) - exeCmd( - "git add -A", - "git commit -m \"see $date log\"", - "git push origin $branchName", - "git checkout master", - "git merge $branchName", - "git push origin master", - "git checkout $branchName" - ) - } - - static void gitNewBranch() { - exeCmd( - "git checkout master", - "git checkout -b ${Config.versionName}", - "git push origin ${Config.versionName}:${Config.versionName}", - ) - } - - private static def getGitBranch() { - return exeCmd("git symbolic-ref --short -q HEAD") - } - - private static def exeCmd(String... cmds) { - String output = "" - for (def cmd in cmds) { - output = _exeCmd(cmd) - } - return output - } - - private static def _exeCmd(String cmd) { - def output = new StringBuilder() - GLog.l("Execute command: ${cmd}") - def cmdResult = ShellUtils.execCmd(cmd) - GLog.l("$cmdResult") - return cmdResult.successMsg - } -} -// ./gradlew gitHelp diff --git a/buildSrc/src/main/groovy/LibConfig.groovy b/buildSrc/src/main/groovy/LibConfig.groovy new file mode 100644 index 0000000000..6369553ba0 --- /dev/null +++ b/buildSrc/src/main/groovy/LibConfig.groovy @@ -0,0 +1,29 @@ +class LibConfig { + + String path + + String getGroupId() { + String[] splits = path.split(":") + return splits.length == 3 ? splits[0] : null + } + + String getArtifactId() { + String[] splits = path.split(":") + return splits.length == 3 ? splits[1] : null + } + + String getVersion() { + String[] splits = path.split(":") + return splits.length == 3 ? splits[2] : null + } + + @Override + String toString() { + return "LibConfig { path = $path }" + } + + static String getFlag(boolean b) { + return b ? "✅" : "❌" + } +} + diff --git a/buildSrc/src/main/groovy/ModuleConfig.groovy b/buildSrc/src/main/groovy/ModuleConfig.groovy new file mode 100644 index 0000000000..291abd8ffe --- /dev/null +++ b/buildSrc/src/main/groovy/ModuleConfig.groovy @@ -0,0 +1,35 @@ +class ModuleConfig { + + boolean isApply // 是否应用 + boolean useLocal // 是否使用本地的 + String localPath // 本地路径 + String remotePath // 远程路径 + def dep // 根据条件生成项目最终的依赖项 + + String getGroupId() { + String[] splits = remotePath.split(":") + return splits.length == 3 ? splits[0] : null + } + + String getArtifactId() { + String[] splits = remotePath.split(":") + return splits.length == 3 ? splits[1] : null + } + + String getVersion() { + String[] splits = remotePath.split(":") + return splits.length == 3 ? splits[2] : null + } + + @Override + String toString() { + return "ModuleConfig { isApply = ${getFlag(isApply)}" + + ", dep = " + dep + + " }" + } + + static String getFlag(boolean b) { + return b ? "✅" : "❌" + } +} + diff --git a/buildSrc/src/main/groovy/PluginConfig.groovy b/buildSrc/src/main/groovy/PluginConfig.groovy new file mode 100644 index 0000000000..3811c6a0ca --- /dev/null +++ b/buildSrc/src/main/groovy/PluginConfig.groovy @@ -0,0 +1,35 @@ +final class PluginConfig { + + boolean isApply = true // 是否应用 + boolean useLocal // 是否使用本地的 + String path // 插件路径 + String id // 插件 ID + + String getGroupId() { + String[] splits = path.split(":") + return splits.length == 3 ? splits[0] : null + } + + String getArtifactId() { + String[] splits = path.split(":") + return splits.length == 3 ? splits[1] : null + } + + String getVersion() { + String[] splits = path.split(":") + return splits.length == 3 ? splits[2] : null + } + + @Override + String toString() { + return "PluginConfig { isApply = ${getFlag(isApply)}" + + ", useLocal = ${getFlag(useLocal)}" + + ", path = " + path + + ", id = " + id + + " }" + } + + static String getFlag(boolean b) { + return b ? "✅" : "❌" + } +} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/ShellUtils.java b/buildSrc/src/main/groovy/ShellUtils.java deleted file mode 100644 index ef4917c68e..0000000000 --- a/buildSrc/src/main/groovy/ShellUtils.java +++ /dev/null @@ -1,228 +0,0 @@ -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.List; - -/** - *
- *     author: Blankj
- *     blog  : http://blankj.com
- *     time  : 2016/08/07
- *     desc  : utils about shell
- * 
- */ -public final class ShellUtils { - - private static final String LINE_SEP = System.getProperty("line.separator"); - - private ShellUtils() { - throw new UnsupportedOperationException("u can't instantiate me..."); - } - - /** - * Execute the command. - * - * @param command The command. - * @return the single {@link CommandResult} instance - */ - public static CommandResult execCmd(final String command) { - return execCmd(new String[]{command}, false, true); - } - - /** - * Execute the command. - * - * @param command The command. - * @param isRooted True to use root, false otherwise. - * @return the single {@link CommandResult} instance - */ - public static CommandResult execCmd(final String command, final boolean isRooted) { - return execCmd(new String[]{command}, isRooted, true); - } - - /** - * Execute the command. - * - * @param commands The commands. - * @return the single {@link CommandResult} instance - */ - public static CommandResult execCmd(final List commands) { - return execCmd(commands == null ? null : commands.toArray(new String[]{}), false, true); - } - - /** - * Execute the command. - * - * @param commands The commands. - * @param isRooted True to use root, false otherwise. - * @return the single {@link CommandResult} instance - */ - public static CommandResult execCmd(final List commands, final boolean isRooted) { - return execCmd(commands == null ? null : commands.toArray(new String[]{}), isRooted, true); - } - - /** - * Execute the command. - * - * @param commands The commands. - * @return the single {@link CommandResult} instance - */ - public static CommandResult execCmd(final String[] commands) { - return execCmd(commands, false, true); - } - - /** - * Execute the command. - * - * @param commands The commands. - * @param isRooted True to use root, false otherwise. - * @return the single {@link CommandResult} instance - */ - public static CommandResult execCmd(final String[] commands, final boolean isRooted) { - return execCmd(commands, isRooted, true); - } - - /** - * Execute the command. - * - * @param command The command. - * @param isRooted True to use root, false otherwise. - * @param isNeedResultMsg True to return the message of result, false otherwise. - * @return the single {@link CommandResult} instance - */ - public static CommandResult execCmd(final String command, - final boolean isRooted, - final boolean isNeedResultMsg) { - return execCmd(new String[]{command}, isRooted, isNeedResultMsg); - } - - /** - * Execute the command. - * - * @param commands The commands. - * @param isRooted True to use root, false otherwise. - * @param isNeedResultMsg True to return the message of result, false otherwise. - * @return the single {@link CommandResult} instance - */ - public static CommandResult execCmd(final List commands, - final boolean isRooted, - final boolean isNeedResultMsg) { - return execCmd(commands == null ? null : commands.toArray(new String[]{}), - isRooted, - isNeedResultMsg); - } - - /** - * Execute the command. - * - * @param commands The commands. - * @param isRooted True to use root, false otherwise. - * @param isNeedResultMsg True to return the message of result, false otherwise. - * @return the single {@link CommandResult} instance - */ - public static CommandResult execCmd(final String[] commands, - final boolean isRooted, - final boolean isNeedResultMsg) { - int result = -1; - if (commands == null || commands.length == 0) { - return new CommandResult(result, "", ""); - } - Process process = null; - BufferedReader successResult = null; - BufferedReader errorResult = null; - StringBuilder successMsg = null; - StringBuilder errorMsg = null; - DataOutputStream os = null; - try { - process = Runtime.getRuntime().exec(isRooted ? "su" : "sh"); - os = new DataOutputStream(process.getOutputStream()); - for (String command : commands) { - if (command == null) continue; - os.write(command.getBytes()); - os.writeBytes(LINE_SEP); - os.flush(); - } - os.writeBytes("exit" + LINE_SEP); - os.flush(); - result = process.waitFor(); - if (isNeedResultMsg) { - successMsg = new StringBuilder(); - errorMsg = new StringBuilder(); - successResult = new BufferedReader( - new InputStreamReader(process.getInputStream(), "UTF-8") - ); - errorResult = new BufferedReader( - new InputStreamReader(process.getErrorStream(), "UTF-8") - ); - String line; - if ((line = successResult.readLine()) != null) { - successMsg.append(line); - while ((line = successResult.readLine()) != null) { - successMsg.append(LINE_SEP).append(line); - } - } - if ((line = errorResult.readLine()) != null) { - errorMsg.append(line); - while ((line = errorResult.readLine()) != null) { - errorMsg.append(LINE_SEP).append(line); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - if (os != null) { - os.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - try { - if (successResult != null) { - successResult.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - try { - if (errorResult != null) { - errorResult.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - if (process != null) { - process.destroy(); - } - } - return new CommandResult( - result, - successMsg == null ? "" : successMsg.toString(), - errorMsg == null ? "" : errorMsg.toString() - ); - } - - /** - * The result of command. - */ - public static class CommandResult { - public int result; - public String successMsg; - public String errorMsg; - - public CommandResult(final int result, final String successMsg, final String errorMsg) { - this.result = result; - this.successMsg = successMsg; - this.errorMsg = errorMsg; - } - - @Override - public String toString() { - return "result: " + result + "\n" + - "successMsg: " + successMsg + "\n" + - "errorMsg: " + errorMsg; - } - } -} diff --git a/buildSrc/src/main/groovy/TaskDurationUtils.groovy b/buildSrc/src/main/groovy/TaskDurationUtils.groovy index 9ff2722345..6aacfcf30f 100644 --- a/buildSrc/src/main/groovy/TaskDurationUtils.groovy +++ b/buildSrc/src/main/groovy/TaskDurationUtils.groovy @@ -38,6 +38,11 @@ class TaskDurationUtils { } }) grd.addBuildListener(new BuildListener() { + @Override + void beforeSettings(Settings settings) { + super.beforeSettings(settings) + } + @Override void buildStarted(Gradle gradle) {} diff --git a/config.json b/config.json deleted file mode 100644 index aa55557a6a..0000000000 --- a/config.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "appConfigDesc": "appConfig 配置的是可以跑 app 的模块,git 提交务必只包含 launcher", - "appConfig": ["launcher"], - "pkgConfigDesc": "pkgConfig 配置的是要依赖的功能包,为空则依赖全部,git 提交务必为空", - "pkgConfig": [], - "proConfigDesc": "proConfig 配置的是使用本地还是仓库,优先级低于 appConfig 和 pkgConfig", - "proConfig": [ - {"isApply": true, "useLocal": true, "localPath": ":plugin:api-gradle-plugin"}, - {"isApply": true, "useLocal": true, "localPath": ":plugin:bus-gradle-plugin"}, - {"isApply": true, "useLocal": false, "localPath": ":plugin:lib:base-transform", "remotePath": "com.blankj:base-transform:1.0"}, - {"isApply": true, "useLocal": true, "localPath": ":feature:mock"}, - {"isApply": true, "useLocal": true, "localPath": ":feature:launcher:app"}, - {"isApply": true, "useLocal": true, "localPath": ":feature:main:app"}, - {"isApply": true, "useLocal": true, "localPath": ":feature:main:pkg"}, - {"isApply": true, "useLocal": true, "localPath": ":feature:subutil:app"}, - {"isApply": true, "useLocal": true, "localPath": ":feature:subutil:pkg"}, - {"isApply": true, "useLocal": true, "localPath": ":feature:subutil:export"}, - {"isApply": true, "useLocal": true, "localPath": ":feature:utilcode:app"}, - {"isApply": true, "useLocal": true, "localPath": ":feature:utilcode:pkg"}, - {"isApply": true, "useLocal": true, "localPath": ":feature:utilcode:export", "remotePath": "com.blankj:utilcode-export:1.1"}, - {"isApply": true, "useLocal": true, "localPath": ":lib:base"}, - {"isApply": true, "useLocal": true, "localPath": ":lib:common"}, - {"isApply": true, "useLocal": true, "localPath": ":lib:subutil"}, - {"isApply": true, "useLocal": true, "localPath": ":lib:utilcode", "remotePath": "com.blankj:utilcode:$versionName"}, - {"isApply": true, "useLocal": true, "localPath": ":lib:utildebug"}, - {"isApply": true, "useLocal": true, "localPath": ":lib:utildebug-no-op"} - ] -} diff --git a/config/flavor.gradle b/config/flavor.gradle new file mode 100644 index 0000000000..25c1801983 --- /dev/null +++ b/config/flavor.gradle @@ -0,0 +1,22 @@ +android { + flavorDimensions "env" + productFlavors { + dev { + dimension "env" + } + + production { + dimension "env" + } + } + + variantFilter { variant -> + def flavorNames = variant.flavors*.name + def buildTypeName = variant.buildType.name + + // production 包不允许 debug 构建 + if (flavorNames.contains("production") && buildTypeName.contains("debug")) { + variant.setIgnore(true) + } + } +} \ No newline at end of file diff --git a/config/publish.gradle b/config/publish.gradle new file mode 100644 index 0000000000..7608215123 --- /dev/null +++ b/config/publish.gradle @@ -0,0 +1,226 @@ +/* + 1. add + signing.keyId=xx + signing.password=xx + signing.secretKeyRingFile=/Users/xx/secring.gpg + ossrhUsername=xx + ossrhPassword=xx + in root local.properties + + 2. copy the file to the directory of gradle, and apply the file in the module + ext { + groupId = Config.modules.lib_utilcode.groupId + artifactId = Config.modules.lib_utilcode.artifactId + version = Config.modules.lib_utilcode.version + website = "https://github.com/Blankj/AndroidUtilCode" +} + apply from: "${rootDir.path}/config/publish.gradle" + + 3. execute following command to publish + ./gradlew :xxmodule:publish2Local -> upload to mavenLocal + ./gradlew :xxmodule:publish2Remote -> upload to mavenCentral +*/ + +apply plugin: 'maven-publish' +apply plugin: 'signing' + +ext.multiPublishMode = true + +File localPropertiesFile = project.rootProject.file("local.properties"); +if (!localPropertiesFile.exists()) { + return +} + +Properties properties = new Properties() +properties.load(new FileInputStream(localPropertiesFile)) +properties.each { name, value -> ext[name] = value } + +afterEvaluate { + def ext = project.ext + publishing { + publications { + release(MavenPublication) { + groupId ext.groupId + artifactId ext.artifactId + version ext.version + + if (isAndroidEnv(project)) { + if (project.ext.multiPublishMode) { + artifact("$buildDir/outputs/aar/${project.getName()}-release.aar") + artifact sourcesJar + } else { + from project.components.release + } + } else { + from project.components.java + } + + pom { + name = ext.artifactId + description = ext.artifactId + url = ext.website + + licenses { + license { + name = 'The Apache Software License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + developers { + developer { + id = ext.ossrhUsername + name = ext.ossrhUsername + } + } + scm { + url = ext.website + connection = ext.website + developerConnection = ext.website + ".git" + } + + if (project.ext.multiPublishMode) { + withXml { + def dependenciesNode = asNode().getAt('dependencies')[0] ?: + asNode().appendNode('dependencies') + + configurations.api.getDependencies().each { + dep -> addDependency(project, dependenciesNode, dep, "compile") + } + configurations.implementation.getDependencies().each { + dep -> addDependency(project, dependenciesNode, dep, "runtime") + } + } + } + } + } + } + + repositories { + maven { + // s01 is newest + def releasesUrl = "https://s01.oss.sonatype.org/content/repositories/releases/" + def snapshotUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" + url = version.toUpperCase().endsWith('SNAPSHOT') ? snapshotUrl : releasesUrl + + credentials { + username ossrhUsername + password ossrhPassword + } + } + } + } + + signing { + sign publishing.publications + } +} + +private void addDependency(Project project, def dependenciesNode, Dependency dep, String scope) { + if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified") { + return + } + + final dependencyNode = dependenciesNode.appendNode('dependency') + dependencyNode.appendNode('scope', scope) + + if (dep.version == 'unspecified') { + // 检测 module 中的 dependencies 是否有源码依赖 + // 如果是源码依赖,而且没有在 config 中配置 remotePath, + // 那么发布到仓库,其他地方依赖该库时会找不到源码的那个库 + println "publish -> module(unspecified) <${dep.group}:${dep.name}:${dep.version}>" + if (project.ext.groupId || project.ext.version) { + throw new GradleException("The module of <" + dep.name + "> should set groupId & version.") + } + // 源码依赖,但配置了 remotePath,让 pom 中写入 remotePath + println("publish -> module(wrapped) <${project.ext.groupId}:${name}:${project.ext.version}>") + + dependencyNode.appendNode('groupId', project.ext.pomGroupID) + dependencyNode.appendNode('artifactId', dep.name) + dependencyNode.appendNode('version', project.ext.pomVersion) + } else { + dependencyNode.appendNode('groupId', dep.group) + dependencyNode.appendNode('artifactId', dep.name) + dependencyNode.appendNode('version', dep.version) + println("publish -> library <${dep.group}:${dep.name}:${dep.version}>") + } + + if (!dep.transitive) { + // In case of non transitive dependency, + // all its dependencies should be force excluded from them POM file + final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion') + exclusionNode.appendNode('groupId', '*') + exclusionNode.appendNode('artifactId', '*') + } else if (!dep.properties.excludeRules.empty) { + // For transitive with exclusions, all exclude rules should be added to the POM file + final exclusions = dependencyNode.appendNode('exclusions') + dep.properties.excludeRules.each { ExcludeRule rule -> + final exclusionNode = exclusions.appendNode('exclusion') + exclusionNode.appendNode('groupId', rule.group ?: '*') + exclusionNode.appendNode('artifactId', rule.module ?: '*') + } + } +} + +if (isAndroidEnv(project)) { + // This generates sources.jar + task sourcesJar(type: Jar) { + classifier = 'sources' + from android.sourceSets.main.java.source + } + + task javadoc(type: Javadoc) { + source = android.sourceSets.main.java.source + classpath += configurations.compile + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + } + + task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir + } +} else { + task sourcesJar(type: Jar, dependsOn: classes) { + classifier = 'sources' + from sourceSets.main.allSource + } + + task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir + } +} + +if (project.hasProperty("kotlin")) { + // Disable creating javadocs + project.tasks.withType(Javadoc) { + enabled = false + } +} + +javadoc { + options { + encoding "UTF-8" + charSet 'UTF-8' + author true + version project.ext.version + links "http://docs.oracle.com/javase/7/docs/api" + title "${project.ext.artifactId} ${project.ext.version}" + } +} + +artifacts { + archives javadocJar + archives sourcesJar +} + +static def isAndroidEnv(Project project) { + return project.getPlugins().hasPlugin('com.android.application') || project.getPlugins().hasPlugin('com.android.library') +} + +task publish2Local(type: GradleBuild) { + tasks = ['assemble', 'publishReleasePublicationToMavenLocal'] +} + +task publish2Remote(type: GradleBuild) { + tasks = ['assemble', 'publishReleasePublicationToMavenRepository'] +} \ No newline at end of file diff --git a/feature/launcher/app/build.gradle b/feature/launcher/app/build.gradle index 408db62a67..8f2b6d205d 100644 --- a/feature/launcher/app/build.gradle +++ b/feature/launcher/app/build.gradle @@ -1,5 +1,5 @@ apply plugin: 'kotlin-kapt' dependencies { - kapt Config.depConfig.eventbus_processor.dep + kapt Config.libs.eventbus_processor.path } \ No newline at end of file diff --git a/feature/launcher/app/src/main/AndroidManifest.xml b/feature/launcher/app/src/main/AndroidManifest.xml index 19f6313965..4f033c06a6 100644 --- a/feature/launcher/app/src/main/AndroidManifest.xml +++ b/feature/launcher/app/src/main/AndroidManifest.xml @@ -7,6 +7,7 @@ android:allowBackup="false" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" + android:supportsRtl="true" android:theme="@style/AppTheme"> >( CommonItemClick(R.string.core_util, true) { - ApiUtils.getApi(UtilCodeApi::class.java).startUtilCodeActivity(this) + ApiUtils.getApi(UtilCodeApi::class.java)?.startUtilCodeActivity(this) }, CommonItemClick(R.string.sub_util, true) { - ApiUtils.getApi(SubUtilApi::class.java).startSubUtilActivity(this) + ApiUtils.getApi(SubUtilApi::class.java)?.startSubUtilActivity(this) } )) diff --git a/feature/main/pkg/src/main/res/layout/activity_main.xml b/feature/main/pkg/src/main/res/layout/activity_main.xml index a78e6dab8b..3a33dd0f8e 100644 --- a/feature/main/pkg/src/main/res/layout/activity_main.xml +++ b/feature/main/pkg/src/main/res/layout/activity_main.xml @@ -1,16 +1,16 @@ - - - - - - + + - - + diff --git a/feature/subutil/pkg/src/main/res/values/strings.xml b/feature/subutil/pkg/src/main/res/values/strings.xml index 4654e85f06..e758c294a0 100644 --- a/feature/subutil/pkg/src/main/res/values/strings.xml +++ b/feature/subutil/pkg/src/main/res/values/strings.xml @@ -24,4 +24,6 @@ Reboot To Bootloader Send SMS Silent Mobile Data Enabled + + \ No newline at end of file diff --git a/feature/utilcode/export/build.gradle b/feature/utilcode/export/build.gradle index cecc254461..30e59272ee 100644 --- a/feature/utilcode/export/build.gradle +++ b/feature/utilcode/export/build.gradle @@ -1,10 +1,8 @@ -apply from: "${rootDir.path}/gradle/publish.gradle" -publish { - def depConfig = Config.depConfig.feature_utilcode_export - name = "UtilCodeExport" - groupId = depConfig.groupId - artifactId = depConfig.artifactId - version = depConfig.version - website = "https://github.com/Blankj/UtilCodeExport" +ext { + groupId = Config.modules.feature_utilcode_export.groupId + artifactId = Config.modules.feature_utilcode_export.artifactId + version = Config.modules.feature_utilcode_export.version + website = "https://github.com/Blankj/AndroidUtilCode" } +//apply from: "${rootDir.path}/config/publish.gradle" //./gradlew :feature_utilcode_export:mavenLocal // 上传到本地 mavenLocal \ No newline at end of file diff --git a/feature/utilcode/pkg/src/main/AndroidManifest.xml b/feature/utilcode/pkg/src/main/AndroidManifest.xml index f77ad3d953..8da0667a23 100644 --- a/feature/utilcode/pkg/src/main/AndroidManifest.xml +++ b/feature/utilcode/pkg/src/main/AndroidManifest.xml @@ -18,6 +18,7 @@ + diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/activity/ActivityActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/activity/ActivityActivity.kt index 63d2ac5bd8..97023b94c2 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/activity/ActivityActivity.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/activity/ActivityActivity.kt @@ -4,8 +4,8 @@ import android.content.Context import android.content.Intent import android.graphics.drawable.BitmapDrawable import android.os.Bundle -import android.support.v4.app.ActivityOptionsCompat import android.widget.ImageView +import androidx.core.app.ActivityOptionsCompat import com.blankj.base.rv.ItemViewHolder import com.blankj.common.activity.CommonActivity import com.blankj.common.item.CommonItem diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/activity/SubActivityActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/activity/SubActivityActivity.kt index 9c972d6234..3505709cd2 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/activity/SubActivityActivity.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/activity/SubActivityActivity.kt @@ -3,7 +3,7 @@ package com.blankj.utilcode.pkg.feature.activity import android.app.Activity import android.content.Intent import android.os.Bundle -import android.support.v4.app.ActivityCompat +import androidx.core.app.ActivityCompat import android.view.View import com.blankj.common.activity.CommonActivity import com.blankj.utilcode.pkg.R diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/api/ApiActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/api/ApiActivity.kt index 0857ceaeac..8e11495b09 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/api/ApiActivity.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/api/ApiActivity.kt @@ -35,10 +35,10 @@ class ApiActivity : CommonActivity() { override fun bindItems(): MutableList> { return CollectionUtils.newArrayList( CommonItemClick(R.string.api_invoke_with_params) { - ApiUtils.getApi(OtherModuleApi::class.java).invokeWithParams(OtherModuleApi.ApiBean("params")) + ApiUtils.getApi(OtherModuleApi::class.java)?.invokeWithParams(OtherModuleApi.ApiBean("params")) }, CommonItemClick(R.string.api_invoke_with_return_value) { - ToastUtils.showShort(ApiUtils.getApi(OtherModuleApi::class.java).invokeWithReturnValue().name) + ToastUtils.showShort(ApiUtils.getApi(OtherModuleApi::class.java)?.invokeWithReturnValue()?.name) } ); } diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/app/AppActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/app/AppActivity.kt index 5499f78eb7..21eb351146 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/app/AppActivity.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/app/AppActivity.kt @@ -54,7 +54,10 @@ class AppActivity : CommonActivity(), Utils.OnAppStatusChangedListener { override fun bindItems(): MutableList> { return CollectionUtils.newArrayList( - CommonItemSwitch("registerAppStatusChangedListener", { isRegisterAppStatusChangedListener }, { + CommonItemSwitch( + "registerAppStatusChangedListener", + { isRegisterAppStatusChangedListener }, + { isRegisterAppStatusChangedListener = it if (it) { AppUtils.registerAppStatusChangedListener(this) @@ -62,55 +65,63 @@ class AppActivity : CommonActivity(), Utils.OnAppStatusChangedListener { AppUtils.unregisterAppStatusChangedListener(this) } }), - CommonItemTitle("isAppRoot", AppUtils.isAppRoot().toString()), - CommonItemTitle("isAppDebug", AppUtils.isAppDebug().toString()), - CommonItemTitle("isAppSystem", AppUtils.isAppSystem().toString()), - CommonItemTitle("isAppForeground", AppUtils.isAppForeground(AppUtils.getAppPackageName()).toString()), - CommonItemTitle("isAppRunning", AppUtils.isAppRunning(AppUtils.getAppPackageName()).toString()), - CommonItemImage("getAppIcon") { - it.setImageDrawable(AppUtils.getAppIcon()) - }, - CommonItemTitle("getAppPackageName", AppUtils.getAppPackageName()), - CommonItemTitle("getAppName", AppUtils.getAppName()), - CommonItemTitle("getAppPath", AppUtils.getAppPath()), - CommonItemTitle("getAppVersionName", AppUtils.getAppVersionName()), - CommonItemTitle("getAppVersionCode", AppUtils.getAppVersionCode().toString()), - CommonItemTitle("getAppSignatureSHA1", AppUtils.getAppSignatureSHA1()), - CommonItemTitle("getAppSignatureSHA256", AppUtils.getAppSignatureSHA256()), - CommonItemTitle("getAppSignatureMD5", AppUtils.getAppSignatureMD5()), - CommonItemTitle("getAppUid", AppUtils.getAppUid().toString()), - CommonItemTitle("getApkInfo", AppUtils.getApkInfo(AppUtils.getAppPath()).toString()), - - CommonItemClick(R.string.app_install) { - if (AppUtils.isAppInstalled(Config.TEST_PKG)) { - ToastUtils.showShort(R.string.app_install_tips) + CommonItemTitle("isAppRoot", AppUtils.isAppRoot().toString()), + CommonItemTitle("isAppDebug", AppUtils.isAppDebug().toString()), + CommonItemTitle("isAppSystem", AppUtils.isAppSystem().toString()), + CommonItemTitle( + "isAppForeground", + AppUtils.isAppForeground(AppUtils.getAppPackageName()).toString() + ), + CommonItemTitle( + "isAppRunning", + AppUtils.isAppRunning(AppUtils.getAppPackageName()).toString() + ), + CommonItemImage("getAppIcon") { + it.setImageDrawable(AppUtils.getAppIcon()) + }, + CommonItemTitle("getAppPackageName", AppUtils.getAppPackageName()), + CommonItemTitle("getAppName", AppUtils.getAppName()), + CommonItemTitle("getAppPath", AppUtils.getAppPath()), + CommonItemTitle("getAppVersionName", AppUtils.getAppVersionName()), + CommonItemTitle("getAppVersionCode", AppUtils.getAppVersionCode().toString()), + CommonItemTitle("getAppMinSdkVersion", AppUtils.getAppMinSdkVersion().toString()), + CommonItemTitle("getAppTargetSdkVersion", AppUtils.getAppTargetSdkVersion().toString()), + CommonItemTitle("getAppSignaturesSHA1", AppUtils.getAppSignaturesSHA1().toString()), + CommonItemTitle("getAppSignaturesSHA256", AppUtils.getAppSignaturesSHA256().toString()), + CommonItemTitle("getAppSignaturesMD5", AppUtils.getAppSignaturesMD5().toString()), + CommonItemTitle("getAppUid", AppUtils.getAppUid().toString()), + CommonItemTitle("getApkInfo", AppUtils.getApkInfo(AppUtils.getAppPath()).toString()), + + CommonItemClick(R.string.app_install) { + if (AppUtils.isAppInstalled(Config.TEST_PKG)) { + ToastUtils.showShort(R.string.app_install_tips) + } else { + if (!FileUtils.isFileExists(Config.TEST_APK_PATH)) { + ReleaseInstallApkTask(listener).execute() } else { - if (!FileUtils.isFileExists(Config.TEST_APK_PATH)) { - ReleaseInstallApkTask(listener).execute() - } else { - listener.onReleased() - } + listener.onReleased() } - }, - CommonItemClick(R.string.app_uninstall) { - if (AppUtils.isAppInstalled(Config.TEST_PKG)) { - AppUtils.uninstallApp(Config.TEST_PKG) - } else { - ToastUtils.showShort(R.string.app_uninstall_tips) - } - }, - CommonItemClick(R.string.app_launch) { - AppUtils.launchApp(this.packageName) - }, - CommonItemClick(R.string.app_relaunch) { - AppUtils.relaunchApp() - }, - CommonItemClick(R.string.app_launch_details_settings, true) { - AppUtils.launchAppDetailsSettings() - }, - CommonItemClick(R.string.app_exit) { - AppUtils.exitApp() } + }, + CommonItemClick(R.string.app_uninstall) { + if (AppUtils.isAppInstalled(Config.TEST_PKG)) { + AppUtils.uninstallApp(Config.TEST_PKG) + } else { + ToastUtils.showShort(R.string.app_uninstall_tips) + } + }, + CommonItemClick(R.string.app_launch) { + AppUtils.launchApp(this.packageName) + }, + CommonItemClick(R.string.app_relaunch) { + AppUtils.relaunchApp() + }, + CommonItemClick(R.string.app_launch_details_settings, true) { + AppUtils.launchAppDetailsSettings() + }, + CommonItemClick(R.string.app_exit) { + AppUtils.exitApp() + } ) } @@ -130,7 +141,8 @@ class AppActivity : CommonActivity(), Utils.OnAppStatusChangedListener { } } -class ReleaseInstallApkTask(private val mListener: OnReleasedListener) : ThreadUtils.SimpleTask() { +class ReleaseInstallApkTask(private val mListener: OnReleasedListener) : + ThreadUtils.SimpleTask() { override fun doInBackground() { ResourceUtils.copyFileFromAssets("test_install", Config.TEST_APK_PATH) diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/bar/nav/BarNavActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/bar/nav/BarNavActivity.kt index 1b3032974f..48a738ecd7 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/bar/nav/BarNavActivity.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/bar/nav/BarNavActivity.kt @@ -12,7 +12,6 @@ import com.blankj.utilcode.pkg.R import com.blankj.utilcode.util.BarUtils import com.blankj.utilcode.util.CollectionUtils import com.blankj.utilcode.util.ColorUtils -import com.blankj.utilcode.util.Utils /** * ``` @@ -41,24 +40,43 @@ class BarNavActivity : CommonActivity() { add(CommonItemTitle("isSupportNavBar", BarUtils.isSupportNavBar().toString())) if (BarUtils.isSupportNavBar()) { add(CommonItemSwitch( - R.string.bar_nav_visibility, - { BarUtils.isNavBarVisible(this@BarNavActivity) }, - { BarUtils.setNavBarVisibility(this@BarNavActivity, it) } + R.string.bar_nav_visibility, + { BarUtils.isNavBarVisible(this@BarNavActivity) }, + { BarUtils.setNavBarVisibility(this@BarNavActivity, it) } )) add(CommonItemSwitch( - R.string.bar_nav_light_mode, - { BarUtils.isNavBarLightMode(this@BarNavActivity) }, - { BarUtils.setNavBarLightMode(this@BarNavActivity, it) } + R.string.bar_nav_light_mode, + { BarUtils.isNavBarLightMode(this@BarNavActivity) }, + { BarUtils.setNavBarLightMode(this@BarNavActivity, it) } )) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - add(CommonItemClick("getNavBarColor: ${ColorUtils.int2ArgbString(BarUtils.getNavBarColor(this@BarNavActivity))}").setOnItemClickListener() { _, item, _ -> - BarUtils.setNavBarColor(this@BarNavActivity, ColorUtils.getRandomColor()) - itemsView.updateItems(bindItems()) - item.title = "getNavBarColor: ${ColorUtils.int2ArgbString(BarUtils.getNavBarColor(this@BarNavActivity))}" - }) + add( + CommonItemClick( + "getNavBarColor: ${ + ColorUtils.int2ArgbString( + BarUtils.getNavBarColor( + this@BarNavActivity + ) + ) + }" + ).setOnItemClickListener() { _, item, _ -> + BarUtils.setNavBarColor( + this@BarNavActivity, + ColorUtils.getRandomColor() + ) + itemsView.updateItems(bindItems()) + item.title = "getNavBarColor: ${ + ColorUtils.int2ArgbString( + BarUtils.getNavBarColor(this@BarNavActivity) + ) + }" + }) } + add(CommonItemClick("transparentNavBar").setOnItemClickListener() { _, item, _ -> + BarUtils.transparentNavBar(this@BarNavActivity) + }) } } } diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/bar/status/fragment/BarStatusFragmentActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/bar/status/fragment/BarStatusFragmentActivity.kt index d504987c93..6df145b5be 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/bar/status/fragment/BarStatusFragmentActivity.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/bar/status/fragment/BarStatusFragmentActivity.kt @@ -3,13 +3,13 @@ package com.blankj.utilcode.pkg.feature.bar.status.fragment import android.content.Context import android.content.Intent import android.os.Bundle -import android.support.design.widget.BottomNavigationView -import android.support.v4.app.Fragment -import android.support.v4.app.FragmentPagerAdapter -import android.support.v4.view.ViewPager import android.view.View +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentPagerAdapter +import androidx.viewpager.widget.ViewPager import com.blankj.common.activity.CommonActivity import com.blankj.utilcode.pkg.R +import com.google.android.material.bottomnavigation.BottomNavigationView import kotlinx.android.synthetic.main.bar_status_fragment_activity.* import java.util.* @@ -37,7 +37,7 @@ class BarStatusFragmentActivity : CommonActivity() { R.id.barStatusFragmentNavigationCustom ) - private val mFragmentList = ArrayList() + private val mFragmentList = ArrayList() private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener l@{ item -> when (item.itemId) { diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/bus/BusActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/bus/BusActivity.kt index 4343463169..9bd7c870d0 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/bus/BusActivity.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/bus/BusActivity.kt @@ -2,7 +2,7 @@ package com.blankj.utilcode.pkg.feature.bus import android.content.Context import android.content.Intent -import android.support.annotation.Keep +import androidx.annotation.Keep import com.blankj.common.activity.CommonActivity import com.blankj.common.item.CommonItem import com.blankj.common.item.CommonItemClick diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/clean/CleanActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/clean/CleanActivity.kt index 7185cc33cb..f0b8620eca 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/clean/CleanActivity.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/clean/CleanActivity.kt @@ -3,8 +3,6 @@ package com.blankj.utilcode.pkg.feature.clean import android.content.Context import android.content.Intent import com.blankj.common.activity.CommonActivity -import com.blankj.common.activity.CommonActivityItemsView -import com.blankj.common.activity.CommonActivityTitleView import com.blankj.common.item.CommonItem import com.blankj.common.item.CommonItemClick import com.blankj.utilcode.pkg.R @@ -54,6 +52,11 @@ class CleanActivity : CommonActivity() { showSnackbar(CleanUtils.cleanExternalCache(), externalCacheDir?.absolutePath) }) } + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { + add(CommonItemClick(R.string.clean_app_user_data) { + CleanUtils.cleanAppUserData() + }) + } } } diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/click/ClickActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/click/ClickActivity.kt index 788ee59061..7a6a112c15 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/click/ClickActivity.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/click/ClickActivity.kt @@ -2,9 +2,9 @@ package com.blankj.utilcode.pkg.feature.click import android.content.Context import android.content.Intent -import android.support.annotation.StringRes import android.view.View import android.widget.TextView +import androidx.annotation.StringRes import com.blankj.base.rv.ItemViewHolder import com.blankj.common.activity.CommonActivity import com.blankj.common.item.CommonItem diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/device/DeviceActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/device/DeviceActivity.kt index 1df423ded3..d70fe14e93 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/device/DeviceActivity.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/device/DeviceActivity.kt @@ -46,6 +46,9 @@ class DeviceActivity : CommonActivity() { add(CommonItemTitle("getABIs", Arrays.asList(*DeviceUtils.getABIs()).toString())) add(CommonItemTitle("isTablet", DeviceUtils.isTablet().toString())) add(CommonItemTitle("isEmulator", DeviceUtils.isEmulator().toString())) + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { + add(CommonItemTitle("isDevelopmentSettingsEnabled", DeviceUtils.isDevelopmentSettingsEnabled().toString())) + } add(CommonItemTitle("getUniqueDeviceId", DeviceUtils.getUniqueDeviceId("util"))) add(CommonItemTitle("isSameDevice", DeviceUtils.isSameDevice(DeviceUtils.getUniqueDeviceId()).toString())) } diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/fragment/ChildFragment.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/fragment/ChildFragment.kt index c7c2e5fd0a..a4b1450de5 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/fragment/ChildFragment.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/fragment/ChildFragment.kt @@ -1,8 +1,8 @@ package com.blankj.utilcode.pkg.feature.fragment import android.os.Bundle -import android.support.v4.app.FragmentManager import android.view.View +import androidx.fragment.app.FragmentManager import com.blankj.common.fragment.CommonFragment import com.blankj.common.item.CommonItem import com.blankj.common.item.CommonItemClick diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/fragment/ContainerFragment.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/fragment/ContainerFragment.kt index 3e57295596..e21eb521fb 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/fragment/ContainerFragment.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/fragment/ContainerFragment.kt @@ -2,12 +2,11 @@ package com.blankj.utilcode.pkg.feature.fragment import android.os.Build import android.os.Bundle -import android.support.annotation.RequiresApi -import android.support.v4.app.Fragment -import android.support.v4.app.FragmentManager import android.transition.* import android.view.View import android.widget.ImageView +import androidx.annotation.RequiresApi +import androidx.fragment.app.FragmentManager import com.blankj.base.rv.ItemViewHolder import com.blankj.common.fragment.CommonFragment import com.blankj.common.item.CommonItem @@ -15,7 +14,6 @@ import com.blankj.common.item.CommonItemClick import com.blankj.utilcode.pkg.R import com.blankj.utilcode.pkg.helper.DialogHelper import com.blankj.utilcode.util.* -import kotlinx.android.synthetic.main.fragment_container.* import java.util.* /** @@ -145,7 +143,7 @@ class ContainerFragment : CommonFragment(), FragmentUtils.OnBackClickListener { } } - private fun addSharedElement(fragment: Fragment): Fragment { + private fun addSharedElement(fragment: androidx.fragment.app.Fragment): androidx.fragment.app.Fragment { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { fragment.sharedElementEnterTransition = DetailTransition() fragment.enterTransition = Fade() diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/fragment/FragmentActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/fragment/FragmentActivity.kt index 99b6355629..5b337e48d5 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/fragment/FragmentActivity.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/fragment/FragmentActivity.kt @@ -4,8 +4,8 @@ import android.content.Context import android.content.Intent import android.os.Bundle import android.os.PersistableBundle -import android.support.design.widget.BottomNavigationView -import android.support.v4.app.Fragment +import com.google.android.material.bottomnavigation.BottomNavigationView +import androidx.fragment.app.Fragment import android.view.View import com.blankj.common.activity.CommonActivity import com.blankj.utilcode.pkg.R @@ -29,7 +29,7 @@ class FragmentActivity : CommonActivity() { } } - private val mFragments = arrayListOf() + private val mFragments = arrayListOf() private var curIndex: Int = 0 private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item -> diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/keyboard/KeyboardActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/keyboard/KeyboardActivity.kt index b94f66876f..5ed25ae4fe 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/keyboard/KeyboardActivity.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/keyboard/KeyboardActivity.kt @@ -10,8 +10,7 @@ import com.blankj.common.item.CommonItemClick import com.blankj.common.item.CommonItemTitle import com.blankj.utilcode.pkg.R import com.blankj.utilcode.pkg.helper.DialogHelper -import com.blankj.utilcode.util.CollectionUtils -import com.blankj.utilcode.util.KeyboardUtils +import com.blankj.utilcode.util.* import kotlinx.android.synthetic.main.keyboard_activity.* /** diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/language/LanguageActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/language/LanguageActivity.kt index 0e14482b91..c928da21fa 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/language/LanguageActivity.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/language/LanguageActivity.kt @@ -60,6 +60,9 @@ class LanguageActivity : CommonActivity() { CommonItemClick(R.string.language_apply_english) { LanguageUtils.applyLanguage(Locale.ENGLISH, isRelaunchApp()) }, + CommonItemClick(R.string.language_apply_arabic) { + LanguageUtils.applyLanguage(Locale("ar"), isRelaunchApp()) + }, CommonItemClick(R.string.language_apply_system) { LanguageUtils.applySystemLanguage(isRelaunchApp()) } diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpActivity.java b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpActivity.java index 813431f6f8..7fff29f4a7 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpActivity.java +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpActivity.java @@ -1,16 +1,15 @@ package com.blankj.utilcode.pkg.feature.mvp; -import android.arch.lifecycle.ViewModel; -import android.arch.lifecycle.ViewModelProvider; import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.View; import com.blankj.common.activity.CommonActivity; import com.blankj.utilcode.pkg.R; +import androidx.annotation.Nullable; + /** *
  *     author: blankj
diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpModel.java b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpModel.java
index 8697f11c1d..e16b4f1934 100644
--- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpModel.java
+++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpModel.java
@@ -12,7 +12,7 @@
  *     desc  :
  * 
*/ -public class MvpModel extends BaseModel implements IMvp.Model { +public class MvpModel extends BaseModel implements MvpMvp.Model { private int index; diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/IMvp.java b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpMvp.java similarity index 94% rename from feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/IMvp.java rename to feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpMvp.java index 4e8edc023e..d0335ef203 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/IMvp.java +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpMvp.java @@ -10,7 +10,7 @@ * desc : * */ -public interface IMvp { +public interface MvpMvp { interface View { void setLoadingVisible(boolean visible); diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpPresenter.java b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpPresenter.java index 01990aa3af..fcb68bd3ed 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpPresenter.java +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpPresenter.java @@ -13,7 +13,7 @@ * */ public class MvpPresenter extends BasePresenter - implements IMvp.Presenter { + implements MvpMvp.Presenter { @Override public void onBindView() { diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpView.java b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpView.java index 054cd7ade9..e916398e48 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpView.java +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpView.java @@ -6,7 +6,6 @@ import com.blankj.base.mvp.BaseView; import com.blankj.utilcode.pkg.R; -import com.blankj.utilcode.pkg.feature.fragment.FragmentActivity; import com.blankj.utilcode.util.ClickUtils; import com.blankj.utilcode.util.LogUtils; import com.blankj.utilcode.util.SizeUtils; @@ -22,7 +21,7 @@ * */ public class MvpView extends BaseView - implements IMvp.View { + implements MvpMvp.View { private TextView mvpTv; private TextView mvpMeasureWidthTv; diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/network/NetworkActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/network/NetworkActivity.kt index f0c9962b2d..452040376d 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/network/NetworkActivity.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/network/NetworkActivity.kt @@ -2,13 +2,17 @@ package com.blankj.utilcode.pkg.feature.network import android.content.Context import android.content.Intent +import android.net.wifi.ScanResult +import android.net.wifi.WifiManager import android.os.Bundle import android.view.View import com.blankj.common.activity.CommonActivity +import com.blankj.common.helper.PermissionHelper import com.blankj.common.item.CommonItem import com.blankj.common.item.CommonItemClick import com.blankj.common.item.CommonItemSwitch import com.blankj.common.item.CommonItemTitle +import com.blankj.utilcode.constant.PermissionConstants import com.blankj.utilcode.pkg.R import com.blankj.utilcode.util.* @@ -24,12 +28,24 @@ class NetworkActivity : CommonActivity(), NetworkUtils.OnNetworkStatusChangedLis companion object { fun start(context: Context) { - val starter = Intent(context, NetworkActivity::class.java) - context.startActivity(starter) + PermissionHelper.request(context, object : PermissionUtils.SimpleCallback { + override fun onGranted() { + val starter = Intent(context, NetworkActivity::class.java) + context.startActivity(starter) + } + + override fun onDenied() { + } + }, PermissionConstants.LOCATION) } } private lateinit var itemsTask: ThreadUtils.SimpleTask>> + private lateinit var wifiScanResultItem: CommonItemTitle + private val consumer = Utils.Consumer { t -> + wifiScanResultItem.setContent(scanResults2String(t.filterResults)) + wifiScanResultItem.update() + } override fun bindTitleRes(): Int { return R.string.demo_network @@ -51,6 +67,7 @@ class NetworkActivity : CommonActivity(), NetworkUtils.OnNetworkStatusChangedLis override fun bindItems(): List> { if (ThreadUtils.isMainThread()) return arrayListOf() + wifiScanResultItem = CommonItemTitle("getWifiScanResult", scanResults2String(NetworkUtils.getWifiScanResult().filterResults)) return CollectionUtils.newArrayList( CommonItemTitle("isConnected", NetworkUtils.isConnected().toString()), CommonItemTitle("getMobileDataEnabled", NetworkUtils.getMobileDataEnabled().toString()), @@ -72,10 +89,19 @@ class NetworkActivity : CommonActivity(), NetworkUtils.OnNetworkStatusChangedLis CommonItemTitle("isWifiAvailable", NetworkUtils.isWifiAvailable().toString()), CommonItemTitle("isAvailable", NetworkUtils.isAvailable().toString()), CommonItemTitle("getBaiduDomainAddress", NetworkUtils.getDomainAddress("baidu.com")), + wifiScanResultItem, CommonItemSwitch( R.string.network_wifi_enabled, - { NetworkUtils.getWifiEnabled() }, + { + val wifiEnabled = NetworkUtils.getWifiEnabled() + if (wifiEnabled) { + NetworkUtils.addOnWifiChangedConsumer(consumer) + } else { + NetworkUtils.removeOnWifiChangedConsumer(consumer) + } + wifiEnabled + }, { NetworkUtils.setWifiEnabled(it) ThreadUtils.executeByIo(getItemsTask()) @@ -112,5 +138,14 @@ class NetworkActivity : CommonActivity(), NetworkUtils.OnNetworkStatusChangedLis super.onDestroy() ThreadUtils.cancel(itemsTask) NetworkUtils.unregisterNetworkStatusChangedListener(this) + NetworkUtils.removeOnWifiChangedConsumer(consumer) + } + + private fun scanResults2String(results: List): String { + val sb: StringBuilder = StringBuilder() + for (result in results) { + sb.append(String.format("${result.SSID}, Level: ${WifiManager.calculateSignalLevel(result.level, 4)}\n")) + } + return sb.toString() } } diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/phone/PhoneActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/phone/PhoneActivity.kt index cb453b3b89..c9b748cdfa 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/phone/PhoneActivity.kt +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/phone/PhoneActivity.kt @@ -54,8 +54,8 @@ class PhoneActivity : CommonActivity() { CommonItemTitle("getSimOperatorName", PhoneUtils.getSimOperatorName()), CommonItemTitle("getSimOperatorByMnc", PhoneUtils.getSimOperatorByMnc()), - CommonItemClick(R.string.phone_dial) { PhoneUtils.dial("10000") }, - CommonItemClick(R.string.phone_call) { PhoneUtils.call("10000") }, + CommonItemClick(R.string.phone_dial) { PhoneUtils.dial("*10000#haha") }, + CommonItemClick(R.string.phone_call) { PhoneUtils.call("*10000#haha") }, CommonItemClick(R.string.phone_send_sms) { PhoneUtils.sendSms("10000", "sendSms") } ) } diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/reflect/TestPrivateStaticFinal.java b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/reflect/TestPrivateStaticFinal.java index e62c518699..b7efb5f4d7 100644 --- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/reflect/TestPrivateStaticFinal.java +++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/reflect/TestPrivateStaticFinal.java @@ -1,6 +1,6 @@ package com.blankj.utilcode.pkg.feature.reflect; -import android.support.annotation.Keep; +import androidx.annotation.Keep; /** *
diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/snackbar/SnackbarActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/snackbar/SnackbarActivity.kt
index 568caecff2..dcde367a5b 100644
--- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/snackbar/SnackbarActivity.kt
+++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/snackbar/SnackbarActivity.kt
@@ -3,10 +3,10 @@ package com.blankj.utilcode.pkg.feature.snackbar
 import android.content.Context
 import android.content.Intent
 import android.graphics.Color
-import android.support.annotation.StringRes
 import android.text.SpannableStringBuilder
 import android.view.ViewGroup
 import android.widget.TextView
+import androidx.annotation.StringRes
 import com.blankj.common.activity.CommonActivity
 import com.blankj.common.item.CommonItem
 import com.blankj.common.item.CommonItemClick
diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/span/SpanActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/span/SpanActivity.kt
index d43afd850f..84c9f868bb 100644
--- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/span/SpanActivity.kt
+++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/span/SpanActivity.kt
@@ -5,7 +5,6 @@ import android.content.Context
 import android.content.Intent
 import android.graphics.*
 import android.os.Bundle
-import android.support.annotation.ColorInt
 import android.text.Layout
 import android.text.SpannableStringBuilder
 import android.text.TextPaint
@@ -14,6 +13,7 @@ import android.text.style.ClickableSpan
 import android.text.style.UpdateAppearance
 import android.view.View
 import android.view.animation.LinearInterpolator
+import androidx.annotation.ColorInt
 import com.blankj.common.activity.CommonActivity
 import com.blankj.utilcode.pkg.R
 import com.blankj.utilcode.util.SpanUtils
diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/toast/CustomToast.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/toast/CustomToast.kt
index 384b1877ea..f0b6876ad4 100644
--- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/toast/CustomToast.kt
+++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/toast/CustomToast.kt
@@ -1,7 +1,7 @@
 package com.blankj.utilcode.pkg.feature.toast
 
-import android.support.annotation.StringRes
 import android.widget.TextView
+import androidx.annotation.StringRes
 import com.blankj.utilcode.pkg.R
 import com.blankj.utilcode.util.StringUtils
 import com.blankj.utilcode.util.ToastUtils
diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/toast/ToastActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/toast/ToastActivity.kt
index 5d55e3c754..f4267ad3a9 100644
--- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/toast/ToastActivity.kt
+++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/toast/ToastActivity.kt
@@ -4,6 +4,7 @@ import android.content.Context
 import android.content.Intent
 import android.graphics.Color
 import android.view.Gravity
+import androidx.core.content.ContextCompat
 import com.blankj.common.activity.CommonActivity
 import com.blankj.common.item.CommonItem
 import com.blankj.common.item.CommonItemClick
@@ -79,6 +80,9 @@ class ToastActivity : CommonActivity() {
                 CommonItemClick(R.string.toast_show_middle) {
                     ToastUtils.make().setGravity(Gravity.CENTER, 0, 0).show(R.string.toast_middle)
                 },
+                CommonItemClick(R.string.toast_show_top) {
+                    ToastUtils.make().setGravity(Gravity.TOP or Gravity.CENTER_HORIZONTAL, 0, 0).show(R.string.toast_top)
+                },
                 CommonItemClick(R.string.toast_show_custom_view) {
                     Thread(Runnable { CustomToast.showLong(R.string.toast_custom_view) }).start()
                 },
diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/vibrate/VibrateActivity.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/vibrate/VibrateActivity.kt
index d2cd9bc147..5dc337bc5b 100644
--- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/vibrate/VibrateActivity.kt
+++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/vibrate/VibrateActivity.kt
@@ -32,11 +32,23 @@ class VibrateActivity : CommonActivity() {
 
     override fun bindItems(): MutableList> {
         return CollectionUtils.newArrayList(
-                CommonItemClick(R.string.vibrate_1000ms) { VibrateUtils.vibrate(1000) },
+                CommonItemClick(R.string.vibrate_1000ms) {
+                    VibrateUtils.vibrate(1000)
+                },
                 CommonItemClick(R.string.vibrate_custom) {
                     VibrateUtils.vibrate(longArrayOf(0, 1000, 1000, 2000, 2000, 1000), 1)
                 },
-                CommonItemClick(R.string.vibrate_cancel) { VibrateUtils.cancel() }
+                CommonItemClick(R.string.vibrate_background) {
+                    backHome()
+                    mContentView.postDelayed({
+//                        VibrateUtils.vibrate(1000) -- can not vibrate in background
+                        VibrateUtils.vibrateCompat(longArrayOf(0, 1000, 1000, 2000, 2000, 1000), 1)
+//                        VibrateUtils.vibrateCompat(1000)
+                    }, 1000)
+                },
+                CommonItemClick(R.string.vibrate_cancel) {
+                    VibrateUtils.cancel()
+                }
         )
     }
 
@@ -44,4 +56,11 @@ class VibrateActivity : CommonActivity() {
         super.onDestroy()
         VibrateUtils.cancel()
     }
+
+    private fun backHome() {
+        val intent = Intent(Intent.ACTION_MAIN).apply {
+            addCategory(Intent.CATEGORY_HOME)
+        }
+        startActivity(intent)
+    }
 }
diff --git a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/helper/DialogHelper.kt b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/helper/DialogHelper.kt
index 6643ec7806..7d38fda3ca 100644
--- a/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/helper/DialogHelper.kt
+++ b/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/helper/DialogHelper.kt
@@ -4,7 +4,6 @@ import android.content.Context
 import android.content.DialogInterface
 import android.graphics.Bitmap
 import android.graphics.drawable.ColorDrawable
-import android.support.v4.app.FragmentActivity
 import android.text.method.ScrollingMovementMethod
 import android.view.Gravity
 import android.view.View
@@ -13,6 +12,7 @@ import android.widget.Button
 import android.widget.EditText
 import android.widget.ImageView
 import android.widget.TextView
+import androidx.fragment.app.FragmentActivity
 import com.blankj.base.dialog.BaseDialogFragment
 import com.blankj.base.dialog.DialogLayoutCallback
 import com.blankj.utilcode.pkg.R
@@ -155,4 +155,4 @@ object DialogHelper {
             override fun onDismiss(dialog: BaseDialogFragment) {}
         }).show()
     }
-}
+}
\ No newline at end of file
diff --git a/feature/utilcode/pkg/src/main/res/layout/activity_adaptscreen.xml b/feature/utilcode/pkg/src/main/res/layout/activity_adaptscreen.xml
new file mode 100644
index 0000000000..278fe8c2c6
--- /dev/null
+++ b/feature/utilcode/pkg/src/main/res/layout/activity_adaptscreen.xml
@@ -0,0 +1,34 @@
+
+
+
+