Skip to content

Instantly share code, notes, and snippets.

View FreakyAli's full-sized avatar
💭
I may be slow to respond.

Gulam Ali H. FreakyAli

💭
I may be slow to respond.
View GitHub Profile
@FreakyAli
FreakyAli / FreakySignatureCanvasView.cs
Created November 11, 2023 03:15
FreakySignatureCanvasView is a custom Maui shared view
public class FreakySignatureCanvasView : View
{
#region Events
public event EventHandler StrokeCompleted;
public event EventHandler Cleared;
public event EventHandler<ImageStreamRequestedEventArgs> ImageStreamRequested;
@FreakyAli
FreakyAli / MainPage.xaml
Last active November 9, 2023 03:29
Compiled binding example
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="Samples.MainPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:samples="clr-namespace:Samples"
x:DataType="samples:MainViewModel">
<ListView
CachingStrategy="RecycleElementAndDataTemplate"
@FreakyAli
FreakyAli / MainViewModel.cs
Last active August 23, 2022 20:48
An example of how you can use a basic ViewModel setup to demonstrate data transfer
using System;
using System.Text;
using System.Windows.Input;
using NDEF.MAUI;
using NDEF.MAUI.Interfaces;
public class MainViewModel : BaseViewModel
{
private readonly INfcService nfcAdapter;
private string stringData;
@FreakyAli
FreakyAli / NfcService.cs
Created August 23, 2022 16:30
NFC service for iOS
using System;
using CoreNFC;
using NDEF.MAUI.Enums;
using NDEF.MAUI.Interfaces;
using UIKit;
public class NfcService : INfcService
{
public async Task SendAsync(byte[] bytes)
{
@FreakyAli
FreakyAli / NFCService.cs
Last active August 23, 2022 20:20
Android NFC service
using System;
using Android.App;
using Android.Content;
using Android.Nfc;
using Android.Nfc.Tech;
using Android.OS;
using Application = Microsoft.Maui.Controls.Application;
using NDEF.MAUI.Enums;
using static Android.Nfc.NfcAdapter;
using NDEF.MAUI.Interfaces;
@FreakyAli
FreakyAli / INfcService.cs
Created August 23, 2022 16:19
Interface for NFCService
public interface INfcService
{
/// <summary>
/// Configuration for NFC service
/// </summary>
public void ConfigureNfcAdapter()
{
}
@FreakyAli
FreakyAli / SessionDelegate.cs
Created August 23, 2022 16:02
SessionDelegate for NFCNdefReaderSessionDelegate
public class SessionDelegate : NFCNdefReaderSessionDelegate
{
private readonly byte[] bytes;
public TaskCompletionSource<NfcTransmissionStatus> WasDataTransmitted { get; set; }
public SessionDelegate(byte[] bytes)
{
this.bytes = bytes;
WasDataTransmitted = new TaskCompletionSource<NfcTransmissionStatus>();
}
@FreakyAli
FreakyAli / Info.plist
Last active August 23, 2022 15:45
Info plist related changes
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NFCReaderUsageDescription</key>
<string>This application wants to access NFC</string>
</dict>
</plist>
@FreakyAli
FreakyAli / Entitlement.plist
Created August 23, 2022 15:37
Entitlements for NFC
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>NDEF</string>
<string>TAG</string>
</array>
</dict>
@FreakyAli
FreakyAli / MainActivity.cs
Last active August 23, 2022 15:25
MainActivity for NFC feature
[MetaData(NfcAdapter.ActionTechDiscovered, Resource = "@xml/nfc_tech_filter")]
[IntentFilter(new[] { NfcAdapter.ActionTechDiscovered }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = "text/plain")]
[IntentFilter(new[] { NfcAdapter.ActionNdefDiscovered }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = "text/plain")]
[IntentFilter(new[] { NfcAdapter.ActionTagDiscovered }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = "text/plain")]
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, Exported = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
public TaskCompletionSource<Tag> NfcTag { get; set; }