Skip to content

Commit

Permalink
Add MAUI sample (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
albi005 committed May 20, 2022
1 parent 617f99f commit f3a18ad
Show file tree
Hide file tree
Showing 38 changed files with 732 additions and 23 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
BUILD_CONFIG: 'Release'
SOLUTION: 'MaterialColorUtilities.sln'

runs-on: ubuntu-latest
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
Expand All @@ -33,22 +33,25 @@ jobs:
echo "BUILD_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
shell: pwsh

- name: Setup NuGet
uses: NuGet/setup-nuget@v1.0.6

- name: Restore dependencies
run: nuget restore $SOLUTION

- name: Setup .NET
uses: actions/setup-dotnet@v2.0.0
with:
dotnet-version: 6.0.x

- name: Install .NET MAUI workload
run: dotnet workload install maui

- name: Setup NuGet
uses: NuGet/setup-nuget@v1.0.6

- name: Restore dependencies
run: nuget restore $env:SOLUTION

- name: Build
run: dotnet build $SOLUTION --configuration $BUILD_CONFIG -p:Version=$BUILD_VERSION --no-restore
run: dotnet build $env:SOLUTION --configuration $env:BUILD_CONFIG -p:Version=$env:BUILD_VERSION --no-restore

- name: Run tests
run: dotnet test /p:Configuration=$BUILD_CONFIG --no-restore --no-build --verbosity normal
run: dotnet test /p:Configuration=$env:BUILD_CONFIG --no-restore --no-build --verbosity normal

- name: Publish
if: startsWith(github.ref, 'refs/tags/v')
Expand Down
28 changes: 21 additions & 7 deletions MaterialColorUtilities.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ VisualStudioVersion = 17.1.31911.260
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaterialColorUtilities", "MaterialColorUtilities\MaterialColorUtilities.csproj", "{0281EA50-1EDE-4AB7-BA15-DA37126A5E52}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaterialColorUtilities.Console", "MaterialColorUtilities.Console\MaterialColorUtilities.Console.csproj", "{14D6A693-7174-4A4C-B1EF-3528B98041B2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaterialColorUtilities.Tests", "MaterialColorUtilities.Tests\MaterialColorUtilities.Tests.csproj", "{35FD1BCC-D495-463C-8DE8-4E18EBC1790E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaterialColorUtilities.SourceGenerators", "MaterialColorUtilities.SourceGenerators\MaterialColorUtilities.SourceGenerators.csproj", "{13AF7E9C-9F4A-4D9C-BA64-0A7BAA23C0A1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaterialColorUtilities.SourceGenerators", "MaterialColorUtilities.SourceGenerators\MaterialColorUtilities.SourceGenerators.csproj", "{13AF7E9C-9F4A-4D9C-BA64-0A7BAA23C0A1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaterialColorUtilities.Samples.Console", "Samples\MaterialColorUtilities.Samples.Console\MaterialColorUtilities.Samples.Console.csproj", "{14D6A693-7174-4A4C-B1EF-3528B98041B2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaterialColorUtilities.Samples.Maui", "Samples\MaterialColorUtilities.Samples.Maui\MaterialColorUtilities.Samples.Maui.csproj", "{1A4BD9E1-4EC5-4D39-B643-08EEDCA3F59E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{097D3E8C-2CB9-49CE-B4D8-2F4BC94A78A5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -21,10 +25,6 @@ Global
{0281EA50-1EDE-4AB7-BA15-DA37126A5E52}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0281EA50-1EDE-4AB7-BA15-DA37126A5E52}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0281EA50-1EDE-4AB7-BA15-DA37126A5E52}.Release|Any CPU.Build.0 = Release|Any CPU
{14D6A693-7174-4A4C-B1EF-3528B98041B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{14D6A693-7174-4A4C-B1EF-3528B98041B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{14D6A693-7174-4A4C-B1EF-3528B98041B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{14D6A693-7174-4A4C-B1EF-3528B98041B2}.Release|Any CPU.Build.0 = Release|Any CPU
{35FD1BCC-D495-463C-8DE8-4E18EBC1790E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{35FD1BCC-D495-463C-8DE8-4E18EBC1790E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35FD1BCC-D495-463C-8DE8-4E18EBC1790E}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -33,10 +33,24 @@ Global
{13AF7E9C-9F4A-4D9C-BA64-0A7BAA23C0A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13AF7E9C-9F4A-4D9C-BA64-0A7BAA23C0A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13AF7E9C-9F4A-4D9C-BA64-0A7BAA23C0A1}.Release|Any CPU.Build.0 = Release|Any CPU
{14D6A693-7174-4A4C-B1EF-3528B98041B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{14D6A693-7174-4A4C-B1EF-3528B98041B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{14D6A693-7174-4A4C-B1EF-3528B98041B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{14D6A693-7174-4A4C-B1EF-3528B98041B2}.Release|Any CPU.Build.0 = Release|Any CPU
{1A4BD9E1-4EC5-4D39-B643-08EEDCA3F59E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A4BD9E1-4EC5-4D39-B643-08EEDCA3F59E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A4BD9E1-4EC5-4D39-B643-08EEDCA3F59E}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{1A4BD9E1-4EC5-4D39-B643-08EEDCA3F59E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A4BD9E1-4EC5-4D39-B643-08EEDCA3F59E}.Release|Any CPU.Build.0 = Release|Any CPU
{1A4BD9E1-4EC5-4D39-B643-08EEDCA3F59E}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{14D6A693-7174-4A4C-B1EF-3528B98041B2} = {097D3E8C-2CB9-49CE-B4D8-2F4BC94A78A5}
{1A4BD9E1-4EC5-4D39-B643-08EEDCA3F59E} = {097D3E8C-2CB9-49CE-B4D8-2F4BC94A78A5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BBCD7EC3-2035-4EAC-B506-48CDDAEBC992}
EndGlobalSection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MaterialColorUtilities.Console
namespace MaterialColorUtilities.Samples.Console
{
public class ConsoleHelper
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MaterialColorUtilities.SourceGenerators\MaterialColorUtilities.SourceGenerators.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"/>
<ProjectReference Include="..\MaterialColorUtilities\MaterialColorUtilities.csproj" />
<ProjectReference
Include="..\..\MaterialColorUtilities.SourceGenerators\MaterialColorUtilities.SourceGenerators.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"/>
<ProjectReference Include="..\..\MaterialColorUtilities\MaterialColorUtilities.csproj" />
</ItemGroup>


</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MaterialColorUtilities.Blend;
using MaterialColorUtilities.Console;
using MaterialColorUtilities.Palettes;
using MaterialColorUtilities.Samples.Console;
using MaterialColorUtilities.Schemes;
using MaterialColorUtilities.Utils;
using SkiaSharp;
Expand All @@ -10,7 +10,7 @@
// Extract a seed color from an image:
// Load the image into an int[].
// The image is stored in an embedded resource, and then decoded and resized using SkiaSharp.
string imageResourceId = "MaterialColorUtilities.Console.Resources.wallpaper.webp";
string imageResourceId = "MaterialColorUtilities.Samples.Console.Resources.wallpaper.webp";
using Stream resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(imageResourceId);
SKBitmap bitmap = SKBitmap.Decode(resourceStream).Resize(new SKImageInfo(112, 112), SKFilterQuality.Medium);
int[] pixels = bitmap.Pixels.Select(p => (int)(uint)p).ToArray();
Expand Down
95 changes: 95 additions & 0 deletions Samples/MaterialColorUtilities.Samples.Maui/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MaterialColorUtilities.Samples.Maui"
x:Class="MaterialColorUtilities.Samples.Maui.App">
<Application.Resources>
<!--Placeholders for IntelliSense-->
<Color x:Key="Primary" />
<Color x:Key="PrimaryContainer" />
<Color x:Key="Secondary" />
<Color x:Key="SecondaryContainer" />
<Color x:Key="Tertiary" />
<Color x:Key="TertiaryContainer" />
<Color x:Key="Surface" />
<Color x:Key="SurfaceVariant" />
<Color x:Key="Background" />
<Color x:Key="Error" />
<Color x:Key="ErrorContainer" />
<Color x:Key="OnPrimary" />
<Color x:Key="OnPrimaryContainer" />
<Color x:Key="OnSecondary" />
<Color x:Key="OnSecondaryContainer" />
<Color x:Key="OnTertiary" />
<Color x:Key="OnTertiaryContainer" />
<Color x:Key="OnSurface" />
<Color x:Key="OnSurfaceVariant" />
<Color x:Key="OnError" />
<Color x:Key="OnErrorContainer" />
<Color x:Key="OnBackground" />
<Color x:Key="Outline" />
<Color x:Key="Shadow" />
<Color x:Key="InverseSurface" />
<Color x:Key="InverseOnSurface" />
<Color x:Key="InversePrimary" />
<Color x:Key="Elevation1" />
<Color x:Key="Elevation2" />
<Color x:Key="Elevation3" />
<Color x:Key="Elevation4" />
<Color x:Key="Elevation5" />
<SolidColorBrush x:Key="PrimaryBrush" />
<SolidColorBrush x:Key="PrimaryContainerBrush" />
<SolidColorBrush x:Key="SecondaryBrush" />
<SolidColorBrush x:Key="SecondaryContainerBrush" />
<SolidColorBrush x:Key="TertiaryBrush" />
<SolidColorBrush x:Key="TertiaryContainerBrush" />
<SolidColorBrush x:Key="SurfaceBrush" />
<SolidColorBrush x:Key="SurfaceVariantBrush" />
<SolidColorBrush x:Key="BackgroundBrush" />
<SolidColorBrush x:Key="ErrorBrush" />
<SolidColorBrush x:Key="ErrorContainerBrush" />
<SolidColorBrush x:Key="OnPrimaryBrush" />
<SolidColorBrush x:Key="OnPrimaryContainerBrush" />
<SolidColorBrush x:Key="OnSecondaryBrush" />
<SolidColorBrush x:Key="OnSecondaryContainerBrush" />
<SolidColorBrush x:Key="OnTertiaryBrush" />
<SolidColorBrush x:Key="OnTertiaryContainerBrush" />
<SolidColorBrush x:Key="OnSurfaceBrush" />
<SolidColorBrush x:Key="OnSurfaceVariantBrush" />
<SolidColorBrush x:Key="OnErrorBrush" />
<SolidColorBrush x:Key="OnErrorContainerBrush" />
<SolidColorBrush x:Key="OnBackgroundBrush" />
<SolidColorBrush x:Key="OutlineBrush" />
<SolidColorBrush x:Key="ShadowBrush" />
<SolidColorBrush x:Key="InverseSurfaceBrush" />
<SolidColorBrush x:Key="InverseOnSurfaceBrush" />
<SolidColorBrush x:Key="InversePrimaryBrush" />
<SolidColorBrush x:Key="Elevation1Brush" />
<SolidColorBrush x:Key="Elevation2Brush" />
<SolidColorBrush x:Key="Elevation3Brush" />
<SolidColorBrush x:Key="Elevation4Brush" />
<SolidColorBrush x:Key="Elevation5Brush" />

<Style TargetType="Page" ApplyToDerivedTypes="True">
<Setter Property="BackgroundColor" Value="{DynamicResource Background}" />
</Style>

<Style TargetType="Slider">
<Setter Property="MinimumTrackColor" Value="{DynamicResource Primary}" />
<Setter Property="MaximumTrackColor" Value="{OnPlatform Android={DynamicResource Primary}, Default={DynamicResource SurfaceVariant}}" />
<Setter Property="ThumbColor" Value="{DynamicResource Primary}" />
</Style>

<Style x:Key="BaseStyle" TargetType="Element">
<Setter Property="Shell.BackgroundColor" Value="{DynamicResource Elevation2}" />
<Setter Property="Shell.ForegroundColor" Value="{DynamicResource OnSurface}" />
<Setter Property="Shell.TitleColor" Value="{DynamicResource OnSurface}" />
</Style>
<Style BasedOn="{StaticResource BaseStyle}" TargetType="ShellItem" ApplyToDerivedTypes="True" />

<Style TargetType="Label">
<Setter Property="TextColor" Value="{DynamicResource OnSurface}" />
</Style>

</Application.Resources>
</Application>
17 changes: 17 additions & 0 deletions Samples/MaterialColorUtilities.Samples.Maui/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using MaterialColorUtilities.Samples.Maui.Services;

namespace MaterialColorUtilities.Samples.Maui
{
public partial class App : Application
{
public App(ThemeService themeService)
{
InitializeComponent();

themeService.Apply();
RequestedThemeChanged += (sender, args) => themeService.Apply();

MainPage = new AppShell();
}
}
}
40 changes: 40 additions & 0 deletions Samples/MaterialColorUtilities.Samples.Maui/AppScheme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using MaterialColorUtilities.Blend;
using MaterialColorUtilities.Palettes;
using MaterialColorUtilities.Schemes;

namespace MaterialColorUtilities.Samples.Maui;

public partial class AppScheme<TColor> : Scheme<TColor>
{
public TColor Elevation1 { get; set; }
public TColor Elevation2 { get; set; }
public TColor Elevation3 { get; set; }
public TColor Elevation4 { get; set; }
public TColor Elevation5 { get; set; }
}

public class DarkAppSchemeMapper : DarkSchemeMapper<CorePalette, AppScheme<int>>
{
protected override void MapCore(CorePalette corePalette, AppScheme<int> scheme)
{
base.MapCore(corePalette, scheme);
scheme.Elevation1 = Blender.Cam16Ucs(scheme.Background, scheme.Primary, .05);
scheme.Elevation2 = Blender.Cam16Ucs(scheme.Background, scheme.Primary, .08);
scheme.Elevation3 = Blender.Cam16Ucs(scheme.Background, scheme.Primary, .11);
scheme.Elevation4 = Blender.Cam16Ucs(scheme.Background, scheme.Primary, .12);
scheme.Elevation5 = Blender.Cam16Ucs(scheme.Background, scheme.Primary, .14);
}
}

public class LightAppSchemeMapper : LightSchemeMapper<CorePalette, AppScheme<int>>
{
protected override void MapCore(CorePalette corePalette, AppScheme<int> scheme)
{
base.MapCore(corePalette, scheme);
scheme.Elevation1 = Blender.Cam16Ucs(scheme.Background, scheme.Primary, .05);
scheme.Elevation2 = Blender.Cam16Ucs(scheme.Background, scheme.Primary, .08);
scheme.Elevation3 = Blender.Cam16Ucs(scheme.Background, scheme.Primary, .11);
scheme.Elevation4 = Blender.Cam16Ucs(scheme.Background, scheme.Primary, .12);
scheme.Elevation5 = Blender.Cam16Ucs(scheme.Background, scheme.Primary, .14);
}
}
21 changes: 21 additions & 0 deletions Samples/MaterialColorUtilities.Samples.Maui/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="MaterialColorUtilities.Samples.Maui.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MaterialColorUtilities.Samples.Maui"
Shell.FlyoutBehavior="Flyout"
>

<ShellContent
Title="Theme settings"
ContentTemplate="{DataTemplate local:ThemePage}"
Route="ThemePage"
/>

<ShellContent
Title="Graphs"
ContentTemplate="{DataTemplate local:GraphsPage}"
Route="GraphsPage" />

</Shell>
10 changes: 10 additions & 0 deletions Samples/MaterialColorUtilities.Samples.Maui/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace MaterialColorUtilities.Samples.Maui
{
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
}
Loading

0 comments on commit f3a18ad

Please sign in to comment.