Adding Android Skia binding
- Android binding project created - Using the system skia. Need to build the Android version. The system skia is not working on all devices. Guessing you need Android M. - Android Forms sample hooked up - Moved the upper left matrix change to the iOS native view. Otherwise Android has to apply it twice.
This commit is contained in:
Родитель
186c976097
Коммит
b0f2d2343d
|
@ -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.
|
|
@ -0,0 +1,57 @@
|
|||
#pragma warning disable 1591
|
||||
// ------------------------------------------------------------------------------
|
||||
// <autogenerated>
|
||||
// This code was generated by a tool.
|
||||
// Mono Runtime Version: 4.0.30319.17020
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </autogenerated>
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
[assembly: Android.Runtime.ResourceDesignerAttribute("SkiaSharp.Android.Resource", IsApplication=false)]
|
||||
|
||||
namespace SkiaSharp.Android
|
||||
{
|
||||
|
||||
|
||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
|
||||
public partial class Resource
|
||||
{
|
||||
|
||||
static Resource()
|
||||
{
|
||||
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
|
||||
}
|
||||
|
||||
public partial class Attribute
|
||||
{
|
||||
|
||||
static Attribute()
|
||||
{
|
||||
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
|
||||
}
|
||||
|
||||
private Attribute()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public partial class String
|
||||
{
|
||||
|
||||
// aapt resource value: 0x7f020000
|
||||
public static int library_name = 2130837504;
|
||||
|
||||
static String()
|
||||
{
|
||||
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
|
||||
}
|
||||
|
||||
private String()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore 1591
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="library_name">SkiaSharp.Android</string>
|
||||
</resources>
|
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<ProjectGuid>{C737DC80-5B71-4B26-A2DC-DA30421788B0}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>SkiaSharp.Android</RootNamespace>
|
||||
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
|
||||
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
|
||||
<AndroidResgenClass>Resource</AndroidResgenClass>
|
||||
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
|
||||
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
|
||||
<AssemblyName>SkiaSharp</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.3</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AndroidLinkMode>None</AndroidLinkMode>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Mono.Android" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Resources\Resource.designer.cs" />
|
||||
<Compile Include="..\SharedProps\SkiaSharpAssemblyInfo.cs">
|
||||
<Link>Properties\SkiaSharpAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\AboutResources.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidResource Include="Resources\values\Strings.xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\Binding\Binding.projitems" Label="Shared" Condition="Exists('..\Binding\Binding.projitems')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -14,10 +14,6 @@ namespace Skia.Forms.Demo
|
|||
|
||||
public static void DrawXamagon (SKCanvas canvas, int width, int height)
|
||||
{
|
||||
// Set the origin to the top left
|
||||
canvas.Scale (1, -1);
|
||||
canvas.Translate (0, -height);
|
||||
|
||||
// Width 41.6587026 => 144.34135
|
||||
// Height 56 => 147
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using Android.Views;
|
||||
using Android.Graphics;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Skia.Forms.Demo.Droid
|
||||
{
|
||||
public class NativeSkiaView : View
|
||||
{
|
||||
private Bitmap bitmap;
|
||||
SkiaView skiaView;
|
||||
|
||||
public NativeSkiaView (Android.Content.Context context, SkiaView skiaView) : base (context)
|
||||
{
|
||||
this.skiaView = skiaView;
|
||||
}
|
||||
|
||||
protected override void OnDraw (Android.Graphics.Canvas canvas)
|
||||
{
|
||||
base.OnDraw (canvas);
|
||||
|
||||
if (bitmap == null || bitmap.Width != canvas.Width || bitmap.Height != canvas.Height) {
|
||||
if (bitmap != null)
|
||||
bitmap.Dispose ();
|
||||
|
||||
bitmap = Bitmap.CreateBitmap (canvas.Width, canvas.Height, Bitmap.Config.Argb8888);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (var surface = SKSurface.Create (canvas.Width, canvas.Height, SKColorType.Rgba_8888, SKAlphaType.Premul, bitmap.LockPixels (), canvas.Width * 4)) {
|
||||
var skcanvas = surface.Canvas;
|
||||
skcanvas.Scale (((float)canvas.Width)/(float)skiaView.Width, ((float)canvas.Height)/(float)skiaView.Height);
|
||||
(skiaView as ISkiaViewController).SendDraw (skcanvas);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
bitmap.UnlockPixels ();
|
||||
}
|
||||
|
||||
canvas.DrawBitmap (bitmap, 0, 0, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ namespace Skia.Forms.Demo.Droid
|
|||
|
||||
public static void UpdateIdValues()
|
||||
{
|
||||
global::SkiaSharp.Android.Resource.String.library_name = global::Skia.Forms.Demo.Droid.Resource.String.library_name;
|
||||
}
|
||||
|
||||
public partial class Attribute
|
||||
|
@ -56,6 +57,22 @@ namespace Skia.Forms.Demo.Droid
|
|||
{
|
||||
}
|
||||
}
|
||||
|
||||
public partial class String
|
||||
{
|
||||
|
||||
// aapt resource value: 0x7f030000
|
||||
public const int library_name = 2130903040;
|
||||
|
||||
static String()
|
||||
{
|
||||
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
|
||||
}
|
||||
|
||||
private String()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore 1591
|
||||
|
|
|
@ -63,11 +63,17 @@
|
|||
<Project>{F750563C-EF08-4BCB-AF58-C98C307B01B5}</Project>
|
||||
<Name>Skia.Forms.Demo</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\binding\SkiaSharp.Android\SkiaSharp.Android.csproj">
|
||||
<Project>{C737DC80-5B71-4B26-A2DC-DA30421788B0}</Project>
|
||||
<Name>SkiaSharp.Android</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MainActivity.cs" />
|
||||
<Compile Include="Resources\Resource.designer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="NativeSkiaView.cs" />
|
||||
<Compile Include="SkiaViewRenderer.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\AboutResources.txt" />
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.Android;
|
||||
|
||||
[assembly: ExportRenderer (typeof(Skia.Forms.Demo.SkiaView), typeof(Skia.Forms.Demo.Droid.SkiaViewRenderer))]
|
||||
|
||||
namespace Skia.Forms.Demo.Droid
|
||||
{
|
||||
public class SkiaViewRenderer : ViewRenderer<SkiaView, NativeSkiaView>
|
||||
{
|
||||
NativeSkiaView view;
|
||||
|
||||
public SkiaViewRenderer ()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnElementChanged (ElementChangedEventArgs<SkiaView> e)
|
||||
{
|
||||
base.OnElementChanged (e);
|
||||
|
||||
if (Control == null) {
|
||||
view = new NativeSkiaView (Context, Element);
|
||||
SetNativeControl (view);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.iOS", "..\..\bind
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.Portable", "..\..\binding\SkiaSharp.Portable\SkiaSharp.Portable.csproj", "{7AA90628-2FDD-4585-AF2F-CC51CFA8B52A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.Android", "..\..\binding\SkiaSharp.Android\SkiaSharp.Android.csproj", "{C737DC80-5B71-4B26-A2DC-DA30421788B0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -59,6 +61,18 @@ Global
|
|||
{7AA90628-2FDD-4585-AF2F-CC51CFA8B52A}.Release|iPhone.Build.0 = Release|Any CPU
|
||||
{7AA90628-2FDD-4585-AF2F-CC51CFA8B52A}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||
{7AA90628-2FDD-4585-AF2F-CC51CFA8B52A}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
||||
{C737DC80-5B71-4B26-A2DC-DA30421788B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C737DC80-5B71-4B26-A2DC-DA30421788B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C737DC80-5B71-4B26-A2DC-DA30421788B0}.Debug|iPhone.ActiveCfg = Debug|Any CPU
|
||||
{C737DC80-5B71-4B26-A2DC-DA30421788B0}.Debug|iPhone.Build.0 = Debug|Any CPU
|
||||
{C737DC80-5B71-4B26-A2DC-DA30421788B0}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||
{C737DC80-5B71-4B26-A2DC-DA30421788B0}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||
{C737DC80-5B71-4B26-A2DC-DA30421788B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C737DC80-5B71-4B26-A2DC-DA30421788B0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C737DC80-5B71-4B26-A2DC-DA30421788B0}.Release|iPhone.ActiveCfg = Release|Any CPU
|
||||
{C737DC80-5B71-4B26-A2DC-DA30421788B0}.Release|iPhone.Build.0 = Release|Any CPU
|
||||
{C737DC80-5B71-4B26-A2DC-DA30421788B0}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||
{C737DC80-5B71-4B26-A2DC-DA30421788B0}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
||||
{E2A02581-8F55-400F-951C-691EADFD7D3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E2A02581-8F55-400F-951C-691EADFD7D3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E2A02581-8F55-400F-951C-691EADFD7D3A}.Debug|iPhone.ActiveCfg = Debug|Any CPU
|
||||
|
|
|
@ -27,8 +27,12 @@ namespace Skia.Forms.Demo.iOS
|
|||
try {
|
||||
|
||||
using (var surface = SKSurface.Create (width, height, SKColorType.Rgba_8888, SKAlphaType.Premul, buff, width * 4)) {
|
||||
surface.Canvas.Scale (screenScale, screenScale);
|
||||
skiaView.SendDraw (surface.Canvas);
|
||||
var skcanvas = surface.Canvas;
|
||||
|
||||
// 2 for one here. Scaling to the pixel size + moving the origin to the top left
|
||||
skcanvas.Scale (screenScale, -screenScale);
|
||||
skcanvas.Translate (0, (float)-Frame.Height);
|
||||
skiaView.SendDraw (skcanvas);
|
||||
}
|
||||
|
||||
using (var colorSpace = CoreGraphics.CGColorSpace.CreateDeviceRGB ()) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче