diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..852773f --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties +.idea +/.idea +aar-publish +/aar-publish \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c79b8ce --- /dev/null +++ b/README.md @@ -0,0 +1,108 @@ +# IconPackManager +[![Maven Central](https://img.shields.io/maven-central/v/com.iamverycute/IconPackManager.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.iamverycute/IconPackManager/) ![API: 14+ (shields.io)](https://img.shields.io/badge/API-14+-green) ![License: Apache-2.0 (shields.io)](https://img.shields.io/badge/license-Apache--2.0-brightgreen) + +[ [中文说明](README_zh_cn.md) | [English](#) ] + +**Quick load icon pack.** + +*Library for reading icon pack resources, support custom keywords to find icons, support icon cropping, scaling and color saturation modification. Demo app, a simple Android desktop, can be more intuitive to understand the usefulness of this library.* + +## Prerequisites ++ SDK Version >= 14 ++ kotlin ++ install the custom icon pack [Pure Icon Pack](https://apkpure.net/cn/pure-circle-icon-pack/me.morirain.dev.iconpack.pure) or Others you like + +## Quick Start + +1. Import AAR + + Gradle or Download [IconPackManager](https://github.com/lalakii/IconPackManager/releases) + + ```kotlin + dependencies { + implementation("com.iamverycute:IconPackManager:6.3") + } + ``` + +2. Code Sample + + ```kotlin + import com.iamverycute.iconpackmanager.IconPackManager + + // IconPackManager + val ipm = IconPackManager(packageManager) + + val iconPacks = ipm.isSupportedIconPacks() + + ipm.isSupportedIconPacks(true) //Force Flush IconPack cache + + iconPacks.forEach { + //…… + } + + // Add rules for a custom icon + val rules = HashMap> + rules["com.android.chrome"]=arrayOf("browser","...") + rules["com.android.email"]=arrayOf("mail","message") + rules["video"]=arrayOf("tencent","youtube") + iconPackItem.setRules(rules) + /** Use this method to add rules when you need to specify icons for an application, + parameter 1: package name, parameter 2: keyword (icon resource name) Fuzzy Matching + How to get keywords? see icon pack.apk assets/appfilter.xml + */ + + // clear all rules, if need + iconPackItem.setRules(null) + ``` + ```xml + + + + + + + + + ... + ... + ... + + ``` + *ipm.isSupportedIconPacks() is a list that can be traversed to get all the icon packs.* + ```kotlin + // load icon pack + ipm.isSupportedIconPacks().forEach { + /** If you have more than one icon pack theme installed, you need to exclude it here + filter other icon pack**/ + // if (it.name != "your icon pack") + + //get icon pack name + val iconPackName = it.name + + //get icon from icon pack + val launchIntent = getLaunchIntentForPackage(packageName) + val icon = it.loadIcon(launchIntent) //Intent or ComponentName or ApplicationInfo + + //if not found icon, modify the original icon + if(icon == null) + { + //Cutting circles + it.transformIcon(applicationInfo.loadIcon(packageManager),0.5f,scaleF,saturation) + + //Cropping rounded corners requires a number of parameters to be defined, + // in order of radius, scale, and color saturation, + // and a variable type parameter, Float, which defaults to 1f. + it.transformIcon(applicationInfo.loadIcon(packageManager),radius,scaleF,saturation) + } + } + ``` + +## Demo + + + +## About + +Generating electricity for love. + ++ feedback:dazen@189.cn \ No newline at end of file diff --git a/README_zh_cn.md b/README_zh_cn.md new file mode 100644 index 0000000..1f290ab --- /dev/null +++ b/README_zh_cn.md @@ -0,0 +1,102 @@ +# IconPackManager +[![Maven Central](https://img.shields.io/maven-central/v/com.iamverycute/IconPackManager.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.iamverycute/IconPackManager/) ![API: 14+ (shields.io)](https://img.shields.io/badge/API-14+-green) ![License: Apache-2.0 (shields.io)](https://img.shields.io/badge/license-Apache--2.0-brightgreen) + +[ [中文说明](#) | [English](README.md) ] + +**快速加载图标包** + +*用于读取图标包资源的库,支持自定义关键词查找图标,支持图标裁剪、缩放以及色彩饱和度修改。演示app,是一个简易的安卓桌面,可以更加直观的了解这个库的用处。* + +## 必要条件 ++ SDK 版本 大于 14 ++ kotlin ++ 测试图标包 [Pure Icon Pack](https://www.coolapk.com/apk/me.morirain.dev.iconpack.pure) 或你自己喜欢的 + +## 快速开始 + +1. 导入 + + 使用Gradle,或者直接下载AAR [IconPackManager](https://github.com/lalakii/IconPackManager/releases) + + ```kotlin + dependencies { + implementation("com.iamverycute:IconPackManager:6.3") + } + ``` + +2. 代码示例 + + ```kotlin + import com.iamverycute.iconpackmanager.IconPackManager + + // IconPackManager + val ipm = IconPackManager(packageManager) + + val iconPacks = ipm.isSupportedIconPacks() + + ipm.isSupportedIconPacks(true)// 强制刷新缓存,如果需要 + + iconPacks.forEach { + //……遍历所有图标包 + } + + // 为某个图标包添加自定义规则,图标包没有相应图标时,按照规则查找图标包内的图标 + val rules = HashMap> //key是包名,可模糊匹配;value是需要匹配的应用图标包名,可模糊匹配,支持多个参数 + rules["com.android.chrome"]=arrayOf("browser","...") + rules["com.android.email"]=arrayOf("mail","message") + rules["video"]=arrayOf("tencent","youtube") + iconPackItem.setRules(rules) + + //清除当前图标包的自定义规则 + iconPackItem.setRules(null) + ``` + ```xml + + + + + + + + + ... + ... + ... + + ``` + *ipm.isSupportedIconPacks()是一个list,遍历可获取图标包名称以及相应的工具类* + ```kotlin + // load icon pack + ipm.isSupportedIconPacks().forEach { + /** 根据图标包名称,筛选图标包 **/ + // if (it.name != "your icon pack") + + //get icon pack name + val iconPackName = it.name + + //get icon from icon pack; + val launchIntent = getLaunchIntentForPackage(packageName) + val icon = it.loadIcon(launchIntent) //可选Intent or ComponentName or ApplicationInfo + + //如果未找到图标,可选 裁剪原始图标 + if(icon == null) + { + //裁剪圆形 + it.transformIcon(applicationInfo.loadIcon(packageManager),0.5f,scaleF,saturation) + + //裁剪圆角 需要自己定义一些参数 radius是半径,scaleF是图标缩放,saturation是色彩饱和度。Float可变类型参数,默认值为1f + it.transformIcon(applicationInfo.loadIcon(packageManager),radius,scaleF,saturation) + } + } + ``` + +## 演示 + + + +## 关于 + +为爱发电。 + ++ feedback:dazen@189.cn + diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..956c004 --- /dev/null +++ b/app/.gitignore @@ -0,0 +1,2 @@ +/build +/release \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..64e9281 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,99 @@ +import com.android.build.gradle.tasks.PackageAndroidArtifact +import java.time.ZonedDateTime +import java.time.format.DateTimeFormatter + +plugins { + id("com.android.application") + id("org.jetbrains.kotlin.android") +} +android { + namespace = "cn.lalaki.tinydesk" + compileSdk = 34 + defaultConfig { + applicationId = namespace + minSdk = 14 + //noinspection ExpiredTargetSdkVersion + targetSdk = 29 + versionCode = 4 + versionName = + "$versionCode.${ + ZonedDateTime.now().toLocalDate().format(DateTimeFormatter.ofPattern("MMdd")) + }" + } + signingConfigs { + register("lalaki_config") { + enableV1Signing = true + enableV2Signing = false + enableV3Signing = false + enableV4Signing = false + keyAlias = "dazen@189.cn" + storeFile = file("D:\\imoe.jks") + storePassword = System.getenv("mystorepass") + keyPassword = System.getenv("mystorepass2") + } + } + buildTypes { + named("release") { + signingConfig = signingConfigs.getByName("lalaki_config") + isMinifyEnabled = true + isShrinkResources = true + isCrunchPngs = true + isJniDebuggable = false + isDebuggable = false + setProguardFiles( + setOf( + getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" + ) + ) + } + } + dependenciesInfo { + includeInApk = false + includeInBundle = false + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 + } + kotlinOptions.jvmTarget = "21" + packaging.resources.excludes.addAll( + mutableSetOf( + "META-INF", + "META-INF/**", + "kotlin/**", + "DebugProbesKt.bin", + "kotlin-tooling-metadata.json", + ) + ) +} + +dependencies { + implementation(project(":library")) + implementation("com.belerweb:pinyin4j:2.5.1") +} + +tasks.withType { + doFirst { appMetadata.asFile.get().writeText("") } +} + +tasks.configureEach { + if (arrayOf("aarmetadata", "artprofile", "jni", "native").any { + name.lowercase().contains(it) + }) { + enabled = false + } + if (this.name.contains("assembleRelease")) { + this.doLast { + android.applicationVariants.all { + outputs.forEach { + val outputDirectory = it.outputFile.parent +// if (outputDirectory.contains("release")) +// exec { +// executable = "cmd.exe" +// args("/c", "start", outputDirectory) +// } + } + } + } + } +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..7eb4393 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,13 @@ +-assumenosideeffects class android.util.Log { + public static *** i(...); + public static *** d(...); + public static *** v(...); + public static *** e(...); + public static *** w(...); + public static *** wtf(...); +} +-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!method/propagation/parameter +-optimizationpasses 7 +-ignorewarnings +-allowaccessmodification +-verbose \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..4a6e662 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/cn/lalaki/tinydesk/MainActivity.kt b/app/src/main/java/cn/lalaki/tinydesk/MainActivity.kt new file mode 100644 index 0000000..0aa06dd --- /dev/null +++ b/app/src/main/java/cn/lalaki/tinydesk/MainActivity.kt @@ -0,0 +1,251 @@ +package cn.lalaki.tinydesk + +import android.annotation.SuppressLint +import android.app.Activity +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.content.IntentFilter +import android.content.pm.PackageManager +import android.graphics.Color +import android.net.Uri +import android.os.Bundle +import android.provider.Settings +import android.text.TextUtils +import android.util.DisplayMetrics +import android.view.Gravity +import android.view.KeyEvent +import android.widget.GridLayout +import android.widget.LinearLayout +import android.widget.ScrollView +import android.widget.SearchView +import android.widget.SearchView.OnQueryTextListener +import android.widget.TextView +import com.iamverycute.iconpackmanager.IconPackManager +import net.sourceforge.pinyin4j.PinyinHelper +import java.io.File +import java.lang.IllegalArgumentException +@Suppress("QueryPermissionsNeeded", "InternalInsetResource", "DiscouragedApi") +class MainActivity : Activity(), OnQueryTextListener { + private val appMap = linkedMapOf() + private val grid by lazy { GridLayout(this) } + private val innerDir by lazy { filesDir } + private val search by lazy { + SearchView(this).apply { + setOnQueryTextListener(this@MainActivity) + isIconifiedByDefault = false + queryHint = "搜索本机应用" + setBackgroundColor(Color.argb(50, 255, 255, 255)) + } + } + + @SuppressLint("ResourceType") + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + var statusBarHeight = 20 + val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android") + if (resourceId > 0) { + statusBarHeight = resources.getDimensionPixelSize(resourceId) + } + setContentView(LinearLayout(this).apply { + orientation = LinearLayout.VERTICAL + isFocusableInTouchMode = true + setBackgroundColor(Color.argb(35, 255, 255, 255)) + addView( + search, LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT + ).apply { + leftMargin = 20 + rightMargin = 20 + topMargin = statusBarHeight + 20 + } + ) + addView( + ScrollView(this@MainActivity).apply { + addView(grid) + }, LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f + ) + ) + }) + var column = 3 + if (innerDir.exists()) { + val files = innerDir.list() + if (files != null) { + for (it in files) { + val col = (it.first() + "").toIntOrNull() + if (col != null && col > 0) + column = col + } + } + } + grid.columnCount = column + val side = resources.displayMetrics.widthPixels / grid.columnCount + val density = resources.displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT + val mTextSize = side / density * 0.135f + val paddingSide = side / 5 + val halfSide = side / 2 + grid.setPadding(0, paddingSide, 0, paddingSide) + val topVal = side / 8 + val pm = packageManager + val iconPack = IconPackManager(pm).isSupportedIconPacks().firstOrNull() + for (app in pm.queryIntentActivities( + Intent(Intent.ACTION_MAIN).addCategory( + Intent.CATEGORY_LAUNCHER + ), PackageManager.GET_ACTIVITIES + )) { + val appName = app.loadLabel(pm).toString() + if (appName.contains("输入法") || packageName == app.activityInfo.packageName || app.activityInfo.packageName == iconPack?.packageName) continue + var appIcon = app.loadIcon(pm) + val launchIntent = + Intent().setClassName(app.activityInfo.packageName, app.activityInfo.name) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + if (iconPack != null) { + val customIcon = iconPack.loadIcon(launchIntent) + val iconPackName = iconPack.name.toString().lowercase() + if (customIcon == null) { + appIcon = if (iconPackName.contains("aura")) { //这些图标默认是圆角 + iconPack.transformIcon( + appIcon, 0.3f, 0.92f + ) + } else { + if (iconPackName.contains("delta")) { + iconPack.transformIcon( + appIcon, 0.5f, 0.89f, 0.72f + ) + } else { + iconPack.transformIcon( + appIcon, 0.5f, 0.89f + ) + } + } + } else { + appIcon = customIcon + } + } + val app0 = TextView(this).apply { + text = appName + setTextColor(Color.BLACK) + maxLines = 1 + textSize = mTextSize + ellipsize = TextUtils.TruncateAt.END + gravity = Gravity.CENTER + appIcon.setBounds(0, 0, halfSide, halfSide) + setCompoundDrawables(null, appIcon, null, null) + setOnClickListener { startActivity(launchIntent) } + setOnLongClickListener { + startActivity( + Intent( + Settings.ACTION_APPLICATION_DETAILS_SETTINGS, + Uri.parse("package:${app.activityInfo.packageName}") + ) + ) + true + } + layoutParams = GridLayout.LayoutParams().apply { + height = side + width = side + topMargin = topVal + } + } + if (!appMap.containsKey(app.activityInfo.packageName)) { + var pinyin = "" + for (c in appName) { + try { + pinyin += PinyinHelper.toHanyuPinyinStringArray(c) + .joinToString(transform = { it.replace(Regex("\\d+"), "") }) + } catch (_: Exception) { + } + } + app0.tag = pinyin + appMap[app.activityInfo.packageName] = app0 + grid.addView(app0) + } + } + registerReceiver(object : BroadcastReceiver() { + override fun onReceive(c: Context, i: Intent) { + val packageName = i.dataString.toString().split(':').last() + when (i.action) { + Intent.ACTION_PACKAGE_ADDED -> { + if (appMap[packageName] == null) { + recreate() + } + } + + Intent.ACTION_PACKAGE_REMOVED -> { + try { + pm.getApplicationEnabledSetting(packageName) + } catch (_: IllegalArgumentException) { + if (appMap.containsKey(packageName)) { + grid.removeView(appMap[packageName]) + appMap.remove(packageName) + } + } + } + } + } + }, IntentFilter().apply { + addAction(Intent.ACTION_PACKAGE_ADDED) + addAction(Intent.ACTION_PACKAGE_REMOVED) + addDataScheme("package") + }) + } + + override fun onResume() { + super.onResume() + clearSearchText() + } + + private fun clearSearchText() { + if (search.isFocusable && !searchText.isNullOrEmpty()) { + search.setQuery("", false) + } + search.clearFocus() + } + + override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { + if (keyCode == KeyEvent.KEYCODE_BACK) { + clearSearchText() + return true + } + return super.onKeyDown(keyCode, event) + } + + override fun onQueryTextSubmit(query: String?): Boolean { + return false + } + + private var searchText: String? = null + + override fun onQueryTextChange(newText: String?): Boolean { + searchText = newText + if (newText != null && newText.length > 8 && 1 == newText.toSet().size) { + if (newText.toIntOrNull() != null) { + val files = innerDir.listFiles() + if (files != null) { + for (it in files) { + if (it.isDirectory) + it.delete() + } + } + File(innerDir, newText).mkdirs() + recreate() + } + } + grid.removeAllViews() + for (it in appMap.values) { + grid.addView(it) + } + val text = newText?.replace(Regex("\\s+"), "").toString() + if (text.isNotEmpty()) { + for (it in appMap.values) { + if (!it.text.toString().contains(text, ignoreCase = true) && !it.tag.toString() + .contains(text, ignoreCase = true) + ) { + grid.removeView(it) + } + } + } + return false + } +} \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..b380a9e --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..a78c576 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,4 @@ +plugins { + id("com.android.application") version "8.2.2" apply false + id("org.jetbrains.kotlin.android") version "1.9.22" apply false +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..217b9da --- /dev/null +++ b/gradle.properties @@ -0,0 +1,26 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m -Dfile.encoding=UTF-8 +org.gradle.warning.mode=none + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Kotlin code style for this project: "official" or "obsolete": +kotlin.code.style=official +# Enables namespacing of each library's R class so that its R class includes only the +# resources declared in the library itself and none from the library's dependencies, +# thereby reducing the size of the R class for that library +android.nonTransitiveRClass=false +android.suppressUnsupportedCompileSdk=34 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e708b1c Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..eb27366 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Sat Jan 27 08:36:29 CST 2024 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=http\://mirrors.cloud.tencent.com/gradle/gradle-8.6-all.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..4f906e0 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/library/.gitignore b/library/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/library/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/library/build.gradle.kts b/library/build.gradle.kts new file mode 100644 index 0000000..d9e3d15 --- /dev/null +++ b/library/build.gradle.kts @@ -0,0 +1,104 @@ +import com.android.build.gradle.internal.tasks.AarMetadataTask + +plugins { + id("com.android.library") + id("org.jetbrains.kotlin.android") +} + +android { + namespace = "com.iamverycute.iconpackmanager" + compileSdk = 34 + version = 6.3 + buildTypes { + named("release") { + isMinifyEnabled = false + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + kotlinOptions.jvmTarget = "17" + base.archivesName = namespace +} + +tasks.withType { + isEnabled = false +} + +tasks.configureEach { + if (name == "assembleRelease") { + doLast { + val buildRoot = file("${project.layout.buildDirectory.get()}\\outputs\\aar") + val pomXml = """ + + + + + + + 4.0.0 + com.iamverycute + IconPackManager + ${version} + aar + IconPackManager + Get all icon pack applications, read the corresponding icon resources and also customize rules to find icons. + https://github.com/lalakii/IconPackManager + 2024 + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + lalakii + dazen@189.cn + lalaki.cn + + + + scm:git:https://github.com/lalakii/IconPackManager.git + https://github.com/lalakii/IconPackManager + + +""" + val pomFile = file("${buildRoot.absolutePath}\\IconPackManager-${version}.pom") + pomFile.writeText(pomXml) + sign(pomFile.parentFile, "*.pom") + sign(pomFile.parentFile, "*.aar") + val osName = System.getProperty("os.name").lowercase() + if (osName.contains("windows")) + openExplorer() + } + } +} + +fun openExplorer() { + exec { + executable = "cmd.exe" + args( + "/c", + "sleep", + "3", + "&&", + "start", + "${project.layout.buildDirectory.get()}\\outputs\\aar\\" + ) + } +} + +fun sign(path: File, fileName: String) { + try { + exec { + workingDir = path + executable = "gpg" + args("--yes", "--armor", "--detach-sign", fileName) + } + } catch (_: Exception) { + System.err.println("Please install GnuPG: https://gnupg.org/download/") + } +} \ No newline at end of file diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml new file mode 100644 index 0000000..e3bf5b8 --- /dev/null +++ b/library/src/main/AndroidManifest.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/library/src/main/java/com/iamverycute/iconpackmanager/IconPackManager.kt b/library/src/main/java/com/iamverycute/iconpackmanager/IconPackManager.kt new file mode 100644 index 0000000..86e45e8 --- /dev/null +++ b/library/src/main/java/com/iamverycute/iconpackmanager/IconPackManager.kt @@ -0,0 +1,211 @@ +package com.iamverycute.iconpackmanager + +import android.content.ComponentName +import android.content.Intent +import android.content.pm.ApplicationInfo +import android.content.pm.PackageManager +import android.content.res.Resources +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.ColorMatrix +import android.graphics.ColorMatrixColorFilter +import android.graphics.Paint +import android.graphics.Path +import android.graphics.RectF +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable +import android.os.Build +import org.xmlpull.v1.XmlPullParser + +@Suppress("DiscouragedApi", "Deprecation", "Unused") +open class IconPackManager(val pm: PackageManager) { + private val iconPacks by lazy { mutableListOf() } + open fun isSupportedIconPacks() = isSupportedIconPacks(false) + open fun isSupportedIconPacks(reload: Boolean): MutableList { + if (iconPacks.isEmpty() || reload) { + iconPacks.clear() + for (info in pm.queryIntentActivities( + Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER), + PackageManager.GET_ACTIVITIES + )) { + if (info.activityInfo.flags and (ApplicationInfo.FLAG_SYSTEM) == 0) try { + val res = pm.getResourcesForApplication(info.activityInfo.packageName) + val id = res.getIdentifier("appfilter", "xml", info.activityInfo.packageName) + if (id > 0) { + iconPacks += IconPack( + info.activityInfo.packageName, info.loadLabel(pm), res, id + ) + } + } catch (_: Exception) { + } + } + } + return iconPacks + } + + private val paint by lazy { Paint() } + private val rect by lazy { RectF() } + private val path by lazy { Path() } + + open inner class IconPack( + val packageName: String, val name: CharSequence, private val res: Resources, id: Int + ) { + private val caches by lazy { hashMapOf() } + private var rules: HashMap>? = null + private val icons = hashMapOf() + private var saturation = 1f + private val colorFilter by lazy { + ColorMatrixColorFilter(ColorMatrix().apply { setSaturation(saturation) }) + } + + init { + res.getXml(id).run { + try { + while (eventType != XmlPullParser.END_DOCUMENT) { + if (eventType == XmlPullParser.START_TAG && name == "item") { + val key = getAttributeValue(null, "component") + val value = getAttributeValue(null, "drawable") + if (!key.isNullOrEmpty() && !value.isNullOrEmpty()) icons[key] = value + } + next() + } + } catch (_: Exception) { + } finally { + close() + } + } + } + + @Deprecated("There may be serious performance loss.") + open fun getAllIconResources(): HashMap { + val drawables = hashMapOf() + val distinctIcon = icons.entries.distinctBy { it.value }.associate { it.key to it.value } + for (it in distinctIcon) { + val icon = getDrawable(it.value) + if (icon != null) { + drawables[it.key] = icon + } + } + return drawables + } + + private fun getDrawable(value: String): Drawable? { + val resourceId = res.getIdentifier(value, "drawable", packageName) + if (resourceId > 0) { + return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + res.getDrawable(resourceId) + } else { + res.getDrawable(resourceId, null) + } + } + return null + } + + open fun loadIcon(info: ApplicationInfo): Drawable? { + if (caches.containsKey(info.packageName)) { + val comp = caches[info.packageName] + if (comp != null) { + val icon = loadIcon(comp) + if (icon != null) return icon + } + } + pm.getPackageArchiveInfo( + info.sourceDir, PackageManager.GET_ACTIVITIES + )?.activities?.forEach { + val icon = loadIcon(ComponentName(info.packageName, it.name)) + if (icon != null) { + return icon + } + } + return null + } + + open fun loadIcon(launchIntent: Intent): Drawable? { + val comp = launchIntent.component ?: return null + return loadIcon(comp) ?: loadIcon( + pm.getApplicationInfo( + comp.packageName, if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + PackageManager.MATCH_UNINSTALLED_PACKAGES + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE) { + PackageManager.GET_UNINSTALLED_PACKAGES + } else { + 0 + } + ) + ) + } + + open fun loadIcon(comp: ComponentName): Drawable? { + var drawableVal = icons[comp.toString()] + if (drawableVal.isNullOrEmpty()) { + val rules = this.rules ?: return null + var words: Array? = null + for (it in rules) { + if (comp.packageName.contains(it.key, ignoreCase = true)) { + words = rules[it.key] + break + } + } + if (words == null) return null + for (icon in icons.keys) { + if (words.any { icon.contains(it, ignoreCase = true) }) { + drawableVal = icons[icon] + break + } + } + } + if (!drawableVal.isNullOrEmpty()) { + caches[comp.packageName] = comp + return getDrawable(drawableVal) + } + return null + } + + open fun setRules(r: HashMap>) { + this.rules = r + } + + open fun transformIcon(drawable: Drawable, vararg params: Float): BitmapDrawable { + var radius: Float? = null + var scale: Float? = null + for (p in params) { + if (radius == null) { + radius = p + } else if (scale == null) { + scale = p + } else { + this.saturation = p + } + } + val icon = Bitmap.createBitmap( + drawable.intrinsicWidth, drawable.intrinsicHeight, Bitmap.Config.ARGB_8888 + ) + val canvas = Canvas(icon) + val side = canvas.width.toFloat() + if (scale != null) { + val cwh = side / 2 + canvas.scale(scale, scale, cwh, cwh) + } + drawable.setBounds(0, 0, side.toInt(), side.toInt()) + rect.set(0f, 0f, side, side) + var roundedWidth = side + if (radius != null) { + roundedWidth *= radius + } + path.reset() + path.addRoundRect(rect, roundedWidth, roundedWidth, Path.Direction.CW) + canvas.clipPath(path) + drawable.draw(canvas) + if (this.saturation != 1f) { + paint.reset() + paint.colorFilter = colorFilter + Canvas(icon).drawBitmap(icon, 0f, 0f, paint) + } + return if (Build.VERSION.SDK_INT > Build.VERSION_CODES.CUPCAKE) { + BitmapDrawable(null, icon) + } else { + BitmapDrawable(icon) + } + } + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..29d1082 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,17 @@ +pluginManagement { + repositories { + maven(url = "https://jitpack.io") + maven(url = "https://mirrors.cloud.tencent.com/nexus/repository/maven-public/") + } +} +@Suppress("UnstableApiUsage") +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + maven(url = "https://jitpack.io") + maven(url = "https://mirrors.cloud.tencent.com/nexus/repository/maven-public/") + } +} +rootProject.name = "IconPackManager" +include(":app") +include(":library") \ No newline at end of file diff --git a/video/demo.gif b/video/demo.gif new file mode 100644 index 0000000..c8854e5 Binary files /dev/null and b/video/demo.gif differ