-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from egvijayanand/working
.NET MAUI 9 Preview 7 Embedded samples for `Android` and `iOS`
- Loading branch information
Showing
60 changed files
with
697 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:label="@string/app_name" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"> | ||
</application> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net9.0-android</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
|
||
<!-- Project Options --> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>latest</LangVersion> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<RootNamespace>EmbeddedAndroid</RootNamespace> | ||
|
||
<!-- .NET MAUI --> | ||
<UseMaui>true</UseMaui> | ||
<MauiEnablePlatformUsings>true</MauiEnablePlatformUsings> | ||
|
||
<!-- App Identifier --> | ||
<ApplicationId>com.companyname.embeddedandroid</ApplicationId> | ||
|
||
<!-- App Version --> | ||
<ApplicationVersion>1</ApplicationVersion> | ||
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> | ||
|
||
<!-- Target Platform Options --> | ||
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion> | ||
</PropertyGroup> | ||
|
||
<!-- | ||
Enable full trimming in Release mode. | ||
To learn more, see: https://learn.microsoft.com/dotnet/core/deploying/trimming/trimming-options#trimming-granularity | ||
--> | ||
<PropertyGroup Condition="'$(Configuration)' == 'Release'"> | ||
<TrimMode>full</TrimMode> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmbeddedAndroid", "EmbeddedAndroid.csproj", "{6080BD5C-A536-4175-A64D-78FFC4642A41}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{6080BD5C-A536-4175-A64D-78FFC4642A41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{6080BD5C-A536-4175-A64D-78FFC4642A41}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{6080BD5C-A536-4175-A64D-78FFC4642A41}.Debug|Any CPU.Deploy.0 = Debug|Any CPU | ||
{6080BD5C-A536-4175-A64D-78FFC4642A41}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{6080BD5C-A536-4175-A64D-78FFC4642A41}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{6080BD5C-A536-4175-A64D-78FFC4642A41}.Release|Any CPU.Deploy.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Solution> | ||
<Project Path="EmbeddedAndroid.csproj"> | ||
<Deploy /> | ||
</Project> | ||
<Properties Name="Visual Studio"> | ||
<!-- Support is provisionally available on Visual Studio 17.10 and later versions. --> | ||
<Property Name="OpenWith" Value="Visual Studio Version 17" /> | ||
</Properties> | ||
</Solution> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Note: There's a change in namespace. | ||
using Microsoft.Maui.Controls.Embedding; | ||
//using Microsoft.Maui.Embedding; | ||
using Microsoft.Maui.Platform; | ||
|
||
namespace EmbeddedAndroid | ||
{ | ||
[Activity(Label = "@string/app_name", MainLauncher = true)] | ||
public class MainActivity : Activity | ||
{ | ||
protected override void OnCreate(Bundle? savedInstanceState) | ||
{ | ||
base.OnCreate(savedInstanceState); | ||
|
||
// Set our view from the "main" layout resource | ||
//SetContentView(Resource.Layout.activity_main); | ||
|
||
var mauiApp = MauiApp.CreateBuilder() | ||
.UseMauiEmbeddedApp<MyApp>() // Note: The method name too got updated. | ||
.Build(); | ||
|
||
var mauiContext = new MauiContext(mauiApp.Services, this); | ||
|
||
var mauiPage = new MauiPage(); | ||
// Platform-specific extension method | ||
SetContentView(mauiPage.ToContainerView(mauiContext)); | ||
// Platform-neutral extension method | ||
//SetContentView(mauiPage.ToPlatform(mauiContext)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<ContentPage | ||
x:Class="EmbeddedAndroid.MauiPage" | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:d="http://schemas.microsoft.com/dotnet/2021/maui/design" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
<ContentPage.Content> | ||
<Grid> | ||
<Label | ||
HorizontalOptions="Center" | ||
Text=".NET MAUI Embedding is uber cool!!!" | ||
VerticalOptions="Center" /> | ||
</Grid> | ||
</ContentPage.Content> | ||
</ContentPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace EmbeddedAndroid; | ||
|
||
public partial class MauiPage : ContentPage | ||
{ | ||
public MauiPage() => InitializeComponent(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<Application | ||
x:Class="EmbeddedAndroid.MyApp" | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:d="http://schemas.microsoft.com/dotnet/2021/maui/design" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
<Application.Resources> | ||
<Color x:Key="Primary">#512BD4</Color> | ||
|
||
<Style TargetType="Label"> | ||
<Setter Property="FontSize" Value="20" /> | ||
<Setter Property="TextColor" Value="{StaticResource Primary}" /> | ||
</Style> | ||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace EmbeddedAndroid; | ||
|
||
public partial class MyApp : Microsoft.Maui.Controls.Application | ||
{ | ||
public MyApp() => InitializeComponent(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Images, layout descriptions, binary blobs and string dictionaries can be included | ||
in your application as resource files. Various Android APIs are designed to | ||
operate on the resource IDs instead of dealing with images, strings or binary blobs | ||
directly. | ||
|
||
For example, a sample Android app that contains a user interface layout (main.xml), | ||
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) | ||
would keep its resources in the "Resources" directory of the application: | ||
|
||
Resources/ | ||
drawable/ | ||
icon.png | ||
|
||
layout/ | ||
main.xml | ||
|
||
values/ | ||
strings.xml | ||
|
||
In order to get the build system to recognize Android resources, set the build action to | ||
"AndroidResource". The native Android APIs do not operate directly with filenames, but | ||
instead operate on resource IDs. When you compile an Android application that uses resources, | ||
the build system will package the resources for distribution and generate a class called "Resource" | ||
(this is an Android convention) that contains the tokens for each one of the resources | ||
included. For example, for the above Resources layout, this is what the Resource class would expose: | ||
|
||
public class Resource { | ||
public class Drawable { | ||
public const int icon = 0x123; | ||
} | ||
|
||
public class Layout { | ||
public const int main = 0x456; | ||
} | ||
|
||
public class Strings { | ||
public const int first_string = 0xabc; | ||
public const int second_string = 0xbcd; | ||
} | ||
} | ||
|
||
You would then use Resource.Drawable.icon to reference the drawable/icon.png file, or | ||
Resource.Layout.main to reference the layout/main.xml file, or Resource.Strings.first_string | ||
to reference the first string in the dictionary file values/strings.xml. |
13 changes: 13 additions & 0 deletions
13
src/NET_9/EmbeddedAndroid/Resources/layout/activity_main.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerInParent="true" | ||
android:text="@string/app_text" | ||
/> | ||
</RelativeLayout> |
4 changes: 4 additions & 0 deletions
4
src/NET_9/EmbeddedAndroid/Resources/mipmap-anydpi-v26/appicon.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<background android:drawable="@mipmap/appicon_background" /> | ||
<foreground android:drawable="@mipmap/appicon_foreground" /> | ||
</adaptive-icon> |
4 changes: 4 additions & 0 deletions
4
src/NET_9/EmbeddedAndroid/Resources/mipmap-anydpi-v26/appicon_round.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<background android:drawable="@mipmap/appicon_background" /> | ||
<foreground android:drawable="@mipmap/appicon_foreground" /> | ||
</adaptive-icon> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+97 Bytes
src/NET_9/EmbeddedAndroid/Resources/mipmap-hdpi/appicon_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.25 KB
src/NET_9/EmbeddedAndroid/Resources/mipmap-hdpi/appicon_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+92 Bytes
src/NET_9/EmbeddedAndroid/Resources/mipmap-mdpi/appicon_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.24 KB
src/NET_9/EmbeddedAndroid/Resources/mipmap-mdpi/appicon_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+100 Bytes
src/NET_9/EmbeddedAndroid/Resources/mipmap-xhdpi/appicon_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.76 KB
src/NET_9/EmbeddedAndroid/Resources/mipmap-xhdpi/appicon_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+108 Bytes
src/NET_9/EmbeddedAndroid/Resources/mipmap-xxhdpi/appicon_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.88 KB
src/NET_9/EmbeddedAndroid/Resources/mipmap-xxhdpi/appicon_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+117 Bytes
src/NET_9/EmbeddedAndroid/Resources/mipmap-xxxhdpi/appicon_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.74 KB
src/NET_9/EmbeddedAndroid/Resources/mipmap-xxxhdpi/appicon_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions
4
src/NET_9/EmbeddedAndroid/Resources/values/ic_launcher_background.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="ic_launcher_background">#2C3E50</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<resources> | ||
<string name="app_name">EmbeddedAndroid</string> | ||
<string name="app_text">Hello, Android!</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Note: There's a change in namespace. | ||
using Microsoft.Maui.Controls.Embedding; | ||
//using Microsoft.Maui.Embedding; | ||
using Microsoft.Maui.Platform; | ||
|
||
namespace EmbeddediOS; | ||
|
||
[Register(nameof(AppDelegate))] | ||
public class AppDelegate : UIApplicationDelegate | ||
{ | ||
public override UIWindow? Window { get; set; } | ||
|
||
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) | ||
{ | ||
var mauiApp = MauiApp.CreateBuilder() | ||
.UseMauiEmbeddedApp<MyApp>() // Note: The method name too got updated. | ||
.Build(); | ||
|
||
var mauiContext = new MauiContext(mauiApp.Services); | ||
var mauiPage = new MauiPage(); | ||
// Platform-specific extension method | ||
var viewController = mauiPage.ToUIViewController(mauiContext); | ||
|
||
// Create a new window instance based on the screen size | ||
Window = new UIWindow(UIScreen.MainScreen.Bounds) | ||
{ | ||
RootViewController = viewController | ||
}; | ||
|
||
// Here MauiView is a type defined using .NET MAUI construct | ||
// Platform-neutral Windowless API | ||
//var nativeView = new MauiView().ToPlatform(mauiContext); | ||
// Window-aware API - platformWindow can be passed as a method parameter | ||
//var nativeView = new MauiView().ToPlatformEmbedded(mauiContext); | ||
|
||
// Make the window visible | ||
Window.MakeKeyAndVisible(); | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.