Skip to content
Draft
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
48 changes: 48 additions & 0 deletions Lottie.Android.net6/Additions/AboutAdditions.txt
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; }
}
31 changes: 31 additions & 0 deletions Lottie.Android.net6/Additions/LottieAnimationView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using Android.Graphics;

namespace Com.Airbnb.Lottie
{
public partial class LottieAnimationView
{
/// <summary>
/// Delegate to handle the loading of bitmaps that are not packaged in the assets of your app.
/// </summary>
public void SetImageAssetDelegate(Func<LottieImageAsset, Bitmap> funcAssetLoad)
{
this.SetImageAssetDelegate(new ImageAssetDelegateImpl(funcAssetLoad));
}

internal sealed class ImageAssetDelegateImpl : Java.Lang.Object, IImageAssetDelegate
{
private readonly Func<LottieImageAsset, Bitmap> funcAssetLoad;

public ImageAssetDelegateImpl(Func<LottieImageAsset, Bitmap> funcAssetLoad)
{
this.funcAssetLoad = funcAssetLoad;
}

public Bitmap FetchBitmap(LottieImageAsset asset)
{
return this.funcAssetLoad(asset);
}
}
}
}
160 changes: 160 additions & 0 deletions Lottie.Android.net6/Additions/LottieComposition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Android.Content;

namespace Com.Airbnb.Lottie
{
public partial class LottieComposition
{
public partial class Factory
{
/// <summary>
/// Asynchronously loads a composition from a file stored in /assets.
/// </summary>
public static ICancellable FromAssetFileName(Context context, string fileName, Action<LottieComposition> onLoaded)
{
return Factory.FromAssetFileName(context, fileName, new ActionCompositionLoaded(onLoaded));
}

/// <summary>
/// Asynchronously loads a composition from an arbitrary input stream.
/// </summary>
public static ICancellable FromInputStream(System.IO.Stream stream, Action<LottieComposition> onLoaded)
{
return Factory.FromInputStream(stream, new ActionCompositionLoaded(onLoaded));
}

/// <summary>
/// Asynchronously loads a composition from a json string. This is useful for animations loaded from the network.
/// </summary>
public static ICancellable FromJsonString(string jsonString, Action<LottieComposition> onLoaded)
{
return Factory.FromJsonString(jsonString, new ActionCompositionLoaded(onLoaded));
}

///// <summary>
///// Asynchronously loads a composition from a file stored in /assets.
///// </summary>
public static Task<LottieComposition> FromAssetFileNameAsync(Context context, string fileName)
{
return FromAssetFileNameAsync(context, fileName, CancellationToken.None);
}

/////// <summary>
/////// Asynchronously loads a composition from a file stored in /assets.
/////// </summary>
public static Task<LottieComposition> FromAssetFileNameAsync(Context context, string fileName, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
return Task.FromCanceled<LottieComposition>(cancellationToken);

var tcs = new TaskCompletionSource<LottieComposition>();
var cancelable = Factory.FromAssetFileName(context, fileName, (composition) =>
{
cancellationToken.ThrowIfCancellationRequested();
tcs.SetResult(composition);
});

cancellationToken.Register(() =>
{
if (!tcs.Task.IsCompleted)
{
cancelable.Cancel();
tcs.TrySetCanceled(cancellationToken);
}
});

return tcs.Task;
}

///// <summary>
///// Asynchronously loads a composition from an arbitrary input stream.
///// </summary>
public static Task<LottieComposition> FromInputStreamAsync(Context context, System.IO.Stream stream)
{
return FromInputStreamAsync(stream, CancellationToken.None);
}

///// <summary>
///// Asynchronously loads a composition from an arbitrary input stream.
///// </summary>
public static Task<LottieComposition> FromInputStreamAsync(System.IO.Stream stream, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
return Task.FromCanceled<LottieComposition>(cancellationToken);

var tcs = new TaskCompletionSource<LottieComposition>();
var cancelable = Factory.FromInputStream(stream, (composition) =>
{
cancellationToken.ThrowIfCancellationRequested();
tcs.SetResult(composition);
});

cancellationToken.Register(() =>
{
if (!tcs.Task.IsCompleted)
{
cancelable.Cancel();
tcs.TrySetCanceled(cancellationToken);
}
});

return tcs.Task;
}

///// <summary>
///// Asynchronously loads a composition from a raw json object. This is useful for animations loaded from the network.
///// </summary>
public static Task<LottieComposition> FromJsonStringAsync(string jsonString)
{
return FromJsonStringAsync(jsonString, CancellationToken.None);
}

///// <summary>
///// Asynchronously loads a composition from a raw json object. This is useful for animations loaded from the network.
///// </summary>
public static Task<LottieComposition> FromJsonStringAsync(string jsonString, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
return Task.FromCanceled<LottieComposition>(cancellationToken);

var tcs = new TaskCompletionSource<LottieComposition>();
var cancelable = Factory.FromJsonString(jsonString, (composition) =>
{
cancellationToken.ThrowIfCancellationRequested();
tcs.SetResult(composition);
});

cancellationToken.Register(() =>
{
if (!tcs.Task.IsCompleted)
{
cancelable.Cancel();
tcs.TrySetCanceled(cancellationToken);
}
});

return tcs.Task;
}

internal sealed class ActionCompositionLoaded : Java.Lang.Object, IOnCompositionLoadedListener
{
private readonly Action<LottieComposition> onLoaded;

public ActionCompositionLoaded(Action<LottieComposition> onLoaded)
{
this.onLoaded = onLoaded;
}

public void OnCompositionLoaded(LottieComposition compostion)
{
if (onLoaded != null)
{
onLoaded(compostion);
}
}
}
}
}
}
36 changes: 36 additions & 0 deletions Lottie.Android.net6/Jars/AboutJars.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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.

