Skip to content

Commit

Permalink
Merge pull request #38 from egvijayanand/working
Browse files Browse the repository at this point in the history
Added FUNDING.yml file and Embedded Android sample
  • Loading branch information
egvijayanand authored May 31, 2022
2 parents c63d71b + a54cd3c commit c5d4b97
Show file tree
Hide file tree
Showing 29 changed files with 209 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# These are supported funding model platforms

github: ["egvijayanand"]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: ["https://paypal.me/egvijayanand", "https://www.buymeacoffee.com/egvijayanand"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ Available under the `src` directory:
- UI, ViewModel, Model, and Business logic all from shared project
- Head projects serve as an app container
- Both Xamarin.Forms and .NET MAUI from a single project - `DateCalculator.UI`
* `EmbeddedAndroid` - .NET MAUI Page embedded in a Native Android App, targeting .NET 6 (`net6.0-android`)
6 changes: 6 additions & 0 deletions src/EmbeddedAndroid/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/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true">
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
7 changes: 7 additions & 0 deletions src/EmbeddedAndroid/App.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EmbeddedAndroid
{
public class App : Application
{

}
}
28 changes: 28 additions & 0 deletions src/EmbeddedAndroid/EmbeddedAndroid.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-android</TargetFramework>
<OutputType>Exe</OutputType>

<!-- Project Options -->
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>EmbeddedAndroid</RootNamespace>

<!-- .NET MAUI -->
<UseMaui>true</UseMaui>

<!-- App Identifier -->
<ApplicationId>com.companyname.embeddedandroid</ApplicationId>

<!-- App Version -->
<ApplicationVersion>1</ApplicationVersion>
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>

<!-- Target Platform Options -->
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui.Markup" Version="1.0.0" />
</ItemGroup>
</Project>
26 changes: 26 additions & 0 deletions src/EmbeddedAndroid/EmbeddedAndroid.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32519.111
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmbeddedAndroid", "EmbeddedAndroid.csproj", "{73A85CF6-9D64-4E4D-AB58-AB68EF69B3FC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{73A85CF6-9D64-4E4D-AB58-AB68EF69B3FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{73A85CF6-9D64-4E4D-AB58-AB68EF69B3FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73A85CF6-9D64-4E4D-AB58-AB68EF69B3FC}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{73A85CF6-9D64-4E4D-AB58-AB68EF69B3FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73A85CF6-9D64-4E4D-AB58-AB68EF69B3FC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1BDC1A21-2B2C-4625-B4F1-A5B39689F0E8}
EndGlobalSection
EndGlobal
31 changes: 31 additions & 0 deletions src/EmbeddedAndroid/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Android.App;
using Android.OS;
using CommunityToolkit.Maui.Markup;
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 builder = MauiApp.CreateBuilder();
builder.UseMauiEmbedding<App>()
.UseMauiCommunityToolkitMarkup();
var mauiApp = builder.Build();
var mauiContext = new MauiContext(mauiApp.Services, this);
var mauiPage = new MauiPage();
// Platform-specific extension method
SetContentView(mauiPage.ToContainerView(mauiContext));
// Platform-independent extension method
//SetContentView(mauiPage.ToPlatform(mauiContext));
}
}
}
22 changes: 22 additions & 0 deletions src/EmbeddedAndroid/MauiPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using CommunityToolkit.Maui.Markup;
using static Microsoft.Maui.Graphics.Colors;

namespace EmbeddedAndroid
{
public class MauiPage : ContentPage
{
public MauiPage()
{
Content = new StackLayout
{
Children =
{
new Label
{
Text = "Welcome to .NET MAUI!!!"
}.TextColor(Purple)
}
}.Center();
}
}
}
44 changes: 44 additions & 0 deletions src/EmbeddedAndroid/Resources/AboutResources.txt
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 src/EmbeddedAndroid/Resources/layout/activity_main.xml
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_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.
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.
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.
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.
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.
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.
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.
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.
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>
4 changes: 4 additions & 0 deletions src/EmbeddedAndroid/Resources/values/strings.xml
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>

0 comments on commit c5d4b97

Please sign in to comment.