-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8d1272
commit 3b1c583
Showing
12 changed files
with
270 additions
and
6 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,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Project> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0-android</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
</Project> |
48 changes: 48 additions & 0 deletions
48
AndroidBindableLibraries/MaterialCalendarView/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; } | ||
} |
50 changes: 50 additions & 0 deletions
50
AndroidBindableLibraries/MaterialCalendarView/MaterialCalendarView.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,50 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<SupportedOSPlatformVersion>23</SupportedOSPlatformVersion> | ||
<PackageId>VladislavAntonyuk.$(AssemblyName)</PackageId> | ||
<Version>1.9.0</Version> | ||
<PackageReadmeFile>ReadMe.md</PackageReadmeFile> | ||
<PackageOutputPath>..\..\LocalPackages\</PackageOutputPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="XamPrototype.Android.MavenBinding.Tasks" Version="0.0.11" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<!-- Include format is {GroupId}:{ArtifactId} --> | ||
<AndroidMavenLibrary Include="org.jetbrains.kotlin:kotlin-android-extensions-runtime" Version="1.6.10" Bind="false" /> | ||
<AndroidMavenLibrary Include="com.annimon:stream" Version="1.2.2" Bind="false" /> | ||
<AndroidMavenLibrary Include="com.applandeo:material-calendar-view" Version="1.9.0" /> | ||
<PackageReference Include="Xamarin.AndroidX.AppCompat"> | ||
<Version>1.6.1.6</Version> | ||
</PackageReference> | ||
<PackageReference Include="Xamarin.AndroidX.ConstraintLayout"> | ||
<Version>2.1.4.9</Version> | ||
</PackageReference> | ||
<PackageReference Include="Xamarin.AndroidX.Core.Core.Ktx"> | ||
<Version>1.12.0.3</Version> | ||
</PackageReference> | ||
<PackageReference Include="Xamarin.Kotlin.StdLib"> | ||
<Version>1.9.21.1</Version> | ||
</PackageReference> | ||
<PackageReference Include="Xamarin.Kotlin.StdLib.Jdk8"> | ||
<Version>1.9.21.1</Version> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Xamarin.AndroidX.Collection" Version="1.3.0.2" /> | ||
<PackageReference Include="Xamarin.AndroidX.Collection.Jvm" Version="1.3.0.2" /> | ||
<PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.3.0.2" /> | ||
|
||
<PackageReference Include="Xamarin.AndroidX.Fragment.Ktx "> | ||
<Version>1.6.2.1</Version> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Update="ReadMe.md"> | ||
<Pack>True</Pack> | ||
<PackagePath>\</PackagePath> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
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,3 @@ | ||
# Android Material Calendar View | ||
|
||
Android Java Library Binding for [Material Calendar View](https://github.com/Applandeo/Material-Calendar-View) |
14 changes: 14 additions & 0 deletions
14
AndroidBindableLibraries/MaterialCalendarView/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,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. | ||
<mapping jni-class="android/support/v4/app/FragmentActivity$FragmentTag" clr-enum-type="Android.Support.V4.App.FragmentTagType"> | ||
<field jni-name="Fragment_name" clr-name="Name" value="0" /> | ||
<field jni-name="Fragment_id" clr-name="Id" value="1" /> | ||
<field jni-name="Fragment_tag" clr-name="Tag" value="2" /> | ||
</mapping> | ||
--> | ||
</enum-field-mappings> |
13 changes: 13 additions & 0 deletions
13
AndroidBindableLibraries/MaterialCalendarView/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,13 @@ | ||
<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> | ||
--> | ||
</enum-method-mappings> |
9 changes: 9 additions & 0 deletions
9
AndroidBindableLibraries/MaterialCalendarView/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> |
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
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
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,99 @@ | ||
namespace MauiBells.Calendar; | ||
|
||
using System.ComponentModel; | ||
using Android; | ||
using Com.Applandeo.Materialcalendarview; | ||
using Com.Applandeo.Materialcalendarview.Listeners; | ||
using Java.Lang; | ||
using Microsoft.Maui.Handlers; | ||
using Calendar = Com.Applandeo.Materialcalendarview.CalendarView; | ||
|
||
public class CalendarMaterialHandler(IPropertyMapper mapper, CommandMapper? commandMapper = null) : ViewHandler<ICalendarView, Calendar>(mapper, commandMapper) | ||
{ | ||
public static IPropertyMapper<ICalendarView, CalendarMaterialHandler> PropertyMapper = new PropertyMapper<ICalendarView, CalendarMaterialHandler>(ViewMapper) | ||
{ | ||
[nameof(ICalendarView.FirstDayOfWeek)] = MapFirstDayOfWeek, | ||
[nameof(ICalendarView.MinDate)] = MapMinDate, | ||
[nameof(ICalendarView.MaxDate)] = MapMaxDate, | ||
[nameof(ICalendarView.SelectedDate)] = MapSelectedDate, | ||
}; | ||
|
||
public static CommandMapper<ICalendarView, CalendarMaterialHandler> CommandMapper = new(ViewCommandMapper); | ||
|
||
public CalendarMaterialHandler() : this(PropertyMapper, CommandMapper) | ||
{ | ||
} | ||
|
||
protected override Calendar CreatePlatformView() | ||
{ | ||
return new Calendar(Context); | ||
} | ||
|
||
protected override void ConnectHandler(Calendar platformView) | ||
{ | ||
base.ConnectHandler(platformView); | ||
platformView.CalendarDayClick += PlatformView_SelectedDatesChanged; | ||
} | ||
|
||
private void PlatformView_SelectedDatesChanged(object? sender, CalendarDayClickEventArgs e) | ||
{ | ||
var calendar = e.CalendarDay.Calendar; | ||
var time = TimeSpan.FromMilliseconds(calendar.TimeInMillis); | ||
var result = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); | ||
VirtualView.SelectedDate = new DateTimeOffset(result.Add(time).Add(TimeSpan.FromMilliseconds(calendar.TimeZone.RawOffset))); | ||
VirtualView.OnSelectedDateChanged(VirtualView.SelectedDate); | ||
} | ||
|
||
protected override void DisconnectHandler(Calendar platformView) | ||
{ | ||
platformView.CalendarDayClick -= PlatformView_SelectedDatesChanged; | ||
base.DisconnectHandler(platformView); | ||
} | ||
|
||
private static void MapFirstDayOfWeek(CalendarMaterialHandler handler, ICalendarView virtualView) | ||
{ | ||
var calendarWeekDate = virtualView.FirstDayOfWeek switch | ||
{ | ||
DayOfWeek.Sunday => CalendarWeekDay.Sunday, | ||
DayOfWeek.Monday => CalendarWeekDay.Monday, | ||
DayOfWeek.Tuesday => CalendarWeekDay.Tuesday, | ||
DayOfWeek.Wednesday => CalendarWeekDay.Wednesday, | ||
DayOfWeek.Thursday => CalendarWeekDay.Thursday, | ||
DayOfWeek.Friday => CalendarWeekDay.Friday, | ||
DayOfWeek.Saturday => CalendarWeekDay.Saturday, | ||
_ => throw new InvalidEnumArgumentException(), | ||
}; | ||
ArgumentNullException.ThrowIfNull(calendarWeekDate); | ||
handler.PlatformView.SetFirstDayOfWeek(calendarWeekDate); | ||
} | ||
|
||
private static void MapMinDate(CalendarMaterialHandler handler, ICalendarView virtualView) | ||
{ | ||
var calendar = Java.Util.Calendar.Instance; | ||
calendar.Set(virtualView.MinDate.Year, virtualView.MinDate.Month - 1, virtualView.MinDate.Day); | ||
handler.PlatformView.SetMinimumDate(calendar); | ||
} | ||
|
||
private static void MapMaxDate(CalendarMaterialHandler handler, ICalendarView virtualView) | ||
{ | ||
var calendar = Java.Util.Calendar.Instance; | ||
calendar.Set(virtualView.MaxDate.Year, virtualView.MaxDate.Month - 1, virtualView.MaxDate.Day); | ||
handler.PlatformView.SetMaximumDate(calendar); | ||
} | ||
|
||
private static void MapSelectedDate(CalendarMaterialHandler handler, ICalendarView virtualView) | ||
{ | ||
if (virtualView.SelectedDate is null) | ||
{ | ||
return; | ||
} | ||
|
||
var calendar = Java.Util.Calendar.Instance; | ||
calendar.Set(virtualView.SelectedDate.Value.Year, virtualView.SelectedDate.Value.Month - 1, virtualView.SelectedDate.Value.Day); | ||
List<CalendarDay> events = new(); | ||
var day = new CalendarDay(calendar); | ||
day.BackgroundResource = Integer.ValueOf(Resource.Color.HoloRedDark); | ||
events.Add(day); | ||
handler.PlatformView.SetCalendarDays(events); | ||
} | ||
} |
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
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