Skip to content

Commit 3cea8b1

Browse files
committed
Merged Splat code.
1 parent 6f568d1 commit 3cea8b1

File tree

4 files changed

+132
-29
lines changed

4 files changed

+132
-29
lines changed

KPCLib.sln

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ VisualStudioVersion = 15.0.27130.2027
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KPCLib", "KPCLib\KPCLib.csproj", "{3F08B816-6E5F-4DB5-9BF5-4EDF9E662855}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AndroidUnitTestApp", "AndroidUnitTestApp\AndroidUnitTestApp.csproj", "{E168B8E7-191C-402D-BB9A-C3A321955E91}"
9-
EndProject
108
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UWPTestApp", "UWPTestApp\UWPTestApp.csproj", "{7922B150-33B7-4221-A292-EB82FA27C8CE}"
119
EndProject
1210
Global
@@ -37,30 +35,6 @@ Global
3735
{3F08B816-6E5F-4DB5-9BF5-4EDF9E662855}.Release|x64.Build.0 = Release|Any CPU
3836
{3F08B816-6E5F-4DB5-9BF5-4EDF9E662855}.Release|x86.ActiveCfg = Release|Any CPU
3937
{3F08B816-6E5F-4DB5-9BF5-4EDF9E662855}.Release|x86.Build.0 = Release|Any CPU
40-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Debug|Any CPU.Build.0 = Debug|Any CPU
42-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
43-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Debug|ARM.ActiveCfg = Debug|Any CPU
44-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Debug|ARM.Build.0 = Debug|Any CPU
45-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Debug|ARM.Deploy.0 = Debug|Any CPU
46-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Debug|x64.ActiveCfg = Debug|Any CPU
47-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Debug|x64.Build.0 = Debug|Any CPU
48-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Debug|x64.Deploy.0 = Debug|Any CPU
49-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Debug|x86.ActiveCfg = Debug|Any CPU
50-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Debug|x86.Build.0 = Debug|Any CPU
51-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Debug|x86.Deploy.0 = Debug|Any CPU
52-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Release|Any CPU.ActiveCfg = Release|Any CPU
53-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Release|Any CPU.Build.0 = Release|Any CPU
54-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Release|Any CPU.Deploy.0 = Release|Any CPU
55-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Release|ARM.ActiveCfg = Release|Any CPU
56-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Release|ARM.Build.0 = Release|Any CPU
57-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Release|ARM.Deploy.0 = Release|Any CPU
58-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Release|x64.ActiveCfg = Release|Any CPU
59-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Release|x64.Build.0 = Release|Any CPU
60-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Release|x64.Deploy.0 = Release|Any CPU
61-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Release|x86.ActiveCfg = Release|Any CPU
62-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Release|x86.Build.0 = Release|Any CPU
63-
{E168B8E7-191C-402D-BB9A-C3A321955E91}.Release|x86.Deploy.0 = Release|Any CPU
6438
{7922B150-33B7-4221-A292-EB82FA27C8CE}.Debug|Any CPU.ActiveCfg = Debug|x86
6539
{7922B150-33B7-4221-A292-EB82FA27C8CE}.Debug|ARM.ActiveCfg = Debug|ARM
6640
{7922B150-33B7-4221-A292-EB82FA27C8CE}.Debug|ARM.Build.0 = Debug|ARM

KPCLib/KPCLib.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<OutputType>Library</OutputType>
77
<StartupObject />
88
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
9-
<Version>1.1.3</Version>
9+
<Version>1.1.4</Version>
1010
<PackageLicenseUrl>https://github.com/passxyz/KPCLib/blob/master/LICENSE</PackageLicenseUrl>
1111
<PackageProjectUrl>https://github.com/passxyz/KPCLib</PackageProjectUrl>
1212
<RepositoryUrl>https://github.com/passxyz/KPCLib</RepositoryUrl>
@@ -24,7 +24,11 @@
2424
</PropertyGroup>
2525

2626
<ItemGroup>
27-
<PackageReference Include="Splat" Version="2.1.0" />
27+
<Folder Include="Splat\" />
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<PackageReference Include="Xamarin.Forms" Version="2.5.0.122203" />
2832
</ItemGroup>
2933

3034
</Project>

KPCLib/PwDatabase.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,17 @@ public Image GetCustomIcon(PwUuid pwIconId)
16431643

16441644
return null;
16451645
}
1646+
1647+
public PwCustomIcon GetPwCustomIcon(PwUuid pwIconId)
1648+
{
1649+
int nIndex = GetCustomIconIndex(pwIconId);
1650+
if (nIndex >= 0)
1651+
return m_vCustomIcons[nIndex];
1652+
else { Debug.Assert(false); }
1653+
1654+
return null;
1655+
}
1656+
16461657
#elif !KeePassLibSD
16471658
[Obsolete("Additionally specify the size.")]
16481659
public Image GetCustomIcon(PwUuid pwIconId)
@@ -1674,7 +1685,7 @@ public Image GetCustomIcon(PwUuid pwIconId, int w, int h)
16741685
}
16751686
#endif
16761687

