generated from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GmsCore): add
Custom branding icon
patch
- Loading branch information
Showing
78 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
src/main/kotlin/app/revanced/patches/gmscore/branding/icon/CustomBrandingIconPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package app.revanced.patches.gmscore.branding.icon | ||
|
||
import app.revanced.patcher.data.ResourceContext | ||
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption | ||
import app.revanced.util.ResourceGroup | ||
import app.revanced.util.Utils.trimIndentMultiline | ||
import app.revanced.util.copyFile | ||
import app.revanced.util.copyResources | ||
import app.revanced.patcher.patch.ResourcePatch | ||
|
||
import app.revanced.util.underBarOrThrow | ||
|
||
//@Suppress("unused") | ||
object CustomBrandingIconPatch : ResourcePatch( | ||
name = "Custom branding icon", | ||
description = "Changes the app icon to the icon specified in options.json.", | ||
compatiblePackages = setOf( | ||
CompatiblePackage("app.revanced.android.gms") | ||
) | ||
) { | ||
private const val DEFAULT_ICON = "revancify_blue" | ||
|
||
private val availableIcon = mapOf( | ||
"MMT" to "mmt", | ||
"Revancify Blue" to DEFAULT_ICON, | ||
"Revancify Red" to "revancify_red" | ||
) | ||
|
||
private val sizeArray = arrayOf( | ||
"xxxhdpi", | ||
"xxhdpi", | ||
"xhdpi", | ||
"hdpi", | ||
"mdpi", | ||
) | ||
|
||
private val mipmapDirectories = sizeArray.map { "mipmap-$it" } | ||
|
||
private val launcherIconResourceFileNames = arrayOf( | ||
"ic_app", | ||
"ic_app_round", | ||
"ic_app_foreground", | ||
"ic_app_foreground_mono", | ||
"ic_app_background" | ||
).map { "$it.png" }.toTypedArray() | ||
|
||
private fun List<String>.getResourceGroup(fileNames: Array<String>) = map { directory -> | ||
ResourceGroup( | ||
directory, *fileNames | ||
) | ||
} | ||
|
||
private val iconResourceGroups = | ||
mipmapDirectories.getResourceGroup(launcherIconResourceFileNames) | ||
|
||
// region patch option | ||
|
||
val AppIcon = stringPatchOption( | ||
key = "AppIcon", | ||
default = DEFAULT_ICON, | ||
values = availableIcon, | ||
title = "App icon", | ||
description = """ | ||
The icon to apply to the app. | ||
If a path to a folder is provided, the folder must contain the following folders: | ||
${mipmapDirectories.joinToString("\n") { "- $it" }} | ||
Each of these folders must contain the following files: | ||
${launcherIconResourceFileNames.joinToString("\n") { "- $it" }} | ||
""".trimIndentMultiline(), | ||
required = true | ||
) | ||
|
||
// endregion | ||
|
||
override fun execute(context: ResourceContext) { | ||
|
||
// Check patch options first. | ||
val appIcon = AppIcon | ||
.underBarOrThrow() | ||
|
||
val appIconResourcePath = "gmscore/branding/icon/$appIcon" | ||
|
||
context.copyResources("gmscore/branding/icon", ResourceGroup("mipmap-anydpi-v26", "ic_app.xml")) | ||
// Check if a custom path is used in the patch options. | ||
if (!availableIcon.containsValue(appIcon)) { | ||
context.copyFile( | ||
iconResourceGroups, | ||
appIcon, | ||
"WARNING: Invalid app icon path: $appIcon. Does not apply patches." | ||
) | ||
} else { | ||
// Change launcher icon. | ||
|
||
iconResourceGroups.let { resourceGroups -> | ||
resourceGroups.forEach { | ||
context.copyResources(appIconResourcePath, it) | ||
} | ||
} | ||
} | ||
val manifest = context.get("AndroidManifest.xml", false) | ||
manifest.writeText( | ||
manifest.readText() | ||
.replace( | ||
"\"@mipmap/ic_app_settings\"", | ||
"\"@mipmap/ic_app\"", | ||
).replace( | ||
"android:roundIcon=\"@mipmap/ic_app\"", | ||
"android:roundIcon=\"@mipmap/ic_app_round\"" | ||
), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package app.revanced.util | ||
|
||
internal object Utils { | ||
internal fun String.trimIndentMultiline() = | ||
this.split("\n") | ||
.joinToString("\n") { it.trimIndent() } // Remove the leading whitespace from each line. | ||
.trimIndent() // Remove the leading newline. | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/resources/gmscore/branding/icon/mipmap-anydpi-v26/ic_app.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<adaptive-icon | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<background android:drawable="@mipmap/ic_app_background" /> | ||
<foreground android:drawable="@mipmap/ic_app_foreground" /> | ||
<monochrome android:drawable="@mipmap/ic_app_foreground_mono" /> | ||
</adaptive-icon> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+225 Bytes
src/main/resources/gmscore/branding/icon/mmt/mipmap-hdpi/ic_app_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.08 KB
src/main/resources/gmscore/branding/icon/mmt/mipmap-hdpi/ic_app_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.63 KB
...main/resources/gmscore/branding/icon/mmt/mipmap-hdpi/ic_app_foreground_mono.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.89 KB
src/main/resources/gmscore/branding/icon/mmt/mipmap-hdpi/ic_app_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+137 Bytes
src/main/resources/gmscore/branding/icon/mmt/mipmap-mdpi/ic_app_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.45 KB
src/main/resources/gmscore/branding/icon/mmt/mipmap-mdpi/ic_app_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.12 KB
...main/resources/gmscore/branding/icon/mmt/mipmap-mdpi/ic_app_foreground_mono.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.19 KB
src/main/resources/gmscore/branding/icon/mmt/mipmap-mdpi/ic_app_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+291 Bytes
src/main/resources/gmscore/branding/icon/mmt/mipmap-xhdpi/ic_app_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.83 KB
src/main/resources/gmscore/branding/icon/mmt/mipmap-xhdpi/ic_app_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.16 KB
...ain/resources/gmscore/branding/icon/mmt/mipmap-xhdpi/ic_app_foreground_mono.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.32 KB
src/main/resources/gmscore/branding/icon/mmt/mipmap-xhdpi/ic_app_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.03 KB
src/main/resources/gmscore/branding/icon/mmt/mipmap-xxhdpi/ic_app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+432 Bytes
src/main/resources/gmscore/branding/icon/mmt/mipmap-xxhdpi/ic_app_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.27 KB
src/main/resources/gmscore/branding/icon/mmt/mipmap-xxhdpi/ic_app_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.31 KB
...in/resources/gmscore/branding/icon/mmt/mipmap-xxhdpi/ic_app_foreground_mono.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.1 KB
src/main/resources/gmscore/branding/icon/mmt/mipmap-xxhdpi/ic_app_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.87 KB
src/main/resources/gmscore/branding/icon/mmt/mipmap-xxxhdpi/ic_app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+590 Bytes
src/main/resources/gmscore/branding/icon/mmt/mipmap-xxxhdpi/ic_app_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.8 KB
src/main/resources/gmscore/branding/icon/mmt/mipmap-xxxhdpi/ic_app_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.52 KB
...n/resources/gmscore/branding/icon/mmt/mipmap-xxxhdpi/ic_app_foreground_mono.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.53 KB
src/main/resources/gmscore/branding/icon/mmt/mipmap-xxxhdpi/ic_app_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.69 KB
src/main/resources/gmscore/branding/icon/revancify_blue/mipmap-hdpi/ic_app.png
Oops, something went wrong.
Binary file added
BIN
+470 Bytes
...esources/gmscore/branding/icon/revancify_blue/mipmap-hdpi/ic_app_background.png
Oops, something went wrong.
Binary file added
BIN
+1.92 KB
...esources/gmscore/branding/icon/revancify_blue/mipmap-hdpi/ic_app_foreground.png
Oops, something went wrong.
Binary file added
BIN
+1.54 KB
...ces/gmscore/branding/icon/revancify_blue/mipmap-hdpi/ic_app_foreground_mono.png
Oops, something went wrong.
Binary file added
BIN
+3.18 KB
...ain/resources/gmscore/branding/icon/revancify_blue/mipmap-hdpi/ic_app_round.png
Oops, something went wrong.
Binary file added
BIN
+1.14 KB
src/main/resources/gmscore/branding/icon/revancify_blue/mipmap-mdpi/ic_app.png
Oops, something went wrong.
Binary file added
BIN
+328 Bytes
...esources/gmscore/branding/icon/revancify_blue/mipmap-mdpi/ic_app_background.png
Oops, something went wrong.
Binary file added
BIN
+1.21 KB
...esources/gmscore/branding/icon/revancify_blue/mipmap-mdpi/ic_app_foreground.png
Oops, something went wrong.
Binary file added
BIN
+1020 Bytes
...ces/gmscore/branding/icon/revancify_blue/mipmap-mdpi/ic_app_foreground_mono.png
Oops, something went wrong.
Binary file added
BIN
+2.05 KB
...ain/resources/gmscore/branding/icon/revancify_blue/mipmap-mdpi/ic_app_round.png
Oops, something went wrong.
Binary file added
BIN
+2.29 KB
src/main/resources/gmscore/branding/icon/revancify_blue/mipmap-xhdpi/ic_app.png
Oops, something went wrong.
Binary file added
BIN
+652 Bytes
...sources/gmscore/branding/icon/revancify_blue/mipmap-xhdpi/ic_app_background.png
Oops, something went wrong.
Binary file added
BIN
+2.65 KB
...sources/gmscore/branding/icon/revancify_blue/mipmap-xhdpi/ic_app_foreground.png
Oops, something went wrong.
Binary file added
BIN
+2.14 KB
...es/gmscore/branding/icon/revancify_blue/mipmap-xhdpi/ic_app_foreground_mono.png
Oops, something went wrong.
Binary file added
BIN
+4.63 KB
...in/resources/gmscore/branding/icon/revancify_blue/mipmap-xhdpi/ic_app_round.png
Oops, something went wrong.
Binary file added
BIN
+3.29 KB
src/main/resources/gmscore/branding/icon/revancify_blue/mipmap-xxhdpi/ic_app.png
Oops, something went wrong.
Binary file added
BIN
+1.03 KB
...ources/gmscore/branding/icon/revancify_blue/mipmap-xxhdpi/ic_app_background.png
Oops, something went wrong.
Binary file added
BIN
+4.31 KB
...ources/gmscore/branding/icon/revancify_blue/mipmap-xxhdpi/ic_app_foreground.png
Oops, something went wrong.
Binary file added
BIN
+3.35 KB
...s/gmscore/branding/icon/revancify_blue/mipmap-xxhdpi/ic_app_foreground_mono.png
Oops, something went wrong.
Binary file added
BIN
+7.2 KB
...n/resources/gmscore/branding/icon/revancify_blue/mipmap-xxhdpi/ic_app_round.png
Oops, something went wrong.
Binary file added
BIN
+4.7 KB
src/main/resources/gmscore/branding/icon/revancify_blue/mipmap-xxxhdpi/ic_app.png
Oops, something went wrong.
Binary file added
BIN
+1.56 KB
...urces/gmscore/branding/icon/revancify_blue/mipmap-xxxhdpi/ic_app_background.png
Oops, something went wrong.
Binary file added
BIN
+6.03 KB
...urces/gmscore/branding/icon/revancify_blue/mipmap-xxxhdpi/ic_app_foreground.png
Oops, something went wrong.
Binary file added
BIN
+5.29 KB
.../gmscore/branding/icon/revancify_blue/mipmap-xxxhdpi/ic_app_foreground_mono.png
Oops, something went wrong.
Binary file added
BIN
+10.5 KB
.../resources/gmscore/branding/icon/revancify_blue/mipmap-xxxhdpi/ic_app_round.png
Oops, something went wrong.
Binary file added
BIN
+1.67 KB
src/main/resources/gmscore/branding/icon/revancify_red/mipmap-hdpi/ic_app.png
Oops, something went wrong.
Binary file added
BIN
+470 Bytes
...resources/gmscore/branding/icon/revancify_red/mipmap-hdpi/ic_app_background.png
Oops, something went wrong.
Binary file added
BIN
+1.91 KB
...resources/gmscore/branding/icon/revancify_red/mipmap-hdpi/ic_app_foreground.png
Oops, something went wrong.
Binary file added
BIN
+1.54 KB
...rces/gmscore/branding/icon/revancify_red/mipmap-hdpi/ic_app_foreground_mono.png
Oops, something went wrong.
Binary file added
BIN
+3.14 KB
...main/resources/gmscore/branding/icon/revancify_red/mipmap-hdpi/ic_app_round.png
Oops, something went wrong.
Binary file added
BIN
+1.12 KB
src/main/resources/gmscore/branding/icon/revancify_red/mipmap-mdpi/ic_app.png
Oops, something went wrong.
Binary file added
BIN
+328 Bytes
...resources/gmscore/branding/icon/revancify_red/mipmap-mdpi/ic_app_background.png
Oops, something went wrong.
Binary file added
BIN
+1.23 KB
...resources/gmscore/branding/icon/revancify_red/mipmap-mdpi/ic_app_foreground.png
Oops, something went wrong.
Binary file added
BIN
+1020 Bytes
...rces/gmscore/branding/icon/revancify_red/mipmap-mdpi/ic_app_foreground_mono.png
Oops, something went wrong.
Binary file added
BIN
+2.04 KB
...main/resources/gmscore/branding/icon/revancify_red/mipmap-mdpi/ic_app_round.png
Oops, something went wrong.
Binary file added
BIN
+2.28 KB
src/main/resources/gmscore/branding/icon/revancify_red/mipmap-xhdpi/ic_app.png
Oops, something went wrong.
Binary file added
BIN
+652 Bytes
...esources/gmscore/branding/icon/revancify_red/mipmap-xhdpi/ic_app_background.png
Oops, something went wrong.
Binary file added
BIN
+2.68 KB
...esources/gmscore/branding/icon/revancify_red/mipmap-xhdpi/ic_app_foreground.png
Oops, something went wrong.
Binary file added
BIN
+2.14 KB
...ces/gmscore/branding/icon/revancify_red/mipmap-xhdpi/ic_app_foreground_mono.png
Oops, something went wrong.
Binary file added
BIN
+4.61 KB
...ain/resources/gmscore/branding/icon/revancify_red/mipmap-xhdpi/ic_app_round.png
Oops, something went wrong.
Binary file added
BIN
+3.29 KB
src/main/resources/gmscore/branding/icon/revancify_red/mipmap-xxhdpi/ic_app.png
Oops, something went wrong.
Binary file added
BIN
+1.03 KB
...sources/gmscore/branding/icon/revancify_red/mipmap-xxhdpi/ic_app_background.png
Oops, something went wrong.
Binary file added
BIN
+4.37 KB
...sources/gmscore/branding/icon/revancify_red/mipmap-xxhdpi/ic_app_foreground.png
Oops, something went wrong.
Binary file added
BIN
+3.35 KB
...es/gmscore/branding/icon/revancify_red/mipmap-xxhdpi/ic_app_foreground_mono.png
Oops, something went wrong.
Binary file added
BIN
+7.15 KB
...in/resources/gmscore/branding/icon/revancify_red/mipmap-xxhdpi/ic_app_round.png
Oops, something went wrong.
Binary file added
BIN
+4.7 KB
src/main/resources/gmscore/branding/icon/revancify_red/mipmap-xxxhdpi/ic_app.png
Oops, something went wrong.
Binary file added
BIN
+1.56 KB
...ources/gmscore/branding/icon/revancify_red/mipmap-xxxhdpi/ic_app_background.png
Oops, something went wrong.
Binary file added
BIN
+6.13 KB
...ources/gmscore/branding/icon/revancify_red/mipmap-xxxhdpi/ic_app_foreground.png
Oops, something went wrong.
Binary file added
BIN
+5.29 KB
...s/gmscore/branding/icon/revancify_red/mipmap-xxxhdpi/ic_app_foreground_mono.png
Oops, something went wrong.
Binary file added
BIN
+10.4 KB
...n/resources/gmscore/branding/icon/revancify_red/mipmap-xxxhdpi/ic_app_round.png
Oops, something went wrong.