diff --git a/lib/src/android.dart b/lib/src/android.dart index 3cd60c0..6f2a793 100644 --- a/lib/src/android.dart +++ b/lib/src/android.dart @@ -109,9 +109,10 @@ void _createAndroidAdaptiveIcon({ CliLogger.info(message); _createAdaptiveForeground(adaptiveIcons, foreground); - _createAdaptiveBackground(adaptiveIcons, background); + _createAdaptiveBackground(adaptiveIcons, background, monochrome); if (round != null) { - _createAdaptiveRound(androidIcons, round, isValidHexaCode(background)); + _createAdaptiveRound( + androidIcons, round, isValidHexaCode(background), monochrome != null); } else { _removeAdaptiveRound(androidIcons); } @@ -125,12 +126,13 @@ void _createAndroidAdaptiveIcon({ /// Create the adaptive background void _createAdaptiveBackground( List adaptiveIcons, - String background, -) { + String background, [ + String? monochrome, +]) { // Check background is hexa color or image if (isValidHexaCode(background)) { _handleColorsXmlFile(background); - _createIcLauncherColorXmlFile(); + _createIcLauncherColorXmlFile(monochrome != null); } else { try { final backgroundImage = Icon.loadFile(background); @@ -153,7 +155,7 @@ void _createAdaptiveBackground( 'Generated adaptive background images', level: CliLoggerLevel.two, ); - _createIcLauncherMipMapXmlFile(); + _createIcLauncherMipMapXmlFile(monochrome != null); } catch (e) { CliLogger.error( 'Incorrect `$background` of `adaptive_background_color` or `adaptive_background_image`', @@ -196,6 +198,7 @@ void _createAdaptiveRound( List adaptiveIcons, String round, bool backgroundIsColor, + bool hasMonochrome, ) { final roundImage = Icon.loadFile(round); if (roundImage == null) { @@ -213,7 +216,7 @@ void _createAdaptiveRound( ANDROID_ADAPTIVE_ROUND_ICON_FILE_NAME, ); } - _createIcLauncherRoundMipMapXmlFile(backgroundIsColor); + _createIcLauncherRoundMipMapXmlFile(backgroundIsColor, hasMonochrome); _createAndroidManifestIconLauncherRound(); CliLogger.success( 'Generated adaptive round images', @@ -349,11 +352,13 @@ void _updateColorsFile(File colorsXml, String backgroundColor) { } /// Create ic_launcher_color.xml file -void _createIcLauncherColorXmlFile() { +void _createIcLauncherColorXmlFile(bool hasMonochrome) { final icLauncherXml = File( '${_flavorHelper.androidResFolder}$ANDROID_ADAPTIVE_XML_DIR/$ANDROID_ADAPTIVE_XML_FILE_NAME'); icLauncherXml.createSync(recursive: true); - icLauncherXml.writeAsStringSync(IC_LAUNCHER_BACKGROUND_COLOR_XML); + icLauncherXml.writeAsStringSync(hasMonochrome + ? IC_LAUNCHER_BACKGROUND_COLOR_XML + : IC_LAUNCHER_BACKGROUND_COLOR_NO_MONOCHROME_XML); CliLogger.success( 'Created `$ANDROID_ADAPTIVE_XML_FILE_NAME`', level: CliLoggerLevel.two, @@ -361,11 +366,13 @@ void _createIcLauncherColorXmlFile() { } /// Create ic luncher xml file -void _createIcLauncherMipMapXmlFile() { +void _createIcLauncherMipMapXmlFile(bool hasMonochrome) { final icLauncherXml = File( '${_flavorHelper.androidResFolder}$ANDROID_ADAPTIVE_XML_DIR/$ANDROID_ADAPTIVE_XML_FILE_NAME'); icLauncherXml.createSync(recursive: true); - icLauncherXml.writeAsStringSync(IC_LAUNCHER_MIP_MAP_XML); + icLauncherXml.writeAsStringSync(hasMonochrome + ? IC_LAUNCHER_MIP_MAP_XML + : IC_LAUNCHER_MIP_MAP_NO_MONOCHROME_XML); CliLogger.success( 'Created `$ANDROID_ADAPTIVE_XML_FILE_NAME`', level: CliLoggerLevel.two, @@ -373,13 +380,26 @@ void _createIcLauncherMipMapXmlFile() { } /// Create ic_launcher_round.xml file -void _createIcLauncherRoundMipMapXmlFile(bool backgroundIsColor) { +void _createIcLauncherRoundMipMapXmlFile( + bool backgroundIsColor, bool hasMonochrome) { final icLauncherXml = File( '${_flavorHelper.androidResFolder}$ANDROID_ADAPTIVE_XML_DIR/$ANDROID_ADAPTIVE_ROUND_XML_FILE_NAME'); + String contents; + if (backgroundIsColor) { + if (hasMonochrome) { + contents = IC_LAUNCHER_ROUND_BACKGROUND_COLOR_XML; + } else { + contents = IC_LAUNCHER_ROUND_BACKGROUND_COLOR_NO_MONOCHROME_XML; + } + } else { + if (hasMonochrome) { + contents = IC_LAUNCHER_ROUND_MIP_MAP_XML; + } else { + contents = IC_LAUNCHER_ROUND_MIP_MAP_NO_MONOCHROME_XML; + } + } icLauncherXml.createSync(recursive: true); - icLauncherXml.writeAsStringSync(backgroundIsColor - ? IC_LAUNCHER_ROUND_BACKGROUND_COLOR_XML - : IC_LAUNCHER_ROUND_MIP_MAP_XML); + icLauncherXml.writeAsStringSync(contents); CliLogger.success( 'Created `$ANDROID_ADAPTIVE_ROUND_XML_FILE_NAME`', level: CliLoggerLevel.two, @@ -408,7 +428,7 @@ void _createAndroidManifestIconLauncherRound() { if (index != -1) { final lineUpdated = manifestLines.elementAt(index).replaceAll( RegExp(r'android:roundIcon="[^"]*(\\"[^"]*)*"'), - 'android:roundIcon="@mipmap/$ANDROID_ADAPTIVE_ROUND_ICON_NAME"', + 'android:roundIcon="@mipmap/$ANDROID_ADAPTIVE_ROUND_XML_FILE_NAME_WITHOUT_EXTENSION"', ); manifestLines.replaceRange(index, index + 1, [lineUpdated]); androidManifestFile.writeAsStringSync(manifestLines.join('\n')); @@ -424,7 +444,7 @@ void _createAndroidManifestIconLauncherRound() { .elementAt(index) .replaceAll(RegExp(r'android:icon="[^"]*(\\"[^"]*)*"'), ''' android:icon="@mipmap/$ANDROID_ICON_NAME" -\t\tandroid:roundIcon="@mipmap/$ANDROID_ADAPTIVE_ROUND_ICON_NAME"'''); +\t\tandroid:roundIcon="@mipmap/$ANDROID_ADAPTIVE_ROUND_XML_FILE_NAME_WITHOUT_EXTENSION"'''); manifestLines.replaceRange(index, index + 1, [lineUpdated]); androidManifestFile.writeAsStringSync(manifestLines.join('\n')); diff --git a/lib/utils/constants.dart b/lib/utils/constants.dart index bee13e2..82c35ec 100644 --- a/lib/utils/constants.dart +++ b/lib/utils/constants.dart @@ -78,9 +78,13 @@ const String ANDROID_ADAPTIVE_XML_DIR = 'mipmap-anydpi-v26'; /// Android adaptive icon file const String ANDROID_ADAPTIVE_XML_FILE_NAME = '$ANDROID_ICON_NAME.xml'; +/// Android adapttive round xml file without extension +const String ANDROID_ADAPTIVE_ROUND_XML_FILE_NAME_WITHOUT_EXTENSION = + 'ic_launcher_rounded'; + /// Android adaptive round icon file const String ANDROID_ADAPTIVE_ROUND_XML_FILE_NAME = - '$ANDROID_ADAPTIVE_ROUND_ICON_NAME.xml'; + '$ANDROID_ADAPTIVE_ROUND_XML_FILE_NAME_WITHOUT_EXTENSION.xml'; /// Android launcher background color xml const String IC_LAUNCHER_BACKGROUND_COLOR_XML = ''' @@ -92,6 +96,15 @@ const String IC_LAUNCHER_BACKGROUND_COLOR_XML = ''' '''; +/// Android launcher background color with no monochrome xml +const String IC_LAUNCHER_BACKGROUND_COLOR_NO_MONOCHROME_XML = ''' + + + + + +'''; + /// Android launcher background image xml const String IC_LAUNCHER_MIP_MAP_XML = ''' @@ -102,26 +115,53 @@ const String IC_LAUNCHER_MIP_MAP_XML = ''' '''; +/// Android launcher background image with no monochrome xml +const String IC_LAUNCHER_MIP_MAP_NO_MONOCHROME_XML = ''' + + + + + +'''; + /// Android launcher background round color xml const String IC_LAUNCHER_ROUND_BACKGROUND_COLOR_XML = ''' - + '''; +/// Android launcher background round color with no monochrome xml +const String IC_LAUNCHER_ROUND_BACKGROUND_COLOR_NO_MONOCHROME_XML = ''' + + + + + +'''; + /// Android launcher background round image xml const String IC_LAUNCHER_ROUND_MIP_MAP_XML = ''' - + '''; +/// Android launcher background round image with no monochrome xml +const String IC_LAUNCHER_ROUND_MIP_MAP_NO_MONOCHROME_XML = ''' + + + + + +'''; + /// IOS config file location const String IOS_CONFIG_FILE = 'ios/Runner.xcodeproj/project.pbxproj';