Skip to content

Commit a64432f

Browse files
Copy/Paste images internally for Android (#257)
1 parent 680896f commit a64432f

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using Microsoft.Extensions.DependencyInjection;
22
using Pixed.Application.Platform;
33
using Pixed.Common.DependencyInjection;
4+
using Pixed.Common.Platform;
45

56
namespace Pixed.Android;
67
internal class AndroidDependencyRegister : IDependencyRegister
78
{
89
public void Register(ref IServiceCollection collection)
910
{
1011
collection.AddSingleton<IPlatformFolder, PlatformFolder>();
12+
collection.AddSingleton<IClipboardHandle, PlatformClipboard>();
1113
}
1214
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Avalonia.Input;
2+
using Avalonia.Input.Platform;
3+
using Pixed.Common.Platform;
4+
5+
namespace Pixed.Android;
6+
internal class PlatformClipboard : IClipboardHandle
7+
{
8+
private byte[]? _copiedBuffer;
9+
public Task ClearAsync()
10+
{
11+
_copiedBuffer = null;
12+
return Task.CompletedTask;
13+
}
14+
15+
public Task<object?> GetDataAsync(string format)
16+
{
17+
if(format != "PNG" || _copiedBuffer == null)
18+
{
19+
return Task.FromResult<object?>(null);
20+
}
21+
22+
return Task.FromResult<object?>(_copiedBuffer);
23+
}
24+
25+
public Task<string[]> GetFormatsAsync()
26+
{
27+
return Task.FromResult<string[]>(_copiedBuffer == null ? [] : ["PNG"]);
28+
}
29+
30+
public void Initialize(IClipboard clipboard)
31+
{
32+
}
33+
34+
public Task SetDataObjectAsync(IDataObject data)
35+
{
36+
var png = data.Get("PNG");
37+
38+
if(png != null && png is byte[] array)
39+
{
40+
_copiedBuffer = array;
41+
}
42+
43+
return Task.CompletedTask;
44+
}
45+
}

0 commit comments

Comments
 (0)