Skip to content

Commit

Permalink
First working Android, UWP samples
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Jan 17, 2021
1 parent cb747a0 commit 114bfce
Show file tree
Hide file tree
Showing 17 changed files with 739 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<AndroidUseAapt2>true</AndroidUseAapt2>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v11.0</TargetFrameworkVersion>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseIntermediateDesignerFile>True</AndroidUseIntermediateDesignerFile>
<ResourcesDirectory>..\CSharpMath.UWPUno.Example.Shared\Strings</ResourcesDirectory>
Expand Down Expand Up @@ -65,6 +65,9 @@
<PackageReference Include="Uno.UniversalImageLoader" Version="1.9.33" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.1" />
<PackageReference Include="Validation">
<Version>2.4.22</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
Expand All @@ -89,10 +92,26 @@
<AndroidResource Include="Resources\values\Styles.xml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\CSharpMath.Editor\CSharpMath.Editor.csproj">
<Project>{38f58489-ede4-4289-8acf-a9756977a7a6}</Project>
<Name>CSharpMath.Editor</Name>
</ProjectReference>
<ProjectReference Include="..\..\CSharpMath.Rendering\CSharpMath.Rendering.csproj">
<Project>{65016a61-2125-4e0c-90e8-a915230c7826}</Project>
<Name>CSharpMath.Rendering</Name>
</ProjectReference>
<ProjectReference Include="..\..\CSharpMath.SkiaSharp\CSharpMath.SkiaSharp.csproj">
<Project>{35b4bb5b-2202-436e-9afe-00997ca2cc65}</Project>
<Name>CSharpMath.SkiaSharp</Name>
</ProjectReference>
<ProjectReference Include="..\..\CSharpMath.UWPUno\CSharpMath.UWPUno.csproj">
<Project>{5c46ca75-fa31-4281-80eb-a07750e1fecb}</Project>
<Name>CSharpMath.UWPUno</Name>
</ProjectReference>
<ProjectReference Include="..\..\CSharpMath\CSharpMath.csproj">
<Project>{5157367b-f03e-4acb-83a1-0de414a3bfca}</Project>
<Name>CSharpMath</Name>
</ProjectReference>
</ItemGroup>
<Import Project="..\CSharpMath.UWPUno.Example.Shared\CSharpMath.UWPUno.Example.Shared.projitems" Label="Shared" Condition="Exists('..\CSharpMath.UWPUno.Example.Shared\CSharpMath.UWPUno.Example.Shared.projitems')" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="CSharpMath.UWPUno.Example" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="29" />
<application android:label="CSharpMath.UWPUno.Example"></application>
</manifest>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="30" />
<application android:label="CSharpMath.UWPUno.Example"></application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,33 @@
<Compile Include="$(MSBuildThisFileDirectory)App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)ClockPage.xaml.cs">
<DependentUpon>ClockPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)MoreExamples.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MoreExamplesPage.xaml.cs">
<DependentUpon>MoreExamplesPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)TryPage.xaml.cs">
<DependentUpon>TryPage.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Include="$(MSBuildThisFileDirectory)ClockPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)MainPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)MoreExamplesPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)TryPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Page
x:Class="CSharpMath.UWPUno.Example.ClockPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CSharpMath.UWPUno.Example"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:skia="using:SkiaSharp.Views.UWP"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<skia:SKXamlCanvas
x:Name="canvasView"
VerticalAlignment="Stretch"
PaintSurface="CanvasView_PaintSurface" />
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using CSharpMath.SkiaSharp;
using SkiaSharp;
using SkiaSharp.Views.UWP;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using static System.Math;