1677-
public bool DeleteCustomIcons(List<PwUuid> vUuidsToDelete)
1688+
public bool DeleteCustomIcons(List<PwUuid> vUuidsToDelete)
16781689
{
16791690
Debug.Assert(vUuidsToDelete != null);
16801691
if(vUuidsToDelete == null) throw new ArgumentNullException("vUuidsToDelete");

KPCLib/Splat/Bitmaps.cs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Splat
10+
{
11+
public enum CompressedBitmapFormat
12+
{
13+
Png, Jpeg,
14+
}
15+
16+
/// <summary>
17+
/// Represents the platform-specific image loader class. Unless you are
18+
/// testing image loading, you don't usually need to implement this.
19+
/// </summary>
20+
public interface IBitmapLoader
21+
{
22+
/// <summary>
23+
/// Loads a bitmap from a byte stream
24+
/// </summary>
25+
/// <param name="sourceStream">The stream to load the image from.</param>
26+
/// <param name="desiredWidth">The desired width of the image.</param>
27+
/// <param name="desiredHeight">The desired height of the image.</param>
28+
/// <returns>A future result representing the loaded image</returns>
29+
Task<IBitmap> Load(Stream sourceStream, float? desiredWidth, float? desiredHeight);
30+
31+
/// <summary>
32+
/// Loads from the application's resources (i.e. from bundle on Cocoa,
33+
/// from Pack URIs on Windows, etc)
34+
/// </summary>
35+
/// <param name="source">The source resource, as a relative path.</param>
36+
/// <param name="desiredWidth">Desired width.</param>
37+
/// <param name="desiredHeight">Desired height.</param>
38+
/// <returns>A future result representing the loaded image</returns>
39+
Task<IBitmap> LoadFromResource(string source, float? desiredWidth, float? desiredHeight);
40+
41+
/// <summary>
42+
/// Creates an empty bitmap of the specified dimensions
43+
/// </summary>
44+
/// <param name="width">The width of the canvas</param>
45+
/// <param name="height">The height of the canvas</param>
46+
/// <returns>A new image. Use ToNative() to convert this to a native bitmap</returns>
47+
IBitmap Create(float width, float height);
48+
}
49+
50+
/// <summary>
51+
/// Represents a bitmap image that was loaded via a ViewModel. Every platform
52+
/// provides FromNative and ToNative methods to convert this object to the
53+
/// platform-specific versions.
54+
/// </summary>
55+
public interface IBitmap : IDisposable
56+
{
57+
/// <summary>
58+
/// Width in pixel units (depending on platform)
59+
/// </summary>
60+
float Width { get; }
61+
62+
/// <summary>
63+
/// Height in pixel units (depending on platform)
64+
/// </summary>
65+
float Height { get; }
66+
67+
/// <summary>
68+
/// Saves an image to a target stream
69+
/// </summary>
70+
/// <param name="format">The format to save the image in.</param>
71+
/// <param name="quality">If JPEG is specified, this is a quality
72+
/// factor between 0.0 and 1.0f where 1.0f is the best quality.</param>
73+
/// <param name="target">The target stream to save to.</param>
74+
/// <returns>A signal indicating the Save has completed.</returns>
75+
Task Save(CompressedBitmapFormat format, float quality, Stream target);
76+
}
77+
78+
/// <summary>
79+
/// This class loads and creates bitmap resources in a platform-independent
80+
/// way.
81+
/// </summary>
82+
public static class BitmapLoader
83+
{
84+
static BitmapLoader()
85+
{
86+
var platBitmapLoader = Xamarin.Forms.DependencyService.Get<IBitmapLoader>();
87+
88+
// var platBitmapLoader = AssemblyFinder.AttemptToLoadType<IBitmapLoader>("Splat.PlatformBitmapLoader");
89+
#if DEBUG
90+
if (platBitmapLoader == null)
91+
Debug.WriteLine("BitmapLoader: Cannot load the inteface.");
92+
else
93+
Debug.WriteLine("BitmapLoader: Loaded the inteface successfully.");
94+
#endif
95+
_Current = platBitmapLoader;
96+
}
97+
98+
// TODO: This needs to be improved once we move the "Detect in Unit Test
99+
// Runner" code into Splat
100+
static IBitmapLoader _Current;
101+
102+
public static IBitmapLoader Current {
103+
get {
104+
var ret = _Current;
105+
if (ret == null) {
106+
throw new Exception("Could not find a default bitmap loader. This should never happen, your dependency resolver is broken");
107+
}
108+
109+
return ret;
110+
}
111+
set { _Current = value; }
112+
}
113+
}
114+
}

0 commit comments

Comments
 (0)