Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
[DropboxSync] Added Android binding support
Browse files Browse the repository at this point in the history
  • Loading branch information
dalexsoto committed Jul 13, 2013
1 parent c7d6ccd commit 8573dc3
Show file tree
Hide file tree
Showing 21 changed files with 319 additions and 17 deletions.
59 changes: 45 additions & 14 deletions Rakefile
Expand Up @@ -2,13 +2,24 @@ require "rake/clean"

CLEAN.include "*.xam"
CLEAN.include "xpkg"
CLEAN.include "source/binding/*.a"
CLEAN.include "source/binding/*.zip"
CLEAN.include "source/binding/*.dll"
CLEAN.include "source/binding/bin"
CLEAN.include "source/binding/obj"
CLEAN.include "source/samples/DropBoxSyncSampleMTD/bin"
CLEAN.include "source/samples/DropBoxSyncSampleMTD/obj"
CLEAN.include "source/binding/iOS/*.a"
CLEAN.include "source/binding/iOS/*.zip"
CLEAN.include "source/binding/iOS/*.dll"
CLEAN.include "source/binding/iOS/bin"
CLEAN.include "source/binding/iOS/obj"
CLEAN.include "source/samples/DropBoxSyncSampleMTD/DropBoxSyncSampleMTD/bin"
CLEAN.include "source/samples/DropBoxSyncSampleMTD/DropBoxSyncSampleMTD/obj"
CLEAN.include "source/samples/MonkeyBox/MonkeyBox/bin"
CLEAN.include "source/samples/MonkeyBox/MonkeyBox/obj"
CLEAN.include "source/binding/Android/*.zip"
CLEAN.include "source/binding/Android/*.dll"
CLEAN.include "source/binding/Android/Jars/*.jar"
CLEAN.include "source/binding/Android/bin"
CLEAN.include "source/binding/Android/obj"
CLEAN.include "source/binding/Android/Jars/armeabi"
CLEAN.include "source/binding/Android/Jars/armeabi-v7a"
CLEAN.include "source/binding/Android/Jars/mips"
CLEAN.include "source/binding/Android/Jars/x86"

COMPONENT = "dropboxsync-1.9.xam"
MONOXBUILD = "/Library/Frameworks/Mono.framework/Commands/xbuild"
Expand All @@ -21,14 +32,29 @@ file "xpkg/xamarin-component.exe" do
sh "rm xpkg.zip"
end

file "source/binding/DropBoxSync.iOS.dll" do
sh "curl -L 'http://dl.dropboxusercontent.com/s/qvmbr43p94iszak/dropbox-ios-sync-sdk-2.0-b1.zip' > source/binding/dropbox-ios-sync-sdk-2.0-b1.zip"
sh "unzip -p source/binding/dropbox-ios-sync-sdk-2.0-b1.zip 'dropbox-ios-sync-sdk-2.0-b1/Dropbox.framework/Dropbox' > source/binding/Dropbox.a"
sh "#{MONOXBUILD} /p:Configuration=Release source/binding/DropBoxSync.iOS.csproj"
sh "cp source/binding/bin/Release/DropBoxSync.iOS.dll source/binding/DropBoxSync.iOS.dll"
file "source/binding/iOS/DropBoxSync.iOS.dll" do
sh "curl -L 'http://dl.dropboxusercontent.com/s/qvmbr43p94iszak/dropbox-ios-sync-sdk-2.0-b1.zip' > source/binding/iOS/dropbox-ios-sync-sdk-2.0-b1.zip"
sh "unzip -p source/binding/iOS/dropbox-ios-sync-sdk-2.0-b1.zip 'dropbox-ios-sync-sdk-2.0-b1/Dropbox.framework/Dropbox' > source/binding/iOS/Dropbox.a"
sh "#{MONOXBUILD} /p:Configuration=Release source/binding/iOS/DropBoxSync.iOS.csproj"
sh "cp source/binding/iOS/bin/Release/DropBoxSync.iOS.dll source/binding/iOS/DropBoxSync.iOS.dll"
end

