Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/SingleProject/Resizetizer/src/CreatePartialInfoPlistTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class CreatePartialInfoPlistTask : Task

public string Storyboard { get; set; }

public string LaunchScreenImage { get; set; }

public string LaunchScreenColor { get; set; }

const string plistHeader =
@"<?xml version=""1.0"" encoding=""UTF-8""?>
<!DOCTYPE plist PUBLIC ""-//Apple//DTD PLIST 1.0//EN"" ""http://www.apple.com/DTDs/PropertyList-1.0.dtd"">
Expand Down Expand Up @@ -52,7 +56,26 @@ public override bool Execute()
f.WriteLine(" </array>");
}

if (!string.IsNullOrEmpty(Storyboard))
if (!string.IsNullOrEmpty(LaunchScreenImage) || !string.IsNullOrEmpty(LaunchScreenColor))
{
f.WriteLine(" <key>UILaunchScreen</key>");
f.WriteLine(" <dict>");

if (!string.IsNullOrEmpty(LaunchScreenImage))
{
f.WriteLine(" <key>UIImageName</key>");
f.WriteLine($" <string>{LaunchScreenImage}</string>");
}

if (!string.IsNullOrEmpty(LaunchScreenColor))
{
f.WriteLine(" <key>UIColorName</key>");
f.WriteLine($" <string>{LaunchScreenColor}</string>");
}

f.WriteLine(" </dict>");
}
else if (!string.IsNullOrEmpty(Storyboard))
{
f.WriteLine(" <key>UILaunchStoryboardName</key>");
f.WriteLine($" <string>{Path.GetFileNameWithoutExtension(Storyboard)}</string>");
Expand Down
26 changes: 26 additions & 0 deletions src/SingleProject/Resizetizer/src/DpiPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public static class Android
public static DpiPath Original =>
new DpiPath("drawable", 1.0m);

public static DpiPath OriginalNight =>
new DpiPath("drawable-night", 1.0m);

public static DpiPath[] Image
=> new[]
{
Expand All @@ -58,6 +61,16 @@ public static DpiPath[] Image
new DpiPath("drawable-xxxhdpi", 4.0m),
};

public static DpiPath[] ImageNight
=> new[]
{
new DpiPath("drawable-night-mdpi", 1.0m),
new DpiPath("drawable-night-hdpi", 1.5m),
new DpiPath("drawable-night-xhdpi", 2.0m),
new DpiPath("drawable-night-xxhdpi", 3.0m),
new DpiPath("drawable-night-xxxhdpi", 4.0m),
};

public static DpiPath[] AppIcon
=> new[]
{
Expand Down Expand Up @@ -89,6 +102,11 @@ public static DpiPath[] AppIconParts
public static class Ios
{
public const string AppIconPath = "Assets.xcassets/{name}.appiconset";
public const string SplashImageName = "MauiSplashImage";
public const string SplashImageDarkName = "MauiSplashImageDark";
public const string SplashColorName = "MauiSplashColor";
public const string SplashImageSetPath = "Assets.xcassets/MauiSplashImage.imageset";
public const string SplashColorSetPath = "Assets.xcassets/MauiSplashColor.colorset";

public static DpiPath Original =>
new DpiPath("Resources", 1.0m);
Expand All @@ -101,6 +119,14 @@ public static DpiPath[] Image
new DpiPath("", 3.0m, null,"@3x"),
};

public static DpiPath[] SplashImageAsset
=> new[]
{
new DpiPath(SplashImageSetPath, 1.0m),
new DpiPath(SplashImageSetPath, 2.0m, null, "@2x"),
new DpiPath(SplashImageSetPath, 3.0m, null, "@3x"),
};

public static DpiPath[] AppIcon
=> new[]
{
Expand Down
126 changes: 110 additions & 16 deletions src/SingleProject/Resizetizer/src/GenerateSplashAndroidResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,33 @@ public override bool Execute()
var info = ResizeImageInfo.Parse(splash);

var resizer = new Resizer(info, IntermediateOutputPath, this);
Resizer darkResizer = null;
if (info.HasDarkMode)
{
var darkInfo = info.CreateDarkVariant(GetDarkOutputAlias(info));
if (darkInfo.BaseSize is null && !string.IsNullOrWhiteSpace(info.DarkFilename))
darkInfo.BaseSize = resizer.BaseSize ?? resizer.GetOriginalSize();
darkResizer = new Resizer(darkInfo, IntermediateOutputPath, this);
}

WriteImages(resizer);
WriteColors(resizer);
WriteDrawable(resizer);
WriteDrawable_v31(resizer);
if (darkResizer is not null)
{
CleanStaleNightImageResources(darkResizer.Info.Resize);
WriteImages(darkResizer, dark: true);
Comment thread
jfversluis marked this conversation as resolved.
}
else
CleanNightResources();

WriteColors(resizer, darkResizer);
WriteDrawable(resizer, dark: false);
WriteDrawable_v31(resizer, dark: false);

if (darkResizer is not null)
{
WriteDrawable(darkResizer, dark: true);
WriteDrawable_v31(darkResizer, dark: true);
}

return !Log.HasLoggedErrors;
}
Expand All @@ -63,28 +85,38 @@ public override bool Execute()
const string Comment = "This file was auto-generated by .NET MAUI.";
const float PreferredImageSize = 108f;

private void WriteImages(Resizer resizer)
private void WriteImages(Resizer resizer, bool dark = false)
{
if (resizer.Info.Resize)
{
foreach (var dpi in DpiPath.Android.Image)
foreach (var dpi in dark ? DpiPath.Android.ImageNight : DpiPath.Android.Image)
{
Log.LogMessage(MessageImportance.Low, $"Splash Screen Resize: " + dpi);
resizer.Resize(dpi, InputsFile);
}
}
else
{
var dpi = DpiPath.Android.Original;
var dpi = dark ? DpiPath.Android.OriginalNight : DpiPath.Android.Original;

Log.LogMessage(MessageImportance.Low, $"Splash Screen Copy: " + dpi);
resizer.CopyFile(dpi, InputsFile);
}
}

void WriteColors(Resizer resizer)
void WriteColors(Resizer resizer, Resizer darkResizer)
{
var dir = Path.Combine(IntermediateOutputPath, "values");
WriteColors(resizer.Info.Color, "values");

if (darkResizer?.Info.Color is not null)
WriteColors(darkResizer.Info.Color, "values-night");
else if (darkResizer is not null)
DeleteNightColors();
}

void WriteColors(SKColor? color, string directory)
{
var dir = Path.Combine(IntermediateOutputPath, directory);
Directory.CreateDirectory(dir);

var colorsFile = Path.Combine(dir, "maui_colors.xml");
Expand All @@ -95,25 +127,25 @@ void WriteColors(Resizer resizer)
writer.WriteComment(Comment);
writer.WriteStartElement("resources");

if (resizer.Info.Color is not null)
if (color is not null)
{
writer.WriteStartElement("color");
writer.WriteAttributeString("name", "maui_splash_color");
writer.WriteString(resizer.Info.Color.ToString());
writer.WriteString(color.ToString());
writer.WriteEndElement();
}

writer.WriteEndDocument();
}

void WriteDrawable(Resizer resizer)
void WriteDrawable(Resizer resizer, bool dark)
{
var dir = Path.Combine(IntermediateOutputPath, "drawable");
var dir = Path.Combine(IntermediateOutputPath, dark ? "drawable-night" : "drawable");
Directory.CreateDirectory(dir);

var drawableFile = Path.Combine(dir, "maui_splash_image.xml");

Log.LogMessage(MessageImportance.Low, $"Splash Screen Drawable: " + drawableFile);
Log.LogMessage(MessageImportance.Low, $"Splash Screen Drawable{(dark ? " (night)" : "")}: " + drawableFile);

using var writer = XmlWriter.Create(drawableFile, Settings);
writer.WriteComment(Comment);
Expand All @@ -130,16 +162,16 @@ void WriteDrawable(Resizer resizer)
writer.WriteEndDocument();
}

void WriteDrawable_v31(Resizer resizer)
void WriteDrawable_v31(Resizer resizer, bool dark)
{
var size = CalculateScaledSize(resizer);

var dir = Path.Combine(IntermediateOutputPath, "drawable-v31");
var dir = Path.Combine(IntermediateOutputPath, dark ? "drawable-night-v31" : "drawable-v31");
Directory.CreateDirectory(dir);

var drawableFile = Path.Combine(dir, "maui_splash_image.xml");

Log.LogMessage(MessageImportance.Low, $"Splash Screen Drawable (v31): " + drawableFile);
Log.LogMessage(MessageImportance.Low, $"Splash Screen Drawable ({(dark ? "night " : "")}v31): " + drawableFile);

using var writer = XmlWriter.Create(drawableFile, Settings);
writer.WriteComment(Comment);
Expand All @@ -164,6 +196,68 @@ void ILogger.Log(string message)
Log?.LogMessage(message);
}

void CleanNightResources()
{
foreach (var directory in new[]
{
"values-night",
"drawable-night",
"drawable-night-v31",
"drawable-night-mdpi",
"drawable-night-hdpi",
"drawable-night-xhdpi",
"drawable-night-xxhdpi",
"drawable-night-xxxhdpi",
})
{
var path = Path.Combine(IntermediateOutputPath, directory);
if (Directory.Exists(path))
Directory.Delete(path, recursive: true);
}
}

void DeleteNightColors()
{
var colorsFile = Path.Combine(IntermediateOutputPath, "values-night", "maui_colors.xml");
if (File.Exists(colorsFile))
File.Delete(colorsFile);
}

void CleanStaleNightImageResources(bool resize)
{
foreach (var directory in resize ? NightOriginalResourceDirectories : NightDensityResourceDirectories)
{
var path = Path.Combine(IntermediateOutputPath, directory);
if (Directory.Exists(path))
Directory.Delete(path, recursive: true);
}
}

static readonly string[] NightOriginalResourceDirectories =
{
"drawable-night",
};

static readonly string[] NightDensityResourceDirectories =
{
"drawable-night-mdpi",
"drawable-night-hdpi",
"drawable-night-xhdpi",
"drawable-night-xxhdpi",
"drawable-night-xxxhdpi",
};

static string GetDarkOutputAlias(ResizeImageInfo info)
{
var extension = info.DarkIsVector || (string.IsNullOrWhiteSpace(info.DarkFilename) && info.IsVector)
? Resizer.RasterFileExtension
: !string.IsNullOrWhiteSpace(info.DarkFilename)
? Path.GetExtension(info.DarkFilename)
: info.OutputExtension;

return info.OutputName + extension;
}

static SKSize CalculateScaledSize(Resizer resizer)
{
var size = resizer.BaseSize ?? resizer.GetOriginalSize();
Expand Down
Loading
Loading