Binary file added Lottie.Android.net6/Jars/lottie-4.2.2.aar
Binary file not shown.
Binary file not shown.
32 changes: 32 additions & 0 deletions Lottie.Android.net6/Lottie.Android.net6.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0-android</TargetFrameworks>
<AssemblyName>Lottie.Android</AssemblyName>
<RootNamespace>Lottie.Android</RootNamespace>
<Description>Render After Effects animations natively on Android, iOS, MacOS, TVOs and UWP</Description>
<PackageId>Com.Airbnb.Android.Lottie</PackageId>
<IsBindingProject>true</IsBindingProject>
<EnableDefaultItems>false</EnableDefaultItems>
<Version>6.0.4</Version>

<AndroidCodegenTarget>XAJavaInterop1</AndroidCodegenTarget>
<_EnableInterfaceMembers>true</_EnableInterfaceMembers>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidDexTool>d8</AndroidDexTool>
<AndroidLinkTool>r8</AndroidLinkTool>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Square.OkIO" Version="1.17.4" />
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.3.1.3" />
<PackageReference Include="Xamarin.Build.Download" Version="0.10.0" PrivateAssets="All" />
<!-- None Include="Additions\*;Jars\*;Transforms\*" /-->
<LibraryProjectZip Include="Jars\*.aar" />
<!--<JavaSourceJar Include="JavaDocs\*.jar" />-->
<TransformFile Include="Transforms\*.xml" />
<Compile Include="Additions\*.cs" />
<None Include="readme.txt" pack="true" PackagePath="." />
<None Include="**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions Lottie.Android.net6/Lottie.Android.net6.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 25.0.1700.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lottie.Android", "Lottie.Android.net6.csproj", "{C3DB3049-F830-4FB1-844F-3379005C7C78}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C3DB3049-F830-4FB1-844F-3379005C7C78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3DB3049-F830-4FB1-844F-3379005C7C78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3DB3049-F830-4FB1-844F-3379005C7C78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3DB3049-F830-4FB1-844F-3379005C7C78}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BA8370AE-4B2B-429F-9ADA-65BF99FFB691}
EndGlobalSection
EndGlobal
19 changes: 19 additions & 0 deletions Lottie.Android.net6/Transforms/EnumFields.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
19 changes: 19 additions & 0 deletions Lottie.Android.net6/Transforms/EnumMethods.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
Loading