task :default => ["xpkg/xamarin-component.exe", "source/binding/DropBoxSync.iOS.dll"] do
file "source/binding/Android/DropboxSync.Android.dll" do
sh "curl -L 'http://dl.dropboxusercontent.com/s/lkyp4mj0vhjay05/dropbox-android-sync-sdk-2.0.0-b2.zip' > source/binding/Android/dropbox-android-sync-sdk-2.0.0-b2.zip"
sh "mkdir -p source/binding/Android/Jars/armeabi/"
sh "mkdir -p source/binding/Android/Jars/armeabi-v7a/"
sh "mkdir -p source/binding/Android/Jars/mips/"
sh "mkdir -p source/binding/Android/Jars/x86/"
sh "unzip -p source/binding/Android/dropbox-android-sync-sdk-2.0.0-b2.zip 'dropbox-android-sync-sdk-2.0.0-b2/libs/armeabi/libDropboxSync.so' > source/binding/Android/Jars/armeabi/libDropboxSync.so"
sh "unzip -p source/binding/Android/dropbox-android-sync-sdk-2.0.0-b2.zip 'dropbox-android-sync-sdk-2.0.0-b2/libs/armeabi/libDropboxSync.so' > source/binding/Android/Jars/armeabi-v7a/libDropboxSync.so"
sh "unzip -p source/binding/Android/dropbox-android-sync-sdk-2.0.0-b2.zip 'dropbox-android-sync-sdk-2.0.0-b2/libs/mips/libDropboxSync.so' > source/binding/Android/Jars/mips/libDropboxSync.so"
sh "unzip -p source/binding/Android/dropbox-android-sync-sdk-2.0.0-b2.zip 'dropbox-android-sync-sdk-2.0.0-b2/libs/x86/libDropboxSync.so' > source/binding/Android/Jars/x86/libDropboxSync.so"
sh "unzip -p source/binding/Android/dropbox-android-sync-sdk-2.0.0-b2.zip 'dropbox-android-sync-sdk-2.0.0-b2/libs/dropbox-sync-sdk-android.jar' > source/binding/Android/Jars/dropbox-sync-sdk-android.jar"
sh "#{MONOXBUILD} /p:Configuration=Release source/binding/Android/DropboxSync.Android.csproj"
sh "cp source/binding/Android/bin/Release/DropboxSync.Android.dll source/binding/Android/DropboxSync.Android.dll"
end

task :default => ["xpkg/xamarin-component.exe", "source/binding/iOS/DropBoxSync.iOS.dll", "source/binding/Android/DropboxSync.Android.dll"] do
line = <<-END
mono xpkg/xamarin-component.exe package
END
Expand All @@ -38,7 +64,12 @@ task :default => ["xpkg/xamarin-component.exe", "source/binding/DropBoxSync.iOS.
puts "* Created #{COMPONENT}"
end

task :prepare => "source/binding/DropBoxSync.iOS.dll" do
task :prepareios => "source/binding/iOS/DropBoxSync.iOS.dll" do
puts "\n\n"
puts "Binding project prepared, now you can open DropBoxSync.iOS.csproj and samples in Xamarin Studio"
end

task :preparedroid => "source/binding/Android/DropboxSync.Android.dll" do
puts "\n\n"
puts "Binding Android project prepared, now you can open DropboxSync.Android.csproj in Xamarin Studio"
end
3 changes: 2 additions & 1 deletion component.yaml
Expand Up @@ -5,7 +5,8 @@ publisher: Dropbox, Inc.
publisher-url: https://www.dropbox.com/developers/sync
summary: Give your app its own private Dropbox client and leave the syncing to Dropbox.
libraries:
ios: source/binding/DropBoxSync.iOS.dll
ios: source/binding/iOS/DropBoxSync.iOS.dll
android: source/binding/Android/DropboxSync.Android.dll
samples:
"iOS Sample. Demonstrates Dropbox Awesomeness on iOS.": "source/samples/DropBoxSyncSampleMTD/DropBoxSyncSampleMTD.sln"
"iOS MonkeyBox. Demonstrates Dropbox Datastore Awesomeness on iOS.": "source/samples/MonkeyBox/MonkeyBox.sln"
Expand Down
48 changes: 48 additions & 0 deletions source/binding/Android/Additions/AboutAdditions.txt
@@ -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; }
}
19 changes: 19 additions & 0 deletions source/binding/Android/Additions/Com.Dropbox.Sync.Android.cs
@@ -0,0 +1,19 @@
using System;
namespace DropboxSync.Android
{
public sealed partial class DBPath
{
public int CompareTo (Java.Lang.Object target)
{
return this.CompareTo ((DBPath) target);
}
}
public sealed partial class DBFileInfo
{
public int CompareTo (Java.Lang.Object target)
{
return this.CompareTo ((DBPath) target);
}
}
}

69 changes: 69 additions & 0 deletions source/binding/Android/DropboxSync.Android.csproj
@@ -0,0 +1,69 @@
<?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>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{40125294-A03F-4D7D-A863-7A55C646D1B2}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{10368E6C-D01B-4462-8E8B-01FC667A7035};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>DropboxSync.Android</RootNamespace>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<AssemblyName>DropboxSync.Android</AssemblyName>
</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>
<ConsolePause>false</ConsolePause>
<AndroidLinkMode>None</AndroidLinkMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Mono.Android" />
<Reference Include="Mono.Android.Support.v4" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Additions\Com.Dropbox.Sync.Android.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)\Novell\Xamarin.Android.Bindings.targets" />
<ItemGroup>
<EmbeddedJar Include="Jars\dropbox-sync-sdk-android.jar" />
</ItemGroup>
<ItemGroup>
<EmbeddedNativeLibrary Include="Jars\armeabi\libDropboxSync.so" />
<EmbeddedNativeLibrary Include="Jars\mips\libDropboxSync.so" />
<EmbeddedNativeLibrary Include="Jars\x86\libDropboxSync.so" />
<EmbeddedNativeLibrary Include="Jars\armeabi-v7a\libDropboxSync.so" />
</ItemGroup>
<ItemGroup>
<Folder Include="Jars\armeabi-v7a\" />
</ItemGroup>
</Project>
37 changes: 37 additions & 0 deletions source/binding/Android/Jars/AboutJars.txt
@@ -0,0 +1,37 @@
This directory is for Android .jars.

