Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uno Platform Support #121

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions CSharpMath.Rendering/FrontEnd/ICSharpMathAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ public interface ICSharpMathAPI<TContent, TColor> where TContent : class {
TColor TextColor { get; set; }
TColor ErrorColor { get; set; }
///<summary>Unit of measure: points; Defaults to <see cref="FontSize"/>.</summary>
float? ErrorFontSize { get; set; }
double ErrorFontSize { get; set; }
bool DisplayErrorInline { get; set; }
PaintStyle PaintStyle { get; set; }
float Magnification { get; set; }
double Magnification { get; set; }
string? ErrorMessage { get; }
#endregion Non-display-recreating properties
#region Display-recreating properties
/// <summary>Unit of measure: points</summary>
float FontSize { get; set; }
double FontSize { get; set; }
System.Collections.Generic.IEnumerable<Typeface> LocalTypefaces { get; set; }
Atom.LineStyle LineStyle { get; set; }
TContent? Content { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Rendering/FrontEnd/MathPainter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override void UpdateDisplayCore(float unused) {
public override void Draw(TCanvas canvas, TextAlignment alignment = TextAlignment.Center, Thickness padding = default, float offsetX = 0, float offsetY = 0) {
var c = WrapCanvas(canvas);
UpdateDisplay(float.NaN);
DrawCore(c, Display, Display == null ? new PointF?() : IPainterExtensions.GetDisplayPosition(Display.Width, Display.Ascent, Display.Descent, FontSize, c.Width, c.Height, alignment, padding, offsetX, offsetY));
DrawCore(c, Display, Display == null ? new PointF?() : IPainterExtensions.GetDisplayPosition(Display.Width, Display.Ascent, Display.Descent, (float)FontSize, c.Width, c.Height, alignment, padding, offsetX, offsetY));
}
public void Draw(TCanvas canvas, float x, float y) {
var c = WrapCanvas(canvas);
Expand Down
12 changes: 6 additions & 6 deletions CSharpMath.Rendering/FrontEnd/Painter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public Painter() {
/// Unit of measure: points;
/// Defaults to <see cref="FontSize"/>.
/// </summary>
public float? ErrorFontSize { get; set; }
public double ErrorFontSize { get; set; }
public bool DisplayErrorInline { get; set; } = true;
public TColor ErrorColor { get; set; }
public TColor TextColor { get; set; }
public TColor HighlightColor { get; set; }
public (TColor glyph, TColor textRun)? GlyphBoxColor { get; set; }
public PaintStyle PaintStyle { get; set; } = PaintStyle.Fill;
public float Magnification { get; set; } = 1;
public double Magnification { get; set; } = 1;
public string? ErrorMessage { get; protected set; }
public abstract IDisplay<Fonts, Glyph>? Display { get; protected set; }
#endregion Non-redisplaying properties
Expand All @@ -47,9 +47,9 @@ public Painter() {
protected abstract void SetRedisplay();
protected Fonts Fonts { get; private set; } = new Fonts(Array.Empty<Typeface>(), DefaultFontSize);
/// <summary>Unit of measure: points</summary>
public float FontSize { get => Fonts.PointSize; set { Fonts = new Fonts(Fonts, value); SetRedisplay(); } }
public double FontSize { get => Fonts.PointSize; set { Fonts = new Fonts(Fonts, (float)value); SetRedisplay(); } }
IEnumerable<Typeface> __localTypefaces = Array.Empty<Typeface>();
public IEnumerable<Typeface> LocalTypefaces { get => __localTypefaces; set { Fonts = new Fonts(value, FontSize); __localTypefaces = value; SetRedisplay(); } }
public IEnumerable<Typeface> LocalTypefaces { get => __localTypefaces; set { Fonts = new Fonts(value, (float)FontSize); __localTypefaces = value; SetRedisplay(); } }
Atom.LineStyle __style = Atom.LineStyle.Display;
public Atom.LineStyle LineStyle { get => __style; set { __style = value; SetRedisplay(); } }
TContent? __content;
Expand All @@ -74,7 +74,7 @@ protected void UpdateDisplay(float textPainterCanvasWidth) {
UpdateDisplayCore(textPainterCanvasWidth);
if (Display == null && DisplayErrorInline && ErrorMessage != null) {
var font = Fonts;
if (ErrorFontSize is { } errorSize) font = new Fonts(font, errorSize);
if (ErrorFontSize > 0) font = new Fonts(font, (float)ErrorFontSize);
var errorLines = ErrorMessage.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
var runs = new List<Display.Displays.TextRunDisplay<Fonts, Glyph>>();
float y = 0;
Expand Down Expand Up @@ -116,7 +116,7 @@ protected void DrawCore(ICanvas canvas, IDisplay<Fonts, Glyph>? display, PointF?
canvas.Save();
//invert the canvas vertically: displays are drawn with mathematical coordinates, not graphical coordinates
canvas.Scale(1, -1);
canvas.Scale(Magnification, Magnification);
canvas.Scale((float)Magnification, (float)Magnification);
if (position is { } p) display.Position = new PointF(p.X, p.Y);
canvas.DefaultColor = WrapColor(TextColor);
canvas.CurrentColor = WrapColor(HighlightColor);
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Rendering/FrontEnd/TextPainter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void DrawCore(TCanvas canvas, float? width, TextAlignment alignment,
System.Math.Max(_relativeXCoordDisplay.Width, _absoluteXCoordDisplay.Width),
System.Math.Max(_relativeXCoordDisplay.Ascent, _absoluteXCoordDisplay.Ascent),
System.Math.Max(_relativeXCoordDisplay.Descent, _absoluteXCoordDisplay.Descent),
FontSize, width ?? c.Width,
(float)FontSize, width ?? c.Width,
c.Height, alignment, padding, offsetX, offsetY
));
var adjustedCanvasWidth =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Any raw assets you want to be deployed with your application can be placed in
this directory (and child directories) and given a Build Action of "AndroidAsset".

These files will be deployed with you package and will be accessible using Android's
AssetManager, like this:

public class ReadAsset : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);

InputStream input = Assets.Open ("my_asset.txt");
}
}

Additionally, some Android functions will automatically load asset files:

Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{B7759D42-229D-47CB-96A2-E99DB18AA316}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CSharpMath.UWPUno.Example.Droid</RootNamespace>
<AssemblyName>CSharpMath.UWPUno.Example.Droid</AssemblyName>
<FileAlignment>512</FileAlignment>
<AndroidApplication>true</AndroidApplication>
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<AndroidUseAapt2>true</AndroidUseAapt2>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v11.0</TargetFrameworkVersion>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseIntermediateDesignerFile>True</AndroidUseIntermediateDesignerFile>
<ResourcesDirectory>..\CSharpMath.UWPUno.Example.Shared\Strings</ResourcesDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
<AndroidLinkMode>None</AndroidLinkMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
<AndroidCreatePackagePerAbi>true</AndroidCreatePackagePerAbi>
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
<AotAssemblies>true</AotAssemblies>
<EnableLLVM>true</EnableLLVM>
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="Mono.Android.Export" />
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Uno.UI" Version="3.6.0-dev.81" />
<PackageReference Include="Uno.UI.RemoteControl" Version="3.6.0-dev.81" Condition="'$(Configuration)'=='Debug'" />
<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" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Main.cs" />
</ItemGroup>
<ItemGroup>
<AndroidAsset Include="Assets\Fonts\uno-fluentui-assets.ttf" />
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\values\Strings.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\Icon.png" />
</ItemGroup>
<ItemGroup>
<None Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<ItemGroup>
<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" />
<!-- This will force the generation of the APK when not building inside visual studio -->
<Target Name="GenerateBuild" DependsOnTargets="SignAndroidPackage" AfterTargets="Build" Condition="'$(BuildingInsideVisualStudio)'==''" />
<Target Name="Issue3897Workaround" Condition=" '$(ManagedDesignTimeBuild)' == 'True' " AfterTargets="_RemoveLegacyDesigner">
<!-- See https://github.com/unoplatform/uno/issues/3897 and https://github.com/xamarin/xamarin-android/issues/5069 for more details -->
<ItemGroup>
<Compile Remove="$(_AndroidResourceDesignerFile)" />
</ItemGroup>
</Target>
</Project>
43 changes: 43 additions & 0 deletions CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Droid/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Com.Nostra13.Universalimageloader.Core;
using Windows.UI.Xaml.Media;

namespace CSharpMath.UWPUno.Example.Droid
{
[global::Android.App.ApplicationAttribute(
Label = "@string/ApplicationName",
LargeHeap = true,
HardwareAccelerated = true,
Theme = "@style/AppTheme"
)]
public class Application : Windows.UI.Xaml.NativeApplication
{
public Application(IntPtr javaReference, JniHandleOwnership transfer)
: base(() => new App(), javaReference, transfer)
{
ConfigureUniversalImageLoader();
}

private void ConfigureUniversalImageLoader()
{
// Create global configuration and initialize ImageLoader with this config
ImageLoaderConfiguration config = new ImageLoaderConfiguration
.Builder(Context)
.Build();

ImageLoader.Instance.Init(config);

ImageSource.DefaultImageLoader = ImageLoader.Instance.LoadImageAsync;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Content.PM;
using Android.Views;

namespace CSharpMath.UWPUno.Example.Droid
{
[Activity(
MainLauncher = true,
ConfigurationChanges = global::Uno.UI.ActivityHelper.AllConfigChanges,
WindowSoftInputMode = SoftInput.AdjustPan | SoftInput.StateHidden
)]
public class MainActivity : Windows.UI.Xaml.ApplicationActivity
{
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +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="30" />
<application android:label="CSharpMath.UWPUno.Example"></application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CSharpMath.UWPUno.Example.Droid")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CSharpMath.UWPUno.Example.Droid")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Images, layout descriptions, binary blobs and string dictionaries can be included
in your application as resource files. Various Android APIs are designed to
operate on the resource IDs instead of dealing with images, strings or binary blobs
directly.

For example, a sample Android app that contains a user interface layout (main.axml),
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
would keep its resources in the "Resources" directory of the application:

Resources/
drawable/
icon.png

layout/
main.axml

values/
strings.xml

In order to get the build system to recognize Android resources, set the build action to
"AndroidResource". The native Android APIs do not operate directly with filenames, but
instead operate on resource IDs. When you compile an Android application that uses resources,
the build system will package the resources for distribution and generate a class called "R"
(this is an Android convention) that contains the tokens for each one of the resources
included. For example, for the above Resources layout, this is what the R class would expose:

public class R {
public class drawable {
public const int icon = 0x123;
}

public class layout {
public const int main = 0x456;
}

public class strings {
public const int first_string = 0xabc;
public const int second_string = 0xbcd;
}
}

You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main
to reference the layout/main.axml file, or R.strings.first_string to reference the first
string in the dictionary file values/strings.xml.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="Hello">Hello World, Click Me!</string>
<string name="ApplicationName">CSharpMath.UWPUno.Example</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">

<!-- This removes the ActionBar -->
<item name="windowActionBar">false</item>
<item name="android:windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowNoTitle">true</item>

</style>
</resources>
Loading