-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android: add barebones binding solution
Adding a barebones android binding solution that should be used in conjunction with OneSignal-Android-SDK to enable Xamarin.Android support.
- Loading branch information
Vivek Ayer
committed
Feb 11, 2016
1 parent
88a2d40
commit 3196ca4
Showing
9 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2012 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneSignal.Android.Binding", "OneSignal.Android.Binding\OneSignal.Android.Binding.csproj", "{9144F592-91B9-4ACA-BC3C-D771F8319996}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{9144F592-91B9-4ACA-BC3C-D771F8319996}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{9144F592-91B9-4ACA-BC3C-D771F8319996}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{9144F592-91B9-4ACA-BC3C-D771F8319996}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{9144F592-91B9-4ACA-BC3C-D771F8319996}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
16 changes: 16 additions & 0 deletions
16
OneSignal.Android.Binding/OneSignal.Android.Binding.userprefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Properties StartupItem="OneSignal.Android.Binding/OneSignal.Android.Binding.csproj"> | ||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="Android.Xamarin_Android_API_15" /> | ||
<MonoDevelop.Ide.Workbench> | ||
<Pads> | ||
<Pad Id="ProjectPad"> | ||
<State name="__root__"> | ||
<Node name="OneSignal.Android.Binding" expanded="True" /> | ||
</State> | ||
</Pad> | ||
</Pads> | ||
</MonoDevelop.Ide.Workbench> | ||
<MonoDevelop.Ide.DebuggingService.Breakpoints> | ||
<BreakpointStore /> | ||
</MonoDevelop.Ide.DebuggingService.Breakpoints> | ||
<MonoDevelop.Ide.DebuggingService.PinnedWatches /> | ||
</Properties> |
48 changes: 48 additions & 0 deletions
48
OneSignal.Android.Binding/OneSignal.Android.Binding/Additions/AboutAdditions.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
Additions allow you to add arbitrary C# to the generated classes | ||
before they are compiled. This can be helpful for providing convenience | ||
methods or adding pure C# classes. | ||
|
||
== Adding Methods to Generated Classes == | ||
|
||
Let's say the library being bound has a Rectangle class with a constructor | ||
that takes an x and y position, and a width and length size. It will look like | ||
this: | ||
|
||
public partial class Rectangle | ||
{ | ||
public Rectangle (int x, int y, int width, int height) | ||
{ | ||
// JNI bindings | ||
} | ||
} | ||
|
||
Imagine we want to add a constructor to this class that takes a Point and | ||
Size structure instead of 4 ints. We can add a new file called Rectangle.cs | ||
with a partial class containing our new method: | ||
|
||
public partial class Rectangle | ||
{ | ||
public Rectangle (Point location, Size size) : | ||
this (location.X, location.Y, size.Width, size.Height) | ||
{ | ||
} | ||
} | ||
|
||
At compile time, the additions class will be added to the generated class | ||
and the final assembly will a Rectangle class with both constructors. | ||
|
||
|
||
== Adding C# Classes == | ||
|
||
Another thing that can be done is adding fully C# managed classes to the | ||
generated library. In the above example, let's assume that there isn't a | ||
Point class available in Java or our library. The one we create doesn't need | ||
to interact with Java, so we'll create it like a normal class in C#. | ||
|
||
By adding a Point.cs file with this class, it will end up in the binding library: | ||
|
||
public class Point | ||
{ | ||
public int X { get; set; } | ||
public int Y { get; set; } | ||
} |
37 changes: 37 additions & 0 deletions
37
OneSignal.Android.Binding/OneSignal.Android.Binding/Jars/AboutJars.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
This directory is for Android .jars. | ||
|
||
There are 4 types of jars that are supported: | ||
|
||
== Input Jar and Embedded Jar == | ||
|
||
This is the jar that bindings should be generated for. | ||
|
||
For example, if you were binding the Google Maps library, this would | ||
be Google's "maps.jar". | ||
|
||
The difference between EmbeddedJar and InputJar is, EmbeddedJar is to be | ||
embedded in the resulting dll as EmbeddedResource, while InputJar is not. | ||
There are couple of reasons you wouldn't like to embed the target jar | ||
in your dll (the ones that could be internally loaded by <uses-library> | ||
feature e.g. maps.jar, or you cannot embed jars that are under some | ||
proprietary license). | ||
|
||
Set the build action for these jars in the properties page to "InputJar". | ||
|
||
|
||
== Reference Jar and Embedded Reference Jar == | ||
|
||
These are jars that are referenced by the input jar. C# bindings will | ||
not be created for these jars. These jars will be used to resolve | ||
types used by the input jar. | ||
|
||
NOTE: Do not add "android.jar" as a reference jar. It will be added automatically | ||
based on the Target Framework selected. | ||
|
||
Set the build action for these jars in the properties page to "ReferenceJar". | ||
|
||
"EmbeddedJar" works like "ReferenceJar", but like "EmbeddedJar", it is | ||
embedded in your dll. But at application build time, they are not included | ||
in the final apk, like ReferenceJar files. | ||
|
||
|
55 changes: 55 additions & 0 deletions
55
OneSignal.Android.Binding/OneSignal.Android.Binding/OneSignal.Android.Binding.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?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};{10368E6C-D01B-4462-8E8B-01FC667A7035};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<ProjectGuid>{9144F592-91B9-4ACA-BC3C-D771F8319996}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<RootNamespace>OneSignal.Android.Binding</RootNamespace> | ||
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix> | ||
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix> | ||
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk> | ||
<AssemblyName>OneSignal.Android.Binding</AssemblyName> | ||
<TargetFrameworkVersion>v6.0</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> | ||
</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> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="Mono.Android" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Additions\AboutAdditions.txt" /> | ||
<None Include="Jars\AboutJars.txt" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<TransformFile Include="Transforms\EnumFields.xml" /> | ||
<TransformFile Include="Transforms\EnumMethods.xml" /> | ||
<TransformFile Include="Transforms\Metadata.xml" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.Bindings.targets" /> | ||
</Project> |
28 changes: 28 additions & 0 deletions
28
OneSignal.Android.Binding/OneSignal.Android.Binding/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using Android.App; | ||
|
||
// Information about this assembly is defined by the following attributes. | ||
// Change them to the values specific to your project. | ||
|
||
[assembly: AssemblyTitle ("OneSignal.Android.Binding")] | ||
[assembly: AssemblyDescription ("")] | ||
[assembly: AssemblyConfiguration ("")] | ||
[assembly: AssemblyCompany ("")] | ||
[assembly: AssemblyProduct ("")] | ||
[assembly: AssemblyCopyright ("vivek")] | ||
[assembly: AssemblyTrademark ("")] | ||
[assembly: AssemblyCulture ("")] | ||
|
||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". | ||
// The form "{Major}.{Minor}.*" will automatically update the build and revision, | ||
// and "{Major}.{Minor}.{Build}.*" will update just the revision. | ||
|
||
[assembly: AssemblyVersion ("1.0.0")] | ||
|
||
// The following attributes are used to specify the signing key for the assembly, | ||
// if desired. See the Mono documentation for more information about signing. | ||
|
||
//[assembly: AssemblyDelaySign(false)] | ||
//[assembly: AssemblyKeyFile("")] | ||
|
18 changes: 18 additions & 0 deletions
18
OneSignal.Android.Binding/OneSignal.Android.Binding/Transforms/EnumFields.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<enum-field-mappings> | ||
<!-- | ||
This example converts the constants Fragment_id, Fragment_name, | ||
and Fragment_tag from android.support.v4.app.FragmentActivity.FragmentTag | ||
to an enum called Android.Support.V4.App.FragmentTagType with values | ||
Id, Name, and Tag. | ||
<mapping clr-enum-type="Android.Support.V4.App.FragmentTagType" jni-class="android/support/v4/app/FragmentActivity$FragmentTag"> | ||
<field clr-name="Id" jni-name="Fragment_id" value="1" /> | ||
<field clr-name="Name" jni-name="Fragment_name" value="0" /> | ||
<field clr-name="Tag" jni-name="Fragment_tag" value="2" /> | ||
</type> | ||
Notes: | ||
- An optional "bitfield" attribute marks the enum type with [Flags]. | ||
- For Java interfaces, use "jni-interface" attribute instead of "jni-class" attribute. | ||
--> | ||
</enum-field-mappings> |
18 changes: 18 additions & 0 deletions
18
OneSignal.Android.Binding/OneSignal.Android.Binding/Transforms/EnumMethods.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<enum-method-mappings> | ||
<!-- | ||
This example changes the Java method: | ||
android.support.v4.app.Fragment.SavedState.writeToParcel (int flags) | ||
to be: | ||
android.support.v4.app.Fragment.SavedState.writeToParcel (Android.OS.ParcelableWriteFlags flags) | ||
when bound in C#. | ||
<mapping jni-class="android/support/v4/app/Fragment.SavedState"> | ||
<method jni-name="writeToParcel" parameter="flags" clr-enum-type="Android.OS.ParcelableWriteFlags" /> | ||
</mapping> | ||
Notes: | ||
- For Java interfaces, use "jni-interface" attribute instead of "jni-class" attribute. | ||
- To change the type of the return value, use "return" as the parameter name. | ||
- The parameter names will be p0, p1, ... unless you provide JavaDoc file in the project. | ||
--> | ||
</enum-method-mappings> |
9 changes: 9 additions & 0 deletions
9
OneSignal.Android.Binding/OneSignal.Android.Binding/Transforms/Metadata.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<metadata> | ||
<!-- | ||
This sample removes the class: android.support.v4.content.AsyncTaskLoader.LoadTask: | ||
<remove-node path="/api/package[@name='android.support.v4.content']/class[@name='AsyncTaskLoader.LoadTask']" /> | ||
This sample removes the method: android.support.v4.content.CursorLoader.loadInBackground: | ||
<remove-node path="/api/package[@name='android.support.v4.content']/class[@name='CursorLoader']/method[@name='loadInBackground']" /> | ||
--> | ||
</metadata> |