There are 3 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.


28 changes: 28 additions & 0 deletions source/binding/Android/Properties/AssemblyInfo.cs
@@ -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("DropboxSync.Android")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Xamarin")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Alex Soto")]
[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("")]

14 changes: 14 additions & 0 deletions source/binding/Android/Transforms/EnumFields.xml
@@ -0,0 +1,14 @@
<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.
<type enum-type="Android\Support\V4\App\FragmentTagType" java-class="android/support/v4/app/FragmentActivity$FragmentTag">
<member enum="Id" java="Fragment_id" value="1" />
<member enum="Name" java="Fragment_name" value="0" />
<member enum="Tag" java="Fragment_tag" value="2" />
</type>
-->
</enum-field-mappings>
11 changes: 11 additions & 0 deletions source/binding/Android/Transforms/EnumMethods.xml
@@ -0,0 +1,11 @@
<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#.
<map package="android.support.v4.app" class="Fragment.SavedState" method="writeToParcel" parameter="flags" enum="Android.OS.ParcelableWriteFlags" />
-->
</enum-method-mappings>
44 changes: 44 additions & 0 deletions source/binding/Android/Transforms/Metadata.xml
@@ -0,0 +1,44 @@
<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']" />
-->

<!-- Visibility Change -->
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='CoreClient']" name="visibility">public</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxAtom']" name="visibility">public</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxValue']" name="visibility">public</attr>

<!-- Namespace Normalization -->
<attr path="/api/package[@name='com.dropbox.client2.android']" name="managedName">DropboxSync.Android.Client2</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']" name="managedName">DropboxSync.Android</attr>

<!-- Class Normalization -->
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxAccount']" name="managedName">DBAccount</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxAccountInfo']" name="managedName">DBAccountInfo</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxAccountManager']" name="managedName">DBAccountManager</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxAtom']" name="managedName">DBAtom</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxAuthActivity']" name="managedName">DBAuthActivity</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxDatastore']" name="managedName">DBDatastore</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxDatastoreManager']" name="managedName">DBDatastoreManager</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxDatastoreStatus']" name="managedName">DBDatastoreStatus</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxException']" name="managedName">DBException</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxFields']" name="managedName">DBFields</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxFile']" name="managedName">DBFile</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxFileInfo']" name="managedName">DBFileInfo</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxFileStatus']" name="managedName">DBFileStatus</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxFileSystem']" name="managedName">DBFileSystem</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxList']" name="managedName">DBList</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxPath']" name="managedName">DBPath</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxRecord']" name="managedName">DBRecord</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxSyncService']" name="managedName">DBSyncService</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxSyncStatus']" name="managedName">DBSyncStatus</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxTable']" name="managedName">DBTable</attr>
<attr path="/api/package[@name='com.dropbox.sync.android']/class[@name='DbxValue']" name="managedName">DBValue</attr>

<!-- Interface Normalization -->
<attr path="/api/package[@name='com.dropbox.sync.android']/interface[@name='DbxFileSystem.PathListener']" name="managedName">DBFileSystem.IPathListener</attr>
</metadata>
Binary file removed source/binding/DropBoxSync.iOS.dll
Binary file not shown.
Binary file removed source/binding/Dropbox.a
Binary file not shown.
Binary file removed source/binding/dropbox-ios-sync-sdk-2.0-b1.zip
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -82,7 +82,7 @@
<Reference Include="monotouch" />
<Reference Include="MonoTouch.Dialog-1" />
<Reference Include="DropBoxSync.iOS">
<HintPath>..\..\..\binding\DropBoxSync.iOS.dll</HintPath>
<HintPath>..\..\..\binding\iOS\DropBoxSync.iOS.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion source/samples/MonkeyBox/MonkeyBox/MonkeyBox.csproj
Expand Up @@ -85,7 +85,7 @@
<Reference Include="System.Core" />
<Reference Include="monotouch" />
<Reference Include="DropBoxSync.iOS">
<HintPath>..\..\..\binding\DropBoxSync.iOS.dll</HintPath>
<HintPath>..\..\..\binding\iOS\DropBoxSync.iOS.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 8573dc3

Please sign in to comment.