Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
d5cac27
Conform the Essentials API to the rest of MAUI
mattleibow Mar 18, 2022
95fc6d8
Merge remote-tracking branch 'origin/main' into dev/essentials-api
mattleibow Mar 18, 2022
5e3038d
Trying things with essentials
mattleibow Mar 19, 2022
0c54a81
moar
mattleibow Mar 19, 2022
15b7314
Merge remote-tracking branch 'origin/main' into dev/essentials-api
mattleibow Mar 19, 2022
558f847
more
mattleibow Mar 19, 2022
05e6f21
more
mattleibow Mar 19, 2022
f42b4e4
more
mattleibow Mar 21, 2022
4665e8a
Merge remote-tracking branch 'origin/main' into dev/essentials-api
mattleibow Mar 22, 2022
095c31b
more
mattleibow Mar 22, 2022
36090f5
Merge remote-tracking branch 'origin/main' into dev/essentials-api
mattleibow Mar 22, 2022
c81443d
more
mattleibow Mar 23, 2022
c7b2c27
Merge remote-tracking branch 'origin/main' into dev/essentials-api
mattleibow Mar 23, 2022
736de5c
near the end
mattleibow Mar 23, 2022
9bc09c2
sms
mattleibow Mar 23, 2022
633fd8f
mostly done
mattleibow Mar 23, 2022
dcc9b81
Merge remote-tracking branch 'origin/main' into dev/essentials-api
mattleibow Mar 23, 2022
f3e2a66
2 to go
mattleibow Mar 23, 2022
aa5aa84
Merge remote-tracking branch 'origin/main' into dev/essentials-api
mattleibow Mar 23, 2022
4d691e0
done
mattleibow Mar 24, 2022
e379020
things
mattleibow Mar 24, 2022
aa35908
Merge remote-tracking branch 'origin/main' into dev/essentials-api
mattleibow Mar 24, 2022
085322c
not this
mattleibow Mar 24, 2022
1d91d52
compiles again
mattleibow Mar 24, 2022
3b7800f
Merge remote-tracking branch 'origin/main' into dev/essentials-api
mattleibow Mar 24, 2022
c28a203
Sensors
mattleibow Mar 24, 2022
35c58f5
namespaces
mattleibow Mar 24, 2022
6cfdd67
more ns changes
mattleibow Mar 24, 2022
f8c39e6
Merge remote-tracking branch 'origin/main' into dev/essentials-ns
mattleibow Mar 24, 2022
e4a5fd3
sample
mattleibow Mar 24, 2022
86bfd4b
more
mattleibow Mar 24, 2022
c639f6a
namespaces
mattleibow Mar 25, 2022
f939d74
Merge remote-tracking branch 'origin/main' into dev/essentials-ns
mattleibow Mar 25, 2022
be6aca4
Merge branch 'dev/essentials-ns' into dev/essentials-api
mattleibow Mar 25, 2022
d20a0c5
skip the gallery
mattleibow Mar 25, 2022
fb6c5e6
oops
mattleibow Mar 25, 2022
77f3160
merges
mattleibow Mar 25, 2022
8df21fd
revert things
mattleibow Mar 25, 2022
671b7f4
Merge branch 'dev/essentials-api' into dev/essentials-temp
mattleibow Mar 25, 2022
b7abfed
merge files again
mattleibow Mar 25, 2022
e8751f0
revert
mattleibow Mar 25, 2022
f26fafc
no need to fix here
mattleibow Mar 25, 2022
a4987d8
revert
mattleibow Mar 25, 2022
ddc15d5
filenames
mattleibow Mar 25, 2022
54e6090
this
mattleibow Mar 25, 2022
772fcfa
Merge branch 'dev/essentials-ns' into dev/essentials-api
mattleibow Mar 25, 2022
5322147
fix
mattleibow Mar 25, 2022
9e155fa
message
mattleibow Mar 25, 2022
0b8ef87
fix
mattleibow Mar 25, 2022
869ac86
more fixes
mattleibow Mar 25, 2022
217f3fb
add it back
mattleibow Mar 25, 2022
5a05c80
api mismatch
mattleibow Mar 25, 2022
585dedd
missing ns
mattleibow Mar 25, 2022
1c0f498
use new API
mattleibow Mar 25, 2022
821467c
Merge branch 'temp' into dev/essentials-api
mattleibow Mar 25, 2022
3aba9ae
Merge remote-tracking branch 'origin/main' into dev/essentials-api
mattleibow Mar 25, 2022
f06b745
merge things
mattleibow Mar 25, 2022
64b4a64
oops
mattleibow Mar 25, 2022
a5bcde3
Improve tablet mode checks
mattleibow Mar 25, 2022
08d7dac
oops
mattleibow Mar 25, 2022
ef90f33
Fix tests based on new implementation details
mattleibow Mar 25, 2022
cd04013
Merge remote-tracking branch 'origin/main' into dev/essentials-api
mattleibow Mar 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static async Task CallFilePickerAsync(IValueCallback filePathCallback, F
var pickOptions = GetPickOptions(fileChooserParams);
var fileResults = fileChooserParams?.Mode == ChromeFileChooserMode.OpenMultiple ?
await FilePicker.PickMultipleAsync(pickOptions) :
new[] { await FilePicker.PickAsync(pickOptions) };
new[] { (await FilePicker.PickAsync(pickOptions))! };

if (fileResults?.All(f => f is null) ?? true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
<Button x:Name="RenderButton" Text="Render This Button As Image" Clicked="RenderButton_Clicked" />
<Button Text="Render Window As Image" Clicked="RenderWindow_Clicked" />
<HorizontalStackLayout Spacing="5" RadioButtonGroup.GroupName="Image Type" HorizontalOptions="Center"
RadioButtonGroup.SelectedValue="{Binding Selection}">
RadioButtonGroup.SelectedValue="{Binding Selection}">
<RadioButton Content="JPEG" Value="JPEG"/>
<RadioButton Content="PNG" Value="PNG"/>
<RadioButton Content="BMP" Value="BMP"/>
</HorizontalStackLayout>
</VerticalStackLayout>
<Image x:Name="TestImage" Grid.Row="1"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,125 +1,112 @@
#nullable enable

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
using Maui.Controls.Sample.ViewModels.Base;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Devices;
using Microsoft.Maui.Platform;
using Microsoft.Maui.ApplicationModel.DataTransfer;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Media;
using Microsoft.Maui.Storage;

namespace Maui.Controls.Sample.Pages
{
public partial class RenderViewPage
{
Stopwatch stopwatch = new Stopwatch();
RenderBindingModel vm;
readonly Stopwatch stopwatch = new Stopwatch();
readonly RenderBindingModel vm;

MemoryStream? imageStream;
byte[]? byteStream;

public RenderViewPage()
{
InitializeComponent();
this.BindingContext = this.vm = new RenderBindingModel();

BindingContext = vm = new RenderBindingModel();
}

private async void RenderWindow_Clicked(object sender, System.EventArgs e)
async void RenderWindow_Clicked(object sender, EventArgs e)
{
Reset();
RenderedView? renderImage = null;
var window = this.GetParentWindow() as IWindow;
stopwatch.Start();
try
{
if (window is not null)
{
renderImage = await window.RenderAsImage(vm.RenderType);
}

}
catch (System.Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
var renderImage = await Window.CaptureAsync();

stopwatch.Stop();

RenderView(renderImage);
await RenderView(renderImage);
}

private async void RenderButton_Clicked(object sender, System.EventArgs e)
async void RenderButton_Clicked(object sender, EventArgs e)
{
Reset();
RenderedView? renderImage = null;
stopwatch.Start();
try
{
renderImage = await this.RenderButton.RenderAsImage(vm.RenderType);

}
catch (System.Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}

var renderImage = await RenderButton.CaptureAsync();

stopwatch.Stop();

RenderView(renderImage);
await RenderView(renderImage);
}

private async void RenderViewSaved_Clicked(object sender, System.EventArgs e)
async void RenderViewSaved_Clicked(object sender, EventArgs e)
{
if (byteStream is not null)
if (imageStream is not null)
{
var extension = vm.RenderType switch
{
RenderType.JPEG => "jpg",
RenderType.PNG => "png",
RenderType.BMP => "bmp",
_ => "jpg",
ScreenshotFormat.Jpeg => ".jpg",
ScreenshotFormat.Png => ".png",
_ => ".jpg",
};
string fileName = $"{System.IO.Path.GetTempFileName()}.{extension}";
string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), fileName);
File.WriteAllBytes(filePath, byteStream);
await Share.RequestAsync(new ShareFileRequest() { Title = fileName, File = new ShareFile(filePath) });

var fileName = Path.GetTempFileName() + extension;
var filePath = Path.Combine(FileSystem.CacheDirectory, fileName);

File.WriteAllBytes(filePath, imageStream.ToArray());

await Share.RequestAsync(new ShareFileRequest
{
Title = fileName,
File = new ShareFile(filePath)
});
}
}

private void RenderView(RenderedView? renderImage)
async Task RenderView(IScreenshotResult? renderImage)
{
if (renderImage?.Render is not null)
if (renderImage is not null)
{
try
{
byteStream = renderImage.Render;
imageStream = new MemoryStream(renderImage.Render);
this.TestImage.Source = ImageSource.FromStream(() => imageStream);
}
catch (System.Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
imageStream = new MemoryStream();
await renderImage.CopyToAsync(imageStream, vm.RenderType);
imageStream.Position = 0;

TestImage.Source = ImageSource.FromStream(() => imageStream);
}
this.StopwatchTime.Text = stopwatch.Elapsed.ToString();
this.RenderStats.Text = $"Type: {renderImage?.RenderType}; Size: {SizeInBytes(renderImage?.Render)}";

StopwatchTime.Text = stopwatch.Elapsed.ToString();
RenderStats.Text = $"Size: {SizeInBytes(imageStream)}";
}

private void Reset()
void Reset()
{
stopwatch.Reset();

StopwatchTime.Text = string.Empty;
RenderStats.Text = string.Empty;
this.TestImage.Source = null;

TestImage.Source = null;
}

private string SizeInBytes(byte[]? array)
static string SizeInBytes(Stream? stream)
{
if (array is null)
return string.Empty;
if (stream is null)
return "<null>";

string[] sizes = { "B", "KB", "MB", "GB", "TB" };
double len = System.Convert.ToDouble(array.Length);

double len = stream.Length;
int order = 0;
while (len >= 1024D && order < sizes.Length - 1)
{
Expand All @@ -131,36 +118,19 @@ private string SizeInBytes(byte[]? array)
}
}

public class RenderBindingModel : INotifyPropertyChanged
public class RenderBindingModel : BaseViewModel
{
private string? _selection;

public event PropertyChangedEventHandler? PropertyChanged;

void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
string? _selection;

public string? Selection
{
get => _selection;
set
{
_selection = value;
OnPropertyChanged(nameof(Selection));
}
set => SetProperty(ref _selection, value);
}

public RenderType RenderType
{
get
{
if (_selection is null)
return RenderType.JPEG;

return (RenderType)System.Enum.Parse(typeof(RenderType), _selection);
}
}
public ScreenshotFormat RenderType =>
Enum.TryParse<ScreenshotFormat>(Selection, out var format)
? format
: ScreenshotFormat.Jpeg;
}
}
2 changes: 1 addition & 1 deletion src/Controls/tests/Core.UnitTests/MockDeviceDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class MockDeviceDisplay : IDeviceDisplay

public event EventHandler<DisplayInfoChangedEventArgs>? MainDisplayInfoChanged;

public DisplayInfo GetMainDisplayInfo() => _mainDisplayInfo;
public DisplayInfo MainDisplayInfo => _mainDisplayInfo;

public void UpdateMainDisplayInfo(DisplayInfo displayInfo)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Core/src/Fonts/FontRegistrar.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ public partial class FontRegistrar : IFontRegistrar
{
string? LoadNativeAppFont(string font, string filename, string? alias)
{
if (FileSystemImplementation.AppPackageFileExists(filename))
if (FileSystemUtils.AppPackageFileExists(filename))
return $"ms-appx:///{filename}";

var packagePath = Path.Combine("Assets", filename);
if (FileSystemImplementation.AppPackageFileExists(packagePath))
if (FileSystemUtils.AppPackageFileExists(packagePath))
return $"ms-appx:///Assets/{filename}";

packagePath = Path.Combine("Fonts", filename);
if (FileSystemImplementation.AppPackageFileExists(packagePath))
if (FileSystemUtils.AppPackageFileExists(packagePath))
return $"ms-appx:///Fonts/{filename}";

packagePath = Path.Combine("Assets", "Fonts", filename);
if (FileSystemImplementation.AppPackageFileExists(packagePath))
if (FileSystemUtils.AppPackageFileExists(packagePath))
return $"ms-appx:///Assets/Fonts/{filename}";

// TODO: check other folders as well
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Hosting/EssentialsMauiAppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal static MauiAppBuilder UseEssentials(this MauiAppBuilder builder)
life.AddWindows(windows => windows
.OnPlatformMessage((window, args) =>
{
ApplicationModel.Platform.NewWindowProc(args.Hwnd, args.MessageId, args.WParam, args.LParam);
ApplicationModel.Platform.OnWindowMessage(args.Hwnd, args.MessageId, args.WParam, args.LParam);
})
.OnActivated((window, args) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public partial class StreamImageSourceService

var image = new BitmapImage();

using var ras = stream.AsRandomAccessStream();
var ras = stream.AsRandomAccessStream();
await image.SetSourceAsync(ras);

var result = new ImageSourceServiceResult(image);
Expand Down
44 changes: 0 additions & 44 deletions src/Core/src/Platform/Android/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,50 +307,6 @@ public static void RemoveFromParent(this AView view)
PlatformInterop.RemoveFromParent(view);
}

public static Task<byte[]?> RenderAsBMP(this IView view)
{
var platformView = view?.ToPlatform();
if (platformView == null)
return Task.FromResult<byte[]?>(null);

return Task.FromResult<byte[]?>(platformView.RenderAsBMP());
}

public static Task<byte[]?> RenderAsPNG(this IView view)
{
var platformView = view?.ToPlatform();
if (platformView == null)
return Task.FromResult<byte[]?>(null);

return platformView.RenderAsPNG();
}

public static Task<byte[]?> RenderAsJPEG(this IView view)
{
var platformView = view?.ToPlatform();
if (platformView == null)
return Task.FromResult<byte[]?>(null);

return platformView.RenderAsJPEG();
}

public static Task<byte[]?> RenderAsImage(this AView view, RenderType type)
{
return type switch
{
RenderType.JPEG => view.RenderAsJPEG(),
RenderType.PNG => view.RenderAsPNG(),
RenderType.BMP => Task.FromResult<byte[]?>(view.RenderAsBMP()),
_ => throw new NotImplementedException()
};
}

public static Task<byte[]?> RenderAsPNG(this AView view)
=> Task.FromResult<byte[]?>(view.RenderAsImage(Android.Graphics.Bitmap.CompressFormat.Png));

public static Task<byte[]?> RenderAsJPEG(this AView view)
=> Task.FromResult<byte[]?>(view.RenderAsImage(Android.Graphics.Bitmap.CompressFormat.Jpeg));

internal static Rect GetPlatformViewBounds(this IView view)
{
var platformView = view?.ToPlatform();
Expand Down
33 changes: 0 additions & 33 deletions src/Core/src/Platform/Android/WindowExtensions.cs

This file was deleted.

9 changes: 0 additions & 9 deletions src/Core/src/Platform/Standard/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ public static void UpdateMinimumWidth(this object platformView, IView view) { }

public static void UpdateMaximumWidth(this object platformView, IView view) { }

public static System.Threading.Tasks.Task<byte[]?> RenderAsBMP(this IView view)
=> System.Threading.Tasks.Task.FromResult<byte[]?>(null);

public static System.Threading.Tasks.Task<byte[]?> RenderAsPNG(this IView view)
=> System.Threading.Tasks.Task.FromResult<byte[]?>(null);

public static System.Threading.Tasks.Task<byte[]?> RenderAsJPEG(this IView view)
=> System.Threading.Tasks.Task.FromResult<byte[]?>(null);

internal static Graphics.Rect GetPlatformViewBounds(this IView view) => view.Frame;

internal static System.Numerics.Matrix4x4 GetViewTransform(this IView view) => new System.Numerics.Matrix4x4();
Expand Down
Loading