├── .github └── workflows │ ├── ci.yml │ └── release.yml ├── .gitignore ├── LICENSE.txt ├── README.md ├── README_zh.md ├── build.gradle.kts ├── buildSrc ├── .gitignore ├── build.gradle.kts └── src │ └── main │ └── kotlin │ ├── BuildConfig.kt │ ├── github-release.gradle.kts │ └── maven-central-publish.gradle.kts ├── deps.versions.toml ├── functional-test ├── .gitignore ├── build.gradle.kts └── src │ └── functionalTest │ └── kotlin │ └── BasicFunctionalTest.kt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── images └── launcher_icons.png ├── publish.sh ├── publish_to_local.sh ├── sample ├── .gitignore ├── app │ ├── .gitignore │ ├── build.gradle.kts │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── me │ │ │ └── xx2bab │ │ │ └── scratchpaper │ │ │ └── sample │ │ │ └── MainActivity.kt │ │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── build_debug.sh ├── build_test.sh ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle.kts ├── scratchpaper ├── .gitignore ├── build.gradle.kts └── src │ └── main │ └── kotlin │ └── me │ └── xx2bab │ └── scratchpaper │ ├── IconOverlayContent.kt │ ├── IconOverlayStyle.kt │ ├── ScratchPaperExtension.kt │ ├── ScratchPaperPlugin.kt │ ├── icon │ ├── Aapt2Operations.kt │ ├── AdaptiveIconProcessor.kt │ ├── AddIconOverlayTaskAction.kt │ ├── BaseIconProcessor.kt │ ├── IconProcessorParam.kt │ └── RegularIconProcessor.kt │ └── utils │ ├── CacheLocation.kt │ └── Logger.kt ├── settings.gradle.kts └── sp-banner.png /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - master 7 | paths-ignore: 8 | - '*.md' 9 | push: 10 | branches: 11 | - master 12 | paths-ignore: 13 | - '*.md' 14 | 15 | env: 16 | CI: true 17 | GRADLE_OPTS: -Dorg.gradle.daemon=false -Dkotlin.incremental=false 18 | TERM: dumb 19 | 20 | jobs: 21 | assemble: 22 | name: Assemble 23 | runs-on: ubuntu-latest 24 | env: 25 | JAVA_TOOL_OPTIONS: -Xmx4g 26 | 27 | steps: 28 | - uses: actions/checkout@v2 29 | - uses: gradle/wrapper-validation-action@v1 30 | - name: Set up JDK 17 31 | uses: actions/setup-java@v2 32 | with: 33 | distribution: 'zulu' 34 | java-version: '17' 35 | - uses: actions/cache@v2 36 | with: 37 | path: | 38 | ~/.gradle/caches 39 | ~/.gradle/wrapper 40 | key: ${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} 41 | restore-keys: | 42 | ${{ runner.os }}-${{ github.job }}- 43 | - run: | 44 | ./gradlew assemble 45 | checks: 46 | name: Checks (unit tests and static analysis, TODO:add detekt check after set it up) 47 | runs-on: ubuntu-latest 48 | env: 49 | JAVA_TOOL_OPTIONS: -Xmx4g 50 | 51 | steps: 52 | - uses: actions/checkout@v2 53 | - uses: gradle/wrapper-validation-action@v1 54 | - name: Set up JDK 17 55 | uses: actions/setup-java@v2 56 | with: 57 | distribution: 'zulu' 58 | java-version: '17' 59 | - uses: actions/cache@v2 60 | with: 61 | path: | 62 | ~/.gradle/caches 63 | ~/.gradle/wrapper 64 | key: ${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} 65 | restore-keys: | 66 | ${{ runner.os }}-${{ github.job }}- 67 | - run: | 68 | ./gradlew :scratchpaper:test 69 | functional-tests: 70 | name: Functional tests 71 | runs-on: ubuntu-latest 72 | env: 73 | JAVA_TOOL_OPTIONS: -Xmx4g 74 | steps: 75 | - uses: actions/checkout@v2 76 | - uses: gradle/wrapper-validation-action@v1 77 | - name: Set up JDK 17 78 | uses: actions/setup-java@v2 79 | with: 80 | distribution: 'zulu' 81 | java-version: '17' 82 | - uses: actions/cache@v2 83 | with: 84 | path: | 85 | ~/.gradle/caches 86 | ~/.gradle/wrapper 87 | key: ${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} 88 | restore-keys: | 89 | ${{ runner.os }}-${{ github.job }}- 90 | - name: Prepare environment 91 | env: 92 | SIGNING_SECRET_KEY_CONTENT: ${{ secrets.SIGNING_SECRET_KEY_CONTENT }} 93 | SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE }} 94 | run: | 95 | git fetch --unshallow 96 | sudo bash -c "echo '$SIGNING_SECRET_KEY_CONTENT' | base64 -d > '$SIGNING_SECRET_KEY_RING_FILE'" 97 | - name: Build & Release all Polyfill libraries to MavenLocal 98 | run: chmod +x ./publish_to_local.sh | ./publish_to_local.sh 99 | env: 100 | SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} 101 | SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} 102 | SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE }} 103 | SIGNING_SECRET_KEY_CONTENT: ${{ secrets.SIGNING_SECRET_KEY_CONTENT }} 104 | OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} 105 | OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} 106 | GH_DEV_TOKEN: ${{ secrets.GH_DEV_TOKEN }} 107 | - run: | 108 | ./gradlew clean :functional-test:functionalTest 109 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | 8 | jobs: 9 | scratch-paper-release: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Check out 13 | uses: actions/checkout@v2 14 | 15 | - name: Set up JDK 17 16 | uses: actions/setup-java@v2 17 | with: 18 | distribution: 'zulu' 19 | java-version: '17' 20 | 21 | - name: Prepare environment 22 | env: 23 | SIGNING_SECRET_KEY_CONTENT: ${{ secrets.SIGNING_SECRET_KEY_CONTENT }} 24 | SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE }} 25 | run: | 26 | git fetch --unshallow 27 | sudo bash -c "echo '$SIGNING_SECRET_KEY_CONTENT' | base64 -d > '$SIGNING_SECRET_KEY_RING_FILE'" 28 | 29 | 30 | - name: Build & Release ScratchPaper plugin to Maven Central 31 | run: chmod +x ./publish.sh | ./publish.sh 32 | env: 33 | SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} 34 | SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} 35 | SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE }} 36 | SIGNING_SECRET_KEY_CONTENT: ${{ secrets.SIGNING_SECRET_KEY_CONTENT }} 37 | OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} 38 | OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} 39 | GH_DEV_TOKEN: ${{ secrets.GH_DEV_TOKEN }} 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle/ 3 | local.properties 4 | .idea/ 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | /local -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ScratchPaper 2 | 3 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/me.2bab/scratchpaper/badge.svg)](https://search.maven.org/artifact/me.2bab/scratchpaper) 4 | [![Actions Status](https://github.com/2bab/ScratchPaper/workflows/CI/badge.svg)](https://github.com/2bab/ScratchPaper/actions) 5 | [![Apache 2](https://img.shields.io/badge/License-Apache%202-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0) 6 | 7 | [English][[中文说明]](./README_zh.md) 8 | 9 | ScratchPaper is a Gradle Plugin helps distinguish the variant/version/git-commit-id by adding a launcher icon overlay, powered by [New Variant/Artifact API](https://developer.android.com/studio/build/extend-agp) & [Polyfill](https://github.com/2BAB/Polyfill). Accepted by [Google Dev Library](https://devlibrary.withgoogle.com/products/android/repos/2BAB-ScratchPaper). 10 | 11 | 12 | ## How does it work? 13 | 14 | ![](./images/launcher_icons.png) 15 | 16 | > If you install both debug&release Apps on one device, you can not distinguish which one you is your target for testing. 17 | 18 | > If you have more than one staging Apps for QAs, when they found some issues you may don't know how to match the App version to your code base (branch/commit/etc..), because all of them share the same version like "2.1.0-SNAPSHOT". 19 | 20 | ScratchPaper can add an overlay on your launcher icon, and put given information on it. 21 | 22 | - Support regular & round Icons 23 | - Support adaptive-icon 24 | - Support AAPT2 25 | - Support custom text of multiple lines with some built-in content 26 | 27 | In addition, the plugin can be enabled/disabled for per variant respectively. 28 | 29 | 30 | ## Why choose ScratchPaper? 31 | 32 | We can find some similar solutions from Github, but the pain points of them are: most of them do not support latest AAPT2/AGP. ScratchPaper supports latest AAPT2/AGP, adaptive icons, and use new Variant API / Gradle lazy properties to gain a better performance. Apart from that, [usefulness/easylauncher-gradle-plugin](https://github.com/usefulness/easylauncher-gradle-plugin) is one of the most popular solution that is still under maintained, it supports fancy filters and additional pngs to add on badges. If you don't need multiple lines text, that is a great choice as well. 33 | 34 | 35 | ## Usage 36 | 37 | **0x01. Add the plugin to classpath:** 38 | 39 | ```gradle 40 | // Option 1. 41 | // Add `mavenCentral` to `pluginManagement{}` on `settings.gradle.kts` (or the root `build.gradle.kts`), 42 | // and scratchpaper plugin id. 43 | pluginManagement { 44 | repositories { 45 | ... 46 | mavenCentral() 47 | } 48 | plugins { 49 | ... 50 | id("me.2bab.scratchpaper") version "3.3.0" apply false 51 | } 52 | } 53 | 54 | 55 | // Option 2. 56 | // Using classic `buildscript{}` block in root build.gradle.kts. 57 | buildscript { 58 | repositories { 59 | ... 60 | mavenCentral() 61 | } 62 | dependencies { 63 | ... 64 | classpath("me.2bab:scratchpaper:3.3.0") 65 | } 66 | } 67 | ``` 68 | 69 | 70 | **0x02. Apply Plugin:** 71 | 72 | ``` gradle 73 | // On Application's build.gradle.kts (do not use in Library project) 74 | plugin { 75 | ... 76 | id("me.2bab.scratchpaper") 77 | } 78 | ``` 79 | 80 | **0x03. Advanced Configurations** 81 | 82 | ``` kotlin 83 | scratchPaper { 84 | // Main feature flags. Mandatory field. 85 | // Can not be lazily set, it's valid only before "afterEvaluate{}". 86 | // In this way, only "FullDebug" variant will get icon overlays 87 | enableByVariant { variant -> 88 | variant.name.contains("debug", true) 89 | && variant.name.contains("full", true) 90 | } 91 | 92 | // Mandatory field. 93 | // Can be lazily set even after configuration phrase. 94 | iconNames.set("ic_launcher, ic_launcher_round") 95 | 96 | // Some sub-feature flags 97 | enableXmlIconsRemoval.set(false) // Can be lazily set even after configuration phrase. 98 | forceUpdateIcons = true // Can not be lazily set, it's valid only before "afterEvaluate{}". 99 | 100 | // ICON_OVERLAY styles, contents. 101 | style { 102 | textSize.set(9) 103 | textColor.set("#FFFFFFFF") // Accepts 3 kinds of format: "FFF", "FFFFFF", "FFFFFFFF". 104 | lineSpace.set(4) 105 | backgroundColor.set("#99000000") // Same as textColor. 106 | } 107 | 108 | content { 109 | showVersionName.set(true) 110 | showVariantName.set(true) 111 | showGitShortId.set(true) 112 | showDateTime.set(true) 113 | extraInfo.set("For QA") 114 | } 115 | } 116 | ``` 117 | 118 | **0x04. Build your App and Enjoy!** 119 | 120 | Check screenshots on the top. 121 | 122 | 123 | ## Compatible 124 | 125 | ScratchPaper is only supported & tested on LATEST ONE Minor versions of Android Gradle Plugin. Since `2.5.4`, the publish repository has been shifted from Jcenter to **Maven Central**. 126 | 127 | AGP Version|Latest Support Version 128 | -----------|----------------- 129 | 8.1.x | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/me.2bab/scratchpaper/badge.svg)](https://search.maven.org/artifact/me.2bab/scratchpaper) 130 | 8.0.x | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/me.2bab/scratchpaper/badge.svg)](https://search.maven.org/artifact/me.2bab/scratchpaper) 131 | 7.2.x | 3.2.1 132 | 7.1.x | 3.2.1 133 | 7.0.x | 3.0.0 134 | 4.2.x | 2.6.0 135 | 4.1.x | 2.5.4 136 | 4.0.x | 2.5.3 137 | 3.6.x | 2.5.1 138 | 3.5.x | 2.4.2 139 | 3.4.x | 2.4.1 140 | 3.3.x | 2.4.1 141 | 3.2.x | 2.4.0 142 | 3.1.x | 2.4.0 143 | 3.0.x (Aapt2) | Support 144 | 2.3.x (Aapt2) | Never Tested 145 | 2.3.x (Aapt1) | Not Support 146 | 147 | 148 | ## Git Commit Check 149 | 150 | Check this [link](https://medium.com/walmartlabs/check-out-these-5-git-tips-before-your-next-commit-c1c7a5ae34d1) to make sure everyone will make a **meaningful** commit message. 151 | 152 | So far we haven't added any hook tool, but follow the regex below: 153 | 154 | ``` 155 | (chore|feat|docs|fix|refactor|style|test|hack|release)(:)( )(.{0,80}) 156 | ``` 157 | 158 | 159 | ## v1.x (Deprecated) 160 | 161 | The v1.x `IconCover` forked from [icon-version@akonior](https://github.com/akonior/icon-version). It provided icon editor functions that compatible with `Aapt1`, and I added some little enhancement like hex color support, custom text support. As time goes by, we have to move to `Aapt2` sooner or later. So I decide to revamp the whole project and add more fancy features. **If you are still using `Aapt1` with `IconCover`, now is the time to consider moving into the new one.** 162 | 163 | 164 | ## License 165 | 166 | > 167 | > Copyright Since 2016 2BAB 168 | > 169 | >Licensed under the Apache License, Version 2.0 (the "License"); 170 | you may not use this file except in compliance with the License. 171 | You may obtain a copy of the License at 172 | > 173 | > http://www.apache.org/licenses/LICENSE-2.0 174 | > 175 | > Unless required by applicable law or agreed to in writing, software 176 | distributed under the License is distributed on an "AS IS" BASIS, 177 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 178 | See the License for the specific language governing permissions and 179 | limitations under the License. 180 | 181 | -------------------------------------------------------------------------------- /README_zh.md: -------------------------------------------------------------------------------- 1 | ScratchPaper 2 | 3 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/me.2bab/scratchpaper/badge.svg)](https://search.maven.org/artifact/me.2bab/scratchpaper) 4 | [![Actions Status](https://github.com/2bab/ScratchPaper/workflows/CI/badge.svg)](https://github.com/2bab/ScratchPaper/actions) 5 | [![Apache 2](https://img.shields.io/badge/License-Apache%202-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0) 6 | 7 | [中文说明][[English]](./README.md) 8 | 9 | ScratchPaper 是一个 Gradle 插件,用来给 APK 图标添加 variant/version/git-commit-id 等信息以区分不同版本,由[全新的 Variant/Artifact API](https://developer.android.com/studio/build/extend-agp) 和 [Polyfill](https://github.com/2BAB/Polyfill) 框架驱动。 10 | 11 | ## ScratchPaper 解决了什么问题? 12 | 13 | ![](./images/launcher_icons.png) 14 | 15 | > 如果你在一台设备上同时安装一个 App 的 Debug 版和 Release 版,你可能很难区分出来到底哪个你要测试的版本(不打开的情况下)。 16 | 17 | > 如果你同时打了多个测试包给测试或者产品(例如前后打了三次 "2.1.0-SNAPSHOT"),当他们给你反馈的问题时候你和他们可能都很难分别出每个 App 对应的具体的分支或者 commit 节点。 18 | 19 | ScratchPaper 可以在你的 App 启动图标上加一个蒙层用以区分不同变体的 App,其承载了版本信息等附加文字。 20 | 21 | - 支持 常规 和 圆形 的图标 22 | - 支持 adaptive-icon 23 | - 支持 AAPT2 24 | - 支持多行自定义文字内容(包括一些内置的内容) 25 | 26 | ## 为什么一定要试试 ScratchPaper 27 | 28 | 其实市面上不乏有类似的解决方案,但是他们的最重要问题在于:多数都不支持 AAPT2 和新版的 AGP。ScratchPaper 提供了朴素的文字蒙层叠加,支持最新的 AGP 和 adaptive icons,以及 Gradle 惰性配置的特性(可减少配置期耗时)。如果你不需要多行文字的特性,也可以选择另外一个比较流行并且还在维护的方案 [sefulness/easylauncher-gradle-plugin](https://github.com/usefulness/easylauncher-gradle-plugin)。 29 | 30 | ## 如何使用? 31 | 32 | **0x01. Add the plugin to classpath:** 33 | 34 | ``` kotlin 35 | // 可选方式 1. 36 | // 添加 `mavenCentral` 到 `settings.gradle.kts`(或根目录 `build.gradle.kts`) 的 `pluginManagement{}` 内, 37 | // 并且声明 scratchpaper 插件的 id. 38 | pluginManagement { 39 | repositories { 40 | ... 41 | mavenCentral() 42 | } 43 | plugins { 44 | ... 45 | id("me.2bab.scratchpaper") version "3.3.0" apply false 46 | } 47 | } 48 | 49 | 50 | // 可选方式 2. 51 | // 使用经典的 `buildscript{}` 引入方式(在根目录的 build.gradle.kts). 52 | buildscript { 53 | repositories { 54 | ... 55 | mavenCentral() 56 | } 57 | dependencies { 58 | ... 59 | classpath("me.2bab:scratchpaper:3.3.0") 60 | } 61 | } 62 | ``` 63 | 64 | **0x02. Apply Plugin:** 65 | 66 | ``` gradle 67 | // 在 Application 模块的 build.gradle.kts (不要在 Library 模块使用) 68 | plugin { 69 | ... 70 | id("me.2bab.scratchpaper") 71 | } 72 | ``` 73 | 74 | **0x03. Advanced Configurations** 75 | 76 | ``` kotlin 77 | scratchPaper { 78 | // 可以根据 variant 开启 79 | // Can not be lazily set, it's valid only before "afterEvaluate{}". 80 | // In this way, only "FullDebug" variant will get icon overlays 81 | enableByVariant { variant -> 82 | variant.name.contains("debug", true) 83 | && variant.name.contains("full", true) 84 | } 85 | 86 | // !!! Mandatory field. 87 | // Can be lazily set even after configuration phrase. 88 | iconNames.set("ic_launcher, ic_launcher_round") 89 | 90 | // Some sub-feature flags 91 | enableXmlIconsRemoval.set(false) // Can be lazily set even after configuration phrase. 92 | forceUpdateIcons = true // Can not be lazily set, it's valid only before "afterEvaluate{}". 93 | 94 | // ICON_OVERLAY styles, contents. 95 | style { 96 | textSize.set(9) 97 | textColor.set("#FFFFFFFF") // Accepts 3 kinds of format: "FFF", "FFFFFF", "FFFFFFFF". 98 | lineSpace.set(4) 99 | backgroundColor.set("#99000000") // Same as textColor. 100 | } 101 | 102 | content { 103 | showVersionName.set(true) 104 | showVariantName.set(true) 105 | showGitShortId.set(true) 106 | showDateTime.set(true) 107 | extraInfo.set("For QA") 108 | } 109 | } 110 | ``` 111 | 112 | **0x04. Build your App and Enjoy!** 113 | 114 | 效果请看头部的截图。 115 | 116 | ## 兼容性 117 | 118 | 精力有限,ScratchPaper 只会支持最新两个 Minor 版本的 Android Gradle Plugin。从 `2.5.4` 开始,ScratchPaper 发布的仓库从 Jcenter 迁移到 **Maven Central**。 119 | 120 | AGP Version|Latest Support Version 121 | -----------|----------------- 122 | 8.1.x | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/me.2bab/scratchpaper/badge.svg)](https://search.maven.org/artifact/me.2bab/scratchpaper) 123 | 8.0.x | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/me.2bab/scratchpaper/badge.svg)](https://search.maven.org/artifact/me.2bab/scratchpaper) 124 | 7.2.x | 3.2.1 125 | 7.1.x | 3.2.1 126 | 7.0.x | 3.0.0 127 | 4.1.x | 2.5.4 128 | 4.0.x | 2.5.3 129 | 3.6.x | 2.5.1 130 | 3.5.x | 2.4.2 131 | 3.4.x | 2.4.1 132 | 3.3.x | 2.4.1 133 | 3.2.x | 2.4.0 134 | 3.1.x | 2.4.0 135 | 3.0.x (Aapt2) | Support 136 | 2.3.x (Aapt2) | Never Tested 137 | 2.3.x (Aapt1) | Not Support 138 | 139 | ## Git Commit Check 140 | 141 | Check this [link](https://medium.com/walmartlabs/check-out-these-5-git-tips-before-your-next-commit-c1c7a5ae34d1) to make sure everyone will make a **meaningful** commit message. 142 | 143 | So far we haven't added any hook tool, but follow the regex below: 144 | 145 | ``` 146 | (chore|feat|docs|fix|refactor|style|test|hack|release)(:)( )(.{0,80}) 147 | ``` 148 | 149 | 150 | ## v1.x (Deprecated) 151 | 152 | The v1.x `IconCover` forked from [icon-version@akonior](https://github.com/akonior/icon-version). It provided icon editor functions that compatible with `Aapt1`, and I added some little enhancement like hex color support, custom text support. As time goes by, we have to move to `Aapt2` sooner or later. So I decide to revamp the whole project and add more fancy features. **If you are still using `Aapt1` with `IconCover`, now is the time to consider moving into the new one.** 153 | 154 | ## License 155 | 156 | > 157 | > Copyright Since 2016 2BAB 158 | > 159 | >Licensed under the Apache License, Version 2.0 (the "License"); 160 | you may not use this file except in compliance with the License. 161 | You may obtain a copy of the License at 162 | > 163 | > http://www.apache.org/licenses/LICENSE-2.0 164 | > 165 | > Unless required by applicable law or agreed to in writing, software 166 | distributed under the License is distributed on an "AS IS" BASIS, 167 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 168 | See the License for the specific language governing permissions and 169 | limitations under the License. 170 | 171 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | task("clean") { 2 | delete(rootProject.buildDir) 3 | } -------------------------------------------------------------------------------- /buildSrc/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build/ -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | } 4 | 5 | dependencies { 6 | // Github Release 7 | implementation("com.github.breadmoirai:github-release:2.5.2") 8 | } 9 | 10 | repositories { 11 | mavenCentral() 12 | gradlePluginPortal() 13 | } -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/BuildConfig.kt: -------------------------------------------------------------------------------- 1 | object BuildConfig { 2 | 3 | object Versions { 4 | const val scratchPaperVersion = "3.3.0" 5 | } 6 | 7 | } -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/github-release.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.github.breadmoirai.githubreleaseplugin.GithubReleaseTask 2 | import java.util.* 3 | 4 | val taskName = "releaseArtifactsToGithub" 5 | 6 | val tokenFromEnv: String? = System.getenv("GH_DEV_TOKEN") 7 | val token: String = if (!tokenFromEnv.isNullOrBlank()) { 8 | tokenFromEnv 9 | } else if (project.rootProject.file("local.properties").exists()){ 10 | val properties = Properties() 11 | properties.load(project.rootProject.file("local.properties").inputStream()) 12 | properties.getProperty("github.devtoken") ?: "" 13 | } else { 14 | "" 15 | } 16 | 17 | 18 | val repo = "ScratchPaper" 19 | val tagBranch = "master" 20 | val version = BuildConfig.Versions.scratchPaperVersion 21 | val releaseNotes = "" 22 | val task = createGithubReleaseTaskInternal(token, repo, tagBranch, version, releaseNotes) 23 | 24 | 25 | fun createGithubReleaseTaskInternal( 26 | token: String, 27 | repo: String, 28 | tagBranch: String, 29 | version: String, 30 | releaseNotes: String 31 | ): TaskProvider { 32 | return project.tasks.register(taskName) { 33 | authorization.set("Token $token") 34 | owner.set("2bab") 35 | this.repo.set(repo) 36 | tagName.set(version) 37 | targetCommitish.set(tagBranch) 38 | releaseName.set("v${version}") 39 | body.set(releaseNotes) 40 | draft.set(false) 41 | prerelease.set(false) 42 | overwrite.set(true) 43 | allowUploadToExisting.set(true) 44 | apiEndpoint.set("https://api.github.com") 45 | dryRun.set(false) 46 | generateReleaseNotes.set(false) 47 | releaseAssets.from( 48 | tasks.getByName("jar").archiveFile, // seal-${version}.jar 49 | tasks.getByName("sourcesJar").archiveFile, // seal-${version}-sources.jar 50 | tasks.getByName("javadocJar").archiveFile, // seal-${version}-javadoc.jar 51 | //tasks.getByName("signPluginMavenPublication").outputs, // seal-${version}-asc.jar, seal-${version}-sources-asc.jar, seal-${version}-sources-asc.jar, 52 | ) 53 | } 54 | } -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/maven-central-publish.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `maven-publish` 3 | signing 4 | } 5 | 6 | 7 | // Stub secrets to let the project sync and build without the publication values set up 8 | ext["signing.keyId"] = null 9 | ext["signing.password"] = null 10 | ext["signing.secretKeyRingFile"] = null 11 | ext["ossrh.username"] = null 12 | ext["ossrh.password"] = null 13 | 14 | // Grabbing secrets from local.properties file or from environment variables, 15 | // which could be used on CI 16 | val secretPropsFile = project.rootProject.file("local.properties") 17 | if (secretPropsFile.exists()) { 18 | secretPropsFile.reader().use { 19 | java.util.Properties().apply { 20 | load(it) 21 | } 22 | }.onEach { (name, value) -> 23 | ext[name.toString()] = value 24 | } 25 | } else { 26 | ext["signing.keyId"] = System.getenv("SIGNING_KEY_ID") 27 | ext["signing.password"] = System.getenv("SIGNING_PASSWORD") 28 | ext["signing.secretKeyRingFile"] = System.getenv("SIGNING_SECRET_KEY_RING_FILE") 29 | ext["ossrh.username"] = System.getenv("OSSRH_USERNAME") 30 | ext["ossrh.password"] = System.getenv("OSSRH_PASSWORD") 31 | } 32 | fun getExtraString(name: String) = ext[name]?.toString() 33 | 34 | 35 | val groupName = "me.2bab" 36 | val projectName = "scratchpaper" 37 | val mavenDesc = "A Gradle Plugin to resolve AndroidManifest.xml merge conflicts." 38 | val baseUrl = "https://github.com/2BAB/ScratchPaper" 39 | val siteUrl = baseUrl 40 | val gitUrl = "$baseUrl.git" 41 | val issueUrl = "$baseUrl/issues" 42 | 43 | val licenseIds = "Apache-2.0" 44 | val licenseNames = arrayOf("The Apache Software License, Version 2.0") 45 | val licenseUrls = arrayOf("http://www.apache.org/licenses/LICENSE-2.0.txt") 46 | val inception = "2017" 47 | 48 | val username = "2BAB" 49 | 50 | 51 | publishing { 52 | // Configure MavenCentral repository 53 | repositories { 54 | maven { 55 | name = "sonatype" 56 | setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") 57 | credentials { 58 | username = getExtraString("ossrh.username") 59 | password = getExtraString("ossrh.password") 60 | } 61 | } 62 | } 63 | 64 | // Configure MavenLocal repository 65 | repositories { 66 | maven { 67 | name = "myMavenlocal" 68 | url = uri(System.getProperty("user.home") + "/.m2/repository") 69 | } 70 | } 71 | } 72 | 73 | afterEvaluate { 74 | publishing.publications.all { 75 | signing.sign(this) 76 | val publicationName = this.name 77 | (this as MavenPublication).apply { 78 | if (publicationName == "pluginMaven") { 79 | groupId = groupName 80 | artifactId = projectName 81 | } 82 | version = BuildConfig.Versions.scratchPaperVersion 83 | 84 | pom { 85 | if (publicationName == "pluginMaven") { 86 | name.set(project.name) 87 | } 88 | 89 | description.set(mavenDesc) 90 | url.set(siteUrl) 91 | 92 | inceptionYear.set(inception) 93 | licenses { 94 | licenseNames.forEachIndexed { ln, li -> 95 | license { 96 | name.set(li) 97 | url.set(licenseUrls[ln]) 98 | } 99 | } 100 | } 101 | developers { 102 | developer { 103 | name.set(username) 104 | } 105 | } 106 | scm { 107 | connection.set(gitUrl) 108 | developerConnection.set(gitUrl) 109 | url.set(siteUrl) 110 | } 111 | } 112 | } 113 | } 114 | } -------------------------------------------------------------------------------- /deps.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | kotlinVer = "1.9.22" 3 | androidToolVer = "31.2.0" 4 | polyfillVer = "0.9.1" 5 | mockitoVer = "3.9.0" 6 | 7 | agpVer = "8.1.2" 8 | agpPatchIgnoredVer = "8.1.0" # To be used by backport version matching 9 | agpBackportVer = "8.0.1" 10 | agpBackportPatchIgnoredVer = "8.0.0" # To be used by backport version matching, e.g. apply backport patches when (7.1.0 <= ver < 7.2.0) 11 | 12 | [libraries] 13 | android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "agpVer" } 14 | android-tools-sdkcommon = { module = "com.android.tools:sdk-common", version.ref = "androidToolVer" } 15 | android-tools-sdklib = { module = "com.android.tools:sdklib", version.ref = "androidToolVer" } 16 | kotlin-std = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlinVer" } 17 | kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.3.2" } 18 | polyfill-main = { module = "me.2bab:polyfill", version.ref = "polyfillVer" } 19 | polyfill-res = { module = "me.2bab:polyfill-res", version.ref = "polyfillVer" } 20 | jfreesvg = { module = "org.jfree:jfreesvg", version = "3.3" } 21 | junit = { module = "junit:junit", version = "4.12" } 22 | mockito = { module = "org.mockito:mockito-core", version.ref = "mockitoVer" } 23 | mockitoInline = { module = "org.mockito:mockito-inline", version.ref = "mockitoVer" } 24 | hamcrest = { module = "org.hamcrest:hamcrest-library", version = "2.2" } 25 | kotlin-coroutine = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm", version = "1.6.0" } 26 | 27 | 28 | [bundles] 29 | 30 | [plugins] -------------------------------------------------------------------------------- /functional-test/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build/ -------------------------------------------------------------------------------- /functional-test/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("jvm") 3 | kotlin("plugin.serialization") 4 | } 5 | 6 | group = "me.2bab" 7 | 8 | java { 9 | withSourcesJar() 10 | withJavadocJar() 11 | sourceCompatibility = JavaVersion.VERSION_11 12 | targetCompatibility = JavaVersion.VERSION_17 13 | } 14 | 15 | dependencies { 16 | implementation(deps.kotlin.std) 17 | implementation(deps.kotlin.coroutine) 18 | implementation(platform("org.jetbrains.kotlin:kotlin-bom")) 19 | } 20 | 21 | testing { 22 | suites { 23 | val functionalTest by registering(JvmTestSuite::class) { 24 | useJUnitJupiter() 25 | testType.set(TestSuiteType.FUNCTIONAL_TEST) 26 | dependencies { 27 | implementation(deps.hamcrest) 28 | implementation("dev.gradleplugins:gradle-test-kit:7.4.2") 29 | implementation(deps.kotlin.coroutine) 30 | implementation(deps.kotlin.serialization) 31 | } 32 | } 33 | } 34 | } 35 | 36 | tasks.named("check") { 37 | dependsOn(testing.suites.named("functionalTest")) 38 | } 39 | 40 | tasks.withType { 41 | testLogging { 42 | this.showStandardStreams = true 43 | } 44 | } -------------------------------------------------------------------------------- /functional-test/src/functionalTest/kotlin/BasicFunctionalTest.kt: -------------------------------------------------------------------------------- 1 | 2 | import kotlinx.coroutines.Dispatchers 3 | import kotlinx.coroutines.async 4 | import kotlinx.coroutines.runBlocking 5 | import org.gradle.testkit.runner.GradleRunner 6 | import org.hamcrest.MatcherAssert.assertThat 7 | import org.hamcrest.Matchers.`is` 8 | import org.hamcrest.core.StringContains 9 | import org.junit.jupiter.api.BeforeAll 10 | import org.junit.jupiter.params.ParameterizedTest 11 | import org.junit.jupiter.params.provider.MethodSource 12 | import java.io.File 13 | import java.util.concurrent.TimeUnit 14 | 15 | 16 | class BasicFunctionalTest { 17 | 18 | companion object { 19 | 20 | private const val testProjectPath = "../sample" 21 | private const val spIntermediates = 22 | "./build/sample-%s/app/build/intermediates/scratch-paper/" 23 | 24 | @BeforeAll 25 | @JvmStatic 26 | fun buildTestProject() { 27 | if (File("../local.properties").exists()) { 28 | println("Publishing libraries to MavenLocal...") 29 | ("./gradlew" + " :scratchpaper:publishToMavenLocal" 30 | + " --stacktrace").runCommand(File("../")) 31 | println("All libraries published.") 32 | } 33 | runBlocking(Dispatchers.IO) { 34 | agpVerProvider().map { agpVer -> 35 | async { 36 | println( 37 | "Copying project for AGP [${agpVer}] from ${ 38 | File(testProjectPath).absolutePath 39 | }..." 40 | ) 41 | 42 | val targetProject = File("./build/sample-$agpVer") 43 | targetProject.deleteRecursively() 44 | File(testProjectPath).copyRecursively(targetProject) 45 | val settings = File(targetProject, "settings.gradle.kts") 46 | val newSettings = settings.readText() 47 | .replace( 48 | "= \"../\"", 49 | "= \"../../../\"" 50 | ) // Redirect the base dir 51 | .replace( 52 | "enabledCompositionBuild = true", 53 | "enabledCompositionBuild = false" 54 | ) // Force the app to find plugin from maven local 55 | .replace( 56 | "getVersion(\"agpVer\")", 57 | "\"$agpVer\"" 58 | ) // Hardcode agp version 59 | settings.writeText(newSettings) 60 | 61 | println("assembleFullDebug for [$agpVer]") 62 | 63 | GradleRunner.create() 64 | .withGradleVersion("8.5") 65 | .forwardOutput() 66 | .withArguments("clean", "assembleFullDebug", "--stacktrace") 67 | .withProjectDir(targetProject) 68 | .build() 69 | 70 | println("Testing...") 71 | } 72 | }.forEach { 73 | it.await() 74 | } 75 | } 76 | } 77 | 78 | @JvmStatic 79 | fun agpVerProvider(): List { 80 | val versions = File("../deps.versions.toml").readText() 81 | val regexPlaceHolder = "%s\\s\\=\\s\\\"([A-Za-z0-9\\.\\-]+)\\\"" 82 | val getVersion = { s: String -> 83 | regexPlaceHolder.format(s).toRegex().find(versions)!!.groupValues[1] 84 | } 85 | return listOf(getVersion("agpVer"), getVersion("agpBackportVer")) 86 | } 87 | 88 | fun String.runCommand(workingDir: File) { 89 | ProcessBuilder(*split(" ").toTypedArray()) 90 | .directory(workingDir) 91 | .redirectOutput(ProcessBuilder.Redirect.INHERIT) 92 | .redirectError(ProcessBuilder.Redirect.INHERIT) 93 | .start() 94 | .waitFor(15, TimeUnit.MINUTES) 95 | } 96 | } 97 | 98 | 99 | @ParameterizedTest 100 | @MethodSource("agpVerProvider") 101 | fun flavorSupport_Successfully(agpVer: String) { 102 | val fullDebug = File("${spIntermediates.format(agpVer)}/icons-fullDebug/") 103 | assertThat(fullDebug.exists(), `is`(true)) 104 | assertThat(fullDebug.isDirectory, `is`(true)) 105 | assertThat(fullDebug.listFiles().isNotEmpty(), `is`(true)) 106 | } 107 | 108 | @ParameterizedTest 109 | @MethodSource("agpVerProvider") 110 | fun pngIconsAreGenerated_Successfully(agpVer: String) { 111 | listOf( 112 | "mipmap-xxxhdpi", 113 | "mipmap-xxhdpi", 114 | "mipmap-xhdpi", 115 | "mipmap-hdpi", 116 | "mipmap-mdpi" 117 | ).forEach { 118 | val normalAppIcon = 119 | File("${spIntermediates.format(agpVer)}/icons-fullDebug/$it/ic_launcher.png") 120 | val roundAppIcon = 121 | File("${spIntermediates.format(agpVer)}/icons-fullDebug/$it/ic_launcher_round.png") 122 | assertThat(normalAppIcon.exists(), `is`(true)) 123 | assertThat(roundAppIcon.exists(), `is`(true)) 124 | } 125 | } 126 | 127 | @ParameterizedTest 128 | @MethodSource("agpVerProvider") 129 | fun xmlIconsAreGenerated_Successfully(agpVer: String) { 130 | val normalAppIcon = 131 | File("${spIntermediates.format(agpVer)}/icons-fullDebug/mipmap-anydpi-v26/ic_launcher.xml") 132 | val roundAppIcon = 133 | File("${spIntermediates.format(agpVer)}/icons-fullDebug/mipmap-anydpi-v26/ic_launcher_round.xml") 134 | assertThat(normalAppIcon.exists(), `is`(true)) 135 | assertThat(roundAppIcon.exists(), `is`(true)) 136 | assertThat(normalAppIcon.readText(), StringContains.containsString("ic_launcher_overlay")) 137 | assertThat( 138 | roundAppIcon.readText(), 139 | StringContains.containsString("ic_launcher_round_overlay") 140 | ) 141 | 142 | listOf( 143 | "ic_launcher_overlay.svg", 144 | "ic_launcher_overlay.xml", 145 | "ic_launcher_round_overlay.svg", 146 | "ic_launcher_round_overlay.xml" 147 | ).forEach { 148 | assertThat( 149 | File("${spIntermediates.format(agpVer)}/icons-fullDebug/drawable/$it").exists(), 150 | `is`(true) 151 | ) 152 | } 153 | } 154 | 155 | @ParameterizedTest 156 | @MethodSource("agpVerProvider") 157 | fun pngOverlayContentIsAttached_Correctly() { 158 | // TODO: Haven't found a simple&free OCR framework 159 | // to fulfill the test requirement. Will add the test once seeked. 160 | } 161 | 162 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/2BAB/ScratchPaper/db2838970e497becd75d1772513810be39afc6cd/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit 88 | 89 | # Use the maximum available, or set MAX_FD != -1 to use that value. 90 | MAX_FD=maximum 91 | 92 | warn () { 93 | echo "$*" 94 | } >&2 95 | 96 | die () { 97 | echo 98 | echo "$*" 99 | echo 100 | exit 1 101 | } >&2 102 | 103 | # OS specific support (must be 'true' or 'false'). 104 | cygwin=false 105 | msys=false 106 | darwin=false 107 | nonstop=false 108 | case "$( uname )" in #( 109 | CYGWIN* ) cygwin=true ;; #( 110 | Darwin* ) darwin=true ;; #( 111 | MSYS* | MINGW* ) msys=true ;; #( 112 | NONSTOP* ) nonstop=true ;; 113 | esac 114 | 115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 116 | 117 | 118 | # Determine the Java command to use to start the JVM. 119 | if [ -n "$JAVA_HOME" ] ; then 120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 121 | # IBM's JDK on AIX uses strange locations for the executables 122 | JAVACMD=$JAVA_HOME/jre/sh/java 123 | else 124 | JAVACMD=$JAVA_HOME/bin/java 125 | fi 126 | if [ ! -x "$JAVACMD" ] ; then 127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 128 | 129 | Please set the JAVA_HOME variable in your environment to match the 130 | location of your Java installation." 131 | fi 132 | else 133 | JAVACMD=java 134 | if ! command -v java >/dev/null 2>&1 135 | then 136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | fi 142 | 143 | # Increase the maximum file descriptors if we can. 144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 145 | case $MAX_FD in #( 146 | max*) 147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 148 | # shellcheck disable=SC2039,SC3045 149 | MAX_FD=$( ulimit -H -n ) || 150 | warn "Could not query maximum file descriptor limit" 151 | esac 152 | case $MAX_FD in #( 153 | '' | soft) :;; #( 154 | *) 155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 156 | # shellcheck disable=SC2039,SC3045 157 | ulimit -n "$MAX_FD" || 158 | warn "Could not set maximum file descriptor limit to $MAX_FD" 159 | esac 160 | fi 161 | 162 | # Collect all arguments for the java command, stacking in reverse order: 163 | # * args from the command line 164 | # * the main class name 165 | # * -classpath 166 | # * -D...appname settings 167 | # * --module-path (only if needed) 168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 169 | 170 | # For Cygwin or MSYS, switch paths to Windows format before running java 171 | if "$cygwin" || "$msys" ; then 172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 174 | 175 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 176 | 177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 178 | for arg do 179 | if 180 | case $arg in #( 181 | -*) false ;; # don't mess with options #( 182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 183 | [ -e "$t" ] ;; #( 184 | *) false ;; 185 | esac 186 | then 187 | arg=$( cygpath --path --ignore --mixed "$arg" ) 188 | fi 189 | # Roll the args list around exactly as many times as the number of 190 | # args, so each arg winds up back in the position where it started, but 191 | # possibly modified. 192 | # 193 | # NB: a `for` loop captures its iteration list before it begins, so 194 | # changing the positional parameters here affects neither the number of 195 | # iterations, nor the values presented in `arg`. 196 | shift # remove old arg 197 | set -- "$@" "$arg" # push replacement arg 198 | done 199 | fi 200 | 201 | 202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 204 | 205 | # Collect all arguments for the java command: 206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 207 | # and any embedded shellness will be escaped. 208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 209 | # treated as '${Hostname}' itself on the command line. 210 | 211 | set -- \ 212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 213 | -classpath "$CLASSPATH" \ 214 | org.gradle.wrapper.GradleWrapperMain \ 215 | "$@" 216 | 217 | # Stop when "xargs" is not available. 218 | if ! command -v xargs >/dev/null 2>&1 219 | then 220 | die "xargs is not available" 221 | fi 222 | 223 | # Use "xargs" to parse quoted args. 224 | # 225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 226 | # 227 | # In Bash we could simply go: 228 | # 229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 230 | # set -- "${ARGS[@]}" "$@" 231 | # 232 | # but POSIX shell has neither arrays nor command substitution, so instead we 233 | # post-process each arg (as a line of input to sed) to backslash-escape any 234 | # character that might be a shell metacharacter, then use eval to reverse 235 | # that process (while maintaining the separation between arguments), and wrap 236 | # the whole thing up as a single "set" statement. 237 | # 238 | # This will of course break if any of these variables contains a newline or 239 | # an unmatched quote. 240 | # 241 | 242 | eval "set -- $( 243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 244 | xargs -n1 | 245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 246 | tr '\n' ' ' 247 | )" '"$@"' 248 | 249 | exec "$JAVACMD" "$@" 250 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /images/launcher_icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/2BAB/ScratchPaper/db2838970e497becd75d1772513810be39afc6cd/images/launcher_icons.png -------------------------------------------------------------------------------- /publish.sh: -------------------------------------------------------------------------------- 1 | ./gradlew clean :scratchpaper:publishAllPublicationsToSonatypeRepository :scratchpaper:releaseArtifactsToGithub -------------------------------------------------------------------------------- /publish_to_local.sh: -------------------------------------------------------------------------------- 1 | ./gradlew clean :scratchpaper:assemble :scratchpaper:publishToMavenLocal 2 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.android.application") 3 | kotlin("android") 4 | id("me.2bab.scratchpaper") 5 | } 6 | 7 | android { 8 | namespace = "me.xx2bab.scratchpaper.sample" 9 | compileSdk = 34 10 | defaultConfig { 11 | applicationId = "me.xx2bab.scratchpaper.sample" 12 | minSdk = 23 13 | targetSdk = 34 14 | versionCode = 1 15 | versionName = "3.3.0" 16 | } 17 | 18 | buildTypes { 19 | getByName("debug") { 20 | isMinifyEnabled = false 21 | applicationIdSuffix = ".debug" 22 | versionNameSuffix = "-debug" 23 | } 24 | getByName("release") { 25 | isMinifyEnabled = false 26 | } 27 | } 28 | 29 | flavorDimensions += "featureScope" 30 | productFlavors { 31 | create("demo") { 32 | dimension = "featureScope" 33 | applicationIdSuffix = ".demo" 34 | versionNameSuffix = "-demo" 35 | } 36 | create("full") { 37 | dimension = "featureScope" 38 | applicationIdSuffix = ".full" 39 | versionNameSuffix = "-full" 40 | } 41 | } 42 | 43 | splits { 44 | density { 45 | isEnable = true 46 | reset() 47 | include("mdpi") 48 | compatibleScreens("xlarge") 49 | } 50 | } 51 | 52 | sourceSets["main"].java.srcDir("src/main/kotlin") 53 | 54 | compileOptions { 55 | sourceCompatibility = JavaVersion.VERSION_11 56 | targetCompatibility = JavaVersion.VERSION_17 57 | } 58 | 59 | kotlinOptions { 60 | jvmTarget = "17" 61 | } 62 | } 63 | 64 | 65 | dependencies { 66 | implementation(deps.kotlin.std) 67 | implementation("androidx.appcompat:appcompat:1.6.1") 68 | } 69 | 70 | // Run `./gradlew clean assembleFullDebug` for testing 71 | scratchPaper { 72 | // Main feature flags. !!! Mandatory field. 73 | // Can not be lazily set, it's valid only before "afterEvaluate{}". 74 | // In this way, only "FullDebug" variant will get icon overlays 75 | enableByVariant { variant -> 76 | variant.name.contains("debug", true) 77 | && variant.name.contains("full", true) 78 | } 79 | 80 | // !!! Mandatory field. 81 | // Can be lazily set even after configuration phrase. 82 | iconNames.set("ic_launcher, ic_launcher_round") 83 | 84 | // Some sub-feature flags 85 | enableXmlIconsRemoval.set(false) // Can be lazily set even after configuration phrase. 86 | forceUpdateIcons = false // Can not be lazily set, it's valid only before "afterEvaluate{}". 87 | 88 | // ICON_OVERLAY styles, contents. 89 | style { 90 | textSize.set(8) 91 | textColor.set("#FFFFFFFF") // Accepts 3 kinds of format: "FFF", "FFFFFF", "FFFFFFFF". 92 | lineSpace.set(2) 93 | backgroundColor.set("#99000000") // Same as textColor. 94 | } 95 | 96 | content { 97 | showVersionName.set(true) 98 | showVariantName.set(true) 99 | showGitShortId.set(true) 100 | showDateTime.set(true) 101 | extraInfo.set("For QA") 102 | } 103 | } -------------------------------------------------------------------------------- /sample/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /sample/app/src/main/java/me/xx2bab/scratchpaper/sample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package me.xx2bab.scratchpaper.sample 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | 6 | class MainActivity : AppCompatActivity() { 7 | 8 | override fun onCreate(savedInstanceState: Bundle?) { 9 | super.onCreate(savedInstanceState) 10 | setContentView(R.layout.activity_main) 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /sample/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /sample/app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /sample/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | -------------------------------------------------------------------------------- /sample/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /sample/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /sample/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/2BAB/ScratchPaper/db2838970e497becd75d1772513810be39afc6cd/sample/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/2BAB/ScratchPaper/db2838970e497becd75d1772513810be39afc6cd/sample/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/2BAB/ScratchPaper/db2838970e497becd75d1772513810be39afc6cd/sample/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/2BAB/ScratchPaper/db2838970e497becd75d1772513810be39afc6cd/sample/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/2BAB/ScratchPaper/db2838970e497becd75d1772513810be39afc6cd/sample/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/2BAB/ScratchPaper/db2838970e497becd75d1772513810be39afc6cd/sample/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/2BAB/ScratchPaper/db2838970e497becd75d1772513810be39afc6cd/sample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/2BAB/ScratchPaper/db2838970e497becd75d1772513810be39afc6cd/sample/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/2BAB/ScratchPaper/db2838970e497becd75d1772513810be39afc6cd/sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/2BAB/ScratchPaper/db2838970e497becd75d1772513810be39afc6cd/sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /sample/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Scratch Paper 3 | 4 | -------------------------------------------------------------------------------- /sample/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | -------------------------------------------------------------------------------- /sample/build_debug.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ./gradlew clean assembleFullDebug --no-daemon -Dorg.gradle.debug=true --info 3 | 4 | echo 'Done. Check the outputs on ./app/build/intermediates/scratch-paper/' -------------------------------------------------------------------------------- /sample/build_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ./gradlew clean assembleFullDebug 3 | 4 | echo 'Done. Check the outputs on ./app/build/intermediates/scratch-paper/' -------------------------------------------------------------------------------- /sample/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Kotlin code style for this project: "official" or "obsolete": 19 | kotlin.code.style=official -------------------------------------------------------------------------------- /sample/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/2BAB/ScratchPaper/db2838970e497becd75d1772513810be39afc6cd/sample/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /sample/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /sample/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit 88 | 89 | # Use the maximum available, or set MAX_FD != -1 to use that value. 90 | MAX_FD=maximum 91 | 92 | warn () { 93 | echo "$*" 94 | } >&2 95 | 96 | die () { 97 | echo 98 | echo "$*" 99 | echo 100 | exit 1 101 | } >&2 102 | 103 | # OS specific support (must be 'true' or 'false'). 104 | cygwin=false 105 | msys=false 106 | darwin=false 107 | nonstop=false 108 | case "$( uname )" in #( 109 | CYGWIN* ) cygwin=true ;; #( 110 | Darwin* ) darwin=true ;; #( 111 | MSYS* | MINGW* ) msys=true ;; #( 112 | NONSTOP* ) nonstop=true ;; 113 | esac 114 | 115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 116 | 117 | 118 | # Determine the Java command to use to start the JVM. 119 | if [ -n "$JAVA_HOME" ] ; then 120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 121 | # IBM's JDK on AIX uses strange locations for the executables 122 | JAVACMD=$JAVA_HOME/jre/sh/java 123 | else 124 | JAVACMD=$JAVA_HOME/bin/java 125 | fi 126 | if [ ! -x "$JAVACMD" ] ; then 127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 128 | 129 | Please set the JAVA_HOME variable in your environment to match the 130 | location of your Java installation." 131 | fi 132 | else 133 | JAVACMD=java 134 | if ! command -v java >/dev/null 2>&1 135 | then 136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | fi 142 | 143 | # Increase the maximum file descriptors if we can. 144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 145 | case $MAX_FD in #( 146 | max*) 147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 148 | # shellcheck disable=SC2039,SC3045 149 | MAX_FD=$( ulimit -H -n ) || 150 | warn "Could not query maximum file descriptor limit" 151 | esac 152 | case $MAX_FD in #( 153 | '' | soft) :;; #( 154 | *) 155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 156 | # shellcheck disable=SC2039,SC3045 157 | ulimit -n "$MAX_FD" || 158 | warn "Could not set maximum file descriptor limit to $MAX_FD" 159 | esac 160 | fi 161 | 162 | # Collect all arguments for the java command, stacking in reverse order: 163 | # * args from the command line 164 | # * the main class name 165 | # * -classpath 166 | # * -D...appname settings 167 | # * --module-path (only if needed) 168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 169 | 170 | # For Cygwin or MSYS, switch paths to Windows format before running java 171 | if "$cygwin" || "$msys" ; then 172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 174 | 175 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 176 | 177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 178 | for arg do 179 | if 180 | case $arg in #( 181 | -*) false ;; # don't mess with options #( 182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 183 | [ -e "$t" ] ;; #( 184 | *) false ;; 185 | esac 186 | then 187 | arg=$( cygpath --path --ignore --mixed "$arg" ) 188 | fi 189 | # Roll the args list around exactly as many times as the number of 190 | # args, so each arg winds up back in the position where it started, but 191 | # possibly modified. 192 | # 193 | # NB: a `for` loop captures its iteration list before it begins, so 194 | # changing the positional parameters here affects neither the number of 195 | # iterations, nor the values presented in `arg`. 196 | shift # remove old arg 197 | set -- "$@" "$arg" # push replacement arg 198 | done 199 | fi 200 | 201 | 202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 204 | 205 | # Collect all arguments for the java command: 206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 207 | # and any embedded shellness will be escaped. 208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 209 | # treated as '${Hostname}' itself on the command line. 210 | 211 | set -- \ 212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 213 | -classpath "$CLASSPATH" \ 214 | org.gradle.wrapper.GradleWrapperMain \ 215 | "$@" 216 | 217 | # Stop when "xargs" is not available. 218 | if ! command -v xargs >/dev/null 2>&1 219 | then 220 | die "xargs is not available" 221 | fi 222 | 223 | # Use "xargs" to parse quoted args. 224 | # 225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 226 | # 227 | # In Bash we could simply go: 228 | # 229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 230 | # set -- "${ARGS[@]}" "$@" 231 | # 232 | # but POSIX shell has neither arrays nor command substitution, so instead we 233 | # post-process each arg (as a line of input to sed) to backslash-escape any 234 | # character that might be a shell metacharacter, then use eval to reverse 235 | # that process (while maintaining the separation between arguments), and wrap 236 | # the whole thing up as a single "set" statement. 237 | # 238 | # This will of course break if any of these variables contains a newline or 239 | # an unmatched quote. 240 | # 241 | 242 | eval "set -- $( 243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 244 | xargs -n1 | 245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 246 | tr '\n' ' ' 247 | )" '"$@"' 248 | 249 | exec "$JAVACMD" "$@" 250 | -------------------------------------------------------------------------------- /sample/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /sample/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "scratch-paper-root" 2 | 3 | pluginManagement { 4 | extra["externalDependencyBaseDir"] = "../" 5 | val versions = 6 | file(extra["externalDependencyBaseDir"].toString() + "deps.versions.toml").readText() 7 | val regexPlaceHolder = "%s\\s\\=\\s\\\"([A-Za-z0-9\\.\\-]+)\\\"" 8 | val getVersion = 9 | { s: String -> regexPlaceHolder.format(s).toRegex().find(versions)!!.groupValues[1] } 10 | 11 | plugins { 12 | kotlin("android") version getVersion("kotlinVer") apply false 13 | id("com.android.application") version getVersion("agpVer") apply false 14 | kotlin("plugin.serialization") version getVersion("kotlinVer") apply false 15 | // id("me.2bab.scratchpaper") version "3.2.0" apply false 16 | } 17 | resolutionStrategy { 18 | eachPlugin { 19 | if (requested.id.id == "me.2bab.scratchpaper") { 20 | // It will be replaced by a local module using `includeBuild` below, 21 | // thus we just put a generic version (+) here. 22 | useModule("me.2bab:scratchpaper:+") 23 | } 24 | } 25 | } 26 | repositories { 27 | mavenLocal() 28 | mavenCentral() 29 | google() 30 | gradlePluginPortal() 31 | } 32 | } 33 | 34 | val externalDependencyBaseDir = extra["externalDependencyBaseDir"].toString() 35 | val enabledCompositionBuild = true 36 | 37 | dependencyResolutionManagement { 38 | repositories { 39 | mavenLocal() 40 | google() 41 | mavenCentral() 42 | } 43 | versionCatalogs { 44 | create("deps") { 45 | from(files(externalDependencyBaseDir + "deps.versions.toml")) 46 | } 47 | } 48 | } 49 | 50 | include(":app") 51 | if (enabledCompositionBuild) { 52 | includeBuild(externalDependencyBaseDir) { 53 | dependencySubstitution { 54 | substitute(module("me.2bab:scratchpaper")) 55 | .using(project(":scratchpaper")) 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /scratchpaper/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build/ -------------------------------------------------------------------------------- /scratchpaper/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gradle-plugin") 3 | `kotlin-dsl` 4 | `github-release` 5 | `maven-central-publish` 6 | kotlin("plugin.serialization") 7 | } 8 | 9 | group = "me.2bab" 10 | version = BuildConfig.Versions.scratchPaperVersion 11 | 12 | 13 | java { 14 | withSourcesJar() 15 | withJavadocJar() 16 | sourceCompatibility = JavaVersion.VERSION_11 17 | targetCompatibility = JavaVersion.VERSION_17 18 | } 19 | 20 | gradlePlugin { 21 | plugins { 22 | create("scratchpaper") { 23 | id = "me.2bab.scratchpaper" 24 | implementationClass = "me.xx2bab.scratchpaper.ScratchPaperPlugin" 25 | displayName = "me.2bab.scratchpaper" 26 | } 27 | } 28 | } 29 | 30 | dependencies { 31 | implementation(gradleApi()) 32 | 33 | implementation(deps.kotlin.std) 34 | implementation(deps.kotlin.serialization) 35 | 36 | compileOnly(deps.android.gradle.plugin) 37 | compileOnly(deps.android.tools.sdkcommon) 38 | compileOnly(deps.android.tools.sdklib) 39 | 40 | implementation(deps.polyfill.main) 41 | implementation(deps.jfreesvg) 42 | 43 | testImplementation(gradleTestKit()) 44 | testImplementation(deps.junit) 45 | testImplementation(deps.mockito) 46 | testImplementation(deps.mockitoInline) 47 | } -------------------------------------------------------------------------------- /scratchpaper/src/main/kotlin/me/xx2bab/scratchpaper/IconOverlayContent.kt: -------------------------------------------------------------------------------- 1 | package me.xx2bab.scratchpaper 2 | 3 | import org.gradle.api.model.ObjectFactory 4 | import org.gradle.api.provider.Property 5 | import org.gradle.api.tasks.Input 6 | import org.gradle.kotlin.dsl.property 7 | import javax.inject.Inject 8 | 9 | open class IconOverlayContent @Inject constructor( 10 | objects: ObjectFactory 11 | ) { 12 | 13 | @Input 14 | val showVersionName: Property = objects.property().convention(true) 15 | 16 | @Input 17 | val showVariantName: Property = objects.property().convention(true) 18 | 19 | @Input 20 | val showGitShortId: Property = objects.property().convention(true) 21 | 22 | @Input 23 | val showDateTime: Property = objects.property().convention(true) // dd-MM,HH:mm 24 | 25 | @Input 26 | val extraInfo: Property = objects.property().convention("") 27 | } -------------------------------------------------------------------------------- /scratchpaper/src/main/kotlin/me/xx2bab/scratchpaper/IconOverlayStyle.kt: -------------------------------------------------------------------------------- 1 | package me.xx2bab.scratchpaper 2 | 3 | import org.gradle.api.model.ObjectFactory 4 | import org.gradle.api.provider.Property 5 | import org.gradle.kotlin.dsl.property 6 | import javax.inject.Inject 7 | 8 | open class IconOverlayStyle @Inject constructor( 9 | objects: ObjectFactory 10 | ) { 11 | 12 | val textSize: Property = objects.property().convention(12) 13 | 14 | val textColor: Property = objects.property().convention("#FFFFFFFF") 15 | 16 | val lineSpace: Property = objects.property().convention(4) 17 | 18 | val backgroundColor: Property = objects.property().convention("#CC000000") 19 | 20 | } -------------------------------------------------------------------------------- /scratchpaper/src/main/kotlin/me/xx2bab/scratchpaper/ScratchPaperExtension.kt: -------------------------------------------------------------------------------- 1 | package me.xx2bab.scratchpaper 2 | 3 | import com.android.build.api.variant.Variant 4 | import groovy.lang.Closure 5 | import org.gradle.api.Action 6 | import org.gradle.api.model.ObjectFactory 7 | import org.gradle.kotlin.dsl.property 8 | import java.awt.Color 9 | import javax.inject.Inject 10 | 11 | open class ScratchPaperExtension @Inject constructor( 12 | objects: ObjectFactory 13 | ) { 14 | 15 | var kotlinEnableByVariant: EnableByVariant? = null 16 | 17 | var groovyEnableByVariant: Closure? = null 18 | 19 | // For Gradle Kotlin DSL 20 | fun enableByVariant(selector: EnableByVariant) { 21 | kotlinEnableByVariant = selector 22 | } 23 | 24 | // For Gradle Groovy DSL 25 | fun enableByVariant(selector: Closure) { 26 | groovyEnableByVariant = selector.dehydrate() 27 | } 28 | 29 | var forceUpdateIcons: Boolean = false 30 | 31 | // Experimental field 32 | // @see IconOverlayGenerator#removeXmlIconFiles 33 | var enableXmlIconsRemoval = objects.property().convention(false) 34 | 35 | var iconNames = objects.property().convention("ic_launcher, ic_launcher_round") 36 | 37 | val style: IconOverlayStyle = objects.newInstance( 38 | IconOverlayStyle::class.java 39 | ) 40 | 41 | fun style(action: Action) { 42 | action.execute(style) 43 | } 44 | 45 | val content: IconOverlayContent = objects.newInstance( 46 | IconOverlayContent::class.java 47 | ) 48 | 49 | fun content(action: Action) { 50 | action.execute(content) 51 | } 52 | 53 | 54 | companion object { 55 | 56 | fun isFeatureEnabled(variant: Variant, 57 | kotlinEnableByVariant: EnableByVariant?, 58 | groovyEnableByVariant: Closure? 59 | ): Boolean = when { 60 | kotlinEnableByVariant != null -> { 61 | kotlinEnableByVariant.invoke(variant) 62 | } 63 | groovyEnableByVariant != null -> { 64 | groovyEnableByVariant.call(variant) 65 | } 66 | else -> false 67 | } 68 | 69 | 70 | fun parseBackgroundColor(backgroundColor: String): Color { 71 | val color: IntArray = hexColorToRGBIntArray(backgroundColor) 72 | return Color(color[1], color[2], color[3], color[0]) 73 | } 74 | 75 | fun parseTextColor(textColor: String): Color { 76 | val color: IntArray = hexColorToRGBIntArray(textColor) 77 | return Color(color[1], color[2], color[3], color[0]) 78 | } 79 | 80 | 81 | private fun hexColorToRGBIntArray(hexColor: String): IntArray { 82 | val processedHexColor: String 83 | if (!hexColor.startsWith("#")) { 84 | throw IllegalArgumentException() 85 | } else { 86 | processedHexColor = hexColor.replace("#", "") 87 | } 88 | val argbIntArray = intArrayOf(0, 0, 0, 0) 89 | val colorLength = processedHexColor.length 90 | val octetHexColor: String 91 | 92 | octetHexColor = when (colorLength) { 93 | 3 -> "FF" + processedHexColor.let { 94 | val builder = StringBuilder() 95 | for (i in 0..2) { 96 | builder.append(it.substring(i, i + 1)).append(it.substring(i, i + 1)) 97 | } 98 | builder.toString() 99 | } 100 | 101 | 6 -> "FF$processedHexColor" 102 | 103 | 8 -> processedHexColor 104 | 105 | else -> { 106 | throw IllegalArgumentException() 107 | } 108 | } 109 | 110 | for (i in 0..3) { 111 | argbIntArray[i] = octetHexColor.substring(2 * i, 2 * i + 2).toInt(16) 112 | } 113 | 114 | return argbIntArray 115 | } 116 | } 117 | } 118 | 119 | internal typealias EnableByVariant = (variant: Variant) -> Boolean -------------------------------------------------------------------------------- /scratchpaper/src/main/kotlin/me/xx2bab/scratchpaper/ScratchPaperPlugin.kt: -------------------------------------------------------------------------------- 1 | package me.xx2bab.scratchpaper 2 | 3 | import com.android.build.api.variant.ApplicationAndroidComponentsExtension 4 | import com.android.build.api.variant.VariantOutput 5 | import me.xx2bab.polyfill.PolyfilledMultipleArtifact 6 | import me.xx2bab.polyfill.PolyfilledSingleArtifact 7 | import me.xx2bab.polyfill.artifactsPolyfill 8 | import me.xx2bab.polyfill.getBuildToolInfo 9 | import me.xx2bab.polyfill.getCapitalizedName 10 | import me.xx2bab.polyfill.getTaskContainer 11 | import me.xx2bab.scratchpaper.icon.AddIconOverlayTaskAction 12 | import me.xx2bab.scratchpaper.utils.CacheLocation 13 | import me.xx2bab.scratchpaper.utils.Logger 14 | import org.gradle.api.Plugin 15 | import org.gradle.api.Project 16 | import org.gradle.kotlin.dsl.apply 17 | import org.gradle.kotlin.dsl.create 18 | 19 | class ScratchPaperPlugin : Plugin { 20 | 21 | private val extensionName = "scratchPaper" 22 | private val groupName = "scratch-paper" 23 | 24 | override fun apply(project: Project) { 25 | Logger.init(project) 26 | project.apply(plugin = "me.2bab.polyfill") 27 | val config = project.extensions.create(extensionName) 28 | 29 | val androidExt = 30 | project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java) 31 | androidExt.onVariants { variant -> 32 | val variantName = variant.getCapitalizedName() 33 | // TODO: find a better way to support both SINGLE and MULTI APKs version names 34 | val mainOutput: VariantOutput = variant.outputs[0] 35 | 36 | // For icon overlay 37 | // Check feature flag 38 | if (!ScratchPaperExtension.isFeatureEnabled( 39 | variant, 40 | config.kotlinEnableByVariant, 41 | config.groovyEnableByVariant 42 | ) 43 | ) { 44 | return@onVariants 45 | } 46 | 47 | // Add icon overlay 48 | val addIconOverlayTaskProvider = AddIconOverlayTaskAction( 49 | buildToolInfoProvider = variant.getBuildToolInfo(project), 50 | allInputResourcesProvider = variant.artifactsPolyfill.getAll( 51 | PolyfilledMultipleArtifact.ALL_RESOURCES 52 | ), 53 | variantName = variantName, 54 | versionName = mainOutput.versionName, 55 | iconNamesProvider = config.iconNames, 56 | enableXmlIconsRemovalProvider = config.enableXmlIconsRemoval, 57 | styleConfigProvider = config.style, 58 | contentConfigProvider = config.content, 59 | iconCacheDirProvider = CacheLocation.getCacheDir(project, "icons-${variant.name}") 60 | ) 61 | variant.artifactsPolyfill.use( 62 | action = addIconOverlayTaskProvider, 63 | toInPlaceUpdate = PolyfilledSingleArtifact.MERGED_RESOURCES 64 | ) 65 | 66 | // To decide whether the merge task should always run for 67 | // collecting the latest icons that can contain timestamp update. 68 | if (config.forceUpdateIcons) { 69 | project.afterEvaluate { 70 | val mergeTask = variant.getTaskContainer().mergeResourcesTask.get() 71 | mergeTask.outputs.upToDateWhen { false } 72 | } 73 | } 74 | 75 | } 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /scratchpaper/src/main/kotlin/me/xx2bab/scratchpaper/icon/Aapt2Operations.kt: -------------------------------------------------------------------------------- 1 | package me.xx2bab.scratchpaper.icon 2 | 3 | import me.xx2bab.polyfill.tools.CommandLineKit 4 | import java.io.File 5 | 6 | fun compileResDir( 7 | aapt2ExecutorPath: String, targetDir: File, resFiles: List 8 | ) { 9 | CommandLineKit.runCommand("$aapt2ExecutorPath compile --legacy " 10 | + "-o ${targetDir.absolutePath} " 11 | + resFiles.joinToString(separator = " ") { it.absolutePath } 12 | ) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /scratchpaper/src/main/kotlin/me/xx2bab/scratchpaper/icon/AdaptiveIconProcessor.kt: -------------------------------------------------------------------------------- 1 | package me.xx2bab.scratchpaper.icon 2 | 3 | import com.android.ide.common.vectordrawable.Svg2Vector 4 | import me.xx2bab.scratchpaper.utils.Logger 5 | import org.jfree.graphics2d.svg.SVGGraphics2D 6 | import org.jfree.graphics2d.svg.SVGUtils 7 | import org.w3c.dom.Document 8 | import org.w3c.dom.Element 9 | import java.awt.Graphics2D 10 | import java.awt.font.TextLayout 11 | import java.io.File 12 | import javax.xml.parsers.DocumentBuilderFactory 13 | import javax.xml.transform.TransformerFactory 14 | import javax.xml.transform.dom.DOMSource 15 | import javax.xml.transform.stream.StreamResult 16 | 17 | 18 | /** 19 | * In this Processor, we generate the SVG for overlay at first. Then we convert it 20 | * to Android Vector Drawable XML file, and merge it with the original icon. To deal 21 | * with SVG stuffs, we use "org.jfree:jfreesvg:3.3" now. If you need more advanced 22 | * functions, can choose "org.apache.xmlgraphics:batik-svgpp:1.10" as well. 23 | * 24 | * @link https://github.com/jfree/jfreesvg 25 | * @link https://github.com/jfree/jfree-demos 26 | * @link https://xmlgraphics.apache.org/batik/using/svg-generator.html 27 | */ 28 | class AdaptiveIconProcessor( 29 | originIcon: File, 30 | destDir: File, 31 | param: IconProcessorParam 32 | ) : BaseIconProcessor(originIcon, destDir, param) { 33 | 34 | private val attrDrawable = "android:drawable" 35 | private val tagForeground = "foreground" 36 | private val tagLayerList = "layer-list" 37 | private val tagItem = "item" 38 | private val tagAdaptiveIcon = "adaptive-icon" 39 | 40 | override fun getSize(): Pair { 41 | return Pair(width, height) 42 | } 43 | 44 | override fun getGraphic(): Graphics2D { 45 | return graphic 46 | } 47 | 48 | override fun drawText(line: String, x: Int, y: Int) { 49 | // Do not use Graphics2D.drawString(line: String, x: Int, y: Int), it will generates String 50 | // with in SVG file, and Android Vector Converter doesn't support . 51 | // Since we want to get a good compatible experience, so we draw text in to solve it. 52 | // @see com.android.ide.common.vectordrawable.Svg2Vector#unsupportedSvgNodes 53 | val tl = TextLayout(line, getGraphic().font, getGraphic().fontRenderContext) 54 | tl.draw(getGraphic(), x.toFloat(), y.toFloat()) 55 | } 56 | 57 | override fun writeIcon(): Array { 58 | // prepare destination file and its directory. 59 | // Creating a directory is to separate images from different pixel dimensions, 60 | // and support the AAPT2 compiling correctly(it requires the resource file 61 | // is put inside a res-dimension dir like "mipmap-xxhdpi"). 62 | val imageParentFile = File(destDir, originIcon.parentFile.name) 63 | if (!imageParentFile.exists() && !imageParentFile.mkdirs()) { 64 | Logger.e("Can not create cache directory for ScratchPaper.") 65 | } 66 | val destIcon = File(imageParentFile, originIcon.name).apply { createNewFile() } 67 | 68 | // generate overlay svg & convert svg to vector drawable xml 69 | val commonDrawableDir = File(destIcon.parentFile.parent + File.separator + "drawable").apply { mkdir() } 70 | val overlaySVG = File(commonDrawableDir, "${destIcon.nameWithoutExtension}_overlay.svg") 71 | val overlayVectorDrawableFileName = "${destIcon.nameWithoutExtension}_overlay.xml" 72 | val overlayVectorDrawable = File(commonDrawableDir, overlayVectorDrawableFileName).apply { createNewFile() } 73 | SVGUtils.writeToSVG(overlaySVG, (getGraphic() as SVGGraphics2D).svgElement) 74 | val out = overlayVectorDrawable.outputStream() 75 | Svg2Vector.parseSvgToXml(overlaySVG.toPath(), out) 76 | 77 | // append overlay to 78 | val itemDrawableElement = originIconXmlDoc.createElement(tagItem) 79 | val drawableAttr = originIconXmlDoc.createAttribute(attrDrawable) 80 | drawableAttr.value = "@drawable/$overlayVectorDrawableFileName".removeSuffix(".xml") 81 | itemDrawableElement.setAttributeNode(drawableAttr) 82 | layerList.appendChild(itemDrawableElement) 83 | 84 | // write to destination 85 | val transformerFactory = TransformerFactory.newInstance() 86 | val transformer = transformerFactory.newTransformer() 87 | val source = DOMSource(originIconXmlDoc) 88 | val result = StreamResult(destIcon) 89 | transformer.transform(source, result) 90 | 91 | return arrayOf(destIcon, overlayVectorDrawable) 92 | } 93 | 94 | private val width = 100 95 | private val height = 100 96 | private val graphic: Graphics2D 97 | private val originIconXmlDoc: Document = DocumentBuilderFactory.newInstance() 98 | .newDocumentBuilder().parse(originIcon) 99 | private var layerList: Element 100 | 101 | init { 102 | 103 | // parse foreground node & clean all attributes and childs 104 | var drawableInForeground: String? = null 105 | 106 | var foregroundElement = originIconXmlDoc.getElementsByTagName(tagForeground).item(0) 107 | if (foregroundElement != null) { 108 | if (foregroundElement.attributes.getNamedItem(attrDrawable) != null) { 109 | drawableInForeground = foregroundElement.attributes.getNamedItem(attrDrawable).nodeValue 110 | foregroundElement.attributes.removeNamedItem(attrDrawable) 111 | } 112 | } else { 113 | foregroundElement = originIconXmlDoc.createElement(tagForeground) 114 | val adaptiveIconNode = originIconXmlDoc.getElementsByTagName(tagAdaptiveIcon).item(0) 115 | adaptiveIconNode.appendChild(foregroundElement) 116 | } 117 | 118 | // add a as its only one child 119 | // append all childs & attributes to new 120 | layerList = originIconXmlDoc.createElement(tagLayerList) 121 | foregroundElement.appendChild(layerList) 122 | 123 | if (drawableInForeground != null) { 124 | val itemDrawableElement = originIconXmlDoc.createElement(tagItem) 125 | val drawableAttr = originIconXmlDoc.createAttribute(attrDrawable) 126 | drawableAttr.value = drawableInForeground 127 | itemDrawableElement.setAttributeNode(drawableAttr) 128 | layerList.appendChild(itemDrawableElement) 129 | } 130 | 131 | // init a new Graphic2D object to draw overlay 132 | graphic = SVGGraphics2D(width, height) 133 | } 134 | 135 | 136 | } -------------------------------------------------------------------------------- /scratchpaper/src/main/kotlin/me/xx2bab/scratchpaper/icon/AddIconOverlayTaskAction.kt: -------------------------------------------------------------------------------- 1 | package me.xx2bab.scratchpaper.icon 2 | 3 | import com.android.sdklib.BuildToolInfo 4 | import kotlinx.serialization.json.JsonElement 5 | import kotlinx.serialization.json.JsonNull 6 | import kotlinx.serialization.json.JsonObject 7 | import kotlinx.serialization.json.JsonPrimitive 8 | import me.xx2bab.polyfill.PolyfillAction 9 | import me.xx2bab.polyfill.tools.CommandLineKit 10 | import me.xx2bab.scratchpaper.IconOverlayContent 11 | import me.xx2bab.scratchpaper.IconOverlayStyle 12 | import me.xx2bab.scratchpaper.ScratchPaperExtension 13 | import org.gradle.api.Task 14 | import org.gradle.api.file.Directory 15 | import org.gradle.api.provider.Property 16 | import org.gradle.api.provider.Provider 17 | import java.io.File 18 | import java.time.LocalDateTime 19 | import java.time.format.DateTimeFormatter 20 | 21 | class AddIconOverlayTaskAction( 22 | private val buildToolInfoProvider: Provider, 23 | private val allInputResourcesProvider: Provider>, 24 | private val variantName: String, 25 | private val versionName: Property, 26 | private val iconNamesProvider: Property, 27 | private val enableXmlIconsRemovalProvider: Property, 28 | private val styleConfigProvider: IconOverlayStyle, 29 | private val contentConfigProvider: IconOverlayContent, 30 | private val iconCacheDirProvider: Provider, 31 | ) : PolyfillAction { 32 | 33 | override fun onTaskConfigure(task: Task) { 34 | task.inputs.property("variantName", variantName) 35 | task.inputs.property("versionName", versionName.get()) 36 | task.inputs.property("iconNamesProvider", iconNamesProvider.get()) 37 | task.inputs.property("enableXmlIconsRemovalProvider", enableXmlIconsRemovalProvider.get()) 38 | 39 | styleConfigProvider.apply { 40 | val map = mapOf( 41 | "textSize" to textSize.get(), 42 | "textColor" to textColor.get(), 43 | "lineSpace" to lineSpace.get(), 44 | "backgroundColor" to backgroundColor.get() 45 | ).toJsonObject() 46 | task.inputs.property("styleConfigProvider", map.toString()) 47 | } 48 | 49 | contentConfigProvider.apply { 50 | val map = mapOf( 51 | "showVersionName" to showVersionName.get(), 52 | "showVariantName" to showVariantName.get(), 53 | "showGitShortId" to showGitShortId.get(), 54 | "showDateTime" to showDateTime.get(), 55 | "extraInfo" to extraInfo.get() 56 | ).toJsonObject() 57 | task.inputs.property("contentConfigProvider", map.toString()) 58 | } 59 | } 60 | 61 | 62 | override fun onExecute(mergedResourceDirProvider: Provider) { 63 | val processedIcons = arrayListOf() 64 | val destDir = iconCacheDirProvider.get().asFile 65 | val mergedResourceDir = mergedResourceDirProvider.get().asFile 66 | val resDirs = allInputResourcesProvider.get().map { it.asFile } 67 | val iconNames = iconNamesProvider.get().split(",") 68 | val styleConfig = styleConfigProvider 69 | val contentConfig = contentConfigProvider 70 | 71 | val text = mutableListOf() 72 | if (contentConfig.showVariantName.get()) { 73 | text.add(variantName) 74 | } 75 | if (contentConfig.showVersionName.get()) { 76 | text.add(versionName.get()) 77 | } 78 | if (contentConfig.showGitShortId.get()) { 79 | text.add(generateGitShortId()) 80 | } 81 | if (contentConfig.showDateTime.get()) { 82 | text.add(generateDateTime()) 83 | } 84 | text.add(contentConfig.extraInfo.get() ?: "") 85 | 86 | val iconProcessorParam = IconProcessorParam( 87 | text = text, 88 | textSize = styleConfig.textSize.get(), 89 | textColor = ScratchPaperExtension.parseTextColor(styleConfig.textColor.get()), 90 | lineSpace = styleConfig.lineSpace.get(), 91 | bgColor = ScratchPaperExtension.parseBackgroundColor(styleConfig.backgroundColor.get()) 92 | ) 93 | 94 | 95 | // Add overlay to icons and generated to an intermediates dir 96 | findIcons(resDirs, iconNames).forEach { icon -> 97 | val icons = getProcessor( 98 | icon, 99 | destDir, 100 | iconProcessorParam 101 | )?.process() 102 | icons?.forEach(processedIcons::add) 103 | } 104 | 105 | // Compiled images to .flat files using aapt2 and replaced previous compiled icons, 106 | // later .flat files will be fed to merged resource task. 107 | val aapt2ExecutorPath = buildToolInfoProvider.get().getPath(BuildToolInfo.PathId.AAPT2) 108 | compileResDir(aapt2ExecutorPath, mergedResourceDir, processedIcons) 109 | 110 | // [Optional] Remove original xml files 111 | if (enableXmlIconsRemovalProvider.isPresent && enableXmlIconsRemovalProvider.get()) { 112 | removeXmlIconFiles(iconNames, mergedResourceDir) 113 | } 114 | } 115 | 116 | private fun generateGitShortId(): String { 117 | var shortId = CommandLineKit.runCommand("git rev-parse --short HEAD") 118 | if (shortId == null || shortId.length > 8) { 119 | shortId = "" 120 | } 121 | return shortId 122 | } 123 | 124 | private fun generateDateTime(): String = 125 | LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd-MM,HH:mm")) 126 | 127 | 128 | private fun findIcons( 129 | where: List?, 130 | iconNames: List 131 | ): Collection { 132 | val result: MutableSet = hashSetOf() 133 | where?.forEach { 134 | it.walk().maxDepth(3) 135 | .filter { dir -> 136 | dir.name.contains("mipmap") || dir.name.contains("drawable") 137 | } 138 | .forEach { file -> 139 | file.walk().forEach { image -> 140 | iconNames.forEach { iconName -> 141 | if (isIconFile(iconName, image)) { 142 | result.add(image) 143 | } 144 | } 145 | } 146 | } 147 | } 148 | return result 149 | } 150 | 151 | private fun isIconFile(namePrefix: String, file: File): Boolean { 152 | return file.isFile && file.nameWithoutExtension == namePrefix.trim() 153 | } 154 | 155 | 156 | private fun getProcessor( 157 | originIcon: File, 158 | destDir: File, 159 | iconProcessorParam: IconProcessorParam 160 | ): BaseIconProcessor? { 161 | if (!originIcon.exists()) { 162 | return null 163 | } 164 | return if (originIcon.extension == "xml") { 165 | AdaptiveIconProcessor(originIcon, destDir, iconProcessorParam) 166 | } else { 167 | RegularIconProcessor(originIcon, destDir, iconProcessorParam) 168 | } 169 | } 170 | 171 | /** 172 | * If the [AdaptiveIconProcessor] does not fulfill the requirement, 173 | * alternatively you can use this function to remove those adaptive icons 174 | * since ScratchPaper is working for QA testing products only. 175 | * 176 | * @param iconNames the icons defined in the AndroidManifest.xml (icon & roundIcons) 177 | * @param mergedResDir it's a directory like /build/intermediates/res/merged/debug 178 | */ 179 | private fun removeXmlIconFiles(iconNames: List, mergedResDir: File) { 180 | if (mergedResDir.isFile) { 181 | return 182 | } 183 | mergedResDir.walk().forEach { file -> 184 | iconNames.forEach { iconName -> 185 | if (file.isFile && file.name.contains("$iconName.xml.flat")) { 186 | file.delete() 187 | } 188 | } 189 | } 190 | } 191 | 192 | private fun Map<*, *>.toJsonObject(): JsonObject = JsonObject( 193 | mapNotNull { 194 | (it.key as? String ?: return@mapNotNull null) to it.value.toJsonElement() 195 | }.toMap(), 196 | ) 197 | 198 | private fun Any?.toJsonElement(): JsonElement = when (this) { 199 | null -> JsonNull 200 | is Map<*, *> -> toJsonElement() 201 | is Collection<*> -> toJsonElement() 202 | else -> JsonPrimitive(toString()) 203 | } 204 | 205 | } 206 | 207 | -------------------------------------------------------------------------------- /scratchpaper/src/main/kotlin/me/xx2bab/scratchpaper/icon/BaseIconProcessor.kt: -------------------------------------------------------------------------------- 1 | package me.xx2bab.scratchpaper.icon 2 | 3 | import java.awt.Font 4 | import java.awt.Graphics2D 5 | import java.awt.RenderingHints 6 | import java.io.File 7 | 8 | abstract class BaseIconProcessor(val originIcon: File, 9 | val destDir: File, 10 | val param: IconProcessorParam) { 11 | 12 | // to make sure the fontSize can be a regular number (like 11 12 14 that developers usually use) 13 | // I test 14 on all dpi generating, and found 96 (which is the xhdpi icon size) can fits it well 14 | // so we just make it as a standard size and compute the ratio for others to scale 15 | private val prettyImageSizeFits14FontSize = 96 16 | 17 | fun process(): Array { 18 | val size = getSize() 19 | val imgWidth: Int = size.first 20 | val imgHeight: Int = size.second 21 | val ratio = imgWidth * 1.0 / prettyImageSizeFits14FontSize 22 | 23 | val fontSize: Int = (param.textSize * ratio).toInt() 24 | val linePadding: Int = (param.lineSpace * ratio).toInt() 25 | val lineCount: Int = param.text.size 26 | val totalLineHeight: Int = (fontSize * lineCount) + ((linePadding + 1) * lineCount) 27 | 28 | getGraphic().apply { 29 | this.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON) 30 | 31 | // Draw background overlay 32 | val marginTop = (imgHeight - totalLineHeight) / 2 33 | color = param.bgColor 34 | fillRect(0, marginTop, imgWidth, totalLineHeight) 35 | 36 | // Draw each line of text 37 | font = Font(Font.SANS_SERIF, Font.PLAIN, fontSize) 38 | color = param.textColor 39 | for ((i, line) in param.text.reversed().withIndex()) { 40 | if (line.isBlank()) { 41 | continue 42 | } 43 | val strWidth = this.fontMetrics.stringWidth(line) 44 | 45 | var x = 0 46 | if (imgWidth >= strWidth) { 47 | x = (imgWidth - strWidth) / 2 48 | } 49 | 50 | val y = imgHeight - (fontSize * i) - ((i + 1) * linePadding) - marginTop 51 | 52 | // drawString(line, x, y) 53 | drawText(line, x, y) 54 | } 55 | } 56 | return writeIcon() 57 | } 58 | 59 | abstract fun getSize(): Pair 60 | 61 | abstract fun getGraphic(): Graphics2D 62 | 63 | abstract fun drawText(line: String, x: Int, y: Int) 64 | 65 | abstract fun writeIcon(): Array 66 | 67 | 68 | } -------------------------------------------------------------------------------- /scratchpaper/src/main/kotlin/me/xx2bab/scratchpaper/icon/IconProcessorParam.kt: -------------------------------------------------------------------------------- 1 | package me.xx2bab.scratchpaper.icon 2 | 3 | import java.awt.Color 4 | 5 | data class IconProcessorParam( 6 | val text: List, 7 | val textSize: Int, 8 | val textColor: Color, 9 | val lineSpace: Int, 10 | val bgColor: Color, 11 | ) 12 | -------------------------------------------------------------------------------- /scratchpaper/src/main/kotlin/me/xx2bab/scratchpaper/icon/RegularIconProcessor.kt: -------------------------------------------------------------------------------- 1 | package me.xx2bab.scratchpaper.icon 2 | 3 | import me.xx2bab.scratchpaper.utils.Logger 4 | import java.awt.Graphics2D 5 | import java.awt.GraphicsEnvironment 6 | import java.awt.image.BufferedImage 7 | import java.io.File 8 | import javax.imageio.ImageIO 9 | 10 | class RegularIconProcessor( 11 | originIcon: File, 12 | destDir: File, 13 | param: IconProcessorParam 14 | ) : BaseIconProcessor(originIcon, destDir, param) { 15 | 16 | private val bufferedImage: BufferedImage = ImageIO.read(originIcon) 17 | private val graphic: Graphics2D = GraphicsEnvironment.getLocalGraphicsEnvironment().createGraphics(bufferedImage) 18 | 19 | override fun getSize(): Pair { 20 | return Pair(bufferedImage.width, bufferedImage.height) 21 | } 22 | 23 | override fun getGraphic(): Graphics2D { 24 | return graphic 25 | } 26 | 27 | override fun drawText(line: String, x: Int, y: Int) { 28 | getGraphic().drawString(line, x, y) 29 | } 30 | 31 | override fun writeIcon(): Array { 32 | // prepare destination file and its directory. 33 | // Creating a directory is to separate images from different pixel dimensions, 34 | // and support the AAPT2 compiling correctly(it requires the resource file 35 | // is put inside a res-dimension dir like "mipmap-xxhdpi"). 36 | val imageParentFile = File(destDir, originIcon.parentFile.name) 37 | if (!imageParentFile.exists() && !imageParentFile.mkdirs()) { 38 | Logger.e("Can not create cache directory for ScratchPaper.") 39 | } 40 | val destIcon = File(imageParentFile, originIcon.name) 41 | ImageIO.write(bufferedImage, "png", destIcon) 42 | return arrayOf(destIcon) 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /scratchpaper/src/main/kotlin/me/xx2bab/scratchpaper/utils/CacheLocation.kt: -------------------------------------------------------------------------------- 1 | package me.xx2bab.scratchpaper.utils 2 | 3 | import org.gradle.api.Project 4 | import org.gradle.api.file.Directory 5 | import org.gradle.api.provider.Provider 6 | import java.io.File 7 | 8 | object CacheLocation { 9 | 10 | fun getCacheDir(project: Project, dimension: String): Provider = 11 | project.layout.buildDirectory.dir( 12 | "intermediates" + File.separator + "scratch-paper" 13 | + File.separator + dimension.trim() 14 | ) 15 | 16 | } -------------------------------------------------------------------------------- /scratchpaper/src/main/kotlin/me/xx2bab/scratchpaper/utils/Logger.kt: -------------------------------------------------------------------------------- 1 | package me.xx2bab.scratchpaper.utils 2 | 3 | import org.gradle.api.Project 4 | import org.gradle.api.logging.Logger 5 | 6 | object Logger { 7 | 8 | private const val TAG = "[ScratchPaper]: " 9 | 10 | private lateinit var gradleLogger: Logger 11 | 12 | fun init (project: Project){ 13 | gradleLogger = project.logger 14 | } 15 | 16 | fun d(message: String) { 17 | gradleLogger.debug(TAG + message) 18 | } 19 | 20 | fun i(message: String) { 21 | gradleLogger.info(TAG + message) 22 | } 23 | 24 | fun e(message: String) { 25 | gradleLogger.error(TAG + message) 26 | } 27 | 28 | fun l(message: String) { 29 | gradleLogger.lifecycle(TAG + message) 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "scratch-paper-root" 2 | 3 | pluginManagement { 4 | val versions = file("deps.versions.toml").readText() 5 | val regexPlaceHolder = "%s\\s\\=\\s\\\"([A-Za-z0-9\\.\\-]+)\\\"" 6 | val getVersion = { s: String -> regexPlaceHolder.format(s).toRegex().find(versions)!!.groupValues[1] } 7 | 8 | plugins { 9 | kotlin("jvm") version getVersion("kotlinVer") apply false 10 | kotlin("plugin.serialization") version getVersion("kotlinVer") apply false 11 | } 12 | repositories { 13 | mavenCentral() 14 | google() 15 | gradlePluginPortal() 16 | } 17 | } 18 | 19 | dependencyResolutionManagement { 20 | repositories { 21 | google() 22 | mavenCentral() 23 | mavenLocal() 24 | } 25 | versionCatalogs { 26 | create("deps") { 27 | from(files("deps.versions.toml")) 28 | } 29 | } 30 | } 31 | 32 | include(":scratchpaper", ":functional-test") 33 | 34 | //if (file("../../Polyfill").run { exists() && isDirectory }) { 35 | // includeBuild("../../Polyfill") { 36 | // dependencySubstitution { 37 | // substitute(module("me.2bab:polyfill")) 38 | // .with(project(":polyfill")) 39 | // } 40 | // } 41 | //} -------------------------------------------------------------------------------- /sp-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/2BAB/ScratchPaper/db2838970e497becd75d1772513810be39afc6cd/sp-banner.png --------------------------------------------------------------------------------