namespace CSharpMath.UWPUno.Example {
public sealed partial class ClockPage : Page {
private readonly DispatcherTimer _timer;

public ClockPage() {
this.InitializeComponent();
_timer = new DispatcherTimer();
_timer.Interval = TimeSpan.FromMilliseconds(200);
_timer.Tick += (s, e) => {
canvasView.Invalidate();
};
this.Loaded += ClockPage_Loaded;
this.Unloaded += ClockPage_Unloaded;
}

private void ClockPage_Loaded(object sender, RoutedEventArgs e) {
_timer.Start();
}

private void ClockPage_Unloaded(object sender, RoutedEventArgs e) {
_timer.Stop();
}

readonly SKPaint blackFillPaint = new SKPaint {
Style = SKPaintStyle.Fill,
Color = SKColors.Black
};
readonly SKPaint whiteFillPaint = new SKPaint {
Style = SKPaintStyle.Fill,
Color = SKColors.White
};
readonly SKPaint whiteStrokePaint = new SKPaint {
Style = SKPaintStyle.Stroke,
Color = SKColors.White,
StrokeCap = SKStrokeCap.Round,
IsAntialias = true
};
readonly SKPaint redStrokePaint = new SKPaint {
Style = SKPaintStyle.Stroke,
Color = SKColors.Red,
StrokeCap = SKStrokeCap.Round,
IsAntialias = true
};
readonly string[] labels = {
// Four 4s make 1 to 12 using different operations
@"$\frac{44+4}{4}$",
@"$\frac{44}{44}$",
@"$\frac{4}{4}+\frac{4}{4}$",
@"$\frac{4+4+4}{4}$",
@"$4+\frac{4-4}{4}$",
@"$4+4^{4-4}$",
@"$4+\frac{4+4}{4}$",
@"$\frac{44}{4}-4$",
@"$\sqrt{4}^{4-\frac{4}{4}}$",
@"$\:\:(4-\frac{4}{4})^{\sqrt{4}}$",
@"$\frac{44-4}{4}$",
@"$\frac{4!}{\sqrt{4}}-\frac{4}{4}$"
};
private void CanvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs e) {
var canvas = e.Surface.Canvas;
canvas.Clear(SKColors.CornflowerBlue);
canvas.Translate(e.Info.Width / 2, e.Info.Height / 2);
canvas.Scale(e.Info.Width / 210f);
canvas.DrawCircle(0, 0, 100, blackFillPaint);
var painter = new TextPainter { FontSize = 8, TextColor = SKColors.White };
for (int i = 0; i < 60; i++) {
// Dots
canvas.Save();
canvas.RotateDegrees(6 * i);
canvas.DrawCircle(0, -90, i % 5 == 0 ? 4 : 2, whiteFillPaint);
canvas.Restore();
// Maths
if (i % 5 == 0) {
painter.LaTeX = labels[i / 5];
if (!(painter.Measure(e.Info.Width) is { } measure))
throw new Structures.InvalidCodePathException("Invalid LaTeX");
var θ = (90 - 6 * i) / 180f * PI;
var sinθ = (float)Sin(θ);
var cosθ = (float)Cos(θ);
painter.Draw(canvas,
new System.Drawing.PointF(75 * cosθ - (float)measure.Width / 2,
-75 * sinθ - (float)measure.Height / 2),
float.PositiveInfinity);
}
}
var dateTime = DateTime.Now;
// H
canvas.Save();
canvas.RotateDegrees(30 * dateTime.Hour + dateTime.Minute / 2f);
whiteStrokePaint.StrokeWidth = 12;
canvas.DrawLine(0, 0, 0, -50, whiteStrokePaint);
canvas.Restore();
// M
canvas.Save();
canvas.RotateDegrees(6 * dateTime.Minute + dateTime.Second / 10f);
whiteStrokePaint.StrokeWidth = 6;
canvas.DrawLine(0, 0, 0, -65, whiteStrokePaint);
canvas.Restore();
// S
canvas.Save();
canvas.RotateDegrees(6f * (dateTime.Second + dateTime.Millisecond / 1000f));
redStrokePaint.StrokeWidth = 2;
canvas.DrawLine(0, 0, 0, -75, redStrokePaint);
canvas.Restore();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<PivotItem Header="Try">
<local:TryPage />
</PivotItem>
<!--<PivotItem Header="More examples">
<shared:MoreExamplesPage />
<PivotItem Header="More examples">
<local:MoreExamplesPage />
</PivotItem>
<PivotItem Header="Clock">
<shared:ClockPage />
</PivotItem>-->
<local:ClockPage />
</PivotItem>
</Pivot>
</Grid>
</Page>
Loading

0 comments on commit 114bfce

Please sign in to comment.