14 changed files with 601 additions and 2 deletions
@ -0,0 +1,71 @@ |
|||
using System; |
|||
using Android.App; |
|||
using Android.Content; |
|||
using Android.Graphics; |
|||
using Android.Runtime; |
|||
using Android.Views; |
|||
using Android.Widget; |
|||
using Android.OS; |
|||
using Android.Util; |
|||
using Perspex.Media; |
|||
using Perspex.Platform; |
|||
using Perspex; |
|||
|
|||
namespace Perspex.Skia.Android.TestApp |
|||
{ |
|||
[Activity(Label = "Perspex.Skia.Android.TestApp", MainLauncher = true, Icon = "@drawable/icon")] |
|||
public class MainActivity : Activity |
|||
{ |
|||
|
|||
protected override void OnCreate(Bundle bundle) |
|||
{ |
|||
base.OnCreate(bundle); |
|||
SetContentView(new MainView(this)); |
|||
} |
|||
|
|||
class MainView : SkiaView |
|||
{ |
|||
float _radians = 0; |
|||
public MainView(Activity context) : base(context) |
|||
{ |
|||
} |
|||
|
|||
protected override void OnRender(DrawingContext ctx) |
|||
{ |
|||
ctx.FillRectangle(Brushes.Green, new Rect(0, 0, Width, Height)); |
|||
|
|||
var rc = new Rect(0, 0, Width/3, Height/3); |
|||
using (ctx.PushPostTransform( |
|||
Perspex.Matrix.CreateTranslation(-Width/6, -Width/6)* |
|||
Perspex.Matrix.CreateRotation(_radians)* |
|||
Perspex.Matrix.CreateTranslation(Width/2, Height/2))) |
|||
{ |
|||
ctx.FillRectangle(new LinearGradientBrush() |
|||
{ |
|||
GradientStops = |
|||
{ |
|||
new GradientStop() {Color = Colors.Blue}, |
|||
new GradientStop(Colors.Red, 1) |
|||
} |
|||
}, rc, 5); |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
public override bool OnTouchEvent(MotionEvent e) |
|||
{ |
|||
if (e.Action == MotionEventActions.Down) |
|||
return true; |
|||
if (e.Action == MotionEventActions.Move) |
|||
{ |
|||
_radians = (e.RawY + e.RawY)/100; |
|||
Invalidate(); |
|||
return true; |
|||
} |
|||
return base.OnTouchEvent(e); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,122 @@ |
|||
<?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>{F92E55A5-ED73-4CCB-AB4B-0541B6757F31}</ProjectGuid> |
|||
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
|||
<OutputType>Library</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>Perspex.Skia.Android.TestApp</RootNamespace> |
|||
<AssemblyName>Perspex.Skia.Android.TestApp</AssemblyName> |
|||
<FileAlignment>512</FileAlignment> |
|||
<AndroidApplication>true</AndroidApplication> |
|||
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile> |
|||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies> |
|||
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk> |
|||
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion> |
|||
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime> |
|||
<AndroidLinkMode>None</AndroidLinkMode> |
|||
<AndroidLinkSkip /> |
|||
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk> |
|||
<BundleAssemblies>False</BundleAssemblies> |
|||
<AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi> |
|||
<AndroidSupportedAbis>armeabi-v7a,x86</AndroidSupportedAbis> |
|||
<AndroidStoreUncompressedFileExtensions /> |
|||
<MandroidI18n /> |
|||
<Debugger>Xamarin</Debugger> |
|||
<AndroidEnableMultiDex>False</AndroidEnableMultiDex> |
|||
<DevInstrumentationEnabled>True</DevInstrumentationEnabled> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime> |
|||
<AndroidLinkMode>SdkOnly</AndroidLinkMode> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="Mono.Android" /> |
|||
<Reference Include="mscorlib" /> |
|||
<Reference Include="System" /> |
|||
<Reference Include="System.Collections" /> |
|||
<Reference Include="System.Core" /> |
|||
<Reference Include="System.Runtime" /> |
|||
<Reference Include="System.Xml.Linq" /> |
|||
<Reference Include="System.Xml" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Compile Include="MainActivity.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
<Compile Include="Resources\Resource.Designer.cs" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<None Include="Properties\AndroidManifest.xml" /> |
|||
<AndroidResource Include="Resources\layout\Main.axml" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\Perspex.Animation\Perspex.Animation.csproj"> |
|||
<Project>{d211e587-d8bc-45b9-95a4-f297c8fa5200}</Project> |
|||
<Name>Perspex.Animation</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Base\Perspex.Base.csproj"> |
|||
<Project>{b09b78d8-9b26-48b0-9149-d64a2f120f3f}</Project> |
|||
<Name>Perspex.Base</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Controls\Perspex.Controls.csproj"> |
|||
<Project>{d2221c82-4a25-4583-9b43-d791e3f6820c}</Project> |
|||
<Name>Perspex.Controls</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Input\Perspex.Input.csproj"> |
|||
<Project>{62024b2d-53eb-4638-b26b-85eeaa54866e}</Project> |
|||
<Name>Perspex.Input</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Interactivity\Perspex.Interactivity.csproj"> |
|||
<Project>{6b0ed19d-a08b-461c-a9d9-a9ee40b0c06b}</Project> |
|||
<Name>Perspex.Interactivity</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Layout\Perspex.Layout.csproj"> |
|||
<Project>{42472427-4774-4c81-8aff-9f27b8e31721}</Project> |
|||
<Name>Perspex.Layout</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.SceneGraph\Perspex.SceneGraph.csproj"> |
|||
<Project>{eb582467-6abb-43a1-b052-e981ba910e3a}</Project> |
|||
<Name>Perspex.SceneGraph</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Styling\Perspex.Styling.csproj"> |
|||
<Project>{f1baa01a-f176-4c6a-b39d-5b40bb1b148f}</Project> |
|||
<Name>Perspex.Styling</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.Skia.Android\Perspex.Skia.Android.csproj"> |
|||
<Project>{bd43f7c0-396b-4aa1-bad9-dfde54d51298}</Project> |
|||
<Name>Perspex.Skia.Android</Name> |
|||
</ProjectReference> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<AndroidResource Include="Resources\drawable\Icon.png" /> |
|||
<AndroidResource Include="Resources\values\Strings.xml" /> |
|||
</ItemGroup> |
|||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
|||
@ -0,0 +1,5 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="Perspex.Skia.Android.TestApp" android:versionCode="1" android:versionName="1.0"> |
|||
<uses-sdk /> |
|||
<application android:label="Perspex.Skia.Android.TestApp" android:icon="@drawable/Icon"></application> |
|||
</manifest> |
|||
@ -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("Perspex.Skia.Android.TestApp")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("")] |
|||
[assembly: AssemblyProduct("Perspex.Skia.Android.TestApp")] |
|||
[assembly: AssemblyCopyright("Copyright © 2015")] |
|||
[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")] |
|||
@ -0,0 +1,112 @@ |
|||
#pragma warning disable 1591
|
|||
//------------------------------------------------------------------------------
|
|||
// <auto-generated>
|
|||
// This code was generated by a tool.
|
|||
// Runtime Version:4.0.30319.42000
|
|||
//
|
|||
// Changes to this file may cause incorrect behavior and will be lost if
|
|||
// the code is regenerated.
|
|||
// </auto-generated>
|
|||
//------------------------------------------------------------------------------
|
|||
|
|||
[assembly: global::Android.Runtime.ResourceDesignerAttribute("Perspex.Skia.Android.TestApp.Resource", IsApplication=true)] |
|||
|
|||
namespace Perspex.Skia.Android.TestApp |
|||
{ |
|||
|
|||
|
|||
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] |
|||
public partial class Resource |
|||
{ |
|||
|
|||
static Resource() |
|||
{ |
|||
global::Android.Runtime.ResourceIdManager.UpdateIdValues(); |
|||
} |
|||
|
|||
public static void UpdateIdValues() |
|||
{ |
|||
} |
|||
|
|||
public partial class Attribute |
|||
{ |
|||
|
|||
static Attribute() |
|||
{ |
|||
global::Android.Runtime.ResourceIdManager.UpdateIdValues(); |
|||
} |
|||
|
|||
private Attribute() |
|||
{ |
|||
} |
|||
} |
|||
|
|||
public partial class Drawable |
|||
{ |
|||
|
|||
// aapt resource value: 0x7f020000
|
|||
public const int Icon = 2130837504; |
|||
|
|||
static Drawable() |
|||
{ |
|||
global::Android.Runtime.ResourceIdManager.UpdateIdValues(); |
|||
} |
|||
|
|||
private Drawable() |
|||
{ |
|||
} |
|||
} |
|||
|
|||
public partial class Id |
|||
{ |
|||
|
|||
// aapt resource value: 0x7f050000
|
|||
public const int MyButton = 2131034112; |
|||
|
|||
static Id() |
|||
{ |
|||
global::Android.Runtime.ResourceIdManager.UpdateIdValues(); |
|||
} |
|||
|
|||
private Id() |
|||
{ |
|||
} |
|||
} |
|||
|
|||
public partial class Layout |
|||
{ |
|||
|
|||
// aapt resource value: 0x7f030000
|
|||
public const int Main = 2130903040; |
|||
|
|||
static Layout() |
|||
{ |
|||
global::Android.Runtime.ResourceIdManager.UpdateIdValues(); |
|||
} |
|||
|
|||
private Layout() |
|||
{ |
|||
} |
|||
} |
|||
|
|||
public partial class String |
|||
{ |
|||
|
|||
// aapt resource value: 0x7f040001
|
|||
public const int ApplicationName = 2130968577; |
|||
|
|||
// aapt resource value: 0x7f040000
|
|||
public const int Hello = 2130968576; |
|||
|
|||
static String() |
|||
{ |
|||
global::Android.Runtime.ResourceIdManager.UpdateIdValues(); |
|||
} |
|||
|
|||
private String() |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
} |
|||
#pragma warning restore 1591
|
|||
|
After Width: | Height: | Size: 4.0 KiB |
@ -0,0 +1,13 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|||
android:orientation="vertical" |
|||
android:layout_width="fill_parent" |
|||
android:layout_height="fill_parent" |
|||
> |
|||
<Button |
|||
android:id="@+id/MyButton" |
|||
android:layout_width="fill_parent" |
|||
android:layout_height="wrap_content" |
|||
android:text="@string/Hello" |
|||
/> |
|||
</LinearLayout> |
|||
@ -0,0 +1,5 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<resources> |
|||
<string name="Hello">Hello World, Click Me!</string> |
|||
<string name="ApplicationName">Perspex.Skia.Android.TestApp</string> |
|||
</resources> |
|||
@ -0,0 +1,29 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.InteropServices; |
|||
using System.Text; |
|||
|
|||
using Android.App; |
|||
using Android.Content; |
|||
using Android.Graphics; |
|||
using Android.OS; |
|||
using Android.Runtime; |
|||
using Android.Views; |
|||
using Android.Widget; |
|||
|
|||
namespace Perspex.Skia |
|||
{ |
|||
class MethodTableImpl : MethodTable |
|||
{ |
|||
[DllImport(@"perspesk")] |
|||
private static extern IntPtr GetPerspexMethodTable(); |
|||
[DllImport(@"perspesk")] |
|||
private static extern IntPtr PerspexJniInit(IntPtr jniEnv); |
|||
|
|||
public MethodTableImpl() : base(GetPerspexMethodTable()) |
|||
{ |
|||
PerspexJniInit(JNIEnv.Handle); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,106 @@ |
|||
<?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>{BD43F7C0-396B-4AA1-BAD9-DFDE54D51298}</ProjectGuid> |
|||
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
|||
<OutputType>Library</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>Perspex.Skia.Android</RootNamespace> |
|||
<AssemblyName>Perspex.Skia.Android</AssemblyName> |
|||
<FileAlignment>512</FileAlignment> |
|||
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile> |
|||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies> |
|||
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk> |
|||
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="Mono.Android" /> |
|||
<Reference Include="mscorlib" /> |
|||
<Reference Include="System" /> |
|||
<Reference Include="System.Core" /> |
|||
<Reference Include="System.Xml.Linq" /> |
|||
<Reference Include="System.Xml" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Folder Include="Properties\" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\Perspex.Animation\Perspex.Animation.csproj"> |
|||
<Project>{d211e587-d8bc-45b9-95a4-f297c8fa5200}</Project> |
|||
<Name>Perspex.Animation</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Base\Perspex.Base.csproj"> |
|||
<Project>{b09b78d8-9b26-48b0-9149-d64a2f120f3f}</Project> |
|||
<Name>Perspex.Base</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Controls\Perspex.Controls.csproj"> |
|||
<Project>{d2221c82-4a25-4583-9b43-d791e3f6820c}</Project> |
|||
<Name>Perspex.Controls</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Input\Perspex.Input.csproj"> |
|||
<Project>{62024b2d-53eb-4638-b26b-85eeaa54866e}</Project> |
|||
<Name>Perspex.Input</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Interactivity\Perspex.Interactivity.csproj"> |
|||
<Project>{6b0ed19d-a08b-461c-a9d9-a9ee40b0c06b}</Project> |
|||
<Name>Perspex.Interactivity</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Layout\Perspex.Layout.csproj"> |
|||
<Project>{42472427-4774-4c81-8aff-9f27b8e31721}</Project> |
|||
<Name>Perspex.Layout</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.SceneGraph\Perspex.SceneGraph.csproj"> |
|||
<Project>{eb582467-6abb-43a1-b052-e981ba910e3a}</Project> |
|||
<Name>Perspex.SceneGraph</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.Styling\Perspex.Styling.csproj"> |
|||
<Project>{f1baa01a-f176-4c6a-b39d-5b40bb1b148f}</Project> |
|||
<Name>Perspex.Styling</Name> |
|||
</ProjectReference> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Compile Include="MethodTable.cs" /> |
|||
<Compile Include="SkiaView.cs" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<EmbeddedNativeLibrary Include="..\native\Android\arm_v7\libperspesk.so"> |
|||
<Link>native\armeabi-v7a\libperspesk.so</Link> |
|||
</EmbeddedNativeLibrary> |
|||
<EmbeddedNativeLibrary Include="..\native\Android\x86\libperspesk.so"> |
|||
<Link>native\x86\libperspesk.so</Link> |
|||
</EmbeddedNativeLibrary> |
|||
</ItemGroup> |
|||
<Import Project="..\Perspex.Skia\Perspex.Skia.projitems" Label="Shared" /> |
|||
<Import Project="..\..\Shared\RenderHelpers\RenderHelpers.projitems" Label="Shared" /> |
|||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
|||
@ -0,0 +1,92 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
using Android.App; |
|||
using Android.Content; |
|||
using Android.Graphics; |
|||
using Android.OS; |
|||
using Android.Runtime; |
|||
using Android.Util; |
|||
using Android.Views; |
|||
using Android.Widget; |
|||
using Perspex.Media; |
|||
using Perspex.Platform; |
|||
|
|||
namespace Perspex.Skia.Android |
|||
{ |
|||
public abstract class SkiaView : SurfaceView, ISurfaceHolderCallback |
|||
{ |
|||
private readonly Activity _context; |
|||
bool _invalidateQueued; |
|||
object _lock = new object(); |
|||
public SkiaView(Activity context) : base(context) |
|||
{ |
|||
_context = context; |
|||
SkiaPlatform.Initialize(); |
|||
Holder.AddCallback(this); |
|||
} |
|||
private IRenderTarget _renderTarget; |
|||
|
|||
public override void Invalidate() |
|||
{ |
|||
lock (_lock) |
|||
{ |
|||
if(_invalidateQueued) |
|||
return; |
|||
_context.RunOnUiThread(() => |
|||
{ |
|||
lock (_lock) |
|||
{ |
|||
_invalidateQueued = false; |
|||
} |
|||
Draw(); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
public override void Invalidate(global::Android.Graphics.Rect dirty) |
|||
{ |
|||
Invalidate(); |
|||
} |
|||
|
|||
public override void Invalidate(int l, int t, int r, int b) |
|||
{ |
|||
Invalidate(); |
|||
} |
|||
|
|||
public void SurfaceChanged(ISurfaceHolder holder, Format format, int width, int height) |
|||
{ |
|||
Log.Info("PERSPEX", "Surface Changed"); |
|||
_renderTarget.Resize(width, height); |
|||
Draw(); |
|||
} |
|||
|
|||
public void SurfaceCreated(ISurfaceHolder holder) |
|||
{ |
|||
Log.Info("PERSPEX", "Surface Created"); |
|||
_renderTarget = |
|||
PerspexLocator.Current.GetService<IPlatformRenderInterface>() |
|||
.CreateRenderer(new PlatformHandle(holder.Surface.Handle, "Surface"), Width, Height); |
|||
Draw(); |
|||
} |
|||
|
|||
public void SurfaceDestroyed(ISurfaceHolder holder) |
|||
{ |
|||
Log.Info("PERSPEX", "Surface Destroyed"); |
|||
_renderTarget.Dispose(); |
|||
_renderTarget = null; |
|||
} |
|||
|
|||
void Draw() |
|||
{ |
|||
if(_renderTarget == null) |
|||
return; |
|||
using (var ctx = _renderTarget.CreateDrawingContext()) |
|||
OnRender(ctx); |
|||
} |
|||
|
|||
protected abstract void OnRender(DrawingContext ctx); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue