Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maui conversion - Part II #11

Open
wants to merge 5 commits into
base: maui-ios-conversion
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions App1.Maui/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App1"
x:Class="App1.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
66 changes: 32 additions & 34 deletions App1/App1/App.cs → App1.Maui/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

namespace App1
{
public class App : Application
public partial class App : Application
{
public App() : base()
public App()
{
InitializeComponent();

AppManager.Initialize(this);

// Uncomment the following to add the styles from this page to the application.
Expand All @@ -23,38 +25,6 @@ public App() : base()
AppManager.Instance.AssemblyManager.RegisterAssemblies(this.GetType().Assembly);
}

protected override async void OnStart()
{
await AppManager.Instance.InitializeAsync();
var appPage = await AppManager.Instance.Bootstrapper.LoadAppAsync(new Uri("resource://app.json"));
await AppManager.Instance.Bootstrapper.DisplayAppAsync(appPage.Page);
}

/*
OnSleep() and OnResume() don't seem to get called by Xamarin so we're providing the same functionality explicitly for iOS, Android.
*/

// <inheritdoc/>
protected override void OnSleep()
{
AppManager.Instance.OnBackgrounded();

base.OnSleep();
}

// <inheritdoc/>
protected override void OnResume()
{
// OnResume will get called when background processing begins.
// UWP activated events are raised in UWP App.xaml.cs.
if (DeviceInfo.Platform != DevicePlatform.WinUI)
{
AppManager.Instance.OnActivated();
}

base.OnResume();
}

private View GetContent()
{
// Stack
Expand Down Expand Up @@ -97,5 +67,33 @@ void ShowStatus(object sender, LoadingEventArgs e)

return stack;
}

protected override async void OnStart()
{
await AppManager.Instance.InitializeAsync();
var appPage = await AppManager.Instance.Bootstrapper.LoadAppAsync(new Uri("resource://app.json"));
await AppManager.Instance.Bootstrapper.DisplayAppAsync(appPage.Page);
}

// <inheritdoc/>
protected override void OnSleep()
{
AppManager.Instance.OnBackgrounded();

base.OnSleep();
}

// <inheritdoc/>
protected override void OnResume()
{
// OnResume will get called when background processing begins.
// UWP activated events are raised in UWP App.xaml.cs.
if (DeviceInfo.Platform != DevicePlatform.WinUI)
{
AppManager.Instance.OnActivated();
}

base.OnResume();
}
}
}
72 changes: 72 additions & 0 deletions App1.Maui/App1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>

<OutputType>Exe</OutputType>
<RootNamespace>App1.Maui</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<!-- Display name -->
<ApplicationTitle>App1.Maui</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.companyname.app1.maui</ApplicationId>

<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='net8.0-ios'">
<ProvisioningType>manual</ProvisioningType>
<CodesignKey>Apple Development: Created via API (O17P7NVJQPH6)</CodesignKey>
<CodesignProvision>VS: WildCard Development</CodesignProvision>
</PropertyGroup>

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.Contains('windows'))">
<MauiAsset Include="Platforms\Windows\Assets\**">
<LogicalName>%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
</MauiAsset>
<None Remove="Assets\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Esri.ArcGISRuntime" Version="200.5.0" />
<PackageReference Include="Esri.ArcGISRuntime.Maui" Version="200.5.0" />
<PackageReference Include="VertiGIS.Mobile" Version="5.34.0-main.20" />
</ItemGroup>
</Project>
27 changes: 27 additions & 0 deletions App1.Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Extensions.Logging;
using VertiGIS.Mobile.Platform;

namespace App1
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseStudioMobile()
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
}
}
6 changes: 6 additions & 0 deletions App1.Maui/Platforms/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Android.App;
using Android.App;
using Android.Content.PM;
using Android.OS;
using Java.Lang;
using VertiGIS.Mobile.Platforms;
using static Java.Lang.Thread;

namespace App1.Droid;
namespace App1;

// See Android App Lifecycle: https://learn.microsoft.com/dotnet/maui/fundamentals/app-lifecycle#android
// See MainActivity: https://learn.microsoft.com/dotnet/maui/android/manifest#activity-name
Expand All @@ -22,7 +22,7 @@ protected override void OnCreate(Bundle bundle)
HandleExceptions();

// The app was launched with the splash screen theme, so change it to the main theme now
base.SetTheme(Android.Resource.Style.MainTheme);
base.SetTheme(Maui.Resource.Style.MainTheme);

base.OnCreate(bundle);

Expand All @@ -32,7 +32,7 @@ protected override void OnCreate(Bundle bundle)
HandleAppPermissions(); // Location, bluetooth, etc.
}

public void UncaughtException(Thread t, Throwable e)
public void UncaughtException(Java.Lang.Thread t, Throwable e)
{
//throw new System.NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using Android.App;
using Android.App;
using Android.Runtime;
using Microsoft.Maui;
using Microsoft.Maui.Hosting;
using System;

namespace App1.Droid
namespace App1
{
[Application]
public class MainApplication : MauiApplication
{
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowActionBar">true</item>
</style>

</resources>
12 changes: 5 additions & 7 deletions App1/App1.UWP/App.xaml → App1.Maui/Platforms/Windows/App.xaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<maui:MauiWinUIApplication
x:Class="App1.UWP.App"
<maui:MauiWinUIApplication
x:Class="App1.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui"
xmlns:local="using:App1.UWP">
xmlns:maui="using:Microsoft.Maui">
<maui:MauiWinUIApplication.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<ResourceDictionary Source="VertiGIS.Mobile/Platforms/Windows/VertiGISResources.xaml" />
<ResourceDictionary Source="../../VertiGIS.Mobile/Platforms/Windows/VertiGISResources.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="DefaultButtonStyle" TargetType="Button">
<Setter Property="Background" Value="Blue"/>
</Style>
</ResourceDictionary>
</maui:MauiWinUIApplication.Resources>

</maui:MauiWinUIApplication>
25 changes: 25 additions & 0 deletions App1.Maui/Platforms/Windows/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.UI.Xaml;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace App1.WinUI
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : MauiWinUIApplication
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}

}
52 changes: 52 additions & 0 deletions App1.Maui/Platforms/Windows/Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap">

<Identity Name="quickstart-package-name-placeholder" Publisher="CN=User Name" Version="0.0.0.0" />

<mp:PhoneIdentity PhoneProductId="092565AB-E55A-426D-B501-590EEE75F1CF" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

<Properties>
<DisplayName>$placeholder$</DisplayName>
<PublisherDisplayName>User Name</PublisherDisplayName>
<Logo>$placeholder$.png</Logo>
</Properties>

<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.19041.0" MaxVersionTested="10.0.19041.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.19041.0" MaxVersionTested="10.0.19041.0" />
</Dependencies>

<Resources>
<Resource Language="x-generate" />
</Resources>

<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="$placeholder$"
Description="$placeholder$"
Square150x150Logo="$placeholder$.png"
Square44x44Logo="$placeholder$.png"
BackgroundColor="#00777A">
<uap:SplashScreen Image="$placeholder$.png" BackgroundColor="#00777A" />
</uap:VisualElements>
</Application>
</Applications>

<Capabilities>
<rescap:Capability Name="runFullTrust" />
<Capability Name="internetClient" />
<Capability Name="internetClientServer" />
<uap:Capability Name="enterpriseAuthentication" />
<Capability Name="privateNetworkClientServer" />
<DeviceCapability Name="location" />
<DeviceCapability Name="bluetooth" />
<DeviceCapability Name="webcam" />
</Capabilities>

</Package>
15 changes: 15 additions & 0 deletions App1.Maui/Platforms/Windows/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="App1.WinUI.app"/>

<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<!-- The combination of below two tags have the following effect:
1) Per-Monitor for >= Windows 10 Anniversary Update
2) System < Windows 10 Anniversary Update
-->
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
</windowsSettings>
</application>
</assembly>
Loading